Package CyberRail :: Package common :: Module CyberrailConnection :: Class CyberrailConnection
[hide private]
[frames] | no frames]

Class CyberrailConnection

source code



CyberrailConnection is the simplest way to connect to the central Cyberrail node.
Usage :
    con = CyberrailConnection("moduleName", moduleVersion)
    con.register("message xxx", self.handlerForMessageXXX)
    con.register("message yyy", self.handlerForMessageYYY)
    con.main()
    
When the program enters the main method, the Connection will receive some
events. These events will be dispatched given the registerd callbacks. See
register and others for details.
    
See __init__ for details.

Instance Methods [hide private]
 
__init__(self, moduleName, moduleVersion=0, host="::1", port=8417, ipV6=True, exclusive=True, acceptAllErrors=False)
Create a connection with the central node.
source code
 
main(self, communicationManager=None)
Call me to start the event loop
source code
 
register(self, message, handler)
Register a message handler.
source code
 
registerError(self, handler)
Register a callback when we receive an error
source code
 
close(self)
Close the connection and return from the main method.
source code
 
send(self, data)
Send some data to the central node.
source code
 
eventReceived(self, event)
Private method.
source code
 
defaultInterruptHandler(self)
Private method.
source code
 
defaultErrorHandler(self, message)
Private method.
source code
 
defaultLackOfModuleHandler(self, moduleName)
Private method.
source code
 
defaultPacketManagement(self, packet)
Private method.
source code
 
managePacket(self, packet)
Private method.
source code
 
error(self, message)
Called in case of errors.
source code
 
interrupt(self)
Called in case of interruption
source code
 
checkFor(self, moduleNameToCheck)
Check if a module is connected to the central node
source code
 
requireModule(self, moduleName, lackOfModuleHandler=None)
Ask the Connection to give up if/when the given module is not present.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, moduleName, moduleVersion=0, host="::1", port=8417, ipV6=True, exclusive=True, acceptAllErrors=False)
(Constructor)

source code 

Create a connection with the central node.

Parameters:
  • moduleName - the name of the module
  • moduleVersion - the version of the module
  • host - the host to contact, default to ipv6-localhost
  • port - the TCP port
  • ipV6 - wether or not use IP v6
  • exclusive - if yes, the connection is closed if another module of the same name is connected. Once ocnnected, this parameter has no more effect.
  • acceptAllErrors - receive all errors sent to the central node
Overrides: object.__init__

main(self, communicationManager=None)

source code 

Call me to start the event loop

Parameters:
  • communicationManager - the communication manager to use (default to the standard one)
Returns:
when the connection is lost or can't be established (in fact when the communication manager returns)

register(self, message, handler)

source code 

Register a message handler.

Parameters:
  • message - a string identifying the message
  • handler - the callback

send(self, data)

source code 

Send some data to the central node. Data should be a Cyberrail.protocol.Message

eventReceived(self, event)

source code 

Private method. Local high level event handler.

defaultInterruptHandler(self)

source code 

Private method. When ctrl+c is hit.

managePacket(self, packet)

source code 

Private method. Handle a message

requireModule(self, moduleName, lackOfModuleHandler=None)

source code 

Ask the Connection to give up if/when the given module is not present.

Parameters:
  • moduleName - the name of the module
  • lackOfModuleHandler - a handler that will be called if a required module disapear.