Exemple #1
0
def clientconnector(whiteboardBackplane="WHITEBOARD", audioBackplane="AUDIO", port=1500):
    return Pipeline(
        chunks_to_lines(),
        lines_to_tokenlists(),
        Graphline(
            ROUTER = Router( ((lambda T : T[0]=="SOUND"), "audio"),
                             ((lambda T : T[0]!="SOUND"), "whiteboard"),
                           ),
            WHITEBOARD = FilteringPubsubBackplane(whiteboardBackplane),
            AUDIO = Pipeline(
                        SimpleDetupler(1),     # remove 'SOUND' tag
                        SpeexDecode(3),
                        FilteringPubsubBackplane(audioBackplane, dontRemoveTag=True),
                        RawAudioMixer(),
                        SpeexEncode(3),
                        Entuple(prefix=["SOUND"],postfix=[]),
                    ),
            linkages = {
                # incoming messages go to a router
                ("", "inbox") : ("ROUTER", "inbox"),
                # distribute messages to appropriate destinations
                ("ROUTER",      "audio") : ("AUDIO",      "inbox"),
                ("ROUTER", "whiteboard") : ("WHITEBOARD", "inbox"),
                # aggregate all output
                ("AUDIO",      "outbox") : ("", "outbox"),
                ("WHITEBOARD", "outbox") : ("", "outbox"),
                # shutdown routing, not sure if this will actually work, but hey!
                ("", "control") : ("ROUTER", "control"),
                ("ROUTER", "signal") : ("AUDIO", "control"),
                ("AUDIO", "signal") : ("WHITEBOARD", "control"),
                ("WHITEBOARD", "signal") : ("", "signal")
                },
            ),
        tokenlists_to_lines(),
        )
Exemple #2
0
def EventServerClients(rhost, rport, 
                       whiteboardBackplane="WHITEBOARD",
                       audioBackplane="AUDIO"):
    # plug a TCPClient into the backplane
    
    loadingmsg = "Fetching sketch from server..."

    return Graphline(
            # initial messages sent to the server, and the local whiteboard
            GETIMG = Pipeline(
                        OneShot(msg=[["GETIMG"]]),
                        tokenlists_to_lines()
                    ),
            BLACKOUT =  OneShot(msg="CLEAR 0 0 0\r\n"
                                    "WRITE 100 100 24 255 255 255 "+loadingmsg+"\r\n"),
            NETWORK = TCPClient(host=rhost,port=rport),
            APPCOMMS = clientconnector(whiteboardBackplane=whiteboardBackplane,
                                       audioBackplane=audioBackplane),
            linkages = {
                ("GETIMG",   "outbox") : ("NETWORK",    "inbox"), # Single shot out
                ("APPCOMMS", "outbox") : ("NETWORK", "inbox"), # Continuous out

                ("BLACKOUT", "outbox") : ("APPCOMMS", "inbox"), # Single shot in
                ("NETWORK", "outbox") : ("APPCOMMS", "inbox"), # Continuous in
            } 
        )
Exemple #3
0
def FilterAndTagWrapper(target, dontRemoveTag=False):
    """\
    Returns a component that wraps a target component, tagging all traffic
    going into its inbox; and filtering outany traffic coming out of its outbox
    with the same unique id.
    """
    if dontRemoveTag:
        Filter = FilterButKeepTag
    else:
        Filter = FilterTag

    return Graphline(
        TAGGER=UidTagger(),
        FILTER=Filter(),
        TARGET=target,
        linkages={
            ("TARGET", "outbox"):
            ("FILTER", "inbox"),  # filter data coming from target
            ("FILTER", "outbox"): ("self", "outbox"),
            ("TAGGER", "uid"):
            ("FILTER", "uid"),  # ensure filter uses right uid
            ("self", "inbox"): ("TAGGER", "inbox"),  # tag data going to target
            ("TAGGER", "outbox"): ("TARGET", "inbox"),
            ("self", "control"):
            ("TARGET", "control"),  # shutdown signalling path
            ("TARGET", "signal"): ("TAGGER", "control"),
            ("TAGGER", "signal"): ("FILTER", "control"),
            ("FILTER", "signal"): ("self", "signal"),
        },
    )
