comparison mupdf-source/thirdparty/tesseract/src/viewer/svutil.h @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 ///////////////////////////////////////////////////////////////////////
2 // 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 //
17 ///////////////////////////////////////////////////////////////////////
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
35 namespace tesseract {
36
37 /// The SVSync class provides functionality for Thread & Process Creation
38 class SVSync {
39 public:
40 /// Starts a new process.
41 static void StartProcess(const char *executable, const char *args);
42 };
43
44 /// A semaphore class which encapsulates the main signaling
45 /// and wait abilities of semaphores for windows and unix.
46 class SVSemaphore {
47 public:
48 /// Sets up a semaphore.
49 SVSemaphore();
50 /// Cleans up the mutex
51 ~SVSemaphore();
52 /// Signal a semaphore.
53 void Signal();
54 /// Wait on a semaphore.
55 void Wait();
56
57 private:
58 #ifdef _WIN32
59 HANDLE semaphore_;
60 #elif defined(__APPLE__)
61 sem_t *semaphore_;
62 #else
63 sem_t semaphore_;
64 #endif
65 };
66
67 /// The SVNetwork class takes care of the remote connection for ScrollView
68 /// This means setting up and maintaining a remote connection, sending and
69 /// receiving messages and closing the connection.
70 /// It is designed to work on both Linux and Windows.
71 class SVNetwork {
72 public:
73 /// Set up a connection to hostname on port.
74 SVNetwork(const char *hostname, int port);
75
76 /// Destructor.
77 ~SVNetwork();
78
79 /// Put a message in the messagebuffer to the server and try to send it.
80 void Send(const char *msg);
81
82 /// Receive a message from the server.
83 /// This will always return one line of char* (denoted by \\n).
84 char *Receive();
85
86 /// Close the connection to the server.
87 void Close();
88
89 /// Flush the buffer.
90 void Flush();
91
92 private:
93 /// The mutex for access to Send() and Flush().
94 std::mutex mutex_send_;
95 /// The actual stream_ to the server.
96 int stream_;
97 /// Stores the last received message-chunk from the server.
98 char *msg_buffer_in_;
99
100 /// Stores the messages which are supposed to go out.
101 std::string msg_buffer_out_;
102
103 /// Where we are at in our msg_buffer_in_
104 char *buffer_ptr_; // strtok_r, strtok_s
105 };
106
107 } // namespace tesseract
108
109 #endif // TESSERACT_VIEWER_SVUTIL_H_