comparison light8/dmxserver.py @ 194:70d45c584776

minor old changes
author drewp
date Tue, 15 Jun 2004 02:06:36 +0000
parents 8e6165bc1ca5
children cde2ae379be0
comparison
equal deleted inserted replaced
193:e16b8ca470d8 194:70d45c584776
24 24
25 from __future__ import division 25 from __future__ import division
26 from twisted.internet import reactor 26 from twisted.internet import reactor
27 from twisted.web import xmlrpc, server 27 from twisted.web import xmlrpc, server
28 import sys,time 28 import sys,time
29 from optik import OptionParser 29 from optparse import OptionParser
30 from io import ParportDMX 30 from io import ParportDMX
31 from updatefreq import Updatefreq 31 from updatefreq import Updatefreq
32 32
33 class XMLRPCServe(xmlrpc.XMLRPC): 33 class XMLRPCServe(xmlrpc.XMLRPC):
34 def __init__(self,options): 34 def __init__(self,options):
61 # the other loop 61 # the other loop
62 self.purgeclients() 62 self.purgeclients()
63 63
64 def purgeclients(self): 64 def purgeclients(self):
65 65
66 """forget about any clients who haven't sent levels in a while 66 """forget about any clients who haven't sent levels in a while.
67 (5 seconds). this runs in a loop""" 67 this runs in a loop"""
68 68
69 purge_age=10 # seconds 69 purge_age=10 # seconds
70 70
71 reactor.callLater(1,self.purgeclients) 71 reactor.callLater(1,self.purgeclients)
72 72
73 now=time.time() 73 now=time.time()
74 for cid,lastseen in self.lastseen.items(): 74 cids=self.clientlevels.keys()
75 for cid in cids:
76 lastseen=self.lastseen[cid]
75 if lastseen<now-purge_age: 77 if lastseen<now-purge_age:
76 print ("forgetting client %s (no activity for %s sec)" % 78 print ("forgetting client %s (no activity for %s sec)" %
77 (cid,purge_age)) 79 (cid,purge_age))
78 del self.clientlevels[cid] 80 del self.clientlevels[cid]
81 del self.clientfreq[cid]
79 del self.lastseen[cid] 82 del self.lastseen[cid]
80 del self.clientfreq[cid]
81 83
82 def sendlevels(self): 84 def sendlevels(self):
83 85
84 """sends to dmx if levels have changed, or if we havent sent 86 """sends to dmx if levels have changed, or if we havent sent
85 in a while""" 87 in a while"""
151 return x 153 return x
152 154
153 def xmlrpc_outputlevels(self,cid,levellist): 155 def xmlrpc_outputlevels(self,cid,levellist):
154 """send a unique id for your client (name+pid maybe), then 156 """send a unique id for your client (name+pid maybe), then
155 the variable-length dmx levellist (scaled 0..1)""" 157 the variable-length dmx levellist (scaled 0..1)"""
156 if levellist!=self.clientlevels.get(cid,[]): 158 if levellist!=self.clientlevels.get(cid,None):
157 self.clientlevels[cid]=levellist 159 self.clientlevels[cid]=levellist
158 self.clientschanged=1 160 self.clientschanged=1
159 if cid not in self.lastseen: 161 if cid not in self.lastseen:
160 print "hello new client %s" % cid 162 print "hello new client %s" % cid
161 self.clientfreq[cid]=Updatefreq() 163 self.clientfreq[cid]=Updatefreq()