Annotation of libaitrpc/inc/aitrpc.h, revision 1.1.1.1.2.21

1.1       misho       1: /*************************************************************************
                      2: * (C) 2010 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>
                      3: *  by Michael Pounov <misho@openbsd-bg.org>
                      4: *
                      5: * $Author: misho $
1.1.1.1.2.21! misho       6: * $Id: aitrpc.h,v 1.1.1.1.2.20 2010/07/08 09:18:51 misho Exp $
1.1       misho       7: *
                      8: *************************************************************************/
                      9: #ifndef __AITRPC_H
                     10: #define __AITRPC_H
                     11: 
                     12: 
                     13: #include <assert.h>
                     14: #include <stdlib.h>
                     15: #include <string.h>
                     16: #include <sys/types.h>
                     17: #include <sys/param.h>
                     18: #include <sys/limits.h>
                     19: #include <sys/socket.h>
                     20: 
                     21: 
                     22: #define RPC_VERSION            1
                     23: #define RPC_DEFPORT            2611
                     24: 
                     25: 
                     26: /* RPC builtin registed calls */
                     27: 
1.1.1.1.2.5  misho      28: #define CALL_BLOBSHUTDOWN      "rpcBLOBServerShutdown"
                     29: #define CALL_BLOBCLIENTS       "rpcBLOBServerClients"
                     30: #define CALL_BLOBVARS          "rpcBLOBServerVars"
1.1.1.1.2.12  misho      31: #define CALL_BLOBSTATE         "rpcBLOBServerState"
1.1.1.1.2.5  misho      32: 
1.1.1.1.2.1  misho      33: #define CALL_SRVSHUTDOWN       "rpcServerShutdown"
1.1       misho      34: #define CALL_SRVCLIENTS                "rpcServerClients"
                     35: #define CALL_SRVCALLS          "rpcServerCalls"
                     36: #define CALL_SRVSESSIONS       "rpcServerSessions"
                     37: 
                     38: 
                     39: /* RPC types */
                     40: 
                     41: typedef enum {
                     42:        empty,                          // empty -> variable is not set
1.1.1.1.2.3  misho      43:        buffer, string, blob,           // buffer -> uint8_t*; string -> int8_t*; blob -> void*(+socket);
1.1       misho      44:        size, offset, datetime,         // size -> size_t; offset -> off_t; datetime -> time_t;
                     45:        real, bigreal,                  // real -> float; bigreal -> double;
                     46:        u8, u16, u32, u64,              // unsigned integers ...
                     47:        i8, i16, i32, i64               // integers ...
                     48: } rpc_type_t;
                     49: 
1.1.1.1.2.6  misho      50: typedef enum {
1.1.1.1.2.8  misho      51:        disable, enable,                // for blob.state
                     52:        ok, error,                      // for blob reply
                     53:        get, set, unset                 // for blob request
1.1.1.1.2.6  misho      54: } cmd_type_t;
                     55: 
1.1       misho      56: /* RPC value */
                     57: 
                     58: typedef struct {
                     59:        rpc_type_t      val_type;
                     60:        size_t          val_len;
                     61:        union {
                     62:                uint8_t         *buffer;
                     63:                int8_t          *string;
1.1.1.1.2.17  misho      64:                uint32_t        blob;
1.1       misho      65:                size_t          size;
                     66:                off_t           offset;
                     67:                time_t          datetime;
                     68:                float           real;
                     69:                double          bigreal;
                     70:                uint8_t         u8;
                     71:                uint16_t        u16;
                     72:                uint32_t        u32;
                     73:                uint64_t        u64;
                     74:                int8_t          i8;
                     75:                int16_t         i16;
                     76:                int32_t         i32;
                     77:                int64_t         i64;
                     78:        } val;
                     79: } __packed rpc_val_t;
                     80: 
                     81: #define RPC_TYPE_VAL(vl)               ((vl)->val_type)
                     82: #define RPC_LEN_VAL(vl)                        ((vl)->val_len)
