--- libaitrpc/inc/aitrpc.h 2011/09/01 11:39:26 1.3.2.5 +++ libaitrpc/inc/aitrpc.h 2011/09/03 12:39:27 1.3.2.6 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: aitrpc.h,v 1.3.2.5 2011/09/01 11:39:26 misho Exp $ +* $Id: aitrpc.h,v 1.3.2.6 2011/09/03 12:39:27 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -79,9 +79,9 @@ SUCH DAMAGE. /* RPC types */ typedef enum { - disable, enable, kill, /* for blob.state */ - ok, error, /* for blob reply */ - get, set, unset /* for blob request */ + disable, enable, running, kill, /* for blob.state */ + ok, error, /* for blob reply */ + get, set, unset /* for blob request */ } cmd_type_t; @@ -247,11 +247,19 @@ rpc_srv_t *rpc_srv_initServer(u_int regProgID, u_int r */ void rpc_srv_endServer(rpc_srv_t * __restrict srv); /* - * rpc_srv_execServer() Execute Main server loop and wait for clients requests + * rpc_srv_loopServer() Execute Main server loop and wait for clients requests * @srv = RPC Server instance * return: -1 error or 0 ok, infinite loop ... */ -int rpc_srv_execServer(rpc_srv_t * __restrict srv); +int rpc_srv_loopServer(rpc_srv_t * __restrict srv); +#define rpc_srv_execServer(_srv, _sync) do { assert((_srv)); pthread_t __tid; \ + pthread_create(&__tid, NULL, (void*(*)(void*)) \ + rpc_srv_loopServer, (_srv)); \ + if ((_sync)) \ + pthread_join(__tid, (void**) (_sync)); \ + else \ + pthread_detach(__tid); \ + } while (0) /* * rpc_srv_initBLOBServer() Init & create BLOB Server @@ -268,11 +276,19 @@ int rpc_srv_initBLOBServer(rpc_srv_t * __restrict srv, */ void rpc_srv_endBLOBServer(rpc_srv_t * __restrict srv); /* - * rpc_srv_execBLOBServer() Execute Main BLOB server loop and wait for clients requests + * rpc_srv_loopBLOB() Execute Main BLOB server loop and wait for clients requests * @srv = RPC Server instance * return: -1 error or 0 ok, infinite loop ... */ -int rpc_srv_execBLOBServer(rpc_srv_t * __restrict srv); +int rpc_srv_loopBLOB(rpc_srv_t * __restrict srv); +#define rpc_srv_execBLOBServer(_srv) do { assert((_srv)); pthread_t __tid; \ + if ((_srv)->srv_blob.state == enable) { \ + pthread_create(&__tid, NULL, (void*(*)(void*)) \ + rpc_srv_loopBLOB, (_srv)); \ + pthread_detach(__tid); \ + (_srv)->srv_blob.state = running; \ + } \ + } while (0) /* * rpc_srv_registerCall() Register call to RPC server