00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00019
00020
00021
00022
00023
00024 #ifndef TESSERACT_VIEWER_SVUTIL_H__
00025 #define TESSERACT_VIEWER_SVUTIL_H__
00026
00027 #ifdef WIN32
00028 #include <windows.h>
00029 #define snprintf _snprintf
00030 #if (_MSC_VER <= 1400)
00031 #define vsnprintf _vsnprintf
00032 #endif
00033 #pragma warning(disable:4786)
00034 #else
00035 #include <pthread.h>
00036 #include <semaphore.h>
00037 #endif
00038
00039 #include <string>
00040
00041 #ifndef MAX
00042 #define MAX(a, b) ((a > b) ? a : b)
00043 #endif
00044
00045 #ifndef MIN
00046 #define MIN(a, b) ((a < b) ? a : b)
00047 #endif
00048
00050 class SVSync {
00051 public:
00053 static void StartThread(void *(*func)(void*), void* arg);
00055 static void ExitThread();
00057 static void StartProcess(const char* executable, const char* args);
00058 };
00059
00062 class SVSemaphore {
00063 public:
00065 SVSemaphore();
00067 void Signal();
00069 void Wait();
00070 private:
00071 #ifdef WIN32
00072 HANDLE semaphore_;
00073 #else
00074 sem_t semaphore_;
00075 #endif
00076 };
00077
00080 class SVMutex {
00081 public:
00083 SVMutex();
00085 void Lock();
00087 void Unlock();
00088 private:
00089 #ifdef WIN32
00090 HANDLE mutex_;
00091 #else
00092 pthread_mutex_t mutex_;
00093 #endif
00094 };
00095
00100 class SVNetwork {
00101 public:
00103 SVNetwork(const char* hostname, int port);
00104
00106 ~SVNetwork();
00107
00109 void Send(const char* msg);
00110
00113 char* Receive();
00114
00116 void Close();
00117
00119 void Flush();
00120
00121 private:
00123 SVMutex* mutex_send_;
00125 int stream_;
00127 char* msg_buffer_in_;
00128
00130 std::string msg_buffer_out_;
00131
00132 bool has_content;
00134 char* buffer_ptr_;
00135 };
00136
00137 #endif // TESSERACT_VIEWER_SVUTIL_H__