diff options
Diffstat (limited to 'module/remote')
-rw-r--r-- | module/remote/apitypes.py | 11 | ||||
-rw-r--r-- | module/remote/apitypes_debug.py | 3 | ||||
-rw-r--r-- | module/remote/pyload.thrift | 21 | ||||
-rw-r--r-- | module/remote/wsbackend/AsyncHandler.py | 27 |
4 files changed, 39 insertions, 23 deletions
diff --git a/module/remote/apitypes.py b/module/remote/apitypes.py index aaec2b3ce..83368c6de 100644 --- a/module/remote/apitypes.py +++ b/module/remote/apitypes.py @@ -297,11 +297,14 @@ class ProgressInfo(BaseObject): self.download = download class ServerStatus(BaseObject): - __slots__ = ['speed', 'files', 'notifications', 'paused', 'download', 'reconnect'] + __slots__ = ['speed', 'linkstotal', 'linksqueue', 'sizetotal', 'sizequeue', 'notifications', 'paused', 'download', 'reconnect'] - def __init__(self, speed=None, files=None, notifications=None, paused=None, download=None, reconnect=None): + def __init__(self, speed=None, linkstotal=None, linksqueue=None, sizetotal=None, sizequeue=None, notifications=None, paused=None, download=None, reconnect=None): self.speed = speed - self.files = files + self.linkstotal = linkstotal + self.linksqueue = linksqueue + self.sizetotal = sizetotal + self.sizequeue = sizequeue self.notifications = notifications self.paused = paused self.download = download @@ -427,8 +430,6 @@ class Iface(object): pass def getCoreConfig(self): pass - def getEvents(self, uuid): - pass def getFileInfo(self, fid): pass def getFileTree(self, pid, full): diff --git a/module/remote/apitypes_debug.py b/module/remote/apitypes_debug.py index 6d30f1da6..4fab11f96 100644 --- a/module/remote/apitypes_debug.py +++ b/module/remote/apitypes_debug.py @@ -37,7 +37,7 @@ classes = { 'PackageInfo' : [int, basestring, basestring, int, int, basestring, basestring, basestring, int, (list, basestring), int, bool, int, PackageStats, (list, int), (list, int)], 'PackageStats' : [int, int, int, int], 'ProgressInfo' : [basestring, basestring, basestring, int, int, int, (None, DownloadProgress)], - 'ServerStatus' : [int, PackageStats, int, bool, bool, bool], + 'ServerStatus' : [int, int, int, int, int, int, bool, bool, bool], 'ServiceDoesNotExists' : [basestring, basestring], 'ServiceException' : [basestring], 'TreeCollection' : [PackageInfo, (dict, int, FileInfo), (dict, int, PackageInfo)], @@ -82,7 +82,6 @@ methods = { 'getConfig': (dict, basestring, ConfigHolder), 'getConfigValue': basestring, 'getCoreConfig': (list, ConfigInfo), - 'getEvents': (list, EventInfo), 'getFileInfo': FileInfo, 'getFileTree': TreeCollection, 'getFilteredFileTree': TreeCollection, diff --git a/module/remote/pyload.thrift b/module/remote/pyload.thrift index dc6b1c406..06add4208 100644 --- a/module/remote/pyload.thrift +++ b/module/remote/pyload.thrift @@ -196,11 +196,14 @@ struct LinkStatus { struct ServerStatus { 1: ByteCount speed, - 2: PackageStats files, - 3: i16 notifications, - 4: bool paused, - 5: bool download, - 6: bool reconnect, + 2: i16 linkstotal, + 3: i16 linksqueue, + 4: ByteCount sizetotal, + 5: ByteCount sizequeue, + 6: i16 notifications, + 7: bool paused, + 8: bool download, + 9: bool reconnect, } struct InteractionTask { @@ -257,7 +260,7 @@ struct ConfigInfo { struct EventInfo { 1: string eventname, - 2: list<JSONString> event_args, + 2: list<JSONString> event_args, //will contain json objects } struct UserData { @@ -481,12 +484,6 @@ service Pyload { list<InteractionTask> getNotifications(), /////////////////////// - // Event Handling - /////////////////////// - - list<EventInfo> getEvents(1: string uuid), - - /////////////////////// // Account Methods /////////////////////// diff --git a/module/remote/wsbackend/AsyncHandler.py b/module/remote/wsbackend/AsyncHandler.py index 2f9b43ad2..5c08aa96d 100644 --- a/module/remote/wsbackend/AsyncHandler.py +++ b/module/remote/wsbackend/AsyncHandler.py @@ -16,11 +16,13 @@ # @author: RaNaN ############################################################################### +import re from Queue import Queue, Empty from threading import Lock from mod_pywebsocket.msgutil import receive_message +from module.Api import EventInfo from module.utils import lock from AbstractHandler import AbstractHandler @@ -41,31 +43,40 @@ class AsyncHandler(AbstractHandler): COMMAND = "start" PROGRESS_INTERVAL = 2 - STATUS_INTERVAL = 60 + EVENT_PATTERN = re.compile(r"^(package|file)", re.I) def __init__(self, api): AbstractHandler.__init__(self, api) self.clients = [] self.lock = Lock() + self.core.evm.addEvent("event", self.add_event) + @lock def on_open(self, req): req.queue = Queue() req.interval = self.PROGRESS_INTERVAL + req.events = self.EVENT_PATTERN req.mode = Mode.STANDBY self.clients.append(req) @lock def on_close(self, req): try: + del req.queue self.clients.remove(req) except ValueError: # ignore when not in list pass @lock - def add_event(self, event): + def add_event(self, event, *args): + # Convert arguments to json suited instance + event = EventInfo(event, [x.toInfoData() if hasattr(x, 'toInfoData') else x for x in args]) + for req in self.clients: - req.queue.put(event) + if req.events.search(event.eventname): + self.log.debug("Pushing event %s" % event) + req.queue.put(event) def transfer_data(self, req): while True: @@ -100,6 +111,8 @@ class AsyncHandler(AbstractHandler): if func == "setInterval": req.interval = args[0] + elif func == "setEvents": + req.events = re.compile(args[0], re.I) elif func == self.COMMAND: req.mode = Mode.RUNNING @@ -108,7 +121,13 @@ class AsyncHandler(AbstractHandler): """ Listen for events, closes socket when returning True """ try: ev = req.queue.get(True, req.interval) - self.send(req, ev) + try: + self.send(req, ev) + except TypeError: + self.log.debug("Event %s not converted" % ev) + ev.event_args = [] + # Resend the event without arguments + self.send(req, ev) except Empty: # TODO: server status is not enough |