coherence.upnp.core.event (module) — Cohen3 0.8.0 documentation

# coherence.upnp.core.event (module)

## Events

This module contains several classes related to UPnP events.

### `EventServer`

A class inherited from `twisted.web.resource.Resource` representing an event’s server with dispatch events capabilities via EventsDispatcher.

### `EventSubscriptionServer`

This class is the server part on the device side. It listens to subscribe requests and registering the subscriber to send event messages to the device.

### `Event`

A dictionary representing an UPnP’s Event.

### `EventProtocol`

The Event’s Protocol.

### `NotificationProtocol`

The Notification protocol used to by `send_notification()`.

class `EventServer`(control_point)

  Bases: `eventdispatcher.eventdispatcher.EventDispatcher`, `twisted.web.resource.Resource`, `coherence.log.LogAble`

  Changed in version 0.9.0:

  - Migrated from louie/dispatcher to EventDispatcher

  - The emitted events changed:

    > - UPnP.Event.Server.message_received => event_server_message_received

  `logCategory` = 'event_server'
  `render_NOTIFY`(request)

class `EventSubscriptionServer`(service)

  Bases: `eventdispatcher.eventdispatcher.EventDispatcher`, `twisted.web.resource.Resource`, `coherence.log.LogAble`

  This class is the server part on the device side. It listens to subscribe requests and registers the subscriber to send event messages to this device. If an unsubscribe request is received, the subscription is cancelled and no more event messages will be sent.

  we receive a subscription request like:

      {'callback':
          '<http://192.168.213.130:9083/BYvZMzfTSQkjHwzOThaP/ConnectionManager>',
       'host': '192.168.213.107:30020',
       'nt': 'upnp:event',
       'content-length': '0',
       'timeout': 'Second-300'}

  modify the callback value:

      callback = callback[1:len(callback)-1]

  and pack it into a subscriber dict:

      {'uuid:oAQbxiNlyYojCAdznJnC':
          {
          'callback':
          '<http://192.168.213.130:9083/BYvZMzfTSQkjHwzOThaP/ConnectionManager>',
          'created': 1162374189.257338,
          'timeout': 'Second-300',
          'sid': 'uuid:oAQbxiNlyYojCAdznJnC'}}

  Changed in version 0.9.0:

  - Migrated from louie/dispatcher to EventDispatcher

  - The emitted events changed:

    > - UPnP.Event.Client.message_received => event_client_message_received

  `logCategory` = 'event_subscription_server'
  `render_SUBSCRIBE`(request)
  `render_UNSUBSCRIBE`(request)

class `Event`(sid, elements=None, raw=None)

  Bases: `dict`, `coherence.log.LogAble`

  `logCategory` = 'event'
  `ns` = 'urn:schemas-upnp-org:event-1-0'
  `get_sid`()
  `from_elements`(elements)
  `_update_event`(prop)

class `EventProtocol`(service, action)

  Bases: `twisted.internet.protocol.Protocol`, `coherence.log.LogAble`

  `logCategory` = 'event_protocol'
  `teardown`()
  `connectionMade`()

    Called when a connection is made.

    This may be considered the initializer of the protocol, because it is called when the connection is completed. For clients, this is called once the connection to the server has been established; for servers, this is called after an accept() call stops blocking and a socket has been received. If you need to send any greeting or initial message, do it here.

  `dataReceived`(data)

    Called whenever data is received.

    Use this method to translate to a higher-level message. Usually, some callback will be made upon the receipt of each complete protocol message.

    @param data: a string of indeterminate length. Please keep in mind
      that you will probably need to buffer some data, as partial (or multiple) protocol messages may be received! I recommend that unit tests for protocols call through to this method with differing chunk sizes, down to one byte at a time.
  `connectionLost`(reason)

    Called when the connection is shut down.

    Clear any circular references here, and any external references to this Protocol. The connection has been closed.

    @type reason: L{twisted.python.failure.Failure}

`unsubscribe`(service, action='unsubscribe')

`subscribe`(service, action='subscribe')

  send a subscribe/renewal/unsubscribe request to a service return the device response

class `NotificationProtocol`

  Bases: `twisted.internet.protocol.Protocol`, `coherence.log.LogAble`

  `logCategory` = 'notification_protocol'
  `connectionMade`()

    Called when a connection is made.

    This may be considered the initializer of the protocol, because it is called when the connection is completed. For clients, this is called once the connection to the server has been established; for servers, this is called after an accept() call stops blocking and a socket has been received. If you need to send any greeting or initial message, do it here.

  `dataReceived`(data)

    Called whenever data is received.

    Use this method to translate to a higher-level message. Usually, some callback will be made upon the receipt of each complete protocol message.

    @param data: a string of indeterminate length. Please keep in mind
      that you will probably need to buffer some data, as partial (or multiple) protocol messages may be received! I recommend that unit tests for protocols call through to this method with differing chunk sizes, down to one byte at a time.
  `connectionLost`(reason)

    Called when the connection is shut down.

    Clear any circular references here, and any external references to this Protocol. The connection has been closed.

    @type reason: L{twisted.python.failure.Failure}

`send_notification`(s, xml)

  send a notification a subscriber return its response