1
0
mirror of https://github.com/haiwen/libsearpc.git synced 2025-09-01 21:07:24 +00:00
Files
libsearpc/lib/searpc-server.h

142 lines
3.5 KiB
C
Raw Normal View History

2011-04-08 20:58:15 +08:00
#ifndef SEARPC_SERVER_H
#define SEARPC_SERVER_H
2019-11-01 15:52:36 +08:00
#ifdef LIBSEARPC_EXPORTS
#define LIBSEARPC_API __declspec(dllexport)
#else
#define LIBSEARPC_API
#endif
2011-04-08 20:58:15 +08:00
#include <glib.h>
2013-08-08 16:24:20 +08:00
#include <glib-object.h>
#include <jansson.h>
2011-04-08 20:58:15 +08:00
#ifndef DFT_DOMAIN
#define DFT_DOMAIN g_quark_from_string(G_LOG_DOMAIN)
#endif
2011-04-08 20:58:15 +08:00
G_BEGIN_DECLS
2013-08-08 16:24:20 +08:00
typedef gchar* (*SearpcMarshalFunc) (void *func, json_t *param_array,
2011-04-08 20:58:15 +08:00
gsize *ret_len);
2012-06-20 20:24:49 +08:00
typedef void (*RegisterMarshalFunc) (void);
2019-11-01 15:52:36 +08:00
LIBSEARPC_API
2013-08-08 16:24:20 +08:00
void searpc_set_string_to_ret_object (json_t *object, char *ret);
2019-11-01 15:52:36 +08:00
LIBSEARPC_API
2013-08-08 16:24:20 +08:00
void searpc_set_int_to_ret_object (json_t *object, json_int_t ret);
2019-11-01 15:52:36 +08:00
LIBSEARPC_API
2013-08-08 16:24:20 +08:00
void searpc_set_object_to_ret_object (json_t *object, GObject *ret);
2019-11-01 15:52:36 +08:00
LIBSEARPC_API
2013-08-08 16:24:20 +08:00
void searpc_set_objlist_to_ret_object (json_t *object, GList *ret);
2019-11-01 15:52:36 +08:00
LIBSEARPC_API
2016-06-28 10:46:17 +08:00
void searpc_set_json_to_ret_object (json_t *object, json_t *ret);
2019-11-01 15:52:36 +08:00
LIBSEARPC_API
2013-08-09 14:24:12 +08:00
char *searpc_marshal_set_ret_common (json_t *object, gsize *len, GError *error);
2011-04-08 20:58:15 +08:00
/**
* searpc_server_init:
*
* Inititalize searpc server.
*/
2019-11-01 15:52:36 +08:00
LIBSEARPC_API
2012-06-20 20:24:49 +08:00
void searpc_server_init (RegisterMarshalFunc register_func);
2011-04-08 20:58:15 +08:00
2018-12-21 18:29:58 +08:00
/**
* searpc_server_init_with_slow_log:
*
* Inititalize searpc server with slow log file.
*/
2019-11-01 15:52:36 +08:00
LIBSEARPC_API int
2018-12-21 18:29:58 +08:00
searpc_server_init_with_slow_log (RegisterMarshalFunc register_func,
const char *slow_log_path,
gint64 slow_threshold_in);
/**
* Used in log rotate.
*/
2019-11-01 15:52:36 +08:00
LIBSEARPC_API int
2018-12-21 18:29:58 +08:00
searpc_server_reopen_slow_log (const char *slow_log_path);
2011-11-13 14:09:58 +08:00
/**
* searpc_server_final:
*
* Free the server structure.
*/
2019-11-01 15:52:36 +08:00
LIBSEARPC_API
2011-11-13 14:09:58 +08:00
void searpc_server_final ();
/**
* searpc_create_service:
*
* Create a new service. Service is a set of functions.
* The new service will be registered to the server.
*
* @svc_name: Service name.
*/
2019-11-01 15:52:36 +08:00
LIBSEARPC_API
int searpc_create_service (const char *svc_name);
/**
* searpc_remove_service:
*
* Remove the service from the server.
*/
2019-11-01 15:52:36 +08:00
LIBSEARPC_API
void searpc_remove_service (const char *svc_name);
2011-04-08 20:58:15 +08:00
/**
* searpc_server_register_marshal:
*
* For user to extend marshal functions.
2011-11-13 14:09:58 +08:00
*
* @signature: the signature of the marshal, register_marshal() will take
* owner of this string.
2011-04-08 20:58:15 +08:00
*/
2019-11-01 15:52:36 +08:00
LIBSEARPC_API
2011-11-13 14:09:58 +08:00
gboolean searpc_server_register_marshal (gchar *signature,
2011-04-08 20:58:15 +08:00
SearpcMarshalFunc marshal);
/**
* searpc_server_register_function:
*
* Register a rpc function with given signature to a service.
*
2011-11-13 14:09:58 +08:00
* @signature: the signature of the function, register_function() will take
* owner of this string.
2011-04-08 20:58:15 +08:00
*/
2019-11-01 15:52:36 +08:00
LIBSEARPC_API
gboolean searpc_server_register_function (const char *service,
void* func,
2011-04-08 20:58:15 +08:00
const gchar *fname,
2011-11-13 14:09:58 +08:00
gchar *signature);
2011-04-08 20:58:15 +08:00
/**
* searpc_server_call_function:
* @service: service name.
2011-04-08 20:58:15 +08:00
* @func: the serialized representation of the function to call.
* @len: length of @func.
* @ret_len: the length of the returned string.
*
* Call a registered function @func of a service.
2011-04-08 20:58:15 +08:00
*
* Returns the serialized representatio of the returned value.
*/
2019-11-01 15:52:36 +08:00
LIBSEARPC_API
gchar *searpc_server_call_function (const char *service,
2012-06-04 00:19:16 +08:00
gchar *func, gsize len, gsize *ret_len);
2011-04-08 20:58:15 +08:00
/**
* searpc_compute_signature:
* @ret_type: the return type of the function.
* @pnum: number of parameters of the function.
*
* Compute function signature.
*/
2019-11-01 15:52:36 +08:00
LIBSEARPC_API
2018-06-21 10:49:32 +08:00
char* searpc_compute_signature (const gchar *ret_type, int pnum, ...);
2011-04-08 20:58:15 +08:00
G_END_DECLS
2011-04-08 20:58:15 +08:00
#endif