rpc.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* $Id$
  2. *
  3. * SER Remote Procedure Call Interface
  4. *
  5. * Copyright (C) 2005 iptelorg GmbH
  6. *
  7. * This file is part of ser, a free SIP server.
  8. *
  9. * ser is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version
  13. *
  14. * For a license to use the ser software under conditions
  15. * other than those described here, or to purchase support for this
  16. * software, please contact iptel.org by e-mail at the following addresses:
  17. * [email protected]
  18. *
  19. * ser is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  27. */
  28. #ifndef _RPC_H
  29. #define _RPC_H
  30. /*
  31. * TODO: Add the possibility to add printf-like formatted string to fault
  32. */
  33. enum rpc_flags {
  34. RET_ARRAY = (1 << 0),
  35. RET_VALUE = (1 << 1)
  36. };
  37. typedef enum rpc_capabilities {
  38. RPC_DELAYED_REPLY = (1 <<0) /* delayed reply support */
  39. } rpc_capabilities_t;
  40. struct rpc_delayed_ctx;
  41. /* Send the result to the caller */
  42. typedef int (*rpc_send_f)(void* ctx); /* Send the reply to the client */
  43. typedef void (*rpc_fault_f)(void* ctx, int code, char* fmt, ...); /* Signal a failure to the client */
  44. typedef int (*rpc_add_f)(void* ctx, char* fmt, ...); /* Add a new piece of data to the result */
  45. typedef int (*rpc_scan_f)(void* ctx, char* fmt, ...); /* Retrieve request parameters */
  46. typedef int (*rpc_rpl_printf_f)(void* ctx, char* fmt, ...); /* Add printf-like formated data to the result set */
  47. typedef int (*rpc_struct_add_f)(void* ctx, char* fmt, ...); /* Add fields in a structure */
  48. typedef int (*rpc_array_add_f)(void* ctx, char* fmt, ...); /* Add values in an array */
  49. typedef int (*rpc_struct_scan_f)(void* ctx, char* fmt, ...); /* Scan attributes of a structure */
  50. typedef int (*rpc_struct_printf_f)(void* ctx, char* name, char* fmt, ...); /* Struct version of rpc_printf */
  51. /* returns the supported capabilities */
  52. typedef rpc_capabilities_t (*rpc_capabilities_f)(void* ctx);
  53. /* create a special "context" for delayed replies */
  54. typedef struct rpc_delayed_ctx* (*rpc_delayed_ctx_new_f)(void* ctx);
  55. /* close the special "context" for delayed replies */
  56. typedef void (*rpc_delayed_ctx_close_f)(struct rpc_delayed_ctx* dctx);
  57. /*
  58. * RPC context, this is what RPC functions get as a parameter and use
  59. * it to obtain the value of the parameters of the call and reference
  60. * to the result structure that will be returned to the caller
  61. */
  62. typedef struct rpc {
  63. rpc_fault_f fault;
  64. rpc_send_f send;
  65. rpc_add_f add;
  66. rpc_scan_f scan;
  67. rpc_rpl_printf_f rpl_printf;
  68. rpc_struct_add_f struct_add;
  69. rpc_array_add_f array_add;
  70. rpc_struct_scan_f struct_scan;
  71. rpc_struct_printf_f struct_printf;
  72. rpc_capabilities_f capabilities;
  73. rpc_delayed_ctx_new_f delayed_ctx_new;
  74. rpc_delayed_ctx_close_f delayed_ctx_close;
  75. } rpc_t;
  76. typedef struct rpc_delayed_ctx{
  77. rpc_t rpc;
  78. void* reply_ctx;
  79. /* more private data might follow */
  80. } rpc_delayed_ctx_t;
  81. /*
  82. * RPC Function Prototype
  83. */
  84. typedef void (*rpc_function_t)(rpc_t* rpc, void* ctx);
  85. /*
  86. * RPC callback context.
  87. *
  88. * Defines a convenient way of packing an rpc callback
  89. * (rpc_function_t) parameters and it's not used/needed
  90. * by the rpc api/interface.
  91. */
  92. typedef struct rpc_cb_ctx {
  93. rpc_t *rpc;
  94. void *c;
  95. } rpc_cb_ctx_t;
  96. /*
  97. * Remote Procedure Call Export
  98. */
  99. typedef struct rpc_export {
  100. const char* name; /* Name of the RPC function (null terminated) */
  101. rpc_function_t function; /* Pointer to the function */
  102. const char** doc_str; /* Documentation strings, method signature and description */
  103. unsigned int flags; /* Various flags, reserved for future use */
  104. } rpc_export_t;
  105. #endif /* _RPC_H */