rpc.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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_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, ...); /* Create a new structure */
  48. typedef int (*rpc_struct_scan_f)(void* ctx, char* fmt, ...); /* Scan attributes of a structure */
  49. typedef int (*rpc_struct_printf_f)(void* ctx, char* name, char* fmt, ...); /* Struct version of rpc_printf */
  50. /* returns the supported capabilities */
  51. typedef rpc_capabilities_t (*rpc_capabilities_f)(void* ctx);
  52. /* create a special "context" for delayed replies */
  53. typedef struct rpc_delayed_ctx* (*rpc_delayed_ctx_new_f)(void* ctx);
  54. /* close the special "context" for delayed replies */
  55. typedef void (*rpc_delayed_ctx_close_f)(struct rpc_delayed_ctx* dctx);
  56. /*
  57. * RPC context, this is what RPC functions get as a parameter and use
  58. * it to obtain the value of the parameters of the call and reference
  59. * to the result structure that will be returned to the caller
  60. */
  61. typedef struct rpc {
  62. rpc_fault_f fault;
  63. rpc_send_f send;
  64. rpc_add_f add;
  65. rpc_scan_f scan;
  66. rpc_printf_f printf;
  67. rpc_struct_add_f struct_add;
  68. rpc_struct_scan_f struct_scan;
  69. rpc_struct_printf_f struct_printf;
  70. rpc_capabilities_f capabilities;
  71. rpc_delayed_ctx_new_f delayed_ctx_new;
  72. rpc_delayed_ctx_close_f delayed_ctx_close;
  73. } rpc_t;
  74. typedef struct rpc_delayed_ctx{
  75. rpc_t rpc;
  76. void* reply_ctx;
  77. /* more private data might follow */
  78. } rpc_delayed_ctx_t;
  79. /*
  80. * RPC Function Prototype
  81. */
  82. typedef void (*rpc_function_t)(rpc_t* rpc, void* ctx);
  83. /*
  84. * RPC callback context.
  85. *
  86. * Defines a convenient way of packing an rpc callback
  87. * (rpc_function_t) parameters and it's not used/needed
  88. * by the rpc api/interface.
  89. */
  90. typedef struct rpc_cb_ctx {
  91. rpc_t *rpc;
  92. void *c;
  93. } rpc_cb_ctx_t;
  94. /*
  95. * Remote Procedure Call Export
  96. */
  97. typedef struct rpc_export {
  98. const char* name; /* Name of the RPC function (null terminated) */
  99. rpc_function_t function; /* Pointer to the function */
  100. const char** doc_str; /* Documentation strings, method signature and description */
  101. unsigned int flags; /* Various flags, reserved for future use */
  102. } rpc_export_t;
  103. #endif /* _RPC_H */