33 : d_name(name ? new char[1 + strlen(name)] : NULL)
35 , d_typename(tname ? new char[1 + strlen(tname)] : NULL)
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)
66 vrpn_int32 gotConnection_type;
111 fprintf(stderr,
"vrpn_SharedObject::bindConnection: " 112 "Tried to rebind a connection to %s.\n",
177 fprintf(stderr,
"vrpn_SharedObject::registerDeferredUpdateCallback: " 190 vrpn_bool acceptedUpdate)
196 if (acceptedUpdate && isLocalSet) {
356 void vrpn_SharedObject::postBindCleanup(
void)
358 vrpn_int32 gotConnection_type;
387 , d_value(defaultValue)
389 , d_timedCallbacks(NULL)
391 , d_policyCallback(NULL)
392 , d_policyUserdata(NULL)
407 vrpn_Shared_int32::operator vrpn_int32()
const {
return value(); }
413 return set(newValue, now);
418 return set(newValue, when, vrpn_TRUE);
425 fprintf(stderr,
"vrpn_Shared_int32::register_handler: " 447 fprintf(stderr,
"vrpn_Shared_int32::unregister_handler: " 448 "Handler not found.\n");
461 fprintf(stderr,
"vrpn_Shared_int32::register_handler: " 483 fprintf(stderr,
"vrpn_Shared_int32::unregister_handler: " 484 "Handler not found.\n");
502 vrpn_bool isLocalSet,
505 vrpn_bool acceptedUpdate;
508 if (acceptedUpdate) {
528 vrpn_bool isLocalSet,
630 vrpn_int32 newValue, timeval when)
const 636 vrpn_int32 newValue, timeval when,
643 for (i = 0; i < t->
size(); i++) {
649 vrpn_int32 *newValue, timeval *when)
const 655 vrpn_int32 *newValue, timeval *when,
665 array =
new vrpn_uint32[size];
666 for (i = 0; i < size; i++) {
678 vrpn_int32 buflen = 32;
688 encode(&bp, &buflen, newValue, when);
727 set(newValue, when, vrpn_FALSE);
748 s->
set(newValue, when, vrpn_FALSE, t);
760 vrpn_int32 defaultValue,
761 vrpn_int32 defaultMode)
786 vrpn_int32 defaultValue,
787 vrpn_int32 defaultMode)
810 vrpn_float64 defaultValue,
813 , d_value(defaultValue)
815 , d_timedCallbacks(NULL)
817 , d_policyCallback(NULL)
818 , d_policyUserdata(NULL)
838 vrpn_Shared_float64::operator vrpn_float64()
const {
return value(); }
844 return set(newValue, now);
850 return set(newValue, when, vrpn_TRUE);
858 fprintf(stderr,
"vrpn_Shared_float64::register_handler: " 880 fprintf(stderr,
"vrpn_Shared_float64::unregister_handler: " 881 "Handler not found.\n");
894 fprintf(stderr,
"vrpn_Shared_float64::register_handler: " 916 fprintf(stderr,
"vrpn_Shared_float64::unregister_handler: " 917 "Handler not found.\n");
936 vrpn_bool isLocalSet)
938 vrpn_bool acceptedUpdate;
941 if (acceptedUpdate) {
961 vrpn_bool isLocalSet)
1029 vrpn_float64 newValue, timeval when)
const 1035 vrpn_float64 *newValue, timeval *when)
const 1049 vrpn_int32 buflen = 32;
1053 encode(&bp, &buflen, newValue, when);
1082 vrpn_float64 newValue;
1087 set(newValue, when, vrpn_FALSE);
1093 const char *name, vrpn_float64 defaultValue, vrpn_int32 defaultMode)
1119 const char *name, vrpn_float64 defaultValue, vrpn_int32 defaultMode)
1144 const char *defaultValue,
1147 , d_value(defaultValue ? new char[1 + strlen(defaultValue)] : NULL)
1149 , d_timedCallbacks(NULL)
1151 , d_policyCallback(NULL)
1152 , d_policyUserdata(NULL)
1156 strcpy(
d_value, defaultValue);
1178 vrpn_Shared_String::operator
const char *()
const {
return value(); }
1184 return set(newValue, now);
1189 return set(newValue, when, vrpn_TRUE);
1197 fprintf(stderr,
"vrpn_Shared_String::register_handler: " 1198 "Out of memory.\n");
1215 snitch = &(e->
next);
1219 fprintf(stderr,
"vrpn_Shared_String::unregister_handler: " 1220 "Handler not found.\n");
1233 fprintf(stderr,
"vrpn_Shared_String::register_handler: " 1234 "Out of memory.\n");
1251 snitch = &(e->
next);
1255 fprintf(stderr,
"vrpn_Shared_String::unregister_handler: " 1256 "Handler not found.\n");
1274 vrpn_bool isLocalSet)
1276 vrpn_bool acceptedUpdate;
1279 if (acceptedUpdate) {
1285 d_value =
new char[1 + strlen(newValue)];
1287 fprintf(stderr,
"vrpn_Shared_String::set: Out of memory.\n");
1313 vrpn_bool isLocalSet)
1381 const char *newValue, timeval when)
const 1387 static_cast<vrpn_int32>(strlen(newValue)));
1390 char *newValue, timeval *when)
const 1394 newValue[*len -
sizeof(*when)] = 0;
1402 vrpn_int32 buflen = 1024;
1406 encode(&bp, &buflen, newValue, when);
1435 char newValue[1024];
1440 set(newValue, when, vrpn_FALSE);
1446 const char *defaultValue,
1447 vrpn_int32 defaultMode)
1472 const char *defaultValue,
1473 vrpn_int32 defaultMode)
virtual int unregister_handler(vrpn_int32 type, vrpn_MESSAGEHANDLER handler, void *userdata, vrpn_int32 sender=vrpn_ANY_SENDER)
virtual ~vrpn_Shared_String_Remote(void)
virtual void sendUpdate(void)=0
Should invoke default sendUpdate() for this derived type.
void decode(const char **buffer, vrpn_int32 *len, vrpn_int32 *newValue, timeval *when) const
virtual ~vrpn_Shared_int32_Remote(void)
void remotePostBindCleanup(void)
vrpn_int32 value(void) const
static int VRPN_CALLBACK handle_update(void *, vrpn_HANDLERPARAM)
Passes arguments to handleUpdate() for this type; registered in postBindCleanup();.
void register_handler(vrpnSharedFloatCallback, void *)
vrpn_Shared_float64_Remote(const char *name, vrpn_float64 defaultValue=0, vrpn_int32 defaultMode=VRPN_SO_DEFAULT)
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.
int(VRPN_CALLBACK * vrpnTimedSharedStringCallback)(void *userdata, const char *newValue, timeval when, vrpn_bool isLocal)
vrpn_Shared_String & operator=(const char *newValue)
void setSerializerPolicy(vrpn_SerializerPolicy policy=vrpn_ACCEPT, vrpnSharedIntSerializerPolicy f=NULL, void *userdata=NULL)
Implements a distributed event clock as defined by Leslie Lamport in some seminal papers I can't find...
int size(void) const
Returns the number of hosts participating in the timestamp.
virtual vrpn_bool shouldAcceptUpdate(vrpn_int32 newValue, timeval when, vrpn_bool isLocalSet, vrpn_LamportTimestamp *)
vrpn_Shared_float64_Remote & operator=(vrpn_float64 newValue)
vrpn_bool d_isSerializer
default to vrpn_TRUE for servers, FALSE for remotes
int(VRPN_CALLBACK * vrpnSharedIntCallback)(void *userdata, vrpn_int32 newValue, vrpn_bool isLocal)
vrpnTimedSharedIntCallback handler
virtual void sendUpdate(void)
Should invoke default sendUpdate() for this derived type.
const vrpn_uint32 vrpn_CONNECTION_RELIABLE
Classes of service for messages, specify multiple by ORing them together Priority of satisfying these...
void encode(char **buffer, vrpn_int32 *len, const char *newValue, timeval when) const
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...
vrpn_bool isSerializer(void) const
vrpn_Shared_String_Server & operator=(const char *)
timedCallbackEntry * next
virtual ~vrpn_Shared_float64(void)
void unregister_handler(vrpnSharedIntCallback, void *)
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_Shared_String_Remote & operator=(const char *)
int(VRPN_CALLBACK * vrpnSharedFloatSerializerPolicy)(void *userdata, vrpn_float64 newValue, timeval when, vrpn_Shared_float64 *object)
static int VRPN_CALLBACK handle_requestSerializer(void *, vrpn_HANDLERPARAM)
int(VRPN_CALLBACK * vrpnTimedSharedFloatCallback)(void *userdata, vrpn_float64 newValue, timeval when, vrpn_bool isLocal)
#define VRPN_SO_IGNORE_IDEMPOTENT
void becomeSerializer(void)
Requests that this instance of the shared object becomes the serializer (i.e. lock-arbitrator),...
vrpnSharedFloatCallback handler
class VRPN_API vrpn_LamportTimestamp
void decodeLamport(const char **buffer, vrpn_int32 *len, vrpn_int32 *newValue, timeval *when, vrpn_LamportTimestamp **t) const
virtual ~vrpn_Shared_String(void)
vrpn_SerializerPolicy d_policy
vrpn_LamportClock * d_lClock
virtual ~vrpn_SharedObject(void)
vrpn_Shared_float64 & operator=(vrpn_float64 newValue)
vrpn_int32 d_grantSerializer_type
Sent by the serializer to grant a request.
callbackEntry * d_callbacks
vrpn_Shared_String_Server(const char *name, const char *defaultValue=NULL, vrpn_int32 defaultMode=VRPN_SO_DEFAULT)
int handleUpdate(vrpn_HANDLERPARAM)
vrpn_Shared_int32_Remote & operator=(vrpn_int32 newValue)
int(VRPN_CALLBACK * vrpnSharedFloatCallback)(void *userdata, vrpn_float64 newValue, vrpn_bool isLocal)
vrpn_bool d_isNegotiatingSerializer
As long as we have inorder delivery, this should be sufficient to keep us from getting many at once.
vrpn_SharedObject(const char *name, const char *tname, vrpn_int32 mode)
timedCallbackEntry * next
void serverPostBindCleanup(void)
Generic connection class not specific to the transport mechanism.
vrpn_Shared_int32 & set(vrpn_int32 newValue, timeval when)
int yankDeferredUpdateCallbacks(void)
returns -1 on error (i.e. nonzero return by a callback)
vrpn_bool d_queueSets
If this is true, no set()s are processed; instead, they are queued for later execution....
vrpnTimedSharedStringCallback handler
virtual vrpn_Shared_String & set(const char *newValue, timeval when)
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(const char *name, vrpn_float64 defaultValue=0, vrpn_int32 defaultMode=VRPN_SO_DEFAULT)
vrpn_Shared_String_Remote(const char *name, const char *defaultValue=NULL, vrpn_int32 defaultMode=VRPN_SO_DEFAULT)
void unregister_handler(vrpnSharedFloatCallback, void *)
void registerDeferredUpdateCallback(vrpnDeferredUpdateCallback, void *userdata)
The specified function will be passed userdata when this particular shared object defers an update (r...
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...
vrpnSharedIntSerializerPolicy d_policyCallback
vrpn_Connection * d_connection
int(VRPN_CALLBACK * vrpnSharedIntSerializerPolicy)(void *userdata, vrpn_int32 newValue, timeval when, vrpn_Shared_int32 *object)
virtual void bindConnection(vrpn_Connection *)
Every derived class should call this, do what it needs to, and ALSO call {server,remote}PostBindClean...
Timestamp for a single event, produced by a vrpn_LamportClock and hopefully generally usable in place...
vrpnSharedStringCallback handler
deferredUpdateCallbackEntry * d_deferredUpdateCallbacks
void receive(const vrpn_LamportTimestamp &)
Updates this clock to reflect a timestamp received from another clock/host.
This structure is what is passed to a vrpn_Connection message callback.
void encode(char **buffer, vrpn_int32 *len, vrpn_int32 newValue, timeval when) const
int(VRPN_CALLBACK * vrpnSharedStringSerializerPolicy)(void *userdata, const char *newValue, timeval when, vrpn_Shared_String *object)
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_bool shouldAcceptUpdate(const char *newValue, timeval when, vrpn_bool isLocalSet)
vrpn_Shared_int32_Server & operator=(vrpn_int32 newValue)
virtual vrpn_bool shouldAcceptUpdate(vrpn_float64 newValue, timeval when, vrpn_bool isLocalSet)
timedCallbackEntry * d_timedCallbacks
timedCallbackEntry * d_timedCallbacks
vrpn_LamportTimestamp * d_lastLamportUpdate
vrpn_int32 d_assumeSerializer_type
Sent by a new serializer once it has been notified that its request has been granted.
virtual ~vrpn_Shared_String_Server(void)
vrpn_SerializerPolicy d_policy
int yankCallbacks(vrpn_bool isLocal)
vrpnSharedFloatSerializerPolicy d_policyCallback
void useLamportClock(vrpn_LamportClock *)
Lamport Clocks are NOT currently integrated. They should provide serialization (virtual timestamps) t...
void unregister_handler(vrpnSharedStringCallback, void *)
virtual int handleUpdate(vrpn_HANDLERPARAM)=0
bool vrpn_TimevalGreater(const timeval &tv1, const timeval &tv2)
const char * vrpn_got_connection
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_float64 & set(vrpn_float64 newValue, timeval when)
vrpnSharedIntCallback handler
void setSerializerPolicy(vrpn_SerializerPolicy policy=vrpn_ACCEPT, vrpnSharedFloatSerializerPolicy f=NULL, void *userdata=NULL)
virtual vrpn_bool shouldSendUpdate(vrpn_bool isLocalSet, vrpn_bool acceptedUpdate)
vrpn_Shared_String(const char *name, const char *defaultValue=NULL, vrpn_int32 mode=VRPN_SO_DEFAULT)
void setSerializerPolicy(vrpn_SerializerPolicy policy=vrpn_ACCEPT, vrpnSharedStringSerializerPolicy f=NULL, void *userdata=NULL)
bool vrpn_TimevalEqual(const timeval &tv1, const timeval &tv2)
vrpn_Shared_int32_Server(const char *name, vrpn_int32 defaultValue=0, vrpn_int32 defaultMode=VRPN_SO_DEFAULT)
virtual void sendUpdate(void)
Should invoke default sendUpdate() for this derived type.
int(VRPN_CALLBACK * vrpnDeferredUpdateCallback)(void *userdata)
void encode(char **buffer, vrpn_int32 *len, vrpn_float64 newValue, timeval when) const
const char * value(void) const
virtual ~vrpn_Shared_int32_Server(void)
vrpn_Shared_float64(const char *name, vrpn_float64 defaultValue=0.0, vrpn_int32 mode=VRPN_SO_DEFAULT)
static int VRPN_CALLBACK handle_lamportUpdate(void *, vrpn_HANDLERPARAM)
void decode(const char **buffer, vrpn_int32 *len, char *newValue, timeval *when) const
void encodeLamport(char **buffer, vrpn_int32 *len, vrpn_int32 newValue, timeval when, vrpn_LamportTimestamp *t) const
virtual ~vrpn_Shared_float64_Remote(void)
vrpn_int32 d_requestSerializer_type
Sent to the serializer to assume its duties.
static int VRPN_CALLBACK handle_grantSerializer(void *, vrpn_HANDLERPARAM)
timedCallbackEntry * next
vrpn_LamportTimestamp * getTimestampAndAdvance(void)
Increments the current timestamp and returns it.
virtual void sendUpdate(void)
Should invoke default sendUpdate() for this derived type.
#define vrpn_gettimeofday
vrpnTimedSharedFloatCallback handler
virtual ~vrpn_Shared_float64_Server(void)
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.
vrpn_Shared_float64_Server & operator=(vrpn_float64 newValue)
int yankCallbacks(vrpn_bool isLocal)
vrpnSharedStringSerializerPolicy d_policyCallback
int handleUpdate(vrpn_HANDLERPARAM)
vrpn_float64 value(void) const
int handleUpdate(vrpn_HANDLERPARAM)
int yankCallbacks(vrpn_bool isLocal)
void register_handler(vrpnSharedIntCallback, void *)
int(VRPN_CALLBACK * vrpnSharedStringCallback)(void *userdata, const char *newValue, vrpn_bool isLocal)
virtual void bindConnection(vrpn_Connection *)
Every derived class should call this, do what it needs to, and ALSO call {server,remote}PostBindClean...
void decode(const char **buffer, vrpn_int32 *len, vrpn_float64 *newValue, timeval *when) const
virtual void bindConnection(vrpn_Connection *)
Every derived class should call this, do what it needs to, and ALSO call {server,remote}PostBindClean...
#define VRPN_SO_DEFER_UPDATES
vrpnDeferredUpdateCallback handler
vrpn_SerializerPolicy d_policy
static int VRPN_CALLBACK handle_assumeSerializer(void *, vrpn_HANDLERPARAM)
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(void)
const char * name(void) const
deferredUpdateCallbackEntry * next
void addReference()
Counting references to this connection.
vrpn_Shared_int32(const char *name, vrpn_int32 defaultValue=0, vrpn_int32 mode=VRPN_SO_DEFAULT)
void register_handler(vrpnSharedStringCallback, void *)
virtual vrpn_int32 register_message_type(const char *name)
virtual void bindConnection(vrpn_Connection *)
Every derived class should call this, do what it needs to, and ALSO call {server,remote}PostBindClean...
timedCallbackEntry * d_timedCallbacks
vrpn_Shared_int32 & operator=(vrpn_int32 newValue)
int(VRPN_CALLBACK * vrpnTimedSharedIntCallback)(void *userdata, vrpn_int32 newValue, timeval when, vrpn_bool isLocal)
#define VRPN_SO_IGNORE_OLD
callbackEntry * d_callbacks
callbackEntry * d_callbacks