Software
Some useful bits of software
Shared - Coin3D shared via CORBA
This library provides a simple shared scene graph using Coin3D and CORBA. It implements the following extension nodes that share their state via CORBA event channels:
- SharedData - distributes field values
- SharedEngine - distributes connected fields
- SharedGroup - distributes children
These nodes distribute information in a simple symmetric way. Changes observed at one instance are send to all other instances. Updates are applied as they are received. There are no guarantees on the ordering, however, any properties of the underlying CORBA event channel implementation are preserved. Thus, if it delivers messages to all clients in the same order, the changes to the nodes will be in the same order for all instances.
Organisation of nodes into communicating groups is only via event channels. Each node has a SoSFString field channel that contains a URI describing the channel to connect to. All nodes using the same channel form will distribute changes among them. shared depends on omniORB CORBA and omniEvents EventService implementations. Typically, a correctly setup NameService and EventService are required to use it.
Shared is distributed under LGPL and is available here shared-1.0.tgz.
A simple example of a SharedData node:
SharedData {
fields [ SoSFString text , SoSFVec3f position ]
channel "corbaname:rir:#maptable/TestChannel"
interval 0.1
text "Hello World"
position 1 0 0
}
C++ Template-based Finite State Machine
This small header file fsm.h provides a simple state machine implementation based on C++ template programming. It supports handling incoming events and entry/exit calls for each state. It does not support hierarchical state machines, tracing, explicit start/stop states etc.
It's aim is to be usable with minimal overhead in the client code. Thus, there is no need to declare and implement hierarchies of state classes or construct tables of state transitions and functions to call. The following code shows a simple usage example of a light switch that only receives a single kind of event:
enum States { OFF, ON }; // possible states used in the state machine
struct LightSwitch { // a simple lightswitch
typedef LIST2(OFF, ON) StateList; // List of states
// default templates are for undefined handlers
template <int> int event() { cout << "undefined event handler" << endl; return 0; }
template <int> void enter() { cout << "undefined enter" << endl; }
template <int> void exit() { cout << "undefined leave" << endl; };
};
/// implement the specializations for states that require behaviour
template <> int LightSwitch::event<ON>() { cout << "reveived push" << endl; return OFF; };
template <> int LightSwitch::event<OFF>() { cout << "received push" << endl; return ON; };
template <> void LightSwitch::enter<ON>() { cout << "enter ON - turn on" << endl; }
template <> void LightSwitch::enter<OFF>() { cout << "enter OFF - turn off" << endl; }
template <> void LightSwitch::exit<ON>() { cout << "exit ON - do nothing" << endl; }
template <> void LightSwitch::exit<OFF>() { cout << "exit OFF - do nothing" << endl; }
int main() {
LightSwitch c;
StateMachine<LightSwitch> sm(c);
sm.work();
sm.work();
sm.work();
}
Links to the code:
- fsm.h - finite state machine header file
- lightswitch.cpp - simple example
- lightswitch_complex.cpp - example with arbitrary event type passed in