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