mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-11-02 01:25:11 +00:00
FS-10167: More work on the event channel workflow, switched callback data back to using void* and the assumption callback will clear the data or that it would be cleaned up by a handle shutdown by allocating within the handle pool. Base tests currently working, committing to sync up linux build
This commit is contained in:
1 parent
4c29e4d630
commit
fd3348cafc
11 files changed
+232
-129
No files matched your search
@@ -18,6 +18,8 @@ struct command_def_s {
|
||||
void command_quit(blade_handle_t *bh, char *args);
|
||||
void command_locate(blade_handle_t *bh, char *args);
|
||||
void command_join(blade_handle_t *bh, char *args);
|
||||
void command_subscribe(blade_handle_t *bh, char *args);
|
||||
void command_unsubscribe(blade_handle_t *bh, char *args);
|
||||
void command_leave(blade_handle_t *bh, char *args);
|
||||
void command_talk(blade_handle_t *bh, char *args);
|
||||
|
||||
@@ -25,6 +27,8 @@ static const struct command_def_s command_defs[] = {
|
||||
{ "quit", command_quit },
|
||||
{ "locate", command_locate },
|
||||
{ "join", command_join },
|
||||
{ "subscribe", command_subscribe },
|
||||
{ "unsubscribe", command_unsubscribe },
|
||||
{ "leave", command_leave },
|
||||
{ "talk", command_talk },
|
||||
|
||||
@@ -33,7 +37,7 @@ static const struct command_def_s command_defs[] = {
|
||||
|
||||
const char *g_testcon_nodeid = NULL;
|
||||
|
||||
ks_bool_t test_locate_response_handler(blade_rpc_response_t *brpcres, cJSON *data)
|
||||
ks_bool_t test_locate_response_handler(blade_rpc_response_t *brpcres, void *data)
|
||||
{
|
||||
blade_handle_t *bh = NULL;
|
||||
blade_session_t *bs = NULL;
|
||||
@@ -87,7 +91,7 @@ ks_bool_t test_locate_response_handler(blade_rpc_response_t *brpcres, cJSON *dat
|
||||
return KS_FALSE;
|
||||
}
|
||||
|
||||
ks_bool_t test_join_response_handler(blade_rpc_response_t *brpcres, cJSON *data)
|
||||
ks_bool_t test_join_response_handler(blade_rpc_response_t *brpcres, void *data)
|
||||
{
|
||||
blade_handle_t *bh = NULL;
|
||||
blade_session_t *bs = NULL;
|
||||
@@ -111,7 +115,7 @@ ks_bool_t test_join_response_handler(blade_rpc_response_t *brpcres, cJSON *data)
|
||||
return KS_FALSE;
|
||||
}
|
||||
|
||||
ks_bool_t test_leave_response_handler(blade_rpc_response_t *brpcres, cJSON *data)
|
||||
ks_bool_t test_leave_response_handler(blade_rpc_response_t *brpcres, void *data)
|
||||
{
|
||||
blade_handle_t *bh = NULL;
|
||||
blade_session_t *bs = NULL;
|
||||
@@ -135,7 +139,7 @@ ks_bool_t test_leave_response_handler(blade_rpc_response_t *brpcres, cJSON *data
|
||||
return KS_FALSE;
|
||||
}
|
||||
|
||||
ks_bool_t test_talk_response_handler(blade_rpc_response_t *brpcres, cJSON *data)
|
||||
ks_bool_t test_talk_response_handler(blade_rpc_response_t *brpcres, void *data)
|
||||
{
|
||||
blade_handle_t *bh = NULL;
|
||||
blade_session_t *bs = NULL;
|
||||
@@ -159,7 +163,35 @@ ks_bool_t test_talk_response_handler(blade_rpc_response_t *brpcres, cJSON *data)
|
||||
return KS_FALSE;
|
||||
}
|
||||
|
||||
ks_bool_t test_broadcast_handler(blade_rpc_request_t *brpcreq, cJSON *data)
|
||||
ks_bool_t test_subscribe_response_handler(blade_rpc_response_t *brpcres, void *data)
|
||||
{
|
||||
blade_handle_t *bh = NULL;
|
||||
blade_session_t *bs = NULL;
|
||||
cJSON *res = NULL;
|
||||
cJSON *res_result = NULL;
|
||||
|
||||
ks_assert(brpcres);
|
||||
|
||||
bh = blade_rpc_response_handle_get(brpcres);
|
||||
ks_assert(bh);
|
||||
|
||||
bs = blade_sessionmgr_session_lookup(blade_handle_sessionmgr_get(bh), blade_rpc_response_sessionid_get(brpcres));
|
||||
ks_assert(bs);
|
||||
|
||||
res = blade_rpc_response_message_get(brpcres);
|
||||
ks_assert(res);
|
||||
|
||||
res_result = cJSON_GetObjectItem(res, "result");
|
||||
ks_assert(res_result);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) blade.subscribe response processing\n", blade_session_id_get(bs));
|
||||
|
||||
blade_session_read_unlock(bs);
|
||||
|
||||
return KS_FALSE;
|
||||
}
|
||||
|
||||
ks_bool_t test_channel_handler(blade_rpc_request_t *brpcreq, void *data)
|
||||
{
|
||||
blade_handle_t *bh = NULL;
|
||||
blade_session_t *bs = NULL;
|
||||
@@ -177,7 +209,7 @@ ks_bool_t test_broadcast_handler(blade_rpc_request_t *brpcreq, cJSON *data)
|
||||
params = blade_rpcbroadcast_request_params_get(brpcreq);
|
||||
ks_assert(params);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) test broadcast processing\n", blade_session_id_get(bs));
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) test channel event processing\n", blade_session_id_get(bs));
|
||||
|
||||
blade_session_read_unlock(bs);
|
||||
|
||||
@@ -327,7 +359,6 @@ void command_locate(blade_handle_t *bh, char *args)
|
||||
void command_join(blade_handle_t *bh, char *args)
|
||||
{
|
||||
cJSON *params = NULL;
|
||||
cJSON *channels = NULL;
|
||||
|
||||
ks_assert(bh);
|
||||
ks_assert(args);
|
||||
@@ -337,14 +368,38 @@ void command_join(blade_handle_t *bh, char *args)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
params = cJSON_CreateObject();
|
||||
blade_handle_rpcexecute(bh, g_testcon_nodeid, "test.join", "test", "mydomain.com", params, test_join_response_handler, NULL);
|
||||
cJSON_Delete(params);
|
||||
}
|
||||
|
||||
void command_subscribe(blade_handle_t *bh, char *args)
|
||||
{
|
||||
cJSON *channels = NULL;
|
||||
|
||||
if (!g_testcon_nodeid) {
|
||||
ks_log(KS_LOG_DEBUG, "Protocol controller has not been located\n");
|
||||
return;
|
||||
}
|
||||
|
||||
channels = cJSON_CreateArray();
|
||||
cJSON_AddItemToArray(channels, cJSON_CreateString("test"));
|
||||
blade_handle_rpcsubscribe(bh, "test", "mydomain.com", channels, NULL, NULL, NULL, test_broadcast_handler, NULL);
|
||||
cJSON_AddItemToArray(channels, cJSON_CreateString("channel"));
|
||||
blade_handle_rpcsubscribe(bh, "test", "mydomain.com", channels, NULL, NULL, NULL, test_channel_handler, NULL);
|
||||
cJSON_Delete(channels);
|
||||
}
|
||||
|
||||
void command_unsubscribe(blade_handle_t *bh, char *args)
|
||||
{
|
||||
cJSON *channels = NULL;
|
||||
|
||||
if (!g_testcon_nodeid) {
|
||||
ks_log(KS_LOG_DEBUG, "Protocol controller has not been located\n");
|
||||
return;
|
||||
}
|
||||
|
||||
channels = cJSON_CreateArray();
|
||||
cJSON_AddItemToArray(channels, cJSON_CreateString("channel"));
|
||||
blade_handle_rpcsubscribe(bh, "test", "mydomain.com", NULL, channels, test_subscribe_response_handler, NULL, test_channel_handler, NULL);
|
||||
cJSON_Delete(channels);
|
||||
}
|
||||
|
||||
@@ -364,11 +419,6 @@ void command_leave(blade_handle_t *bh, char *args)
|
||||
params = cJSON_CreateObject();
|
||||
blade_handle_rpcexecute(bh, g_testcon_nodeid, "test.leave", "test", "mydomain.com", params, test_leave_response_handler, NULL);
|
||||
cJSON_Delete(params);
|
||||
|
||||
channels = cJSON_CreateArray();
|
||||
cJSON_AddItemToArray(channels, cJSON_CreateString("test"));
|
||||
blade_handle_rpcsubscribe(bh, "test", "mydomain.com", NULL, channels, NULL, NULL, NULL, NULL);
|
||||
cJSON_Delete(channels);
|
||||
}
|
||||
|
||||
void command_talk(blade_handle_t *bh, char *args)
|
||||
|
||||
@@ -88,7 +88,7 @@ ks_status_t testproto_destroy(testproto_t **testP)
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
ks_bool_t test_publish_response_handler(blade_rpc_response_t *brpcres, cJSON *data)
|
||||
ks_bool_t test_publish_response_handler(blade_rpc_response_t *brpcres, void *data)
|
||||
{
|
||||
//testproto_t *test = NULL;
|
||||
blade_handle_t *bh = NULL;
|
||||
@@ -97,7 +97,7 @@ ks_bool_t test_publish_response_handler(blade_rpc_response_t *brpcres, cJSON *da
|
||||
ks_assert(brpcres);
|
||||
ks_assert(data);
|
||||
|
||||
//test = (testproto_t *)cJSON_GetPtrValue(data);
|
||||
//test = (testproto_t *)data;
|
||||
|
||||
bh = blade_rpc_response_handle_get(brpcres);
|
||||
ks_assert(bh);
|
||||
@@ -112,7 +112,7 @@ ks_bool_t test_publish_response_handler(blade_rpc_response_t *brpcres, cJSON *da
|
||||
return KS_FALSE;
|
||||
}
|
||||
|
||||
ks_bool_t test_join_request_handler(blade_rpc_request_t *brpcreq, cJSON *data)
|
||||
ks_bool_t test_join_request_handler(blade_rpc_request_t *brpcreq, void *data)
|
||||
{
|
||||
testproto_t *test = NULL;
|
||||
blade_handle_t *bh = NULL;
|
||||
@@ -126,7 +126,7 @@ ks_bool_t test_join_request_handler(blade_rpc_request_t *brpcreq, cJSON *data)
|
||||
ks_assert(brpcreq);
|
||||
ks_assert(data);
|
||||
|
||||
test = (testproto_t *)cJSON_GetPtrValue(data);
|
||||
test = (testproto_t *)data;
|
||||
|
||||
bh = blade_rpc_request_handle_get(brpcreq);
|
||||
ks_assert(bh);
|
||||
@@ -183,7 +183,7 @@ ks_bool_t test_join_request_handler(blade_rpc_request_t *brpcreq, cJSON *data)
|
||||
return KS_FALSE;
|
||||
}
|
||||
|
||||
ks_bool_t test_leave_request_handler(blade_rpc_request_t *brpcreq, cJSON *data)
|
||||
ks_bool_t test_leave_request_handler(blade_rpc_request_t *brpcreq, void *data)
|
||||
{
|
||||
testproto_t *test = NULL;
|
||||
blade_handle_t *bh = NULL;
|
||||
@@ -191,12 +191,13 @@ ks_bool_t test_leave_request_handler(blade_rpc_request_t *brpcreq, cJSON *data)
|
||||
const char *requester_nodeid = NULL;
|
||||
//const char *key = NULL;
|
||||
cJSON *params = NULL;
|
||||
cJSON *channels = NULL;
|
||||
cJSON *result = NULL;
|
||||
|
||||
ks_assert(brpcreq);
|
||||
ks_assert(data);
|
||||
|
||||
test = (testproto_t *)cJSON_GetPtrValue(data);
|
||||
test = (testproto_t *)data;
|
||||
|
||||
bh = blade_rpc_request_handle_get(brpcreq);
|
||||
ks_assert(bh);
|
||||
@@ -216,22 +217,36 @@ ks_bool_t test_leave_request_handler(blade_rpc_request_t *brpcreq, cJSON *data)
|
||||
ks_hash_remove(test->participants, (void *)requester_nodeid);
|
||||
ks_hash_write_unlock(test->participants);
|
||||
|
||||
blade_session_read_unlock(bs);
|
||||
// deauthorize channels with the master for the requester
|
||||
channels = cJSON_CreateArray();
|
||||
cJSON_AddItemToArray(channels, cJSON_CreateString("channel"));
|
||||
|
||||
blade_handle_rpcauthorize(bh, requester_nodeid, KS_TRUE, "test", "mydomain.com", channels, NULL, NULL);
|
||||
|
||||
cJSON_Delete(channels);
|
||||
|
||||
// send rpcexecute response to the requester
|
||||
result = cJSON_CreateObject();
|
||||
|
||||
blade_rpcexecute_response_send(brpcreq, result);
|
||||
|
||||
cJSON_Delete(result);
|
||||
|
||||
blade_session_read_unlock(bs);
|
||||
|
||||
// broadcast to authorized nodes that have subscribed, that the requester has left
|
||||
params = cJSON_CreateObject();
|
||||
|
||||
cJSON_AddStringToObject(params, "leaver-nodeid", requester_nodeid);
|
||||
|
||||
blade_handle_rpcbroadcast(bh, "test", "mydomain.com", "channel", "leave", params, NULL, NULL);
|
||||
|
||||
cJSON_Delete(params);
|
||||
|
||||
return KS_FALSE;
|
||||
}
|
||||
|
||||
ks_bool_t test_talk_request_handler(blade_rpc_request_t *brpcreq, cJSON *data)
|
||||
ks_bool_t test_talk_request_handler(blade_rpc_request_t *brpcreq, void *data)
|
||||
{
|
||||
//testproto_t *test = NULL;
|
||||
blade_handle_t *bh = NULL;
|
||||
@@ -244,7 +259,7 @@ ks_bool_t test_talk_request_handler(blade_rpc_request_t *brpcreq, cJSON *data)
|
||||
ks_assert(brpcreq);
|
||||
ks_assert(data);
|
||||
|
||||
//test = (testproto_t *)cJSON_GetPtrValue(data);
|
||||
//test = (testproto_t *)data;
|
||||
|
||||
bh = blade_rpc_request_handle_get(brpcreq);
|
||||
ks_assert(bh);
|
||||
@@ -263,12 +278,16 @@ ks_bool_t test_talk_request_handler(blade_rpc_request_t *brpcreq, cJSON *data)
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) test.talk (%s) request processing\n", blade_session_id_get(bs), requester_nodeid);
|
||||
|
||||
blade_session_read_unlock(bs);
|
||||
|
||||
// send rpcexecute response to the requester
|
||||
result = cJSON_CreateObject();
|
||||
|
||||
blade_rpcexecute_response_send(brpcreq, result);
|
||||
|
||||
cJSON_Delete(result);
|
||||
|
||||
blade_session_read_unlock(bs);
|
||||
|
||||
// broadcast to authorized nodes that have subscribed, that the requester has said something
|
||||
params = cJSON_CreateObject();
|
||||
|
||||
cJSON_AddStringToObject(params, "text", text);
|
||||
@@ -277,6 +296,8 @@ ks_bool_t test_talk_request_handler(blade_rpc_request_t *brpcreq, cJSON *data)
|
||||
|
||||
blade_handle_rpcbroadcast(bh, "test", "mydomain.com", "channel", "talk", params, NULL, NULL);
|
||||
|
||||
cJSON_Delete(params);
|
||||
|
||||
return KS_FALSE;
|
||||
}
|
||||
|
||||
@@ -345,19 +366,21 @@ int main(int argc, char **argv)
|
||||
// @todo use session state change callback to know when the session is ready and the realm(s) available from blade.connect, this hack temporarily ensures it's ready before trying to publish upstream
|
||||
ks_sleep_ms(3000);
|
||||
|
||||
blade_rpc_create(&brpc, bh, "test.join", "test", "mydomain.com", test_join_request_handler, cJSON_CreatePtr((uintptr_t)test));
|
||||
blade_rpc_create(&brpc, bh, "test.join", "test", "mydomain.com", test_join_request_handler, (void *)test);
|
||||
blade_rpcmgr_protocolrpc_add(blade_handle_rpcmgr_get(bh), brpc);
|
||||
|
||||
blade_rpc_create(&brpc, bh, "test.leave", "test", "mydomain.com", test_leave_request_handler, cJSON_CreatePtr((uintptr_t)test));
|
||||
blade_rpc_create(&brpc, bh, "test.leave", "test", "mydomain.com", test_leave_request_handler, (void *)test);
|
||||
blade_rpcmgr_protocolrpc_add(blade_handle_rpcmgr_get(bh), brpc);
|
||||
|
||||
blade_rpc_create(&brpc, bh, "test.talk", "test", "mydomain.com", test_talk_request_handler, cJSON_CreatePtr((uintptr_t)test));
|
||||
blade_rpc_create(&brpc, bh, "test.talk", "test", "mydomain.com", test_talk_request_handler, (void *)test);
|
||||
blade_rpcmgr_protocolrpc_add(blade_handle_rpcmgr_get(bh), brpc);
|
||||
|
||||
channels = cJSON_CreateArray();
|
||||
cJSON_AddItemToArray(channels, cJSON_CreateString("channel"));
|
||||
|
||||
blade_handle_rpcpublish(bh, "test", "mydomain.com", channels, test_publish_response_handler, cJSON_CreatePtr((uintptr_t)test));
|
||||
blade_handle_rpcpublish(bh, "test", "mydomain.com", channels, test_publish_response_handler, (void *)test);
|
||||
|
||||
cJSON_Delete(channels);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user