12 enum comm_enum { NULL_COMM, IPC_COMM, ZMQ_COMM,
13 RPC_COMM, SERVER_COMM, CLIENT_COMM,
14 ASCII_FILE_COMM, ASCII_TABLE_COMM, ASCII_TABLE_ARRAY_COMM };
15 typedef enum comm_enum comm_type;
16 #define COMM_NAME_SIZE 100 17 #define COMM_ADDRESS_SIZE 500 18 #define COMM_DIR_SIZE 100 54 ret.address[0] =
'\0';
55 ret.direction[0] =
'\0';
59 ret.serializer = NULL;
61 ret.always_send_header = 0;
62 ret.index_in_register = -1;
83 comm_t* new_comm_base(
char *address,
const char *direction,
const comm_type t,
84 const void *seri_info) {
87 cislog_error(
"new_comm_base: Failed to malloc comm.");
90 ret[0] = empty_comm_base();
94 strcpy(ret->address, address);
95 if (direction == NULL) {
98 strcpy(ret->direction, direction);
100 ret->serializer = init_serializer(-1, seri_info);
101 ret->maxMsgSize = CIS_MSG_MAX;
102 ret->last_send = (time_t*)malloc(
sizeof(time_t));
103 ret->last_send[0] = 0;
104 ret->sent_eof = (
int*)malloc(
sizeof(
int));
105 ret->recv_eof = (
int*)malloc(
sizeof(
int));
106 ret->used = (
int*)malloc(
sizeof(
int));
107 ret->sent_eof[0] = 0;
108 ret->recv_eof[0] = 0;
126 comm_t* init_comm_base(
const char *name,
const char *direction,
127 const comm_type t,
const void *seri_info) {
128 char full_name[COMM_NAME_SIZE];
129 char *address = NULL;
131 strcpy(full_name, name);
133 if ((direction != NULL) && (strlen(direction) > 0)) {
134 if (is_send(direction))
135 strcat(full_name,
"_OUT");
136 else if (is_recv(direction))
137 strcat(full_name,
"_IN");
140 address = getenv(full_name);
142 comm_t *ret = new_comm_base(address, direction, t, seri_info);
144 cislog_error(
"init_comm_base: Error in new_comm_base");
150 strcpy(ret->name, full_name);
151 if ((strlen(ret->address) == 0) && (t != SERVER_COMM) && (t != CLIENT_COMM)) {
152 cislog_error(
"init_comm_base: %s not registered as environment variable.\n",
156 cislog_debug(
"init_comm_base(%s): Done", ret->name);
166 int free_comm_base(
comm_t *x) {
181 if (x->
used != NULL) {
204 int comm_base_send(
const comm_t x,
const char *data,
const size_t len) {
212 if (len > CIS_MSG_MAX) {
213 cislog_error(
"comm_base_send(%s): message too large for single packet (CIS_MSG_MAX=%d, len=%d)",
214 x.
name, CIS_MSG_MAX, len);
void * handle
Pointer to handle for comm.
Definition: CommBase.h:29
void * info
Pointer to any extra info comm requires.
Definition: CommBase.h:30
Communication structure.
Definition: CommBase.h:23
char address[COMM_ADDRESS_SIZE]
Comm address.
Definition: CommBase.h:26
int is_work_comm
Flag specifying if comm is a temporary work comm.
Definition: CommBase.h:41
Serializer structure.
Definition: SerializeBase.h:19
time_t * last_send
Clock output at time of last send.
Definition: CommBase.h:35
size_t maxMsgSize
The maximum message size.
Definition: CommBase.h:32
int * used
Flag specifying if the comm has been used.
Definition: CommBase.h:38
comm_type type
Comm type.
Definition: CommBase.h:24
int is_file
Flag specifying if the comm connects directly to a file.
Definition: CommBase.h:40
int always_send_header
1 if comm should always send a header.
Definition: CommBase.h:33
seri_t * serializer
Serializer for comm messages.
Definition: CommBase.h:31
char direction[COMM_DIR_SIZE]
send or recv for direction messages will go.
Definition: CommBase.h:27
char name[COMM_NAME_SIZE]
Comm name.
Definition: CommBase.h:25
int * sent_eof
Flag specifying if EOF has been sent.
Definition: CommBase.h:36
int valid
1 if communicator initialized, 0 otherwise.
Definition: CommBase.h:28
int * recv_eof
Flag specifying if EOF has been received.
Definition: CommBase.h:37
int index_in_register
Index of the comm in the comm register.
Definition: CommBase.h:34
void * reply
Reply information.
Definition: CommBase.h:39