Exemple #4
0
def FixedRateControlledReusableFileReader(readmode = "bytes", **rateargs):
    """\
    FixedRateControlledReusableFileReader(readmode, rateargs) -> reusable file reader component

    A file reading component that can be reused. Based on a carousel - send a
    filename to the "next" or "inbox" inboxes to start reading from that file.

    Data is read at the specified rate.
    
    Keyword arguments:
    - readmode = "bytes" or "lines"
    - rateargs = arguments for ByteRate_RequestControl component constructor
    """
    return Graphline(RC       = ByteRate_RequestControl(**rateargs),
                     CAR      = ReusableFileReader(readmode),
                     linkages = {
                        ("self", "inbox")      : ("CAR", "next"),
                        ("self", "control")    : ("RC", "control"),
                        ("RC", "outbox")       : ("CAR", "inbox"),
                        ("RC", "signal")       : ("CAR", "control"),
                        ("CAR", "outbox")      : ("self", "outbox"),
                        ("CAR", "signal")      : ("self", "signal"),
                        ("CAR", "requestNext") : ("self", "requestNext"),
                        ("self", "next")       : ("CAR", "next")
                    }
        )
Exemple #5
0
def Pop3Proxy():
    return Graphline(SERVER=TCPClient(POP3SERVER_NAME, POP3SERVER_PORT),
                     RELAY=Pop3CommandRelay(),
                     LINESPLIT_CMDS=LineSplit(),
                     LINESPLIT_RESP=LineSplit(),
                     DELETION_STORE=SimpleCache(PERSISTENCE_STORE_FILENAME),
                     linkages={
                         ("", "inbox"): ("LINESPLIT_CMDS", "inbox"),
                         ("", "control"): ("LINESPLIT_CMDS", "control"),
                         ("LINESPLIT_CMDS", "outbox"): ("RELAY", "inbox"),
                         ("LINESPLIT_CMDS", "signal"): ("RELAY", "control"),
                         ("RELAY", "toServer"): ("SERVER", "inbox"),
                         ("RELAY", "toServerControl"): ("SERVER", "control"),
                         ("SERVER", "outbox"): ("LINESPLIT_RESP", "inbox"),
                         ("SERVER", "signal"): ("LINESPLIT_RESP", "control"),
                         ("LINESPLIT_RESP", "outbox"): ("RELAY", "fromServer"),
                         ("LINESPLIT_RESP", "signal"):
                         ("RELAY", "fromServerSignal"),
                         ("RELAY", "outbox"): ("", "outbox"),
                         ("RELAY", "signal"): ("", "signal"),
                         ("RELAY", "toStore"): ("DELETION_STORE", "inbox"),
                         ("RELAY", "toStoreControl"):
                         ("DELETION_STORE", "control"),
                         ("DELETION_STORE", "outbox"): ("RELAY", "fromStore"),
                     })
Exemple #6
0
def InactivityChassis(somecomponent, timeout=2, debug=False):
    """
    This convenience function will link a component up to an ActivityMonitor and
    a ResettableSender that will emit a producerFinished signal within timeout
    seconds if the component does not send any messages on its outbox or
    CreatorFeedback boxes.  To link the specified component to an external component
    simply link it to the returned chassis's outbox or CreatorFeedback outboxes.
    """
    linkages = {
        ("SHUTTERDOWNER", "outbox"): ("OBJ", "control"),
        ("self", "inbox"): ("OBJ", "inbox"),
        ("self", "control"): ("OBJ", "control"),
        ("self", "ReadReady"): ("OBJ", "ReadReady"),
        ("self", "SendReady"): ("OBJ", "SendReady"),
        ("OBJ", "outbox"): ("ACT", "inbox"),
        ("OBJ", "CreatorFeedback"): ("ACT", "inbox2"),
        #        ("OBJ","_selectorSignal"):("ACT","inbox3"),
        ("OBJ", "signal"): ("ACT", "control"),
        ("ACT", "observed"): ("SHUTTERDOWNER", "inbox"),
        ("ACT", "outbox"): ("self", "outbox"),
        ("ACT", "outbox2"): ("self", "CreatorFeedback"),
        #        ("ACT","outbox3"):("self","_selectorSignal"),
        ("ACT", "signal"): ("self", "signal"),
    }
    return Graphline(OBJ=somecomponent,
                     ACT=ActivityMonitor(),
                     SHUTTERDOWNER=ResettableSender(debug=debug,
                                                    message=producerFinished(),
                                                    timeout=timeout),
                     linkages=linkages)
Exemple #7
0
    def createPosts2fileManager(self, channels_plugsplitter,
                                feeds_plugsplitter, posts_plugsplitter,
                                config_plugsplitter, templateField,
                                outputFileField):
        return Graphline(
            CHANNELS_SUBSCRIBER=self.subscribeToPlugsplitter(
                channels_plugsplitter),
            FEEDS_SUBSCRIBER=self.subscribeToPlugsplitter(feeds_plugsplitter),
            POSTS_SUBSCRIBER=self.subscribeToPlugsplitter(posts_plugsplitter),
            CONFIG_SUBSCRIBER=self.subscribeToPlugsplitter(
                config_plugsplitter),
            POSTS2FILE=KamTemplateProcessor(templateField, outputFileField),
            FILE_WRITER=Carousel(SimpleFileWriter),
            linkages={
                ('FEEDS_SUBSCRIBER', 'outbox'): ('POSTS2FILE', 'feeds-inbox'),
                ('POSTS_SUBSCRIBER', 'outbox'): ('POSTS2FILE', 'posts-inbox'),
                ('CONFIG_SUBSCRIBER', 'outbox'):
                ('POSTS2FILE', 'config-inbox'),
                ('CHANNELS_SUBSCRIBER', 'outbox'):
                ('POSTS2FILE', 'channels-inbox'),
                ('POSTS2FILE', 'outbox'): ('FILE_WRITER', 'inbox'),
                ('POSTS2FILE', 'create-output'): ('FILE_WRITER', 'next'),

                # Signals
                ('POSTS_SUBSCRIBER', 'signal'): ('POSTS2FILE', 'control'),
                ('POSTS2FILE', 'signal'): ('FILE_WRITER', 'control'),
            })
Exemple #8
0
def clientconnectorwc(webcamBackplane="WEBCAM", port=1501):
    # Connects webcams to the network
    return Pipeline(
        Graphline(
            WEBCAM=FilteringPubsubBackplane(webcamBackplane),
            STRINGCONVERTER=PureTransformer(
                lambda x: pygame.image.tostring(x, "RGB")),
            SURFACECONVERTER=StringToSurface(190, 140),
            FRAMER=DataChunker(),
            CONSOLE=ConsoleEchoer(),
            DEFRAMER=DataDeChunker(),
            SIZER=PureTransformer(
                lambda x: pygame.transform.scale(x, (190, 140))
            ),  # This is a temporary fix - we should really be sending full resolution images
            # The issue is that to do this we need to send the original size as metadata and this needs more work to include
            linkages={
                # Receive data from the network - deframe and convert to image for display
                ("self", "inbox"): ("DEFRAMER", "inbox"),
                ("DEFRAMER", "outbox"): ("SURFACECONVERTER", "inbox"),
                # Send to display
                ("SURFACECONVERTER", "outbox"): ("WEBCAM", "inbox"),
                # Forward local images to the network - convert to strings and frame
                ("WEBCAM", "outbox"): ("SIZER", "inbox"),
                ("SIZER", "outbox"): ("STRINGCONVERTER", "inbox"),
                ("STRINGCONVERTER", "outbox"): ("FRAMER", "inbox"),
                # Send to network
                ("FRAMER", "outbox"): ("self", "outbox"),
            },
        ), )
