MIDAS
Loading...
Searching...
No Matches
minife.c File Reference
#include "midas.h"
#include "msystem.h"
#include <stdio.h>
Include dependency graph for minife.c:

Go to the source code of this file.

Functions

INT tr_start (INT rn, char *error)
 
INT tr_stop (INT rn, char *error)
 
int main (void)
 

Variables

INT running
 
INT serial = 0
 
INT run_number = 0
 
HNDLE hBuf
 

Function Documentation

◆ main()

int main ( void  )

Definition at line 55 of file minife.c.

57{
58 INT status, size, *pdata, id=0;
59 INT convert_flags;
60 DWORD last_time = 0;
61 char event[2000];
62 char host_name[256];
63 char dash[] = "-/|\\";
65
66#ifdef OS_VXWORKS
67 strcpy(host_name, ahost_name);
68#else
69 printf("Host to connect: ");
70 ss_gets(host_name, 256);
71#endif
72
73 /* now connect to server */
75 if (status != CM_SUCCESS)
76 return 1;
77
80 printf("Cannot start server");
81 return 0;
82 }
83#ifdef _DEBUG
85#endif
86
87 /* open the "system" buffer, 2x maximal event size */
89
90 /* set the buffer cache size on the server */
91 bm_set_cache_size(hBuf, 0, 100000);
92
93 pdata = (INT *) (event + sizeof(EVENT_HEADER));
94 size = 1000;
95
96 /* compose an event */
97 bm_compose_event((EVENT_HEADER *) event, 1, 1, size, serial);
98
99 pdata[0] = size; /* simulate data for consume.exe */
100 pdata[size / 4 - 1] = size;
101
102 /* convert test data if necessary to format on server */
103 rpc_get_convert_flags(&convert_flags);
104 if (convert_flags) {
105 rpc_convert_single(&pdata[0], TID_DWORD, RPC_OUTGOING, convert_flags);
106 rpc_convert_single(&pdata[size / 4 - 1], TID_DWORD, RPC_OUTGOING, convert_flags);
107 }
108
109 do {
110 if (!running) {
111 /* if run is not started, call yield with a timeout of 1s */
112 status = cm_yield(1000);
113 if (status == RPC_SHUTDOWN || status == SS_ABORT)
114 break;
115 } else {
116 /* if run is started, call yield with a timeout of 0 once each second.
117 This minimizes the calls to select() inside rpc_server_yield and
118 increases the network speed */
119 if (ss_millitime() - last_time > 300) {
120 printf("%c\r", dash[id++ % 4]);
121 fflush(stdout);
122
123 status = cm_yield(0);
124 if (status == RPC_SHUTDOWN || status == SS_ABORT)
125 break;
127 }
128 }
129
130 /* if run is started, send event */
131 if (running) {
132 /* only compose new event if not blocked by previous send */
133 if (!blocked) {
134 /* increment serial number */
135 ((EVENT_HEADER *) event)->serial_number = serial++;
136 }
137
138 status = rpc_send_event(hBuf, event, size + sizeof(EVENT_HEADER), BM_NO_WAIT, 1);
139 if (status == BM_ASYNC_RETURN)
140 blocked = TRUE;
141 else if (status == BM_SUCCESS)
142 blocked = FALSE;
143 else if (status != BM_SUCCESS) {
144 printf("Error sending event");
145 goto error;
146 }
147
148 }
149
150 } while (run_number < 1000);
151
153
154 error:
155
156 return 1;
157}
#define FALSE
Definition cfortran.h:309
#define MAX_EVENT_SIZE
Definition consume.cxx:17
INT bm_open_buffer(const char *buffer_name, INT buffer_size, INT *buffer_handle)
Definition midas.cxx:6717
INT bm_set_cache_size(INT buffer_handle, size_t read_size, size_t write_size)
Definition midas.cxx:8140
INT bm_compose_event(EVENT_HEADER *event_header, short int event_id, short int trigger_mask, DWORD data_size, DWORD serial)
Definition midas.cxx:8281
INT cm_register_transition(INT transition, INT(*func)(INT, char *), INT sequence_number)
Definition midas.cxx:3593
INT cm_yield(INT millisec)
Definition midas.cxx:5642
INT cm_connect_experiment(const char *host_name, const char *exp_name, const char *client_name, void(*func)(char *))
Definition midas.cxx:2278
INT cm_disconnect_experiment(void)
Definition midas.cxx:2846
INT cm_set_watchdog_params(BOOL call_watchdog, DWORD timeout)
Definition midas.cxx:3283
#define CM_SUCCESS
Definition midas.h:582
#define BM_ASYNC_RETURN
Definition midas.h:613
#define BM_SUCCESS
Definition midas.h:605
#define SS_ABORT
Definition midas.h:677
#define RPC_SHUTDOWN
Definition midas.h:707
unsigned int DWORD
Definition mcstd.h:51
#define TR_START
Definition midas.h:405
#define BM_NO_WAIT
Definition midas.h:366
#define TR_STOP
Definition midas.h:406
#define TID_DWORD
Definition midas.h:336
DWORD ss_millitime()
Definition system.cxx:3393
char * ss_gets(char *string, int size)
Definition system.cxx:7770
INT rpc_send_event(INT buffer_handle, const EVENT_HEADER *pevent, int unused, INT async_flag, INT mode)
Definition midas.cxx:13901
INT rpc_get_convert_flags(void)
Definition midas.cxx:13030
void rpc_convert_single(void *data, INT tid, INT flags, INT convert_flags)
Definition midas.cxx:11681
DWORD last_time
Definition mana.cxx:3070
char host_name[HOST_NAME_LENGTH]
Definition mana.cxx:242
DWORD BOOL
Definition midas.h:105
int INT
Definition midas.h:129
#define RPC_OUTGOING
Definition midas.h:1585
#define TRUE
Definition midas.h:182
#define EVENT_BUFFER_NAME
Definition midas.h:269
INT run_number
Definition minife.c:21
INT running
Definition minife.c:19
INT tr_stop(INT rn, char *error)
Definition minife.c:36
INT tr_start(INT rn, char *error)
Definition minife.c:25
INT serial
Definition minife.c:20
HNDLE hBuf
Definition minife.c:23
DWORD status
Definition odbhist.cxx:39
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
Here is the call graph for this function:

◆ tr_start()

INT tr_start ( INT  rn,
char error 
)

Definition at line 25 of file minife.c.

26{
27 printf("Start run %d\n", rn);
28
29 serial = 0;
30 run_number = rn;
31 running = TRUE;
32
33 return CM_SUCCESS;
34}
INT rn
Definition mstat.cxx:30
Here is the caller graph for this function:

◆ tr_stop()

INT tr_stop ( INT  rn,
char error 
)

Definition at line 36 of file minife.c.

37{
38 printf("Stop run %d -", rn);
39
40 running = FALSE;
41
42 rpc_flush_event(); /* send events in TCP cache */
43 bm_flush_cache(hBuf, BM_WAIT); /* flush buffer cache */
44
45 printf(" done\n");
46
47 return CM_SUCCESS;
48}
INT bm_flush_cache(int buffer_handle, int timeout_msec)
Definition midas.cxx:10207
#define BM_WAIT
Definition midas.h:365
INT rpc_flush_event()
Definition midas.cxx:14038
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ hBuf

HNDLE hBuf

Definition at line 23 of file minife.c.

◆ run_number

INT run_number = 0

Definition at line 21 of file minife.c.

◆ running

INT running

Definition at line 19 of file minife.c.

◆ serial

INT serial = 0

Definition at line 20 of file minife.c.