1.1.1.1.2.3  misho      83: #define RPC_BLOB_CHUNKS(vl, n)         ((vl)->val_len / (n) + ((vl)->val_len % (n)) ? 1 : 0)
1.1       misho      84: #define RPC_EMPTY_VAL(vl)              ((vl)->val_type == empty)
                     85: 
                     86: #define RPC_GET_BUF(vl)                        (assert((vl)->val_type == buffer), (vl)->val.buffer)
                     87: #define RPC_GET_STR(vl)                        (assert((vl)->val_type == string), (vl)->val.string)
1.1.1.1.2.3  misho      88: #define RPC_GET_BLOB(vl)               (assert((vl)->val_type == blob), (vl)->val.blob)
1.1       misho      89: #define RPC_GET_SIZE(vl)               (assert((vl)->val_type == size), (vl)->val.size)
                     90: #define RPC_GET_OFF(vl)                        (assert((vl)->val_type == offset), (vl)->val.offset)
                     91: #define RPC_GET_TIME(vl)               (assert((vl)->val_type == datetime), (vl)->val.datetime)
                     92: #define RPC_GET_REAL(vl)               (assert((vl)->val_type == real), (vl)->val.real)
                     93: #define RPC_GET_BREAL(vl)              (assert((vl)->val_type == bigreal), (vl)->val.bigreal)
                     94: #define RPC_GET_U8(vl)                 (assert((vl)->val_type == u8), (vl)->val.u8)
                     95: #define RPC_GET_U16(vl)                        (assert((vl)->val_type == u16), (vl)->val.u16)
                     96: #define RPC_GET_U32(vl)                        (assert((vl)->val_type == u32), (vl)->val.u32)
                     97: #define RPC_GET_U64(vl)                        (assert((vl)->val_type == u64), (vl)->val.u64)
                     98: #define RPC_GET_I8(vl)                 (assert((vl)->val_type == i8), (vl)->val.i8)
                     99: #define RPC_GET_I16(vl)                        (assert((vl)->val_type == i16), (vl)->val.i16)
                    100: #define RPC_GET_I32(vl)                        (assert((vl)->val_type == i32), (vl)->val.i32)
                    101: #define RPC_GET_I64(vl)                        (assert((vl)->val_type == i64), (vl)->val.i64)
                    102: 
                    103: #define RPC_SET_BUF(vl, v, l)          do { rpc_val_t *val = (vl); assert(val); val->val.buffer = malloc(l); \
                    104:                                                if (val->val.buffer) { \
                    105:                                                        val->val_type = buffer; val->val_len = l; \
                    106:                                                        memcpy(val->val.buffer, v, l); \
                    107:                                                } } while (0)
                    108: #define RPC_SET_STR(vl, v)             do { rpc_val_t *val = (vl); assert(val); val->val.string = (int8_t*) strdup(v); \
                    109:                                                if (val->val.string) { \
                    110:                                                        val->val_type = string; val->val_len = strlen(v) + 1; \
                    111:                                                } } while (0)
1.1.1.1.2.17  misho     112: #define RPC_SET_BLOB(vl, v, l)         do { rpc_val_t *val = (vl); assert(val); val->val_type = blob; \
                    113:                                                val->val.blob = v; val->val_len = l; } while (0)
                    114: #define RPC_SET_BLOB2(vl, b)           do { rpc_val_t *val = (vl); assert(val); assert(b); val->val_type = blob; \
                    115:                                                val->val.blob = b->blob_var; val->val_len = b->blob_len; } while (0)
