summaryrefslogtreecommitdiff
path: root/src/leap/common/events
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@leap.se>2013-05-28 17:38:30 -0300
committerTomás Touceda <chiiph@leap.se>2013-05-28 17:38:30 -0300
commit205fcd6c6bb8712a115f3dfe738c490f5427e09b (patch)
tree0d824ab1fc1de09fe2136f1419a0a2966225fac4 /src/leap/common/events
parentb7dc270bce885ce5079d86d8e52fd96b8390fc9d (diff)
parent354467c605f07042568c10c3e931f7fc093c0bf4 (diff)
Merge remote-tracking branch 'kali/bug/allow-absolute-paths2' into develop
Diffstat (limited to 'src/leap/common/events')
-rw-r--r--src/leap/common/events/__init__.py56
-rw-r--r--src/leap/common/events/component.py80
-rw-r--r--src/leap/common/events/daemon.py40
-rw-r--r--src/leap/common/events/server.py40
4 files changed, 108 insertions, 108 deletions
diff --git a/src/leap/common/events/__init__.py b/src/leap/common/events/__init__.py
index c949080..9fc93ee 100644
--- a/src/leap/common/events/__init__.py
+++ b/src/leap/common/events/__init__.py
@@ -45,24 +45,24 @@ def register(signal, callback, uid=None, replace=False, reqcbk=None,
returned for a synch request but nothing will be returned for an asynch
request.
- @param signal: the signal that causes the callback to be launched
- @type signal: int (see the `events.proto` file)
- @param callback: the callback to be called when the signal is received
- @type callback: function
- @param uid: a unique id for the callback
- @type uid: int
- @param replace: should an existent callback with same uid be replaced?
- @type replace: bool
- @param reqcbk: a callback to be called when a response from server is
+ :param signal: the signal that causes the callback to be launched
+ :type signal: int (see the `events.proto` file)
+ :param callback: the callback to be called when the signal is received
+ :type callback: function
+ :param uid: a unique id for the callback
+ :type uid: int
+ :param replace: should an existent callback with same uid be replaced?
+ :type replace: bool
+ :param reqcbk: a callback to be called when a response from server is
received
- @type reqcbk: function
+ :type reqcbk: function
callback(leap.common.events.events_pb2.EventResponse)
- @param timeout: the timeout for synch calls
- @type timeout: int
+ :param timeout: the timeout for synch calls
+ :type timeout: int
- @return: the response from server for synch calls or nothing for asynch
+ :return: the response from server for synch calls or nothing for asynch
calls
- @rtype: leap.common.events.events_pb2.EventsResponse or None
+ :rtype: leap.common.events.events_pb2.EventsResponse or None
"""
return component.register(signal, callback, uid, replace, reqcbk, timeout)
@@ -78,23 +78,23 @@ def signal(signal, content="", mac_method="", mac="", reqcbk=None,
returned for a synch request but nothing will be returned for an asynch
request.
- @param signal: the signal that causes the callback to be launched
- @type signal: int (see the `events.proto` file)
- @param content: the contents of the event signal
- @type content: str
- @param mac_method: the method used to auth mac
- @type mac_method: str
- @param mac: the content of the auth mac
- @type mac: str
- @param reqcbk: a callback to be called when a response from server is
+ :param signal: the signal that causes the callback to be launched
+ :type signal: int (see the `events.proto` file)
+ :param content: the contents of the event signal
+ :type content: str
+ :param mac_method: the method used to auth mac
+ :type mac_method: str
+ :param mac: the content of the auth mac
+ :type mac: str
+ :param reqcbk: a callback to be called when a response from server is
received
- @type reqcbk: function
+ :type reqcbk: function
callback(leap.common.events.events_pb2.EventResponse)
- @param timeout: the timeout for synch calls
- @type timeout: int
+ :param timeout: the timeout for synch calls
+ :type timeout: int
- @return: the response from server for synch calls or nothing for asynch
+ :return: the response from server for synch calls or nothing for asynch
calls
- @rtype: leap.common.events.events_pb2.EventsResponse or None
+ :rtype: leap.common.events.events_pb2.EventsResponse or None
"""
return component.signal(signal, content, mac_method, mac, reqcbk, timeout)
diff --git a/src/leap/common/events/component.py b/src/leap/common/events/component.py
index f62f948..9932190 100644
--- a/src/leap/common/events/component.py
+++ b/src/leap/common/events/component.py
@@ -63,8 +63,8 @@ def ensure_component_daemon():
Ensure the component daemon is running and listening for incoming
messages.
- @return: the daemon instance
- @rtype: EventsComponentDaemon
+ :return: the daemon instance
+ :rtype: EventsComponentDaemon
"""
import time
daemon = EventsComponentDaemon.ensure(0)
@@ -91,28 +91,28 @@ def register(signal, callback, uid=None, replace=False, reqcbk=None,
returned for a synch request but nothing will be returned for an asynch
request.
- @param signal: the signal that causes the callback to be launched
- @type signal: int (see the `events.proto` file)
- @param callback: the callback to be called when the signal is received
- @type callback: function
+ :param signal: the signal that causes the callback to be launched
+ :type signal: int (see the `events.proto` file)
+ :param callback: the callback to be called when the signal is received
+ :type callback: function
callback(leap.common.events.events_pb2.SignalRequest)
- @param uid: a unique id for the callback
- @type uid: int
- @param replace: should an existent callback with same uid be replaced?
- @type replace: bool
- @param reqcbk: a callback to be called when a response from server is
+ :param uid: a unique id for the callback
+ :type uid: int
+ :param replace: should an existent callback with same uid be replaced?
+ :type replace: bool
+ :param reqcbk: a callback to be called when a response from server is
received
- @type reqcbk: function
+ :type reqcbk: function
callback(leap.common.events.events_pb2.EventResponse)
- @param timeout: the timeout for synch calls
- @type timeout: int
+ :param timeout: the timeout for synch calls
+ :type timeout: int
Might raise a CallbackAlreadyRegistered exception if there's already a
callback identified by the given uid and replace is False.
- @return: the response from server for synch calls or nothing for asynch
+ :return: the response from server for synch calls or nothing for asynch
calls
- @rtype: leap.common.events.events_pb2.EventsResponse or None
+ :rtype: leap.common.events.events_pb2.EventsResponse or None
"""
ensure_component_daemon() # so we can receive registered signals
# register callback locally
@@ -152,24 +152,24 @@ def signal(signal, content="", mac_method="", mac="", reqcbk=None,
returned for a synch request but nothing will be returned for an asynch
request.
- @param signal: the signal that causes the callback to be launched
- @type signal: int (see the `events.proto` file)
- @param content: the contents of the event signal
- @type content: str
- @param mac_method: the method used for auth mac
- @type mac_method: str
- @param mac: the content of the auth mac
- @type mac: str
- @param reqcbk: a callback to be called when a response from server is
+ :param signal: the signal that causes the callback to be launched
+ :type signal: int (see the `events.proto` file)
+ :param content: the contents of the event signal
+ :type content: str
+ :param mac_method: the method used for auth mac
+ :type mac_method: str
+ :param mac: the content of the auth mac
+ :type mac: str
+ :param reqcbk: a callback to be called when a response from server is
received
- @type reqcbk: function
+ :type reqcbk: function
callback(leap.common.events.events_pb2.EventResponse)
- @param timeout: the timeout for synch calls
- @type timeout: int
+ :param timeout: the timeout for synch calls
+ :type timeout: int
- @return: the response from server for synch calls or nothing for asynch
+ :return: the response from server for synch calls or nothing for asynch
calls
- @rtype: leap.common.events.events_pb2.EventsResponse or None
+ :rtype: leap.common.events.events_pb2.EventsResponse or None
"""
request = proto.SignalRequest()
request.event = signal
@@ -197,12 +197,12 @@ class EventsComponentService(proto.EventsComponentService):
This method is called whenever a signal request is received from
server.
- @param controller: used to mediate a single method call
- @type controller: protobuf.socketrpc.controller.SocketRpcController
- @param request: the request received from the component
- @type request: leap.common.events.events_pb2.SignalRequest
- @param done: callback to be called when done
- @type done: protobuf.socketrpc.server.Callback
+ :param controller: used to mediate a single method call
+ :type controller: protobuf.socketrpc.controller.SocketRpcController
+ :param request: the request received from the component
+ :type request: leap.common.events.events_pb2.SignalRequest
+ :param done: callback to be called when done
+ :type done: protobuf.socketrpc.server.Callback
"""
logger.info('Received signal from server: %s...' % str(request)[:40])
@@ -230,10 +230,10 @@ class EventsComponentDaemon(daemon.EventsSingletonDaemon):
"""
Make sure the daemon is running on the given port.
- @param port: the port in which the daemon should listen
- @type port: int
+ :param port: the port in which the daemon should listen
+ :type port: int
- @return: a daemon instance
- @rtype: EventsComponentDaemon
+ :return: a daemon instance
+ :rtype: EventsComponentDaemon
"""
return cls.ensure_service(port, EventsComponentService())
diff --git a/src/leap/common/events/daemon.py b/src/leap/common/events/daemon.py
index d2c7b9b..c253948 100644
--- a/src/leap/common/events/daemon.py
+++ b/src/leap/common/events/daemon.py
@@ -50,10 +50,10 @@ class EventsRpcServer(SocketRpcServer):
"""
Initialize a RPC server.
- @param port: the port in which to listen for incoming messages
- @type port: int
- @param host: the address to bind to
- @type host: str
+ :param port: the port in which to listen for incoming messages
+ :type port: int
+ :param host: the address to bind to
+ :type host: str
"""
SocketRpcServer.__init__(self, port, host)
self._server = None
@@ -111,10 +111,10 @@ class EventsSingletonDaemon(threading.Thread):
This is a static method disguised as instance method that actually
does the initialization of the daemon instance.
- @param port: the port in which to listen for incoming messages
- @type port: int
- @param service: the service to provide in this daemon
- @type service: google.protobuf.service.Service
+ :param port: the port in which to listen for incoming messages
+ :type port: int
+ :param service: the service to provide in this daemon
+ :type service: google.protobuf.service.Service
"""
threading.Thread.__init__(self)
self._port = port
@@ -141,11 +141,11 @@ class EventsSingletonDaemon(threading.Thread):
with the appropriate service from the `events.proto` definitions, and
return the daemon instance.
- @param port: the port in which the daemon should be listening
- @type port: int
+ :param port: the port in which the daemon should be listening
+ :type port: int
- @return: a daemon instance
- @rtype: EventsSingletonDaemon
+ :return: a daemon instance
+ :rtype: EventsSingletonDaemon
"""
raise NotImplementedError(self.ensure)
@@ -156,11 +156,11 @@ class EventsSingletonDaemon(threading.Thread):
Might return ServiceAlreadyRunningException
- @param port: the port in which the daemon should be listening
- @type port: int
+ :param port: the port in which the daemon should be listening
+ :type port: int
- @return: a daemon instance
- @rtype: EventsSingletonDaemon
+ :return: a daemon instance
+ :rtype: EventsSingletonDaemon
"""
daemon = cls(port, service)
if not daemon.is_alive():
@@ -178,8 +178,8 @@ class EventsSingletonDaemon(threading.Thread):
"""
Retrieve singleton instance of this daemon.
- @return: a daemon instance
- @rtype: EventsSingletonDaemon
+ :return: a daemon instance
+ :rtype: EventsSingletonDaemon
"""
return cls.__instance
@@ -200,8 +200,8 @@ class EventsSingletonDaemon(threading.Thread):
Retrieve the value of the port to which the service running in this
daemon is binded to.
- @return: the port to which the daemon is binded to
- @rtype: int
+ :return: the port to which the daemon is binded to
+ :rtype: int
"""
if self._port is 0:
self._port = self._server.port
diff --git a/src/leap/common/events/server.py b/src/leap/common/events/server.py
index 34c573a..1f3a874 100644
--- a/src/leap/common/events/server.py
+++ b/src/leap/common/events/server.py
@@ -55,11 +55,11 @@ def ensure_server(port=SERVER_PORT):
Attempt to connect to given local port. Upon success, assume that the
events server has already been started. Upon failure, start events server.
- @param port: the port in which server should be listening
- @type port: int
+ :param port: the port in which server should be listening
+ :type port: int
- @return: the daemon instance or nothing
- @rtype: EventsServerDaemon or None
+ :return: the daemon instance or nothing
+ :rtype: EventsServerDaemon or None
"""
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@@ -81,12 +81,12 @@ class EventsServerService(proto.EventsServerService):
"""
Register a component port to be signaled when specific events come in.
- @param controller: used to mediate a single method call
- @type controller: protobuf.socketrpc.controller.SocketRpcController
- @param request: the request received from the component
- @type request: leap.common.events.events_pb2.RegisterRequest
- @param done: callback to be called when done
- @type done: protobuf.socketrpc.server.Callback
+ :param controller: used to mediate a single method call
+ :type controller: protobuf.socketrpc.controller.SocketRpcController
+ :param request: the request received from the component
+ :type request: leap.common.events.events_pb2.RegisterRequest
+ :param done: callback to be called when done
+ :type done: protobuf.socketrpc.server.Callback
"""
logger.info("Received registration request: %s..." % str(request)[:40])
# add component port to signal list
@@ -105,12 +105,12 @@ class EventsServerService(proto.EventsServerService):
Perform an RPC call to signal all components registered to receive a
specific signal.
- @param controller: used to mediate a single method call
- @type controller: protobuf.socketrpc.controller.SocketRpcController
- @param request: the request received from the component
- @type request: leap.common.events.events_pb2.SignalRequest
- @param done: callback to be called when done
- @type done: protobuf.socketrpc.server.Callback
+ :param controller: used to mediate a single method call
+ :type controller: protobuf.socketrpc.controller.SocketRpcController
+ :param request: the request received from the component
+ :type request: leap.common.events.events_pb2.SignalRequest
+ :param done: callback to be called when done
+ :type done: protobuf.socketrpc.server.Callback
"""
logger.info('Received signal from component: %s...', str(request)[:40])
# send signal to all registered components
@@ -140,10 +140,10 @@ class EventsServerDaemon(daemon.EventsSingletonDaemon):
"""
Make sure the daemon is running on the given port.
- @param port: the port in which the daemon should listen
- @type port: int
+ :param port: the port in which the daemon should listen
+ :type port: int
- @return: a daemon instance
- @rtype: EventsServerDaemon
+ :return: a daemon instance
+ :rtype: EventsServerDaemon
"""
return cls.ensure_service(port, EventsServerService())