vrpn 07.35
Virtual Reality Peripheral Network
Loading...
Searching...
No Matches
vrpn_SharedObject.C
Go to the documentation of this file.
1#include <stdio.h> // for fprintf, stderr, sprintf
2#include <string.h> // for NULL, strcpy, strlen, etc
3
4#include "vrpn_Connection.h" // for vrpn_Connection, etc
5#include "vrpn_LamportClock.h" // for vrpn_LamportTimestamp, etc
6#include "vrpn_SharedObject.h"
7
8struct timeval;
9
10// We can't put d_lastUpdate in the message header timestamps; it must
11// go in the body.
12// This is because we're (probably) using a synchronized connection,
13// and VRPN clock sync munges these timestamps.
14// If we send a message from A to B and it gets sent back to A, attempting
15// to preserve the timestamp at both ends, but sending it over a synchronized
16// connection, its timestamp will end up equal to the original timestamp
17// PLUS the network RTT (round-trip time).
18// The original design intent of a vrpn_SharedObject was to be able to use
19// timestamps as message identifiers/sequencers, so they need to be invariant
20// over several network hops.
21
22// Note on Lamport clocks: the implementation was never completed
23// (see vrpn_LamportClock.[C,h]), so it's use here has been disabled in the
24// following ways. First, the code that considers the Lamport clock
25// in vrpn_Shared_int32::shouldAcceptUpdates(...) is commented out
26// (the other shared objects, float64 and String, never had code to
27// consider the Lamport clock). Second, the body of the method
28// vrpn_SharedObject::useLamportClock is commented out so that a
29// Lamport clock is never started.
30
31vrpn_SharedObject::vrpn_SharedObject(const char *name, const char *tname,
32 vrpn_int32 mode)
33 : d_name(NULL)
34 , d_mode(mode)
35 , d_typename(NULL)
36 , d_connection(NULL)
37 , d_serverId(-1)
38 , d_remoteId(-1)
39 , d_myId(-1)
40 , d_peerId(-1)
41 , d_update_type(-1)
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)
49 , d_lClock(NULL)
50 , d_lastLamportUpdate(NULL)
51 , d_deferredUpdateCallbacks(NULL)
52{
53 if (name) {
54 d_name = new char[1 + strlen(name)];
55 strcpy(d_name, name);
56 }
57 if (tname) {
58 d_typename = new char[1 + strlen(tname)];
59 strcpy(d_typename, tname);
60 }
62}
63
64// virtual
66{
67 vrpn_int32 gotConnection_type;
68
69 if (d_name) {
70 try {
71 delete[] d_name;
72 } catch (...) {
73 fprintf(stderr, "vrpn_SharedObject::~vrpn_SharedObject(): delete failed\n");
74 return;
75 }
76 }
77 if (d_typename) {
78 try {
79 delete[] d_typename;
80 } catch (...) {
81 fprintf(stderr, "vrpn_SharedObject::~vrpn_SharedObject(): delete failed\n");
82 return;
83 }
84 }
85 if (d_connection) {
87 d_peerId);
94
95 gotConnection_type =
97 d_connection->unregister_handler(gotConnection_type,
99
101 }
102}
103
104const char *vrpn_SharedObject::name(void) const { return d_name; }
105
106vrpn_bool vrpn_SharedObject::isSerializer(void) const { return VRPN_TRUE; }
107
108// virtual
110{
111 char buffer[101];
112 if (c == NULL) {
113 // unbind the connection
114 if (d_connection) {
116 }
117 d_connection = NULL;
118 return;
119 }
120
121 if (c && d_connection) {
122 fprintf(stderr, "vrpn_SharedObject::bindConnection: "
123 "Tried to rebind a connection to %s.\n",
124 d_name);
125 return;
126 }
127
128 d_connection = c;
129 c->addReference();
130 sprintf(buffer, "vrpn Shared server %s %s", d_typename, d_name);
131 d_serverId = c->register_sender(buffer);
132 sprintf(buffer, "vrpn Shared peer %s %s", d_typename, d_name);
133 d_remoteId = c->register_sender(buffer);
134 // d_updateFromServer_type = c->register_message_type
135 //("vrpn_Shared update_from_server");
136 // d_updateFromRemote_type = c->register_message_type
137 //("vrpn_Shared update_from_remote");
138 d_update_type = c->register_message_type("vrpn_Shared update");
139
140 // fprintf (stderr, "My name is %s; myId %d, ufs type %d, ufr type %d.\n",
141 // buffer, d_myId, d_updateFromServer_type, d_updateFromRemote_type);
142
144 c->register_message_type("vrpn_Shared request_serializer");
146 c->register_message_type("vrpn_Shared grant_serializer");
148 c->register_message_type("vrpn_Shared assume_serializer");
149}
150
152{
153
154 // NOTE: this is disabled
155 // d_lClock = l;
156}
157
159{
160 timeval now;
161
162 // Make sure only one request is outstanding
163
165 return;
166 }
167
168 d_isNegotiatingSerializer = vrpn_TRUE;
169
170 // send requestSerializer
171
172 if (d_connection) {
173 vrpn_gettimeofday(&now, NULL);
176 }
177
178 // fprintf(stderr, "sent requestSerializer\n");
179}
180
182 vrpnDeferredUpdateCallback cb, void *userdata)
183{
185
186 try { x = new deferredUpdateCallbackEntry; }
187 catch (...) {
188 fprintf(stderr, "vrpn_SharedObject::registerDeferredUpdateCallback: "
189 "Out of memory!\n");
190 return false;
191 }
192
193 x->handler = cb;
194 x->userdata = userdata;
197 return true;
198}
199
200// virtual
201vrpn_bool vrpn_SharedObject::shouldSendUpdate(vrpn_bool isLocalSet,
202 vrpn_bool acceptedUpdate)
203{
204
205 // fprintf(stderr, "In vrpn_SharedObject::shouldSendUpdate(%s).\n", d_name);
206
207 // Should handle all modes other than VRPN_SO_DEFER_UPDATES.
208 if (acceptedUpdate && isLocalSet) {
209 // fprintf(stderr, "..... accepted; local set => broadcast it.\n");
210 return vrpn_TRUE;
211 }
212
213 // Not a local set or (not accepted and not serializing)
214 if (!(d_mode & VRPN_SO_DEFER_UPDATES)) {
215 // fprintf(stderr, "..... rejected (NOT serialized).\n");
216 return vrpn_FALSE;
217 }
218
219 if (!d_isSerializer && isLocalSet) {
220 // fprintf(stderr, "..... not serializer; local set "
221 //"=> send it to the serializer.\n");
222 return vrpn_TRUE;
223 }
224
225 if (d_isSerializer && !isLocalSet && acceptedUpdate) {
226 // fprintf(stderr, "..... serializer; remote set; accepted =>
227 // broadcast it.\n");
228 return vrpn_TRUE;
229 }
230
231 // fprintf(stderr,"..... rejected (under serialization).\n");
232 return vrpn_FALSE;
233}
234
235// static
238{
239 vrpn_SharedObject *s = (vrpn_SharedObject *)userdata;
240 timeval now;
241
242 if (!s->isSerializer() || s->d_isNegotiatingSerializer) {
243 // ignore this
244 // we should probably return failure or error?
245 return 0;
246 }
247
248 s->d_isNegotiatingSerializer = vrpn_TRUE;
249
250 if (s->d_connection) {
251
252 // Don't set d_isSerializer to FALSE until they've assumed it.
253 // Until then, retain the serializer status but queue all of our
254 // messages; when they finish becoming the serializer, we
255 // set our flag to false and send the queue of set()s we've
256 // received to them.
257
258 // send grantSerializer
259
260 vrpn_gettimeofday(&now, NULL);
264 }
265
266 // start queueing set()s
267
268 s->d_queueSets = vrpn_TRUE;
269
270 // fprintf(stderr, "sent grantSerializer\n");
271 return 0;
272}
273
274// static
276{
277 vrpn_SharedObject *s = (vrpn_SharedObject *)userdata;
278 timeval now;
279
280 s->d_isSerializer = vrpn_TRUE;
281 s->d_isNegotiatingSerializer = vrpn_FALSE;
282
283 // send assumeSerializer
284
285 if (s->d_connection) {
286 vrpn_gettimeofday(&now, NULL);
290 }
291
292 // fprintf(stderr, "sent assumeSerializer\n");
293 return 0;
294}
295
296// static
299{
300 vrpn_SharedObject *s = (vrpn_SharedObject *)userdata;
301
302 s->d_isSerializer = vrpn_FALSE;
303 s->d_isNegotiatingSerializer = vrpn_FALSE;
304
305 // TODO: send queued set()s
306
307 return 0;
308}
309
311{
313
314 for (x = d_deferredUpdateCallbacks; x; x = x->next) {
315 if ((x->handler)(x->userdata)) {
316 return -1;
317 }
318 }
319
320 return 0;
321}
322
324{
327 postBindCleanup();
328}
329
331{
334 postBindCleanup();
335}
336
337// static
339{
340 vrpn_SharedObject *s = (vrpn_SharedObject *)userdata;
341
342 // Send an update to the remote so that they have the correct
343 // initial value for our state. Otherwise an attempt to synchronize
344 // something will assume we're at our initial value until our value
345 // changes, which is an error.
346
347 if (s->d_isSerializer) {
348 s->sendUpdate();
349 // fprintf(stderr, "%s: set client's value.\n", s->d_name);
350 }
351 else if (!(s->d_mode & VRPN_SO_DEFER_UPDATES) &&
352 (s->d_myId == s->d_serverId)) {
353 s->sendUpdate();
354 // fprintf(stderr, "%s: set remote's value.\n", s->d_name);
355 }
356
357 return 0;
358}
359
360// static
362{
363 vrpn_SharedObject *s = (vrpn_SharedObject *)userdata;
364
365 return s->handleUpdate(p);
366}
367
368void vrpn_SharedObject::postBindCleanup(void)
369{
370 vrpn_int32 gotConnection_type;
371
372 if (!d_connection) {
373 return;
374 }
375
376 // listen for update
377
379 d_peerId);
380
381 // listen for request/grant/assumeSerializer
382
389
390 gotConnection_type =
393 this, d_myId);
394}
395
396vrpn_Shared_int32::vrpn_Shared_int32(const char *name, vrpn_int32 defaultValue,
397 vrpn_int32 mode)
398 : vrpn_SharedObject(name, "int32", mode)
399 , d_value(defaultValue)
400 , d_callbacks(NULL)
401 , d_timedCallbacks(NULL)
402 , d_policy(vrpn_ACCEPT)
403 , d_policyCallback(NULL)
404 , d_policyUserdata(NULL)
405{
406}
407
408// virtual
410{
411 // if (d_connection) {
412 // d_connection->unregister_handler(d_becomeSerializer_type,
413 // handle_becomeSerializer, this, d_myId);
414 //}
415}
416
417vrpn_int32 vrpn_Shared_int32::value(void) const { return d_value; }
418
419vrpn_Shared_int32::operator vrpn_int32() const { return value(); }
420
422{
423 struct timeval now;
424 vrpn_gettimeofday(&now, NULL);
425 return set(newValue, now);
426}
427
428vrpn_Shared_int32 &vrpn_Shared_int32::set(vrpn_int32 newValue, timeval when)
429{
430 return set(newValue, when, vrpn_TRUE);
431}
433 void *userdata)
434{
435 callbackEntry *e;
436 try { e = new callbackEntry; }
437 catch (...) {
438 fprintf(stderr, "vrpn_Shared_int32::register_handler: "
439 "Out of memory.\n");
440 return false;
441 }
442 e->handler = cb;
443 e->userdata = userdata;
444 e->next = d_callbacks;
445 d_callbacks = e;
446 return true;
447}
448
450 void *userdata)
451{
452 callbackEntry *e, **snitch;
453
454 snitch = &d_callbacks;
455 e = *snitch;
456 while (e && (e->handler != cb) && (e->userdata != userdata)) {
457 snitch = &(e->next);
458 e = *snitch;
459 }
460 if (!e) {
461 fprintf(stderr, "vrpn_Shared_int32::unregister_handler: "
462 "Handler not found.\n");
463 return;
464 }
465
466 *snitch = e->next;
467 try {
468 delete e;
469 } catch (...) {
470 fprintf(stderr, "vrpn_Shared_int32::unregister_handler(): delete failed\n");
471 return;
472 }
473}
474
476 void *userdata)
477{
479 try { e = new timedCallbackEntry; }
480 catch (...) {
481 fprintf(stderr, "vrpn_Shared_int32::register_handler: "
482 "Out of memory.\n");
483 return false;
484 }
485 e->handler = cb;
486 e->userdata = userdata;
489 return true;
490}
491
493 void *userdata)
494{
495 timedCallbackEntry *e, **snitch;
496
497 snitch = &d_timedCallbacks;
498 e = *snitch;
499 while (e && (e->handler != cb) && (e->userdata != userdata)) {
500 snitch = &(e->next);
501 e = *snitch;
502 }
503 if (!e) {
504 fprintf(stderr, "vrpn_Shared_int32::unregister_handler: "
505 "Handler not found.\n");
506 return;
507 }
508
509 *snitch = e->next;
510 try {
511 delete e;
512 } catch (...) {
513 fprintf(stderr, "vrpn_Shared_int32::unregister_handler(): delete failed\n");
514 return;
515 }
516}
517
520 void *userdata)
521{
522 d_policy = policy;
524 d_policyUserdata = userdata;
525}
526
527vrpn_Shared_int32 &vrpn_Shared_int32::set(vrpn_int32 newValue, timeval when,
528 vrpn_bool isLocalSet,
530{
531 vrpn_bool acceptedUpdate;
532
533 acceptedUpdate = shouldAcceptUpdate(newValue, when, isLocalSet, t);
534 if (acceptedUpdate) {
535 d_value = newValue;
536 d_lastUpdate = when;
537 // yankCallbacks(isLocalSet);
538 }
539
540 if (shouldSendUpdate(isLocalSet, acceptedUpdate)) {
541 sendUpdate(newValue, when);
542 }
543
544 // yankCallbacks is placed after sendUpdate so that the update goes on the
545 // network before the updates due to local callbacks.
546 if (acceptedUpdate) yankCallbacks(isLocalSet);
547
548 return *this;
549}
550
551// virtual
552vrpn_bool vrpn_Shared_int32::shouldAcceptUpdate(vrpn_int32 newValue,
553 timeval when,
554 vrpn_bool isLocalSet,
556{
557
558 // fprintf(stderr, "In vrpn_Shared_int32::shouldAcceptUpdate(%s).\n",
559 // d_name);
560
561 /*
562 // this commented-out code uses Lamport logical clocks, and is
563 // disabled now b/c the implementation of Lamport clocks was
564 // never complete. We use standard timestamps instead.
565 vrpn_bool old, equal;
566 if (t) {
567 old = d_lastLamportUpdate && (*t < *d_lastLamportUpdate);
568 equal = d_lastLamportUpdate && (*t == *d_lastLamportUpdate);
569 } else {
570 old = !vrpn_TimevalGreater(when, d_lastUpdate);
571 equal = vrpn_TimevalEqual( when, d_lastUpdate );
572 }
573 */
574 vrpn_bool old = !vrpn_TimevalGreater(when, d_lastUpdate);
575 vrpn_bool equal = vrpn_TimevalEqual(when, d_lastUpdate);
576
577 // Is this "new" change idempotent?
578 if ((d_mode & VRPN_SO_IGNORE_IDEMPOTENT) && (newValue == d_value)) {
579 // fprintf(stderr, "... was idempotent.\n");
580 return vrpn_FALSE;
581 }
582
583 // Is this "new" change older than the previous change?
584 if ((d_mode & VRPN_SO_IGNORE_OLD) && old) {
585 // fprintf(stderr, "... was outdated.\n");
586 return vrpn_FALSE;
587 }
588 // Is this "new" change older than the previous change?
589 if ((d_mode & VRPN_SO_IGNORE_OLD) && old) {
590
591 // If the timestamps of the new & previous changes are equal:
592 // - if we are the serializer, we can accept the local change
593 // - if we are not the serializer, local updates are to be rejected
594 if (equal) {
595 if (!d_isSerializer && isLocalSet) {
596 return vrpn_FALSE;
597 }
598 }
599 else
600 return vrpn_FALSE;
601 }
602
603 // All other clauses of shouldAcceptUpdate depend on serialization
604 if (!(d_mode & VRPN_SO_DEFER_UPDATES)) {
605 return vrpn_TRUE;
606 }
607
608 // fprintf(stderr, "... serializing: ");
609
610 // If we're not the serializer, don't accept local set() calls -
611 // forward those to the serializer. Non-local set() calls are
612 // messages from the serializer that we should accept.
613 if (!d_isSerializer) {
614 if (isLocalSet) {
615 // fprintf(stderr, "local update, not serializer, so reject.\n");
617 return vrpn_FALSE;
618 }
619 else {
620 // fprintf(stderr, "remote update, not serializer, so accept.\n");
621 return vrpn_TRUE;
622 }
623 }
624
625 // We are the serializer.
626 // fprintf(stderr, "serializer: ");
627
628 if (isLocalSet) {
629 // fprintf(stderr, "local update.\n");
630 if (d_policy == vrpn_DENY_LOCAL) {
631 return vrpn_FALSE;
632 }
633 else {
634 return vrpn_TRUE;
635 }
636 }
637
638 // Are we accepting all updates?
639 if (d_policy == vrpn_ACCEPT) {
640 // fprintf(stderr, "policy is to accept.\n");
641 return vrpn_TRUE;
642 }
643
644 // Does the user want to accept this one?
646 (*d_policyCallback)(d_policyUserdata, newValue, when, this)) {
647 // fprintf(stderr, "user callback accepts.\n");
648 return vrpn_TRUE;
649 }
650
651 // fprintf(stderr, "rejected.\n");
652 return vrpn_FALSE;
653}
654
655void vrpn_Shared_int32::encode(char **buffer, vrpn_int32 *len,
656 vrpn_int32 newValue, timeval when) const
657{
658 vrpn_buffer(buffer, len, newValue);
659 vrpn_buffer(buffer, len, when);
660}
661void vrpn_Shared_int32::encodeLamport(char **buffer, vrpn_int32 *len,
662 vrpn_int32 newValue, timeval when,
663 vrpn_LamportTimestamp *t) const
664{
665 int i;
666 vrpn_buffer(buffer, len, newValue);
667 vrpn_buffer(buffer, len, when);
668 vrpn_buffer(buffer, len, t->size());
669 for (i = 0; i < t->size(); i++) {
670 vrpn_buffer(buffer, len, (*t)[i]);
671 }
672}
673
674void vrpn_Shared_int32::decode(const char **buffer, vrpn_int32 *,
675 vrpn_int32 *newValue, timeval *when) const
676{
677 vrpn_unbuffer(buffer, newValue);
678 vrpn_unbuffer(buffer, when);
679}
680void vrpn_Shared_int32::decodeLamport(const char **buffer, vrpn_int32 *,
681 vrpn_int32 *newValue, timeval *when,
682 vrpn_LamportTimestamp **t) const
683{
684 vrpn_uint32 size;
685 vrpn_uint32 *array;
686 unsigned int i;
687
688 vrpn_unbuffer(buffer, newValue);
689 vrpn_unbuffer(buffer, when);
690 vrpn_unbuffer(buffer, &size);
691 try { array = new vrpn_uint32[size]; }
692 catch (...) {
693 *t = NULL;
694 return;
695 }
696 for (i = 0; i < size; i++) {
697 vrpn_unbuffer(buffer, &array[i]);
698 }
699 vrpn_LamportTimestamp *ret = NULL;
700 try { ret = new vrpn_LamportTimestamp(size, array); }
701 catch (...) {}
702 *t = ret;
703 try {
704 delete[] array;
705 } catch (...) {
706 fprintf(stderr, "vrpn_Shared_int32::decodeLamport(): delete failed\n");
707 return;
708 }
709}
710
712
713void vrpn_Shared_int32::sendUpdate(vrpn_int32 newValue, timeval when)
714{
715 char buffer[32];
716 vrpn_int32 buflen = 32;
717 char *bp = buffer;
718
719 if (d_connection) {
720 if (d_lClock) {
723 encodeLamport(&bp, &buflen, newValue, when, t);
724 try {
725 delete t;
726 } catch (...) {
727 fprintf(stderr, "vrpn_Shared_int32::sendUpdate(): delete failed\n");
728 return;
729 }
730 } else {
731 encode(&bp, &buflen, newValue, when);
732 }
735 // fprintf(stderr, "vrpn_Shared_int32::sendUpdate: packed message of %d
736 // "
737 //"at %d:%d.\n", d_value, d_lastUpdate.tv_sec, d_lastUpdate.tv_usec);
738 }
739}
740
742{
743 callbackEntry *e;
745
746 for (e = d_callbacks; e; e = e->next) {
747 if ((*e->handler)(e->userdata, d_value, isLocal)) {
748 return -1;
749 }
750 }
751 for (te = d_timedCallbacks; te; te = te->next) {
752 if ((*te->handler)(te->userdata, d_value, d_lastUpdate, isLocal)) {
753 return -1;
754 }
755 }
756
757 return 0;
758}
759
761{
762 vrpn_int32 newValue;
763 timeval when;
764
765 decode(&p.buffer, &p.payload_len, &newValue, &when);
766
767 // fprintf(stderr, "%s::handleUpdate to %d at %d:%d.\n",
768 // d_name, newValue, when.tv_sec, when.tv_usec);
769
770 set(newValue, when, vrpn_FALSE);
771
772 // fprintf(stderr, "vrpn_Shared_int32::handleUpdate done\n");
773 return 0;
774}
775
776// static
778{
781 vrpn_int32 newValue;
782 timeval when;
783
784 s->decodeLamport(&p.buffer, &p.payload_len, &newValue, &when, &t);
785
786 // fprintf(stderr, "vrpn_Shared_int32::handleUpdate to %d at %d:%d.\n",
787 // newValue, when.tv_sec, when.tv_usec);
788
789 s->d_lClock->receive(*t);
790
791 s->set(newValue, when, vrpn_FALSE, t);
792
793 if (s->d_lastLamportUpdate) {
794 try {
795 delete s->d_lastLamportUpdate;
796 } catch (...) {
797 fprintf(stderr, "vrpn_Shared_int32::handle_lamportUpdate(): delete failed\n");
798 return -1;
799 }
800 }
801 s->d_lastLamportUpdate = t;
802
803 // fprintf(stderr, "vrpn_Shared_int32::handleUpdate done\n");
804 return 0;
805}
806
808 vrpn_int32 defaultValue,
809 vrpn_int32 defaultMode)
810 : vrpn_Shared_int32(name, defaultValue, defaultMode)
811{
812
813 d_isSerializer = vrpn_TRUE;
814}
815
816// virtual
818
820{
822 return *this;
823}
824
825// virtual
827{
829
831}
832
834 vrpn_int32 defaultValue,
835 vrpn_int32 defaultMode)
836 : vrpn_Shared_int32(name, defaultValue, defaultMode)
837{
838}
839
840// virtual
842
844{
846 return *this;
847}
848
850{
851
853
855}
856
858 vrpn_float64 defaultValue,
859 vrpn_int32 mode)
860 : vrpn_SharedObject(name, "float64", mode)
861 , d_value(defaultValue)
862 , d_callbacks(NULL)
863 , d_timedCallbacks(NULL)
864 , d_policy(vrpn_ACCEPT)
865 , d_policyCallback(NULL)
866 , d_policyUserdata(NULL)
867{
868
869 if (name) {
870 strcpy(d_name, name);
871 }
873}
874
875// virtual
877{
878 // if (d_connection) {
879 // d_connection->unregister_handler(d_becomeSerializer_type,
880 // handle_becomeSerializer, this, d_myId);
881 //}
882}
883
884vrpn_float64 vrpn_Shared_float64::value(void) const { return d_value; }
885
886vrpn_Shared_float64::operator vrpn_float64() const { return value(); }
887
889{
890 struct timeval now;
891 vrpn_gettimeofday(&now, NULL);
892 return set(newValue, now);
893}
894
896 timeval when)
897{
898 return set(newValue, when, vrpn_TRUE);
899}
900
902 void *userdata)
903{
905 if (!e) {
906 fprintf(stderr, "vrpn_Shared_float64::register_handler: "
907 "Out of memory.\n");
908 return;
909 }
910 e->handler = cb;
911 e->userdata = userdata;
912 e->next = d_callbacks;
913 d_callbacks = e;
914}
915
917 void *userdata)
918{
919 callbackEntry *e, **snitch;
920
921 snitch = &d_callbacks;
922 e = *snitch;
923 while (e && (e->handler != cb) && (e->userdata != userdata)) {
924 snitch = &(e->next);
925 e = *snitch;
926 }
927 if (!e) {
928 fprintf(stderr, "vrpn_Shared_float64::unregister_handler: "
929 "Handler not found.\n");
930 return;
931 }
932
933 *snitch = e->next;
934 try {
935 delete e;
936 } catch (...) {
937 fprintf(stderr, "vrpn_Shared_float64::unregister_handler(): delete failed\n");
938 return;
939 }
940}
941
943 void *userdata)
944{
946 if (!e) {
947 fprintf(stderr, "vrpn_Shared_float64::register_handler: "
948 "Out of memory.\n");
949 return;
950 }
951 e->handler = cb;
952 e->userdata = userdata;
955}
956
958 void *userdata)
959{
960 timedCallbackEntry *e, **snitch;
961
962 snitch = &d_timedCallbacks;
963 e = *snitch;
964 while (e && (e->handler != cb) && (e->userdata != userdata)) {
965 snitch = &(e->next);
966 e = *snitch;
967 }
968 if (!e) {
969 fprintf(stderr, "vrpn_Shared_float64::unregister_handler: "
970 "Handler not found.\n");
971 return;
972 }
973
974 *snitch = e->next;
975 try {
976 delete e;
977 } catch (...) {
978 fprintf(stderr, "vrpn_Shared_float64::unregister_handler(): delete failed\n");
979 return;
980 }
981}
982
985 void *userdata)
986{
987 d_policy = policy;
989 d_policyUserdata = userdata;
990}
991
993 timeval when,
994 vrpn_bool isLocalSet)
995{
996 vrpn_bool acceptedUpdate;
997
998 acceptedUpdate = shouldAcceptUpdate(newValue, when, isLocalSet);
999 if (acceptedUpdate) {
1000 d_value = newValue;
1001 d_lastUpdate = when;
1002 // yankCallbacks(isLocalSet);
1003 }
1004
1005 if (shouldSendUpdate(isLocalSet, acceptedUpdate)) {
1006 sendUpdate(newValue, when);
1007 }
1008
1009 // yankCallbacks is placed after sendUpdate so that the update goes on the
1010 // network before the updates due to local callbacks.
1011 if (acceptedUpdate) yankCallbacks(isLocalSet);
1012
1013 return *this;
1014}
1015
1016// virtual
1017vrpn_bool vrpn_Shared_float64::shouldAcceptUpdate(vrpn_float64 newValue,
1018 timeval when,
1019 vrpn_bool isLocalSet)
1020{
1021
1022 // Is this "new" change idempotent?
1023 if ((d_mode & VRPN_SO_IGNORE_IDEMPOTENT) && (newValue == d_value)) {
1024 return vrpn_FALSE;
1025 }
1026
1027 // Is this "new" change older than the previous change?
1028 if ((d_mode & VRPN_SO_IGNORE_OLD) &&
1030
1031 // If the timestamps of the new & previous changes are equal:
1032 // - if we are the serializer, we can accept the local change
1033 // - if we are not the serializer, local updates are to be rejected
1034 if (vrpn_TimevalEqual(when, d_lastUpdate)) {
1035 if (!d_isSerializer && isLocalSet) {
1036 return vrpn_FALSE;
1037 }
1038 }
1039 else
1040 return vrpn_FALSE;
1041 }
1042
1043 // All other clauses of shouldAcceptUpdate depend on serialization
1044 if (!(d_mode & VRPN_SO_DEFER_UPDATES)) {
1045 return vrpn_TRUE;
1046 }
1047
1048 // If we're not the serializer, don't accept local set() calls -
1049 // forward those to the serializer. Non-local set() calls are
1050 // messages from the serializer that we should accept.
1051 if (!d_isSerializer) {
1052 if (isLocalSet) {
1054 return vrpn_FALSE;
1055 }
1056 else {
1057 return vrpn_TRUE;
1058 }
1059 }
1060
1061 // We are the serializer.
1062
1063 if (isLocalSet) {
1064 if (d_policy == vrpn_DENY_LOCAL) {
1065 return vrpn_FALSE;
1066 }
1067 else {
1068 return vrpn_TRUE;
1069 }
1070 }
1071
1072 // Are we accepting all updates?
1073 if (d_policy == vrpn_ACCEPT) {
1074 return vrpn_TRUE;
1075 }
1076
1077 // Does the user want to accept this one?
1079 (*d_policyCallback)(d_policyUserdata, newValue, when, this)) {
1080 return vrpn_TRUE;
1081 }
1082
1083 return vrpn_FALSE;
1084}
1085
1086void vrpn_Shared_float64::encode(char **buffer, vrpn_int32 *len,
1087 vrpn_float64 newValue, timeval when) const
1088{
1089 vrpn_buffer(buffer, len, newValue);
1090 vrpn_buffer(buffer, len, when);
1091}
1092void vrpn_Shared_float64::decode(const char **buffer, vrpn_int32 *,
1093 vrpn_float64 *newValue, timeval *when) const
1094{
1095 vrpn_unbuffer(buffer, newValue);
1096 vrpn_unbuffer(buffer, when);
1097}
1098
1100{
1102}
1103
1104void vrpn_Shared_float64::sendUpdate(vrpn_float64 newValue, timeval when)
1105{
1106 char buffer[32];
1107 vrpn_int32 buflen = 32;
1108 char *bp = buffer;
1109
1110 if (d_connection) {
1111 encode(&bp, &buflen, newValue, when);
1114 // fprintf(stderr, "vrpn_Shared_float64::sendUpdate: packed
1115 // message\n");
1116 }
1117}
1118
1120{
1121 callbackEntry *e;
1123
1124 for (e = d_callbacks; e; e = e->next) {
1125 if ((*e->handler)(e->userdata, d_value, isLocal)) {
1126 return -1;
1127 }
1128 }
1129 for (te = d_timedCallbacks; te; te = te->next) {
1130 if ((*te->handler)(te->userdata, d_value, d_lastUpdate, isLocal)) {
1131 return -1;
1132 }
1133 }
1134
1135 return 0;
1136}
1137
1139{
1140 vrpn_float64 newValue;
1141 timeval when;
1142
1143 decode(&p.buffer, &p.payload_len, &newValue, &when);
1144
1145 set(newValue, when, vrpn_FALSE);
1146
1147 return 0;
1148}
1149
1151 const char *name, vrpn_float64 defaultValue, vrpn_int32 defaultMode)
1152 : vrpn_Shared_float64(name, defaultValue, defaultMode)
1153{
1154
1155 d_isSerializer = vrpn_TRUE;
1156}
1157
1158// virtual
1160
1162operator=(vrpn_float64 c)
1163{
1165 return *this;
1166}
1167
1168// virtual
1170{
1172
1174}
1175
1177 const char *name, vrpn_float64 defaultValue, vrpn_int32 defaultMode)
1178 : vrpn_Shared_float64(name, defaultValue, defaultMode)
1179{
1180}
1181
1182// virtual
1184
1186operator=(vrpn_float64 c)
1187{
1189 return *this;
1190}
1191
1192// virtual
1194{
1195
1197
1199}
1200
1202 const char *defaultValue,
1203 vrpn_int32 mode)
1204 : vrpn_SharedObject(name, "String", mode)
1205 , d_value(defaultValue ? new char[1 + strlen(defaultValue)] : NULL)
1206 , d_callbacks(NULL)
1207 , d_timedCallbacks(NULL)
1208 , d_policy(vrpn_ACCEPT)
1209 , d_policyCallback(NULL)
1210 , d_policyUserdata(NULL)
1211{
1212
1213 if (defaultValue) {
1214 strcpy(d_value, defaultValue);
1215 }
1216 if (name) {
1217 strcpy(d_name, name);
1218 }
1220}
1221
1222// virtual
1224{
1225 if (d_value) {
1226 try {
1227 delete[] d_value;
1228 } catch (...) {
1229 fprintf(stderr, "vrpn_Shared_String::~vrpn_Shared_String(): delete failed\n");
1230 return;
1231 }
1232 }
1233 // if (d_connection) {
1234 // d_connection->unregister_handler(d_becomeSerializer_type,
1235 // handle_becomeSerializer, this, d_myId);
1236 //}
1237}
1238
1239const char *vrpn_Shared_String::value(void) const { return d_value; }
1240
1241vrpn_Shared_String::operator const char *() const { return value(); }
1242
1244{
1245 struct timeval now;
1246 vrpn_gettimeofday(&now, NULL);
1247 return set(newValue, now);
1248}
1249
1250vrpn_Shared_String &vrpn_Shared_String::set(const char *newValue, timeval when)
1251{
1252 return set(newValue, when, vrpn_TRUE);
1253}
1254
1256 void *userdata)
1257{
1258 callbackEntry *e;
1259 try { e = new callbackEntry; }
1260 catch (...) {
1261 fprintf(stderr, "vrpn_Shared_String::register_handler: "
1262 "Out of memory.\n");
1263 return false;
1264 }
1265 e->handler = cb;
1266 e->userdata = userdata;
1267 e->next = d_callbacks;
1268 d_callbacks = e;
1269 return true;
1270}
1271
1273 void *userdata)
1274{
1275 callbackEntry *e, **snitch;
1276
1277 snitch = &d_callbacks;
1278 e = *snitch;
1279 while (e && (e->handler != cb) && (e->userdata != userdata)) {
1280 snitch = &(e->next);
1281 e = *snitch;
1282 }
1283 if (!e) {
1284 fprintf(stderr, "vrpn_Shared_String::unregister_handler: "
1285 "Handler not found.\n");
1286 return;
1287 }
1288
1289 *snitch = e->next;
1290 try {
1291 delete e;
1292 } catch (...) {
1293 fprintf(stderr, "vrpn_Shared_String::unregister_handler(): delete failed\n");
1294 return;
1295 }
1296}
1297
1299 void *userdata)
1300{
1302 try { e = new timedCallbackEntry; }
1303 catch (...) {
1304 fprintf(stderr, "vrpn_Shared_String::register_handler: "
1305 "Out of memory.\n");
1306 return false;
1307 }
1308 e->handler = cb;
1309 e->userdata = userdata;
1311 d_timedCallbacks = e;
1312 return true;
1313}
1314
1316 void *userdata)
1317{
1318 timedCallbackEntry *e, **snitch;
1319
1320 snitch = &d_timedCallbacks;
1321 e = *snitch;
1322 while (e && (e->handler != cb) && (e->userdata != userdata)) {
1323 snitch = &(e->next);
1324 e = *snitch;
1325 }
1326 if (!e) {
1327 fprintf(stderr, "vrpn_Shared_String::unregister_handler: "
1328 "Handler not found.\n");
1329 return;
1330 }
1331
1332 *snitch = e->next;
1333 try {
1334 delete e;
1335 } catch (...) {
1336 fprintf(stderr, "vrpn_Shared_String::unregister_handler(): delete failed\n");
1337 return;
1338 }
1339}
1340
1343 void *userdata)
1344{
1345 d_policy = policy;
1346 d_policyCallback = f;
1347 d_policyUserdata = userdata;
1348}
1349
1350vrpn_Shared_String &vrpn_Shared_String::set(const char *newValue, timeval when,
1351 vrpn_bool isLocalSet)
1352{
1353 vrpn_bool acceptedUpdate;
1354
1355 acceptedUpdate = shouldAcceptUpdate(newValue, when, isLocalSet);
1356 if (acceptedUpdate) {
1357
1358 if ((d_value == NULL) || (strcmp(d_value, newValue) != 0)) {
1359 if (d_value) {
1360 try {
1361 delete[] d_value;
1362 } catch (...) {
1363 fprintf(stderr, "vrpn_Shared_String::set(): delete failed\n");
1364 return *this;
1365 }
1366 }
1367 try { d_value = new char[1 + strlen(newValue)]; }
1368 catch (...) {
1369 fprintf(stderr, "vrpn_Shared_String::set: Out of memory.\n");
1370 return *this;
1371 }
1372 strcpy(d_value, newValue);
1373 }
1374
1375 // fprintf(stderr, "vrpn_Shared_String::set: %s to \"%s\".\n", name(),
1376 // value());
1377
1378 d_lastUpdate = when;
1379 }
1380
1381 if (shouldSendUpdate(isLocalSet, acceptedUpdate)) {
1382 sendUpdate(newValue, when);
1383 }
1384
1385 // yankCallbacks is placed after sendUpdate so that the update goes on the
1386 // network before the updates due to local callbacks.
1387 if (acceptedUpdate) yankCallbacks(isLocalSet);
1388
1389 return *this;
1390}
1391
1392// virtual
1393vrpn_bool vrpn_Shared_String::shouldAcceptUpdate(const char *newValue,
1394 timeval when,
1395 vrpn_bool isLocalSet)
1396{
1397
1398 // Is this "new" change idempotent?
1399 if ((d_mode & VRPN_SO_IGNORE_IDEMPOTENT) && (newValue == d_value)) {
1400 return vrpn_FALSE;
1401 }
1402
1403 // Is this "new" change older than the previous change?
1404 if ((d_mode & VRPN_SO_IGNORE_OLD) &&
1406
1407 // If the timestamps of the new & previous changes are equal:
1408 // - if we are the serializer, we can accept the local change
1409 // - if we are not the serializer, local updates are to be rejected
1410 if (vrpn_TimevalEqual(when, d_lastUpdate)) {
1411 if (!d_isSerializer && isLocalSet) {
1412 return vrpn_FALSE;
1413 }
1414 }
1415 else
1416 return vrpn_FALSE;
1417 }
1418
1419 // All other clauses of shouldAcceptUpdate depend on serialization
1420 if (!(d_mode & VRPN_SO_DEFER_UPDATES)) {
1421 return vrpn_TRUE;
1422 }
1423
1424 // If we're not the serializer, don't accept local set() calls -
1425 // forward those to the serializer. Non-local set() calls are
1426 // messages from the serializer that we should accept.
1427 if (!d_isSerializer) {
1428 if (isLocalSet) {
1430 return vrpn_FALSE;
1431 }
1432 else {
1433 return vrpn_TRUE;
1434 }
1435 }
1436
1437 // We are the serializer.
1438
1439 if (isLocalSet) {
1440 if (d_policy == vrpn_DENY_LOCAL) {
1441 return vrpn_FALSE;
1442 }
1443 else {
1444 return vrpn_TRUE;
1445 }
1446 }
1447
1448 // Are we accepting all updates?
1449 if (d_policy == vrpn_ACCEPT) {
1450 return vrpn_TRUE;
1451 }
1452
1453 // Does the user want to accept this one?
1455 (*d_policyCallback)(d_policyUserdata, newValue, when, this)) {
1456 return vrpn_TRUE;
1457 }
1458
1459 return vrpn_FALSE;
1460}
1461
1462void vrpn_Shared_String::encode(char **buffer, vrpn_int32 *len,
1463 const char *newValue, timeval when) const
1464{
1465 // We reverse ordering from the other vrpn_SharedObject classes
1466 // so that the time value is guaranteed to be aligned.
1467 vrpn_buffer(buffer, len, when);
1468 vrpn_buffer(buffer, len, newValue,
1469 static_cast<vrpn_int32>(strlen(newValue)));
1470}
1471void vrpn_Shared_String::decode(const char **buffer, vrpn_int32 *len,
1472 char *newValue, timeval *when) const
1473{
1474 vrpn_unbuffer(buffer, when);
1475 vrpn_unbuffer(buffer, newValue, *len - sizeof(*when));
1476 newValue[*len - sizeof(*when)] = 0;
1477}
1478
1480
1481void vrpn_Shared_String::sendUpdate(const char *newValue, timeval when)
1482{
1483 char buffer[1024]; // HACK
1484 vrpn_int32 buflen = 1024;
1485 char *bp = buffer;
1486
1487 if (d_connection) {
1488 encode(&bp, &buflen, newValue, when);
1491 // fprintf(stderr, "vrpn_Shared_String::sendUpdate: packed message\n");
1492 }
1493}
1494
1496{
1497 callbackEntry *e;
1499
1500 for (e = d_callbacks; e; e = e->next) {
1501 if ((*e->handler)(e->userdata, d_value, isLocal)) {
1502 return -1;
1503 }
1504 }
1505 for (te = d_timedCallbacks; te; te = te->next) {
1506 if ((*te->handler)(te->userdata, d_value, d_lastUpdate, isLocal)) {
1507 return -1;
1508 }
1509 }
1510
1511 return 0;
1512}
1513
1514// static
1516{
1517 char newValue[1024]; // HACK
1518 timeval when;
1519
1520 decode(&p.buffer, &p.payload_len, newValue, &when);
1521
1522 set(newValue, when, vrpn_FALSE);
1523
1524 return 0;
1525}
1526
1528 const char *defaultValue,
1529 vrpn_int32 defaultMode)
1530 : vrpn_Shared_String(name, defaultValue, defaultMode)
1531{
1532
1533 d_isSerializer = vrpn_TRUE;
1534}
1535
1536// virtual
1538
1540{
1542 return *this;
1543}
1544
1545// virtual
1547{
1549
1551}
1552
1554 const char *defaultValue,
1555 vrpn_int32 defaultMode)
1556 : vrpn_Shared_String(name, defaultValue, defaultMode)
1557{
1558}
1559
1560// virtual
1562
1564{
1566 return *this;
1567}
1568
1569// virtual
1571{
1572
1574
1576}
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.
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...
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 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 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.
const char * buffer
vrpnTimedSharedStringCallback 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
vrpn_SerializerPolicy
@ vrpn_DENY_LOCAL
@ vrpn_ACCEPT
@ vrpn_CALLBACK
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
Definition vrpn_Shared.h:99