1.1       misho     116: #define RPC_SET_SIZE(vl, v)            do { rpc_val_t *val = (vl); assert(val); val->val_type = size; val->val.size = v; \
                    117:                                                val->val_len = sizeof(size_t); } while (0)
                    118: #define RPC_SET_OFF(vl, v)             do { rpc_val_t *val = (vl); assert(val); val->val_type = offset; val->val.offset = v; \
                    119:                                                val->val_len = sizeof(off_t); } while (0)
                    120: #define RPC_SET_TIME(vl, v)            do { rpc_val_t *val = (vl); assert(val); val->val_type = datetime; val->val.datetime = v; \
                    121:                                                val->val_len = sizeof(time_t); } while (0)
                    122: #define RPC_SET_REAL(vl, v)            do { rpc_val_t *val = (vl); assert(val); val->val_type = real; val->val.real = v; \
                    123:                                                val->val_len = sizeof(float); } while (0)
                    124: #define RPC_SET_BREAL(vl, v)           do { rpc_val_t *val = (vl); assert(val); val->val_type = bigreal; val->val.bigreal = v; \
                    125:                                                val->val_len = sizeof(double); } while (0)
                    126: #define RPC_SET_U8(vl, v)              do { rpc_val_t *val = (vl); assert(val); val->val_type = u8; val->val.u8 = v; \
                    127:                                                val->val_len = sizeof(uint8_t); } while (0)
                    128: #define RPC_SET_U16(vl, v)             do { rpc_val_t *val = (vl); assert(val); val->val_type = u16; val->val.u16 = v; \
                    129:                                                val->val_len = sizeof(uint16_t); } while (0)
                    130: #define RPC_SET_U32(vl, v)             do { rpc_val_t *val = (vl); assert(val); val->val_type = u32; val->val.u32 = v; \
                    131:                                                val->val_len = sizeof(uint32_t); } while (0)
                    132: #define RPC_SET_U64(vl, v)             do { rpc_val_t *val = (vl); assert(val); val->val_type = u64; val->val.u64 = v; \
                    133:                                                val->val_len = sizeof(uint64_t); } while (0)
                    134: #define RPC_SET_I8(vl, v)              do { rpc_val_t *val = (vl); assert(val); val->val_type = i8; val->val.i8 = v; \
                    135:                                                val->val_len = sizeof(int8_t); } while (0)
                    136: #define RPC_SET_I16(vl, v)             do { rpc_val_t *val = (vl); assert(val); val->val_type = i16; val->val.i16 = v; \
                    137:                                                val->val_len = sizeof(int16_t); } while (0)
                    138: #define RPC_SET_I32(vl, v)             do { rpc_val_t *val = (vl); assert(val); val->val_type = i32; val->val.i32 = v; \
                    139:                                                val->val_len = sizeof(int32_t); } while (0)
                    140: #define RPC_SET_I64(vl, v)             do { rpc_val_t *val = (vl); assert(val); val->val_type = i64; val->val.i64 = v; \
                    141:                                                val->val_len = sizeof(int64_t); } while (0)
                    142: 
                    143: #define RPC_FREE_VAL(vl)               do { rpc_val_t *val = (vl); assert(val); \
                    144:                                                if (val->val_type == buffer && val->val.buffer) { \
                    145:                                                        free(val->val.buffer); \
                    146:                                                        val->val.buffer = NULL; \
                    147:                                                } \
                    148:                                                if (val->val_type == string && val->val.string) { \
                    149:                                                        free(val->val.string); \
                    150:                                                        val->val.string = NULL; \
                    151:                                                } \
                    152:                                                val->val_type = val->val_len = 0; \
                    153:                                        } while (0)
                    154: 
                    155: 
1.1.1.1.2.18  misho     156: #define RPC_CALLBACK_CHK_RETARGS(f, n) do { \
1.1       misho     157:                                                if (f->func_args != n) { \
                    158:                                                        rpc_SetErr(22, "Error:: different number of arguments!\n"); \
                    159:                                                        return -1; \
                    160:                                                } \
1.1.1.1.2.1  misho     161:                                        } while (0)
1.1.1.1.2.11  misho     162: #define RPC_CALLBACK_CHECK_INPUT(f)    do { \
                    163:                                                if (!f) { \
1.1.1.1.2.1  misho     164:                                                        rpc_SetErr(22, "Error:: invalid callback parameters ...\n"); \
                    165:                                                        return -1; \
                    166:                                                } \
                    167:                                        } while (0)
1.1       misho     168: 
                    169: 
                    170: /* RPC session identification */
                    171: 
                    172: typedef struct {
                    173:        uint8_t         sess_version;
                    174:        uint32_t        sess_program;
                    175:        uint32_t        sess_process;
                    176: } __packed rpc_sess_t;
                    177: 
                    178: 
                    179: /* Server managment RPC functions ... */
                    180: 
                    181: // RPC function registration element!
                    182: typedef struct tagRPCFunc {
                    183:        uint16_t                func_tag;
                    184:        uint32_t                func_hash;
                    185:        int8_t                  func_file[MAXPATHLEN];
                    186:        int8_t                  func_name[UCHAR_MAX + 1];
                    187: 
                    188:        int8_t                  func_args;
                    189:        rpc_val_t               *func_vals;
                    190: 
1.1.1.1.2.11  misho     191:        void                    *func_parent;
1.1       misho     192:        struct tagRPCFunc       *func_next;
                    193: } rpc_func_t;
                    194: 
                    195: 
                    196: /* Network RPC packet - Client request */
                    197: 
                    198: struct tagRPCCall {
                    199:        rpc_sess_t      call_session;
                    200:        uint16_t        call_tag;
                    201:        uint32_t        call_hash;
                    202:        uint8_t         call_argc;
                    203: } __packed;
                    204: 
                    205: /* Network RPC packet - Server response */
                    206: 
                    207: struct tagRPCRet {
                    208:        rpc_sess_t      ret_session;
                    209:        uint16_t        ret_tag;
                    210:        uint32_t        ret_hash;
                    211:        int32_t         ret_retcode;
                    212:        int32_t         ret_errno;
                    213:        uint8_t         ret_argc;
                    214: } __packed;
                    215: 
1.1.1.1.2.6  misho     216: /* Network BLOB packet - Header */
                    217: 
                    218: struct tagBLOBHdr {
                    219:        rpc_sess_t      hdr_session;
                    220:        uint8_t         hdr_cmd;
                    221:        uint32_t        hdr_var;
                    222:        uint32_t        hdr_len;
1.1.1.1.2.19  misho     223:        uint32_t        hdr_ret;
1.1.1.1.2.6  misho     224: } __packed;
                    225: 
1.1       misho     226: /* Network RPC client & server elements */
                    227: 
                    228: typedef struct {
                    229:        struct sockaddr cli_sa;         // host info
                    230:        int             cli_sock;       // socket
                    231:        pthread_t       cli_tid;        // TID of thread
                    232: 
                    233:        void            *cli_parent;    // pointer to parent rpc_srv_t for server or to rpc_sess_t for client
                    234: } rpc_cli_t;
                    235: 
                    236: 
1.1.1.1.2.5  misho     237: // BLOB registration element!
                    238: typedef struct tagBLOB {
1.1.1.1.2.6  misho     239:        uint32_t        blob_var;
                    240: 
1.1.1.1.2.5  misho     241:        size_t          blob_len;       // size of allocated BLOB data
                    242:        void            *blob_data;     // BLOB data
                    243: 
                    244:        struct tagBLOB  *blob_next;
                    245: } rpc_blob_t;
                    246: 
                    247: typedef struct {
1.1       misho     248:        rpc_sess_t      srv_session;    // RPC session registration info
1.1.1.1.2.5  misho     249:        int             srv_numcli;     // maximum concurent client connections
1.1       misho     250: 
1.1.1.1.2.5  misho     251:        rpc_cli_t       srv_server;     // RPC server socket
                    252:        rpc_cli_t       *srv_clients;   // connected rpc client sockets
1.1       misho     253: 
                    254:        rpc_func_t      *srv_funcs;     // registered functions list
1.1.1.1.2.5  misho     255: 
                    256:        pthread_mutex_t srv_mtx;
                    257: 
                    258:        struct {
                    259:                int             state;          // BLOB server state: ==0 disable | !=0 enable
1.1.1.1.2.6  misho     260:                char            dir[UCHAR_MAX + 1];
1.1.1.1.2.5  misho     261: 
                    262:                rpc_cli_t       server;         // BLOB server socket
                    263:                rpc_cli_t       *clients;       // connected blob client sockets
                    264: 
                    265:                rpc_blob_t      *blobs;         // registered blob variables list
                    266: 
                    267:                pthread_mutex_t mtx;
                    268:        }               srv_blob;
1.1       misho     269: } rpc_srv_t;
                    270: 
                    271: 
1.1.1.1.2.11  misho     272: /* 
                    273:  * (*rpc_callback_t)() Callback type definition for RPC call in server process
                    274:  * @arg1 = current execution RPC call function
                    275:  * @arg2 = number of items in input array from call request
                    276:  * @arg3 = input array with values from RPC call execution request
                    277:  * return: -1 error or >-1 success execution
                    278:  */
                    279: typedef int (*rpc_callback_t)(rpc_func_t *, int, rpc_val_t *);
1.1       misho     280: 
                    281: 
                    282: // -----------------------------------------------------------------------
                    283: 
                    284: /* Error support functions */
                    285: 
                    286: // cli_GetErrno() Get error code of last operation
                    287: inline int cli_GetErrno();
                    288: // cli_GetError() Get error text of last operation
                    289: inline const char *cli_GetError();
                    290: 
                    291: 
                    292: /* RPC Server side functions */
                    293: 
                    294: /*
                    295:  * rpc_srv_initServer() Init & create RPC Server
                    296:  * @regProgID = ProgramID for authentication & recognition
                    297:  * @regProcID = ProcessID for authentication & recognition
                    298:  * @concurentClients = Concurent clients at same time to this server
                    299:  * @family = Family socket type, AF_INET or AF_INET6
                    300:  * @csHost = Host name or IP address for bind server, if NULL any address
                    301:  * @Port = Port for bind server, if Port == 0 default port is selected
                    302:  * return: NULL == error or !=NULL bind and created RPC server instance
                    303:  */
                    304: rpc_srv_t *rpc_srv_initServer(u_int regProgID, u_int regProcID, int concurentClients, 
                    305:                u_short family, const char *csHost, u_short Port);
                    306: /*
                    307:  * rpc_srv_endServer() Destroy RPC server, close all opened sockets and free resources
                    308:  * @srv = RPC Server instance
                    309:  * return: none
                    310:  */
                    311: void rpc_srv_endServer(rpc_srv_t * __restrict srv);
                    312: /*
                    313:  * rpc_srv_execServer() Execute Main server loop and wait for clients requests
                    314:  * @srv = RPC Server instance
                    315:  * return: -1 error or 0 ok, infinite loop ...
                    316:  */
                    317: int rpc_srv_execServer(rpc_srv_t * __restrict srv);
                    318: 
                    319: /*
1.1.1.1.2.5  misho     320:  * rpc_srv_initBLOBServer() Init & create BLOB Server
                    321:  * @Port = Port for bind server, if Port == 0 default port is selected
1.1.1.1.2.6  misho     322:  * @diskDir = Disk place for BLOB file objects
1.1.1.1.2.5  misho     323:  * return: -1 == error or 0 bind and created BLOB server instance
                    324:  */
1.1.1.1.2.6  misho     325: int rpc_srv_initBLOBServer(rpc_srv_t * __restrict srv, u_short Port, const char *diskDir);
1.1.1.1.2.5  misho     326: /*
                    327:  * rpc_srv_endBLOBServer() Destroy BLOB server, close all opened sockets and free resources
                    328:  * @srv = RPC Server instance
                    329:  * return: none
                    330:  */
                    331: void rpc_srv_endBLOBServer(rpc_srv_t * __restrict srv);
                    332: /*
                    333:  * rpc_srv_execBLOBServer() Execute Main BLOB server loop and wait for clients requests
                    334:  * @srv = RPC Server instance
                    335:  * return: -1 error or 0 ok, infinite loop ...
                    336:  */
                    337: int rpc_srv_execBLOBServer(rpc_srv_t * __restrict srv);
                    338: 
                    339: /*
1.1       misho     340:  * rpc_srv_registerCall() Register call to RPC server
                    341:  * @srv = RPC Server instance
                    342:  * @csModule = Module name, if NULL self binary
                    343:  * @csFunc = Function name
1.1.1.1.2.17  misho     344:  * @args = Number of return function arguments, use for restriction case!
1.1       misho     345:  * return: -1 error or 0 register ok
                    346:  */
                    347: int rpc_srv_registerCall(rpc_srv_t * __restrict srv, const char *csModule, const char *csFunc, 
                    348:                unsigned char args);
                    349: /*
                    350:  * rpc_srv_unregisterCall() Unregister call from RPC server
                    351:  * @srv = RPC Server instance
                    352:  * @csModule = Module name, if NULL self binary
                    353:  * @csFunc = Function name
                    354:  * return: -1 error, 0 not found call, 1 unregister ok
                    355:  */
                    356: int rpc_srv_unregisterCall(rpc_srv_t * __restrict srv, const char *csModule, const char *csFunc);
                    357: /*
                    358:  * rpc_srv_getFunc() Get registered call from RPC server by Name
                    359:  * @srv = RPC Server instance
                    360:  * @csModule = Module name, if NULL self binary
                    361:  * @csFunc = Function name
                    362:  * return: NULL not found call, !=NULL return call
                    363:  */
                    364: rpc_func_t *rpc_srv_getFunc(rpc_srv_t * __restrict srv, const char *csModule, const char *csFunc);
                    365: /*
                    366:  * rpc_srv_getCall() Get registered call from RPC server
                    367:  * @srv = RPC Server instance
                    368:  * @tag = tag for function
                    369:  * @hash = hash for function
                    370:  * return: NULL not found call, !=NULL return call
                    371:  */
                    372: inline rpc_func_t *rpc_srv_getCall(rpc_srv_t * __restrict srv, uint16_t tag, uint32_t hash);
                    373: /*
                    374:  * rpc_srv_execCall() Execute registered call from RPC server
                    375:  * @call = Register RPC call
                    376:  * @rpc = IN RPC call structure
                    377:  * @args = IN RPC call array of rpc values
                    378:  * return: -1 error, !=-1 ok
                    379:  */
