Module "xpllistener"
This module contains the network listener function that listens for inbound xPL messages. Do not use it directly, it will be invoked automatically when the copas loop starts.
No global will be created, it just returns the listener table. The main xPL module will create a global xpl.listener to access it. To receive incoming messages subscribe to the 'newmessage' event.
Copyright © 2011 Thijs Schreijer
Release: Version 0.1, LuaxPL framework.
Tables
| events | Events generated by xpllistener. |
Functions
| getipaddress () | Returns the current IP address in use by the xpllistener |
| getmydevices (status) | Returns the LuaxPL devices registered with the xpllistener. |
| getport () | Returns the current network port in use by the xpllistener |
| subscribe () | Subscribe to events of xpllistener. |
| unsubscribe () | Unsubscribe from events of xpllistener. |
Tables
- events
- Events generated by xpllistener. There is only one event, for additional events the start and stop events of the
copasscheduler may be used (see 'CopasTimer' and specifically thecopas.eventermodule).Fields
-
newmessage: event to indicate a new message has arrived. The message will be passed as an argument to the event handler. -
networkchange: event to indicate that the newtork state changed (ip address, connectio lost/restored, etc.). ThenewStateandoldStatewill be passed as arguments to the event handler (see 'NetCheck' documentation for details on thexxxStateformat)
See also:
-
Functions
- getipaddress ()
-
Returns the current IP address in use by the xpllistener
Return value:
the IP address now used by the listener and to be used in hbeat messages for the 'remote-ip' key. - getmydevices (status)
-
Returns the LuaxPL devices registered with the xpllistener. Every xpldevice created will upon initialization automatically register itself for xpllistener events.
Parameters:
-
status: ifnilthen all devices will be added to the return table, otherwise only the devices with a status property matching this status will be returned.
Return value:
a table keyed by xPL-address, with value being the xpldevice table/object -
- getport ()
-
Returns the current network port in use by the xpllistener
Return value:
the network port now used by the listener and to be used in hbeat messages for the 'port' key. - subscribe ()
-
Subscribe to events of xpllistener.
Usage:
function xpldevice:eventhandler(sender, event, msg, ...)
-- do your stuff with the message
end
 
function xpldevice:initialize()
-- subscribe to events of listener for new messages
xpl.listener:subscribe(self, self.eventhandler, xpl.listener.events.newmessage)
endSee also:
- unsubscribe ()
-
Unsubscribe from events of xpllistener.
See also: