LCOV - code coverage report
Current view: top level - examples/lowlevel - rpc_srvr.cxx (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 27 0
Test Date: 2025-11-11 10:26:08 Functions: 0.0 % 3 0

            Line data    Source code
       1              : /********************************************************************\
       2              : 
       3              :   Name:         rpc_srvr.c
       4              :   Created by:   Stefan Ritt
       5              : 
       6              :   Contents:     A simple RPC server program. Implements a function
       7              :                 rpc_test, which simply doubles some parameters.
       8              :                 This function can be calles remotely by rpc_clnt.
       9              : 
      10              : 
      11              :   $Id$
      12              : 
      13              : \********************************************************************/
      14              : 
      15              : #include "midas.h"
      16              : #include <stdio.h>
      17              : 
      18              : #define RPC_MYTEST RPC_MIN_ID
      19              : 
      20              : RPC_LIST rpc_list[] = {
      21              : 
      22              :    {RPC_MYTEST, "rpc_mytest",
      23              :     {{TID_UINT8, RPC_IN}
      24              :      ,
      25              :      {TID_UINT16, RPC_IN}
      26              :      ,
      27              :      {TID_INT32, RPC_IN}
      28              :      ,
      29              :      {TID_FLOAT, RPC_IN}
      30              :      ,
      31              :      {TID_DOUBLE, RPC_IN}
      32              :      ,
      33              :      {TID_UINT8, RPC_OUT}
      34              :      ,
      35              :      {TID_UINT16, RPC_OUT}
      36              :      ,
      37              :      {TID_UINT32, RPC_OUT}
      38              :      ,
      39              :      {TID_FLOAT, RPC_OUT}
      40              :      ,
      41              :      {TID_DOUBLE, RPC_OUT}
      42              :      ,
      43              :      {0}
      44              :      }
      45              :     }
      46              :    ,
      47              : 
      48              :    {0}
      49              : 
      50              : };
      51              : 
      52              : /*------------------------------------------------------------------*/
      53              : 
      54              : /* just a small test routine which doubles numbers */
      55            0 : INT rpc_mytest(BYTE b, WORD w, INT i, float f, double d,
      56              :                BYTE * b1, WORD * w1, INT * i1, float *f1, double *d1)
      57              : {
      58            0 :    *b1 = b * 2;
      59            0 :    *w1 = w * 2;
      60            0 :    *i1 = i * 2;
      61            0 :    *f1 = f * 2;
      62            0 :    *d1 = d * 2;
      63              : 
      64            0 :    return 1;
      65              : }
      66              : 
      67              : /* this dispatchers forwards RPC calls to the destination functions */
      68            0 : INT rpc_dispatch(INT index, void *prpc_param[])
      69              : {
      70            0 :    INT status = 1;
      71              : 
      72            0 :    switch (index) {
      73            0 :    case RPC_MYTEST:
      74            0 :       status = rpc_mytest(CBYTE(0), CWORD(1), CINT(2), CFLOAT(3), CDOUBLE(4),
      75            0 :                           CPBYTE(5), CPWORD(6), CPINT(7), CPFLOAT(8), CPDOUBLE(9));
      76            0 :       break;
      77              : 
      78            0 :    default:
      79            0 :       cm_msg(MERROR, "rpc_dispatch", "received unrecognized command");
      80              :    }
      81              : 
      82            0 :    return status;
      83              : }
      84              : 
      85              : /*------------------------------------------------------------------*/
      86              : 
      87            0 : int main()
      88              : {
      89              :    INT status;
      90              : 
      91              :    /* register RPC server under port 1750 */
      92            0 :    status = rpc_register_server(1750, NULL, NULL);
      93            0 :    if (status != RPC_SUCCESS) {
      94            0 :       printf("Cannot start server");
      95            0 :       return 0;
      96              :    }
      97              : 
      98              :    /* Register function list. Calls get forwarded to rpc_dispatch */
      99            0 :    rpc_register_functions(rpc_list, rpc_dispatch);
     100              : 
     101              :    /* Print debugging messages */
     102            0 :    rpc_set_debug((void (*)(const char *)) puts, 0);
     103              : 
     104              :    /* Server loop */
     105            0 :    while (cm_yield(1000) != RPC_SHUTDOWN);
     106              : 
     107              :    /* Shutdown server */
     108            0 :    rpc_server_shutdown();
     109              : 
     110            0 :    return 1;
     111              : }
        

Generated by: LCOV version 2.0-1