Changeset - 70d45c584776
[Not reviewed]
default
0 1 0
drewp - 21 years ago 2004-06-15 02:06:36

minor old changes
1 file changed with 8 insertions and 6 deletions:
0 comments (0 inline, 0 general)
light8/dmxserver.py
Show inline comments
 
@@ -23,13 +23,13 @@ todo:
 
"""
 

	
 
from __future__ import division
 
from twisted.internet import reactor
 
from twisted.web import xmlrpc, server
 
import sys,time
 
from optik import OptionParser
 
from optparse import OptionParser
 
from io import ParportDMX
 
from updatefreq import Updatefreq
 

	
 
class XMLRPCServe(xmlrpc.XMLRPC):
 
    def __init__(self,options):
 

	
 
@@ -60,27 +60,29 @@ class XMLRPCServe(xmlrpc.XMLRPC):
 

	
 
        # the other loop
 
        self.purgeclients()
 
        
 
    def purgeclients(self):
 
        
 
        """forget about any clients who haven't sent levels in a while
 
        (5 seconds). this runs in a loop"""
 
        """forget about any clients who haven't sent levels in a while.
 
        this runs in a loop"""
 

	
 
        purge_age=10 # seconds
 
        
 
        reactor.callLater(1,self.purgeclients)
 

	
 
        now=time.time()
 
        for cid,lastseen in self.lastseen.items():
 
        cids=self.clientlevels.keys()
 
        for cid in cids:
 
            lastseen=self.lastseen[cid]
 
            if lastseen<now-purge_age:
 
                print ("forgetting client %s (no activity for %s sec)" %
 
                       (cid,purge_age))
 
                del self.clientlevels[cid]
 
                del self.clientfreq[cid]
 
                del self.lastseen[cid]
 
                del self.clientfreq[cid]
 
        
 
    def sendlevels(self):
 
        
 
        """sends to dmx if levels have changed, or if we havent sent
 
        in a while"""
 

	
 
@@ -150,13 +152,13 @@ class XMLRPCServe(xmlrpc.XMLRPC):
 
    def xmlrpc_echo(self,x):
 
        return x
 
    
 
    def xmlrpc_outputlevels(self,cid,levellist):
 
        """send a unique id for your client (name+pid maybe), then
 
        the variable-length dmx levellist (scaled 0..1)"""
 
        if levellist!=self.clientlevels.get(cid,[]):
 
        if levellist!=self.clientlevels.get(cid,None):
 
            self.clientlevels[cid]=levellist
 
            self.clientschanged=1
 
            if cid not in self.lastseen:
 
                print "hello new client %s" % cid
 
                self.clientfreq[cid]=Updatefreq()
 
                
0 comments (0 inline, 0 general)