Exemple #9
0
def HTTPServer(createRequestHandler, **argd):
    """\
    HTTPServer() -> new HTTPServer component capable of handling a single connection

    Arguments:
       -- createRequestHandler - a function required by HTTPRequestHandler that
                                 creates the appropriate request-handler component
                                 for each request, see HTTPResourceGlue
    """
    return Graphline(
        PARSER=HTTPParser(**argd),  # Since this is where the data goes first!
        HANDLER=HTTPRequestHandler(createRequestHandler),
        CORELOGIC=HTTPShutdownLogicHandling(),
        linkages={
            # Data Handling
            ("self", "inbox"): ("PARSER", "inbox"),
            ("PARSER", "outbox"): ("HANDLER", "inbox"),
            ("HANDLER", "outbox"): ("self", "outbox"),

            # Signalling Handling
            ("self", "control"): ("CORELOGIC", "control"),
            ("CORELOGIC", "Psignal"): ("PARSER", "control"),
            ("CORELOGIC", "Hsignal"): ("HANDLER", "control"),
            ("CORELOGIC", "signal"): ("self", "signal"),
            ("PARSER", "signal"): ("CORELOGIC", "Pcontrol"),
            ("HANDLER", "signal"): ("CORELOGIC", "Hcontrol"),
        })
Exemple #10
0
def NetworkLinkage(ip1, port1, ip2, port2):
    return Graphline(PIPE=Pipeline(
        TCPClient(ip1, port1),
        TCPClient(ip2, port2),
    ),
                     linkages={
                         ("PIPE", "outbox"): ("PIPE", "inbox"),
                         ("PIPE", "signal"): ("PIPE", "control"),
                     })
Exemple #11
0
def repeatingFile():
    def rfa_factory(_):
        return RateControlledFileReader("junction.ts",readmode="bytes",rate=18000000/8,chunksize=2048)
    return Graphline(CAROUSEL=Carousel(rfa_factory, make1stRequest=True),
                     linkages = { ("CAROUSEL","requestNext") : ("CAROUSEL","next"),
                                  ("CAROUSEL","outbox") : ("self", "outbox"),
                                  ("CAROUSEL","signal") : ("self", "signal"),
                                },
                    )
Exemple #12
0
def JSONProtocol(*argv, **argd):
    return Graphline(
        SPLITTER=JSONSplitter(),
        #CE = ConsoleEchoer(),
        SERVER=JSONHandler(),

        linkages={("self", "inbox"): ("SPLITTER", "inbox"),
                  ("SPLITTER", "outbox"): ("SERVER", "protocolin"),
                  ("SERVER", "protocolout"): ("self", "outbox")}

    )
Exemple #13
0
def SimpleAIMClient(screenname, password):
    return Graphline(
           LOGIC = SimpleResponder(),
           PROTO = AIMHarness(screenname, password),
#           PROTO = FAKE_AIM(),
           linkages = {
               ("LOGIC","outbox"): ("PROTO","inbox"),
               ("LOGIC","signal"): ("PROTO","control"),
               ("PROTO","outbox"): ("LOGIC","inbox"),
               ("PROTO","signal"): ("LOGIC","control"),
           }
    )
Exemple #14
0
def AIMBotServerCore(screenname, password, protocol):
    print "ULTRABOT STARTING UP"
    print "For the moment, ultrabot may not say anything when it's told anything"

    return Graphline(
               AIM = AIMHarness(screenname, password),
               ADAPTER = MessageDemuxer(ignore_first=True,
                                        protocol=protocol),
               linkages = {               
                   ("AIM", "outbox"): ("ADAPTER","inbox"),
                   ("ADAPTER","outbox"):  ("AIM", "inbox"),
               }
           )
