17 #if defined(__ANDROID__) 33 #undef VRPN_USE_WINSOCK_SOCKETS 38 #if defined(_WIN32) && \ 39 (!defined(__CYGWIN__) || defined(VRPN_CYGWIN_USES_WINSOCK_SOCKETS)) 40 #define VRPN_USE_WINSOCK_SOCKETS 43 #ifndef VRPN_USE_WINSOCK_SOCKETS 45 #define INVALID_SOCKET -1 49 #if !(defined(_WIN32) && defined(VRPN_USE_WINSOCK_SOCKETS)) 50 #include <sys/select.h> 51 #include <netinet/in.h> 55 #define perror(x) fprintf(stderr, "%s\n", x); 66 #define VRPN_USE_WINDOWS_GETHOSTBYNAME_HACK 87 #if (!defined(VRPN_USE_WINSOCK_SOCKETS)) 89 #define vrpn_gettimeofday gettimeofday 90 #else // winsock sockets 102 #ifndef WIN32_LEAN_AND_MEAN 103 #define WIN32_LEAN_AND_MEAN 107 #include <sys/timeb.h> 109 #ifdef VRPN_USE_WINSOCK2 110 #include <winsock2.h> 125 #if defined(VRPN_EXPORT_GETTIMEOFDAY) && !defined(_STRUCT_TIMEZONE) && \ 126 !defined(_TIMEZONE_DEFINED) 127 #define _TIMEZONE_DEFINED 134 #if defined(VRPN_EXPORT_GETTIMEOFDAY) && !defined(_STRUCT_TIMEZONE) 135 #define _STRUCT_TIMEZONE 138 #define gettimeofday vrpn_gettimeofday 159 const struct timeval &tv2);
161 const struct timeval &tv2);
167 struct timeval startT);
172 struct timeval startT);
175 const struct timeval &tv2);
177 const struct timeval &tv2);
200 static const int vrpn_int_data_for_endian_test = 1;
201 static const char *vrpn_char_data_for_endian_test =
202 (
char *)(
void *)(&vrpn_int_data_for_endian_test);
203 static const bool vrpn_big_endian = (vrpn_char_data_for_endian_test[0] != 1);
207 const char *
string, vrpn_int32 length);
265 inline vrpn_uint8
hton(vrpn_uint8 hostval) {
return hostval; }
268 inline vrpn_uint8
ntoh(vrpn_uint8 netval) {
return netval; }
271 inline vrpn_uint16
hton(vrpn_uint16 hostval) {
return htons(hostval); }
274 inline vrpn_uint16
ntoh(vrpn_uint16 netval) {
return ntohs(netval); }
277 inline vrpn_uint32
hton(vrpn_uint32 hostval) {
return htonl(hostval); }
280 inline vrpn_uint32
ntoh(vrpn_uint32 netval) {
return ntohl(netval); }
290 template <
typename T>
inline T
hton(T input)
296 inVal.asInput = input;
297 outVal.asInt =
hton(inVal.asInt);
298 return outVal.asInput;
303 template <
typename T>
inline T
ntoh(T input)
309 inVal.asInput = input;
310 outVal.asInt =
ntoh(inVal.asInt);
311 return outVal.asInput;
329 enum { SIZE_OF_BUFFER_ITEM_IS_NOT_ONE_BYTE };
333 #ifdef VRPN_USE_STATIC_ASSERTIONS 334 #if defined(__GXX_EXPERIMENTAL_CXX0X__) || \ 337 (defined(_MSC_VER) && (_MSC_VER >= 1600)) 338 #define VRPN_STATIC_ASSERT(CONDITION, MESSAGE) \ 339 static_assert(CONDITION, #MESSAGE) 341 #define VRPN_STATIC_ASSERT(CONDITION, MESSAGE) \ 342 (void)(::vrpn_detail::vrpn_static_assert<CONDITION>::MESSAGE) 347 #define VRPN_STATIC_ASSERT(CONDITION, MESSAGE) assert((CONDITION) && #MESSAGE) 354 template <
typename T,
typename ByteT>
355 static inline T vrpn_unbuffer_from_little_endian(ByteT *&input)
363 typename ::vrpn_detail::remove_const<ByteT>::type bytes[
sizeof(T)];
368 for (
unsigned int i = 0, j =
sizeof(T) - 1; i <
sizeof(T); ++i, --j) {
369 value.bytes[i] = input[j];
376 return ntoh(value.typed);
391 typename ::vrpn_detail::remove_const<ByteT>::type bytes[
sizeof(T)];
396 memcpy(value.bytes, input,
sizeof(T));
402 return ntoh(value.typed);
409 template <
typename T,
typename ByteT>
410 inline int vrpn_buffer(ByteT **insertPt, vrpn_int32 *buflen,
const T inVal)
416 if ((insertPt == NULL) || (buflen == NULL)) {
417 fprintf(stderr,
"vrpn_buffer: NULL pointer\n");
421 if (
sizeof(T) > static_cast<size_t>(*buflen)) {
422 fprintf(stderr,
"vrpn_buffer: buffer not large enough\n");
428 typename ::vrpn_detail::remove_const<ByteT>::type bytes[
sizeof(T)];
433 value.typed =
hton(inVal);
436 memcpy(*insertPt, value.bytes,
sizeof(T));
439 *insertPt +=
sizeof(T);
441 *buflen -=
sizeof(T);
446 template <
typename T,
typename ByteT>
449 *lvalue = ::vrpn_unbuffer<T, ByteT>(*input);
459 #if defined(sgi) || (defined(_WIN32) && !defined(__CYGWIN__)) || \ 460 defined(linux) || defined(__APPLE__) 461 #define vrpn_THREADS_AVAILABLE 463 #undef vrpn_THREADS_AVAILABLE 470 #elif defined(_WIN32) 474 #include <semaphore.h> 479 #pragma set woff 1110, 1424, 3201 484 #pragma reset woff 1110, 1424, 3201 499 bool reset(
int cNumResources = 1);
523 static usptr_t *ppaArena;
524 static void allocArena();
530 #elif defined(_WIN32) 568 #elif defined(_WIN32) 584 static bool available();
587 static unsigned number_of_processors();
593 void userData(
void *pvNewUserData);
602 static void threadFuncShell(
void *pvThread);
606 static void *threadFuncShellPosix(
void *pvThread);
#define VRPN_STATIC_ASSERT(CONDITION, MESSAGE)
Fall back to normal asserts.
VRPN_API bool vrpn_TimevalEqual(const struct timeval &tv1, const struct timeval &tv2)
VRPN_API void vrpn_SleepMsecs(double dMsecs)
VRPN_API struct timeval vrpn_MsecsTimeval(const double dMsecs)
VRPN_API unsigned long vrpn_TimevalDuration(struct timeval endT, struct timeval startT)
Return number of microseconds between startT and endT.
void(* vrpn_THREAD_FUNC)(vrpn_ThreadData &threadData)
VRPN_API double vrpn_TimevalDurationSeconds(struct timeval endT, struct timeval startT)
Return the number of seconds between startT and endT as a floating-point value.
VRPN_API vrpn_float64 vrpn_ntohd(vrpn_float64 d)
bool vrpn_test_threads_and_semaphores(void)
VRPN_API int vrpn_buffer(char **insertPt, vrpn_int32 *buflen, const char *string, vrpn_int32 length)
Utility routine for placing a character string of given length into a buffer that is to be sent as a ...
vrpn_uint8 hton(vrpn_uint8 hostval)
host to network byte order for 8-bit uints is a no-op
VRPN_API bool vrpn_TimevalGreater(const struct timeval &tv1, const struct timeval &tv2)
vrpn_uint8 ntoh(vrpn_uint8 netval)
network to host byte order for 8-bit uints is a no-op
VRPN_API struct timeval vrpn_TimevalNormalize(const struct timeval &tv)
VRPN_API double vrpn_TimevalMsecs(const struct timeval &tv1)
VRPN_API struct timeval vrpn_TimevalDiff(const struct timeval &tv1, const struct timeval &tv2)
#define vrpn_gettimeofday
VRPN_API vrpn_float64 vrpn_htond(vrpn_float64 d)
VRPN_API struct timeval vrpn_TimevalScale(const struct timeval &tv, double scale)
Traits class to get the uint type of a given size.
VRPN_API int vrpn_unbuffer(const char **buffer, char *string, vrpn_int32 length)
Utility routine for taking a string of specified length from a buffer that was sent as a message...
VRPN_API struct timeval vrpn_TimevalSum(const struct timeval &tv1, const struct timeval &tv2)
Internal header providing unbuffering facilities for a number of types.