def __init__(self): self.playerData = ThreadQueue() self.playerDataPump = ePythonMessagePump()
class HttpDeamon(Thread): session = None #=========================================================================== # #=========================================================================== def __init__(self): self.playerData = ThreadQueue() self.playerDataPump = ePythonMessagePump() #=========================================================================== # #=========================================================================== def getPlayerDataPump(self): printl("", self, "S") printl("", self, "C") return self.playerDataPump #=========================================================================== # #=========================================================================== def getPlayerDataQueue(self): printl("", self, "S") printl("", self, "C") return self.playerData #=========================================================================== # #=========================================================================== def setSession(self, session): self.session = session self.start() #=========================================================================== #PROPERTIES #=========================================================================== PlayerDataPump = property(getPlayerDataPump) PlayerData = property(getPlayerDataQueue) #=========================================================================== # #=========================================================================== def startDeamon(self): printl("", self, "S") Thread.__init__(self) self.HandlerClass = RemoteHandler self.ServerClass = HTTPServer self.protocol = "HTTP/1.0" self.myIp = getMyIp() if not self.myIp: return False try: # this starts updatemechanism to show up as player in devices like ios self.client = PlexGdm() self.client.setClientDetails() self.client.start_registration() except: return False if self.client.check_client_registration(): self.registered = True printl("Successfully registered", self, "D") else: self.registered = False printl("Unsuccessfully registered", self, "D") printl("", self, "C") return True #=========================================================================== # #=========================================================================== def getDeamonState(self): printl("", self, "S") printl("", self, "C") return self.registered, self.remoteListenerInformation #=========================================================================== # #=========================================================================== def stopRemoteDeamon(self): printl("", self, "S") self.client.stop_all() self.httpd.shutdown() printl("", self, "C") #=========================================================================== # #=========================================================================== #def runHttp(session, playerCallback, HandlerClass = MyHandler,ServerClass = HTTPServer, protocol="HTTP/1.0"): def run(self): printl("", __name__, "S") server_address = ("", config.plugins.dreamplex.remotePort.value) self.HandlerClass.protocol_version = self.protocol self.HandlerClass.session = self.session self.HandlerClass.playerCallback = self.nowDoIt self.httpd = self.ServerClass(server_address, self.HandlerClass) sa = self.httpd.socket.getsockname() self.remoteListenerInformation = "Serving HTTP on " + str( sa[0]) + " port " + str(sa[1]) printl(self.remoteListenerInformation, __name__, "D") self.httpd.serve_forever() printl("", __name__, "C") #=========================================================================== # #=========================================================================== def nowDoIt(self, data): self.playerData.push((data, )) self.playerDataPump.send(0)
def __init__(self): self.playerData = ThreadQueue() self.playerDataPump = ePythonMessagePump() self.subMgr = SubscriptionManager()
class HttpDeamon(Thread): session = None httpd = None deamonState = None #=========================================================================== # #=========================================================================== def __init__(self): self.playerData = ThreadQueue() self.playerDataPump = ePythonMessagePump() self.subMgr = SubscriptionManager() #=========================================================================== # #=========================================================================== def getPlayerDataPump(self): printl("", self, "S") printl("", self, "C") return self.playerDataPump #=========================================================================== # #=========================================================================== def getPlayerDataQueue(self): printl("", self, "S") printl("", self, "C") return self.playerData #=========================================================================== # #=========================================================================== def setSession(self, session): self.session = session self.subMgr.session = session self.start() #=========================================================================== #PROPERTIES #=========================================================================== PlayerDataPump = property(getPlayerDataPump) PlayerData = property(getPlayerDataQueue) #=========================================================================== # #=========================================================================== def notifySubscribers(self, players): self.subMgr.notify(players) #=========================================================================== # #=========================================================================== def addSubscriber(self, protocol, host, port, uuid, commandID): self.subMgr.addSubscriber(protocol, host, port, uuid, commandID) #=========================================================================== # #=========================================================================== def getSubscribersList(self): return self.subMgr.getSubscribersList() #=========================================================================== # #=========================================================================== def removeSubscriber(self, uuid): self.subMgr.removeSubscriber(uuid) #=========================================================================== # #=========================================================================== def updateCommandID(self, uuid, commandID): self.subMgr.updateCommandID(uuid, commandID) #=========================================================================== # #=========================================================================== def prepareDeamon(self): printl("", self, "S") Thread.__init__(self) self.HandlerClass = RemoteHandler self.ServerClass = HTTPServer self.protocol = "HTTP/1.0" self.myIp = getMyIp() if not self.myIp: self.deamonState = False self.registered = False return try: # this starts updatemechanism to show up as player in devices like ios self.client = PlexGdm() self.client.setClientDetails() self.client.start_registration() except: self.deamonState = False return if self.client.check_client_registration(): self.registered = True printl("Successfully registered", self, "D") else: self.registered = False printl("Unsuccessfully registered", self, "D") self.deamonState = True printl("", self, "C") #=========================================================================== # #=========================================================================== def getDeamonState(self): printl("", self, "S") printl("", self, "C") return self.registered, self.deamonState #=========================================================================== # #=========================================================================== def stopRemoteDeamon(self): printl("", self, "S") self.client.stop_all() self.httpd.shutdown() printl("", self, "C") #=========================================================================== # #=========================================================================== #def runHttp(session, playerCallback, HandlerClass = MyHandler,ServerClass = HTTPServer, protocol="HTTP/1.0"): def run(self): printl("", __name__, "S") server_address = ("", config.plugins.dreamplex.remotePort.value) self.HandlerClass.protocol_version = self.protocol self.HandlerClass.session = self.session self.HandlerClass.playerCallback = self.nowDoIt self.httpd = self.ServerClass(server_address, self.HandlerClass) sa = self.httpd.socket.getsockname() self.remoteListenerInformation = "Serving HTTP on " + str(sa[0]) + " port " + str(sa[1]) printl(self.remoteListenerInformation, __name__, "D") self.httpd.serve_forever() printl("", __name__, "C") #=========================================================================== # #=========================================================================== def nowDoIt(self, data): printl("", __name__, "S") self.playerData.push((data,)) self.playerDataPump.send(0) printl("", __name__, "C")