1.1.1.1.2.11  misho     380: int rpc_srv_execCall(rpc_func_t * __restrict call, struct tagRPCCall * __restrict rpc, 
                    381:                rpc_val_t * __restrict args);
1.1       misho     382: 
                    383: 
                    384: /*
1.1.1.1.2.11  misho     385:  * rpc_srv_retValsCall() Declare return variables for RPC call and zeroed values
                    386:                                        (for safe handling return values, use this!)
                    387:  * @call = RPC function call
                    388:  * @return_vals = Number of return variables
                    389:  * return: NULL error, !=NULL array with return values for RPC call with return_vals items
                    390:  */
                    391: inline rpc_val_t *rpc_srv_retValsCall(rpc_func_t * __restrict call, int return_vals);
                    392: /*
                    393:  * rpc_srv_declValsCall() Declare return variables for RPC call, 
                    394:                                if already allocated memory for RPC call return values 
                    395:                                function reallocate used space with return_vals count elements
1.1       misho     396:  * @call = RPC function call
                    397:  * @return_vals = Number of return variables
                    398:  * return: -1 error, !=-1 ok
                    399:  */
                    400: inline int rpc_srv_declValsCall(rpc_func_t * __restrict call, int return_vals);
                    401: /*
                    402:  * rpc_srv_freeValsCall() Free return variables for RPC call
                    403:  * @call = RPC function call
                    404:  * return: none
                    405:  */
                    406: inline void rpc_srv_freeValsCall(rpc_func_t * __restrict call);
                    407: /*
                    408:  * rpc_srv_copyValsCall() Copy return variables for RPC call to new variable
                    409:  * @call = RPC function call
                    410:  * @newvals = New allocated variables array, must be free after use
                    411:  * return: -1 error, !=-1 Returned number of copied RPC variables
                    412:  */
                    413: inline int rpc_srv_copyValsCall(rpc_func_t * __restrict call, rpc_val_t ** __restrict newvals);
                    414: /*
1.1.1.1.2.11  misho     415:  * rpc_srv_zeroValsCall() Clean values from return variables of RPC call
1.1       misho     416:  * @call = RPC function call
                    417:  * return: -1 error, !=-1 Returned number of cleaned RPC variables
                    418:  */
1.1.1.1.2.11  misho     419: inline int rpc_srv_zeroValsCall(rpc_func_t * __restrict call);
1.1       misho     420: /*
                    421:  * rpc_srv_getValsCall() Get return variables for RPC call
                    422:  * @call = RPC function call
                    423:  * @vals = Returned variables, may be NULL
                    424:  * return: -1 error, !=-1 Number of returned variables
                    425:  */
                    426: inline int rpc_srv_getValsCall(rpc_func_t * __restrict call, rpc_val_t ** __restrict vals);
                    427: 
                    428: 
