FS-10167: Refactoring and cleanup
This commit is contained in:
parent
53116495d1
commit
84540ea857
|
@ -204,6 +204,7 @@
|
|||
<ClCompile Include="src\blade_session.c" />
|
||||
<ClCompile Include="src\blade_stack.c" />
|
||||
<ClCompile Include="src\blade_transport.c" />
|
||||
<ClCompile Include="src\blade_tuple.c" />
|
||||
<ClCompile Include="src\blade_upstreammgr.c" />
|
||||
<ClCompile Include="src\unqlite.c" />
|
||||
</ItemGroup>
|
||||
|
@ -225,6 +226,7 @@
|
|||
<ClInclude Include="src\include\blade_session.h" />
|
||||
<ClInclude Include="src\include\blade_stack.h" />
|
||||
<ClInclude Include="src\include\blade_transport.h" />
|
||||
<ClInclude Include="src\include\blade_tuple.h" />
|
||||
<ClInclude Include="src\include\blade_types.h" />
|
||||
<ClInclude Include="src\include\blade_upstreammgr.h" />
|
||||
<ClInclude Include="src\include\unqlite.h" />
|
||||
|
|
|
@ -72,6 +72,9 @@
|
|||
<ClCompile Include="src\blade_sessionmgr.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\blade_tuple.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\include\unqlite.h">
|
||||
|
@ -134,5 +137,8 @@
|
|||
<ClInclude Include="src\include\blade_sessionmgr.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\include\blade_tuple.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -140,7 +140,7 @@ KS_DECLARE(ks_status_t) blade_routemgr_route_add(blade_routemgr_t *brmgr, const
|
|||
|
||||
ks_log(KS_LOG_DEBUG, "Route Added: %s through %s\n", key, value);
|
||||
|
||||
blade_protocol_register(brmgr->handle, target, KS_FALSE, NULL, NULL);
|
||||
blade_handle_rpcregister(brmgr->handle, target, KS_FALSE, NULL, NULL);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
|
||||
|
@ -155,7 +155,7 @@ KS_DECLARE(ks_status_t) blade_routemgr_route_remove(blade_routemgr_t *brmgr, con
|
|||
|
||||
ks_log(KS_LOG_DEBUG, "Route Removed: %s\n", target);
|
||||
|
||||
blade_protocol_register(brmgr->handle, target, KS_TRUE, NULL, NULL);
|
||||
blade_handle_rpcregister(brmgr->handle, target, KS_TRUE, NULL, NULL);
|
||||
|
||||
// @note protocols are cleaned up here because routes can be removed that are not locally connected with a session but still
|
||||
// have protocols published to the master node from further downstream, in which case if a route is announced upstream to be
|
||||
|
|
|
@ -42,7 +42,7 @@ struct blade_rpc_s {
|
|||
const char *realm;
|
||||
|
||||
blade_rpc_request_callback_t callback;
|
||||
void *callback_data;
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct blade_rpc_request_s {
|
||||
|
@ -54,7 +54,7 @@ struct blade_rpc_request_s {
|
|||
cJSON *message;
|
||||
const char *message_id; // pulled from message for easier keying
|
||||
blade_rpc_response_callback_t callback;
|
||||
void *callback_data;
|
||||
void *data;
|
||||
// @todo ttl to wait for response before injecting an error response locally
|
||||
};
|
||||
|
||||
|
@ -86,7 +86,7 @@ static void blade_rpc_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cle
|
|||
}
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_rpc_create(blade_rpc_t **brpcP, blade_handle_t *bh, const char *method, const char *protocol, const char *realm, blade_rpc_request_callback_t callback, void *callback_data)
|
||||
KS_DECLARE(ks_status_t) blade_rpc_create(blade_rpc_t **brpcP, blade_handle_t *bh, const char *method, const char *protocol, const char *realm, blade_rpc_request_callback_t callback, void *data)
|
||||
{
|
||||
blade_rpc_t *brpc = NULL;
|
||||
ks_pool_t *pool = NULL;
|
||||
|
@ -106,7 +106,7 @@ KS_DECLARE(ks_status_t) blade_rpc_create(blade_rpc_t **brpcP, blade_handle_t *bh
|
|||
if (protocol) brpc->protocol = ks_pstrdup(pool, protocol);
|
||||
if (realm) brpc->realm = ks_pstrdup(pool, realm);
|
||||
brpc->callback = callback;
|
||||
brpc->callback_data = callback_data;
|
||||
brpc->data = data;
|
||||
|
||||
ks_pool_set_cleanup(pool, brpc, NULL, blade_rpc_cleanup);
|
||||
|
||||
|
@ -169,11 +169,11 @@ KS_DECLARE(blade_rpc_request_callback_t) blade_rpc_callback_get(blade_rpc_t *brp
|
|||
return brpc->callback;
|
||||
}
|
||||
|
||||
KS_DECLARE(void *) blade_rpc_callback_data_get(blade_rpc_t *brpc)
|
||||
KS_DECLARE(void *) blade_rpc_data_get(blade_rpc_t *brpc)
|
||||
{
|
||||
ks_assert(brpc);
|
||||
|
||||
return brpc->callback_data;
|
||||
return brpc->data;
|
||||
}
|
||||
|
||||
|
||||
|
@ -218,7 +218,7 @@ KS_DECLARE(ks_status_t) blade_rpc_request_create(blade_rpc_request_t **brpcreqP,
|
|||
brpcreq->message = cJSON_Duplicate(json, 1);
|
||||
brpcreq->message_id = cJSON_GetObjectCstr(brpcreq->message, "id");
|
||||
brpcreq->callback = callback;
|
||||
brpcreq->callback_data = data;
|
||||
brpcreq->data = data;
|
||||
|
||||
ks_pool_set_cleanup(pool, brpcreq, NULL, blade_rpc_request_cleanup);
|
||||
|
||||
|
@ -243,7 +243,7 @@ KS_DECLARE(ks_status_t) blade_rpc_request_destroy(blade_rpc_request_t **brpcreqP
|
|||
|
||||
KS_DECLARE(ks_status_t) blade_rpc_request_duplicate(blade_rpc_request_t **brpcreqP, blade_rpc_request_t *brpcreq)
|
||||
{
|
||||
return blade_rpc_request_create(brpcreqP, brpcreq->handle, brpcreq->pool, brpcreq->session_id, brpcreq->message, brpcreq->callback, brpcreq->callback_data);
|
||||
return blade_rpc_request_create(brpcreqP, brpcreq->handle, brpcreq->pool, brpcreq->session_id, brpcreq->message, brpcreq->callback, brpcreq->data);
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_handle_t *) blade_rpc_request_handle_get(blade_rpc_request_t *brpcreq)
|
||||
|
@ -276,11 +276,10 @@ KS_DECLARE(blade_rpc_response_callback_t) blade_rpc_request_callback_get(blade_r
|
|||
return brpcreq->callback;
|
||||
}
|
||||
|
||||
KS_DECLARE(void *) blade_rpc_request_callback_data_get(blade_rpc_request_t *brpcreq)
|
||||
KS_DECLARE(void *) blade_rpc_request_data_get(blade_rpc_request_t *brpcreq)
|
||||
{
|
||||
ks_assert(brpcreq);
|
||||
|
||||
return brpcreq->callback_data;
|
||||
return brpcreq->data;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_rpc_request_raw_create(ks_pool_t *pool, cJSON **json, cJSON **params, const char **id, const char *method)
|
||||
|
|
|
@ -62,7 +62,7 @@ static void blade_rpcmgr_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_
|
|||
ks_hash_this(it, (const void **)&key, NULL, (void **)&value);
|
||||
ks_hash_remove(brpcmgr->protocolrpcs, key);
|
||||
|
||||
blade_rpc_destroy(&value); // must call destroy to close the rpc pool, using FREE_VALUE on the hash would attempt to free the rpc from the wrong pool
|
||||
blade_rpc_destroy(&value); // must call destroy to close the method pool, using FREE_VALUE on the hash would attempt to free the method from the wrong pool
|
||||
}
|
||||
while ((it = ks_hash_first(brpcmgr->corerpcs, KS_UNLOCKED)) != NULL) {
|
||||
void *key = NULL;
|
||||
|
|
|
@ -724,7 +724,7 @@ ks_status_t blade_session_process(blade_session_t *bs, cJSON *json)
|
|||
blade_rpc_request_create(&brpcreq, bs->handle, blade_handle_pool_get(bs->handle), bs->id, json, NULL, NULL);
|
||||
ks_assert(brpcreq);
|
||||
|
||||
disconnect = callback(brpcreq, blade_rpc_callback_data_get(brpc));
|
||||
disconnect = callback(brpcreq, blade_rpc_data_get(brpc));
|
||||
|
||||
blade_rpc_request_destroy(&brpcreq);
|
||||
} else {
|
||||
|
@ -779,7 +779,7 @@ ks_status_t blade_session_process(blade_session_t *bs, cJSON *json)
|
|||
blade_rpc_response_create(&brpcres, bs->handle, bs->pool, bs->id, brpcreq, json);
|
||||
ks_assert(brpcres);
|
||||
|
||||
if (callback) disconnect = callback(brpcres, blade_rpc_request_callback_data_get(brpcreq));
|
||||
if (callback) disconnect = callback(brpcres, blade_rpc_request_data_get(brpcreq));
|
||||
|
||||
blade_rpc_response_destroy(&brpcres);
|
||||
}
|
||||
|
|
|
@ -47,13 +47,12 @@ struct blade_handle_s {
|
|||
blade_sessionmgr_t *sessionmgr;
|
||||
};
|
||||
|
||||
|
||||
ks_bool_t blade_protocol_register_request_handler(blade_rpc_request_t *brpcreq, void *data);
|
||||
ks_bool_t blade_protocol_publish_request_handler(blade_rpc_request_t *brpcreq, void *data);
|
||||
ks_bool_t blade_protocol_locate_request_handler(blade_rpc_request_t *brpcreq, void *data);
|
||||
ks_bool_t blade_protocol_execute_request_handler(blade_rpc_request_t *brpcreq, void *data);
|
||||
ks_bool_t blade_protocol_subscribe_request_handler(blade_rpc_request_t *brpcreq, void *data);
|
||||
ks_bool_t blade_protocol_broadcast_request_handler(blade_rpc_request_t *brpcreq, void *data);
|
||||
ks_bool_t blade_rpcregister_request_handler(blade_rpc_request_t *brpcreq, void *data);
|
||||
ks_bool_t blade_rpcpublish_request_handler(blade_rpc_request_t *brpcreq, void *data);
|
||||
ks_bool_t blade_rpclocate_request_handler(blade_rpc_request_t *brpcreq, void *data);
|
||||
ks_bool_t blade_rpcexecute_request_handler(blade_rpc_request_t *brpcreq, void *data);
|
||||
ks_bool_t blade_rpcsubscribe_request_handler(blade_rpc_request_t *brpcreq, void *data);
|
||||
ks_bool_t blade_rpcbroadcast_request_handler(blade_rpc_request_t *brpcreq, void *data);
|
||||
|
||||
|
||||
static void blade_handle_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
|
||||
|
@ -220,22 +219,22 @@ KS_DECLARE(ks_status_t) blade_handle_startup(blade_handle_t *bh, config_setting_
|
|||
|
||||
|
||||
// register internal core rpcs for blade.xxx
|
||||
blade_rpc_create(&brpc, bh, "blade.register", NULL, NULL, blade_protocol_register_request_handler, NULL);
|
||||
blade_rpc_create(&brpc, bh, "blade.register", NULL, NULL, blade_rpcregister_request_handler, NULL);
|
||||
blade_rpcmgr_corerpc_add(bh->rpcmgr, brpc);
|
||||
|
||||
blade_rpc_create(&brpc, bh, "blade.publish", NULL, NULL, blade_protocol_publish_request_handler, NULL);
|
||||
blade_rpc_create(&brpc, bh, "blade.publish", NULL, NULL, blade_rpcpublish_request_handler, NULL);
|
||||
blade_rpcmgr_corerpc_add(bh->rpcmgr, brpc);
|
||||
|
||||
blade_rpc_create(&brpc, bh, "blade.locate", NULL, NULL, blade_protocol_locate_request_handler, NULL);
|
||||
blade_rpc_create(&brpc, bh, "blade.locate", NULL, NULL, blade_rpclocate_request_handler, NULL);
|
||||
blade_rpcmgr_corerpc_add(bh->rpcmgr, brpc);
|
||||
|
||||
blade_rpc_create(&brpc, bh, "blade.execute", NULL, NULL, blade_protocol_execute_request_handler, NULL);
|
||||
blade_rpc_create(&brpc, bh, "blade.execute", NULL, NULL, blade_rpcexecute_request_handler, NULL);
|
||||
blade_rpcmgr_corerpc_add(bh->rpcmgr, brpc);
|
||||
|
||||
blade_rpc_create(&brpc, bh, "blade.subscribe", NULL, NULL, blade_protocol_subscribe_request_handler, NULL);
|
||||
blade_rpc_create(&brpc, bh, "blade.subscribe", NULL, NULL, blade_rpcsubscribe_request_handler, NULL);
|
||||
blade_rpcmgr_corerpc_add(bh->rpcmgr, brpc);
|
||||
|
||||
blade_rpc_create(&brpc, bh, "blade.broadcast", NULL, NULL, blade_protocol_broadcast_request_handler, NULL);
|
||||
blade_rpc_create(&brpc, bh, "blade.broadcast", NULL, NULL, blade_rpcbroadcast_request_handler, NULL);
|
||||
blade_rpcmgr_corerpc_add(bh->rpcmgr, brpc);
|
||||
|
||||
|
||||
|
@ -349,7 +348,7 @@ KS_DECLARE(ks_status_t) blade_handle_connect(blade_handle_t *bh, blade_connectio
|
|||
// which is important for implementation of blade.execute where errors can be relayed back to the requester properly
|
||||
|
||||
// blade.register request generator
|
||||
KS_DECLARE(ks_status_t) blade_protocol_register(blade_handle_t *bh, const char *nodeid, ks_bool_t remove, blade_rpc_response_callback_t callback, void *data)
|
||||
KS_DECLARE(ks_status_t) blade_handle_rpcregister(blade_handle_t *bh, const char *nodeid, ks_bool_t remove, blade_rpc_response_callback_t callback, void *data)
|
||||
{
|
||||
ks_status_t ret = KS_STATUS_SUCCESS;
|
||||
blade_session_t *bs = NULL;
|
||||
|
@ -386,7 +385,7 @@ done:
|
|||
}
|
||||
|
||||
// blade.register request handler
|
||||
ks_bool_t blade_protocol_register_request_handler(blade_rpc_request_t *brpcreq, void *data)
|
||||
ks_bool_t blade_rpcregister_request_handler(blade_rpc_request_t *brpcreq, void *data)
|
||||
{
|
||||
blade_handle_t *bh = NULL;
|
||||
blade_session_t *bs = NULL;
|
||||
|
@ -450,7 +449,7 @@ done:
|
|||
|
||||
|
||||
// blade.publish request generator
|
||||
KS_DECLARE(ks_status_t) blade_protocol_publish(blade_handle_t *bh, const char *name, const char *realm, blade_rpc_response_callback_t callback, void *data)
|
||||
KS_DECLARE(ks_status_t) blade_handle_rpcpublish(blade_handle_t *bh, const char *name, const char *realm, blade_rpc_response_callback_t callback, void *data)
|
||||
{
|
||||
ks_status_t ret = KS_STATUS_SUCCESS;
|
||||
blade_session_t *bs = NULL;
|
||||
|
@ -504,7 +503,7 @@ done:
|
|||
}
|
||||
|
||||
// blade.publish request handler
|
||||
ks_bool_t blade_protocol_publish_request_handler(blade_rpc_request_t *brpcreq, void *data)
|
||||
ks_bool_t blade_rpcpublish_request_handler(blade_rpc_request_t *brpcreq, void *data)
|
||||
{
|
||||
blade_handle_t *bh = NULL;
|
||||
blade_session_t *bs = NULL;
|
||||
|
@ -605,7 +604,7 @@ done:
|
|||
// @todo discuss system to support caching locate results, and internally subscribing to receive event updates related to protocols which have been located
|
||||
// to ensure local caches remain synced when protocol controllers change, but this requires additional filters for event propagating to avoid broadcasting
|
||||
// every protocol update to everyone which may actually be a better way than an explicit locate request
|
||||
KS_DECLARE(ks_status_t) blade_protocol_locate(blade_handle_t *bh, const char *name, const char *realm, blade_rpc_response_callback_t callback, void *data)
|
||||
KS_DECLARE(ks_status_t) blade_handle_rpclocate(blade_handle_t *bh, const char *name, const char *realm, blade_rpc_response_callback_t callback, void *data)
|
||||
{
|
||||
ks_status_t ret = KS_STATUS_SUCCESS;
|
||||
blade_session_t *bs = NULL;
|
||||
|
@ -656,7 +655,7 @@ done:
|
|||
}
|
||||
|
||||
// blade.locate request handler
|
||||
ks_bool_t blade_protocol_locate_request_handler(blade_rpc_request_t *brpcreq, void *data)
|
||||
ks_bool_t blade_rpclocate_request_handler(blade_rpc_request_t *brpcreq, void *data)
|
||||
{
|
||||
blade_handle_t *bh = NULL;
|
||||
blade_session_t *bs = NULL;
|
||||
|
@ -771,7 +770,7 @@ done:
|
|||
|
||||
|
||||
// blade.execute request generator
|
||||
KS_DECLARE(ks_status_t) blade_protocol_execute(blade_handle_t *bh, const char *nodeid, const char *method, const char *protocol, const char *realm, cJSON *params, blade_rpc_response_callback_t callback, void *data)
|
||||
KS_DECLARE(ks_status_t) blade_handle_rpcexecute(blade_handle_t *bh, const char *nodeid, const char *method, const char *protocol, const char *realm, cJSON *params, blade_rpc_response_callback_t callback, void *data)
|
||||
{
|
||||
ks_status_t ret = KS_STATUS_SUCCESS;
|
||||
blade_session_t *bs = NULL;
|
||||
|
@ -798,7 +797,6 @@ KS_DECLARE(ks_status_t) blade_protocol_execute(blade_handle_t *bh, const char *n
|
|||
|
||||
blade_rpc_request_raw_create(pool, &req, &req_params, NULL, "blade.execute");
|
||||
|
||||
// fill in the req_params
|
||||
cJSON_AddStringToObject(req_params, "method", method);
|
||||
cJSON_AddStringToObject(req_params, "protocol", protocol);
|
||||
cJSON_AddStringToObject(req_params, "realm", realm);
|
||||
|
@ -815,8 +813,14 @@ KS_DECLARE(ks_status_t) blade_protocol_execute(blade_handle_t *bh, const char *n
|
|||
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) execute request started\n", blade_session_id_get(bs));
|
||||
|
||||
// @todo change what blade_rpc_request_t carries for tracking data, use a tuple instead which makes it
|
||||
// easier to free the tuple and potentially associated data if a request needs to be destroyed without
|
||||
// the callback being called to know that the data is a tuple to destroy, meanwhile a tuple offers a
|
||||
// spare pointer for universally wrapping callback + data pairs in a case like this
|
||||
// in which case do not create the tuple here, just pass 2 data pointers to send and let it store them
|
||||
// in the internal tuple
|
||||
ret = blade_session_send(bs, req, callback, data);
|
||||
|
||||
|
||||
done:
|
||||
if (req) cJSON_Delete(req);
|
||||
if (bs) blade_session_read_unlock(bs);
|
||||
|
@ -825,7 +829,7 @@ done:
|
|||
}
|
||||
|
||||
// blade.execute request handler
|
||||
ks_bool_t blade_protocol_execute_request_handler(blade_rpc_request_t *brpcreq, void *data)
|
||||
ks_bool_t blade_rpcexecute_request_handler(blade_rpc_request_t *brpcreq, void *data)
|
||||
{
|
||||
ks_bool_t ret = KS_FALSE;
|
||||
blade_handle_t *bh = NULL;
|
||||
|
@ -913,9 +917,9 @@ ks_bool_t blade_protocol_execute_request_handler(blade_rpc_request_t *brpcreq, v
|
|||
blade_session_send(bs, res, NULL, NULL);
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
||||
callback = blade_rpc_callback_get(brpc);
|
||||
if (callback) ret = callback(brpcreq, blade_rpc_callback_data_get(brpc));
|
||||
if (callback) ret = callback(brpcreq, blade_rpc_data_get(brpc));
|
||||
|
||||
done:
|
||||
|
||||
|
@ -925,7 +929,7 @@ done:
|
|||
return ret;
|
||||
}
|
||||
|
||||
KS_DECLARE(const char *) blade_protocol_execute_request_requester_nodeid_get(blade_rpc_request_t *brpcreq)
|
||||
KS_DECLARE(const char *) blade_rpcexecute_request_requester_nodeid_get(blade_rpc_request_t *brpcreq)
|
||||
{
|
||||
cJSON *req = NULL;
|
||||
cJSON *req_params = NULL;
|
||||
|
@ -942,7 +946,7 @@ KS_DECLARE(const char *) blade_protocol_execute_request_requester_nodeid_get(bla
|
|||
return req_requester_nodeid;
|
||||
}
|
||||
|
||||
KS_DECLARE(const char *) blade_protocol_execute_request_responder_nodeid_get(blade_rpc_request_t *brpcreq)
|
||||
KS_DECLARE(const char *) blade_rpcexecute_request_responder_nodeid_get(blade_rpc_request_t *brpcreq)
|
||||
{
|
||||
cJSON *req = NULL;
|
||||
cJSON *req_params = NULL;
|
||||
|
@ -959,7 +963,7 @@ KS_DECLARE(const char *) blade_protocol_execute_request_responder_nodeid_get(bla
|
|||
return req_responder_nodeid;
|
||||
}
|
||||
|
||||
KS_DECLARE(cJSON *) blade_protocol_execute_request_params_get(blade_rpc_request_t *brpcreq)
|
||||
KS_DECLARE(cJSON *) blade_rpcexecute_request_params_get(blade_rpc_request_t *brpcreq)
|
||||
{
|
||||
cJSON *req = NULL;
|
||||
cJSON *req_params = NULL;
|
||||
|
@ -976,7 +980,7 @@ KS_DECLARE(cJSON *) blade_protocol_execute_request_params_get(blade_rpc_request_
|
|||
return req_params_params;
|
||||
}
|
||||
|
||||
KS_DECLARE(cJSON *) blade_protocol_execute_response_result_get(blade_rpc_response_t *brpcres)
|
||||
KS_DECLARE(cJSON *) blade_rpcexecute_response_result_get(blade_rpc_response_t *brpcres)
|
||||
{
|
||||
cJSON *res = NULL;
|
||||
cJSON *res_result = NULL;
|
||||
|
@ -996,7 +1000,7 @@ KS_DECLARE(cJSON *) blade_protocol_execute_response_result_get(blade_rpc_respons
|
|||
// @note added blade_rpc_request_duplicate() to support async responding where the callbacks return immediately and the blade_rpc_request_t will be destroyed,
|
||||
// in such cases duplicate the request to retain a copy for passing to blade_protocol_execute_response_send when sending the response as it contains everything
|
||||
// needed to produce a response except the inner result block for blade.execute and call blade_rpc_request_destroy() to clean up the duplicate when finished
|
||||
KS_DECLARE(void) blade_protocol_execute_response_send(blade_rpc_request_t *brpcreq, cJSON *result)
|
||||
KS_DECLARE(void) blade_rpcexecute_response_send(blade_rpc_request_t *brpcreq, cJSON *result)
|
||||
{
|
||||
blade_handle_t *bh = NULL;
|
||||
blade_session_t *bs = NULL;
|
||||
|
@ -1055,7 +1059,7 @@ KS_DECLARE(void) blade_protocol_execute_response_send(blade_rpc_request_t *brpcr
|
|||
|
||||
|
||||
// blade.subscribe request generator
|
||||
KS_DECLARE(ks_status_t) blade_protocol_subscribe(blade_handle_t *bh, const char *event, const char *protocol, const char *realm, ks_bool_t remove, blade_rpc_response_callback_t callback, void *data, blade_rpc_request_callback_t event_callback, void *event_data)
|
||||
KS_DECLARE(ks_status_t) blade_handle_rpcsubscribe(blade_handle_t *bh, const char *event, const char *protocol, const char *realm, ks_bool_t remove, blade_rpc_response_callback_t callback, void *data, blade_rpc_request_callback_t event_callback, void *event_data)
|
||||
{
|
||||
ks_status_t ret = KS_STATUS_SUCCESS;
|
||||
blade_session_t *bs = NULL;
|
||||
|
@ -1089,7 +1093,7 @@ KS_DECLARE(ks_status_t) blade_protocol_subscribe(blade_handle_t *bh, const char
|
|||
blade_subscription_callback_data_set(bsub, event_data);
|
||||
}
|
||||
|
||||
if (propagate) ret = blade_protocol_subscribe_raw(bh, event, protocol, realm, remove, callback, data);
|
||||
if (propagate) ret = blade_handle_rpcsubscribe_raw(bh, event, protocol, realm, remove, callback, data);
|
||||
|
||||
done:
|
||||
if (bs) blade_session_read_unlock(bs);
|
||||
|
@ -1097,7 +1101,7 @@ done:
|
|||
return ret;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_protocol_subscribe_raw(blade_handle_t *bh, const char *event, const char *protocol, const char *realm, ks_bool_t remove, blade_rpc_response_callback_t callback, void *data)
|
||||
KS_DECLARE(ks_status_t) blade_handle_rpcsubscribe_raw(blade_handle_t *bh, const char *event, const char *protocol, const char *realm, ks_bool_t remove, blade_rpc_response_callback_t callback, void *data)
|
||||
{
|
||||
ks_status_t ret = KS_STATUS_SUCCESS;
|
||||
blade_session_t *bs = NULL;
|
||||
|
@ -1137,7 +1141,7 @@ done:
|
|||
}
|
||||
|
||||
// blade.subscribe request handler
|
||||
ks_bool_t blade_protocol_subscribe_request_handler(blade_rpc_request_t *brpcreq, void *data)
|
||||
ks_bool_t blade_rpcsubscribe_request_handler(blade_rpc_request_t *brpcreq, void *data)
|
||||
{
|
||||
blade_handle_t *bh = NULL;
|
||||
blade_session_t *bs = NULL;
|
||||
|
@ -1212,7 +1216,7 @@ ks_bool_t blade_protocol_subscribe_request_handler(blade_rpc_request_t *brpcreq,
|
|||
propagate = blade_subscriptionmgr_subscriber_add(bh->subscriptionmgr, NULL, req_params_event, req_params_protocol, req_params_realm, blade_session_id_get(bs));
|
||||
}
|
||||
|
||||
if (propagate) blade_protocol_subscribe_raw(bh, req_params_event, req_params_protocol, req_params_realm, remove, NULL, NULL);
|
||||
if (propagate) blade_handle_rpcsubscribe_raw(bh, req_params_event, req_params_protocol, req_params_realm, remove, NULL, NULL);
|
||||
|
||||
// build the actual response finally
|
||||
blade_rpc_response_raw_create(&res, &res_result, blade_rpc_request_messageid_get(brpcreq));
|
||||
|
@ -1234,7 +1238,7 @@ done:
|
|||
|
||||
|
||||
// blade.broadcast request generator
|
||||
KS_DECLARE(ks_status_t) blade_protocol_broadcast(blade_handle_t *bh, const char *broadcaster_nodeid, const char *event, const char *protocol, const char *realm, cJSON *params, blade_rpc_response_callback_t callback, void *data)
|
||||
KS_DECLARE(ks_status_t) blade_handle_rpcbroadcast(blade_handle_t *bh, const char *broadcaster_nodeid, const char *event, const char *protocol, const char *realm, cJSON *params, blade_rpc_response_callback_t callback, void *data)
|
||||
{
|
||||
ks_status_t ret = KS_STATUS_SUCCESS;
|
||||
ks_pool_t *pool = NULL;
|
||||
|
@ -1266,7 +1270,7 @@ KS_DECLARE(ks_status_t) blade_protocol_broadcast(blade_handle_t *bh, const char
|
|||
}
|
||||
|
||||
// blade.broadcast request handler
|
||||
ks_bool_t blade_protocol_broadcast_request_handler(blade_rpc_request_t *brpcreq, void *data)
|
||||
ks_bool_t blade_rpcbroadcast_request_handler(blade_rpc_request_t *brpcreq, void *data)
|
||||
{
|
||||
ks_bool_t ret = KS_FALSE;
|
||||
blade_handle_t *bh = NULL;
|
||||
|
@ -1366,7 +1370,6 @@ ks_bool_t blade_protocol_broadcast_request_handler(blade_rpc_request_t *brpcreq,
|
|||
// request was just received on a session that is already read locked, so we can assume the response goes back on the same session without further lookup
|
||||
blade_session_send(bs, res, NULL, NULL);
|
||||
|
||||
|
||||
done:
|
||||
|
||||
if (res) cJSON_Delete(res);
|
||||
|
@ -1375,7 +1378,7 @@ done:
|
|||
return ret;
|
||||
}
|
||||
|
||||
KS_DECLARE(const char *) blade_protocol_broadcast_request_broadcaster_nodeid_get(blade_rpc_request_t *brpcreq)
|
||||
KS_DECLARE(const char *) blade_rpcbroadcast_request_broadcaster_nodeid_get(blade_rpc_request_t *brpcreq)
|
||||
{
|
||||
cJSON *req = NULL;
|
||||
cJSON *req_params = NULL;
|
||||
|
@ -1392,7 +1395,7 @@ KS_DECLARE(const char *) blade_protocol_broadcast_request_broadcaster_nodeid_get
|
|||
return req_broadcaster_nodeid;
|
||||
}
|
||||
|
||||
KS_DECLARE(cJSON *) blade_protocol_broadcast_request_params_get(blade_rpc_request_t *brpcreq)
|
||||
KS_DECLARE(cJSON *) blade_rpcbroadcast_request_params_get(blade_rpc_request_t *brpcreq)
|
||||
{
|
||||
cJSON *req = NULL;
|
||||
cJSON *req_params = NULL;
|
||||
|
|
|
@ -284,7 +284,7 @@ KS_DECLARE(void) blade_subscriptionmgr_subscriber_cleanup(blade_subscriptionmgr_
|
|||
|
||||
if (!unsubbed) {
|
||||
if (blade_subscriptionmgr_subscriber_remove(bsmgr, NULL, event, protocol, realm, target)) {
|
||||
blade_protocol_subscribe_raw(bsmgr->handle, event, protocol, realm, KS_TRUE, NULL, NULL);
|
||||
blade_handle_rpcsubscribe_raw(bsmgr->handle, event, protocol, realm, KS_TRUE, NULL, NULL);
|
||||
}
|
||||
ks_pool_free(bsmgr->pool, &event);
|
||||
ks_pool_free(bsmgr->pool, &protocol);
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* Copyright (c) 2017, Shane Bryldt
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "blade.h"
|
||||
|
||||
struct blade_tuple_s {
|
||||
ks_pool_t *pool;
|
||||
|
||||
void *value1;
|
||||
void *value2;
|
||||
};
|
||||
|
||||
|
||||
static void blade_tuple_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
|
||||
{
|
||||
//blade_tuple_t *bt = (blade_tuple_t *)ptr;
|
||||
|
||||
//ks_assert(bt);
|
||||
|
||||
switch (action) {
|
||||
case KS_MPCL_ANNOUNCE:
|
||||
break;
|
||||
case KS_MPCL_TEARDOWN:
|
||||
break;
|
||||
case KS_MPCL_DESTROY:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_tuple_create(blade_tuple_t **btP, ks_pool_t *pool, void *value1, void *value2)
|
||||
{
|
||||
blade_tuple_t *bt = NULL;
|
||||
|
||||
ks_assert(btP);
|
||||
ks_assert(pool);
|
||||
|
||||
bt = ks_pool_alloc(pool, sizeof(blade_tuple_t));
|
||||
bt->pool = pool;
|
||||
bt->value1 = value1;
|
||||
bt->value2 = value2;
|
||||
|
||||
ks_pool_set_cleanup(pool, bt, NULL, blade_tuple_cleanup);
|
||||
|
||||
*btP = bt;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_tuple_destroy(blade_tuple_t **btP)
|
||||
{
|
||||
ks_assert(btP);
|
||||
ks_assert(*btP);
|
||||
|
||||
ks_pool_free((*btP)->pool, btP);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(void *) blade_tuple_value1_get(blade_tuple_t *bt)
|
||||
{
|
||||
ks_assert(bt);
|
||||
return bt->value1;
|
||||
}
|
||||
|
||||
KS_DECLARE(void *) blade_tuple_value2_get(blade_tuple_t *bt)
|
||||
{
|
||||
ks_assert(bt);
|
||||
return bt->value2;
|
||||
}
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
|
||||
*/
|
|
@ -46,6 +46,7 @@
|
|||
#include "blade_session.h"
|
||||
#include "blade_protocol.h"
|
||||
#include "blade_subscription.h"
|
||||
#include "blade_tuple.h"
|
||||
|
||||
#include "blade_transportmgr.h"
|
||||
#include "blade_rpcmgr.h"
|
||||
|
|
|
@ -36,14 +36,14 @@
|
|||
#include <blade.h>
|
||||
|
||||
KS_BEGIN_EXTERN_C
|
||||
KS_DECLARE(ks_status_t) blade_rpc_create(blade_rpc_t **brpcP, blade_handle_t *bh, const char *method, const char *protocol, const char *realm, blade_rpc_request_callback_t callback, void *callback_data);
|
||||
KS_DECLARE(ks_status_t) blade_rpc_create(blade_rpc_t **brpcP, blade_handle_t *bh, const char *method, const char *protocol, const char *realm, blade_rpc_request_callback_t callback, void *data);
|
||||
KS_DECLARE(ks_status_t) blade_rpc_destroy(blade_rpc_t **brpcP);
|
||||
KS_DECLARE(blade_handle_t *) blade_rpc_handle_get(blade_rpc_t *brpc);
|
||||
KS_DECLARE(const char *) blade_rpc_method_get(blade_rpc_t *brpc);
|
||||
KS_DECLARE(const char *) blade_rpc_protocol_get(blade_rpc_t *brpc);
|
||||
KS_DECLARE(const char *) blade_rpc_realm_get(blade_rpc_t *brpc);
|
||||
KS_DECLARE(blade_rpc_request_callback_t) blade_rpc_callback_get(blade_rpc_t *brpc);
|
||||
KS_DECLARE(void *) blade_rpc_callback_data_get(blade_rpc_t *brpc);
|
||||
KS_DECLARE(void *) blade_rpc_data_get(blade_rpc_t *brpc);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_rpc_request_create(blade_rpc_request_t **brpcreqP,
|
||||
blade_handle_t *bh,
|
||||
|
@ -58,7 +58,7 @@ KS_DECLARE(const char *) blade_rpc_request_sessionid_get(blade_rpc_request_t *br
|
|||
KS_DECLARE(cJSON *) blade_rpc_request_message_get(blade_rpc_request_t *brpcreq);
|
||||
KS_DECLARE(const char *) blade_rpc_request_messageid_get(blade_rpc_request_t *brpcreq);
|
||||
KS_DECLARE(blade_rpc_response_callback_t) blade_rpc_request_callback_get(blade_rpc_request_t *brpcreq);
|
||||
KS_DECLARE(void *) blade_rpc_request_callback_data_get(blade_rpc_request_t *brpcreq);
|
||||
KS_DECLARE(void *) blade_rpc_request_data_get(blade_rpc_request_t *brpcreq);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_rpc_request_raw_create(ks_pool_t *pool, cJSON **json, cJSON **params, const char **id, const char *method);
|
||||
|
||||
|
|
|
@ -59,25 +59,25 @@ KS_DECLARE(blade_sessionmgr_t *) blade_handle_sessionmgr_get(blade_handle_t *bh)
|
|||
|
||||
KS_DECLARE(ks_status_t) blade_handle_connect(blade_handle_t *bh, blade_connection_t **bcP, blade_identity_t *target, const char *session_id);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_protocol_register(blade_handle_t *bh, const char *nodeid, ks_bool_t remove, blade_rpc_response_callback_t callback, void *data);
|
||||
KS_DECLARE(ks_status_t) blade_handle_rpcregister(blade_handle_t *bh, const char *nodeid, ks_bool_t remove, blade_rpc_response_callback_t callback, void *data);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_protocol_publish(blade_handle_t *bh, const char *name, const char *realm, blade_rpc_response_callback_t callback, void *data);
|
||||
KS_DECLARE(ks_status_t) blade_handle_rpcpublish(blade_handle_t *bh, const char *name, const char *realm, blade_rpc_response_callback_t callback, void *data);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_protocol_locate(blade_handle_t *bh, const char *name, const char *realm, blade_rpc_response_callback_t callback, void *data);
|
||||
KS_DECLARE(ks_status_t) blade_handle_rpclocate(blade_handle_t *bh, const char *name, const char *realm, blade_rpc_response_callback_t callback, void *data);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_protocol_execute(blade_handle_t *bh, const char *nodeid, const char *method, const char *protocol, const char *realm, cJSON *params, blade_rpc_response_callback_t callback, void *data);
|
||||
KS_DECLARE(const char *) blade_protocol_execute_request_requester_nodeid_get(blade_rpc_request_t *brpcreq);
|
||||
KS_DECLARE(const char *) blade_protocol_execute_request_responder_nodeid_get(blade_rpc_request_t *brpcreq);
|
||||
KS_DECLARE(cJSON *) blade_protocol_execute_request_params_get(blade_rpc_request_t *brpcreq);
|
||||
KS_DECLARE(cJSON *) blade_protocol_execute_response_result_get(blade_rpc_response_t *brpcres);
|
||||
KS_DECLARE(void) blade_protocol_execute_response_send(blade_rpc_request_t *brpcreq, cJSON *result);
|
||||
KS_DECLARE(ks_status_t) blade_handle_rpcexecute(blade_handle_t *bh, const char *nodeid, const char *method, const char *protocol, const char *realm, cJSON *params, blade_rpc_response_callback_t callback, void *data);
|
||||
KS_DECLARE(const char *) blade_rpcexecute_request_requester_nodeid_get(blade_rpc_request_t *brpcreq);
|
||||
KS_DECLARE(const char *) blade_rpcexecute_request_responder_nodeid_get(blade_rpc_request_t *brpcreq);
|
||||
KS_DECLARE(cJSON *) blade_rpcexecute_request_params_get(blade_rpc_request_t *brpcreq);
|
||||
KS_DECLARE(cJSON *) blade_rpcexecute_response_result_get(blade_rpc_response_t *brpcres);
|
||||
KS_DECLARE(void) blade_rpcexecute_response_send(blade_rpc_request_t *brpcreq, cJSON *result);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_protocol_subscribe(blade_handle_t *bh, const char *event, const char *protocol, const char *realm, ks_bool_t remove, blade_rpc_response_callback_t callback, void *data, blade_rpc_request_callback_t event_callback, void *event_data);
|
||||
KS_DECLARE(ks_status_t) blade_protocol_subscribe_raw(blade_handle_t *bh, const char *event, const char *protocol, const char *realm, ks_bool_t remove, blade_rpc_response_callback_t callback, void *data);
|
||||
KS_DECLARE(ks_status_t) blade_handle_rpcsubscribe(blade_handle_t *bh, const char *event, const char *protocol, const char *realm, ks_bool_t remove, blade_rpc_response_callback_t callback, void *data, blade_rpc_request_callback_t event_callback, void *event_data);
|
||||
KS_DECLARE(ks_status_t) blade_handle_rpcsubscribe_raw(blade_handle_t *bh, const char *event, const char *protocol, const char *realm, ks_bool_t remove, blade_rpc_response_callback_t callback, void *data);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_protocol_broadcast(blade_handle_t *bh, const char *broadcaster_nodeid, const char *event, const char *protocol, const char *realm, cJSON *params, blade_rpc_response_callback_t callback, void *data);
|
||||
KS_DECLARE(const char *) blade_protocol_broadcast_request_broadcaster_nodeid_get(blade_rpc_request_t *brpcreq);
|
||||
KS_DECLARE(cJSON *) blade_protocol_broadcast_request_params_get(blade_rpc_request_t *brpcreq);
|
||||
KS_DECLARE(ks_status_t) blade_handle_rpcbroadcast(blade_handle_t *bh, const char *broadcaster_nodeid, const char *event, const char *protocol, const char *realm, cJSON *params, blade_rpc_response_callback_t callback, void *data);
|
||||
KS_DECLARE(const char *) blade_rpcbroadcast_request_broadcaster_nodeid_get(blade_rpc_request_t *brpcreq);
|
||||
KS_DECLARE(cJSON *) blade_rpcbroadcast_request_params_get(blade_rpc_request_t *brpcreq);
|
||||
|
||||
KS_END_EXTERN_C
|
||||
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (c) 2017, Shane Bryldt
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _BLADE_TUPLE_H_
|
||||
#define _BLADE_TUPLE_H_
|
||||
#include <blade.h>
|
||||
|
||||
KS_BEGIN_EXTERN_C
|
||||
KS_DECLARE(ks_status_t) blade_tuple_create(blade_tuple_t **btP, ks_pool_t *pool, void *value1, void *value2);
|
||||
KS_DECLARE(ks_status_t) blade_tuple_destroy(blade_tuple_t **btP);
|
||||
KS_DECLARE(void *) blade_tuple_value1_get(blade_tuple_t *bt);
|
||||
KS_DECLARE(void *) blade_tuple_value2_get(blade_tuple_t *bt);
|
||||
KS_END_EXTERN_C
|
||||
|
||||
#endif
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
* indent-tabs-mode:t
|
||||
* tab-width:4
|
||||
* c-basic-offset:4
|
||||
* End:
|
||||
* For VIM:
|
||||
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
|
||||
*/
|
|
@ -50,6 +50,7 @@ typedef struct blade_session_s blade_session_t;
|
|||
typedef struct blade_session_callbacks_s blade_session_callbacks_t;
|
||||
typedef struct blade_protocol_s blade_protocol_t;
|
||||
typedef struct blade_subscription_s blade_subscription_t;
|
||||
typedef struct blade_tuple_s blade_tuple_t;
|
||||
|
||||
typedef struct blade_transportmgr_s blade_transportmgr_t;
|
||||
typedef struct blade_rpcmgr_s blade_rpcmgr_t;
|
||||
|
|
|
@ -42,7 +42,7 @@ ks_bool_t test_echo_response_handler(blade_rpc_response_t *brpcres, void *data)
|
|||
bs = blade_sessionmgr_session_lookup(blade_handle_sessionmgr_get(bh), blade_rpc_response_sessionid_get(brpcres));
|
||||
ks_assert(bs);
|
||||
|
||||
result = blade_protocol_execute_response_result_get(brpcres);
|
||||
result = blade_rpcexecute_response_result_get(brpcres);
|
||||
ks_assert(result);
|
||||
|
||||
text = cJSON_GetObjectCstr(result, "text");
|
||||
|
@ -106,7 +106,7 @@ ks_bool_t blade_locate_response_handler(blade_rpc_response_t *brpcres, void *dat
|
|||
|
||||
params = cJSON_CreateObject();
|
||||
cJSON_AddStringToObject(params, "text", "hello world!");
|
||||
blade_protocol_execute(bh, nodeid, "test.echo", res_result_protocol, res_result_realm, params, test_echo_response_handler, NULL);
|
||||
blade_handle_rpcexecute(bh, nodeid, "test.echo", res_result_protocol, res_result_realm, params, test_echo_response_handler, NULL);
|
||||
|
||||
return KS_FALSE;
|
||||
}
|
||||
|
@ -285,7 +285,7 @@ void command_execute(blade_handle_t *bh, char *args)
|
|||
ks_assert(bh);
|
||||
ks_assert(args);
|
||||
|
||||
blade_protocol_locate(bh, "test", "mydomain.com", blade_locate_response_handler, NULL);
|
||||
blade_handle_rpclocate(bh, "test", "mydomain.com", blade_locate_response_handler, NULL);
|
||||
}
|
||||
|
||||
void command_subscribe(blade_handle_t *bh, char *args)
|
||||
|
@ -293,7 +293,7 @@ void command_subscribe(blade_handle_t *bh, char *args)
|
|||
ks_assert(bh);
|
||||
ks_assert(args);
|
||||
|
||||
blade_protocol_subscribe(bh, "test.event", "test", "mydomain.com", KS_FALSE, blade_subscribe_response_handler, NULL, test_event_request_handler, NULL);
|
||||
blade_handle_rpcsubscribe(bh, "test.event", "test", "mydomain.com", KS_FALSE, blade_subscribe_response_handler, NULL, test_event_request_handler, NULL);
|
||||
}
|
||||
|
||||
/* For Emacs:
|
||||
|
|
|
@ -66,7 +66,7 @@ ks_bool_t test_echo_request_handler(blade_rpc_request_t *brpcreq, void *data)
|
|||
ks_assert(bs);
|
||||
|
||||
// @todo get the inner parameters of a blade.execute request for protocolrpcs
|
||||
params = blade_protocol_execute_request_params_get(brpcreq);
|
||||
params = blade_rpcexecute_request_params_get(brpcreq);
|
||||
ks_assert(params);
|
||||
|
||||
text = cJSON_GetObjectCstr(params, "text");
|
||||
|
@ -80,7 +80,7 @@ ks_bool_t test_echo_request_handler(blade_rpc_request_t *brpcreq, void *data)
|
|||
result = cJSON_CreateObject();
|
||||
cJSON_AddStringToObject(result, "text", text);
|
||||
|
||||
blade_protocol_execute_response_send(brpcreq, result);
|
||||
blade_rpcexecute_response_send(brpcreq, result);
|
||||
|
||||
return KS_FALSE;
|
||||
}
|
||||
|
@ -242,8 +242,8 @@ void command_publish(blade_handle_t *bh, char *args)
|
|||
blade_rpc_create(&brpc, bh, "test.echo", "test", "mydomain.com", test_echo_request_handler, NULL);
|
||||
blade_rpcmgr_protocolrpc_add(blade_handle_rpcmgr_get(bh), brpc);
|
||||
|
||||
// @todo build up json-based method schema for each protocolrpc registered above, and pass into blade_protocol_publish() to attach to the request, to be stored in the blade_protocol_t tracked by the master node
|
||||
blade_protocol_publish(bh, "test", "mydomain.com", blade_publish_response_handler, NULL);
|
||||
// @todo build up json-based method schema for each protocolrpc registered above, and pass into blade_handle_rpcpublish() to attach to the request, to be stored in the blade_protocol_t tracked by the master node
|
||||
blade_handle_rpcpublish(bh, "test", "mydomain.com", blade_publish_response_handler, NULL);
|
||||
}
|
||||
|
||||
void command_broadcast(blade_handle_t *bh, char *args)
|
||||
|
@ -251,7 +251,7 @@ void command_broadcast(blade_handle_t *bh, char *args)
|
|||
ks_assert(bh);
|
||||
ks_assert(args);
|
||||
|
||||
blade_protocol_broadcast(bh, NULL, "test.event", "test", "mydomain.com", NULL, test_event_response_handler, NULL);
|
||||
blade_handle_rpcbroadcast(bh, NULL, "test.event", "test", "mydomain.com", NULL, test_event_response_handler, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ ks_bool_t test_join_response_handler(blade_rpc_response_t *brpcres, void *data)
|
|||
bs = blade_sessionmgr_session_lookup(blade_handle_sessionmgr_get(bh), blade_rpc_response_sessionid_get(brpcres));
|
||||
ks_assert(bs);
|
||||
|
||||
result = blade_protocol_execute_response_result_get(brpcres);
|
||||
result = blade_rpcexecute_response_result_get(brpcres);
|
||||
ks_assert(result);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) test.join response processing\n", blade_session_id_get(bs));
|
||||
|
@ -125,7 +125,7 @@ ks_bool_t test_leave_response_handler(blade_rpc_response_t *brpcres, void *data)
|
|||
bs = blade_sessionmgr_session_lookup(blade_handle_sessionmgr_get(bh), blade_rpc_response_sessionid_get(brpcres));
|
||||
ks_assert(bs);
|
||||
|
||||
result = blade_protocol_execute_response_result_get(brpcres);
|
||||
result = blade_rpcexecute_response_result_get(brpcres);
|
||||
ks_assert(result);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) test.leave response processing\n", blade_session_id_get(bs));
|
||||
|
@ -149,7 +149,7 @@ ks_bool_t test_talk_response_handler(blade_rpc_response_t *brpcres, void *data)
|
|||
bs = blade_sessionmgr_session_lookup(blade_handle_sessionmgr_get(bh), blade_rpc_response_sessionid_get(brpcres));
|
||||
ks_assert(bs);
|
||||
|
||||
result = blade_protocol_execute_response_result_get(brpcres);
|
||||
result = blade_rpcexecute_response_result_get(brpcres);
|
||||
ks_assert(result);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) test.talk response processing\n", blade_session_id_get(bs));
|
||||
|
@ -175,10 +175,10 @@ ks_bool_t test_join_broadcast_handler(blade_rpc_request_t *brpcreq, void *data)
|
|||
bs = blade_sessionmgr_session_lookup(blade_handle_sessionmgr_get(bh), blade_rpc_request_sessionid_get(brpcreq));
|
||||
ks_assert(bs);
|
||||
|
||||
params = blade_protocol_broadcast_request_params_get(brpcreq);
|
||||
params = blade_rpcbroadcast_request_params_get(brpcreq);
|
||||
ks_assert(params);
|
||||
|
||||
broadcaster_nodeid = blade_protocol_broadcast_request_broadcaster_nodeid_get(brpcreq);
|
||||
broadcaster_nodeid = blade_rpcbroadcast_request_broadcaster_nodeid_get(brpcreq);
|
||||
ks_assert(broadcaster_nodeid);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) test.join (%s) broadcast processing\n", blade_session_id_get(bs), broadcaster_nodeid);
|
||||
|
@ -204,10 +204,10 @@ ks_bool_t test_leave_broadcast_handler(blade_rpc_request_t *brpcreq, void *data)
|
|||
bs = blade_sessionmgr_session_lookup(blade_handle_sessionmgr_get(bh), blade_rpc_request_sessionid_get(brpcreq));
|
||||
ks_assert(bs);
|
||||
|
||||
params = blade_protocol_broadcast_request_params_get(brpcreq);
|
||||
params = blade_rpcbroadcast_request_params_get(brpcreq);
|
||||
ks_assert(params);
|
||||
|
||||
broadcaster_nodeid = blade_protocol_broadcast_request_broadcaster_nodeid_get(brpcreq);
|
||||
broadcaster_nodeid = blade_rpcbroadcast_request_broadcaster_nodeid_get(brpcreq);
|
||||
ks_assert(broadcaster_nodeid);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) test.leave (%s) broadcast processing\n", blade_session_id_get(bs), broadcaster_nodeid);
|
||||
|
@ -233,10 +233,10 @@ ks_bool_t test_talk_broadcast_handler(blade_rpc_request_t *brpcreq, void *data)
|
|||
bs = blade_sessionmgr_session_lookup(blade_handle_sessionmgr_get(bh), blade_rpc_request_sessionid_get(brpcreq));
|
||||
ks_assert(bs);
|
||||
|
||||
broadcaster_nodeid = blade_protocol_broadcast_request_broadcaster_nodeid_get(brpcreq);
|
||||
broadcaster_nodeid = blade_rpcbroadcast_request_broadcaster_nodeid_get(brpcreq);
|
||||
ks_assert(broadcaster_nodeid);
|
||||
|
||||
params = blade_protocol_broadcast_request_params_get(brpcreq);
|
||||
params = blade_rpcbroadcast_request_params_get(brpcreq);
|
||||
ks_assert(params);
|
||||
|
||||
// @todo pull out text from params
|
||||
|
@ -385,7 +385,7 @@ void command_locate(blade_handle_t *bh, char *args)
|
|||
ks_assert(bh);
|
||||
ks_assert(args);
|
||||
|
||||
blade_protocol_locate(bh, "test", "mydomain.com", test_locate_response_handler, NULL);
|
||||
blade_handle_rpclocate(bh, "test", "mydomain.com", test_locate_response_handler, NULL);
|
||||
}
|
||||
|
||||
void command_join(blade_handle_t *bh, char *args)
|
||||
|
@ -403,11 +403,11 @@ void command_join(blade_handle_t *bh, char *args)
|
|||
|
||||
params = cJSON_CreateObject();
|
||||
|
||||
blade_protocol_execute(bh, g_testcon_nodeid, "test.join", "test", "mydomain.com", params, test_join_response_handler, NULL);
|
||||
blade_handle_rpcexecute(bh, g_testcon_nodeid, "test.join", "test", "mydomain.com", params, test_join_response_handler, NULL);
|
||||
|
||||
blade_protocol_subscribe(bh, "test.join", "test", "mydomain.com", KS_FALSE, NULL, NULL, test_join_broadcast_handler, NULL);
|
||||
blade_protocol_subscribe(bh, "test.leave", "test", "mydomain.com", KS_FALSE, NULL, NULL, test_leave_broadcast_handler, NULL);
|
||||
blade_protocol_subscribe(bh, "test.talk", "test", "mydomain.com", KS_FALSE, NULL, NULL, test_talk_broadcast_handler, NULL);
|
||||
blade_handle_rpcsubscribe(bh, "test.join", "test", "mydomain.com", KS_FALSE, NULL, NULL, test_join_broadcast_handler, NULL);
|
||||
blade_handle_rpcsubscribe(bh, "test.leave", "test", "mydomain.com", KS_FALSE, NULL, NULL, test_leave_broadcast_handler, NULL);
|
||||
blade_handle_rpcsubscribe(bh, "test.talk", "test", "mydomain.com", KS_FALSE, NULL, NULL, test_talk_broadcast_handler, NULL);
|
||||
}
|
||||
|
||||
void command_leave(blade_handle_t *bh, char *args)
|
||||
|
@ -424,11 +424,11 @@ void command_leave(blade_handle_t *bh, char *args)
|
|||
|
||||
params = cJSON_CreateObject();
|
||||
|
||||
blade_protocol_execute(bh, g_testcon_nodeid, "test.leave", "test", "mydomain.com", params, test_leave_response_handler, NULL);
|
||||
blade_handle_rpcexecute(bh, g_testcon_nodeid, "test.leave", "test", "mydomain.com", params, test_leave_response_handler, NULL);
|
||||
|
||||
blade_protocol_subscribe(bh, "test.join", "test", "mydomain.com", KS_TRUE, NULL, NULL, NULL, NULL);
|
||||
blade_protocol_subscribe(bh, "test.leave", "test", "mydomain.com", KS_TRUE, NULL, NULL, NULL, NULL);
|
||||
blade_protocol_subscribe(bh, "test.talk", "test", "mydomain.com", KS_TRUE, NULL, NULL, NULL, NULL);
|
||||
blade_handle_rpcsubscribe(bh, "test.join", "test", "mydomain.com", KS_TRUE, NULL, NULL, NULL, NULL);
|
||||
blade_handle_rpcsubscribe(bh, "test.leave", "test", "mydomain.com", KS_TRUE, NULL, NULL, NULL, NULL);
|
||||
blade_handle_rpcsubscribe(bh, "test.talk", "test", "mydomain.com", KS_TRUE, NULL, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
void command_talk(blade_handle_t *bh, char *args)
|
||||
|
@ -451,7 +451,7 @@ void command_talk(blade_handle_t *bh, char *args)
|
|||
|
||||
cJSON_AddStringToObject(params, "text", args);
|
||||
|
||||
blade_protocol_execute(bh, g_testcon_nodeid, "test.talk", "test", "mydomain.com", params, test_talk_response_handler, NULL);
|
||||
blade_handle_rpcexecute(bh, g_testcon_nodeid, "test.talk", "test", "mydomain.com", params, test_talk_response_handler, NULL);
|
||||
}
|
||||
|
||||
/* For Emacs:
|
||||
|
|
|
@ -133,10 +133,10 @@ ks_bool_t test_join_request_handler(blade_rpc_request_t *brpcreq, void *data)
|
|||
bs = blade_sessionmgr_session_lookup(blade_handle_sessionmgr_get(bh), blade_rpc_request_sessionid_get(brpcreq));
|
||||
ks_assert(bs);
|
||||
|
||||
requester_nodeid = blade_protocol_execute_request_requester_nodeid_get(brpcreq);
|
||||
requester_nodeid = blade_rpcexecute_request_requester_nodeid_get(brpcreq);
|
||||
ks_assert(requester_nodeid);
|
||||
|
||||
params = blade_protocol_execute_request_params_get(brpcreq);
|
||||
params = blade_rpcexecute_request_params_get(brpcreq);
|
||||
ks_assert(params);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) test.join request processing\n", blade_session_id_get(bs));
|
||||
|
@ -152,11 +152,11 @@ ks_bool_t test_join_request_handler(blade_rpc_request_t *brpcreq, void *data)
|
|||
|
||||
result = cJSON_CreateObject();
|
||||
|
||||
blade_protocol_execute_response_send(brpcreq, result);
|
||||
blade_rpcexecute_response_send(brpcreq, result);
|
||||
|
||||
params = cJSON_CreateObject();
|
||||
|
||||
blade_protocol_broadcast(bh, requester_nodeid, "test.join", "test", "mydomain.com", params, NULL, NULL);
|
||||
blade_handle_rpcbroadcast(bh, requester_nodeid, "test.join", "test", "mydomain.com", params, NULL, NULL);
|
||||
|
||||
return KS_FALSE;
|
||||
}
|
||||
|
@ -182,10 +182,10 @@ ks_bool_t test_leave_request_handler(blade_rpc_request_t *brpcreq, void *data)
|
|||
bs = blade_sessionmgr_session_lookup(blade_handle_sessionmgr_get(bh), blade_rpc_request_sessionid_get(brpcreq));
|
||||
ks_assert(bs);
|
||||
|
||||
requester_nodeid = blade_protocol_execute_request_requester_nodeid_get(brpcreq);
|
||||
requester_nodeid = blade_rpcexecute_request_requester_nodeid_get(brpcreq);
|
||||
ks_assert(requester_nodeid);
|
||||
|
||||
params = blade_protocol_execute_request_params_get(brpcreq);
|
||||
params = blade_rpcexecute_request_params_get(brpcreq);
|
||||
ks_assert(params);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) test.leave (%s) request processing\n", blade_session_id_get(bs), requester_nodeid);
|
||||
|
@ -198,11 +198,11 @@ ks_bool_t test_leave_request_handler(blade_rpc_request_t *brpcreq, void *data)
|
|||
|
||||
result = cJSON_CreateObject();
|
||||
|
||||
blade_protocol_execute_response_send(brpcreq, result);
|
||||
blade_rpcexecute_response_send(brpcreq, result);
|
||||
|
||||
params = cJSON_CreateObject();
|
||||
|
||||
blade_protocol_broadcast(bh, requester_nodeid, "test.leave", "test", "mydomain.com", params, NULL, NULL);
|
||||
blade_handle_rpcbroadcast(bh, requester_nodeid, "test.leave", "test", "mydomain.com", params, NULL, NULL);
|
||||
|
||||
return KS_FALSE;
|
||||
}
|
||||
|
@ -228,10 +228,10 @@ ks_bool_t test_talk_request_handler(blade_rpc_request_t *brpcreq, void *data)
|
|||
bs = blade_sessionmgr_session_lookup(blade_handle_sessionmgr_get(bh), blade_rpc_request_sessionid_get(brpcreq));
|
||||
ks_assert(bs);
|
||||
|
||||
requester_nodeid = blade_protocol_execute_request_requester_nodeid_get(brpcreq);
|
||||
requester_nodeid = blade_rpcexecute_request_requester_nodeid_get(brpcreq);
|
||||
ks_assert(requester_nodeid);
|
||||
|
||||
params = blade_protocol_execute_request_params_get(brpcreq);
|
||||
params = blade_rpcexecute_request_params_get(brpcreq);
|
||||
ks_assert(params);
|
||||
|
||||
text = cJSON_GetObjectCstr(params, "text");
|
||||
|
@ -243,13 +243,13 @@ ks_bool_t test_talk_request_handler(blade_rpc_request_t *brpcreq, void *data)
|
|||
|
||||
result = cJSON_CreateObject();
|
||||
|
||||
blade_protocol_execute_response_send(brpcreq, result);
|
||||
blade_rpcexecute_response_send(brpcreq, result);
|
||||
|
||||
params = cJSON_CreateObject();
|
||||
|
||||
cJSON_AddStringToObject(params, "text", text);
|
||||
|
||||
blade_protocol_broadcast(bh, requester_nodeid, "test.talk", "test", "mydomain.com", params, NULL, NULL);
|
||||
blade_handle_rpcbroadcast(bh, requester_nodeid, "test.talk", "test", "mydomain.com", params, NULL, NULL);
|
||||
|
||||
return KS_FALSE;
|
||||
}
|
||||
|
@ -326,7 +326,7 @@ int main(int argc, char **argv)
|
|||
blade_rpc_create(&brpc, bh, "test.talk", "test", "mydomain.com", test_talk_request_handler, test);
|
||||
blade_rpcmgr_protocolrpc_add(blade_handle_rpcmgr_get(bh), brpc);
|
||||
|
||||
blade_protocol_publish(bh, "test", "mydomain.com", test_publish_response_handler, test);
|
||||
blade_handle_rpcpublish(bh, "test", "mydomain.com", test_publish_response_handler, test);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue