Exemple #1
0
    def clientconnector():
        return Pipeline(
            chunks_to_lines(),
            lines_to_tokenlists(),
            Graphline(
                WHITEBOARD=FilterAndTagWrapper(
                    Pipeline(
                        publishTo(whiteboardBackplane),
                        # well, should be to separate pipelines, this is lazier!
                        subscribeTo(whiteboardBackplane),
                    )),
                AUDIO=Pipeline(
                    SimpleDetupler(1),  # remove 'SOUND' tag
                    SpeexDecode(3),
                    FilterAndTagWrapperKeepingTag(
                        Pipeline(
                            publishTo(audioBackplane),
                            # well, should be to separate pipelines, this is lazier!
                            subscribeTo(audioBackplane),
                        ), ),
                    RawAudioMixer(),
                    SpeexEncode(3),
                    Entuple(prefix=["SOUND"], postfix=[]),
                ),
                ROUTER=Router(
                    ((lambda tuple: tuple[0] == "SOUND"), "audio"),
                    ((lambda tuple: tuple[0] != "SOUND"), "whiteboard"),
                ),
                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, backplane="WHITEBOARD"):
    # plug a TCPClient into the backplae
    from Kamaelia.Internet.TCPClient import TCPClient

    loadingmsg = "Fetching sketch from server..."

    return Pipeline(
        subscribeTo(backplane),
        TagAndFilterWrapper(
            Graphline(
                GETIMG=OneShot(msg=[["GETIMG"]]),
                PIPE=Pipeline(
                    tokenlists_to_lines(),
                    TCPClient(host=rhost, port=rport),
                    chunks_to_lines(),
                    lines_to_tokenlists(),
                ),
                BLACKOUT=OneShot(
                    msg=[["CLEAR", 0, 0, 0],
                         ["WRITE", 100, 100, 24, 255, 255, 255, loadingmsg]]),
                linkages={
                    ("self", "inbox"): ("PIPE", "inbox"),
                    ("self", "control"): ("PIPE", "control"),
                    ("PIPE", "outbox"): ("self", "outbox"),
                    ("PIPE", "signal"): ("self", "signal"),
                    ("GETIMG", "outbox"): ("PIPE", "inbox"),
                    ("BLACKOUT", "outbox"): ("self", "outbox"),
                },
            )),
        publishTo(backplane),
    )  #.activate()
Exemple #3
0
def EventServerClients(rhost, rport, backplane="WHITEBOARD"):
        # plug a TCPClient into the backplae
        from Kamaelia.Internet.TCPClient import TCPClient

        loadingmsg = "Fetching sketch from server..."

        return pipeline( subscribeTo(backplane),
                         TagAndFilterWrapper(
                         Graphline( GETIMG = OneShot(msg=[["GETIMG"]]),
                                    PIPE = pipeline(
                                            tokenlists_to_lines(),
                                            TCPClient(host=rhost,port=rport),
                                            chunks_to_lines(),
                                            lines_to_tokenlists(),
                                        ),
                                    BLACKOUT = OneShot(msg=[["CLEAR",0,0,0],["WRITE",100,100,24,255,255,255,loadingmsg]]),
                                    linkages = { ("self","inbox") : ("PIPE","inbox"),
                                                 ("self","control") : ("PIPE","control"),
                                                 ("PIPE","outbox") : ("self","outbox"),
                                                 ("PIPE","signal") : ("self","signal"),
                                                 ("GETIMG","outbox") : ("PIPE","inbox"),
                                                 ("BLACKOUT","outbox") : ("self","outbox"),
                                               },
                                  )
                         ),
                         publishTo(backplane),
                       ) #.activate()
Exemple #4
0
 def clientconnector():
     return Pipeline(
         chunks_to_lines(),
         lines_to_tokenlists(),
         Graphline(
             WHITEBOARD = FilterAndTagWrapper(
                 Pipeline( publishTo(whiteboardBackplane),
                           # well, should be to separate pipelines, this is lazier!
                           subscribeTo(whiteboardBackplane),
                         )),
             AUDIO = Pipeline(
                 SimpleDetupler(1),     # remove 'SOUND' tag
                 SpeexDecode(3),
                 FilterAndTagWrapperKeepingTag(
                     Pipeline( publishTo(audioBackplane),
                                 # well, should be to separate pipelines, this is lazier!
                             subscribeTo(audioBackplane),
                             ),
                     ),
                 RawAudioMixer(),
                 SpeexEncode(3),
                 Entuple(prefix=["SOUND"],postfix=[]),
                 ),
             ROUTER = Router( ((lambda tuple : tuple[0]=="SOUND"), "audio"),
                              ((lambda tuple : tuple[0]!="SOUND"), "whiteboard"),
                            ),
             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 #5
0
 def clientconnector():
     return Pipeline(
         chunks_to_lines(),
         lines_to_tokenlists(),
         FilterAndTagWrapper(
             Pipeline(
                 publishTo(backplane),
                 # well, should be to separate pipelines, this is lazier!
                 subscribeTo(backplane),
             )),
         tokenlists_to_lines(),
     )
Exemple #6
0
 def clientconnector():
     return pipeline(
         chunks_to_lines(),
         lines_to_tokenlists(),
         FilterAndTagWrapper(
             pipeline( publishTo(backplane),
                         # well, should be to separate pipelines, this is lazier!
                       subscribeTo(backplane),
                     )
             ),
         tokenlists_to_lines(),
         )
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Splitting server. This expects a single inbound connection on one port and spits it out to all recipients who connect on another port. This can be
used as an alternate server for the TCPRelayMulticast to connect to, and
it would expect to be fed using MulticastTCPClientRelay.

"""

from Kamaelia.Util.Backplane import Backplane, publishTo, subscribeTo
from Kamaelia.Util.PipelineComponent import pipeline
from Kamaelia.SimpleServerComponent import SimpleServer
from Kamaelia.SingleServer import SingleServer
from config import tcp_tcp_splitter_port, tcp_splitter_client_port

p = Backplane("Splitting").activate()

pipeline(
    SingleServer(tcp_tcp_splitter_port),
    publishTo("Splitting"),
).activate()


def SubscribeToSplitData():  # Protocol handler for each connected client
    return subscribeTo("Splitting")


SimpleServer(SubscribeToSplitData, tcp_splitter_client_port).run()
Exemple #8
0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
This is a simple proxy to relay multicast data from a given multicast
group and port as a TCP Service on a given port. It's worth noting that
this is one way - any data from the TCP connection is discarded.
"""

from Kamaelia.Util.Backplane import Backplane, publishTo, subscribeTo
from Kamaelia.Internet.Multicast_transceiver import Multicast_transceiver
from Kamaelia.Util.PipelineComponent import pipeline
from config import mcast_group, mcast_port, mcast_tcp_splitter_port

p = Backplane("MulticastProxy").activate()

pipeline(
    Multicast_transceiver("0.0.0.0", mcast_port, mcast_group, 0),
    publishTo("MulticastProxy"),
).activate()


def RelayMulticastData():  # Protocol handler for each connected client
    return subscribeTo("MulticastProxy")


SimpleServer(RelayMulticastData, mcast_tcp_splitter_port).run()
Exemple #9
0
        },
    )

mainsketcher = \
    Graphline( SKETCHER = makeBasicSketcher(width=1024,height=768),
               CONSOLE = Pipeline(ConsoleReader(),text_to_tokenlists(),parseCommands()),

               linkages = { ('self','inbox'):('SKETCHER','inbox'),
                            ('SKETCHER','outbox'):('self','outbox'),
                            ('CONSOLE','outbox'):('SKETCHER','inbox'),
                          }
                 )

# primary whiteboard
Pipeline(subscribeTo("WHITEBOARD"), TagAndFilterWrapper(mainsketcher),
         publishTo("WHITEBOARD")).activate()

if __name__ == "__main__":
    import sys, getopt, re

    rhost, rport, serveport = parseOptions()

    # setup a server, if requested
    if serveport:
        LocalEventServer("WHITEBOARD", port=serveport).activate()

    # connect to remote host & port, if requested
    if rhost and rport:
        EventServerClients(rhost, rport, "WHITEBOARD").activate()

    Backplane("WHITEBOARD").run()
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Splitting server. This expects a single inbound connection on one port and spits it out to all recipients who connect on another port. This can be
used as an alternate server for the TCPRelayMulticast to connect to, and
it would expect to be fed using MulticastTCPClientRelay.

"""

from Kamaelia.Util.Backplane import Backplane, publishTo, subscribeTo
from Kamaelia.Util.PipelineComponent import pipeline
from Kamaelia.SimpleServerComponent import SimpleServer
from Kamaelia.SingleServer import SingleServer
from config import tcp_tcp_splitter_port, tcp_splitter_client_port

p = Backplane("Splitting").activate()

pipeline(SingleServer(tcp_tcp_splitter_port), publishTo("Splitting")).activate()


def SubscribeToSplitData():  # Protocol handler for each connected client
    return subscribeTo("Splitting")


SimpleServer(SubscribeToSplitData, tcp_splitter_client_port).run()
Exemple #11
0
                    )

mainsketcher = \
    Graphline( SKETCHER = makeBasicSketcher(width=1024,height=768),
               CONSOLE = pipeline(ConsoleReader(),text_to_tokenlists(),parseCommands()),

               linkages = { ('self','inbox'):('SKETCHER','inbox'),
                            ('SKETCHER','outbox'):('self','outbox'),
                            ('CONSOLE','outbox'):('SKETCHER','inbox'),
                          }
                 )

# primary whiteboard
pipeline( subscribeTo("WHITEBOARD"),
          TagAndFilterWrapper(mainsketcher),
          publishTo("WHITEBOARD")
        ).activate()

if __name__=="__main__":
    import sys, getopt, re

    rhost, rport, serveport = parseOptions()

    # setup a server, if requested
    if serveport:
        LocalEventServer("WHITEBOARD", port=serveport).activate()

    # connect to remote host & port, if requested
    if rhost and rport:
        EventServerClients(rhost, rport, "WHITEBOARD").activate()
Exemple #12
0
def EventServerClients(rhost,
                       rport,
                       whiteboardBackplane="WHITEBOARD",
                       audioBackplane="AUDIO"):
    # plug a TCPClient into the backplae
    from Kamaelia.Internet.TCPClient import TCPClient
    from Kamaelia.Chassis.Carousel import Carousel

    loadingmsg = "Fetching sketch from server..."

    failuremsg = "FAILED: Couldn't connect to server:"
    failuremsg2 = str(rhost) + " on port " + str(rport)

    return Graphline(
        NETWORK=Graphline(
            PIPE=Pipeline(
                tokenlists_to_lines(),
                TCPClient(host=rhost, port=rport),
                chunks_to_lines(),
                lines_to_tokenlists(),
            ),
            SHUTDOWN=TriggeredOneShot(msg=shutdownMicroprocess()),
            linkages={
                ("", "inbox"): ("PIPE", "inbox"),
                ("PIPE", "outbox"): ("", "outbox"),

                # shutdown stuff - TCPClient may have caused it, so need to
                # loop the shutdown message back round to the front of the pipe
                # as well as propagating it onwards
                ("", "control"): ("PIPE", "control"),
                ("PIPE", "signal"): ("SHUTDOWN", "inbox"),
                ("SHUTDOWN", "outbox"): ("PIPE", "control"),
                ("SHUTDOWN", "signal"): ("", "signal"),
            }),
        ROUTER=Router(
            ((lambda tuple: tuple[0] == "SOUND"), "audio"),
            ((lambda tuple: tuple[0] != "SOUND"), "whiteboard"),
        ),
        WHITEBOARD=FilterAndTagWrapper(
            Pipeline(
                publishTo(whiteboardBackplane),
                #
                subscribeTo(whiteboardBackplane),
            )),
        AUDIO=Pipeline(
            SimpleDetupler(1),  # remove 'SOUND' tag
            SpeexDecode(3),
            FilterAndTagWrapperKeepingTag(
                Pipeline(
                    publishTo(audioBackplane),
                    #
                    subscribeTo(audioBackplane),
                ), ),
            RawAudioMixer(),
            SpeexEncode(3),
            Entuple(prefix=["SOUND"], postfix=[]),
        ),
        GETIMG=OneShot(msg=[["GETIMG"]]),
        BLACKOUT=OneShot(
            msg=[["CLEAR", 0, 0, 0],
                 ["WRITE", 100, 100, 24, 255, 255, 255, loadingmsg]]),
        FAILURE=TriggeredOneShot(
            msg=[["WRITE", 100, 200, 32, 255, 96, 96, failuremsg],
                 ["WRITE", 100, 232, 24, 255, 160, 160, failuremsg2]]),
        linkages={
            # incoming messages from network connection go to a router
            ("NETWORK", "outbox"): ("ROUTER", "inbox"),

            # distribute messages to appropriate destinations
            ("ROUTER", "audio"): ("AUDIO", "inbox"),
            ("ROUTER", "whiteboard"): ("WHITEBOARD", "inbox"),

            # aggregate all output, and send across the network connection
            ("AUDIO", "outbox"): ("NETWORK", "inbox"),
            ("WHITEBOARD", "outbox"): ("NETWORK", "inbox"),

            # initial messages sent to the server, and the local whiteboard
            ("GETIMG", "outbox"): ("NETWORK", "inbox"),
            ("BLACKOUT", "outbox"): ("WHITEBOARD", "inbox"),

            # shutdown routing, not sure if this will actually work, but hey!
            ("NETWORK", "signal"): ("FAILURE", "inbox"),
            ("FAILURE", "outbox"): ("WHITEBOARD", "inbox"),
            ("FAILURE", "signal"): ("ROUTER", "control"),
            ("ROUTER", "signal"): ("AUDIO", "control"),
            ("AUDIO", "signal"): ("WHITEBOARD", "control"),
            ("WHITEBOARD", "signal"): ("", "signal"),
        })
Exemple #13
0
mainsketcher = \
    Graphline( SKETCHER = makeBasicSketcher(width=1024,height=768),
               CONSOLE = Pipeline(ConsoleReader(),text_to_tokenlists(),parseCommands()),

               linkages = { ('self','inbox'):('SKETCHER','inbox'),
                            ('SKETCHER','outbox'):('self','outbox'),
                            ('CONSOLE','outbox'):('SKETCHER','inbox'),
                          }
                 )

if __name__ == "__main__":

    # primary whiteboard
    Pipeline(subscribeTo("WHITEBOARD"), TagAndFilterWrapper(mainsketcher),
             publishTo("WHITEBOARD")).activate()

    # primary sound IO - tagged and filtered, so can't hear self
    Pipeline(
        subscribeTo("AUDIO"),
        TagAndFilterWrapperKeepingTag(
            Pipeline(
                RawAudioMixer(),
                #                      PackageData(channels=1,sample_rate=8000,format="S16_LE"),
                SoundOutput(),
                ######
                SoundInput(),
                #                      ExtractData(),
            ), ),
        publishTo("AUDIO"),
    ).activate()
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
This is a simple proxy to relay multicast data from a given multicast
group and port as a TCP Service on a given port. It's worth noting that
this is one way - any data from the TCP connection is discarded.
"""

from Kamaelia.Util.Backplane import Backplane, publishTo, subscribeTo
from Kamaelia.Internet.Multicast_transceiver import Multicast_transceiver
from Kamaelia.Util.PipelineComponent import pipeline
from config import mcast_group, mcast_port, mcast_tcp_splitter_port

p = Backplane("MulticastProxy").activate()


pipeline(
   Multicast_transceiver("0.0.0.0", mcast_port, mcast_group, 0),
   publishTo("MulticastProxy"),
).activate()

def RelayMulticastData(): # Protocol handler for each connected client
     return subscribeTo("MulticastProxy")

SimpleServer( RelayMulticastData, mcast_tcp_splitter_port).run()
Exemple #15
0
def EventServerClients(rhost, rport, whiteboardBackplane="WHITEBOARD", audioBackplane="AUDIO"):
        # plug a TCPClient into the backplae
        from Kamaelia.Internet.TCPClient import TCPClient
        from Kamaelia.Chassis.Carousel import Carousel

        loadingmsg = "Fetching sketch from server..."
        
        failuremsg  = "FAILED: Couldn't connect to server:"
        failuremsg2 = str(rhost)+" on port "+str(rport)

        return Graphline(
                NETWORK = Graphline(
                    PIPE = Pipeline(
                        tokenlists_to_lines(),
                        TCPClient(host=rhost,port=rport),
                        chunks_to_lines(),
                        lines_to_tokenlists(),
                        ),
                    SHUTDOWN = TriggeredOneShot(msg=shutdownMicroprocess()),
                    linkages = {
                        ("",     "inbox")  : ("PIPE", "inbox"),
                        ("PIPE", "outbox") : ("", "outbox"),
                        
                        # shutdown stuff - TCPClient may have caused it, so need to
                        # loop the shutdown message back round to the front of the pipe
                        # as well as propagating it onwards
                        ("",         "control") : ("PIPE",     "control"),
                        ("PIPE",     "signal")  : ("SHUTDOWN", "inbox"),
                        ("SHUTDOWN", "outbox")  : ("PIPE",     "control"),
                        ("SHUTDOWN", "signal")  : ("",         "signal"),
                    }
                ),
                ROUTER = Router( ((lambda tuple : tuple[0]=="SOUND"), "audio"),
                                 ((lambda tuple : tuple[0]!="SOUND"), "whiteboard"),
                               ),
                WHITEBOARD = FilterAndTagWrapper(
                    Pipeline(
                        publishTo(whiteboardBackplane),
                        #
                        subscribeTo(whiteboardBackplane),
                    )
                ),
                AUDIO = Pipeline(
                    SimpleDetupler(1),     # remove 'SOUND' tag
                    SpeexDecode(3),
                    FilterAndTagWrapperKeepingTag(
                        Pipeline(
                            publishTo(audioBackplane),
                            #
                            subscribeTo(audioBackplane),
                        ),
                    ),
                    RawAudioMixer(),
                    SpeexEncode(3),
                    Entuple(prefix=["SOUND"],postfix=[]),
                ),
                GETIMG = OneShot(msg=[["GETIMG"]]),
                BLACKOUT = OneShot(msg=[["CLEAR",0,0,0],["WRITE",100,100,24,255,255,255,loadingmsg]]),
                FAILURE = TriggeredOneShot(msg=[["WRITE", 100,200, 32, 255, 96, 96, failuremsg],
                                                ["WRITE", 100,232, 24, 255,160,160, failuremsg2]]), 
                
                linkages = {
                    # incoming messages from network connection go to a router
                    ("NETWORK", "outbox") : ("ROUTER", "inbox"),
                    
                    # distribute messages to appropriate destinations
                    ("ROUTER", "audio")      : ("AUDIO",      "inbox"),
                    ("ROUTER", "whiteboard") : ("WHITEBOARD", "inbox"),
                    
                    # aggregate all output, and send across the network connection
                    ("AUDIO",      "outbox") : ("NETWORK", "inbox"),
                    ("WHITEBOARD", "outbox") : ("NETWORK", "inbox"),
                    
                    # initial messages sent to the server, and the local whiteboard
                    ("GETIMG",   "outbox") : ("NETWORK",    "inbox"),
                    ("BLACKOUT", "outbox") : ("WHITEBOARD", "inbox"),
                    
                    # shutdown routing, not sure if this will actually work, but hey!
                    ("NETWORK", "signal") : ("FAILURE", "inbox"),
                    ("FAILURE", "outbox") : ("WHITEBOARD", "inbox"),
                    ("FAILURE",    "signal") : ("ROUTER",     "control"),
                    ("ROUTER",     "signal") : ("AUDIO",      "control"),
                    ("AUDIO",      "signal") : ("WHITEBOARD", "control"),
                    ("WHITEBOARD", "signal") : ("",           "signal"),
                }
            )
Exemple #16
0
               CONSOLE = Pipeline(ConsoleReader(),text_to_tokenlists(),parseCommands()),

               linkages = { ('self','inbox'):('SKETCHER','inbox'),
                            ('SKETCHER','outbox'):('self','outbox'),
                            ('CONSOLE','outbox'):('SKETCHER','inbox'),
                          }
                 )



if __name__=="__main__":
    
    # primary whiteboard
    Pipeline( subscribeTo("WHITEBOARD"),
            TagAndFilterWrapper(mainsketcher),
            publishTo("WHITEBOARD")
            ).activate()
            
    # primary sound IO - tagged and filtered, so can't hear self
    Pipeline( subscribeTo("AUDIO"),
              TagAndFilterWrapperKeepingTag(
                  Pipeline(
                      RawAudioMixer(),
#                      PackageData(channels=1,sample_rate=8000,format="S16_LE"),
                      SoundOutput(),
                      ######
                      SoundInput(),
#                      ExtractData(),
                  ),
              ),
              publishTo("AUDIO"),