tesseract  5.0.0-alpha-619-ge9db
svutil.h
Go to the documentation of this file.
1 // File: svutil.h
3 // Description: ScrollView Utilities
4 // Author: Joern Wanke
5 //
6 // (C) Copyright 2007, Google Inc.
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
18 //
19 // SVUtil contains the SVSync, SVSemaphore and SVNetwork
20 // classes, which are used for thread/process creation & synchronization
21 // and network connection.
22 
23 #ifndef TESSERACT_VIEWER_SVUTIL_H_
24 #define TESSERACT_VIEWER_SVUTIL_H_
25 
26 #ifdef _WIN32
27 # include "host.h" // also includes windows.h
28 #else
29 #include <semaphore.h>
30 #endif
31 
32 #include <mutex>
33 #include <string>
34 
36 class SVSync {
37  public:
39  static void StartProcess(const char* executable, const char* args);
40 };
41 
44 class SVSemaphore {
45  public:
47  SVSemaphore();
49  void Signal();
51  void Wait();
52  private:
53 #ifdef _WIN32
54  HANDLE semaphore_;
55 #elif defined(__APPLE__)
56  sem_t *semaphore_;
57 #else
58  sem_t semaphore_;
59 #endif
60 };
61 
66 class SVNetwork {
67  public:
69  SVNetwork(const char* hostname, int port);
70 
72  ~SVNetwork();
73 
75  void Send(const char* msg);
76 
79  char* Receive();
80 
82  void Close();
83 
85  void Flush();
86 
87  private:
89  std::mutex mutex_send_;
91  int stream_;
93  char* msg_buffer_in_;
94 
96  std::string msg_buffer_out_;
97 
98  bool has_content; // Win32 (strtok)
100  char* buffer_ptr_; // Unix (strtok_r)
101 };
102 
103 #endif // TESSERACT_VIEWER_SVUTIL_H_
string
std::string string
Definition: equationdetect_test.cc:21
SVSemaphore
Definition: svutil.h:44
SVNetwork::Flush
void Flush()
Flush the buffer.
Definition: svutil.cpp:155
host.h
SVSemaphore::Signal
void Signal()
Signal a semaphore.
Definition: svutil.cpp:128
SVSync::StartProcess
static void StartProcess(const char *executable, const char *args)
Starts a new process.
Definition: svutil.cpp:60
SVNetwork::Close
void Close()
Close the connection to the server.
Definition: svutil.cpp:213
SVNetwork::Receive
char * Receive()
Definition: svutil.cpp:165
SVSemaphore::SVSemaphore
SVSemaphore()
Sets up a semaphore.
Definition: svutil.cpp:112
SVSync
The SVSync class provides functionality for Thread & Process Creation.
Definition: svutil.h:36
SVSemaphore::Wait
void Wait()
Wait on a semaphore.
Definition: svutil.cpp:138
SVNetwork::~SVNetwork
~SVNetwork()
Destructor.
Definition: svutil.cpp:339
SVNetwork::SVNetwork
SVNetwork(const char *hostname, int port)
Set up a connection to hostname on port.
Definition: svutil.cpp:264
SVNetwork
Definition: svutil.h:66
SVNetwork::Send
void Send(const char *msg)
Put a message in the messagebuffer to the server and try to send it.
Definition: svutil.cpp:149