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

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

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