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

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.22! misho       6: * $Id: aitrpc.h,v 1.1.1.1.2.21 2010/07/08 12:29:38 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.22! misho     156: #define RPC_CALLBACK_CHECK_INPUT(x)    do { \
        !           157:                                                if (!x) { \
        !           158:                                                        rpc_SetErr(22, "Error:: invalid callback parameters ...\n"); \
1.1       misho     159:                                                        return -1; \
                    160:                                                } \
1.1.1.1.2.1  misho     161:                                        } while (0)
1.1.1.1.2.22! misho     162: #define RPC_CALLBACK_CHK_ARGS(f, n)    do { \
        !           163:                                                RPC_CALLBACK_CHECK_INPUT(f); \
        !           164:                                                if (f && f->func_args != n) { \
        !           165:                                                        rpc_SetErr(22, "Error:: different number of arguments!\n"); \
1.1.1.1.2.1  misho     166:                                                        return -1; \
                    167:                                                } \
                    168:                                        } while (0)
1.1       misho     169: 
                    170: 
                    171: /* RPC session identification */
                    172: 
                    173: typedef struct {
                    174:        uint8_t         sess_version;
                    175:        uint32_t        sess_program;
                    176:        uint32_t        sess_process;
                    177: } __packed rpc_sess_t;
                    178: 
                    179: 
                    180: /* Server managment RPC functions ... */
                    181: 
                    182: // RPC function registration element!
                    183: typedef struct tagRPCFunc {
                    184:        uint16_t                func_tag;
                    185:        uint32_t                func_hash;
                    186:        int8_t                  func_file[MAXPATHLEN];
                    187:        int8_t                  func_name[UCHAR_MAX + 1];
                    188: 
                    189:        int8_t                  func_args;
                    190:        rpc_val_t               *func_vals;
                    191: 
1.1.1.1.2.11  misho     192:        void                    *func_parent;
1.1       misho     193:        struct tagRPCFunc       *func_next;
                    194: } rpc_func_t;
                    195: 
                    196: 
                    197: /* Network RPC packet - Client request */
                    198: 
                    199: struct tagRPCCall {
                    200:        rpc_sess_t      call_session;
                    201:        uint16_t        call_tag;
                    202:        uint32_t        call_hash;
                    203:        uint8_t         call_argc;
                    204: } __packed;
                    205: 
                    206: /* Network RPC packet - Server response */
                    207: 
                    208: struct tagRPCRet {
                    209:        rpc_sess_t      ret_session;
                    210:        uint16_t        ret_tag;
                    211:        uint32_t        ret_hash;
                    212:        int32_t         ret_retcode;
                    213:        int32_t         ret_errno;
                    214:        uint8_t         ret_argc;
                    215: } __packed;
                    216: 
1.1.1.1.2.6  misho     217: /* Network BLOB packet - Header */
                    218: 
                    219: struct tagBLOBHdr {
                    220:        rpc_sess_t      hdr_session;
                    221:        uint8_t         hdr_cmd;
                    222:        uint32_t        hdr_var;
                    223:        uint32_t        hdr_len;
1.1.1.1.2.19  misho     224:        uint32_t        hdr_ret;
1.1.1.1.2.6  misho     225: } __packed;
                    226: 
1.1       misho     227: /* Network RPC client & server elements */
                    228: 
                    229: typedef struct {
                    230:        struct sockaddr cli_sa;         // host info
                    231:        int             cli_sock;       // socket
                    232:        pthread_t       cli_tid;        // TID of thread
                    233: 
                    234:        void            *cli_parent;    // pointer to parent rpc_srv_t for server or to rpc_sess_t for client
                    235: } rpc_cli_t;
                    236: 
                    237: 
1.1.1.1.2.5  misho     238: // BLOB registration element!
                    239: typedef struct tagBLOB {
1.1.1.1.2.6  misho     240:        uint32_t        blob_var;
                    241: 
1.1.1.1.2.5  misho     242:        size_t          blob_len;       // size of allocated BLOB data
                    243:        void            *blob_data;     // BLOB data
                    244: 
                    245:        struct tagBLOB  *blob_next;
                    246: } rpc_blob_t;
                    247: 
                    248: typedef struct {
1.1       misho     249:        rpc_sess_t      srv_session;    // RPC session registration info
1.1.1.1.2.5  misho     250:        int             srv_numcli;     // maximum concurent client connections
1.1       misho     251: 
1.1.1.1.2.5  misho     252:        rpc_cli_t       srv_server;     // RPC server socket
                    253:        rpc_cli_t       *srv_clients;   // connected rpc client sockets
1.1       misho     254: 
                    255:        rpc_func_t      *srv_funcs;     // registered functions list
1.1.1.1.2.5  misho     256: 
                    257:        pthread_mutex_t srv_mtx;
                    258: 
                    259:        struct {
                    260:                int             state;          // BLOB server state: ==0 disable | !=0 enable
1.1.1.1.2.6  misho     261:                char            dir[UCHAR_MAX + 1];
1.1.1.1.2.5  misho     262: 
                    263:                rpc_cli_t       server;         // BLOB server socket
                    264:                rpc_cli_t       *clients;       // connected blob client sockets
                    265: 
                    266:                rpc_blob_t      *blobs;         // registered blob variables list
                    267: 
                    268:                pthread_mutex_t mtx;
                    269:        }               srv_blob;
1.1       misho     270: } rpc_srv_t;
                    271: 
                    272: 
1.1.1.1.2.11  misho     273: /* 
                    274:  * (*rpc_callback_t)() Callback type definition for RPC call in server process
                    275:  * @arg1 = current execution RPC call function
                    276:  * @arg2 = number of items in input array from call request
                    277:  * @arg3 = input array with values from RPC call execution request
                    278:  * return: -1 error or >-1 success execution
                    279:  */
                    280: typedef int (*rpc_callback_t)(rpc_func_t *, int, rpc_val_t *);
1.1       misho     281: 
                    282: 
                    283: // -----------------------------------------------------------------------
                    284: 
                    285: /* Error support functions */
                    286: 
                    287: // cli_GetErrno() Get error code of last operation
                    288: inline int cli_GetErrno();
                    289: // cli_GetError() Get error text of last operation
                    290: inline const char *cli_GetError();
                    291: 
                    292: 
                    293: /* RPC Server side functions */
                    294: 
                    295: /*
                    296:  * rpc_srv_initServer() Init & create RPC Server
                    297:  * @regProgID = ProgramID for authentication & recognition
                    298:  * @regProcID = ProcessID for authentication & recognition
                    299:  * @concurentClients = Concurent clients at same time to this server
                    300:  * @family = Family socket type, AF_INET or AF_INET6
                    301:  * @csHost = Host name or IP address for bind server, if NULL any address
                    302:  * @Port = Port for bind server, if Port == 0 default port is selected
                    303:  * return: NULL == error or !=NULL bind and created RPC server instance
                    304:  */
                    305: rpc_srv_t *rpc_srv_initServer(u_int regProgID, u_int regProcID, int concurentClients, 
                    306:                u_short family, const char *csHost, u_short Port);
                    307: /*
                    308:  * rpc_srv_endServer() Destroy RPC server, close all opened sockets and free resources
                    309:  * @srv = RPC Server instance
                    310:  * return: none
                    311:  */
                    312: void rpc_srv_endServer(rpc_srv_t * __restrict srv);
                    313: /*
                    314:  * rpc_srv_execServer() Execute Main server loop and wait for clients requests
                    315:  * @srv = RPC Server instance
                    316:  * return: -1 error or 0 ok, infinite loop ...
                    317:  */
                    318: int rpc_srv_execServer(rpc_srv_t * __restrict srv);
                    319: 
                    320: /*
1.1.1.1.2.5  misho     321:  * rpc_srv_initBLOBServer() Init & create BLOB Server
                    322:  * @Port = Port for bind server, if Port == 0 default port is selected
1.1.1.1.2.6  misho     323:  * @diskDir = Disk place for BLOB file objects
1.1.1.1.2.5  misho     324:  * return: -1 == error or 0 bind and created BLOB server instance
                    325:  */
