Line data Source code
1 : /********************************************************************\
2 :
3 : Name: MSYSTEM.H
4 : Created by: Stefan Ritt
5 :
6 : Contents: Function declarations and constants for internal
7 : routines
8 :
9 : $Id$
10 :
11 : \********************************************************************/
12 :
13 : #ifndef _MSYSTEM_H
14 : #define _MSYSTEM_H
15 :
16 : /**dox***************************************************************/
17 : /** @file msystem.h
18 : The Midas System include file
19 : */
20 :
21 : /** @defgroup msdefineh System Defines
22 : */
23 : /** @defgroup msmacroh System Macros
24 : */
25 : /** @defgroup mssectionh System Structure Declarations
26 : */
27 :
28 : /**dox***************************************************************/
29 : #ifndef DOXYGEN_SHOULD_SKIP_THIS
30 :
31 : #include "midasinc.h"
32 : #include <string> // std::string
33 : #include <mutex> // std::mutex
34 :
35 : /**dox***************************************************************/
36 : #endif /* DOXYGEN_SHOULD_SKIP_THIS */
37 :
38 : /**dox***************************************************************/
39 : /** @addtogroup msdefineh
40 : * @{ */
41 :
42 : /**
43 : data representations
44 : */
45 : #define DRI_16 (1<<0) /**< - */
46 : #define DRI_32 (1<<1) /**< - */
47 : #define DRI_64 (1<<2) /**< - */
48 : #define DRI_LITTLE_ENDIAN (1<<3) /**< - */
49 : #define DRI_BIG_ENDIAN (1<<4) /**< - */
50 : #define DRF_IEEE (1<<5) /**< - */
51 : #define DRF_G_FLOAT (1<<6) /**< - */
52 : //#define DR_ASCII (1<<7) /**< - */
53 :
54 : /**dox***************************************************************/
55 : /** @} *//* end of msdefineh */
56 :
57 : /**dox***************************************************************/
58 : /** @addtogroup msmacroh
59 : * @{ */
60 :
61 : /* Byte and Word swapping big endian <-> little endian */
62 : /**
63 : SWAP WORD macro */
64 : #ifndef WORD_SWAP
65 : #define WORD_SWAP(x) { BYTE _tmp; \
66 : _tmp= *((BYTE *)(x)); \
67 : *((BYTE *)(x)) = *(((BYTE *)(x))+1); \
68 : *(((BYTE *)(x))+1) = _tmp; }
69 : #endif
70 :
71 : /**
72 : SWAP DWORD macro */
73 : #ifndef DWORD_SWAP
74 : #define DWORD_SWAP(x) { BYTE _tmp; \
75 : _tmp= *((BYTE *)(x)); \
76 : *((BYTE *)(x)) = *(((BYTE *)(x))+3); \
77 : *(((BYTE *)(x))+3) = _tmp; \
78 : _tmp= *(((BYTE *)(x))+1); \
79 : *(((BYTE *)(x))+1) = *(((BYTE *)(x))+2); \
80 : *(((BYTE *)(x))+2) = _tmp; }
81 : #endif
82 :
83 : /**
84 : SWAP QWORD macro */
85 : #ifndef QWORD_SWAP
86 : #define QWORD_SWAP(x) { BYTE _tmp; \
87 : _tmp= *((BYTE *)(x)); \
88 : *((BYTE *)(x)) = *(((BYTE *)(x))+7); \
89 : *(((BYTE *)(x))+7) = _tmp; \
90 : _tmp= *(((BYTE *)(x))+1); \
91 : *(((BYTE *)(x))+1) = *(((BYTE *)(x))+6); \
92 : *(((BYTE *)(x))+6) = _tmp; \
93 : _tmp= *(((BYTE *)(x))+2); \
94 : *(((BYTE *)(x))+2) = *(((BYTE *)(x))+5); \
95 : *(((BYTE *)(x))+5) = _tmp; \
96 : _tmp= *(((BYTE *)(x))+3); \
97 : *(((BYTE *)(x))+3) = *(((BYTE *)(x))+4); \
98 : *(((BYTE *)(x))+4) = _tmp; }
99 : #endif
100 :
101 : /**dox***************************************************************/
102 : /** @} *//* end of msmacroh */
103 :
104 : /**dox***************************************************************/
105 : /** @addtogroup msdefineh
106 : * @{ */
107 :
108 : /**
109 : Definition of implementation specific constants */
110 : #define MESSAGE_BUFFER_SIZE 100000 /**< buffer used for messages */
111 : #define MESSAGE_BUFFER_NAME "SYSMSG" /**< buffer name for messages */
112 : //#define MAX_RPC_CONNECTION 64 /**< server/client connections */
113 : #define MAX_STRING_LENGTH 256 /**< max string length for odb */
114 : #define NET_BUFFER_SIZE (8*1024*1024) /**< size of network receive buffers */
115 :
116 : /*------------------------------------------------------------------*/
117 : /* flag for conditional compilation of debug messages */
118 : #undef DEBUG_MSG
119 :
120 : /* flag for local routines (not for pure network clients) */
121 : #if !defined ( OS_MSDOS ) && !defined ( OS_VXWORKS )
122 : #define LOCAL_ROUTINES
123 : #endif
124 :
125 : #if defined(NO_LOCAL_ROUTINES)
126 : #undef LOCAL_ROUTINES
127 : #endif
128 :
129 : /* YBOS support not in MSDOS */
130 : #if !defined ( OS_MSDOS )
131 : #define YBOS_SUPPORT
132 : #endif
133 :
134 : /** @} */
135 :
136 : /*------------------------------------------------------------------*/
137 :
138 : /* Mapping of function names for socket operations */
139 :
140 : #ifdef OS_MSDOS
141 :
142 : #define closesocket(s) ::close(s)
143 : #define ioctlsocket(s,c,d) ::ioctl(s,c,d)
144 : #define malloc(i) farmalloc(i)
145 :
146 : #undef NET_TCP_SIZE
147 : #define NET_TCP_SIZE 0x7FFF
148 :
149 : #endif /* OS_MSDOS */
150 :
151 : #ifdef OS_VMS
152 :
153 : #define closesocket(s) ::close(s)
154 : #define ioctlsocket(s,c,d)
155 :
156 : #ifndef FD_SET
157 : typedef struct {
158 : INT fds_bits;
159 : } fd_set;
160 :
161 : #define FD_SET(n, p) ((p)->fds_bits |= (1 << (n)))
162 : #define FD_CLR(n, p) ((p)->fds_bits &= ~(1 << (n)))
163 : #define FD_ISSET(n, p) ((p)->fds_bits & (1 << (n)))
164 : #define FD_ZERO(p) ((p)->fds_bits = 0)
165 : #endif /* FD_SET */
166 :
167 : #endif /* OS_VMS */
168 :
169 : /* Missing #defines in VMS */
170 :
171 : #ifdef OS_VMS
172 :
173 : #define P_WAIT 0
174 : #define P_NOWAIT 1
175 : #define P_DETACH 4
176 :
177 : #endif
178 :
179 : /* and for UNIX */
180 :
181 : #ifdef OS_UNIX
182 :
183 : #define closesocket(s) ::close(s)
184 : #define ioctlsocket(s,c,d) ::ioctl(s,c,d)
185 : #ifndef stricmp
186 : #define stricmp(s1, s2) strcasecmp(s1, s2)
187 : #endif
188 :
189 : #define P_WAIT 0
190 : #define P_NOWAIT 1
191 : #define P_DETACH 4
192 :
193 : #endif
194 :
195 : // missing off64_t for MAC OSC
196 : #ifdef __APPLE__
197 : typedef off_t off64_t; // macOS always has 64-bit off_t
198 : #define lseek64 lseek
199 : #define ftruncate64 ftruncate
200 : #endif
201 :
202 : /** @addtogroup msdefineh
203 : * @{ */
204 :
205 : #ifndef FD_SETSIZE
206 : #define FD_SETSIZE 32
207 : #endif
208 :
209 : /** @} */
210 :
211 : /* and VXWORKS */
212 :
213 : #ifdef OS_VXWORKS
214 :
215 : #define P_NOWAIT 1
216 : #define closesocket(s) ::close(s)
217 : #define ioctlsocket(s,c,d) ::ioctl(s,c,d)
218 :
219 : #endif
220 :
221 : /** @addtogroup msdefineh
222 : * @{ */
223 :
224 : /* missing O_BINARY for non-PC */
225 : #ifndef O_BINARY
226 : #define O_BINARY 0
227 : #define O_TEXT 0
228 : #endif
229 :
230 : /** @} */
231 :
232 : /**dox***************************************************************/
233 : /** @addtogroup msmacroh
234 : * @{ */
235 :
236 : /* min/max/abs macros */
237 : #ifndef MAX
238 : #define MAX(a,b) (((a) > (b)) ? (a) : (b))
239 : #endif
240 :
241 : #ifndef MIN
242 : #define MIN(a,b) (((a) < (b)) ? (a) : (b))
243 : #endif
244 :
245 : #ifndef ABS
246 : #define ABS(a) (((a) < 0) ? -(a) : (a))
247 : #endif
248 :
249 : /* missing tell() for some operating systems */
250 : #define TELL(fh) lseek(fh, 0, SEEK_CUR)
251 :
252 : /* define file truncation */
253 : #ifdef OS_WINNT
254 : #define TRUNCATE(fh) chsize(fh, TELL(fh))
255 : #else
256 : #define TRUNCATE(fh) ftruncate(fh, TELL(fh))
257 : #endif
258 :
259 : /** @} */
260 :
261 : /* missing isnan() & co under Windows */
262 : #ifdef OS_WINNT
263 : #include <float.h>
264 : #define isnan(x) _isnan(x)
265 : #define isinf(x) (!_finite(x))
266 : #define strcasecmp _stricmp
267 : #define strncasecmp _strnicmp
268 : #define ftruncate(x,y) _chsize(x,y)
269 : #endif
270 :
271 : #define ctime #error ctime() is not thread safe and should not be used in midas programs
272 : #define localtime #error localtime() is not thread safe and should not be used in midas programs, use localtime_r() instead, do not forget to add a call to tzset()
273 : #define gmtime #error gmtime() is not thread safe and should not be used in midas programs, use gmtime_r() instead
274 : #define asctime #error asctime() is not thread safe and should not be used in midas programs, use asctime_r() instead
275 :
276 : //#define tzset #error tzset() is not thread safe, please use ss_tzset() instead
277 : //#define mktime #error mktime() is not thread safe, please use ss_mktime() instead
278 :
279 : /*------------------------------------------------------------------*/
280 :
281 : /**dox***************************************************************/
282 : /** @addtogroup mssectionh
283 : * @{ */
284 :
285 : /* Network structures */
286 :
287 : typedef struct {
288 : DWORD routine_id; /* routine ID like ID_BM_xxx */
289 : DWORD param_size; /* size in Bytes of parameter */
290 : } NET_COMMAND_HEADER;
291 :
292 : typedef struct {
293 : NET_COMMAND_HEADER header;
294 : char param[32]; /* parameter array */
295 : } NET_COMMAND;
296 :
297 : /** @} *//* end of mssectionh */
298 :
299 : /** @addtogroup msdefineh
300 : * @{ */
301 :
302 : #define MSG_BM 1
303 : #define MSG_ODB 2
304 : #define MSG_CLIENT 3
305 : #define MSG_SERVER 4
306 : #define MSG_LISTEN 5
307 : #define MSG_WATCHDOG 6
308 :
309 : /** @} */
310 :
311 : /**dox***************************************************************/
312 : /** @addtogroup mssectionh
313 : * @{ */
314 :
315 : /* RPC structures */
316 :
317 : struct callback_addr {
318 : std::string host_name;
319 : unsigned short host_port1;
320 : unsigned short host_port2;
321 : unsigned short host_port3;
322 : int debug;
323 : std::string experiment;
324 : std::string directory;
325 : std::string user;
326 :
327 0 : void clear() {
328 0 : host_name = "";
329 0 : host_port1 = 0;
330 0 : host_port2 = 0;
331 0 : host_port3 = 0;
332 0 : debug = 0;
333 0 : experiment = "";
334 0 : directory = "";
335 0 : user = "";
336 0 : }
337 : };
338 :
339 : typedef struct rpc_server_connection_struct {
340 : std::string host_name; /* server name */
341 : INT port; /* ip port */
342 : std::string exp_name; /* experiment to connect */
343 : int send_sock; /* tcp send socket */
344 : int recv_sock; /* tcp receive socket */
345 : int event_sock; /* event socket */
346 : std::mutex event_sock_mutex; /* protect event socket against multithreaded access */
347 : INT remote_hw_type; /* remote hardware type */
348 : INT rpc_timeout; /* in milliseconds */
349 :
350 0 : void clear() {
351 0 : host_name = "";
352 0 : port = 0;
353 0 : exp_name = "";
354 0 : send_sock = 0;
355 0 : recv_sock = 0;
356 0 : event_sock = 0;
357 0 : remote_hw_type = 0;
358 0 : rpc_timeout = 0;
359 0 : }
360 : } RPC_SERVER_CONNECTION;
361 :
362 : typedef struct rpc_server_acception_struct {
363 : std::string prog_name; /* client program name */
364 : std::string host_name; /* client name */
365 : BOOL is_mserver = 0; /* this is an mserver server-side connection */
366 : int send_sock = 0; /* tcp send socket */
367 : int recv_sock = 0; /* tcp receive socket */
368 : int event_sock = 0; /* tcp event socket */
369 : INT remote_hw_type = 0; /* hardware type */
370 : INT watchdog_timeout = 0; /* in milliseconds */
371 : DWORD last_activity = 0; /* time of last recv */
372 : INT convert_flags = 0; /* convertion flags */
373 : char *net_buffer = NULL; /* TCP cache buffer */
374 : INT net_buffer_size = 0; /* size of TCP cache */
375 : INT write_ptr=0, read_ptr=0, misalign=0; /* pointers for cache */
376 : HNDLE odb_handle = 0; /* handle to online datab. */
377 : HNDLE client_handle = 0; /* client key handle . */
378 :
379 0 : void clear() {
380 0 : prog_name = "";
381 0 : host_name = "";
382 0 : is_mserver = FALSE;
383 0 : send_sock = 0;
384 0 : recv_sock = 0;
385 0 : event_sock = 0;
386 0 : remote_hw_type = 0;
387 0 : watchdog_timeout = 0;
388 0 : last_activity = 0;
389 0 : convert_flags = 0;
390 0 : net_buffer = NULL;
391 0 : net_buffer_size = 0;
392 0 : write_ptr = 0;
393 0 : read_ptr = 0;
394 0 : misalign = 0;
395 0 : odb_handle = 0;
396 0 : client_handle = 0;
397 0 : }
398 :
399 : void close();
400 : } RPC_SERVER_ACCEPTION;
401 :
402 : typedef std::vector<RPC_SERVER_ACCEPTION*> RPC_SERVER_ACCEPTION_LIST;
403 :
404 :
405 : typedef struct {
406 : INT size; /**< size in bytes */
407 : INT next_free; /**< Address of next free block */
408 : } FREE_DESCRIP;
409 :
410 : typedef struct {
411 : INT handle; /**< Handle of record base key */
412 : WORD access_mode; /**< R/W flags */
413 : WORD flags; /**< Data format, ... */
414 :
415 : } OPEN_RECORD;
416 :
417 : typedef struct {
418 : char name[NAME_LENGTH]; /* name of client */
419 : INT pid; /* process ID */
420 : INT unused0; /* was thread ID */
421 : INT unused; /* was thread handle */
422 : INT port; /* UDP port for wake up */
423 : INT num_open_records; /* number of open records */
424 : DWORD last_activity; /* time of last activity */
425 : DWORD watchdog_timeout; /* timeout in ms */
426 : INT max_index; /* index of last opren record */
427 :
428 : OPEN_RECORD open_record[MAX_OPEN_RECORDS];
429 :
430 : } DATABASE_CLIENT;
431 :
432 : typedef struct {
433 : char name[NAME_LENGTH]; /* name of database */
434 : INT version; /* database version */
435 : INT num_clients; /* no of active clients */
436 : INT max_client_index; /* index of last client + 1 */
437 : INT key_size; /* size of key area in bytes */
438 : INT data_size; /* size of data area in bytes */
439 : INT root_key; /* root key offset */
440 : INT first_free_key; /* first free key memory */
441 : INT first_free_data; /* first free data memory */
442 :
443 : DATABASE_CLIENT client[MAX_CLIENTS]; /* entries for clients */
444 :
445 : } DATABASE_HEADER;
446 :
447 : /* Per-process buffer access structure (descriptor) */
448 :
449 : typedef struct {
450 : char name[NAME_LENGTH]; /* Name of database */
451 : BOOL attached; /* TRUE if database is attached */
452 : INT client_index; /* index to CLIENT str. in buf. */
453 : DATABASE_HEADER *database_header; /* pointer to database header */
454 : void *database_data; /* pointer to database data */
455 : HNDLE semaphore; /* semaphore handle */
456 : INT lock_cnt; /* flag to avoid multiple locks */
457 : void* shm_adr; /* address of shared memory */
458 : HNDLE shm_size; /* size of shared memory */
459 : HNDLE shm_handle; /* handle (id) to shared memory */
460 : BOOL protect; /* read/write protection */
461 : BOOL protect_read; /* read is permitted */
462 : BOOL protect_write; /* write is permitted */
463 : MUTEX_T *mutex; /* mutex for multi-thread access */
464 : INT timeout; /* timeout for mutex and semaphore */
465 : BOOL inside_lock_unlock; /* protection against recursive call to db_lock/unlock */
466 :
467 : } DATABASE;
468 :
469 : /* Open record descriptor */
470 :
471 : typedef struct {
472 : HNDLE handle; /* Handle of record base key */
473 : HNDLE hDB; /* Handle of record's database */
474 : WORD access_mode; /* R/W flags */
475 : void *data; /* Pointer to local data */
476 : void *copy; /* Pointer of copy to data */
477 : INT buf_size; /* Record size in bytes */
478 : void (*dispatcher) (INT, INT, void *); /* Pointer to dispatcher func. */
479 : void *info; /* addtl. info for dispatcher */
480 :
481 : } RECORD_LIST;
482 :
483 : /* Watch record descriptor */
484 :
485 : typedef struct {
486 : HNDLE handle; /* Handle of watched base key */
487 : HNDLE hDB; /* Handle of watched database */
488 : void (*dispatcher) (INT, INT, INT, void* info); /* Pointer to dispatcher func. */
489 : void* info; /* addtl. info for dispatcher */
490 : } WATCH_LIST;
491 :
492 : /**dox***************************************************************/
493 : /** @} *//* end of mssectionh */
494 :
495 : /** @addtogroup msdefineh
496 : * @{ */
497 :
498 : /*---- Logging channel information ---------------------------------*/
499 :
500 : #define LOG_TYPE_DISK 1
501 : #define LOG_TYPE_TAPE 2
502 : #define LOG_TYPE_FTP 3
503 : #define LOG_TYPE_SFTP 4
504 :
505 : /** @} */
506 :
507 : #if defined(OS_VXWORKS)
508 :
509 : /*---- VxWorks specific taskSpawn arguments ----------------------*/
510 :
511 : typedef struct {
512 : char name[32];
513 : int priority;
514 : int options;
515 : int stackSize;
516 : int arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10;
517 : } VX_TASK_SPAWN;
518 :
519 : #endif
520 :
521 : /*---- Function declarations ---------------------------------------*/
522 :
523 : /*---- common function ----*/
524 : INT EXPRT cm_set_path(const char *path);
525 : [[deprecated("Please use the std::string version of this function")]]
526 : INT EXPRT cm_get_path(char *path, int path_size);
527 : std::string EXPRT cm_get_path();
528 : INT EXPRT cm_get_path_string(std::string* path);
529 : INT EXPRT cm_set_experiment_name(const char *name);
530 : INT cm_dispatch_ipc(const char *message, int message_size, int client_socket);
531 : INT EXPRT cm_msg_log(INT message_type, const char *facility, const char *message);
532 : void EXPRT name2c(char *str);
533 : INT cm_delete_client_info(HNDLE hDB, INT pid);
534 : std::string EXPRT cm_get_history_path(const char* history_channel);
535 :
536 : /*---- online database ----*/
537 : INT EXPRT db_lock_database(HNDLE database_handle);
538 : INT EXPRT db_unlock_database(HNDLE database_handle);
539 : //INT EXPRT db_get_lock_cnt(HNDLE database_handle);
540 : INT EXPRT db_set_lock_timeout(HNDLE database_handle, int timeout_millisec);
541 : INT db_update_record_local(INT hDB, INT hKeyRoot, INT hKey, int index);
542 : INT db_update_record_mserver(INT hDB, INT hKeyRoot, INT hKey, int index, int client_socket);
543 : INT db_close_all_records(void);
544 : INT EXPRT db_flush_database(HNDLE hDB);
545 : INT EXPRT db_notify_clients(HNDLE hDB, HNDLE hKey, int index, BOOL bWalk);
546 : INT EXPRT db_set_client_name(HNDLE hDB, const char *client_name);
547 : INT db_delete_key1(HNDLE hDB, HNDLE hKey, INT level, BOOL follow_links);
548 : INT EXPRT db_show_mem(HNDLE hDB, char **result, BOOL verbose);
549 : INT EXPRT db_get_free_mem(HNDLE hDB, INT *key_size, INT *data_size);
550 : INT db_allow_write_locked(DATABASE* p, const char* caller_name);
551 : //void db_update_last_activity(DWORD actual_time);
552 : void db_cleanup(const char *who, DWORD actual_time, BOOL wrong_interval);
553 : void db_cleanup2(const char* client_name, int ignore_timeout, DWORD actual_time, const char *who);
554 : void db_set_watchdog_params(DWORD timeout);
555 : INT db_check_client(HNDLE hDB, HNDLE hKeyClient);
556 :
557 : /*---- rpc functions -----*/
558 : INT rpc_register_listener(int port, RPC_HANDLER func, int *plsock, int *pport);
559 : RPC_LIST EXPRT *rpc_get_internal_list(INT flag);
560 : INT rpc_server_receive_rpc(int idx, RPC_SERVER_ACCEPTION* sa);
561 : INT rpc_server_receive_event(int idx, RPC_SERVER_ACCEPTION* sa, int timeout_msec);
562 : INT rpc_server_callback(struct callback_addr *callback);
563 : INT EXPRT rpc_server_accept(int sock);
564 : INT rpc_client_accept(int sock);
565 : INT rpc_client_dispatch(int sock);
566 : INT EXPRT rpc_get_convert_flags(void);
567 : INT recv_tcp_check(int sock);
568 : INT rpc_deregister_functions(void);
569 : INT rpc_check_channels(void);
570 : void EXPRT rpc_client_check(void);
571 : INT rpc_server_disconnect(void);
572 : INT EXPRT rpc_set_opt_tcp_size(INT tcp_size);
573 : INT EXPRT rpc_get_opt_tcp_size(void);
574 : INT EXPRT rpc_set_mserver_path(const char *mserver_path);
575 : const char* EXPRT rpc_get_mserver_path(void);
576 : RPC_SERVER_ACCEPTION* rpc_get_mserver_acception(void);
577 :
578 : /** @addtogroup msfunctionc */
579 : /** @{ */
580 :
581 : /*---- system services ----*/
582 : INT ss_shm_open(const char *name, INT size, void **shm_adr, size_t *shm_size, HNDLE *handle, BOOL get_size);
583 : INT ss_shm_close(const char *name, void *shm_adr, size_t shm_size, HNDLE handle, INT destroy_flag);
584 : INT ss_shm_flush(const char *name, const void *shm_adr, size_t shm_size, HNDLE handle, bool wait_for_thread);
585 : INT EXPRT ss_shm_delete(const char *name);
586 : INT ss_shm_protect(HNDLE handle, void *shm_adr, size_t shm_size);
587 : INT ss_shm_unprotect(HNDLE handle, void **shm_adr, size_t shm_size, BOOL read, BOOL write, const char* caller_name);
588 : INT ss_spawnv(INT mode, const char *cmdname, const char* const argv[]);
589 : INT ss_shell(int sock);
590 : INT EXPRT ss_daemon_init(BOOL keep_stdout);
591 : INT EXPRT ss_system(const char *command);
592 : INT EXPRT ss_exec(const char *cmd, INT * child_pid);
593 : std::string EXPRT ss_replace_env_variables(const std::string& inputPath);
594 : std::string EXPRT ss_execs(const char *cmd);
595 : BOOL EXPRT ss_existpid(INT pid);
596 : INT EXPRT ss_getpid(void);
597 : midas_thread_t EXPRT ss_gettid(void);
598 : std::string ss_tid_to_string(midas_thread_t thread_id);
599 : INT EXPRT ss_semaphore_create(const char *semaphore_name, HNDLE * semaphore_handle);
600 : INT EXPRT ss_semaphore_wait_for(HNDLE semaphore_handle, DWORD timeout_millisec);
601 : INT EXPRT ss_semaphore_release(HNDLE semaphore_handle);
602 : INT EXPRT ss_semaphore_delete(HNDLE semaphore_handle, INT destroy_flag);
603 : INT EXPRT ss_mutex_create(MUTEX_T **mutex, BOOL recursive);
604 : INT EXPRT ss_mutex_wait_for(MUTEX_T *mutex, INT timeout);
605 : INT EXPRT ss_mutex_release(MUTEX_T *mutex);
606 : INT EXPRT ss_mutex_delete(MUTEX_T *mutex);
607 : bool EXPRT ss_timed_mutex_wait_for_sec(std::timed_mutex& mutex, const char* mutex_name, double timeout_sec);
608 : INT ss_alarm(INT millitime, void (*func) (int));
609 : INT ss_suspend_init_odb_port();
610 : INT ss_suspend_get_odb_port(INT * port);
611 : INT ss_suspend_get_buffer_port(midas_thread_t thread_id, INT * port);
612 : INT ss_suspend_set_rpc_thread(midas_thread_t thread_id);
613 : INT ss_suspend_set_server_listener(int listen_socket);
614 : INT ss_suspend_set_client_listener(int listen_socket);
615 : INT ss_suspend_set_client_connection(RPC_SERVER_CONNECTION* connection);
616 : INT ss_suspend_set_server_acceptions(RPC_SERVER_ACCEPTION_LIST* acceptions);
617 : INT ss_resume(INT port, const char *message);
618 : INT ss_suspend_exit(void);
619 : INT ss_exception_handler(void (*func) (void));
620 : INT EXPRT ss_suspend(INT millisec, INT msg);
621 : midas_thread_t EXPRT ss_thread_create(INT(*func) (void *), void *param);
622 : INT EXPRT ss_thread_kill(midas_thread_t thread_id);
623 : INT EXPRT ss_thread_set_name(std::string name);
624 : std::string ss_thread_get_name();
625 : INT EXPRT ss_get_struct_align(void);
626 : INT EXPRT ss_get_struct_padding(void);
627 : INT EXPRT ss_timezone(void);
628 : INT EXPRT ss_stack_get(char ***string);
629 : void EXPRT ss_stack_print(void);
630 : void EXPRT ss_stack_history_entry(char *tag);
631 : void EXPRT ss_stack_history_dump(char *filename);
632 : [[deprecated("Please use the std::string version of this function")]]
633 : INT ss_gethostname(char* buffer, int buffer_size);
634 : std::string ss_gethostname();
635 : BOOL ss_pid_exists(int pid);
636 : void ss_kill(int pid);
637 : std::string ss_get_executable(void);
638 : std::string ss_get_cmdline(void);
639 :
640 : /*---- socket routines ----*/
641 : INT EXPRT ss_socket_connect_tcp(const char* hostname, int tcp_port, int* sockp, std::string* error_msg_p);
642 : INT EXPRT ss_socket_listen_tcp(bool listen_localhost, int tcp_port, int* sockp, int* tcp_port_p, std::string* error_msg_p);
643 : INT EXPRT ss_socket_close(int* sockp);
644 : INT EXPRT ss_socket_wait(int sock, int millisec);
645 : INT EXPRT ss_socket_get_peer_name(int sock, std::string* host, int* port);
646 : INT EXPRT send_tcp(int sock, char *buffer, DWORD buffer_size, INT flags);
647 : INT EXPRT recv_tcp(int sock, char *buffer, DWORD buffer_size, INT flags);
648 : INT EXPRT recv_tcp2(int sock, char *buffer, int buffer_size, int timeout_ms);
649 : INT EXPRT recv_string(int sock, char *buffer, DWORD buffer_size, INT flags);
650 : INT EXPRT ss_recv_net_command(int sock, DWORD* routine_id, DWORD* param_size, char **param_ptr, int timeout_ms);
651 :
652 : /*---- mserver event socket ----*/
653 : bool ss_event_socket_has_data();
654 : int rpc_flush_event_socket(int timeout_msec);
655 :
656 : /** @} */
657 :
658 : /*---- event buffer routines ----*/
659 : INT EXPRT eb_create_buffer(INT size);
660 : INT EXPRT eb_free_buffer(void);
661 : BOOL EXPRT eb_buffer_full(void);
662 : BOOL EXPRT eb_buffer_empty(void);
663 : EVENT_HEADER EXPRT *eb_get_pointer(void);
664 : INT EXPRT eb_increment_pointer(INT buffer_handle, INT event_size);
665 : INT EXPRT eb_send_events(BOOL send_all);
666 :
667 : /*---- dual memory event buffer routines ----*/
668 : INT EXPRT dm_buffer_create(INT size, INT usize);
669 : INT EXPRT dm_buffer_release(void);
670 : BOOL EXPRT dm_area_full(void);
671 : EVENT_HEADER EXPRT *dm_pointer_get(void);
672 : INT EXPRT dm_pointer_increment(INT buffer_handle, INT event_size);
673 : INT EXPRT dm_area_send(void);
674 : INT EXPRT dm_area_flush(void);
675 : INT EXPRT dm_task(void *pointer);
676 : DWORD EXPRT dm_buffer_time_get(void);
677 : INT EXPRT dm_async_area_send(void *pointer);
678 :
679 : /*---- ring buffer routines ----*/
680 : int EXPRT rb_set_nonblocking(void);
681 : int EXPRT rb_create(int size, int max_event_size, int *ring_buffer_handle);
682 : int EXPRT rb_delete(int ring_buffer_handle);
683 : int EXPRT rb_get_wp(int handle, void **p, int millisec);
684 : int EXPRT rb_increment_wp(int handle, int size);
685 : int EXPRT rb_get_rp(int handle, void **p, int millisec);
686 : int EXPRT rb_increment_rp(int handle, int size);
687 : int EXPRT rb_get_buffer_level(int handle, int * n_bytes);
688 :
689 : /*---- stop watch ----*/
690 : std::chrono::time_point<std::chrono::high_resolution_clock> ss_us_start();
691 : unsigned int ss_us_since(std::chrono::time_point<std::chrono::high_resolution_clock> start);
692 :
693 : /*---- Include RPC identifiers -------------------------------------*/
694 :
695 : #include "mrpc.h"
696 :
697 : #endif /* _MSYSTEM_H */
698 :
699 : /* emacs
700 : * Local Variables:
701 : * tab-width: 8
702 : * c-basic-offset: 3
703 : * indent-tabs-mode: nil
704 : * End:
705 : */
|