From ad7a1ec89f843efa80be332bf3741a1cd57bba68 Mon Sep 17 00:00:00 2001 From: bendikro Date: Mon, 8 Sep 2014 18:45:59 +0200 Subject: [PATCH] [Core] Add ClientDisconnectedEvent --- deluge/core/rpcserver.py | 7 +++++++ deluge/event.py | 8 ++++++++ deluge/transfer.py | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/deluge/core/rpcserver.py b/deluge/core/rpcserver.py index d7f07e348..07b4554a6 100644 --- a/deluge/core/rpcserver.py +++ b/deluge/core/rpcserver.py @@ -24,6 +24,7 @@ import deluge.component as component import deluge.configmanager from deluge.core.authmanager import AUTH_LEVEL_ADMIN, AUTH_LEVEL_DEFAULT, AUTH_LEVEL_NONE from deluge.error import DelugeError, IncompatibleClient, NotAuthorizedError, WrappedException, _ClientSideRecreateError +from deluge.event import ClientDisconnectedEvent from deluge.transfer import DelugeTransferProtocol RPC_RESPONSE = 1 @@ -169,6 +170,8 @@ class DelugeRPCProtocol(DelugeTransferProtocol): if self.transport.sessionno in self.factory.interested_events: del self.factory.interested_events[self.transport.sessionno] + if self.factory.state == "running": + component.get("EventManager").emit(ClientDisconnectedEvent(self.factory.session_id)) log.info("Deluge client disconnected: %s", reason.value) def valid_session(self): @@ -319,6 +322,7 @@ class RPCServer(component.Component): self.factory = Factory() self.factory.protocol = DelugeRPCProtocol self.factory.session_id = -1 + self.factory.state = "running" # Holds the registered methods self.factory.methods = {} @@ -507,6 +511,9 @@ class RPCServer(component.Component): event.name, event.args, session_id) self.factory.session_protocols[session_id].sendData((RPC_EVENT, event.name, event.args)) + def stop(self): + self.factory.state = "stopping" + def check_ssl_keys(): """ diff --git a/deluge/event.py b/deluge/event.py index 072345bfd..f91d6d2ea 100644 --- a/deluge/event.py +++ b/deluge/event.py @@ -277,3 +277,11 @@ class PluginDisabledEvent(DelugeEvent): """ def __init__(self, plugin_name): self._args = [plugin_name] + + +class ClientDisconnectedEvent(DelugeEvent): + """ + Emitted when a client disconnects. + """ + def __init__(self, session_id): + self._args = [session_id] diff --git a/deluge/transfer.py b/deluge/transfer.py index 45b809dc7..15f88b088 100644 --- a/deluge/transfer.py +++ b/deluge/transfer.py @@ -23,7 +23,7 @@ log = logging.getLogger(__name__) MESSAGE_HEADER_SIZE = 5 -class DelugeTransferProtocol(Protocol): +class DelugeTransferProtocol(Protocol, object): """ Data messages are transfered using very a simple protocol. Data messages are transfered with a header containing