PageRenderTime 46ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/src/google/protobuf-c/protobuf-c-rpc.h

http://protobuf-c.googlecode.com/
C Header | 137 lines | 81 code | 23 blank | 33 comment | 0 complexity | 01931042b80383896d91189548450971 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. #ifndef __PROTOBUF_C_RPC_H_
  2. #define __PROTOBUF_C_RPC_H_
  3. /* Protocol is:
  4. * client issues request with header:
  5. * method_index 32-bit little-endian
  6. * message_length 32-bit little-endian
  7. * request_id 32-bit any-endian
  8. * server responds with header:
  9. * status_code 32-bit little-endian
  10. * method_index 32-bit little-endian
  11. * message_length 32-bit little-endian
  12. * request_id 32-bit any-endian
  13. */
  14. #include "protobuf-c-dispatch.h"
  15. typedef enum
  16. {
  17. PROTOBUF_C_RPC_ADDRESS_LOCAL, /* unix-domain socket */
  18. PROTOBUF_C_RPC_ADDRESS_TCP /* host/port tcp socket */
  19. } ProtobufC_RPC_AddressType;
  20. typedef enum
  21. {
  22. PROTOBUF_C_ERROR_CODE_HOST_NOT_FOUND,
  23. PROTOBUF_C_ERROR_CODE_CONNECTION_REFUSED,
  24. PROTOBUF_C_ERROR_CODE_CLIENT_TERMINATED,
  25. PROTOBUF_C_ERROR_CODE_BAD_REQUEST,
  26. PROTOBUF_C_ERROR_CODE_PROXY_PROBLEM
  27. } ProtobufC_RPC_Error_Code;
  28. typedef enum
  29. {
  30. PROTOBUF_C_STATUS_CODE_SUCCESS,
  31. PROTOBUF_C_STATUS_CODE_SERVICE_FAILED,
  32. PROTOBUF_C_STATUS_CODE_TOO_MANY_PENDING
  33. } ProtobufC_RPC_Status_Code;
  34. typedef void (*ProtobufC_RPC_Error_Func) (ProtobufC_RPC_Error_Code code,
  35. const char *message,
  36. void *error_func_data);
  37. /* --- Client API --- */
  38. typedef struct _ProtobufC_RPC_Client ProtobufC_RPC_Client;
  39. /* The return value (the service) may be cast to ProtobufC_RPC_Client* */
  40. ProtobufCService *protobuf_c_rpc_client_new (ProtobufC_RPC_AddressType type,
  41. const char *name,
  42. const ProtobufCServiceDescriptor *descriptor,
  43. ProtobufCDispatch *dispatch /* or NULL */
  44. );
  45. /* forcing the client to connect */
  46. typedef enum
  47. {
  48. PROTOBUF_C_RPC_CLIENT_CONNECT_SUCCESS,/* also returned if already connected */
  49. PROTOBUF_C_RPC_CLIENT_CONNECT_ERROR_NAME_LOOKUP,
  50. PROTOBUF_C_RPC_CLIENT_CONNECT_ERROR_CONNECT
  51. } ProtobufC_RPC_Client_ConnectStatus;
  52. ProtobufC_RPC_Client_ConnectStatus
  53. protobuf_c_rpc_client_connect (ProtobufC_RPC_Client *client);
  54. /* --- configuring the client */
  55. /* Pluginable async dns hooks */
  56. /* TODO: use adns library or port evdns? ugh */
  57. typedef void (*ProtobufC_NameLookup_Found) (const uint8_t *address,
  58. void *callback_data);
  59. typedef void (*ProtobufC_NameLookup_Failed)(const char *error_message,
  60. void *callback_data);
  61. typedef void (*ProtobufC_NameLookup_Func) (ProtobufCDispatch *dispatch,
  62. const char *name,
  63. ProtobufC_NameLookup_Found found_func,
  64. ProtobufC_NameLookup_Failed failed_func,
  65. void *callback_data);
  66. void protobuf_c_rpc_client_set_name_resolver (ProtobufC_RPC_Client *client,
  67. ProtobufC_NameLookup_Func resolver);
  68. /* Error handling */
  69. void protobuf_c_rpc_client_set_error_handler (ProtobufC_RPC_Client *client,
  70. ProtobufC_RPC_Error_Func func,
  71. void *error_func_data);
  72. /* Configuring the autoreconnect behavior.
  73. If the client is disconnected, all pending requests get an error.
  74. If autoreconnect is set, and it is by default, try connecting again
  75. after a certain amount of time has elapsed. */
  76. void protobuf_c_rpc_client_disable_autoreconnect (ProtobufC_RPC_Client *client);
  77. void protobuf_c_rpc_client_set_autoreconnect_period (ProtobufC_RPC_Client *client,
  78. unsigned millis);
  79. /* checking the state of the client */
  80. protobuf_c_boolean protobuf_c_rpc_client_is_connected (ProtobufC_RPC_Client *client);
  81. /* NOTE: we don't actually start connecting til the main-loop runs,
  82. so you may configure the client immediately after creation */
  83. /* --- Server API --- */
  84. typedef struct _ProtobufC_RPC_Server ProtobufC_RPC_Server;
  85. ProtobufC_RPC_Server *
  86. protobuf_c_rpc_server_new (ProtobufC_RPC_AddressType type,
  87. const char *name,
  88. ProtobufCService *service,
  89. ProtobufCDispatch *dispatch /* or NULL */
  90. );
  91. ProtobufCService *
  92. protobuf_c_rpc_server_destroy (ProtobufC_RPC_Server *server,
  93. protobuf_c_boolean free_underlying_service);
  94. /* NOTE: these do not have guaranteed semantics if called after there are actually
  95. clients connected to the server!
  96. NOTE 2: The purist in me has left the default of no-autotimeout.
  97. The pragmatist in me knows thats going to be a pain for someone.
  98. Please set autotimeout, and if you really don't want it, disable it explicitly,
  99. because i might just go and make it the default! */
  100. void protobuf_c_rpc_server_disable_autotimeout(ProtobufC_RPC_Server *server);
  101. void protobuf_c_rpc_server_set_autotimeout (ProtobufC_RPC_Server *server,
  102. unsigned timeout_millis);
  103. typedef protobuf_c_boolean
  104. (*ProtobufC_RPC_IsRpcThreadFunc) (ProtobufC_RPC_Server *server,
  105. ProtobufCDispatch *dispatch,
  106. void *is_rpc_data);
  107. void protobuf_c_rpc_server_configure_threading (ProtobufC_RPC_Server *server,
  108. ProtobufC_RPC_IsRpcThreadFunc func,
  109. void *is_rpc_data);
  110. /* Error handling */
  111. void protobuf_c_rpc_server_set_error_handler (ProtobufC_RPC_Server *server,
  112. ProtobufC_RPC_Error_Func func,
  113. void *error_func_data);
  114. #endif