Remove signalmanager
This commit is contained in:
parent
75efde8439
commit
5ad7c60b65
|
@ -48,7 +48,6 @@ from deluge.event import *
|
|||
from deluge.core.torrentmanager import TorrentManager
|
||||
from deluge.core.pluginmanager import PluginManager
|
||||
from deluge.core.alertmanager import AlertManager
|
||||
from deluge.core.signalmanager import SignalManager
|
||||
from deluge.core.filtermanager import FilterManager
|
||||
from deluge.core.preferencesmanager import PreferencesManager
|
||||
from deluge.core.autoadd import AutoAdd
|
||||
|
@ -113,7 +112,6 @@ class Core(component.Component):
|
|||
# Create the components
|
||||
self.preferencesmanager = PreferencesManager()
|
||||
self.alertmanager = AlertManager(self.session)
|
||||
self.signalmanager = SignalManager()
|
||||
self.pluginmanager = PluginManager(self)
|
||||
self.torrentmanager = TorrentManager(self.session, self.alertmanager)
|
||||
self.filtermanager = FilterManager(self)
|
||||
|
|
|
@ -143,7 +143,6 @@ class PreferencesManager(component.Component):
|
|||
self.core = component.get("Core")
|
||||
self.session = component.get("Core").session
|
||||
self.settings = component.get("Core").settings
|
||||
self.signals = component.get("SignalManager")
|
||||
|
||||
# Register set functions in the Config
|
||||
self.config.register_set_function("torrentfiles_location",
|
||||
|
|
|
@ -1,109 +0,0 @@
|
|||
#
|
||||
# signalmanager.py
|
||||
#
|
||||
# Copyright (C) 2007, 2008 Andrew Resch <andrewresch@gmail.com>
|
||||
#
|
||||
# Deluge is free software.
|
||||
#
|
||||
# You may redistribute it and/or modify it under the terms of the
|
||||
# GNU General Public License, as published by the Free Software
|
||||
# Foundation; either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# deluge is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with deluge. If not, write to:
|
||||
# The Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor
|
||||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
|
||||
|
||||
import deluge.xmlrpclib as xmlrpclib
|
||||
import socket
|
||||
import struct
|
||||
|
||||
from twisted.internet import reactor
|
||||
from twisted.internet.task import LoopingCall
|
||||
|
||||
import deluge.component as component
|
||||
from deluge.log import LOG as log
|
||||
|
||||
class Transport(xmlrpclib.Transport):
|
||||
def make_connection(self, host):
|
||||
# create a HTTP connection object from a host descriptor
|
||||
import httplib
|
||||
host, extra_headers, x509 = self.get_host_info(host)
|
||||
h = httplib.HTTP(host)
|
||||
h._conn.connect()
|
||||
h._conn.sock.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER,
|
||||
struct.pack('ii', 1, 0))
|
||||
return h
|
||||
|
||||
class SignalManager(component.Component):
|
||||
def __init__(self):
|
||||
component.Component.__init__(self, "SignalManager")
|
||||
self.clients = {}
|
||||
self.handlers = {}
|
||||
|
||||
def shutdown(self):
|
||||
self.clients = {}
|
||||
self.handlers = {}
|
||||
|
||||
def register_handler(self, signal, handler):
|
||||
"""Registers a handler for signals"""
|
||||
if signal not in self.handler.keys():
|
||||
self.handler[signal] = []
|
||||
|
||||
self.handler[signal].append(handler)
|
||||
log.debug("Registered signal handler for %s", signal)
|
||||
|
||||
def deregister_handler(self, handler):
|
||||
"""De-registers the 'handler' function from all signal types."""
|
||||
# Iterate through all handlers and remove 'handler' where found
|
||||
for (key, value) in self.handlers:
|
||||
if handler in value:
|
||||
value.remove(handler)
|
||||
|
||||
def deregister_client(self, address):
|
||||
"""Deregisters a client"""
|
||||
log.debug("Deregistering %s as a signal reciever..", address)
|
||||
for client in self.clients.keys():
|
||||
if client.split("//")[1].split(":")[0] == address:
|
||||
del self.clients[client]
|
||||
break
|
||||
|
||||
def register_client(self, address, port):
|
||||
"""Registers a client to emit signals to."""
|
||||
uri = "http://" + str(address) + ":" + str(port)
|
||||
log.debug("Registering %s as a signal reciever..", uri)
|
||||
self.clients[uri] = xmlrpclib.ServerProxy(uri, transport=Transport())
|
||||
|
||||
def emit(self, signal, *data):
|
||||
# Run the handlers
|
||||
if signal in self.handlers.keys():
|
||||
for handler in self.handlers[signal]:
|
||||
handler(*data)
|
||||
|
||||
for uri in self.clients:
|
||||
# reactor.callLater(0, self._emit, uri, signal, 1, *data)
|
||||
#XXX: Need to fix this for the new signal sending
|
||||
pass
|
||||
|
||||
def _emit(self, uri, signal, count, *data):
|
||||
if uri not in self.clients:
|
||||
return
|
||||
client = self.clients[uri]
|
||||
try:
|
||||
client.emit_event_signal(signal, *data)
|
||||
except (socket.error, Exception), e:
|
||||
log.warning("Unable to emit signal to client %s: %s (%d)", client, e, count)
|
||||
if count < 30:
|
||||
reactor.callLater(1, self._emit, uri, signal, count + 1, *data)
|
||||
else:
|
||||
log.info("Removing %s because it couldn't be reached..", uri)
|
||||
del self.clients[uri]
|
|
@ -108,8 +108,6 @@ class Torrent:
|
|||
# Get the core config
|
||||
self.config = ConfigManager("core.conf")
|
||||
|
||||
self.signals = component.get("SignalManager")
|
||||
|
||||
# Set the libtorrent handle
|
||||
self.handle = handle
|
||||
# Set the torrent_id for this torrent
|
||||
|
|
|
@ -171,8 +171,6 @@ class TorrentManager(component.Component):
|
|||
# Get the pluginmanager reference
|
||||
self.plugins = component.get("CorePluginManager")
|
||||
|
||||
self.signals = component.get("SignalManager")
|
||||
|
||||
# Run the old state upgrader before loading state
|
||||
deluge.core.oldstateupgrader.OldStateUpgrader()
|
||||
|
||||
|
|
Loading…
Reference in New Issue