Register Functions

Register Functions — How to serve and manage new remote methods

Synopsis

typedef             SPRpcMethodID;
void                (*SPRpcMethod)                      (SPRpc *rpc,
                                                         SPRpcMethodID method_id,
                                                         SPRpcParams *params,
                                                         SPRpcParams *return_params,
                                                         gpointer user_data);
SPRpcMethodID       sp_rpc_register                     (SPRpc *rpc,
                                                         const gchar *method_name,
                                                         const gchar *method_description,
                                                         SPRpcParams *params,
                                                         SPRpcMethod method_function,
                                                         gpointer user_data);
void                sp_rpc_unregister                   (SPRpc *rpc,
                                                         SPRpcMethodID method_id);
gboolean            sp_rpc_is_registered                (SPRpc *rpc,
                                                         SPRpcMethodID method_id);

Description

How to serve and manage new remote methods

Details

SPRpcMethodID

typedef gint SPRpcMethodID;

The ID of a registered method.


SPRpcMethod ()

void                (*SPRpcMethod)                      (SPRpc *rpc,
                                                         SPRpcMethodID method_id,
                                                         SPRpcParams *params,
                                                         SPRpcParams *return_params,
                                                         gpointer user_data);

This is the prototype of a method.

rpc :

the SPRpc

method_id :

the ID of this method

params :

the input params

return_params :

a SPRpcParams object for the return values. If it is not empty, it will be send as response.

user_data :

a user data

sp_rpc_register ()

SPRpcMethodID       sp_rpc_register                     (SPRpc *rpc,
                                                         const gchar *method_name,
                                                         const gchar *method_description,
                                                         SPRpcParams *params,
                                                         SPRpcMethod method_function,
                                                         gpointer user_data);

Adds a new method to a SPRpc. The new method will be call when a request is received by the spread ring.

The params describes the inputs of the method. If you specify the type of the input, they will be validated when a client calls this method. If you specify also a value, if the client doesn't send one of them, it will be created with the value you specified here. Use SP_RPC_VALUE_NULL if you want to accept any kind of value.

If a method with this name already exists, it will be replaced with this new one.

rpc :

a SPRpc

method_name :

the name of the method

method_description :

a description of the method or NULL

params :

a SPRpcParams with the SPRpcValues for this method

method_function :

a pointer to a SPRpcMethod

user_data :

data to pass to the function calls

Returns :

a SPRpcMethodID of the new registerd method

sp_rpc_unregister ()

void                sp_rpc_unregister                   (SPRpc *rpc,
                                                         SPRpcMethodID method_id);

Removes a SPRpcMethod from the SPRpc.

rpc :

a SPRpc

method_id :

the ID of the method

sp_rpc_is_registered ()

gboolean            sp_rpc_is_registered                (SPRpc *rpc,
                                                         SPRpcMethodID method_id);

Returns TRUE if the method ID is valid and registerd into a SPRpc.

rpc :

a SPRpc

method_id :

the ID of the method

Returns :

TRUE or FALSE