1.1.1.1.2.6  misho     326: int rpc_srv_initBLOBServer(rpc_srv_t * __restrict srv, u_short Port, const char *diskDir);
1.1.1.1.2.5  misho     327: /*
                    328:  * rpc_srv_endBLOBServer() Destroy BLOB server, close all opened sockets and free resources
                    329:  * @srv = RPC Server instance
                    330:  * return: none
                    331:  */
                    332: void rpc_srv_endBLOBServer(rpc_srv_t * __restrict srv);
                    333: /*
                    334:  * rpc_srv_execBLOBServer() Execute Main BLOB server loop and wait for clients requests
                    335:  * @srv = RPC Server instance
                    336:  * return: -1 error or 0 ok, infinite loop ...
                    337:  */
                    338: int rpc_srv_execBLOBServer(rpc_srv_t * __restrict srv);
                    339: 
                    340: /*
1.1       misho     341:  * rpc_srv_registerCall() Register call to RPC server
                    342:  * @srv = RPC Server instance
                    343:  * @csModule = Module name, if NULL self binary
                    344:  * @csFunc = Function name
1.1.1.1.2.17  misho     345:  * @args = Number of return function arguments, use for restriction case!
1.1       misho     346:  * return: -1 error or 0 register ok
                    347:  */
                    348: int rpc_srv_registerCall(rpc_srv_t * __restrict srv, const char *csModule, const char *csFunc, 
                    349:                unsigned char args);
                    350: /*
                    351:  * rpc_srv_unregisterCall() Unregister call from RPC server
                    352:  * @srv = RPC Server instance
                    353:  * @csModule = Module name, if NULL self binary
                    354:  * @csFunc = Function name
                    355:  * return: -1 error, 0 not found call, 1 unregister ok
                    356:  */
                    357: int rpc_srv_unregisterCall(rpc_srv_t * __restrict srv, const char *csModule, const char *csFunc);
                    358: /*
                    359:  * rpc_srv_getFunc() Get registered call from RPC server by Name
                    360:  * @srv = RPC Server instance
                    361:  * @csModule = Module name, if NULL self binary
                    362:  * @csFunc = Function name
                    363:  * return: NULL not found call, !=NULL return call
                    364:  */
                    365: rpc_func_t *rpc_srv_getFunc(rpc_srv_t * __restrict srv, const char *csModule, const char *csFunc);
                    366: /*
                    367:  * rpc_srv_getCall() Get registered call from RPC server
                    368:  * @srv = RPC Server instance
                    369:  * @tag = tag for function
                    370:  * @hash = hash for function
                    371:  * return: NULL not found call, !=NULL return call
                    372:  */
                    373: inline rpc_func_t *rpc_srv_getCall(rpc_srv_t * __restrict srv, uint16_t tag, uint32_t hash);
                    374: /*
                    375:  * rpc_srv_execCall() Execute registered call from RPC server
                    376:  * @call = Register RPC call
                    377:  * @rpc = IN RPC call structure
                    378:  * @args = IN RPC call array of rpc values
                    379:  * return: -1 error, !=-1 ok
                    380:  */
1.1.1.1.2.11  misho     381: int rpc_srv_execCall(rpc_func_t * __restrict call, struct tagRPCCall * __restrict rpc, 
                    382:                rpc_val_t * __restrict args);
1.1       misho     383: 
                    384: 
                    385: /*
1.1.1.1.2.11  misho     386:  * rpc_srv_retValsCall() Declare return variables for RPC call and zeroed values
                    387:                                        (for safe handling return values, use this!)
                    388:  * @call = RPC function call
                    389:  * @return_vals = Number of return variables
                    390:  * return: NULL error, !=NULL array with return values for RPC call with return_vals items
                    391:  */
                    392: inline rpc_val_t *rpc_srv_retValsCall(rpc_func_t * __restrict call, int return_vals);
                    393: /*
                    394:  * rpc_srv_declValsCall() Declare return variables for RPC call, 
                    395:                                if already allocated memory for RPC call return values 
                    396:                                function reallocate used space with return_vals count elements
1.1       misho     397:  * @call = RPC function call
                    398:  * @return_vals = Number of return variables
                    399:  * return: -1 error, !=-1 ok
                    400:  */
                    401: inline int rpc_srv_declValsCall(rpc_func_t * __restrict call, int return_vals);
                    402: /*
                    403:  * rpc_srv_freeValsCall() Free return variables for RPC call
                    404:  * @call = RPC function call
                    405:  * return: none
                    406:  */
                    407: inline void rpc_srv_freeValsCall(rpc_func_t * __restrict call);
                    408: /*
                    409:  * rpc_srv_copyValsCall() Copy return variables for RPC call to new variable
                    410:  * @call = RPC function call
                    411:  * @newvals = New allocated variables array, must be free after use
                    412:  * return: -1 error, !=-1 Returned number of copied RPC variables
                    413:  */
                    414: inline int rpc_srv_copyValsCall(rpc_func_t * __restrict call, rpc_val_t ** __restrict newvals);
                    415: /*
1.1.1.1.2.11  misho     416:  * rpc_srv_zeroValsCall() Clean values from return variables of RPC call
1.1       misho     417:  * @call = RPC function call
                    418:  * return: -1 error, !=-1 Returned number of cleaned RPC variables
                    419:  */
