SPIN Framework
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes

spin::spinBaseContext Class Reference

A class to facilitate communication with SPIN from any application. More...

#include <spinBaseContext.h>

Inheritance diagram for spin::spinBaseContext:
spin::spinClientContext spin::spinServerContext

List of all members.

Public Types

enum  SpinContextMode { SERVER_MODE, CLIENT_MODE }

Public Member Functions

 spinBaseContext ()
virtual ~spinBaseContext ()
bool isServer ()
virtual bool start ()=0
virtual void debugPrint ()
virtual void addCommandLineOptions (osg::ArgumentParser *arguments)
virtual int parseCommandLineOptions (osg::ArgumentParser *arguments)
bool startThread (void *(*threadFunction)(void *))
void stop ()
bool isRunning ()
void addInfoHandler (EventHandler *obs)
void removeInfoHandler (EventHandler *obs)
void removeHandlerForAllEvents (EventHandler *obs)
bool canAutoAssignPorts ()
void setTTL (int ttl)

Static Public Member Functions

static void sigHandler (int signum)
static int connectionCallback (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data)
static int nodeCallback (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data)
static int sceneCallback (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data)
static int logCallback (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data)
static int debugCallback (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data)
static void oscParser_error (int num, const char *msg, const char *path)

Public Attributes

std::vector< lo_address > lo_txAddrs_
std::vector< lo_address > lo_rxAddrs_
std::vector< lo_server > lo_rxServs_
lo_address lo_infoAddr
lo_address lo_syncAddr
lo_server lo_infoServ_
std::string tcpPort_
lo_server lo_tcpRxServer_
bool doDiscovery_

Static Public Attributes

static volatile bool signalStop = false

Protected Member Functions

void setLog (spinLog &log)
virtual void createServers ()=0

Protected Attributes

bool running
bool autoPorts_
SpinContextMode mode
std::vector< EventHandler * > infoHandlers
std::vector< EventHandler * > nodeHandlers
std::vector< EventHandler * > sceneHandlers

Detailed Description

A class to facilitate communication with SPIN from any application.

This class should not be used directly. Instead, use spinClientContext or spinServerContext.

By instantiating this class, we load the OSG nodekit for SPIN -- otherwise known as libSPIN. Furthermore, all of the network handlers are automatically generated in order to receive OSC messages from SPIN and update state.

Note that this class can be instantiated in different modes, depending on whether the process is to act as a server or a client.

All contexts would probably like to listen to infoPort broadcasts. A client can listen for info about the server, such as the correct ports to send messages. The server can listen to pings from clients to determine if they are still alive and connected.


Constructor & Destructor Documentation

spin::spinBaseContext::spinBaseContext ( )

Constructor.

This is where the actual default port numbers and multicast groups are defined.

spin::spinBaseContext::~spinBaseContext ( ) [virtual]

Destructor

Frees the senders and receivers.


Member Function Documentation

void spin::spinBaseContext::addInfoHandler ( EventHandler obs)

Add an event handler to the list of classes that will be notified when a message is received on the INFO channel:

bool spin::spinBaseContext::canAutoAssignPorts ( ) [inline]

Check if spin is allowed to assign automatic ports (eg, in the case where a port is busy). This is usually true, but if a user specifies ports manually with command-line options, this becomes false.

void spin::spinBaseContext::createServers ( ) [protected, pure virtual]

this method is used by both spinClientContext and spinServerContext

int spin::spinBaseContext::nodeCallback ( const char *  path,
const char *  types,
lo_arg **  argv,
int  argc,
void *  data,
void *  user_data 
) [static]

Callback for messages sent to a node in the scene graph.

Messages to node should have an OSC address in the form /SPIN/<scene id>="">/<node id>=""> Their first argument is the name of the method to call.

Methods to manage Python scripts for a node:

  • addCronScript <label> <path> <frequency>
  • addEventScript <label> <event> <path> [*args...]
  • enableCronScript <label>
  • removeCronScript <label>
  • enableEventScript <label>
  • removeEventScript <label>

We use C++ introspection to figure out the other methods that can be called for a given node.

(lo_type)types[1] == LO_CHAR )

void spin::spinBaseContext::removeInfoHandler ( EventHandler obs)

Remove an INFO channel event handler

int spin::spinBaseContext::sceneCallback ( const char *  path,
const char *  types,
lo_arg **  argv,
int  argc,
void *  data,
void *  user_data 
) [static]

Callback for the OSC message to the whole scene.

The address of the OSC messages sent to the scene are in the form /SPIN/<scene id>=""> <method name>=""> [args...]

They are used mostly to delete all nodes from a scene, or to ask the server to refresh the information about all nodes. It's also possible to save the current scene graph to an XML file, and to load a previously saved XML file.

Some valid method include:

  • clear
  • clearUsers
  • clearStates
  • userRefresh
  • refresh
  • refreshSubscribers
  • getNodeList
  • nodeList [node names...] : Creates many nodes
  • stateList [] : Creates many state sets
  • exportScene [] []
  • load [XML file]
  • save [XML file]
  • saveAll [XML file]
  • saveUsers [XML file]
  • createNode [node name] [node type]
  • createStateSet [name] [type]
  • deleteNode [name]
  • deleteGraph [name]
void spin::spinBaseContext::setTTL ( int  ttl)

Set the time-to-live for multicast packets (corresponds to the number of routers a packet will hop).

bool spin::spinBaseContext::startThread ( void *(*)(void *)  threadFunction)

Starts the context thread (passed as *threadFunction from a derived class)

Startup point of the server's thread.

Startup point of the server's thread.

void spin::spinBaseContext::stop ( )

Stops the currently running thread


Member Data Documentation

Enable or disable multicast discovery services, which uses the INFO port.

For a server, this disables sending via spinApp::infoMessage. For a client, this disables the info port listener callback in spinClientContext.

Multicast group and port number to which the server sends the addresses and port numbers on which it sends and receives.

std::vector<lo_address> spin::spinBaseContext::lo_rxAddrs_

List of address/port combinations on which the server listens for messages that alters the scene graph.

std::vector<lo_server> spin::spinBaseContext::lo_rxServs_

List of OSC receivers on which the server listens for messages that alters the scene graph.

Multicast group and port number to which the server sends messages to synchronize stuff for which timing matters.

std::vector<lo_address> spin::spinBaseContext::lo_txAddrs_

List of clients to send to, each is an address and port combination to which the server sends updates to the scene. The vector usually just contains one multicast address, but for special situations (eg, across many routers, it's sometimes easier to use a list of addresses)

volatile bool spin::spinBaseContext::signalStop = false [static]

Signal handler.

Called, for example, when the user presses Control-C

All threads need to stop according to the following flag:

All threads need to stop according to the following flag. Note this used to be a public class member, but we have sigHandler, which should be used instead


The documentation for this class was generated from the following files: