8 enum comm_enum { NULL_COMM, IPC_COMM, ZMQ_COMM,
9 RPC_COMM, SERVER_COMM, CLIENT_COMM,
10 ASCII_FILE_COMM, ASCII_TABLE_COMM, ASCII_TABLE_ARRAY_COMM };
11 typedef enum comm_enum comm_type;
12 #define COMM_NAME_SIZE 100 13 #define COMM_ADDRESS_SIZE 500 14 #define COMM_DIR_SIZE 100 49 ret.address[0] =
'\0';
50 ret.direction[0] =
'\0';
54 ret.serializer = NULL;
56 ret.always_send_header = 0;
57 ret.index_in_register = -1;
77 comm_t* new_comm_base(
char *address,
const char *direction,
const comm_type t,
78 const void *seri_info) {
81 cislog_error(
"new_comm_base: Failed to malloc comm.");
84 ret[0] = empty_comm_base();
88 strcpy(ret->address, address);
89 if (direction == NULL) {
92 strcpy(ret->direction, direction);
94 ret->serializer = init_serializer(-1, seri_info);
95 ret->maxMsgSize = CIS_MSG_MAX;
96 ret->last_send = (time_t*)malloc(
sizeof(time_t));
97 ret->last_send[0] = 0;
98 ret->sent_eof = (
int*)malloc(
sizeof(
int));
99 ret->recv_eof = (
int*)malloc(
sizeof(
int));
100 ret->used = (
int*)malloc(
sizeof(
int));
101 ret->sent_eof[0] = 0;
102 ret->recv_eof[0] = 0;
120 comm_t* init_comm_base(
const char *name,
const char *direction,
121 const comm_type t,
const void *seri_info) {
122 char full_name[COMM_NAME_SIZE];
123 char *address = NULL;
125 strcpy(full_name, name);
127 if ((direction != NULL) && (strlen(direction) > 0)) {
128 if (is_send(direction))
129 strcat(full_name,
"_OUT");
130 else if (is_recv(direction))
131 strcat(full_name,
"_IN");
134 address = getenv(full_name);
136 comm_t *ret = new_comm_base(address, direction, t, seri_info);
138 cislog_error(
"init_comm_base: Error in new_comm_base");
144 strcpy(ret->name, full_name);
145 if ((strlen(ret->address) == 0) && (t != SERVER_COMM) && (t != CLIENT_COMM)) {
146 cislog_error(
"init_comm_base: %s not registered as environment variable.\n",
150 cislog_debug(
"init_comm_base(%s): Done", ret->name);
160 int free_comm_base(
comm_t *x) {
175 if (x->
used != NULL) {
197 int comm_base_send(
const comm_t x,
const char *data,
const size_t len) {
205 if (len > CIS_MSG_MAX) {
206 cislog_error(
"comm_base_send(%s): message too large for single packet (CIS_MSG_MAX=%d, len=%d)",
207 x.
name, CIS_MSG_MAX, len);
void * handle
Pointer to handle for comm.
Definition: CommBase.h:25
void * info
Pointer to any extra info comm requires.
Definition: CommBase.h:26
Communication structure.
Definition: CommBase.h:19
char address[COMM_ADDRESS_SIZE]
Comm address.
Definition: CommBase.h:22
Serializer structure.
Definition: SerializeBase.h:15
time_t * last_send
Clock output at time of last send.
Definition: CommBase.h:31
size_t maxMsgSize
The maximum message size.
Definition: CommBase.h:28
int * used
Flag specifying if the comm has been used.
Definition: CommBase.h:34
comm_type type
Comm type.
Definition: CommBase.h:20
int is_file
Flag specifying if the comm connects directly to a file.
Definition: CommBase.h:36
int always_send_header
1 if comm should always send a header.
Definition: CommBase.h:29
seri_t * serializer
Serializer for comm messages.
Definition: CommBase.h:27
char direction[COMM_DIR_SIZE]
send or recv for direction messages will go.
Definition: CommBase.h:23
char name[COMM_NAME_SIZE]
Comm name.
Definition: CommBase.h:21
int * sent_eof
Flag specifying if EOF has been sent.
Definition: CommBase.h:32
int valid
1 if communicator initialized, 0 otherwise.
Definition: CommBase.h:24
int * recv_eof
Flag specifying if EOF has been received.
Definition: CommBase.h:33
int index_in_register
Index of the comm in the comm register.
Definition: CommBase.h:30
void * reply
Reply information.
Definition: CommBase.h:35