1.1.1.1.2.7  misho     429: /*
1.1.1.1.2.10  misho     430:  * rpc_srv_blobCreate() Create map blob to memory region and return object
                    431:  * @srv = RPC Server instance
                    432:  * @len = BLOB length object
                    433:  * return: NULL error or !=NULL allocated BLOB object
                    434:  */
                    435: inline rpc_blob_t *rpc_srv_blobCreate(rpc_srv_t * __restrict srv, int len);
                    436: /*
1.1.1.1.2.7  misho     437:  * rpc_srv_blobMap() Map blob to memory region 
                    438:  * @srv = RPC Server instance
                    439:  * @blob = Map to this BLOB element
                    440:  * return: -1 error or 0 ok
                    441:  */
                    442: inline int rpc_srv_blobMap(rpc_srv_t * __restrict srv, rpc_blob_t * __restrict blob);
                    443: /*
                    444:  * rpc_srv_blobUnmap() Unmap blob memory region 
                    445:  * @blob = Mapped BLOB element
                    446:  * return: none
                    447:  */
                    448: inline void rpc_srv_blobUnmap(rpc_blob_t * __restrict blob);
                    449: /*
                    450:  * rpc_srv_blobFree() Free blob from disk & memory
                    451:  * @srv = RPC Server instance
                    452:  * @blob = Mapped BLOB element
                    453:  * return: -1 error or 0 ok
                    454:  */
                    455: inline int rpc_srv_blobFree(rpc_srv_t * __restrict srv, rpc_blob_t * __restrict blob);
                    456: 
1.1.1.1.2.9  misho     457: /*
1.1.1.1.2.10  misho     458:  * rpc_srv_registerBLOB() Register new BLOB to server
                    459:  * @srv = RPC Server instance
                    460:  * @len = BLOB length
1.1.1.1.2.16  misho     461:  * return: NULL error or new registered BLOB
1.1.1.1.2.10  misho     462:  */
                    463: rpc_blob_t *rpc_srv_registerBLOB(rpc_srv_t * __restrict srv, size_t len);
                    464: /*
                    465:  * rpc_srv_unregisterBLOB() Unregister BLOB from server
                    466:  * @srv = RPC Server instance
                    467:  * @var = BLOB Variable for unregister
                    468:  * return: -1 error, 0 not found call, 1 unregister ok
                    469:  */
                    470: int rpc_srv_unregisterBLOB(rpc_srv_t * __restrict srv, uint32_t var);
1.1.1.1.2.21! misho     471: /*
        !           472:  * rpc_srv_getBLOB() Get registered BLOB 
        !           473:  * @srv = RPC Server instance
        !           474:  * @var = hash for variable
        !           475:  * return: NULL not found, !=NULL return blob var
        !           476:  */
        !           477: inline rpc_blob_t *rpc_srv_getBLOB(rpc_srv_t * __restrict srv, uint32_t var);
1.1.1.1.2.10  misho     478: 
                    479: /*
1.1.1.1.2.9  misho     480:  * rpc_srv_sendBLOB() Send mapped BLOB to client
                    481:  * @cli = Client instance
                    482:  * @blob = Mapped BLOB element
                    483:  * return: -1 error, 0 ok
                    484:  */
                    485: int rpc_srv_sendBLOB(rpc_cli_t * __restrict cli, rpc_blob_t * __restrict blob);
                    486: /*
                    487:  * rpc_srv_recvBLOB() Receive BLOB from client
                    488:  * @cli = Client instance
1.1.1.1.2.10  misho     489:  * @blob = Mapped BLOB element
                    490:  * return: -1 error, 0 ok, >0 unreceived data from client, may be error?
1.1.1.1.2.9  misho     491:  */
1.1.1.1.2.10  misho     492: int rpc_srv_recvBLOB(rpc_cli_t * __restrict cli, rpc_blob_t * __restrict blob);
1.1.1.1.2.9  misho     493: 
1.1.1.1.2.13  misho     494: /*
                    495:  * rpc_cli_sendBLOB() Send BLOB to server
                    496:  * @cli = Client instance
                    497:  * @var = BLOB variable
                    498:  * @data = BLOB data
1.1.1.1.2.14  misho     499:  * return: -1 error, 0 ok, 1 remote error
1.1.1.1.2.13  misho     500:  */
                    501: int rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, rpc_val_t * __restrict var, void * __restrict data);
                    502: /*
                    503:  * rpc_cli_recvBLOB() Receive BLOB from server
                    504:  * @cli = Client instance
                    505:  * @var = BLOB variable
                    506:  * @data = BLOB data, must be free after use!
1.1.1.1.2.17  misho     507:  * return: -1 error, 0 ok, 1 remote error
1.1.1.1.2.13  misho     508:  */
                    509: int rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, rpc_val_t * __restrict var, void ** data);
