00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00039
00040 #include "midasinc.h"
00041
00042
00043 #endif
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #define DRI_16 (1<<0)
00054 #define DRI_32 (1<<1)
00055 #define DRI_64 (1<<2)
00056 #define DRI_LITTLE_ENDIAN (1<<3)
00057 #define DRI_BIG_ENDIAN (1<<4)
00058 #define DRF_IEEE (1<<5)
00059 #define DRF_G_FLOAT (1<<6)
00060 #define DR_ASCII (1<<7)
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 #define WORD_SWAP(x) { BYTE _tmp; \
00074 _tmp= *((BYTE *)(x)); \
00075 *((BYTE *)(x)) = *(((BYTE *)(x))+1); \
00076 *(((BYTE *)(x))+1) = _tmp; }
00077
00078
00079
00080 #define DWORD_SWAP(x) { BYTE _tmp; \
00081 _tmp= *((BYTE *)(x)); \
00082 *((BYTE *)(x)) = *(((BYTE *)(x))+3); \
00083 *(((BYTE *)(x))+3) = _tmp; \
00084 _tmp= *(((BYTE *)(x))+1); \
00085 *(((BYTE *)(x))+1) = *(((BYTE *)(x))+2); \
00086 *(((BYTE *)(x))+2) = _tmp; }
00087
00088
00089
00090 #define QWORD_SWAP(x) { BYTE _tmp; \
00091 _tmp= *((BYTE *)(x)); \
00092 *((BYTE *)(x)) = *(((BYTE *)(x))+7); \
00093 *(((BYTE *)(x))+7) = _tmp; \
00094 _tmp= *(((BYTE *)(x))+1); \
00095 *(((BYTE *)(x))+1) = *(((BYTE *)(x))+6); \
00096 *(((BYTE *)(x))+6) = _tmp; \
00097 _tmp= *(((BYTE *)(x))+2); \
00098 *(((BYTE *)(x))+2) = *(((BYTE *)(x))+5); \
00099 *(((BYTE *)(x))+5) = _tmp; \
00100 _tmp= *(((BYTE *)(x))+3); \
00101 *(((BYTE *)(x))+3) = *(((BYTE *)(x))+4); \
00102 *(((BYTE *)(x))+4) = _tmp; }
00103
00104
00105
00106
00107
00108 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00109
00110
00111
00112 #define MESSAGE_BUFFER_SIZE 100000
00113 #define MESSAGE_BUFFER_NAME "SYSMSG"
00114 #define MAX_RPC_CONNECTION 64
00115 #define MAX_STRING_LENGTH 256
00116 #define NET_BUFFER_SIZE (ALIGN8(MAX_EVENT_SIZE)+sizeof(EVENT_HEADER)+\
00117 4*8 + sizeof(NET_COMMAND_HEADER))
00118
00119
00120
00121 #undef DEBUG_MSG
00122
00123
00124 #if !defined ( OS_MSDOS ) && !defined ( OS_VXWORKS )
00125 #define LOCAL_ROUTINES
00126 #endif
00127
00128
00129 #if !defined ( OS_MSDOS )
00130 #define YBOS_SUPPORT
00131 #endif
00132
00133
00134
00135
00136
00137 #ifdef OS_MSDOS
00138
00139 #define closesocket(s) close(s)
00140 #define ioctlsocket(s,c,d) ioctl(s,c,d)
00141 #define malloc(i) farmalloc(i)
00142
00143 #undef NET_TCP_SIZE
00144 #define NET_TCP_SIZE 0x7FFF
00145
00146 #undef MAX_EVENT_SIZE
00147 #define MAX_EVENT_SIZE 4096
00148
00149 #endif
00150
00151 #ifdef OS_VMS
00152
00153 #define closesocket(s) close(s)
00154 #define ioctlsocket(s,c,d)
00155
00156 #ifndef FD_SET
00157 typedef struct {
00158 INT fds_bits;
00159 } fd_set;
00160
00161 #define FD_SET(n, p) ((p)->fds_bits |= (1 << (n)))
00162 #define FD_CLR(n, p) ((p)->fds_bits &= ~(1 << (n)))
00163 #define FD_ISSET(n, p) ((p)->fds_bits & (1 << (n)))
00164 #define FD_ZERO(p) ((p)->fds_bits = 0)
00165 #endif
00166
00167 #endif
00168
00169
00170
00171 #ifdef OS_VMS
00172
00173 #define P_WAIT 0
00174 #define P_NOWAIT 1
00175 #define P_DETACH 4
00176
00177 #endif
00178
00179
00180
00181 #ifdef OS_UNIX
00182
00183 #define closesocket(s) close(s)
00184 #define ioctlsocket(s,c,d) ioctl(s,c,d)
00185
00186 #define P_WAIT 0
00187 #define P_NOWAIT 1
00188 #define P_DETACH 4
00189
00190 extern char **environ;
00191
00192 #endif
00193
00194 #ifndef FD_SETSIZE
00195 #define FD_SETSIZE 32
00196 #endif
00197
00198
00199
00200 #ifdef OS_VXWORKS
00201
00202 #define P_NOWAIT 1
00203 #define closesocket(s) close(s)
00204 #define ioctlsocket(s,c,d) ioctl(s,c,d)
00205
00206 #endif
00207
00208
00209 #ifndef O_BINARY
00210 #define O_BINARY 0
00211 #define O_TEXT 0
00212 #endif
00213
00214
00215 #ifndef MAX
00216 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
00217 #endif
00218
00219 #ifndef MIN
00220 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
00221 #endif
00222
00223 #ifndef ABS
00224 #define ABS(a) (((a) < 0) ? -(a) : (a))
00225 #endif
00226
00227
00228 #define TELL(fh) lseek(fh, 0, SEEK_CUR)
00229
00230
00231 #ifdef OS_SOLARIS
00232 #define MAX_SHM_SIZE 0x20000
00233 #endif
00234
00235
00236
00237
00238
00239 typedef struct {
00240 DWORD routine_id;
00241 DWORD param_size;
00242 } NET_COMMAND_HEADER;
00243
00244 typedef struct {
00245 NET_COMMAND_HEADER header;
00246 char param[32];
00247 } NET_COMMAND;
00248
00249
00250 typedef struct {
00251 DWORD serial_number;
00252 DWORD sequence_number;
00253 } UDP_HEADER;
00254
00255 #define UDP_FIRST 0x80000000l
00256 #define TCP_FAST 0x80000000l
00257
00258 #define MSG_BM 1
00259 #define MSG_ODB 2
00260 #define MSG_CLIENT 3
00261 #define MSG_SERVER 4
00262 #define MSG_LISTEN 5
00263 #define MSG_WATCHDOG 6
00264
00265
00266
00267 struct callback_addr {
00268 char host_name[HOST_NAME_LENGTH];
00269 short host_port1;
00270 short host_port2;
00271 short host_port3;
00272 int debug;
00273 char experiment[NAME_LENGTH];
00274 char directory[MAX_STRING_LENGTH];
00275 char user[NAME_LENGTH];
00276 INT index;
00277 };
00278
00279 typedef struct {
00280 char host_name[HOST_NAME_LENGTH];
00281 INT port;
00282 char exp_name[NAME_LENGTH];
00283 int send_sock;
00284 INT remote_hw_type;
00285 char client_name[NAME_LENGTH];
00286 INT transport;
00287 INT rpc_timeout;
00288
00289 } RPC_CLIENT_CONNECTION;
00290
00291 typedef struct {
00292 char host_name[HOST_NAME_LENGTH];
00293 INT port;
00294 char exp_name[NAME_LENGTH];
00295 int send_sock;
00296 int recv_sock;
00297 int event_sock;
00298 INT remote_hw_type;
00299 INT transport;
00300 INT rpc_timeout;
00301
00302 } RPC_SERVER_CONNECTION;
00303
00304 typedef struct {
00305 INT tid;
00306 char prog_name[NAME_LENGTH];
00307 char host_name[HOST_NAME_LENGTH];
00308 int send_sock;
00309 int recv_sock;
00310 int event_sock;
00311 INT remote_hw_type;
00312 INT transport;
00313 INT watchdog_timeout;
00314 DWORD last_activity;
00315 INT convert_flags;
00316 char *net_buffer;
00317 char *ev_net_buffer;
00318 INT net_buffer_size;
00319 INT write_ptr, read_ptr, misalign;
00320 INT ev_write_ptr, ev_read_ptr, ev_misalign;
00321 HNDLE odb_handle;
00322 HNDLE client_handle;
00323
00324 } RPC_SERVER_ACCEPTION;
00325
00326
00327 #endif
00328
00329
00330
00331
00332
00333
00334 typedef struct {
00335 INT size;
00336 INT next_free;
00337 } FREE_DESCRIP;
00338
00339 typedef struct {
00340 INT handle;
00341 WORD access_mode;
00342 WORD flags;
00343
00344 } OPEN_RECORD;
00345
00346 typedef struct {
00347 char name[NAME_LENGTH];
00348 INT pid;
00349 INT tid;
00350 INT thandle;
00351 INT port;
00352 INT num_open_records;
00353 DWORD last_activity;
00354 DWORD watchdog_timeout;
00355 INT max_index;
00356
00357 OPEN_RECORD open_record[MAX_OPEN_RECORDS];
00358
00359 } DATABASE_CLIENT;
00360
00361 typedef struct {
00362 char name[NAME_LENGTH];
00363 INT version;
00364 INT num_clients;
00365 INT max_client_index;
00366 INT key_size;
00367 INT data_size;
00368 INT root_key;
00369 INT first_free_key;
00370 INT first_free_data;
00371
00372 DATABASE_CLIENT client[MAX_CLIENTS];
00373
00374 } DATABASE_HEADER;
00375
00376
00377
00378 typedef struct {
00379 char name[NAME_LENGTH];
00380 BOOL attached;
00381 INT client_index;
00382 DATABASE_HEADER *database_header;
00383 void *database_data;
00384 HNDLE mutex;
00385 INT lock_cnt;
00386 HNDLE shm_handle;
00387 INT index;
00388 BOOL protect;
00389
00390 } DATABASE;
00391
00392
00393
00394 typedef struct {
00395 HNDLE handle;
00396 HNDLE hDB;
00397 WORD access_mode;
00398 void *data;
00399 void *copy;
00400 INT buf_size;
00401 void (*dispatcher) (INT, INT, void *);
00402 void *info;
00403
00404 } RECORD_LIST;
00405
00406
00407
00408 typedef struct {
00409 INT buffer_handle;
00410 short int event_id;
00411 short int trigger_mask;
00412 void (*dispatcher) (HNDLE, HNDLE, EVENT_HEADER *, void *);
00413
00414 } REQUEST_LIST;
00415
00416
00417
00418
00419
00420 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00421
00422
00423
00424 #define CHN_SETTINGS_STR(_name) char *_name[] = {\
00425 "[Settings]",\
00426 "Active = BOOL : 1",\
00427 "Type = STRING : [8] Disk",\
00428 "Filename = STRING : [256] run%05d.mid",\
00429 "Format = STRING : [8] MIDAS",\
00430 "Compression = INT : 0",\
00431 "ODB dump = BOOL : 1",\
00432 "Log messages = DWORD : 0",\
00433 "Buffer = STRING : [32] SYSTEM",\
00434 "Event ID = INT : -1",\
00435 "Trigger mask = INT : -1",\
00436 "Event limit = DWORD : 0",\
00437 "Byte limit = DOUBLE : 0",\
00438 "Tape capacity = DOUBLE : 0",\
00439 "Subdir format = STRING : [32]",\
00440 "Current filename = STRING : [256]",\
00441 "",\
00442 "[Statistics]",\
00443 "Events written = DOUBLE : 0",\
00444 "Bytes written = DOUBLE : 0",\
00445 "Bytes written total = DOUBLE : 0",\
00446 "Files written = INT : 0",\
00447 "",\
00448 NULL}
00449
00450 typedef struct {
00451 BOOL active;
00452 char type[8];
00453 char filename[256];
00454 char format[8];
00455 INT compression;
00456 BOOL odb_dump;
00457 DWORD log_messages;
00458 char buffer[32];
00459 INT event_id;
00460 INT trigger_mask;
00461 DWORD event_limit;
00462 double byte_limit;
00463 double tape_capacity;
00464 char subdir_format[32];
00465 char current_filename[256];
00466 } CHN_SETTINGS;
00467
00468 typedef struct {
00469 double events_written;
00470 double bytes_written;
00471 double bytes_written_total;
00472 INT files_written;
00473 } CHN_STATISTICS;
00474
00475 typedef struct {
00476 INT handle;
00477 char path[256];
00478 INT type;
00479 INT format;
00480 INT buffer_handle;
00481 INT msg_buffer_handle;
00482 INT request_id;
00483 INT msg_request_id;
00484 HNDLE stats_hkey;
00485 HNDLE settings_hkey;
00486 CHN_SETTINGS settings;
00487 CHN_STATISTICS statistics;
00488 void **format_info;
00489 void *ftp_con;
00490 } LOG_CHN;
00491
00492 #define LOG_TYPE_DISK 1
00493 #define LOG_TYPE_TAPE 2
00494 #define LOG_TYPE_FTP 3
00495
00496
00497
00498 typedef struct {
00499 char name[32];
00500 int priority;
00501 int options;
00502 int stackSize;
00503 int arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10;
00504 } VX_TASK_SPAWN;
00505
00506
00507
00508 #define CH_IPC 1
00509 #define CH_CLIENT 2
00510 #define CH_SERVER 3
00511 #define CH_LISTEN 4
00512
00513
00514
00515
00516 #ifdef __cplusplus
00517 extern "C" {
00518 #endif
00519
00520
00521 INT EXPRT cm_set_path(char *path);
00522 INT EXPRT cm_get_path(char *path);
00523 INT cm_dispatch_ipc(char *message, int socket);
00524 INT EXPRT cm_msg_log(INT message_type, const char *message);
00525 INT EXPRT cm_msg_log1(INT message_type, const char *message, const char *facility);
00526 void EXPRT name2c(char *str);
00527
00528
00529 INT bm_lock_buffer(INT buffer_handle);
00530 INT bm_unlock_buffer(INT buffer_handle);
00531 INT bm_notify_client(char *buffer_name, int socket);
00532 INT EXPRT bm_mark_read_waiting(BOOL flag);
00533 INT bm_push_event(char *buffer_name);
00534 INT bm_check_buffers(void);
00535 INT EXPRT bm_remove_event_request(INT buffer_handle, INT request_id);
00536 void EXPRT bm_defragment_event(HNDLE buffer_handle, HNDLE request_id,
00537 EVENT_HEADER * pevent, void *pdata,
00538 void (*dispatcher) (HNDLE, HNDLE,
00539 EVENT_HEADER *, void *));
00540
00541
00542 INT EXPRT db_lock_database(HNDLE database_handle);
00543 INT EXPRT db_unlock_database(HNDLE database_handle);
00544 INT db_update_record(INT hDB, INT hKey, int socket);
00545 INT db_close_all_records(void);
00546 INT EXPRT db_flush_database(HNDLE hDB);
00547 INT EXPRT db_notify_clients(HNDLE hDB, HNDLE hKey, BOOL bWalk);
00548 INT EXPRT db_set_client_name(HNDLE hDB, char *client_name);
00549 INT db_delete_key1(HNDLE hDB, HNDLE hKey, INT level, BOOL follow_links);
00550 INT EXPRT db_show_mem(HNDLE hDB, char *result, INT buf_size, BOOL verbose);
00551
00552
00553 RPC_LIST EXPRT *rpc_get_internal_list(INT flag);
00554 INT rpc_server_receive(INT index, int sock, BOOL check);
00555 INT rpc_server_callback(struct callback_addr *callback);
00556 INT EXPRT rpc_server_accept(int sock);
00557 INT rpc_client_accept(int sock);
00558 INT rpc_get_server_acception(void);
00559 INT rpc_set_server_acception(INT index);
00560 INT EXPRT rpc_set_server_option(INT item, POINTER_T value);
00561 POINTER_T EXPRT rpc_get_server_option(INT item);
00562 INT recv_tcp_check(int sock);
00563 INT recv_event_check(int sock);
00564 INT rpc_deregister_functions(void);
00565 INT rpc_check_channels(void);
00566 void EXPRT rpc_client_check();
00567 INT rpc_server_disconnect(void);
00568 int EXPRT rpc_get_send_sock(void);
00569 int EXPRT rpc_get_event_sock(void);
00570 INT EXPRT rpc_set_opt_tcp_size(INT tcp_size);
00571 INT EXPRT rpc_get_opt_tcp_size(void);
00572
00573
00574 INT ss_shm_open(char *name, INT size, void **adr, HNDLE * handle);
00575 INT ss_shm_close(char *name, void *adr, HNDLE handle, INT destroy_flag);
00576 INT ss_shm_flush(char *name, void *adr, INT size);
00577 INT ss_shm_protect(HNDLE handle, void *adr);
00578 INT ss_shm_unprotect(HNDLE handle, void **adr);
00579 INT ss_spawnv(INT mode, char *cmdname, char *argv[]);
00580 INT ss_shell(int sock);
00581 INT EXPRT ss_daemon_init(BOOL keep_stdout);
00582 INT EXPRT ss_system(char *command);
00583 INT EXPRT ss_exec(char *cmd, INT * child_pid);
00584 BOOL EXPRT ss_existpid(INT pid);
00585 INT EXPRT ss_getpid(void);
00586 INT EXPRT ss_gettid(void);
00587 INT ss_getthandle(void);
00588 INT ss_set_async_flag(INT flag);
00589 INT EXPRT ss_mutex_create(char *mutex_name, HNDLE * mutex_handle);
00590 INT EXPRT ss_mutex_wait_for(HNDLE mutex_handle, INT timeout);
00591 INT EXPRT ss_mutex_release(HNDLE mutex_handle);
00592 INT EXPRT ss_mutex_delete(HNDLE mutex_handle, INT destroy_flag);
00593 INT ss_wake(INT pid, INT tid, INT thandle);
00594 INT ss_alarm(INT millitime, void (*func) (int));
00595 INT ss_suspend_get_port(INT * port);
00596 INT ss_suspend_set_dispatch(INT channel, void *connection, INT(*dispatch) ());
00597 INT ss_resume(INT port, char *message);
00598 INT ss_suspend_exit(void);
00599 INT ss_exception_handler(void (*func) ());
00600 void EXPRT ss_force_single_thread();
00601 INT EXPRT ss_suspend(INT millisec, INT msg);
00602 midas_thread_t EXPRT ss_thread_create(INT(*func) (void *), void *param);
00603 INT EXPRT ss_thread_kill(midas_thread_t thread_id);
00604 INT EXPRT ss_get_struct_align(void);
00605 INT EXPRT ss_timezone(void);
00606
00607
00608 INT EXPRT send_tcp(int sock, char *buffer, DWORD buffer_size, INT flags);
00609 INT EXPRT recv_tcp(int sock, char *buffer, DWORD buffer_size, INT flags);
00610 INT send_udp(int sock, char *buffer, DWORD buffer_size, INT flags);
00611 INT recv_udp(int sock, char *buffer, DWORD buffer_size, INT flags);
00612 INT EXPRT recv_string(int sock, char *buffer, DWORD buffer_size, INT flags);
00613
00614
00615 INT EXPRT ss_syslog(const char *message);
00616
00617
00618 INT EXPRT eb_create_buffer(INT size);
00619 INT EXPRT eb_free_buffer(void);
00620 BOOL EXPRT eb_buffer_full(void);
00621 BOOL EXPRT eb_buffer_empty(void);
00622 EVENT_HEADER EXPRT *eb_get_pointer(void);
00623 INT EXPRT eb_increment_pointer(INT buffer_handle, INT event_size);
00624 INT EXPRT eb_send_events(BOOL send_all);
00625
00626
00627 INT EXPRT dm_buffer_create(INT size, INT usize);
00628 INT EXPRT dm_buffer_release(void);
00629 BOOL EXPRT dm_area_full(void);
00630 EVENT_HEADER EXPRT *dm_pointer_get(void);
00631 INT EXPRT dm_pointer_increment(INT buffer_handle, INT event_size);
00632 INT EXPRT dm_area_send(void);
00633 INT EXPRT dm_area_flush(void);
00634 INT EXPRT dm_task(void *pointer);
00635 DWORD EXPRT dm_buffer_time_get(void);
00636 INT EXPRT dm_async_area_send(void *pointer);
00637
00638
00639
00640 #include "mrpc.h"
00641
00642 #ifdef __cplusplus
00643 }
00644 #endif
00645
00646 #endif
00647