Exemplo n.º 1
0
    def start(self):
        """
        Start up the UI
        """
        self.loop = asyncio.get_event_loop()
        self.face = ThreadsafeFace(self.loop, '')

        controllerCertificateName = self._identityStorage.getDefaultCertificateNameForIdentity(
            self.prefix)
        self.face.setCommandSigningInfo(self._keyChain,
                                        controllerCertificateName)
        self._keyChain.setFace(
            self.face)  # shouldn't be necessarym but doesn't hurt

        self._isStopped = False
        self.face.stopWhen(lambda: self._isStopped)

        self.loop.call_soon(self.displayMenu)
        try:
            self.loop.run_forever()
        except KeyboardInterrupt:
            pass
        except Exception as e:
            print(e)
            #self.log('Exception', e)
        finally:
            self._isStopped = True
Exemplo n.º 2
0
def main():

    # COMMAND LINE ARGS
    parser = argparse.ArgumentParser(
        description='Parse or follow Cascade Datahub log and publish to NDN.')
    parser.add_argument('filename', help='datahub log file')
    parser.add_argument('-f',
                        dest='follow',
                        action='store_true',
                        help='follow (tail -f) the log file')
    parser.add_argument('--namespace',
                        default='/ndn/edu/ucla/remap/bms',
                        help='root ndn name, no trailing slash')
    args = parser.parse_args()

    # NDN
    global face, keychain
    loop = asyncio.get_event_loop()
    face = ThreadsafeFace(loop, "localhost")

    keychain = KeyChain(
        IdentityManager(
            BasicIdentityStorage(),
            FilePrivateKeyStorage()))  # override default even for MacOS
    cache = MemoryContentCache(face)

    # READ THE FILE (MAIN LOOP)
    if args.follow:
        loop.run_until_complete(
            followfile(args.filename, args.namespace, cache))
    else:
        loop.run_until_complete(readfile(args.filename, args.namespace, cache))

    face.shutdown()
Exemplo n.º 3
0
    def start(self):
        self.loop = asyncio.get_event_loop()
        self.face = ThreadsafeFace(self.loop, "")
        self.face.setCommandSigningInfo(self.keychain, self.certificateName)
        self.songName = raw_input(
            "Song Name(each song separated by a comma): ")
        self.device = raw_input("Music Player: ")
        self.issueSongCommand()

        try:
            self.loop.run_forever()
        finally:
            self.stop()
Exemplo n.º 4
0
    def start(self):
        self._loop = asyncio.get_event_loop()
        self._face = ThreadsafeFace(self._loop, "")
        self._face.setCommandSigningInfo(self._keyChain, self._certificateName)
        self._face.registerPrefix(self.prefix, self.onPlayingCommand,
                                  self.onRegisterFailed)

        try:
            self._loop.run_forever()
        except KeyboardInterrupt:
            sys.exit()
        finally:
            self.stop()
Exemplo n.º 5
0
def main():
    loop = asyncio.get_event_loop()
    face = ThreadsafeFace(loop, "localhost")
    keyChain = KeyChain()
    face.setCommandSigningInfo(keyChain, keyChain.getDefaultCertificateName())

    # TODO: NFD hack: uncomment once NFD forwarding fixed
    # discoveree = Discoveree(loop, face, keyChain)
    # TODO: NFD hack: remove once NFD forwarding fixed
    discoveree = LocalDiscoveree(loop, face, keyChain)

    cecTv = CecTv(loop, face, keyChain, discoveree)

    loop.run_forever()
    face.shutdown()
Exemplo n.º 6
0
def main():
    loop = asyncio.get_event_loop()
    face = ThreadsafeFace(loop, "aleph.ndn.ucla.edu")

    counter = Counter()
    face.stopWhen(lambda: counter._callbackCount >= 1)

    name1 = Name("/")
    dump("Express name ", name1.toUri())
    # This call to exressIinterest is thread safe because face is a ThreadsafeFace.
    face.expressInterest(name1, counter.onData, counter.onTimeout)

    # Run until stopWhen stops the loop.
    loop.run_forever()
    face.shutdown()
Exemplo n.º 7
0
    def start(self):
        print "reg start"
        self.loop = asyncio.get_event_loop()
        self.face = ThreadsafeFace(self.loop, self.address)
        self.face.setCommandSigningInfo(self.keychain, self.certificateName)
        self.face.registerPrefix(self.prefix, self.onInterest,
                                 self.onRegisterFailed)
        self._isStopped = False
        self.face.stopWhen(lambda: self._isStopped)
        try:
            self.loop.run_forever()
        except KeyboardInterrupt:

            sys.exit()
        finally:
            self.stop()
Exemplo n.º 8
0
    def start(self):
        """
        Begins the event loop. After this, the node's Face is set up and it can
        send/receive interests+data
        """
        self.log.info("Starting up")
        self.loop = asyncio.get_event_loop()
        self.face = ThreadsafeFace(self.loop, '')
        self.face.setCommandSigningInfo(self._keyChain,
                                        self.getDefaultCertificateName())
        self._keyChain.setFace(self.face)

        self._isStopped = False
        self.face.stopWhen(lambda: self._isStopped)
        self.beforeLoopStart()

        try:
            self.loop.run_forever()
        except KeyboardInterrupt:
            pass
        except Exception as e:
            self.log.exception(e, exc_info=True)
        finally:
            self._isStopped = True
Exemplo n.º 9
0
        self.issueSongCommand()


def runForever(loop):
    try:
        loop.run_forever()
    finally:
        sys.exit()


if __name__ == '__main__':

    skeychain = KeyChain()
    scertificateName = skeychain.getDefaultCertificateName()
    sloop = asyncio.get_event_loop()
    sface = ThreadsafeFace(sloop, "")

    sface.setCommandSigningInfo(skeychain, scertificateName)

    t = threading.Thread(target=runForever, args=(sloop, ))
    t.daemon = True
    t.start()

    #obtaining song list
    lq = ListRequiry(skeychain, sloop, sface)
    lq.start()
    songList = []
    songList = lq.onListTimeout()
    #wait for 10 sec
    time.sleep(10)
    #order song