Author: duncan
Date: Tue Jan 23 21:00:02 2007
New Revision: 9050

Modified:
   branches/rel-1/freevo/freevo_config.py
   branches/rel-1/freevo/local_conf.py.example
   branches/rel-1/freevo/src/rc.py

Log:
[ 1642393 ] TcpNetwork
Patch from Mathias Weber applied


Modified: branches/rel-1/freevo/freevo_config.py
==============================================================================
--- branches/rel-1/freevo/freevo_config.py      (original)
+++ branches/rel-1/freevo/freevo_config.py      Tue Jan 23 21:00:02 2007
@@ -1869,6 +1869,14 @@
 REMOTE_CONTROL_HOST = '127.0.0.1'
 REMOTE_CONTROL_PORT = 16310
 
+#
+# Remote control daemon. Similar to the one above, but uses TCP instead 
+# of UDP. It is possible to send commands with a telnet client.
+#
+ENABLE_TCP_NETWORK_REMOTE = 0
+REMOTE_CONTROL_TCP_HOST = '127.0.0.1'
+REMOTE_CONTROL_TCP_PORT = 16311
+
 
 #
 # XMLTV File

Modified: branches/rel-1/freevo/local_conf.py.example
==============================================================================
--- branches/rel-1/freevo/local_conf.py.example (original)
+++ branches/rel-1/freevo/local_conf.py.example Tue Jan 23 21:00:02 2007
@@ -1481,6 +1481,15 @@
 
 
 #
+# Remote control daemon. Similar to the one above, but uses TCP instead 
+# of UDP. It is possible to send commands with a telnet client.
+#
+# ENABLE_TCP_NETWORK_REMOTE = 0
+# REMOTE_CONTROL_TCP_HOST = '127.0.0.1'
+# REMOTE_CONTROL_TCP_PORT = 16311
+
+
+#
 # XMLTV File
 #
 # This is the XMLTV file that can be optionally used for TV listings

Modified: branches/rel-1/freevo/src/rc.py
==============================================================================
--- branches/rel-1/freevo/src/rc.py     (original)
+++ branches/rel-1/freevo/src/rc.py     Tue Jan 23 21:00:02 2007
@@ -274,6 +274,62 @@
 
 # 
--------------------------------------------------------------------------------
 
+class TcpNetwork:
+    """
+    Class to handle network control via TCP connection instead of UDP.
+    """
+    import socket
+    MAX_MESSAGE_SIZE = 255 # the maximum size of a message
+    def __init__(self):
+        """
+        init the network event handler
+        """
+        self.port = config.REMOTE_CONTROL_TCP_PORT
+        self.host = config.REMOTE_CONTROL_TCP_HOST
+        self.sock = self.socket.socket(self.socket.AF_INET, \
+                self.socket.SOCK_STREAM)
+        self.sock.setsockopt(self.socket.SOL_SOCKET, \
+                self.socket.SO_REUSEADDR, 1)
+        self.sock.setblocking(0)
+        self.sock.bind((self.host, self.port))
+        self.sock.listen(1)
+        self.connections = []
+
+    def poll(self, rc):
+        """
+        return next event
+        """
+        self._getNewConnections()
+
+        throwout = []
+        for conn in self.connections:
+            try:
+                buffer = conn.recv(self.MAX_MESSAGE_SIZE)
+                return buffer.strip()
+            except self.socket.error, oErr:
+                # if the error is not of typ 11 there is a problem with
+                # the connection, remove it from the list.
+                if oErr[0] != 11:
+                    throwout.append(self.connections.index(conn))
+
+        throwout.reverse()
+        for index in throwout:
+            self.connections.pop(index)
+
+    def _getNewConnections(self):
+        """
+        accept new connections from the socket
+        """
+        try:
+            conn, addr = self.sock.accept()
+            conn.setblocking(0)
+            self.connections.append(conn)
+        except:
+            # do nothing
+            pass
+
+
+
 class Network:
     """
     Class to handle network control
@@ -407,6 +463,11 @@
                config.REMOTE_CONTROL_PORT:
             self.inputs.append(Network())
 
+        if use_netremote and config.ENABLE_TCP_NETWORK_REMOTE and \
+               config.REMOTE_CONTROL_TCP_PORT and \
+               config.REMOTE_CONTROL_TCP_HOST:
+            self.inputs.append(TcpNetwork())
+
         self.app                = None
         self.context            = 'menu'
         self.queue              = []

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to