1.1.1.1.2.20  misho     510: /*
                    511:  * rpc_cli_delBLOB() Delete BLOB from server
                    512:  * @cli = Client instance
                    513:  * @var = BLOB variable
                    514:  * return: -1 error, 0 ok, 1 remote error
                    515:  */
                    516: int rpc_cli_delBLOB(rpc_cli_t * __restrict cli, rpc_val_t * __restrict var);
                    517: /*
                    518:  * rpc_cli_getBLOB() Receive BLOB from server and Delete after that.
                    519:  * @cli = Client instance
                    520:  * @var = BLOB variable
                    521:  * @data = BLOB data, must be free after use!
                    522:  * return: -1 error, 0 ok, >0 remote error
                    523:  */
                    524: inline int rpc_cli_getBLOB(rpc_cli_t * __restrict cli, rpc_val_t * __restrict var, void ** data);
                    525: 
1.1.1.1.2.13  misho     526: 
1.1.1.1.2.7  misho     527: 
1.1       misho     528: /* RPC Client side functions */
                    529: 
                    530: /*
                    531:  * rpc_cli_openClient() Connect to RPC Server
                    532:  * @ProgID = ProgramID for RPC session request
                    533:  * @ProcID = ProcessID for RPC session request
                    534:  * @family = Family socket type, AF_INET or AF_INET6
                    535:  * @csHost = Host name or IP address for bind server
                    536:  * @Port = Port for bind server, if Port == 0 default port is selected
                    537:  * return: NULL == error or !=NULL connection to RPC server established
                    538:  */
                    539: rpc_cli_t *rpc_cli_openClient(u_int ProgID, u_int ProcID, u_short family, 
                    540:                const char *csHost, u_short Port);
                    541: /*
                    542:  * rpc_cli_closeClient() Close connection to RPC server and free resources
                    543:  * @cli = RPC Client session
                    544:  * return: none
                    545:  */
                    546: void rpc_cli_closeClient(rpc_cli_t * __restrict cli);
                    547: /*
                    548:  * rpc_cli_execCall() Execute RPC call
                    549:  * @cli = RPC Client session
                    550:  * @csModule = Module name, if NULL self binary
                    551:  * @csFunc = Function name for execute
                    552:  * @in_argc = IN count of arguments
                    553:  * @in_vals = IN RPC call array of rpc values
                    554:  * @out_argc = OUT returned count of arguments
                    555:  * @out_vals = OUT returned array of rpc values, must be free after use (see rpc_cli_freeVals())
                    556:  * return: -1 error or != -1 ok result
                    557:  */
                    558: int rpc_cli_execCall(rpc_cli_t *cli, const char *csModule, const char *csFunc, int in_argc, 
                    559:                rpc_val_t * __restrict in_vals, int *out_argc, rpc_val_t ** __restrict out_vals);
                    560: /*
                    561:  * rpc_cli_freeVals() Free rpc_val_t array returned from RPC call
                    562:  * @args = Number of arguments in array
                    563:  * @vals = Value elements
                    564:  * return: none
                    565:  */
                    566: inline void rpc_cli_freeVals(int args, rpc_val_t *vals);
                    567: 
                    568: 
1.1.1.1.2.14  misho     569: /*
                    570:  * rpc_cli_openBLOBClient() Connect to BLOB Server
                    571:  * @rpccli = RPC Client session
                    572:  * @Port = Port for bind server, if Port == 0 default port is selected
                    573:  * return: NULL == error or !=NULL connection to BLOB server established
                    574:  */
                    575: rpc_cli_t *rpc_cli_openBLOBClient(rpc_cli_t * __restrict rpccli, u_short Port);
                    576: /*
                    577:  * rpc_cli_closeBLOBClient() Close connection to BLOB server and free resources
                    578:  * @cli = BLOB Client session
                    579:  * return: none
                    580:  */
                    581: void rpc_cli_closeBLOBClient(rpc_cli_t * __restrict cli);
                    582: 
                    583: 
1.1       misho     584: #endif

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