cis_config: /root/cis_interface/cis_interface/cis_interface/interface/CisInterface.h Source File

cis_config

CisInterface.h
1
2 #ifndef CISINTERFACE_H_
3 #define CISINTERFACE_H_
4
5 #include <../tools.h>
6 #include <../communication/communication.h>
7 #include <../dataio/AsciiFile.h>
8 #include <../dataio/AsciiTable.h>
9
10 #ifdef __cplusplus /* If this is a C++ compiler, use C linkage */
11 extern "C" {
12 #endif
13
15 #define cisOutput_t comm_t
16 #define cisInput_t comm_t
17 #define cis_free free_comm
18
19 //==============================================================================
40 //==============================================================================
41
52 static inline
53 cisOutput_t cisOutputFmt(const char *name, const char *fmtString){
54 cisOutput_t ret = init_comm(name, "send", _default_comm,
55 (void*)fmtString);
56 return ret;
57 };
58
68 static inline
69 cisInput_t cisInputFmt(const char *name, const char *fmtString){
70 cisInput_t ret = init_comm(name, "recv", _default_comm,
71 (void*)fmtString);
72 return ret;
73 };
74
82 static inline
83 cisOutput_t cisOutput(const char *name) {
84 cisOutput_t ret = cisOutputFmt(name, NULL);
85 return ret;
86 };
87
95 static inline
96 cisInput_t cisInput(const char *name){
97 cisInput_t ret = cisInputFmt(name, NULL);
98 return ret;
99 };
100
110 static inline
111 int cis_send(const cisOutput_t cisQ, const char *data, const size_t len) {
112 return comm_send(cisQ, data, len);
113 };
114
120 static inline
121 int cis_send_eof(const cisOutput_t cisQ) {
122 return comm_send_eof(cisQ);
123 };
124
135 static inline
136 int cis_recv(const cisInput_t cisQ, char *data, const size_t len){
137 return comm_recv(cisQ, data, len);
138 };
139
151 static inline
152 int cis_send_nolimit(const cisOutput_t cisQ, const char *data, const size_t len){
153 return comm_send_nolimit(cisQ, data, len);
154 };
155
161 static inline
162 int cis_send_nolimit_eof(const cisOutput_t cisQ) {
163 return comm_send_nolimit_eof(cisQ);
164 };
165
179 static inline
180 int cis_recv_nolimit(const cisInput_t cisQ, char **data, const size_t len0){
181 return comm_recv_nolimit(cisQ, data, len0);
182 };
183
184
185 //==============================================================================
205 //==============================================================================
206
216 static inline
217 int vcisSend(const cisOutput_t cisQ, va_list ap) {
218 return vcommSend(cisQ, ap);
219 };
220
233 static inline
234 int vcisRecv(const cisInput_t cisQ, va_list ap) {
235 return vcommRecv(cisQ, ap);
236 };
237
247 static inline
248 int cisSend(const cisOutput_t cisQ, ...){
249 va_list ap;
250 va_start(ap, cisQ);
251 int ret = vcommSend(cisQ, ap);
252 va_end(ap);
253 return ret;
254 };
255
267 static inline
268 int cisRecv(const cisInput_t cisQ, ...){
269 va_list ap;
270 va_start(ap, cisQ);
271 int ret = vcommRecv(cisQ, ap);
272 va_end(ap);
273 return ret;
274 };
275
286 static inline
287 int vcisSend_nolimit(const cisOutput_t cisQ, va_list ap) {
288 return vcommSend_nolimit(cisQ, ap);
289 };
290
303 static inline
304 int vcisRecv_nolimit(const cisInput_t cisQ, va_list ap) {
305 return vcommRecv_nolimit(cisQ, ap);
306 };
307
318 static inline
319 int cisSend_nolimit(const cisOutput_t cisQ, ...) {
320 va_list ap;
321 va_start(ap, cisQ);
322 int ret = vcommSend_nolimit(cisQ, ap);
323 va_end(ap);
324 return ret;
325 };
326
338 static inline
339 int cisRecv_nolimit(const cisInput_t cisQ, ...) {
340 va_list ap;
341 va_start(ap, cisQ);
342 int ret = vcommRecv_nolimit(cisQ, ap);
343 va_end(ap);
344 return ret;
345 };
346
347
348 //==============================================================================
386 //==============================================================================
387
393 #define cisRpc_t comm_t
394
405 static inline
406 cisRpc_t cisRpc(const char *name, const char *outFormat, const char *inFormat) {
407 return init_comm(name, outFormat, RPC_COMM, inFormat);
408 };
409
420 static inline
421 comm_t cisRpcClient(const char *name, const char *outFormat, const char *inFormat){
422 return init_comm(name, outFormat, CLIENT_COMM, inFormat);
423 };
424
435 static inline
436 comm_t cisRpcServer(const char *name, const char *inFormat, const char *outFormat){
437 return init_comm(name, inFormat, SERVER_COMM, outFormat);
438 };
439
450 static inline
451 int vrpcSend(const cisRpc_t rpc, va_list ap) {
452 int ret = vcommSend_nolimit(rpc, ap);
453 return ret;
454 };
455
469 static inline
470 int vrpcRecv(const cisRpc_t rpc, va_list ap) {
471 int ret = vcommRecv_nolimit(rpc, ap);
472 return ret;
473 };
474
485 static inline
486 int rpcSend(const cisRpc_t rpc, ...){
487 va_list ap;
488 va_start(ap, rpc);
489 int ret = vrpcSend(rpc, ap);
490 va_end(ap);
491 return ret;
492 };
493
507 static inline
508 int rpcRecv(const cisRpc_t rpc, ...) {
509 va_list ap;
510 va_start(ap, rpc);
511 int ret = vrpcRecv(rpc, ap);
512 va_end(ap);
513 return ret;
514 };
515
529 static inline
530 int vrpcCall(const cisRpc_t rpc, va_list ap) {
531 int sret, rret;
532 rret = 0;
533
534 // Create copy for receiving
535 va_list op;
536 va_copy(op, ap);
537
538 // pack the args and call
539 sret = vcommSend_nolimit(rpc, ap);
540 if (sret < 0) {
541 cislog_error("vrpcCall: vcisSend_nolimit error: ret %d: %s", sret, strerror(errno));
542 return -1;
543 }
544
545 // Advance through sent arguments
546 cislog_debug("vrpcCall: Used %d arguments in send", sret);
547 int i;
548 for (i = 0; i < sret; i++) {
549 va_arg(op, void*);
550 }
551
552 // unpack the messages into the remaining variable arguments
553 // va_list op;
554 // va_copy(op, ap);
555 rret = vcommRecv_nolimit(rpc, op);
556 va_end(op);
557
558 return rret;
559 };
560
574 static inline
575 int rpcCall(const cisRpc_t rpc, ...){
576 int ret;
577 va_list ap;
578 va_start(ap, rpc);
579 ret = vrpcCall(rpc, ap);
580 va_end(ap);
581 return ret;
582 };
583
584
585 //==============================================================================
621 //==============================================================================
622
624 #define cisAsciiFileInput_t comm_t
625 #define cisAsciiFileOutput_t comm_t
626
632 static inline
633 comm_t cisAsciiFileOutput(const char *name) {
634 comm_t out = init_comm(name, "send", _default_comm, NULL);
635 return out;
636 };
637
643 static inline
644 comm_t cisAsciiFileOutput_local(const char *name) {
645 comm_t out = init_comm(name, "send", ASCII_FILE_COMM, NULL);
646 return out;
647 };
648
654 static inline
655 comm_t cisAsciiFileInput(const char *name) {
656 comm_t out = init_comm(name, "recv", _default_comm, NULL);
657 return out;
658 };
659
660
666 static inline
667 comm_t cisAsciiFileInput_local(const char *name) {
668 comm_t out = init_comm(name, "recv", ASCII_FILE_COMM, NULL);
669 return out;
670 };
671
672
673
674 //==============================================================================
753 //==============================================================================
754
756 #define cisAsciiTableInput_t comm_t
757 #define cisAsciiTableOutput_t comm_t
758 #define cisAsciiArrayInput_t comm_t
759 #define cisAsciiArrayOutput_t comm_t
760
768 static inline
769 comm_t cisAsciiTableOutput(const char *name, const char *format_str) {
770 int flag = 0;
771 comm_t out = init_comm(name, "send", _default_comm, NULL);
772 if (out.valid) {
773 flag = update_serializer(out.serializer, ASCII_TABLE_SERI,
774 (void*)format_str);
775 if (flag == 0) {
776 asciiTable_t *table = (asciiTable_t*)(out.serializer->info);
777 flag = at_update(table, name, "0");
778 }
779 }
780 // TODO: Make sure this is freed.
781 /* asciiTable_t *table = (asciiTable_t*)malloc(sizeof(asciiTable_t)); */
782 /* table[0] = asciiTable(name, "0", format_str, */
783 /* NULL, NULL, NULL); */
784 /* out.serializer.type = ASCII_TABLE_SERI; */
785 /* out.serializer.info = (void*)table; */
786 if (flag < 0) {
787 out.valid = 0;
788 }
789 return out;
790 };
791
797 static inline
798 comm_t cisAsciiTableInput(const char *name) {
799 return init_comm(name, "recv", _default_comm, NULL);
800 };
801
809 static inline
810 comm_t cisAsciiTableOutput_local(const char *name, const char *format_str) {
811 return init_comm(name, "send", ASCII_TABLE_COMM, (void*)format_str);
812 };
813
819 static inline
820 comm_t cisAsciiTableInput_local(const char *name) {
821 return init_comm(name, "recv", ASCII_TABLE_COMM, NULL);
822 };
823
831 static inline
832 comm_t cisAsciiArrayOutput(const char *name, const char *format_str) {
833 comm_t out = cisAsciiTableOutput(name, format_str);
834 out.serializer->type = ASCII_TABLE_ARRAY_SERI;
835 return out;
836 };
837
843 static inline
844 comm_t cisAsciiArrayInput(const char *name) {
845 comm_t out = cisAsciiTableInput(name);
846 // Don't set this so it is updated when it is received.
847 // out.serializer->type = ASCII_TABLE_ARRAY_SERI;
848 return out;
849 };
850
858 static inline
859 comm_t cisAsciiArrayOutput_local(const char *name, const char *format_str) {
860 comm_t out = init_comm(name, "send", ASCII_TABLE_COMM, (void*)format_str);
861 out.serializer->type = ASCII_TABLE_ARRAY_SERI;
862 return out;
863 };
864
870 static inline
871 comm_t cisAsciiArrayInput_local(const char *name) {
872 comm_t out = init_comm(name, "recv", ASCII_TABLE_COMM, NULL);
873 out.serializer->type = ASCII_TABLE_ARRAY_SERI;
874 return out;
875 };
876
877 //==============================================================================
908 //==============================================================================
909
911 #define cisPlyInput_t comm_t
912 #define cisPlyOutput_t comm_t
913
919 static inline
920 comm_t cisPlyOutput(const char *name) {
921 int flag = 0;
922 comm_t out = init_comm(name, "send", _default_comm, NULL);
923 if (out.valid) {
924 flag = update_serializer(out.serializer, PLY_SERI, NULL);
925 }
926 if (flag < 0) {
927 out.valid = 0;
928 }
929 return out;
930 };
931
937 static inline
938 comm_t cisPlyInput(const char *name) {
939 return init_comm(name, "recv", _default_comm, NULL);
940 };
941
942
943 //==============================================================================
974 //==============================================================================
975
977 #define cisObjInput_t comm_t
978 #define cisObjOutput_t comm_t
979
985 static inline
986 comm_t cisObjOutput(const char *name) {
987 int flag = 0;
988 comm_t out = init_comm(name, "send", _default_comm, NULL);
989 if (out.valid) {
990 flag = update_serializer(out.serializer, OBJ_SERI, NULL);
991 }
992 if (flag < 0) {
993 out.valid = 0;
994 }
995 return out;
996 };
997
1003 static inline
1004 comm_t cisObjInput(const char *name) {
1005 return init_comm(name, "recv", _default_comm, NULL);
1006 };
1007
1008
1009 #ifdef __cplusplus /* If this is a C++ compiler, end C linkage */
1010 }
1011 #endif
1012
1013 #endif /*CISINTERFACE_H_*/
comm_t
Communication structure.
Definition: CommBase.h:23
asciiTable_t
Structure containing information about an ASCII table.
Definition: AsciiTable.h:80