1.1.1.1.2.11  misho     420: inline int rpc_srv_zeroValsCall(rpc_func_t * __restrict call);
1.1       misho     421: /*
                    422:  * rpc_srv_getValsCall() Get return variables for RPC call
                    423:  * @call = RPC function call
                    424:  * @vals = Returned variables, may be NULL
                    425:  * return: -1 error, !=-1 Number of returned variables
                    426:  */
                    427: inline int rpc_srv_getValsCall(rpc_func_t * __restrict call, rpc_val_t ** __restrict vals);
                    428: 
                    429: 
1.1.1.1.2.7  misho     430: /*
1.1.1.1.2.10  misho     431:  * rpc_srv_blobCreate() Create map blob to memory region and return object
                    432:  * @srv = RPC Server instance
                    433:  * @len = BLOB length object
                    434:  * return: NULL error or !=NULL allocated BLOB object
                    435:  */
                    436: inline rpc_blob_t *rpc_srv_blobCreate(rpc_srv_t * __restrict srv, int len);
                    437: /*
1.1.1.1.2.7  misho     438:  * rpc_srv_blobMap() Map blob to memory region 
                    439:  * @srv = RPC Server instance
                    440:  * @blob = Map to this BLOB element
                    441:  * return: -1 error or 0 ok
                    442:  */
                    443: inline int rpc_srv_blobMap(rpc_srv_t * __restrict srv, rpc_blob_t * __restrict blob);
                    444: /*
                    445:  * rpc_srv_blobUnmap() Unmap blob memory region 
                    446:  * @blob = Mapped BLOB element
                    447:  * return: none
                    448:  */
                    449: inline void rpc_srv_blobUnmap(rpc_blob_t * __restrict blob);
                    450: /*
                    451:  * rpc_srv_blobFree() Free blob from disk & memory
                    452:  * @srv = RPC Server instance
                    453:  * @blob = Mapped BLOB element
                    454:  * return: -1 error or 0 ok
                    455:  */
                    456: inline int rpc_srv_blobFree(rpc_srv_t * __restrict srv, rpc_blob_t * __restrict blob);
                    457: 
1.1.1.1.2.9  misho     458: /*
1.1.1.1.2.10  misho     459:  * rpc_srv_registerBLOB() Register new BLOB to server
                    460:  * @srv = RPC Server instance
                    461:  * @len = BLOB length
1.1.1.1.2.16  misho     462:  * return: NULL error or new registered BLOB
1.1.1.1.2.10  misho     463:  */
                    464: rpc_blob_t *rpc_srv_registerBLOB(rpc_srv_t * __restrict srv, size_t len);
                    465: /*
                    466:  * rpc_srv_unregisterBLOB() Unregister BLOB from server
                    467:  * @srv = RPC Server instance
                    468:  * @var = BLOB Variable for unregister
                    469:  * return: -1 error, 0 not found call, 1 unregister ok
                    470:  */
                    471: int rpc_srv_unregisterBLOB(rpc_srv_t * __restrict srv, uint32_t var);
1.1.1.1.2.21  misho     472: /*
                    473:  * rpc_srv_getBLOB() Get registered BLOB 
                    474:  * @srv = RPC Server instance
                    475:  * @var = hash for variable
                    476:  * return: NULL not found, !=NULL return blob var
                    477:  */
                    478: inline rpc_blob_t *rpc_srv_getBLOB(rpc_srv_t * __restrict srv, uint32_t var);
1.1.1.1.2.10  misho     479: 
                    480: /*
1.1.1.1.2.9  misho     481:  * rpc_srv_sendBLOB() Send mapped BLOB to client
                    482:  * @cli = Client instance
                    483:  * @blob = Mapped BLOB element
                    484:  * return: -1 error, 0 ok
                    485:  */
                    486: int rpc_srv_sendBLOB(rpc_cli_t * __restrict cli, rpc_blob_t * __restrict blob);
                    487: /*
                    488:  * rpc_srv_recvBLOB() Receive BLOB from client
                    489:  * @cli = Client instance
1.1.1.1.2.10  misho     490:  * @blob = Mapped BLOB element
                    491:  * return: -1 error, 0 ok, >0 unreceived data from client, may be error?
1.1.1.1.2.9  misho     492:  */
1.1.1.1.2.10  misho     493: int rpc_srv_recvBLOB(rpc_cli_t * __restrict cli, rpc_blob_t * __restrict blob);
1.1.1.1.2.9  misho     494: 
1.1.1.1.2.13  misho     495: /*
                    496:  * rpc_cli_sendBLOB() Send BLOB to server
                    497:  * @cli = Client instance
                    498:  * @var = BLOB variable
                    499:  * @data = BLOB data
1.1.1.1.2.14  misho     500:  * return: -1 error, 0 ok, 1 remote error
1.1.1.1.2.13  misho     501:  */
                    502: int rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, rpc_val_t * __restrict var, void * __restrict data);
                    503: /*
                    504:  * rpc_cli_recvBLOB() Receive BLOB from server
                    505:  * @cli = Client instance
                    506:  * @var = BLOB variable
                    507:  * @data = BLOB data, must be free after use!
1.1.1.1.2.17  misho     508:  * return: -1 error, 0 ok, 1 remote error
1.1.1.1.2.13  misho     509:  */
                    510: int rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, rpc_val_t * __restrict var, void ** data);
