Annotation of libaitrpc/example/tsrv.c, revision 1.7.4.5
1.1 misho 1: #include <stdio.h>
1.2 misho 2: #include <pthread.h>
1.1 misho 3: #include <aitrpc.h>
1.7.4.3 misho 4: #include "rc.h"
1.1 misho 5:
1.3 misho 6:
1.7.4.5 ! misho 7: int aaa(rpc_func_t *f, struct tagRPCCall *rpc, array_t *iv)
1.1 misho 8: {
1.2 misho 9: rpc_blob_t *b;
10:
11: RPC_CALLBACK_CHECK_INPUT(f);
1.1 misho 12:
1.7.4.3 misho 13: printf("%s(%d): Piuk! %p(0x%x)\n", __func__, __LINE__,
14: AIT_GET_PTR(&f->func_name), AIT_KEY(&f->func_name));
1.2 misho 15:
16: /*
17: b = rpc_srv_registerBLOB(f->func_parent, BUFSIZ);
18: if (!b)
19: return -1;
20: if (rpc_srv_blobMap(f->func_parent, b) == -1) {
21: rpc_srv_blobFree(f->func_parent, b);
22: return -1;
23: }
24:
25: memset(b->blob_data, 0, b->blob_len);
26: strcpy(b->blob_data, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAa dsfsfsfnskjfnk\n");
27:
28: rpc_srv_blobUnmap(b);
29: */
1.1 misho 30: return 0;
31: }
32:
1.7.4.5 ! misho 33: int BBB(rpc_func_t *f, struct tagRPCCall *rpc, array_t *iv)
1.1 misho 34: {
1.4 misho 35: ait_val_t *v;
1.2 misho 36: rpc_blob_t *b;
1.1 misho 37:
1.2 misho 38: RPC_CALLBACK_CHECK_INPUT(f);
1.1 misho 39:
1.7.4.3 misho 40: printf("%s(%d): Piuk! %p(0x%x) %d %s %X\n", __func__, __LINE__,
41: AIT_GET_PTR(&f->func_name), AIT_KEY(&f->func_name),
1.4 misho 42: AIT_GET_I32(io_array(iv, 0, ait_val_t*)), AIT_GET_STR(io_array(iv, 1, ait_val_t*)),
43: AIT_GET_BLOB(io_array(iv, 2, ait_val_t*)));
1.7.4.3 misho 44: printf("%s(%d): Piuk! %p(0x%x) %d %s %X\n", __func__, __LINE__,
45: AIT_GET_PTR(&f->func_name), AIT_KEY(&f->func_name),
1.4 misho 46: AIT_GET_I32(io_array(iv, 0, ait_val_t*)), AIT_GET_STR(io_array(iv, 1, ait_val_t*)));
1.1 misho 47:
1.2 misho 48: // input blob object
1.4 misho 49: if (!(b = rpc_srv_getBLOB(f->func_parent, AIT_GET_BLOB(io_array(iv, 2, ait_val_t*)))))
1.2 misho 50: return -1;
51: if (rpc_srv_blobMap(f->func_parent, b) == -1) {
52: rpc_srv_blobFree(f->func_parent, b);
53: return -1;
54: }
55: printf("VAR=%X(%d):: %s\n", b->blob_var, b->blob_len, b->blob_data);
1.4 misho 56: rpc_srv_blobUnmap(b);
57: rpc_srv_unregisterBLOB(f->func_parent, AIT_GET_BLOB(io_array(iv, 2, ait_val_t*)));
1.2 misho 58:
59:
1.7.4.2 misho 60: v = io_array(f->func_vars, 0, ait_val_t*);
1.4 misho 61: AIT_SET_BUF(v, "00!oo", 6);
1.7.4.2 misho 62: v = io_array(f->func_vars, 1, ait_val_t*);
1.4 misho 63: AIT_SET_I8(v, 65);
1.7.4.2 misho 64: v = io_array(f->func_vars, 2, ait_val_t*);
1.4 misho 65: AIT_SET_STR(v, "Oho boho i cheburashka");
1.2 misho 66:
67: // return blob object
68: b = rpc_srv_registerBLOB(f->func_parent, 128);
69: if (!b)
70: return -1;
1.4 misho 71: else {
1.7.4.3 misho 72: v = io_array(f->func_vars, 3, ait_val_t*);
1.4 misho 73: AIT_SET_BLOB2(v, b);
1.2 misho 74: }
75:
76: printf("data=%p blen=%d\n", b->blob_data, b->blob_len);
77: memset(b->blob_data, 0, b->blob_len);
78: strcpy(b->blob_data, "Hello Worldzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz mzdnfdskf\naddfs\n");
79:
80: rpc_srv_blobUnmap(b);
1.1 misho 81: return 33;
82: }
83:
1.7.4.5 ! misho 84: int xxx(rpc_func_t *f, struct tagRPCCall *rpc, array_t *iv)
1.7 misho 85: {
86: ait_val_t *v;
87:
88: RPC_CALLBACK_CHECK_INPUT(f);
89:
90: printf("iv_s=%d\n", io_arraySize(iv));
1.7.4.3 misho 91: printf("%s(%d): Piuk! %p(0x%x) --- %s\n", __func__, __LINE__,
92: AIT_GET_PTR(&f->func_name), AIT_KEY(&f->func_name),
1.7 misho 93: AIT_GET_BUF(io_array(iv, 0, ait_val_t*)));
94: fflush(stdout);
95:
1.7.4.2 misho 96: v = io_array(f->func_vars, 0, ait_val_t*);
1.7 misho 97: AIT_SET_DATA(v, "00!oo", 6);
1.7.4.2 misho 98: io_arraySet(f->func_vars, 0, v);
99: v = io_array(f->func_vars, 1, ait_val_t*);
1.7 misho 100: AIT_SET_I8(v, 65);
1.7.4.2 misho 101: io_arraySet(f->func_vars, 1, v);
1.7 misho 102: return 111;
103: }
104:
1.7.4.5 ! misho 105: int xYz(rpc_func_t *f, struct tagRPCCall *rpc, array_t *iv)
1.7.4.2 misho 106: {
107: return 0;
108: }
109:
1.7 misho 110:
1.1 misho 111: int main()
112: {
113: rpc_srv_t *srv;
114: rpc_func_t *f;
1.2 misho 115: int ret;
1.1 misho 116:
1.7.4.2 misho 117: srv = rpc_srv_initServer(100, 2, 2, 1024 * 10, "0.0.0.0", 11111);
118: // srv = rpc_srv_initServer(100, 2, 1, 1024 * 10, "0.0.0.0", 11111);
1.1 misho 119: if (!srv) {
120: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
121: return 1;
122: }
123:
1.2 misho 124: if (rpc_srv_initBLOBServer(srv, 0, "/tmp")) {
125: printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
126: return 1;
127: }
1.1 misho 128:
1.7.4.3 misho 129: rpc_srv_registerCall(srv, RC_aaa, aaa, 0);
130: rpc_srv_registerCall(srv, RC_BBB, BBB, 4);
1.7.4.2 misho 131: rpc_srv_registerCall(srv, 3, NULL, 1);
1.7.4.3 misho 132: rpc_srv_registerCall(srv, RC_xYz, xYz, 2);
133: rpc_srv_registerCall(srv, RC_xxx, xxx, 2);
1.7.4.2 misho 134:
135: rpc_srv_unregisterCall(srv, 4);
136:
1.7.4.4 misho 137: rpc_register_srvServices(srv);
138: rpc_register_blobServices(srv);
139:
1.7.4.3 misho 140: rpc_srv_execBLOBServer(srv);
1.7.4.2 misho 141: rpc_srv_loopServer(srv);
1.1 misho 142:
1.3 misho 143: rpc_srv_endBLOBServer(srv);
1.5 misho 144: rpc_srv_endServer(&srv);
1.1 misho 145: return 0;
146: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>