1
0
mirror of https://github.com/haiwen/libsearpc.git synced 2025-08-01 04:57:11 +00:00

export to generate lib

This commit is contained in:
caixiangyue 2019-11-01 15:52:36 +08:00
parent 3291d04cec
commit 8b853cf41d
5 changed files with 76 additions and 26 deletions

View File

@ -1,6 +1,12 @@
#ifndef SEARPC_CLIENT_H #ifndef SEARPC_CLIENT_H
#define SEARPC_CLIENT_H #define SEARPC_CLIENT_H
#ifdef LIBSEARPC_EXPORTS
#define LIBSEARPC_API __declspec(dllexport)
#else
#define LIBSEARPC_API
#endif
#include <glib.h> #include <glib.h>
#include <glib-object.h> #include <glib-object.h>
#include <jansson.h> #include <jansson.h>
@ -31,85 +37,88 @@ struct _SearpcClient {
void *async_arg; void *async_arg;
}; };
typedef struct _SearpcClient SearpcClient; typedef struct _SearpcClient LIBSEARPC_API SearpcClient;
LIBSEARPC_API
SearpcClient *searpc_client_new (); SearpcClient *searpc_client_new ();
void searpc_client_free (SearpcClient *client); LIBSEARPC_API void
searpc_client_free (SearpcClient *client);
void LIBSEARPC_API void
searpc_client_call (SearpcClient *client, const char *fname, searpc_client_call (SearpcClient *client, const char *fname,
const char *ret_type, GType gobject_type, const char *ret_type, GType gobject_type,
void *ret_ptr, GError **error, void *ret_ptr, GError **error,
int n_params, ...); int n_params, ...);
int LIBSEARPC_API int
searpc_client_call__int (SearpcClient *client, const char *fname, searpc_client_call__int (SearpcClient *client, const char *fname,
GError **error, int n_params, ...); GError **error, int n_params, ...);
gint64 LIBSEARPC_API gint64
searpc_client_call__int64 (SearpcClient *client, const char *fname, searpc_client_call__int64 (SearpcClient *client, const char *fname,
GError **error, int n_params, ...); GError **error, int n_params, ...);
char * LIBSEARPC_API char *
searpc_client_call__string (SearpcClient *client, const char *fname, searpc_client_call__string (SearpcClient *client, const char *fname,
GError **error, int n_params, ...); GError **error, int n_params, ...);
GObject * LIBSEARPC_API GObject *
searpc_client_call__object (SearpcClient *client, const char *fname, searpc_client_call__object (SearpcClient *client, const char *fname,
GType object_type, GType object_type,
GError **error, int n_params, ...); GError **error, int n_params, ...);
GList* LIBSEARPC_API GList*
searpc_client_call__objlist (SearpcClient *client, const char *fname, searpc_client_call__objlist (SearpcClient *client, const char *fname,
GType object_type, GType object_type,
GError **error, int n_params, ...); GError **error, int n_params, ...);
json_t * LIBSEARPC_API json_t *
searpc_client_call__json (SearpcClient *client, const char *fname, searpc_client_call__json (SearpcClient *client, const char *fname,
GError **error, int n_params, ...); GError **error, int n_params, ...);
char* searpc_client_transport_send (SearpcClient *client, LIBSEARPC_API char*
searpc_client_transport_send (SearpcClient *client,
const gchar *fcall_str, const gchar *fcall_str,
size_t fcall_len, size_t fcall_len,
size_t *ret_len); size_t *ret_len);
int LIBSEARPC_API int
searpc_client_async_call__int (SearpcClient *client, searpc_client_async_call__int (SearpcClient *client,
const char *fname, const char *fname,
AsyncCallback callback, void *cbdata, AsyncCallback callback, void *cbdata,
int n_params, ...); int n_params, ...);
int LIBSEARPC_API int
searpc_client_async_call__int64 (SearpcClient *client, searpc_client_async_call__int64 (SearpcClient *client,
const char *fname, const char *fname,
AsyncCallback callback, void *cbdata, AsyncCallback callback, void *cbdata,
int n_params, ...); int n_params, ...);
int LIBSEARPC_API int
searpc_client_async_call__string (SearpcClient *client, searpc_client_async_call__string (SearpcClient *client,
const char *fname, const char *fname,
AsyncCallback callback, void *cbdata, AsyncCallback callback, void *cbdata,
int n_params, ...); int n_params, ...);
int LIBSEARPC_API int
searpc_client_async_call__object (SearpcClient *client, searpc_client_async_call__object (SearpcClient *client,
const char *fname, const char *fname,
AsyncCallback callback, AsyncCallback callback,
GType object_type, void *cbdata, GType object_type, void *cbdata,
int n_params, ...); int n_params, ...);
int LIBSEARPC_API int
searpc_client_async_call__objlist (SearpcClient *client, searpc_client_async_call__objlist (SearpcClient *client,
const char *fname, const char *fname,
AsyncCallback callback, AsyncCallback callback,
GType object_type, void *cbdata, GType object_type, void *cbdata,
int n_params, ...); int n_params, ...);
int LIBSEARPC_API int
searpc_client_async_call__json (SearpcClient *client, searpc_client_async_call__json (SearpcClient *client,
const char *fname, const char *fname,
AsyncCallback callback, void *cbdata, AsyncCallback callback, void *cbdata,
@ -118,7 +127,7 @@ searpc_client_async_call__json (SearpcClient *client,
/* called by the transport layer, the rpc layer should be able to /* called by the transport layer, the rpc layer should be able to
* modify the str, but not take ownership of it */ * modify the str, but not take ownership of it */
int LIBSEARPC_API int
searpc_client_generic_callback (char *retstr, size_t len, searpc_client_generic_callback (char *retstr, size_t len,
void *vdata, const char *errstr); void *vdata, const char *errstr);

View File

@ -1,6 +1,12 @@
#ifndef SEARPC_NAMED_PIPE_TRANSPORT_H #ifndef SEARPC_NAMED_PIPE_TRANSPORT_H
#define SEARPC_NAMED_PIPE_TRANSPORT_H #define SEARPC_NAMED_PIPE_TRANSPORT_H
#ifdef LIBSEARPC_EXPORTS
#define LIBSEARPC_API __declspec(dllexport)
#else
#define LIBSEARPC_API
#endif
#include <pthread.h> #include <pthread.h>
#include <glib.h> #include <glib.h>
#include <glib-object.h> #include <glib-object.h>
@ -34,12 +40,15 @@ struct _SearpcNamedPipeServer {
GThreadPool *named_pipe_server_thread_pool; GThreadPool *named_pipe_server_thread_pool;
}; };
typedef struct _SearpcNamedPipeServer SearpcNamedPipeServer; typedef struct _SearpcNamedPipeServer LIBSEARPC_API SearpcNamedPipeServer;
LIBSEARPC_API
SearpcNamedPipeServer* searpc_create_named_pipe_server(const char *path); SearpcNamedPipeServer* searpc_create_named_pipe_server(const char *path);
LIBSEARPC_API
SearpcNamedPipeServer* searpc_create_named_pipe_server_with_threadpool(const char *path, int named_pipe_server_thread_pool_size); SearpcNamedPipeServer* searpc_create_named_pipe_server_with_threadpool(const char *path, int named_pipe_server_thread_pool_size);
LIBSEARPC_API
int searpc_named_pipe_server_start(SearpcNamedPipeServer *server); int searpc_named_pipe_server_start(SearpcNamedPipeServer *server);
// Client side interface. // Client side interface.
@ -49,14 +58,18 @@ struct _SearpcNamedPipeClient {
SearpcNamedPipe pipe_fd; SearpcNamedPipe pipe_fd;
}; };
typedef struct _SearpcNamedPipeClient SearpcNamedPipeClient; typedef struct _SearpcNamedPipeClient LIBSEARPC_API SearpcNamedPipeClient;
LIBSEARPC_API
SearpcNamedPipeClient* searpc_create_named_pipe_client(const char *path); SearpcNamedPipeClient* searpc_create_named_pipe_client(const char *path);
LIBSEARPC_API
SearpcClient * searpc_client_with_named_pipe_transport(SearpcNamedPipeClient *client, const char *service); SearpcClient * searpc_client_with_named_pipe_transport(SearpcNamedPipeClient *client, const char *service);
LIBSEARPC_API
int searpc_named_pipe_client_connect(SearpcNamedPipeClient *client); int searpc_named_pipe_client_connect(SearpcNamedPipeClient *client);
LIBSEARPC_API
void searpc_free_client_with_pipe_transport (SearpcClient *client); void searpc_free_client_with_pipe_transport (SearpcClient *client);
#endif // SEARPC_NAMED_PIPE_TRANSPORT_H #endif // SEARPC_NAMED_PIPE_TRANSPORT_H

View File

@ -1,6 +1,12 @@
#ifndef SEARPC_SERVER_H #ifndef SEARPC_SERVER_H
#define SEARPC_SERVER_H #define SEARPC_SERVER_H
#ifdef LIBSEARPC_EXPORTS
#define LIBSEARPC_API __declspec(dllexport)
#else
#define LIBSEARPC_API
#endif
#include <glib.h> #include <glib.h>
#include <glib-object.h> #include <glib-object.h>
#include <jansson.h> #include <jansson.h>
@ -13,11 +19,17 @@ typedef gchar* (*SearpcMarshalFunc) (void *func, json_t *param_array,
gsize *ret_len); gsize *ret_len);
typedef void (*RegisterMarshalFunc) (void); typedef void (*RegisterMarshalFunc) (void);
LIBSEARPC_API
void searpc_set_string_to_ret_object (json_t *object, char *ret); void searpc_set_string_to_ret_object (json_t *object, char *ret);
LIBSEARPC_API
void searpc_set_int_to_ret_object (json_t *object, json_int_t ret); void searpc_set_int_to_ret_object (json_t *object, json_int_t ret);
LIBSEARPC_API
void searpc_set_object_to_ret_object (json_t *object, GObject *ret); void searpc_set_object_to_ret_object (json_t *object, GObject *ret);
LIBSEARPC_API
void searpc_set_objlist_to_ret_object (json_t *object, GList *ret); void searpc_set_objlist_to_ret_object (json_t *object, GList *ret);
LIBSEARPC_API
void searpc_set_json_to_ret_object (json_t *object, json_t *ret); void searpc_set_json_to_ret_object (json_t *object, json_t *ret);
LIBSEARPC_API
char *searpc_marshal_set_ret_common (json_t *object, gsize *len, GError *error); char *searpc_marshal_set_ret_common (json_t *object, gsize *len, GError *error);
/** /**
@ -25,6 +37,7 @@ char *searpc_marshal_set_ret_common (json_t *object, gsize *len, GError *error);
* *
* Inititalize searpc server. * Inititalize searpc server.
*/ */
LIBSEARPC_API
void searpc_server_init (RegisterMarshalFunc register_func); void searpc_server_init (RegisterMarshalFunc register_func);
/** /**
@ -32,7 +45,7 @@ void searpc_server_init (RegisterMarshalFunc register_func);
* *
* Inititalize searpc server with slow log file. * Inititalize searpc server with slow log file.
*/ */
int LIBSEARPC_API int
searpc_server_init_with_slow_log (RegisterMarshalFunc register_func, searpc_server_init_with_slow_log (RegisterMarshalFunc register_func,
const char *slow_log_path, const char *slow_log_path,
gint64 slow_threshold_in); gint64 slow_threshold_in);
@ -40,7 +53,7 @@ searpc_server_init_with_slow_log (RegisterMarshalFunc register_func,
/** /**
* Used in log rotate. * Used in log rotate.
*/ */
int LIBSEARPC_API int
searpc_server_reopen_slow_log (const char *slow_log_path); searpc_server_reopen_slow_log (const char *slow_log_path);
/** /**
@ -48,6 +61,7 @@ searpc_server_reopen_slow_log (const char *slow_log_path);
* *
* Free the server structure. * Free the server structure.
*/ */
LIBSEARPC_API
void searpc_server_final (); void searpc_server_final ();
/** /**
@ -58,6 +72,7 @@ void searpc_server_final ();
* *
* @svc_name: Service name. * @svc_name: Service name.
*/ */
LIBSEARPC_API
int searpc_create_service (const char *svc_name); int searpc_create_service (const char *svc_name);
/** /**
@ -65,6 +80,7 @@ int searpc_create_service (const char *svc_name);
* *
* Remove the service from the server. * Remove the service from the server.
*/ */
LIBSEARPC_API
void searpc_remove_service (const char *svc_name); void searpc_remove_service (const char *svc_name);
/** /**
@ -75,6 +91,7 @@ void searpc_remove_service (const char *svc_name);
* @signature: the signature of the marshal, register_marshal() will take * @signature: the signature of the marshal, register_marshal() will take
* owner of this string. * owner of this string.
*/ */
LIBSEARPC_API
gboolean searpc_server_register_marshal (gchar *signature, gboolean searpc_server_register_marshal (gchar *signature,
SearpcMarshalFunc marshal); SearpcMarshalFunc marshal);
@ -86,6 +103,7 @@ gboolean searpc_server_register_marshal (gchar *signature,
* @signature: the signature of the function, register_function() will take * @signature: the signature of the function, register_function() will take
* owner of this string. * owner of this string.
*/ */
LIBSEARPC_API
gboolean searpc_server_register_function (const char *service, gboolean searpc_server_register_function (const char *service,
void* func, void* func,
const gchar *fname, const gchar *fname,
@ -102,6 +120,7 @@ gboolean searpc_server_register_function (const char *service,
* *
* Returns the serialized representatio of the returned value. * Returns the serialized representatio of the returned value.
*/ */
LIBSEARPC_API
gchar *searpc_server_call_function (const char *service, gchar *searpc_server_call_function (const char *service,
gchar *func, gsize len, gsize *ret_len); gchar *func, gsize len, gsize *ret_len);
@ -112,6 +131,7 @@ gchar *searpc_server_call_function (const char *service,
* *
* Compute function signature. * Compute function signature.
*/ */
LIBSEARPC_API
char* searpc_compute_signature (const gchar *ret_type, int pnum, ...); char* searpc_compute_signature (const gchar *ret_type, int pnum, ...);
#endif #endif

View File

@ -2,15 +2,23 @@
#include <glib-object.h> #include <glib-object.h>
#include <jansson.h> #include <jansson.h>
#ifdef LIBSEARPC_EXPORTS
#define LIBSEARPC_API __declspec(dllexport)
#else
#define LIBSEARPC_API
#endif
#define SEARPC_JSON_DOMAIN g_quark_from_string("SEARPC_JSON") #define SEARPC_JSON_DOMAIN g_quark_from_string("SEARPC_JSON")
typedef enum { typedef enum {
SEARPC_JSON_ERROR_LOAD, SEARPC_JSON_ERROR_LOAD,
SEARPC_JSON_ERROR_PACK, SEARPC_JSON_ERROR_PACK,
SEARPC_JSON_ERROR_UPACK SEARPC_JSON_ERROR_UPACK
} SEARPCJSONERROR; } LIBSEARPC_API SEARPCJSONERROR;
LIBSEARPC_API
json_t *json_gobject_serialize (GObject *); json_t *json_gobject_serialize (GObject *);
LIBSEARPC_API
GObject *json_gobject_deserialize (GType , json_t *); GObject *json_gobject_deserialize (GType , json_t *);
inline static void setjetoge(const json_error_t *jerror, GError **error) inline static void setjetoge(const json_error_t *jerror, GError **error)

View File

@ -71,7 +71,7 @@
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile> <ClCompile>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;LIBSEARPC_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat> <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>