[Core] Add ClientDisconnectedEvent
This commit is contained in:
parent
ca1eaa5e15
commit
ad7a1ec89f
|
@ -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():
|
||||
"""
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue