Go to the documentation of this file.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 #ifndef __GNUC__
00029 #include <windows.h>
00030 #define snprintf _snprintf
00031 #if (_MSC_VER <= 1400)
00032 #define vsnprintf _vsnprintf
00033 #endif
00034 #pragma warning(disable:4786)
00035 #else
00036 #include "platform.h"
00037 #include <windows.h>
00038 #endif
00039 #else
00040 #include <pthread.h>
00041 #include <semaphore.h>
00042 #endif
00043
00044 #include <string>
00045
00046 #ifndef MAX
00047 #define MAX(a, b) ((a > b) ? a : b)
00048 #endif
00049
00050 #ifndef MIN
00051 #define MIN(a, b) ((a < b) ? a : b)
00052 #endif
00053
00055 class SVSync {
00056 public:
00058 static void StartThread(void *(*func)(void*), void* arg);
00060 static void ExitThread();
00062 static void StartProcess(const char* executable, const char* args);
00063 };
00064
00067 class SVSemaphore {
00068 public:
00070 SVSemaphore();
00072 void Signal();
00074 void Wait();
00075 private:
00076 #ifdef _WIN32
00077 HANDLE semaphore_;
00078 #else
00079 sem_t semaphore_;
00080 #endif
00081 };
00082
00085 class SVMutex {
00086 public:
00088 SVMutex();
00090 void Lock();
00092 void Unlock();
00093 private:
00094 #ifdef _WIN32
00095 HANDLE mutex_;
00096 #else
00097 pthread_mutex_t mutex_;
00098 #endif
00099 };
00100
00105 class SVNetwork {
00106 public:
00108 SVNetwork(const char* hostname, int port);
00109
00111 ~SVNetwork();
00112
00114 void Send(const char* msg);
00115
00118 char* Receive();
00119
00121 void Close();
00122
00124 void Flush();
00125
00126 private:
00128 SVMutex* mutex_send_;
00130 int stream_;
00132 char* msg_buffer_in_;
00133
00135 std::string msg_buffer_out_;
00136
00137 bool has_content;
00139 char* buffer_ptr_;
00140 };
00141
00142 #endif // TESSERACT_VIEWER_SVUTIL_H__