Package ivy :: Module std_api
[hide private]
[frames] | no frames]

Module std_api

source code

Implements the standard Ivy API.

You can refer to the example code pyhello.py for an example of use.

All methods in this module are frontends to a ivy.IvyServer instance, stored in the module's attributes _IvyServer.

Copyright (c) 2005-2011 Sebastien Bigaret <sbigaret@users.sourceforge.net>

Functions [hide private]
 
IvyBindRegexpChange(regexp_change_callback) source code
 
IvySendError(client, num_id, error_msg)
Sends an "error" message to client
source code
 
IvyGetApplicationMessages(client)
Returns all subscriptions for that client
source code
    Connecting to/disconnecting from the Ivy bus
 
IvyInit(agent_name, ready_msg=None, main_loop_type_ignored=0, on_cnx_fct=<function void_function at 0x293fd70>, on_die_fct=<function void_function at 0x293fd70>)
Initializes the module.
source code
 
IvyStart(ivybus=None)
Starts the Ivy server and fully activate the client.
source code
 
IvyMainLoop()
Simulates the original main loop: simply waits for the server termination.
source code
 
IvyStop() source code
    Bindings
 
IvyBindMsg(on_msg_fct, regexp)
Registers a method that should be called each time a message matching regexps is sent on the Ivy bus.
source code
 
IvyBindDirectMsg(on_msg_fct)
Registers a method that should be called each time someone sends us a direct message
source code
 
IvyUnBindMsg(id)
Unregisters a binding
source code
    Inspecting the Ivy bus
 
IvyGetApplicationList()
Returns the names of the applications that are currently connected
source code
 
IvyGetApplication(name)
Returns the Ivy client registered on the bus under the given name.
source code
 
IvyGetApplicationName(client)
Equivalent to client.agent_name
source code
 
IvyGetApplicationHost(client)
Equivalent to client.fqdn.
source code
    Interacting with other Ivy clients
 
IvySendMsg(msg)
Sends a message on the bus
source code
 
IvySendDieMsg(client)
Sends a "die" message to client, instructing him to terminate.
source code
 
IvySendDirectMsg(client, num_id, msg)
Sends a message directly to an other Ivy client, with the supplied numerical id and message.
source code
    Timers
 
IvyTimerRepeatAfter(count, delay, callback)
Creates and activates a new timer
source code
 
IvyTimerModify(timer_id, delay)
Modifies a timer's delay.
source code
 
IvyTimerRemove(timer_id)
Stops and removes a given timer.
source code
Variables [hide private]
  _IvyServer = None
  _timers = {}
  __package__ = 'ivy'
Function Details [hide private]

IvyInit(agent_name, ready_msg=None, main_loop_type_ignored=0, on_cnx_fct=<function void_function at 0x293fd70>, on_die_fct=<function void_function at 0x293fd70>)

source code 
Initializes the module. This method should be called exactly once before any other method is called.

IvyStart(ivybus=None)

source code 
Starts the Ivy server and fully activate the client. Please refer to the discussion in IvyMainLoop() 's documentation.

IvyMainLoop()

source code 

Simulates the original main loop: simply waits for the server termination.

Note that while the original API requires this to be called, this module does NOT rely in any way on this method. In particular, a client is fully functional and begins to receive messages as soon as the IvyStart() method is called.

IvyBindMsg(on_msg_fct, regexp)

source code 
Registers a method that should be called each time a message matching regexps is sent on the Ivy bus.
Returns:
an id identifying the binding, that can be used to unregister it (see IvyUnBindMsg())

IvyUnBindMsg(id)

source code 
Unregisters a binding
Parameters:
  • id - the binding's id, as previously returned by IvyBindMsg().
Returns:
the regexp corresponding to the unsubscribed binding
Raises:
  • KeyError - if no such subscription can be found

IvySendDieMsg(client)

source code 
Sends a "die" message to client, instructing him to terminate.
Parameters:

IvySendDirectMsg(client, num_id, msg)

source code 
Sends a message directly to an other Ivy client, with the supplied numerical id and message.
Parameters:
  • client - : an ivy.IvyClient object, as returned by IvyGetApplication()
  • num_id - : an additional integer to use. It may, or may not, be meaningful, this only depends on the usage your application makes of it, the Ivy protocol itself does not care and simply transmits it along with the message.
  • msg - : the message to send

IvySendError(client, num_id, error_msg)

source code 
Sends an "error" message to client
Parameters:
  • client - : an ivy.IvyClient object, as returned by IvyGetApplication()
  • num_id - : an additional integer to use. It may, or may not, be meaningful, this only depends on the usage your application makes of it, the Ivy protocol itself does not care and simply transmits it along with the message.
  • error_msg - : the message to send

IvyGetApplicationMessages(client)

source code 
Returns all subscriptions for that client
Parameters:
Returns:
list of tuples (idx, regexp)

IvyGetApplication(name)

source code 

Returns the Ivy client registered on the bus under the given name.

Warning!

if multiple applications are registered w/ the same name only one is returned

Returns:
an ivy.IvyClient object

IvyGetApplicationName(client)

source code 
Equivalent to client.agent_name
Parameters:

IvyGetApplicationHost(client)

source code 
Equivalent to client.fqdn. IP address is stored under client.ip, and port number under client.port
Parameters:

IvyTimerRepeatAfter(count, delay, callback)

source code 
Creates and activates a new timer
Parameters:
  • count - : nb of time to repeat the loop, 0 (zero) for an endless loop
  • delay - : the delay between ticks, in milliseconds
  • callback - : the function to call on every tick. That function is called without any parameters.
Returns:
the timer's id

IvyTimerModify(timer_id, delay)

source code 
Modifies a timer's delay. Note that the modification will happen after the next tick.
Parameters:
  • timer_id - : id of the timer to modify, as returned by IvyTimerRepeatAfter()
  • delay - : the delay, in milliseconds, between ticks

IvyTimerRemove(timer_id)

source code 
Stops and removes a given timer.
Parameters: