42 , d_requestSerializer_type(-1)
43 , d_grantSerializer_type(-1)
44 , d_assumeSerializer_type(-1)
45 , d_lamportUpdate_type(-1)
46 , d_isSerializer(vrpn_TRUE)
47 , d_isNegotiatingSerializer(vrpn_FALSE)
48 , d_queueSets(vrpn_FALSE)
50 , d_lastLamportUpdate(NULL)
51 , d_deferredUpdateCallbacks(NULL)
67 vrpn_int32 gotConnection_type;
73 fprintf(stderr,
"vrpn_SharedObject::~vrpn_SharedObject(): delete failed\n");
81 fprintf(stderr,
"vrpn_SharedObject::~vrpn_SharedObject(): delete failed\n");
122 fprintf(stderr,
"vrpn_SharedObject::bindConnection: "
123 "Tried to rebind a connection to %s.\n",
188 fprintf(stderr,
"vrpn_SharedObject::registerDeferredUpdateCallback: "
202 vrpn_bool acceptedUpdate)
208 if (acceptedUpdate && isLocalSet) {
368void vrpn_SharedObject::postBindCleanup(
void)
370 vrpn_int32 gotConnection_type;
399 , d_value(defaultValue)
401 , d_timedCallbacks(NULL)
403 , d_policyCallback(NULL)
404 , d_policyUserdata(NULL)
419vrpn_Shared_int32::operator vrpn_int32()
const {
return value(); }
425 return set(newValue, now);
430 return set(newValue, when, vrpn_TRUE);
438 fprintf(stderr,
"vrpn_Shared_int32::register_handler: "
461 fprintf(stderr,
"vrpn_Shared_int32::unregister_handler: "
462 "Handler not found.\n");
470 fprintf(stderr,
"vrpn_Shared_int32::unregister_handler(): delete failed\n");
481 fprintf(stderr,
"vrpn_Shared_int32::register_handler: "
504 fprintf(stderr,
"vrpn_Shared_int32::unregister_handler: "
505 "Handler not found.\n");
513 fprintf(stderr,
"vrpn_Shared_int32::unregister_handler(): delete failed\n");
528 vrpn_bool isLocalSet,
531 vrpn_bool acceptedUpdate;
534 if (acceptedUpdate) {
554 vrpn_bool isLocalSet,
656 vrpn_int32 newValue, timeval when)
const
662 vrpn_int32 newValue, timeval when,
669 for (i = 0; i < t->
size(); i++) {
675 vrpn_int32 *newValue, timeval *when)
const
681 vrpn_int32 *newValue, timeval *when,
691 try { array =
new vrpn_uint32[size]; }
696 for (i = 0; i < size; i++) {
706 fprintf(stderr,
"vrpn_Shared_int32::decodeLamport(): delete failed\n");
716 vrpn_int32 buflen = 32;
727 fprintf(stderr,
"vrpn_Shared_int32::sendUpdate(): delete failed\n");
731 encode(&bp, &buflen, newValue, when);
770 set(newValue, when, vrpn_FALSE);
791 s->
set(newValue, when, vrpn_FALSE, t);
797 fprintf(stderr,
"vrpn_Shared_int32::handle_lamportUpdate(): delete failed\n");
808 vrpn_int32 defaultValue,
809 vrpn_int32 defaultMode)
834 vrpn_int32 defaultValue,
835 vrpn_int32 defaultMode)
858 vrpn_float64 defaultValue,
861 , d_value(defaultValue)
863 , d_timedCallbacks(NULL)
865 , d_policyCallback(NULL)
866 , d_policyUserdata(NULL)
886vrpn_Shared_float64::operator vrpn_float64()
const {
return value(); }
892 return set(newValue, now);
898 return set(newValue, when, vrpn_TRUE);
906 fprintf(stderr,
"vrpn_Shared_float64::register_handler: "
928 fprintf(stderr,
"vrpn_Shared_float64::unregister_handler: "
929 "Handler not found.\n");
937 fprintf(stderr,
"vrpn_Shared_float64::unregister_handler(): delete failed\n");
947 fprintf(stderr,
"vrpn_Shared_float64::register_handler: "
969 fprintf(stderr,
"vrpn_Shared_float64::unregister_handler: "
970 "Handler not found.\n");
978 fprintf(stderr,
"vrpn_Shared_float64::unregister_handler(): delete failed\n");
994 vrpn_bool isLocalSet)
996 vrpn_bool acceptedUpdate;
999 if (acceptedUpdate) {
1019 vrpn_bool isLocalSet)
1087 vrpn_float64 newValue, timeval when)
const
1093 vrpn_float64 *newValue, timeval *when)
const
1107 vrpn_int32 buflen = 32;
1111 encode(&bp, &buflen, newValue, when);
1140 vrpn_float64 newValue;
1145 set(newValue, when, vrpn_FALSE);
1151 const char *name, vrpn_float64 defaultValue, vrpn_int32 defaultMode)
1177 const char *name, vrpn_float64 defaultValue, vrpn_int32 defaultMode)
1202 const char *defaultValue,
1205 , d_value(defaultValue ? new char[1 + strlen(defaultValue)] : NULL)
1207 , d_timedCallbacks(NULL)
1209 , d_policyCallback(NULL)
1210 , d_policyUserdata(NULL)
1214 strcpy(
d_value, defaultValue);
1229 fprintf(stderr,
"vrpn_Shared_String::~vrpn_Shared_String(): delete failed\n");
1241vrpn_Shared_String::operator
const char *()
const {
return value(); }
1247 return set(newValue, now);
1252 return set(newValue, when, vrpn_TRUE);
1261 fprintf(stderr,
"vrpn_Shared_String::register_handler: "
1262 "Out of memory.\n");
1280 snitch = &(e->
next);
1284 fprintf(stderr,
"vrpn_Shared_String::unregister_handler: "
1285 "Handler not found.\n");
1293 fprintf(stderr,
"vrpn_Shared_String::unregister_handler(): delete failed\n");
1304 fprintf(stderr,
"vrpn_Shared_String::register_handler: "
1305 "Out of memory.\n");
1323 snitch = &(e->
next);
1327 fprintf(stderr,
"vrpn_Shared_String::unregister_handler: "
1328 "Handler not found.\n");
1336 fprintf(stderr,
"vrpn_Shared_String::unregister_handler(): delete failed\n");
1351 vrpn_bool isLocalSet)
1353 vrpn_bool acceptedUpdate;
1356 if (acceptedUpdate) {
1363 fprintf(stderr,
"vrpn_Shared_String::set(): delete failed\n");
1367 try {
d_value =
new char[1 + strlen(newValue)]; }
1369 fprintf(stderr,
"vrpn_Shared_String::set: Out of memory.\n");
1395 vrpn_bool isLocalSet)
1463 const char *newValue, timeval when)
const
1469 static_cast<vrpn_int32
>(strlen(newValue)));
1472 char *newValue, timeval *when)
const
1476 newValue[*len -
sizeof(*when)] = 0;
1484 vrpn_int32 buflen = 1024;
1488 encode(&bp, &buflen, newValue, when);
1517 char newValue[1024];
1522 set(newValue, when, vrpn_FALSE);
1528 const char *defaultValue,
1529 vrpn_int32 defaultMode)
1554 const char *defaultValue,
1555 vrpn_int32 defaultMode)
Generic connection class not specific to the transport mechanism.
void addReference()
Counting references to this connection.
virtual vrpn_int32 register_message_type(const char *name)
virtual int pack_message(vrpn_uint32 len, struct timeval time, vrpn_int32 type, vrpn_int32 sender, const char *buffer, vrpn_uint32 class_of_service)
Pack a message that will be sent the next time mainloop() is called. Turn off the RELIABLE flag if yo...
virtual vrpn_int32 register_sender(const char *name)
Get a token to use for the string name of the sender or type. Remember to check for -1 meaning failur...
virtual int unregister_handler(vrpn_int32 type, vrpn_MESSAGEHANDLER handler, void *userdata, vrpn_int32 sender=vrpn_ANY_SENDER)
virtual int register_handler(vrpn_int32 type, vrpn_MESSAGEHANDLER handler, void *userdata, vrpn_int32 sender=vrpn_ANY_SENDER)
Set up (or remove) a handler for a message of a given type. Optionally, specify which sender to handl...
Implements a distributed event clock as defined by Leslie Lamport in some seminal papers I can't find...
void receive(const vrpn_LamportTimestamp &)
Updates this clock to reflect a timestamp received from another clock/host.
vrpn_LamportTimestamp * getTimestampAndAdvance(void)
Increments the current timestamp and returns it.
Timestamp for a single event, produced by a vrpn_LamportClock and hopefully generally usable in place...
int size(void) const
Returns the number of hosts participating in the timestamp.
void serverPostBindCleanup(void)
vrpn_bool isSerializer(void) const
const char * name(void) const
deferredUpdateCallbackEntry * d_deferredUpdateCallbacks
static int VRPN_CALLBACK handle_grantSerializer(void *, vrpn_HANDLERPARAM)
vrpn_int32 d_grantSerializer_type
Sent by the serializer to grant a request.
void becomeSerializer(void)
Requests that this instance of the shared object becomes the serializer (i.e. lock-arbitrator),...
virtual void sendUpdate(void)=0
Should invoke default sendUpdate() for this derived type.
vrpn_bool d_isNegotiatingSerializer
As long as we have inorder delivery, this should be sufficient to keep us from getting many at once.
vrpn_bool registerDeferredUpdateCallback(vrpnDeferredUpdateCallback, void *userdata)
The specified function will be passed userdata when this particular shared object defers an update (r...
vrpn_bool d_queueSets
If this is true, no set()s are processed; instead, they are queued for later execution....
static int VRPN_CALLBACK handle_update(void *, vrpn_HANDLERPARAM)
Passes arguments to handleUpdate() for this type; registered in postBindCleanup();.
virtual ~vrpn_SharedObject(void)
vrpn_int32 d_assumeSerializer_type
Sent by a new serializer once it has been notified that its request has been granted.
vrpn_LamportClock * d_lClock
static int VRPN_CALLBACK handle_requestSerializer(void *, vrpn_HANDLERPARAM)
vrpn_LamportTimestamp * d_lastLamportUpdate
vrpn_SharedObject(const char *name, const char *tname, vrpn_int32 mode)
vrpn_bool d_isSerializer
default to vrpn_TRUE for servers, FALSE for remotes
void remotePostBindCleanup(void)
static int VRPN_CALLBACK handle_assumeSerializer(void *, vrpn_HANDLERPARAM)
vrpn_Connection * d_connection
virtual int handleUpdate(vrpn_HANDLERPARAM)=0
int yankDeferredUpdateCallbacks(void)
returns -1 on error (i.e. nonzero return by a callback)
virtual vrpn_bool shouldSendUpdate(vrpn_bool isLocalSet, vrpn_bool acceptedUpdate)
void useLamportClock(vrpn_LamportClock *)
Lamport Clocks are NOT currently integrated. They should provide serialization (virtual timestamps) t...
virtual void bindConnection(vrpn_Connection *)
Every derived class should call this, do what it needs to, and ALSO call {server,remote}PostBindClean...
static int VRPN_CALLBACK handle_gotConnection(void *, vrpn_HANDLERPARAM)
Register this handler in postBindCleanup(); it calls sendUpdate() to make sure the remote has the cor...
vrpn_int32 d_requestSerializer_type
Sent to the serializer to assume its duties.
virtual ~vrpn_Shared_String_Remote(void)
vrpn_Shared_String_Remote & operator=(const char *)
vrpn_Shared_String_Remote(const char *name, const char *defaultValue=NULL, vrpn_int32 defaultMode=VRPN_SO_DEFAULT)
virtual void bindConnection(vrpn_Connection *)
Every derived class should call this, do what it needs to, and ALSO call {server,remote}PostBindClean...
virtual void bindConnection(vrpn_Connection *)
Every derived class should call this, do what it needs to, and ALSO call {server,remote}PostBindClean...
virtual ~vrpn_Shared_String_Server(void)
vrpn_Shared_String_Server & operator=(const char *)
vrpn_Shared_String_Server(const char *name, const char *defaultValue=NULL, vrpn_int32 defaultMode=VRPN_SO_DEFAULT)
int handleUpdate(vrpn_HANDLERPARAM)
virtual ~vrpn_Shared_String(void)
void decode(const char **buffer, vrpn_int32 *len, char *newValue, timeval *when) const
timedCallbackEntry * d_timedCallbacks
void setSerializerPolicy(vrpn_SerializerPolicy policy=vrpn_ACCEPT, vrpnSharedStringSerializerPolicy f=NULL, void *userdata=NULL)
virtual void sendUpdate(void)
Should invoke default sendUpdate() for this derived type.
vrpn_Shared_String(const char *name, const char *defaultValue=NULL, vrpn_int32 mode=VRPN_SO_DEFAULT)
callbackEntry * d_callbacks
virtual vrpn_Shared_String & set(const char *newValue, timeval when)
int yankCallbacks(vrpn_bool isLocal)
vrpn_Shared_String & operator=(const char *newValue)
vrpn_SerializerPolicy d_policy
void encode(char **buffer, vrpn_int32 *len, const char *newValue, timeval when) const
void unregister_handler(vrpnSharedStringCallback, void *)
const char * value(void) const
vrpn_bool register_handler(vrpnSharedStringCallback, void *)
vrpnSharedStringSerializerPolicy d_policyCallback
virtual vrpn_bool shouldAcceptUpdate(const char *newValue, timeval when, vrpn_bool isLocalSet)
virtual ~vrpn_Shared_float64_Remote(void)
virtual void bindConnection(vrpn_Connection *)
Every derived class should call this, do what it needs to, and ALSO call {server,remote}PostBindClean...
vrpn_Shared_float64_Remote(const char *name, vrpn_float64 defaultValue=0, vrpn_int32 defaultMode=VRPN_SO_DEFAULT)
vrpn_Shared_float64_Remote & operator=(vrpn_float64 newValue)
vrpn_Shared_float64_Server(const char *name, vrpn_float64 defaultValue=0, vrpn_int32 defaultMode=VRPN_SO_DEFAULT)
virtual ~vrpn_Shared_float64_Server(void)
virtual void bindConnection(vrpn_Connection *)
Every derived class should call this, do what it needs to, and ALSO call {server,remote}PostBindClean...
vrpn_Shared_float64_Server & operator=(vrpn_float64 newValue)
void setSerializerPolicy(vrpn_SerializerPolicy policy=vrpn_ACCEPT, vrpnSharedFloatSerializerPolicy f=NULL, void *userdata=NULL)
vrpn_Shared_float64(const char *name, vrpn_float64 defaultValue=0.0, vrpn_int32 mode=VRPN_SO_DEFAULT)
vrpn_SerializerPolicy d_policy
vrpn_Shared_float64 & operator=(vrpn_float64 newValue)
int yankCallbacks(vrpn_bool isLocal)
callbackEntry * d_callbacks
void unregister_handler(vrpnSharedFloatCallback, void *)
int handleUpdate(vrpn_HANDLERPARAM)
vrpnSharedFloatSerializerPolicy d_policyCallback
virtual ~vrpn_Shared_float64(void)
vrpn_float64 value(void) const
timedCallbackEntry * d_timedCallbacks
virtual void sendUpdate(void)
Should invoke default sendUpdate() for this derived type.
virtual vrpn_bool shouldAcceptUpdate(vrpn_float64 newValue, timeval when, vrpn_bool isLocalSet)
void encode(char **buffer, vrpn_int32 *len, vrpn_float64 newValue, timeval when) const
void decode(const char **buffer, vrpn_int32 *len, vrpn_float64 *newValue, timeval *when) const
void register_handler(vrpnSharedFloatCallback, void *)
virtual vrpn_Shared_float64 & set(vrpn_float64 newValue, timeval when)
vrpn_Shared_int32_Remote(const char *name, vrpn_int32 defaultValue=0, vrpn_int32 defaultMode=VRPN_SO_DEFAULT)
virtual void bindConnection(vrpn_Connection *)
Every derived class should call this, do what it needs to, and ALSO call {server,remote}PostBindClean...
virtual ~vrpn_Shared_int32_Remote(void)
vrpn_Shared_int32_Remote & operator=(vrpn_int32 newValue)
vrpn_Shared_int32_Server & operator=(vrpn_int32 newValue)
vrpn_Shared_int32_Server(const char *name, vrpn_int32 defaultValue=0, vrpn_int32 defaultMode=VRPN_SO_DEFAULT)
virtual ~vrpn_Shared_int32_Server(void)
virtual void bindConnection(vrpn_Connection *)
Every derived class should call this, do what it needs to, and ALSO call {server,remote}PostBindClean...
static int VRPN_CALLBACK handle_lamportUpdate(void *, vrpn_HANDLERPARAM)
vrpn_bool register_handler(vrpnSharedIntCallback, void *)
callbackEntry * d_callbacks
vrpn_SerializerPolicy d_policy
void decodeLamport(const char **buffer, vrpn_int32 *len, vrpn_int32 *newValue, timeval *when, vrpn_LamportTimestamp **t) const
void encodeLamport(char **buffer, vrpn_int32 *len, vrpn_int32 newValue, timeval when, vrpn_LamportTimestamp *t) const
void decode(const char **buffer, vrpn_int32 *len, vrpn_int32 *newValue, timeval *when) const
vrpn_Shared_int32 & set(vrpn_int32 newValue, timeval when)
vrpn_int32 value(void) const
vrpnSharedIntSerializerPolicy d_policyCallback
vrpn_Shared_int32(const char *name, vrpn_int32 defaultValue=0, vrpn_int32 mode=VRPN_SO_DEFAULT)
int yankCallbacks(vrpn_bool isLocal)
virtual void sendUpdate(void)
Should invoke default sendUpdate() for this derived type.
virtual vrpn_bool shouldAcceptUpdate(vrpn_int32 newValue, timeval when, vrpn_bool isLocalSet, vrpn_LamportTimestamp *)
void unregister_handler(vrpnSharedIntCallback, void *)
int handleUpdate(vrpn_HANDLERPARAM)
vrpn_Shared_int32 & operator=(vrpn_int32 newValue)
void encode(char **buffer, vrpn_int32 *len, vrpn_int32 newValue, timeval when) const
timedCallbackEntry * d_timedCallbacks
void setSerializerPolicy(vrpn_SerializerPolicy policy=vrpn_ACCEPT, vrpnSharedIntSerializerPolicy f=NULL, void *userdata=NULL)
virtual ~vrpn_Shared_int32(void)
This structure is what is passed to a vrpn_Connection message callback.
deferredUpdateCallbackEntry * next
vrpnDeferredUpdateCallback handler
vrpnSharedStringCallback handler
vrpnTimedSharedStringCallback handler
timedCallbackEntry * next
vrpnSharedFloatCallback handler
timedCallbackEntry * next
vrpnTimedSharedFloatCallback handler
vrpnSharedIntCallback handler
timedCallbackEntry * next
vrpnTimedSharedIntCallback handler
const char * vrpn_got_connection
const vrpn_uint32 vrpn_CONNECTION_RELIABLE
Classes of service for messages, specify multiple by ORing them together Priority of satisfying these...
int(VRPN_CALLBACK * vrpnTimedSharedStringCallback)(void *userdata, const char *newValue, timeval when, vrpn_bool isLocal)
int(VRPN_CALLBACK * vrpnTimedSharedFloatCallback)(void *userdata, vrpn_float64 newValue, timeval when, vrpn_bool isLocal)
int(VRPN_CALLBACK * vrpnSharedStringCallback)(void *userdata, const char *newValue, vrpn_bool isLocal)
int(VRPN_CALLBACK * vrpnDeferredUpdateCallback)(void *userdata)
int(VRPN_CALLBACK * vrpnSharedFloatCallback)(void *userdata, vrpn_float64 newValue, vrpn_bool isLocal)
int(VRPN_CALLBACK * vrpnSharedStringSerializerPolicy)(void *userdata, const char *newValue, timeval when, vrpn_Shared_String *object)
int(VRPN_CALLBACK * vrpnSharedIntCallback)(void *userdata, vrpn_int32 newValue, vrpn_bool isLocal)
#define VRPN_SO_DEFER_UPDATES
int(VRPN_CALLBACK * vrpnSharedFloatSerializerPolicy)(void *userdata, vrpn_float64 newValue, timeval when, vrpn_Shared_float64 *object)
int(VRPN_CALLBACK * vrpnTimedSharedIntCallback)(void *userdata, vrpn_int32 newValue, timeval when, vrpn_bool isLocal)
class VRPN_API vrpn_LamportTimestamp
int(VRPN_CALLBACK * vrpnSharedIntSerializerPolicy)(void *userdata, vrpn_int32 newValue, timeval when, vrpn_Shared_int32 *object)
#define VRPN_SO_IGNORE_IDEMPOTENT
#define VRPN_SO_IGNORE_OLD
VRPN_API int vrpn_unbuffer(const char **buffer, timeval *t)
Utility routine for taking a struct timeval from a buffer that was sent as a message.
bool vrpn_TimevalGreater(const timeval &tv1, const timeval &tv2)
VRPN_API int vrpn_buffer(char **insertPt, vrpn_int32 *buflen, const timeval t)
Utility routine for placing a timeval struct into a buffer that is to be sent as a message.
bool vrpn_TimevalEqual(const timeval &tv1, const timeval &tv2)
#define vrpn_gettimeofday