1.1.1.1.2.20  misho     511: /*
                    512:  * rpc_cli_delBLOB() Delete BLOB from server
                    513:  * @cli = Client instance
                    514:  * @var = BLOB variable
                    515:  * return: -1 error, 0 ok, 1 remote error
                    516:  */
                    517: int rpc_cli_delBLOB(rpc_cli_t * __restrict cli, rpc_val_t * __restrict var);
                    518: /*
                    519:  * rpc_cli_getBLOB() Receive BLOB from server and Delete after that.
                    520:  * @cli = Client instance
                    521:  * @var = BLOB variable
                    522:  * @data = BLOB data, must be free after use!
                    523:  * return: -1 error, 0 ok, >0 remote error
                    524:  */
                    525: inline int rpc_cli_getBLOB(rpc_cli_t * __restrict cli, rpc_val_t * __restrict var, void ** data);
                    526: 
1.1.1.1.2.13  misho     527: 
1.1.1.1.2.7  misho     528: 
1.1       misho     529: /* RPC Client side functions */
                    530: 
                    531: /*
                    532:  * rpc_cli_openClient() Connect to RPC Server
                    533:  * @ProgID = ProgramID for RPC session request
                    534:  * @ProcID = ProcessID for RPC session request
                    535:  * @family = Family socket type, AF_INET or AF_INET6
                    536:  * @csHost = Host name or IP address for bind server
                    537:  * @Port = Port for bind server, if Port == 0 default port is selected
                    538:  * return: NULL == error or !=NULL connection to RPC server established
                    539:  */
                    540: rpc_cli_t *rpc_cli_openClient(u_int ProgID, u_int ProcID, u_short family, 
                    541:                const char *csHost, u_short Port);
                    542: /*
                    543:  * rpc_cli_closeClient() Close connection to RPC server and free resources
                    544:  * @cli = RPC Client session
                    545:  * return: none
                    546:  */
                    547: void rpc_cli_closeClient(rpc_cli_t * __restrict cli);
                    548: /*
                    549:  * rpc_cli_execCall() Execute RPC call
                    550:  * @cli = RPC Client session
                    551:  * @csModule = Module name, if NULL self binary
                    552:  * @csFunc = Function name for execute
                    553:  * @in_argc = IN count of arguments
                    554:  * @in_vals = IN RPC call array of rpc values
                    555:  * @out_argc = OUT returned count of arguments
                    556:  * @out_vals = OUT returned array of rpc values, must be free after use (see rpc_cli_freeVals())
                    557:  * return: -1 error or != -1 ok result
                    558:  */
                    559: int rpc_cli_execCall(rpc_cli_t *cli, const char *csModule, const char *csFunc, int in_argc, 
                    560:                rpc_val_t * __restrict in_vals, int *out_argc, rpc_val_t ** __restrict out_vals);
                    561: /*
                    562:  * rpc_cli_freeVals() Free rpc_val_t array returned from RPC call
                    563:  * @args = Number of arguments in array
                    564:  * @vals = Value elements
                    565:  * return: none
                    566:  */
                    567: inline void rpc_cli_freeVals(int args, rpc_val_t *vals);
                    568: 
                    569: 
1.1.1.1.2.14  misho     570: /*
                    571:  * rpc_cli_openBLOBClient() Connect to BLOB Server
                    572:  * @rpccli = RPC Client session
                    573:  * @Port = Port for bind server, if Port == 0 default port is selected
                    574:  * return: NULL == error or !=NULL connection to BLOB server established
                    575:  */
                    576: rpc_cli_t *rpc_cli_openBLOBClient(rpc_cli_t * __restrict rpccli, u_short Port);
                    577: /*
                    578:  * rpc_cli_closeBLOBClient() Close connection to BLOB server and free resources
                    579:  * @cli = BLOB Client session
                    580:  * return: none
                    581:  */
                    582: void rpc_cli_closeBLOBClient(rpc_cli_t * __restrict cli);
                    583: 
                    584: 
1.1       misho     585: #endif

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