Commit 13a6f6f8 authored by lahiker42's avatar lahiker42

working toward an rpc implementation


git-svn-id: https://protobuf-c.googlecode.com/svn/trunk@111 00440858-1255-0410-a3e6-75ea37f81c3a
parent fa977b21
This diff is collapsed.
typedef enum
{
PROTOBUF_C_EVENT_READABLE = (1<<0),
PROTOBUF_C_EVENT_WRITABLE = (1<<1)
} ProtobufC_Events;
/* Create or destroy a Dispatch */
ProtobufC_Dispatch *protobuf_c_dispatch_new (ProtobufCAllocator *allocator);
void protobuf_c_dispatch_free(ProtobufC_Dispatch *dispatch);
ProtobufCAllocator *protobuf_c_dispatch_peek_allocator (ProtobufC_Dispatch *);
typedef void (*ProtobufC_DispatchCallback) (int fd,
unsigned events,
void *callback_data);
/* Registering file-descriptors to watch. */
void protobuf_c_dispatch_watch_fd (ProtobufC_Dispatch *dispatch,
int fd,
unsigned events,
ProtobufC_DispatchCallback callback,
void *callback_data);
void protobuf_c_dispatch_close_fd (ProtobufC_Dispatch *dispatch,
int fd);
void protobuf_c_dispatch_fd_closed(ProtobufC_Dispatch *dispatch,
int fd);
/* --- API for use in standalone application --- */
/* Where you are happy just to run poll(2). */
/* protobuf_c_dispatch_run()
* Run one main-loop iteration, using poll(2) (or some system-level event system);
* 'timeout' is in milliseconds, -1 for no timeout.
*/
void protobuf_c_dispatch_run (ProtobufC_Dispatch *dispatch,
int timeout);
/* --- API for those who want to embed a dispatch into their own main-loop --- */
void protobuf_c_dispatch_dispatch (ProtobufC_Dispatch *dispatch,
size_t n_notifies,
ProtobufC_FDNotify *notifies);
void protobuf_c_dispatch_clear_changes (ProtobufC_Dispatch *);
#ifdef WIN32
typedef SOCKET ProtobufC_FD;
#else
typedef int ProtobufC_FD;
#endif
typedef struct {
ProtobufC_FD fd;
ProtobufC_Events events;
} ProtobufC_FDNotify;
struct _ProtobufC_Dispatch
{
/* changes to the events you are interested in. */
size_t n_changes;
ProtobufC_FDNotify *changes;
/* the complete set of events you are interested in. */
size_t n_notifies_desired;
ProtobufC_FDNotify *notifies_desired;
/* private data follows */
};
#include "protobuf-c-data-buffer.h"
typedef struct _ProtobufC_RPC_Client ProtobufC_RPC_Client;
typedef enum
{
PROTOBUF_C_CLIENT_STATE_NAME_LOOKUP,
PROTOBUF_C_CLIENT_STATE_CONNECTING,
PROTOBUF_C_CLIENT_STATE_CONNECTED,
PROTOBUF_C_CLIENT_STATE_FAILED_WAITING
} ProtobufC_ClientState;
struct _ProtobufC_RPC_Client
{
ProtobufCService base_service;
ProtobufCDataBuffer incoming;
ProtobufCDataBuffer outgoing;
ProtobufCAllocator *allocator;
ProtobufCDispatch *dispatch;
ProtobufC_RPC_AddressType address_type;
char *name;
ProtobufC_ClientState client_state;
ProtobufC_FD fd;
};
ProtobufCService *
protobuf_c_rpc_client_new (ProtobufC_RPC_Options *options,
const ProtobufCServiceDescriptor *descriptor)
{
ProtobufCAllocator *allocator = options->allocator;
ProtobufCDispatch *dispatch = options->dispatch ? options->dispatch : protobuf_c_dispatch_default ();
ProtobufC
...
}
-
void protobuf_c_rpc_server_new (ProtobufC_RPC_Options *options,
ProtobufCService *service);
unsigned port,
const ProtobufCServiceDescriptor *descriptor,
ProtobufCAllocator *allocator,
ProtobufCDispatch *dispatch);
ProtobufCService *protobuf_c_rpc_client_new_local(const char *socket_name,
const ProtobufCServiceDescriptor *descripto,
ProtobufCAllocator *allocator,
ProtobufCDispatch *dispatch);
void protobuf_c_rpc_server_new_tcp (ProtobufCService *service,
unsigned port,
ProtobufCAllocator *allocator,
ProtobufCDispatch *dispatch);
void protobuf_c_rpc_server_new_local(ProtobufCService *service,
const char *socket_nam,
ProtobufCAllocator *allocator,
ProtobufCDispatch *dispatch);
---
#ifndef __PROTOBUF_C_RPC_H_
#define __PROTOBUF_C_RPC_H_
/* Protocol is:
* client issues request with header:
* service_index
* request_id
* message_length
* server responds with header:
* service_index
* request_id
* message_length
*/
typedef struct _ProtobufC_Dispatch ProtobufC_Dispatch;
typedef enum
{
PROTOBUF_C_RPC_ADDRESS_LOCAL, /* unix-domain socket */
PROTOBUF_C_RPC_ADDRESS_TCP /* host/port tcp socket */
} ProtobufC_RPC_AddressType;
typedef void (*ProtobufC_RPC_Error_Func) (ProtobufC_RPC_Error_Code code,
const char *message,
void *error_func_data);
/* --- Client API --- */
/* The return value (the service) may be cast to ProtobufC_RPC_Client* */
ProtobufCService *protobuf_c_rpc_client_new (ProtobufC_RPC_AddressType type,
const char *name,
const ProtobufCServiceDescriptor *descriptor,
ProtobufC_Dispatch *dispatch);
/* --- configuring the client */
typedef struct _ProtobufC_RPC_Client ProtobufC_RPC_Client;
/* Pluginable async dns hooks */
/* TODO: use adns library or port evdns? ugh */
typedef void (*ProtobufC_NameLookup_Found) (const uint8_t *address,
void *callback_data);
typedef void (*ProtobufC_NameLookup_Failed)(const char *error_message,
void *callback_data);
typedef void (*ProtobufC_NameLookup_Func) (ProtobufCDispatch *dispatch,
ProtobufC_NameLookup_Found found_func,
ProtobufC_NameLookup_Failed failed_func,
gpointer callback_data);
void protobuf_c_rpc_client_set_name_resolver (ProtobufC_RPC_Client *client,
ProtobufC_NameLookup_Func resolver);
/* Error handling */
void protobuf_c_rpc_client_set_error_handler (ProtobufC_RPC_Client *client,
ProtobufC_RPC_Error_Func func,
void *error_func_data);
/* Configuring the autoretry behavior.
If the client is disconnected, all pending requests get an error.
If autoretry is set, and it is by default, try connecting again
after a certain amount of time has elapsed. */
void protobuf_c_rpc_client_disable_autoretry (ProtobufC_RPC_Client *client);
void protobuf_c_rpc_client_set_autoretry_period (ProtobufC_RPC_Client *client,
unsigned millis);
/* NOTE: we don't actually start connecting til the main-loop runs,
so you may configure the client immediately after creation */
/* --- Server API --- */
ProtobufC_RPC_Server *
protobuf_c_rpc_server_new (ProtobufC_RPC_AddressType type,
const char *name,
ProtobufCService *service,
ProtobufC_Dispatch *dispatch);
ProtobufCService *
protobuf_c_rpc_server_destroy (ProtobufC_RPC_Server *server,
protobuf_c_boolean free_underlying_service);
/* NOTE: these do not have guaranteed semantics if called after there are actually
clients connected to the server!
NOTE 2: The purist in me has left the default of no-autotimeout.
The pragmatist in me knows thats going to be a pain for someone.
Please set autotimeout, and if you really don't want it, disable it explicitly,
because i might just go and make it the default! */
void protobuf_c_rpc_server_disable_autotimeout(ProtobufC_RPC_Server *server);
void protobuf_c_rpc_server_set_autotimeout (ProtobufC_RPC_Server *server,
unsigned timeout_millis);
/* Error handling */
void protobuf_c_rpc_server_set_error_handler (ProtobufC_RPC_Server *server,
ProtobufC_RPC_Error_Func func,
void *error_func_data);
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment