File:  [ELWIX - Embedded LightWeight unIX -] / libaitrpc / example / tsrv.c
Revision 1.2: download - view: text, annotated - select for diffs - revision graph
Mon May 2 23:12:07 2011 UTC (13 years, 2 months ago) by misho
Branches: MAIN
CVS tags: rpc1_2, rpc1_1, RPC1_1, RPC1_0, HEAD
release 1.0

    1: #include <stdio.h>
    2: #include <pthread.h>
    3: #include <aitrpc.h>
    4: 
    5: 
    6: int aaa(rpc_func_t *f, int in, rpc_val_t *iv)
    7: {
    8: 	rpc_blob_t *b;
    9: 
   10: 	RPC_CALLBACK_CHECK_INPUT(f);
   11: 
   12: 	printf("%s(%d): Piuk! %s\n", __func__, __LINE__, f->func_name);
   13: 
   14: 	/*
   15: 	b = rpc_srv_registerBLOB(f->func_parent, BUFSIZ);
   16: 	if (!b)
   17: 		return -1;
   18: 	if (rpc_srv_blobMap(f->func_parent, b) == -1) {
   19: 		rpc_srv_blobFree(f->func_parent, b);
   20: 		return -1;
   21: 	}
   22: 
   23: 	memset(b->blob_data, 0, b->blob_len);
   24: 	strcpy(b->blob_data, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAa dsfsfsfnskjfnk\n");
   25: 
   26: 	rpc_srv_blobUnmap(b);
   27: 	*/
   28: 	return 0;
   29: }
   30: 
   31: int BBB(rpc_func_t *f, int in, rpc_val_t *iv)
   32: {
   33: 	rpc_val_t *v;
   34: 	rpc_blob_t *b;
   35: 
   36: 	RPC_CALLBACK_CHECK_INPUT(f);
   37: 
   38: 	printf("%s(%d): Piuk! %s  %d %s %X\n", __func__, __LINE__, f->func_name, 
   39: 			RPC_GET_I32(&iv[0]), RPC_GET_STR(&iv[1]), RPC_GET_BLOB(&iv[2]));
   40: 
   41: 	// input blob object
   42: 	if (!(b = rpc_srv_getBLOB(f->func_parent, RPC_GET_BLOB(&iv[2]))))
   43: 		return -1;
   44: 	if (rpc_srv_blobMap(f->func_parent, b) == -1) {
   45: 		rpc_srv_blobFree(f->func_parent, b);
   46: 		return -1;
   47: 	}
   48: 	printf("VAR=%X(%d):: %s\n", b->blob_var, b->blob_len, b->blob_data);
   49: 	rpc_srv_unregisterBLOB(f->func_parent, RPC_GET_BLOB(&iv[2]));
   50: 
   51: 
   52: 	rpc_srv_declValsCall(f, 4);
   53: 	rpc_srv_getValsCall(f, &v);
   54: 	RPC_SET_BUF(&v[0], "00!oo", 6);
   55: 	RPC_SET_I8(&v[1], 65);
   56: 	RPC_SET_STR(&v[2], "Oho boho i cheburashka");
   57: 
   58: 	// return blob object
   59: 	b = rpc_srv_registerBLOB(f->func_parent, 128);
   60: 	if (!b)
   61: 		return -1;
   62: 	else
   63: 		RPC_SET_BLOB2(&v[3], b);
   64: 
   65: 	if (rpc_srv_blobMap(f->func_parent, b) == -1) {
   66: 		rpc_srv_blobFree(f->func_parent, b);
   67: 		return -1;
   68: 	}
   69: 
   70: 	printf("data=%p blen=%d\n", b->blob_data, b->blob_len);
   71: 	memset(b->blob_data, 0, b->blob_len);
   72: 	strcpy(b->blob_data, "Hello Worldzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz mzdnfdskf\naddfs\n");
   73: 
   74: 	rpc_srv_blobUnmap(b);
   75: 	return 33;
   76: }
   77: 
   78: int main()
   79: {
   80: 	rpc_srv_t *srv;
   81: 	rpc_func_t *f;
   82: 	pthread_t tid[2];
   83: 	int ret;
   84: 
   85: 	srv = rpc_srv_initServer(100, 2, 1, 2, "0.0.0.0", 11111);
   86: 	if (!srv) {
   87: 		printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
   88: 		return 1;
   89: 	}
   90: 
   91: 	if (rpc_srv_initBLOBServer(srv, 0, "/tmp")) {
   92: 		printf("error:: errno=%d %s\n", rpc_GetErrno(), rpc_GetError());
   93: 		return 1;
   94: 	}
   95: 
   96: 	/* dump register functions
   97: 	for (f = srv->srv_funcs; f; f = f->func_next)
   98: 		printf("func::name=%s args=%d\n", f->func_name, f->func_args);
   99: 		*/
  100: 
  101: 	if (!fork()) {
  102: 		setsid();
  103: 
  104: 		rpc_srv_registerCall(srv, NULL, "aaa", 0);
  105: 		rpc_srv_registerCall(srv, NULL, "BBB", 4);
  106: 		rpc_srv_registerCall(srv, NULL, "dummy", 1);
  107: 		rpc_srv_registerCall(srv, NULL, "xYz", 2);
  108: 
  109: 		rpc_srv_unregisterCall(srv, NULL, "dummy");
  110: 
  111: 		pthread_create(&tid[1], NULL, (void*(*)(void*)) rpc_srv_execBLOBServer, srv);
  112: 		rpc_srv_execServer(srv);
  113: 	}
  114: 
  115: 	rpc_srv_endServer(srv);
  116: 	return 0;
  117: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>