Exemple #15
0
def UltraBot(screenname, password):
    print "ULTRABOT STARTING UP"
    print "For the moment, ultrabot may not say anything when it's told anything"

    return Graphline(AIM=AIMHarness(screenname, password),
                     ADAPTER=AIMUserTalkAdapter(),
                     USER=ConsoleUser(),
                     linkages={
                         ("AIM", "outbox"): ("ADAPTER", "from_aim"),
                         ("USER", "outbox"): ("ADAPTER", "from_user"),
                         ("ADAPTER", "to_aim"): ("AIM", "inbox"),
                         ("ADAPTER", "to_user"): ("USER", "inbox"),
                     })
Exemple #16
0
def LocalPagingControls(left, top):
    return Graphline(REMOTEPREV=Button(caption="~~<<~~",
                                       size=(63, 32),
                                       position=(left, top),
                                       msg=[['prev']]),
                     REMOTENEXT=Button(caption="~~>>~~",
                                       size=(63, 32),
                                       position=(left + 64, top),
                                       msg=[['next']]),
                     linkages={
                         ("REMOTEPREV", "outbox"): ("self", "outbox"),
                         ("REMOTENEXT", "outbox"): ("self", "outbox"),
                     })
Exemple #17
0
def Logger(channel, formatter=None, name=None, logdir=None, **irc_args):
    return Graphline(irc = SimpleIRCClientPrefab(**irc_args),
                     logger = BasicLogger(channel),
                     log = Carousel(SimpleFileWriter),
                     info = Carousel(SimpleFileWriter),
                     linkages = {("logger", "irc") : ("irc", "inbox"),
                                 ("irc", "outbox") : ("logger", "inbox"),
                                 ("logger", "log_next") : ("log", "next"),
                                 ("logger", "outbox") : ("log", "inbox"),
                                 ("logger", "info_next") : ("info", "next"),
                                 ("logger", "system") : ("info", "inbox"),
                                }
                     ) 
Exemple #18
0
        def __init__(self, jid, password, hostname='localhost', port=5222, tls=False, registercls=None):
            super(KamaeliaClient, self).__init__()
            BaseClient.__init__(self, jid, password, tls, registercls)

            self.graph = Graphline(client = self,
                                   tcp = KTCPClient(hostname, port),
                                   linkages = {('client', 'outbox'): ('tcp', 'inbox'),
                                               ("tcp", "outbox") : ("client", "inbox"),
                                               ("tcp", "signal") : ("client", "tcp-control"),
                                               ("client", "starttls") : ("tcp", "makessl"),
                                               ("tcp", "sslready") : ("client", "tlssuccess")})
            self.addChildren(self.graph)
            self.link((self, 'signal'), (self.graph, 'control'))
Exemple #19
0
def Receiver(frequency, feparams, card=0):
    return Graphline(
        TUNER=Tuner(frequency, feparams, card),
        DEMUX=DemuxerService(),
        linkages={
            ("self", "inbox"): ("DEMUX", "request"),
            ("DEMUX", "pid_request"): ("TUNER", "inbox"),
            ("TUNER", "outbox"): ("DEMUX", "inbox"),

            # propagate shutdown messages
            ("self", "control"): ("TUNER", "control"),
            ("TUNER", "signal"): ("DEMUX", "control"),
            ("DEMUX", "signal"): ("self", "signal"),
        })
Exemple #20
0
def Logger():
    return Graphline(irc = SimpleIRCClientPrefab(host="irc.freenode.net", nick="jinnaslogbot", \
                                               defaultChannel=channel),
                   formatter = IRCFormatter("jinnaslogbot", channel),
                   log = SimpleFileWriter("%s%i.log" % (channel[1:], time.time())),
                   info = SimpleFileWriter("%s%i.info" % (channel[1:], time.time())),
                   linkages = {("irc" , "outbox") : ("formatter", "inbox"),
                               ("irc", "signal") : ("formatter", "control"),
                               ("formatter", "outbox") : ("log", "inbox"),
                               ("formatter", "system") : ("info", "inbox"),
                               ("formatter", "signal") : ("log", "control"),
                               ("log", "signal") : ("info", "control"),
                               }
                     )