FS-10167: Significant cleanup and isolation of code into manager types for better maintainability and easier path to future updates
This commit is contained in:
parent
4da4e1177c
commit
3687a5a0a5
|
@ -189,28 +189,44 @@
|
|||
<ItemGroup>
|
||||
<ClCompile Include="src\blade.c" />
|
||||
<ClCompile Include="src\blade_connection.c" />
|
||||
<ClCompile Include="src\blade_connectionmgr.c" />
|
||||
<ClCompile Include="src\blade_identity.c" />
|
||||
<ClCompile Include="src\blade_mastermgr.c" />
|
||||
<ClCompile Include="src\blade_routemgr.c" />
|
||||
<ClCompile Include="src\blade_rpc.c" />
|
||||
<ClCompile Include="src\blade_protocol.c" />
|
||||
<ClCompile Include="src\blade_rpcmgr.c" />
|
||||
<ClCompile Include="src\blade_sessionmgr.c" />
|
||||
<ClCompile Include="src\blade_subscription.c" />
|
||||
<ClCompile Include="src\blade_subscriptionmgr.c" />
|
||||
<ClCompile Include="src\blade_transportmgr.c" />
|
||||
<ClCompile Include="src\blade_transport_wss.c" />
|
||||
<ClCompile Include="src\blade_session.c" />
|
||||
<ClCompile Include="src\blade_stack.c" />
|
||||
<ClCompile Include="src\blade_transport.c" />
|
||||
<ClCompile Include="src\blade_upstreammgr.c" />
|
||||
<ClCompile Include="src\unqlite.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\include\blade.h" />
|
||||
<ClInclude Include="src\include\blade_connection.h" />
|
||||
<ClInclude Include="src\include\blade_connectionmgr.h" />
|
||||
<ClInclude Include="src\include\blade_identity.h" />
|
||||
<ClInclude Include="src\include\blade_mastermgr.h" />
|
||||
<ClInclude Include="src\include\blade_routemgr.h" />
|
||||
<ClInclude Include="src\include\blade_rpc.h" />
|
||||
<ClInclude Include="src\include\blade_protocol.h" />
|
||||
<ClInclude Include="src\include\blade_rpcmgr.h" />
|
||||
<ClInclude Include="src\include\blade_sessionmgr.h" />
|
||||
<ClInclude Include="src\include\blade_subscription.h" />
|
||||
<ClInclude Include="src\include\blade_subscriptionmgr.h" />
|
||||
<ClInclude Include="src\include\blade_transportmgr.h" />
|
||||
<ClInclude Include="src\include\blade_transport_wss.h" />
|
||||
<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_types.h" />
|
||||
<ClInclude Include="src\include\blade_upstreammgr.h" />
|
||||
<ClInclude Include="src\include\unqlite.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
@ -48,6 +48,30 @@
|
|||
<ClCompile Include="src\blade_subscription.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\blade_transportmgr.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\blade_rpcmgr.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\blade_routemgr.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\blade_subscriptionmgr.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\blade_upstreammgr.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\blade_mastermgr.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\blade_connectionmgr.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\blade_sessionmgr.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\include\unqlite.h">
|
||||
|
@ -86,5 +110,29 @@
|
|||
<ClInclude Include="src\include\blade_subscription.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\include\blade_transportmgr.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\include\blade_rpcmgr.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\include\blade_routemgr.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\include\blade_subscriptionmgr.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\include\blade_upstreammgr.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\include\blade_mastermgr.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\include\blade_connectionmgr.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\include\blade_sessionmgr.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -166,7 +166,7 @@ KS_DECLARE(ks_status_t) blade_connection_shutdown(blade_connection_t *bc)
|
|||
|
||||
ks_assert(bc);
|
||||
|
||||
blade_handle_connections_remove(bc);
|
||||
blade_connectionmgr_connection_remove(blade_handle_connectionmgr_get(bc->handle), bc);
|
||||
|
||||
while (ks_q_trypop(bc->sending, (void **)&json) == KS_STATUS_SUCCESS && json) cJSON_Delete(json);
|
||||
|
||||
|
@ -401,7 +401,7 @@ ks_status_t blade_connection_onstate_startup(blade_connection_t *bc)
|
|||
else if (hook == BLADE_CONNECTION_STATE_HOOK_SUCCESS) {
|
||||
// @todo this is adding a second lock, since we keep it locked in the callback to allow finishing, we don't want get locking here...
|
||||
// or just unlock twice...
|
||||
blade_session_t *bs = blade_handle_sessions_lookup(bc->handle, bc->session);
|
||||
blade_session_t *bs = blade_sessionmgr_session_lookup(blade_handle_sessionmgr_get(bc->handle), bc->session);
|
||||
ks_assert(bs); // should not happen because bs should still be locked
|
||||
|
||||
blade_session_connection_set(bs, bc->id);
|
||||
|
@ -426,7 +426,7 @@ ks_status_t blade_connection_onstate_shutdown(blade_connection_t *bc)
|
|||
if (callback) callback(bc, BLADE_CONNECTION_STATE_CONDITION_POST);
|
||||
|
||||
if (bc->session) {
|
||||
blade_session_t *bs = blade_handle_sessions_lookup(bc->handle, bc->session);
|
||||
blade_session_t *bs = blade_sessionmgr_session_lookup(blade_handle_sessionmgr_get(bc->handle), bc->session);
|
||||
ks_assert(bs);
|
||||
|
||||
blade_session_connection_set(bs, NULL);
|
||||
|
@ -467,7 +467,7 @@ ks_status_t blade_connection_onstate_run(blade_connection_t *bc)
|
|||
|
||||
if (!(done = (json == NULL))) {
|
||||
if (!bs) {
|
||||
bs = blade_handle_sessions_lookup(bc->handle, bc->session);
|
||||
bs = blade_sessionmgr_session_lookup(blade_handle_sessionmgr_get(bc->handle), bc->session);
|
||||
ks_assert(bs);
|
||||
}
|
||||
blade_session_receiving_push(bs, json);
|
||||
|
|
|
@ -0,0 +1,188 @@
|
|||
/*
|
||||
* 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_connectionmgr_s {
|
||||
blade_handle_t *handle;
|
||||
ks_pool_t *pool;
|
||||
|
||||
ks_hash_t *connections; // id, blade_connection_t*
|
||||
};
|
||||
|
||||
|
||||
static void blade_connectionmgr_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
|
||||
{
|
||||
//blade_connectionmgr_t *bcmgr = (blade_connectionmgr_t *)ptr;
|
||||
|
||||
//ks_assert(bcmgr);
|
||||
|
||||
switch (action) {
|
||||
case KS_MPCL_ANNOUNCE:
|
||||
break;
|
||||
case KS_MPCL_TEARDOWN:
|
||||
break;
|
||||
case KS_MPCL_DESTROY:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_connectionmgr_create(blade_connectionmgr_t **bcmgrP, blade_handle_t *bh)
|
||||
{
|
||||
ks_pool_t *pool = NULL;
|
||||
blade_connectionmgr_t *bcmgr = NULL;
|
||||
|
||||
ks_assert(bcmgrP);
|
||||
|
||||
ks_pool_open(&pool);
|
||||
ks_assert(pool);
|
||||
|
||||
bcmgr = ks_pool_alloc(pool, sizeof(blade_connectionmgr_t));
|
||||
bcmgr->handle = bh;
|
||||
bcmgr->pool = pool;
|
||||
|
||||
ks_hash_create(&bcmgr->connections, KS_HASH_MODE_CASE_INSENSITIVE, KS_HASH_FLAG_RWLOCK | KS_HASH_FLAG_DUP_CHECK | KS_HASH_FLAG_FREE_KEY, bcmgr->pool);
|
||||
ks_assert(bcmgr->connections);
|
||||
|
||||
ks_pool_set_cleanup(pool, bcmgr, NULL, blade_connectionmgr_cleanup);
|
||||
|
||||
*bcmgrP = bcmgr;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_connectionmgr_destroy(blade_connectionmgr_t **bcmgrP)
|
||||
{
|
||||
blade_connectionmgr_t *bcmgr = NULL;
|
||||
ks_pool_t *pool;
|
||||
|
||||
ks_assert(bcmgrP);
|
||||
ks_assert(*bcmgrP);
|
||||
|
||||
bcmgr = *bcmgrP;
|
||||
*bcmgrP = NULL;
|
||||
|
||||
ks_assert(bcmgr);
|
||||
|
||||
pool = bcmgr->pool;
|
||||
|
||||
ks_pool_close(&pool);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_handle_t *) blade_connectionmgr_handle_get(blade_connectionmgr_t *bcmgr)
|
||||
{
|
||||
ks_assert(bcmgr);
|
||||
return bcmgr->handle;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_connectionmgr_shutdown(blade_connectionmgr_t *bcmgr)
|
||||
{
|
||||
ks_hash_iterator_t *it = NULL;
|
||||
|
||||
ks_assert(bcmgr);
|
||||
|
||||
ks_hash_read_lock(bcmgr->connections);
|
||||
for (it = ks_hash_first(bcmgr->connections, KS_UNLOCKED); it; it = ks_hash_next(&it)) {
|
||||
void *key = NULL;
|
||||
blade_connection_t *value = NULL;
|
||||
|
||||
ks_hash_this(it, (const void **)&key, NULL, (void **)&value);
|
||||
|
||||
blade_connection_disconnect(value);
|
||||
}
|
||||
ks_hash_read_unlock(bcmgr->connections);
|
||||
while (ks_hash_count(bcmgr->connections) > 0) ks_sleep_ms(100);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_connection_t *) blade_connectionmgr_connection_lookup(blade_connectionmgr_t *bcmgr, const char *id)
|
||||
{
|
||||
blade_connection_t *bc = NULL;
|
||||
|
||||
ks_assert(bcmgr);
|
||||
ks_assert(id);
|
||||
|
||||
bc = ks_hash_search(bcmgr->connections, (void *)id, KS_READLOCKED);
|
||||
if (bc) blade_connection_read_lock(bc, KS_TRUE);
|
||||
ks_hash_read_unlock(bcmgr->connections);
|
||||
|
||||
return bc;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_connectionmgr_connection_add(blade_connectionmgr_t *bcmgr, blade_connection_t *bc)
|
||||
{
|
||||
char *key = NULL;
|
||||
|
||||
ks_assert(bcmgr);
|
||||
ks_assert(bc);
|
||||
|
||||
key = ks_pstrdup(bcmgr->pool, blade_connection_id_get(bc));
|
||||
ks_hash_insert(bcmgr->connections, (void *)key, bc);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Connection Added: %s\n", key);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_connectionmgr_connection_remove(blade_connectionmgr_t *bcmgr, blade_connection_t *bc)
|
||||
{
|
||||
const char *id = NULL;
|
||||
|
||||
ks_assert(bcmgr);
|
||||
ks_assert(bc);
|
||||
|
||||
blade_connection_write_lock(bc, KS_TRUE);
|
||||
|
||||
id = blade_connection_id_get(bc);
|
||||
ks_hash_remove(bcmgr->connections, (void *)id);
|
||||
|
||||
blade_connection_write_unlock(bc);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Connection Removed: %s\n", id);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/* 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:
|
||||
*/
|
|
@ -0,0 +1,227 @@
|
|||
/*
|
||||
* 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_mastermgr_s {
|
||||
blade_handle_t *handle;
|
||||
ks_pool_t *pool;
|
||||
|
||||
// @todo how does "exclusive" play into the controllers, does "exclusive" mean only one provider can exist for a given protocol and realm? what does non exclusive mean?
|
||||
ks_hash_t *protocols; // protocols that have been published with blade.publish, and the details to locate a protocol provider with blade.locate
|
||||
ks_hash_t *protocols_cleanup; // keyed by the nodeid, each value is a hash_t* of which contains string keys matching the "protocol@realm" keys to remove each nodeid from as a provider during cleanup
|
||||
};
|
||||
|
||||
|
||||
static void blade_mastermgr_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
|
||||
{
|
||||
//blade_mastermgr_t *bmmgr = (blade_mastermgr_t *)ptr;
|
||||
|
||||
//ks_assert(bmmgr);
|
||||
|
||||
switch (action) {
|
||||
case KS_MPCL_ANNOUNCE:
|
||||
break;
|
||||
case KS_MPCL_TEARDOWN:
|
||||
break;
|
||||
case KS_MPCL_DESTROY:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_mastermgr_create(blade_mastermgr_t **bmmgrP, blade_handle_t *bh)
|
||||
{
|
||||
ks_pool_t *pool = NULL;
|
||||
blade_mastermgr_t *bmmgr = NULL;
|
||||
|
||||
ks_assert(bmmgrP);
|
||||
|
||||
ks_pool_open(&pool);
|
||||
ks_assert(pool);
|
||||
|
||||
bmmgr = ks_pool_alloc(pool, sizeof(blade_mastermgr_t));
|
||||
bmmgr->handle = bh;
|
||||
bmmgr->pool = pool;
|
||||
|
||||
ks_hash_create(&bmmgr->protocols, KS_HASH_MODE_CASE_INSENSITIVE, KS_HASH_FLAG_RWLOCK | KS_HASH_FLAG_DUP_CHECK | KS_HASH_FLAG_FREE_KEY | KS_HASH_FLAG_FREE_VALUE, bmmgr->pool);
|
||||
ks_assert(bmmgr->protocols);
|
||||
|
||||
ks_hash_create(&bmmgr->protocols_cleanup, KS_HASH_MODE_CASE_INSENSITIVE, KS_HASH_FLAG_RWLOCK | KS_HASH_FLAG_DUP_CHECK | KS_HASH_FLAG_FREE_KEY | KS_HASH_FLAG_FREE_VALUE, bmmgr->pool);
|
||||
ks_assert(bmmgr->protocols_cleanup);
|
||||
|
||||
ks_pool_set_cleanup(pool, bmmgr, NULL, blade_mastermgr_cleanup);
|
||||
|
||||
*bmmgrP = bmmgr;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_mastermgr_destroy(blade_mastermgr_t **bmmgrP)
|
||||
{
|
||||
blade_mastermgr_t *bmmgr = NULL;
|
||||
ks_pool_t *pool;
|
||||
|
||||
ks_assert(bmmgrP);
|
||||
ks_assert(*bmmgrP);
|
||||
|
||||
bmmgr = *bmmgrP;
|
||||
*bmmgrP = NULL;
|
||||
|
||||
ks_assert(bmmgr);
|
||||
|
||||
pool = bmmgr->pool;
|
||||
|
||||
ks_pool_close(&pool);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_handle_t *) blade_mastermgr_handle_get(blade_mastermgr_t *bmmgr)
|
||||
{
|
||||
ks_assert(bmmgr);
|
||||
|
||||
return bmmgr->handle;
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_protocol_t *) blade_mastermgr_protocol_lookup(blade_mastermgr_t *bmmgr, const char *protocol, const char *realm)
|
||||
{
|
||||
blade_protocol_t *bp = NULL;
|
||||
char *key = NULL;
|
||||
|
||||
ks_assert(bmmgr);
|
||||
ks_assert(protocol);
|
||||
ks_assert(realm);
|
||||
|
||||
key = ks_psprintf(bmmgr->pool, "%s@%s", protocol, realm);
|
||||
|
||||
bp = (blade_protocol_t *)ks_hash_search(bmmgr->protocols, (void *)key, KS_READLOCKED);
|
||||
// @todo if (bp) blade_protocol_read_lock(bp);
|
||||
ks_hash_read_unlock(bmmgr->protocols);
|
||||
|
||||
return bp;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_mastermgr_controller_add(blade_mastermgr_t *bmmgr, const char *protocol, const char *realm, const char *controller)
|
||||
{
|
||||
blade_protocol_t *bp = NULL;
|
||||
char *key = NULL;
|
||||
ks_hash_t *cleanup = NULL;
|
||||
|
||||
ks_assert(bmmgr);
|
||||
ks_assert(protocol);
|
||||
ks_assert(realm);
|
||||
ks_assert(controller);
|
||||
|
||||
key = ks_psprintf(bmmgr->pool, "%s@%s", protocol, realm);
|
||||
|
||||
ks_hash_write_lock(bmmgr->protocols);
|
||||
|
||||
bp = (blade_protocol_t *)ks_hash_search(bmmgr->protocols, (void *)key, KS_UNLOCKED);
|
||||
if (bp) {
|
||||
// @todo deal with exclusive stuff when the protocol is already registered
|
||||
}
|
||||
|
||||
if (!bp) {
|
||||
blade_protocol_create(&bp, bmmgr->pool, protocol, realm);
|
||||
ks_assert(bp);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Protocol Added: %s\n", key);
|
||||
ks_hash_insert(bmmgr->protocols, (void *)ks_pstrdup(bmmgr->pool, key), bp);
|
||||
}
|
||||
|
||||
cleanup = (ks_hash_t *)ks_hash_search(bmmgr->protocols_cleanup, (void *)controller, KS_UNLOCKED);
|
||||
if (!cleanup) {
|
||||
ks_hash_create(&cleanup, KS_HASH_MODE_CASE_INSENSITIVE, KS_HASH_FLAG_RWLOCK | KS_HASH_FLAG_DUP_CHECK | KS_HASH_FLAG_FREE_KEY, bmmgr->pool);
|
||||
ks_assert(cleanup);
|
||||
|
||||
ks_hash_insert(bmmgr->protocols_cleanup, (void *)ks_pstrdup(bmmgr->pool, controller), cleanup);
|
||||
}
|
||||
ks_hash_insert(cleanup, (void *)ks_pstrdup(bmmgr->pool, key), (void *)KS_TRUE);
|
||||
blade_protocol_controllers_add(bp, controller);
|
||||
ks_log(KS_LOG_DEBUG, "Protocol Controller Added: %s to %s\n", controller, key);
|
||||
|
||||
ks_hash_write_unlock(bmmgr->protocols);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_mastermgr_controller_remove(blade_mastermgr_t *bmmgr, const char *controller)
|
||||
{
|
||||
ks_hash_t *cleanup = NULL;
|
||||
|
||||
ks_assert(bmmgr);
|
||||
ks_assert(controller);
|
||||
|
||||
ks_hash_write_lock(bmmgr->protocols);
|
||||
cleanup = (ks_hash_t *)ks_hash_search(bmmgr->protocols_cleanup, (void *)controller, KS_UNLOCKED);
|
||||
if (cleanup) {
|
||||
for (ks_hash_iterator_t *it = ks_hash_first(cleanup, KS_UNLOCKED); it; it = ks_hash_next(&it)) {
|
||||
void *key = NULL;
|
||||
void *value = NULL;
|
||||
blade_protocol_t *bp = NULL;
|
||||
ks_hash_t *controllers = NULL;
|
||||
|
||||
ks_hash_this(it, (const void **)&key, NULL, &value);
|
||||
|
||||
bp = (blade_protocol_t *)ks_hash_search(bmmgr->protocols, key, KS_UNLOCKED);
|
||||
ks_assert(bp); // should not happen when a cleanup still has a provider tracked for a protocol
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Protocol Controller Removed: %s from %s\n", controller, key);
|
||||
blade_protocol_controllers_remove(bp, controller);
|
||||
|
||||
controllers = blade_protocol_controllers_get(bp);
|
||||
if (ks_hash_count(controllers) == 0) {
|
||||
// @note this depends on locking something outside of the protocol that won't be destroyed, like the top level
|
||||
// protocols hash, but assumes then that any reader keeps the top level hash read locked while using the protocol
|
||||
// so it cannot be deleted
|
||||
ks_log(KS_LOG_DEBUG, "Protocol Removed: %s\n", key);
|
||||
ks_hash_remove(bmmgr->protocols, key);
|
||||
}
|
||||
}
|
||||
ks_hash_remove(bmmgr->protocols_cleanup, (void *)controller);
|
||||
}
|
||||
ks_hash_write_unlock(bmmgr->protocols);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/* 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:
|
||||
*/
|
|
@ -38,7 +38,7 @@ struct blade_protocol_s {
|
|||
|
||||
const char *name;
|
||||
const char *realm;
|
||||
ks_hash_t *providers;
|
||||
ks_hash_t *controllers;
|
||||
// @todo descriptors (schema, etc) for each method within a protocol
|
||||
};
|
||||
|
||||
|
@ -55,7 +55,7 @@ static void blade_protocol_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_poo
|
|||
case KS_MPCL_TEARDOWN:
|
||||
if (bp->name) ks_pool_free(bp->pool, &bp->name);
|
||||
if (bp->realm) ks_pool_free(bp->pool, &bp->realm);
|
||||
if (bp->providers) ks_hash_destroy(&bp->providers);
|
||||
if (bp->controllers) ks_hash_destroy(&bp->controllers);
|
||||
break;
|
||||
case KS_MPCL_DESTROY:
|
||||
break;
|
||||
|
@ -76,8 +76,8 @@ KS_DECLARE(ks_status_t) blade_protocol_create(blade_protocol_t **bpP, ks_pool_t
|
|||
bp->name = ks_pstrdup(pool, name);
|
||||
bp->realm = ks_pstrdup(pool, realm);
|
||||
|
||||
ks_hash_create(&bp->providers, KS_HASH_MODE_CASE_INSENSITIVE, KS_HASH_FLAG_NOLOCK | KS_HASH_FLAG_DUP_CHECK | KS_HASH_FLAG_FREE_KEY, bp->pool);
|
||||
ks_assert(bp->providers);
|
||||
ks_hash_create(&bp->controllers, KS_HASH_MODE_CASE_INSENSITIVE, KS_HASH_FLAG_NOLOCK | KS_HASH_FLAG_DUP_CHECK | KS_HASH_FLAG_FREE_KEY, bp->pool);
|
||||
ks_assert(bp->controllers);
|
||||
|
||||
ks_pool_set_cleanup(pool, bp, NULL, blade_protocol_cleanup);
|
||||
|
||||
|
@ -100,15 +100,14 @@ KS_DECLARE(ks_status_t) blade_protocol_destroy(blade_protocol_t **bpP)
|
|||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_hash_t *) blade_protocol_providers_get(blade_protocol_t *bp)
|
||||
KS_DECLARE(ks_hash_t *) blade_protocol_controllers_get(blade_protocol_t *bp)
|
||||
{
|
||||
ks_assert(bp);
|
||||
|
||||
return bp->providers;
|
||||
return bp->controllers;
|
||||
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_protocol_providers_add(blade_protocol_t *bp, const char *nodeid)
|
||||
KS_DECLARE(ks_status_t) blade_protocol_controllers_add(blade_protocol_t *bp, const char *nodeid)
|
||||
{
|
||||
char *key = NULL;
|
||||
|
||||
|
@ -116,18 +115,18 @@ KS_DECLARE(ks_status_t) blade_protocol_providers_add(blade_protocol_t *bp, const
|
|||
ks_assert(nodeid);
|
||||
|
||||
key = ks_pstrdup(bp->pool, nodeid);
|
||||
ks_hash_insert(bp->providers, (void *)key, (void *)KS_TRUE);
|
||||
ks_hash_insert(bp->controllers, (void *)key, (void *)KS_TRUE);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_protocol_providers_remove(blade_protocol_t *bp, const char *nodeid)
|
||||
KS_DECLARE(ks_status_t) blade_protocol_controllers_remove(blade_protocol_t *bp, const char *nodeid)
|
||||
{
|
||||
ks_assert(bp);
|
||||
ks_assert(nodeid);
|
||||
|
||||
ks_hash_remove(bp->providers, (void *)nodeid);
|
||||
ks_hash_remove(bp->controllers, (void *)nodeid);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
|
||||
|
|
|
@ -0,0 +1,179 @@
|
|||
/*
|
||||
* 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_routemgr_s {
|
||||
blade_handle_t *handle;
|
||||
ks_pool_t *pool;
|
||||
|
||||
ks_hash_t *routes; // id, id
|
||||
};
|
||||
|
||||
|
||||
static void blade_routemgr_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
|
||||
{
|
||||
//blade_routemgr_t *brmgr = (blade_routemgr_t *)ptr;
|
||||
|
||||
//ks_assert(brmgr);
|
||||
|
||||
switch (action) {
|
||||
case KS_MPCL_ANNOUNCE:
|
||||
break;
|
||||
case KS_MPCL_TEARDOWN:
|
||||
break;
|
||||
case KS_MPCL_DESTROY:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_routemgr_create(blade_routemgr_t **brmgrP, blade_handle_t *bh)
|
||||
{
|
||||
ks_pool_t *pool = NULL;
|
||||
blade_routemgr_t *brmgr = NULL;
|
||||
|
||||
ks_assert(brmgrP);
|
||||
|
||||
ks_pool_open(&pool);
|
||||
ks_assert(pool);
|
||||
|
||||
brmgr = ks_pool_alloc(pool, sizeof(blade_routemgr_t));
|
||||
brmgr->handle = bh;
|
||||
brmgr->pool = pool;
|
||||
|
||||
// @note can let removes free keys and values for routes, both are strings and allocated from the same pool as the hash itself
|
||||
ks_hash_create(&brmgr->routes, KS_HASH_MODE_CASE_INSENSITIVE, KS_HASH_FLAG_RWLOCK | KS_HASH_FLAG_DUP_CHECK | KS_HASH_FLAG_FREE_KEY | KS_HASH_FLAG_FREE_VALUE, brmgr->pool);
|
||||
ks_assert(brmgr->routes);
|
||||
|
||||
ks_pool_set_cleanup(pool, brmgr, NULL, blade_routemgr_cleanup);
|
||||
|
||||
*brmgrP = brmgr;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_routemgr_destroy(blade_routemgr_t **brmgrP)
|
||||
{
|
||||
blade_routemgr_t *brmgr = NULL;
|
||||
ks_pool_t *pool;
|
||||
|
||||
ks_assert(brmgrP);
|
||||
ks_assert(*brmgrP);
|
||||
|
||||
brmgr = *brmgrP;
|
||||
*brmgrP = NULL;
|
||||
|
||||
ks_assert(brmgr);
|
||||
|
||||
pool = brmgr->pool;
|
||||
|
||||
ks_pool_close(&pool);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_handle_t *) blade_routemgr_handle_get(blade_routemgr_t *brmgr)
|
||||
{
|
||||
ks_assert(brmgr);
|
||||
|
||||
return brmgr->handle;
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_session_t *) blade_routemgr_route_lookup(blade_routemgr_t *brmgr, const char *target)
|
||||
{
|
||||
blade_session_t *bs = NULL;
|
||||
const char *router = NULL;
|
||||
|
||||
ks_assert(brmgr);
|
||||
ks_assert(target);
|
||||
|
||||
router = (const char *)ks_hash_search(brmgr->routes, (void *)target, KS_READLOCKED);
|
||||
if (router) bs = blade_sessionmgr_session_lookup(blade_handle_sessionmgr_get(brmgr->handle), router);
|
||||
ks_hash_read_unlock(brmgr->routes);
|
||||
|
||||
return bs;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_routemgr_route_add(blade_routemgr_t *brmgr, const char *target, const char *router)
|
||||
{
|
||||
char *key = NULL;
|
||||
char *value = NULL;
|
||||
|
||||
ks_assert(brmgr);
|
||||
ks_assert(target);
|
||||
ks_assert(router);
|
||||
|
||||
key = ks_pstrdup(brmgr->pool, target);
|
||||
value = ks_pstrdup(brmgr->pool, router);
|
||||
|
||||
ks_hash_insert(brmgr->routes, (void *)key, (void *)value);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Route Added: %s through %s\n", key, value);
|
||||
|
||||
blade_protocol_register(brmgr->handle, target, KS_FALSE, NULL, NULL);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_routemgr_route_remove(blade_routemgr_t *brmgr, const char *target)
|
||||
{
|
||||
ks_assert(brmgr);
|
||||
ks_assert(target);
|
||||
|
||||
ks_hash_remove(brmgr->routes, (void *)target);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Route Removed: %s\n", target);
|
||||
|
||||
blade_protocol_register(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
|
||||
// removed, a master node is still able to catch that here even when there is no direct session, but is also hit when there
|
||||
// is a direct session being terminated
|
||||
|
||||
blade_mastermgr_controller_remove(blade_handle_mastermgr_get(brmgr->handle), target);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/* 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:
|
||||
*/
|
|
@ -0,0 +1,319 @@
|
|||
/*
|
||||
* 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_rpcmgr_s {
|
||||
blade_handle_t *handle;
|
||||
ks_pool_t *pool;
|
||||
|
||||
ks_hash_t *corerpcs; // method, blade_rpc_t*
|
||||
ks_hash_t *protocolrpcs; // method, blade_rpc_t*
|
||||
|
||||
ks_hash_t *requests; // id, KS_TRUE
|
||||
};
|
||||
|
||||
|
||||
static void blade_rpcmgr_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
|
||||
{
|
||||
blade_rpcmgr_t *brpcmgr = (blade_rpcmgr_t *)ptr;
|
||||
ks_hash_iterator_t *it = NULL;
|
||||
|
||||
ks_assert(brpcmgr);
|
||||
|
||||
switch (action) {
|
||||
case KS_MPCL_ANNOUNCE:
|
||||
break;
|
||||
case KS_MPCL_TEARDOWN:
|
||||
while ((it = ks_hash_first(brpcmgr->protocolrpcs, KS_UNLOCKED)) != NULL) {
|
||||
void *key = NULL;
|
||||
blade_rpc_t *value = NULL;
|
||||
|
||||
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
|
||||
}
|
||||
while ((it = ks_hash_first(brpcmgr->corerpcs, KS_UNLOCKED)) != NULL) {
|
||||
void *key = NULL;
|
||||
blade_rpc_t *value = NULL;
|
||||
|
||||
ks_hash_this(it, (const void **)&key, NULL, (void **)&value);
|
||||
ks_hash_remove(brpcmgr->corerpcs, 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
|
||||
}
|
||||
break;
|
||||
case KS_MPCL_DESTROY:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_rpcmgr_create(blade_rpcmgr_t **brpcmgrP, blade_handle_t *bh)
|
||||
{
|
||||
ks_pool_t *pool = NULL;
|
||||
blade_rpcmgr_t *brpcmgr = NULL;
|
||||
|
||||
ks_assert(brpcmgrP);
|
||||
|
||||
ks_pool_open(&pool);
|
||||
ks_assert(pool);
|
||||
|
||||
brpcmgr = ks_pool_alloc(pool, sizeof(blade_rpcmgr_t));
|
||||
brpcmgr->handle = bh;
|
||||
brpcmgr->pool = pool;
|
||||
|
||||
ks_hash_create(&brpcmgr->corerpcs, KS_HASH_MODE_CASE_INSENSITIVE, KS_HASH_FLAG_RWLOCK | KS_HASH_FLAG_DUP_CHECK | KS_HASH_FLAG_FREE_KEY, brpcmgr->pool);
|
||||
ks_assert(brpcmgr->corerpcs);
|
||||
|
||||
ks_hash_create(&brpcmgr->protocolrpcs, KS_HASH_MODE_CASE_INSENSITIVE, KS_HASH_FLAG_RWLOCK | KS_HASH_FLAG_DUP_CHECK | KS_HASH_FLAG_FREE_KEY, brpcmgr->pool);
|
||||
ks_assert(brpcmgr->protocolrpcs);
|
||||
|
||||
ks_hash_create(&brpcmgr->requests, KS_HASH_MODE_CASE_INSENSITIVE, KS_HASH_FLAG_RWLOCK | KS_HASH_FLAG_DUP_CHECK | KS_HASH_FLAG_FREE_KEY, brpcmgr->pool);
|
||||
ks_assert(brpcmgr->requests);
|
||||
|
||||
ks_pool_set_cleanup(pool, brpcmgr, NULL, blade_rpcmgr_cleanup);
|
||||
|
||||
*brpcmgrP = brpcmgr;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_rpcmgr_destroy(blade_rpcmgr_t **brpcmgrP)
|
||||
{
|
||||
blade_rpcmgr_t *brpcmgr = NULL;
|
||||
ks_pool_t *pool;
|
||||
|
||||
ks_assert(brpcmgrP);
|
||||
ks_assert(*brpcmgrP);
|
||||
|
||||
brpcmgr = *brpcmgrP;
|
||||
*brpcmgrP = NULL;
|
||||
|
||||
ks_assert(brpcmgr);
|
||||
|
||||
pool = brpcmgr->pool;
|
||||
|
||||
ks_pool_close(&pool);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_handle_t *) blade_rpcmgr_handle_get(blade_rpcmgr_t *brpcmgr)
|
||||
{
|
||||
ks_assert(brpcmgr);
|
||||
|
||||
return brpcmgr->handle;
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_rpc_t *) blade_rpcmgr_corerpc_lookup(blade_rpcmgr_t *brpcmgr, const char *method)
|
||||
{
|
||||
blade_rpc_t *brpc = NULL;
|
||||
|
||||
ks_assert(brpcmgr);
|
||||
ks_assert(method);
|
||||
|
||||
brpc = (blade_rpc_t *)ks_hash_search(brpcmgr->corerpcs, (void *)method, KS_READLOCKED);
|
||||
// @todo if (brpc) blade_rpc_read_lock(brpc);
|
||||
ks_hash_read_unlock(brpcmgr->corerpcs);
|
||||
|
||||
return brpc;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_rpcmgr_corerpc_add(blade_rpcmgr_t *brpcmgr, blade_rpc_t *brpc)
|
||||
{
|
||||
char *key = NULL;
|
||||
|
||||
ks_assert(brpcmgr);
|
||||
ks_assert(brpc);
|
||||
|
||||
key = ks_pstrdup(brpcmgr->pool, blade_rpc_method_get(brpc));
|
||||
ks_hash_insert(brpcmgr->corerpcs, (void *)key, (void *)brpc);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "CoreRPC Added: %s\n", key);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_rpcmgr_corerpc_remove(blade_rpcmgr_t *brpcmgr, blade_rpc_t *brpc)
|
||||
{
|
||||
const char *method = NULL;
|
||||
|
||||
ks_assert(brpcmgr);
|
||||
ks_assert(brpc);
|
||||
|
||||
method = blade_rpc_method_get(brpc);
|
||||
ks_hash_remove(brpcmgr->corerpcs, (void *)method);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "CoreRPC Removed: %s\n", method);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_rpc_t *) blade_rpcmgr_protocolrpc_lookup(blade_rpcmgr_t *brpcmgr, const char *method, const char *protocol, const char *realm)
|
||||
{
|
||||
blade_rpc_t *brpc = NULL;
|
||||
char *key = NULL;
|
||||
|
||||
ks_assert(brpcmgr);
|
||||
ks_assert(method);
|
||||
ks_assert(protocol);
|
||||
ks_assert(realm);
|
||||
|
||||
key = ks_psprintf(brpcmgr->pool, "%s@%s/%s", protocol, realm, method);
|
||||
brpc = ks_hash_search(brpcmgr->protocolrpcs, (void *)key, KS_READLOCKED);
|
||||
// @todo if (brpc) blade_rpc_read_lock(brpc);
|
||||
ks_hash_read_unlock(brpcmgr->protocolrpcs);
|
||||
|
||||
ks_pool_free(brpcmgr->pool, &key);
|
||||
|
||||
return brpc;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_rpcmgr_protocolrpc_add(blade_rpcmgr_t *brpcmgr, blade_rpc_t *brpc)
|
||||
{
|
||||
const char *method = NULL;
|
||||
const char *protocol = NULL;
|
||||
const char *realm = NULL;
|
||||
char *key = NULL;
|
||||
|
||||
ks_assert(brpcmgr);
|
||||
ks_assert(brpc);
|
||||
|
||||
method = blade_rpc_method_get(brpc);
|
||||
ks_assert(method);
|
||||
|
||||
protocol = blade_rpc_protocol_get(brpc);
|
||||
ks_assert(protocol);
|
||||
|
||||
realm = blade_rpc_realm_get(brpc);
|
||||
ks_assert(realm);
|
||||
|
||||
key = ks_psprintf(brpcmgr->pool, "%s@%s/%s", protocol, realm, method);
|
||||
ks_assert(key);
|
||||
|
||||
ks_hash_insert(brpcmgr->protocolrpcs, (void *)key, (void *)brpc);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "ProtocolRPC Added: %s\n", key);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_rpcmgr_protocolrpc_remove(blade_rpcmgr_t *brpcmgr, blade_rpc_t *brpc)
|
||||
{
|
||||
const char *method = NULL;
|
||||
const char *protocol = NULL;
|
||||
const char *realm = NULL;
|
||||
char *key = NULL;
|
||||
|
||||
ks_assert(brpcmgr);
|
||||
ks_assert(brpc);
|
||||
|
||||
method = blade_rpc_method_get(brpc);
|
||||
ks_assert(method);
|
||||
|
||||
protocol = blade_rpc_protocol_get(brpc);
|
||||
ks_assert(protocol);
|
||||
|
||||
realm = blade_rpc_realm_get(brpc);
|
||||
ks_assert(realm);
|
||||
|
||||
key = ks_psprintf(brpcmgr->pool, "%s@%s/%s", protocol, realm, method);
|
||||
ks_assert(key);
|
||||
|
||||
ks_hash_remove(brpcmgr->protocolrpcs, (void *)key);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "ProtocolRPC Removed: %s\n", key);
|
||||
|
||||
ks_pool_free(brpcmgr->pool, &key);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_rpc_request_t *) blade_rpcmgr_request_lookup(blade_rpcmgr_t *brpcmgr, const char *id)
|
||||
{
|
||||
blade_rpc_request_t *brpcreq = NULL;
|
||||
|
||||
ks_assert(brpcmgr);
|
||||
ks_assert(id);
|
||||
|
||||
brpcreq = (blade_rpc_request_t *)ks_hash_search(brpcmgr->requests, (void *)id, KS_READLOCKED);
|
||||
// @todo if (brpcreq) blade_rpc_request_read_lock(brpcreq);
|
||||
ks_hash_read_unlock(brpcmgr->requests);
|
||||
|
||||
return brpcreq;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_rpcmgr_request_add(blade_rpcmgr_t *brpcmgr, blade_rpc_request_t *brpcreq)
|
||||
{
|
||||
char *key = NULL;
|
||||
|
||||
ks_assert(brpcmgr);
|
||||
ks_assert(brpcreq);
|
||||
|
||||
key = ks_pstrdup(brpcmgr->pool, blade_rpc_request_messageid_get(brpcreq));
|
||||
ks_hash_insert(brpcmgr->requests, (void *)key, (void *)brpcreq);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Request Added: %s\n", key);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_rpcmgr_request_remove(blade_rpcmgr_t *brpcmgr, blade_rpc_request_t *brpcreq)
|
||||
{
|
||||
const char *id = NULL;
|
||||
|
||||
ks_assert(brpcmgr);
|
||||
ks_assert(brpcreq);
|
||||
|
||||
id = blade_rpc_request_messageid_get(brpcreq);
|
||||
ks_hash_remove(brpcmgr->requests, (void *)id);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Request Removed: %s\n", id);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/* 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:
|
||||
*/
|
|
@ -192,12 +192,12 @@ KS_DECLARE(ks_status_t) blade_session_shutdown(blade_session_t *bs)
|
|||
|
||||
ks_hash_this(it, (const void **)&key, NULL, &value);
|
||||
|
||||
blade_handle_route_remove(bs->handle, (const char *)key);
|
||||
blade_routemgr_route_remove(blade_handle_routemgr_get(bs->handle), (const char *)key);
|
||||
}
|
||||
ks_hash_read_unlock(bs->routes);
|
||||
|
||||
// this will also clear the identities and realms in the handle if this is the upstream session
|
||||
blade_handle_sessions_remove(bs);
|
||||
// this will also clear the local id, master id and realms in the handle if this is the upstream session
|
||||
blade_sessionmgr_session_remove(blade_handle_sessionmgr_get(bs->handle), bs);
|
||||
|
||||
while (ks_q_trypop(bs->sending, (void **)&json) == KS_STATUS_SUCCESS && json) cJSON_Delete(json);
|
||||
while (ks_q_trypop(bs->receiving, (void **)&json) == KS_STATUS_SUCCESS && json) cJSON_Delete(json);
|
||||
|
@ -368,7 +368,7 @@ KS_DECLARE(void) blade_session_state_set(blade_session_t *bs, blade_session_stat
|
|||
|
||||
ks_cond_lock(bs->cond);
|
||||
bs->state = state;
|
||||
blade_handle_session_state_callbacks_execute(bs, BLADE_SESSION_STATE_CONDITION_PRE);
|
||||
blade_sessionmgr_callback_execute(blade_handle_sessionmgr_get(bs->handle), bs, BLADE_SESSION_STATE_CONDITION_PRE);
|
||||
ks_cond_unlock(bs->cond);
|
||||
|
||||
ks_cond_try_signal(bs->cond);
|
||||
|
@ -489,7 +489,7 @@ void *blade_session_state_thread(ks_thread_t *thread, void *data)
|
|||
state = bs->state;
|
||||
|
||||
if (bs->connection) {
|
||||
blade_connection_t *bc = blade_handle_connections_lookup(bs->handle, bs->connection);
|
||||
blade_connection_t *bc = blade_connectionmgr_connection_lookup(blade_handle_connectionmgr_get(bs->handle), bs->connection);
|
||||
if (bc) {
|
||||
// @note in order for this to work on session reconnecting, the assumption is that as soon as a session has a connection set,
|
||||
// we can start stuffing any messages queued for output on the session straight to the connection right away, may need to only
|
||||
|
@ -505,7 +505,7 @@ void *blade_session_state_thread(ks_thread_t *thread, void *data)
|
|||
}
|
||||
|
||||
// @todo evolve this system, it's probably not the best way to handle receiving session state updates externally
|
||||
blade_handle_session_state_callbacks_execute(bs, BLADE_SESSION_STATE_CONDITION_POST);
|
||||
blade_sessionmgr_callback_execute(blade_handle_sessionmgr_get(bs->handle), bs, BLADE_SESSION_STATE_CONDITION_POST);
|
||||
|
||||
switch (state) {
|
||||
case BLADE_SESSION_STATE_STARTUP:
|
||||
|
@ -554,7 +554,7 @@ ks_status_t blade_session_onstate_shutdown(blade_session_t *bs)
|
|||
blade_session_state_set(bs, BLADE_SESSION_STATE_CLEANUP);
|
||||
|
||||
if (bs->connection) {
|
||||
blade_connection_t *bc = blade_handle_connections_lookup(bs->handle, bs->connection);
|
||||
blade_connection_t *bc = blade_connectionmgr_connection_lookup(blade_handle_connectionmgr_get(bs->handle), bs->connection);
|
||||
if (bc) {
|
||||
blade_connection_disconnect(bc);
|
||||
blade_connection_read_unlock(bc);
|
||||
|
@ -605,7 +605,7 @@ KS_DECLARE(ks_status_t) blade_session_send(blade_session_t *bs, cJSON *json, bla
|
|||
ks_assert(brpcreq);
|
||||
|
||||
// @todo set request TTL and figure out when requests are checked for expiration (separate thread in the handle?)
|
||||
blade_handle_requests_add(brpcreq);
|
||||
blade_rpcmgr_request_add(blade_handle_rpcmgr_get(bs->handle), brpcreq);
|
||||
} else {
|
||||
// @note This is scenario 3
|
||||
// 3) Sending a response or error (server: method callee or provider)
|
||||
|
@ -616,7 +616,7 @@ KS_DECLARE(ks_status_t) blade_session_send(blade_session_t *bs, cJSON *json, bla
|
|||
if (!bs->connection) {
|
||||
blade_session_sending_push(bs, json);
|
||||
} else {
|
||||
blade_connection_t *bc = blade_handle_connections_lookup(bs->handle, bs->connection);
|
||||
blade_connection_t *bc = blade_connectionmgr_connection_lookup(blade_handle_connectionmgr_get(bs->handle), bs->connection);
|
||||
if (!bc) {
|
||||
blade_session_sending_push(bs, json);
|
||||
return KS_STATUS_FAIL;
|
||||
|
@ -677,11 +677,11 @@ ks_status_t blade_session_process(blade_session_t *bs, cJSON *json)
|
|||
if (params) {
|
||||
const char *params_requester_nodeid = cJSON_GetObjectCstr(params, "requester-nodeid");
|
||||
const char *params_responder_nodeid = cJSON_GetObjectCstr(params, "responder-nodeid");
|
||||
if (params_requester_nodeid && params_responder_nodeid && !blade_handle_local_nodeid_compare(bh, params_responder_nodeid)) {
|
||||
if (params_requester_nodeid && params_responder_nodeid && !blade_upstreammgr_localid_compare(blade_handle_upstreammgr_get(bh), params_responder_nodeid)) {
|
||||
// not meant for local processing, continue with standard unicast routing for requests
|
||||
blade_session_t *bs_router = blade_handle_route_lookup(bh, params_responder_nodeid);
|
||||
blade_session_t *bs_router = blade_routemgr_route_lookup(blade_handle_routemgr_get(bh), params_responder_nodeid);
|
||||
if (!bs_router) {
|
||||
bs_router = blade_handle_sessions_upstream(bh);
|
||||
bs_router = blade_upstreammgr_session_get(blade_handle_upstreammgr_get(bh));
|
||||
if (!bs_router) {
|
||||
cJSON *res = NULL;
|
||||
cJSON *res_error = NULL;
|
||||
|
@ -711,7 +711,7 @@ ks_status_t blade_session_process(blade_session_t *bs, cJSON *json)
|
|||
}
|
||||
|
||||
// reach here if the request was not captured for routing, this SHOULD always mean the message is to be processed by local handlers
|
||||
brpc = blade_handle_corerpc_lookup(bs->handle, method);
|
||||
brpc = blade_rpcmgr_corerpc_lookup(blade_handle_rpcmgr_get(bs->handle), method);
|
||||
|
||||
if (!brpc) {
|
||||
ks_log(KS_LOG_DEBUG, "Received unknown rpc method %s\n", method);
|
||||
|
@ -744,11 +744,11 @@ ks_status_t blade_session_process(blade_session_t *bs, cJSON *json)
|
|||
if (object) {
|
||||
const char *object_requester_nodeid = cJSON_GetObjectCstr(object, "requester-nodeid");
|
||||
const char *object_responder_nodeid = cJSON_GetObjectCstr(object, "responder-nodeid");
|
||||
if (object_requester_nodeid && object_responder_nodeid && !blade_handle_local_nodeid_compare(bh, object_requester_nodeid)) {
|
||||
if (object_requester_nodeid && object_responder_nodeid && !blade_upstreammgr_localid_compare(blade_handle_upstreammgr_get(bh), object_requester_nodeid)) {
|
||||
// not meant for local processing, continue with standard unicast routing for responses
|
||||
blade_session_t *bs_router = blade_handle_route_lookup(bh, object_requester_nodeid);
|
||||
blade_session_t *bs_router = blade_routemgr_route_lookup(blade_handle_routemgr_get(bh), object_requester_nodeid);
|
||||
if (!bs_router) {
|
||||
bs_router = blade_handle_sessions_upstream(bh);
|
||||
bs_router = blade_upstreammgr_session_get(blade_handle_upstreammgr_get(bh));
|
||||
if (!bs_router) {
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) response (%s <= %s) but upstream session unavailable\n", blade_session_id_get(bs), object_requester_nodeid, object_responder_nodeid);
|
||||
return KS_STATUS_DISCONNECTED;
|
||||
|
@ -767,12 +767,12 @@ ks_status_t blade_session_process(blade_session_t *bs, cJSON *json)
|
|||
}
|
||||
}
|
||||
|
||||
brpcreq = blade_handle_requests_lookup(bs->handle, id);
|
||||
brpcreq = blade_rpcmgr_request_lookup(blade_handle_rpcmgr_get(bs->handle), id);
|
||||
if (!brpcreq) {
|
||||
// @todo hangup session entirely?
|
||||
return KS_STATUS_FAIL;
|
||||
}
|
||||
blade_handle_requests_remove(brpcreq);
|
||||
blade_rpcmgr_request_remove(blade_handle_rpcmgr_get(bs->handle), brpcreq);
|
||||
|
||||
callback = blade_rpc_request_callback_get(brpcreq);
|
||||
|
||||
|
|
|
@ -0,0 +1,280 @@
|
|||
/*
|
||||
* 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_sessionmgr_s {
|
||||
blade_handle_t *handle;
|
||||
ks_pool_t *pool;
|
||||
|
||||
ks_hash_t *sessions; // id, blade_session_t*
|
||||
ks_hash_t *callbacks; // id, blade_session_callback_data_t*
|
||||
};
|
||||
|
||||
struct blade_session_callback_data_s {
|
||||
ks_pool_t *pool;
|
||||
|
||||
const char *id;
|
||||
void *data;
|
||||
blade_session_callback_t callback;
|
||||
};
|
||||
|
||||
|
||||
static void blade_sessionmgr_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
|
||||
{
|
||||
//blade_sessionmgr_t *bsmgr = (blade_sessionmgr_t *)ptr;
|
||||
|
||||
//ks_assert(bsmgr);
|
||||
|
||||
switch (action) {
|
||||
case KS_MPCL_ANNOUNCE:
|
||||
break;
|
||||
case KS_MPCL_TEARDOWN:
|
||||
break;
|
||||
case KS_MPCL_DESTROY:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void blade_session_callback_data_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
|
||||
{
|
||||
blade_session_callback_data_t *bscd = (blade_session_callback_data_t *)ptr;
|
||||
|
||||
ks_assert(bscd);
|
||||
|
||||
switch (action) {
|
||||
case KS_MPCL_ANNOUNCE:
|
||||
break;
|
||||
case KS_MPCL_TEARDOWN:
|
||||
ks_pool_free(bscd->pool, &bscd->id);
|
||||
break;
|
||||
case KS_MPCL_DESTROY:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_sessionmgr_create(blade_sessionmgr_t **bsmgrP, blade_handle_t *bh)
|
||||
{
|
||||
ks_pool_t *pool = NULL;
|
||||
blade_sessionmgr_t *bsmgr = NULL;
|
||||
|
||||
ks_assert(bsmgrP);
|
||||
|
||||
ks_pool_open(&pool);
|
||||
ks_assert(pool);
|
||||
|
||||
bsmgr = ks_pool_alloc(pool, sizeof(blade_sessionmgr_t));
|
||||
bsmgr->handle = bh;
|
||||
bsmgr->pool = pool;
|
||||
|
||||
ks_hash_create(&bsmgr->sessions, KS_HASH_MODE_CASE_INSENSITIVE, KS_HASH_FLAG_RWLOCK | KS_HASH_FLAG_DUP_CHECK | KS_HASH_FLAG_FREE_KEY, bsmgr->pool);
|
||||
ks_assert(bsmgr->sessions);
|
||||
|
||||
ks_hash_create(&bsmgr->callbacks, KS_HASH_MODE_CASE_INSENSITIVE, KS_HASH_FLAG_RWLOCK | KS_HASH_FLAG_DUP_CHECK | KS_HASH_FLAG_FREE_KEY | KS_HASH_FLAG_FREE_VALUE, bsmgr->pool);
|
||||
ks_assert(bsmgr->callbacks);
|
||||
|
||||
ks_pool_set_cleanup(pool, bsmgr, NULL, blade_sessionmgr_cleanup);
|
||||
|
||||
*bsmgrP = bsmgr;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_sessionmgr_destroy(blade_sessionmgr_t **bsmgrP)
|
||||
{
|
||||
blade_sessionmgr_t *bsmgr = NULL;
|
||||
ks_pool_t *pool;
|
||||
|
||||
ks_assert(bsmgrP);
|
||||
ks_assert(*bsmgrP);
|
||||
|
||||
bsmgr = *bsmgrP;
|
||||
*bsmgrP = NULL;
|
||||
|
||||
ks_assert(bsmgr);
|
||||
|
||||
pool = bsmgr->pool;
|
||||
|
||||
ks_pool_close(&pool);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_handle_t *) blade_sessionmgr_handle_get(blade_sessionmgr_t *bsmgr)
|
||||
{
|
||||
ks_assert(bsmgr);
|
||||
return bsmgr->handle;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_sessionmgr_shutdown(blade_sessionmgr_t *bsmgr)
|
||||
{
|
||||
ks_hash_iterator_t *it = NULL;
|
||||
|
||||
ks_assert(bsmgr);
|
||||
|
||||
ks_hash_read_lock(bsmgr->sessions);
|
||||
for (it = ks_hash_first(bsmgr->sessions, KS_UNLOCKED); it; it = ks_hash_next(&it)) {
|
||||
void *key = NULL;
|
||||
blade_session_t *value = NULL;
|
||||
|
||||
ks_hash_this(it, (const void **)&key, NULL, (void **)&value);
|
||||
|
||||
blade_session_hangup(value);
|
||||
}
|
||||
ks_hash_read_unlock(bsmgr->sessions);
|
||||
while (ks_hash_count(bsmgr->sessions) > 0) ks_sleep_ms(100);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_session_t *) blade_sessionmgr_session_lookup(blade_sessionmgr_t *bsmgr, const char *id)
|
||||
{
|
||||
blade_session_t *bs = NULL;
|
||||
|
||||
ks_assert(bsmgr);
|
||||
ks_assert(id);
|
||||
|
||||
bs = ks_hash_search(bsmgr->sessions, (void *)id, KS_READLOCKED);
|
||||
if (bs) blade_session_read_lock(bs, KS_TRUE);
|
||||
ks_hash_read_unlock(bsmgr->sessions);
|
||||
|
||||
return bs;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_sessionmgr_session_add(blade_sessionmgr_t *bsmgr, blade_session_t *bs)
|
||||
{
|
||||
char *key = NULL;
|
||||
|
||||
ks_assert(bsmgr);
|
||||
ks_assert(bs);
|
||||
|
||||
key = ks_pstrdup(bsmgr->pool, blade_session_id_get(bs));
|
||||
ks_hash_insert(bsmgr->sessions, (void *)key, bs);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Session Added: %s\n", key);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_sessionmgr_session_remove(blade_sessionmgr_t *bsmgr, blade_session_t *bs)
|
||||
{
|
||||
const char *id = NULL;
|
||||
|
||||
ks_assert(bsmgr);
|
||||
ks_assert(bs);
|
||||
|
||||
blade_session_write_lock(bs, KS_TRUE);
|
||||
|
||||
id = blade_session_id_get(bs);
|
||||
ks_hash_remove(bsmgr->sessions, (void *)id);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Session Removed: %s\n", id);
|
||||
|
||||
blade_subscriptionmgr_subscriber_cleanup(blade_handle_subscriptionmgr_get(bsmgr->handle), id);
|
||||
|
||||
if (blade_upstreammgr_localid_compare(blade_handle_upstreammgr_get(bsmgr->handle), id)) {
|
||||
blade_upstreammgr_localid_set(blade_handle_upstreammgr_get(bsmgr->handle), NULL);
|
||||
blade_upstreammgr_masterid_set(blade_handle_upstreammgr_get(bsmgr->handle), NULL);
|
||||
blade_upstreammgr_realm_clear(blade_handle_upstreammgr_get(bsmgr->handle));
|
||||
}
|
||||
|
||||
blade_session_write_unlock(bs);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_sessionmgr_callback_add(blade_sessionmgr_t *bsmgr, void *data, blade_session_callback_t callback, const char **id)
|
||||
{
|
||||
blade_session_callback_data_t *bscd = NULL;
|
||||
uuid_t uuid;
|
||||
|
||||
ks_assert(bsmgr);
|
||||
ks_assert(callback);
|
||||
ks_assert(id);
|
||||
|
||||
ks_uuid(&uuid);
|
||||
|
||||
bscd = ks_pool_alloc(bsmgr->pool, sizeof(blade_session_callback_data_t));
|
||||
bscd->pool = bsmgr->pool;
|
||||
bscd->id = ks_uuid_str(bsmgr->pool, &uuid);
|
||||
bscd->data = data;
|
||||
bscd->callback = callback;
|
||||
|
||||
ks_pool_set_cleanup(bsmgr->pool, bscd, NULL, blade_session_callback_data_cleanup);
|
||||
|
||||
ks_hash_insert(bsmgr->callbacks, (void *)ks_pstrdup(bscd->pool, bscd->id), bscd);
|
||||
|
||||
*id = bscd->id;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_sessionmgr_callback_remove(blade_sessionmgr_t *bsmgr, const char *id)
|
||||
{
|
||||
ks_assert(bsmgr);
|
||||
ks_assert(id);
|
||||
|
||||
ks_hash_remove(bsmgr->callbacks, (void *)id);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(void) blade_sessionmgr_callback_execute(blade_sessionmgr_t *bsmgr, blade_session_t *bs, blade_session_state_condition_t condition)
|
||||
{
|
||||
ks_assert(bsmgr);
|
||||
ks_assert(bs);
|
||||
|
||||
if (blade_session_state_get(bs) == BLADE_SESSION_STATE_NONE) return;
|
||||
|
||||
ks_hash_read_lock(bsmgr->callbacks);
|
||||
for (ks_hash_iterator_t *it = ks_hash_first(bsmgr->callbacks, KS_UNLOCKED); it; it = ks_hash_next(&it)) {
|
||||
void *key = NULL;
|
||||
blade_session_callback_data_t *value = NULL;
|
||||
|
||||
ks_hash_this(it, (const void **)&key, NULL, (void **)&value);
|
||||
|
||||
value->callback(bs, condition, value->data);
|
||||
}
|
||||
ks_hash_read_unlock(bsmgr->callbacks);
|
||||
}
|
||||
|
||||
/* 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:
|
||||
*/
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,393 @@
|
|||
/*
|
||||
* 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_subscriptionmgr_s {
|
||||
blade_handle_t *handle;
|
||||
ks_pool_t *pool;
|
||||
|
||||
ks_hash_t *subscriptions; // key, blade_subscription_t*
|
||||
ks_hash_t *subscriptions_cleanup; // target, ks_hash_t*
|
||||
|
||||
};
|
||||
|
||||
|
||||
static void blade_subscriptionmgr_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
|
||||
{
|
||||
//blade_routemgr_t *brmgr = (blade_routemgr_t *)ptr;
|
||||
|
||||
//ks_assert(brmgr);
|
||||
|
||||
switch (action) {
|
||||
case KS_MPCL_ANNOUNCE:
|
||||
break;
|
||||
case KS_MPCL_TEARDOWN:
|
||||
break;
|
||||
case KS_MPCL_DESTROY:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_subscriptionmgr_create(blade_subscriptionmgr_t **bsmgrP, blade_handle_t *bh)
|
||||
{
|
||||
ks_pool_t *pool = NULL;
|
||||
blade_subscriptionmgr_t *bsmgr = NULL;
|
||||
|
||||
ks_assert(bsmgrP);
|
||||
|
||||
ks_pool_open(&pool);
|
||||
ks_assert(pool);
|
||||
|
||||
bsmgr = ks_pool_alloc(pool, sizeof(blade_subscriptionmgr_t));
|
||||
bsmgr->handle = bh;
|
||||
bsmgr->pool = pool;
|
||||
|
||||
// @note can let removes free keys and values for subscriptions, both are allocated from the same pool as the hash itself
|
||||
ks_hash_create(&bsmgr->subscriptions, KS_HASH_MODE_CASE_INSENSITIVE, KS_HASH_FLAG_RWLOCK | KS_HASH_FLAG_DUP_CHECK | KS_HASH_FLAG_FREE_KEY | KS_HASH_FLAG_FREE_VALUE, bsmgr->pool);
|
||||
ks_assert(bsmgr->subscriptions);
|
||||
|
||||
ks_hash_create(&bsmgr->subscriptions_cleanup, KS_HASH_MODE_CASE_INSENSITIVE, KS_HASH_FLAG_RWLOCK | KS_HASH_FLAG_DUP_CHECK | KS_HASH_FLAG_FREE_KEY | KS_HASH_FLAG_FREE_VALUE, bsmgr->pool);
|
||||
ks_assert(bsmgr->subscriptions_cleanup);
|
||||
|
||||
ks_pool_set_cleanup(pool, bsmgr, NULL, blade_subscriptionmgr_cleanup);
|
||||
|
||||
*bsmgrP = bsmgr;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_subscriptionmgr_destroy(blade_subscriptionmgr_t **bsmgrP)
|
||||
{
|
||||
blade_subscriptionmgr_t *bsmgr = NULL;
|
||||
ks_pool_t *pool;
|
||||
|
||||
ks_assert(bsmgrP);
|
||||
ks_assert(*bsmgrP);
|
||||
|
||||
bsmgr = *bsmgrP;
|
||||
*bsmgrP = NULL;
|
||||
|
||||
ks_assert(bsmgr);
|
||||
|
||||
pool = bsmgr->pool;
|
||||
|
||||
ks_pool_close(&pool);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_handle_t *) blade_subscriptionmgr_handle_get(blade_subscriptionmgr_t *bsmgr)
|
||||
{
|
||||
ks_assert(bsmgr);
|
||||
return bsmgr->handle;
|
||||
}
|
||||
|
||||
//KS_DECLARE(blade_session_t *) blade_subscriptionmgr_route_lookup(blade_routemgr_t *brmgr, const char *target)
|
||||
//{
|
||||
// blade_session_t *bs = NULL;
|
||||
// const char *router = NULL;
|
||||
//
|
||||
// ks_assert(brmgr);
|
||||
// ks_assert(target);
|
||||
//
|
||||
// router = (const char *)ks_hash_search(brmgr->routes, (void *)target, KS_READLOCKED);
|
||||
// if (router) bs = blade_handle_sessions_lookup(brmgr->handle, router);
|
||||
// ks_hash_read_unlock(brmgr->routes);
|
||||
//
|
||||
// return bs;
|
||||
//}
|
||||
|
||||
KS_DECLARE(blade_subscription_t *) blade_subscriptionmgr_subscription_lookup(blade_subscriptionmgr_t *bsmgr, const char *event, const char *protocol, const char *realm)
|
||||
{
|
||||
blade_subscription_t *bsub = NULL;
|
||||
char *key = NULL;
|
||||
|
||||
ks_assert(bsmgr);
|
||||
ks_assert(event);
|
||||
ks_assert(protocol);
|
||||
ks_assert(realm);
|
||||
|
||||
key = ks_psprintf(bsmgr->pool, "%s@%s/%s", protocol, realm, event);
|
||||
|
||||
bsub = (blade_subscription_t *)ks_hash_search(bsmgr->subscriptions, (void *)key, KS_READLOCKED);
|
||||
// @todo if (bsub) blade_subscription_read_lock(bsub);
|
||||
ks_hash_read_unlock(bsmgr->subscriptions);
|
||||
|
||||
ks_pool_free(bsmgr->pool, &key);
|
||||
|
||||
return bsub;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_bool_t) blade_subscriptionmgr_subscriber_add(blade_subscriptionmgr_t *bsmgr, blade_subscription_t **bsubP, const char *event, const char *protocol, const char *realm, const char *target)
|
||||
{
|
||||
char *key = NULL;
|
||||
blade_subscription_t *bsub = NULL;
|
||||
ks_hash_t *bsub_cleanup = NULL;
|
||||
ks_bool_t propagate = KS_FALSE;
|
||||
|
||||
ks_assert(bsmgr);
|
||||
ks_assert(event);
|
||||
ks_assert(protocol);
|
||||
ks_assert(realm);
|
||||
ks_assert(target);
|
||||
|
||||
key = ks_psprintf(bsmgr->pool, "%s@%s/%s", protocol, realm, event);
|
||||
|
||||
ks_hash_write_lock(bsmgr->subscriptions);
|
||||
|
||||
bsub = (blade_subscription_t *)ks_hash_search(bsmgr->subscriptions, (void *)key, KS_UNLOCKED);
|
||||
|
||||
if (!bsub) {
|
||||
blade_subscription_create(&bsub, bsmgr->pool, event, protocol, realm);
|
||||
ks_assert(bsub);
|
||||
|
||||
ks_hash_insert(bsmgr->subscriptions, (void *)ks_pstrdup(bsmgr->pool, key), bsub);
|
||||
propagate = KS_TRUE;
|
||||
}
|
||||
|
||||
bsub_cleanup = (ks_hash_t *)ks_hash_search(bsmgr->subscriptions_cleanup, (void *)target, KS_UNLOCKED);
|
||||
if (!bsub_cleanup) {
|
||||
ks_hash_create(&bsub_cleanup, KS_HASH_MODE_CASE_INSENSITIVE, KS_HASH_FLAG_RWLOCK | KS_HASH_FLAG_DUP_CHECK | KS_HASH_FLAG_FREE_KEY, bsmgr->pool);
|
||||
ks_assert(bsub_cleanup);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Subscription Added: %s\n", key);
|
||||
ks_hash_insert(bsmgr->subscriptions_cleanup, (void *)ks_pstrdup(bsmgr->pool, target), (void *)bsub_cleanup);
|
||||
}
|
||||
ks_hash_insert(bsub_cleanup, (void *)ks_pstrdup(bsmgr->pool, key), (void *)KS_TRUE);
|
||||
|
||||
blade_subscription_subscribers_add(bsub, target);
|
||||
|
||||
ks_hash_write_unlock(bsmgr->subscriptions);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Subscriber Added: %s to %s\n", target, key);
|
||||
|
||||
ks_pool_free(bsmgr->pool, &key);
|
||||
|
||||
if (bsubP) *bsubP = bsub;
|
||||
|
||||
return propagate;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_bool_t) blade_subscriptionmgr_subscriber_remove(blade_subscriptionmgr_t *bsmgr, blade_subscription_t **bsubP, const char *event, const char *protocol, const char *realm, const char *target)
|
||||
{
|
||||
char *key = NULL;
|
||||
blade_subscription_t *bsub = NULL;
|
||||
ks_hash_t *bsub_cleanup = NULL;
|
||||
ks_bool_t propagate = KS_FALSE;
|
||||
|
||||
ks_assert(bsmgr);
|
||||
ks_assert(event);
|
||||
ks_assert(protocol);
|
||||
ks_assert(realm);
|
||||
ks_assert(target);
|
||||
|
||||
key = ks_psprintf(bsmgr->pool, "%s@%s/%s", protocol, realm, event);
|
||||
|
||||
ks_hash_write_lock(bsmgr->subscriptions);
|
||||
|
||||
bsub = (blade_subscription_t *)ks_hash_search(bsmgr->subscriptions, (void *)key, KS_UNLOCKED);
|
||||
|
||||
if (bsub) {
|
||||
bsub_cleanup = (ks_hash_t *)ks_hash_search(bsmgr->subscriptions_cleanup, (void *)target, KS_UNLOCKED);
|
||||
ks_assert(bsub_cleanup);
|
||||
ks_hash_remove(bsub_cleanup, key);
|
||||
|
||||
if (ks_hash_count(bsub_cleanup) == 0) {
|
||||
ks_hash_remove(bsmgr->subscriptions_cleanup, (void *)target);
|
||||
}
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Subscriber Removed: %s from %s\n", target, key);
|
||||
blade_subscription_subscribers_remove(bsub, target);
|
||||
|
||||
if (ks_hash_count(blade_subscription_subscribers_get(bsub)) == 0) {
|
||||
ks_log(KS_LOG_DEBUG, "Subscription Removed: %s\n", key);
|
||||
ks_hash_remove(bsmgr->subscriptions, (void *)key);
|
||||
propagate = KS_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
ks_hash_write_unlock(bsmgr->subscriptions);
|
||||
|
||||
ks_pool_free(bsmgr->pool, &key);
|
||||
|
||||
if (bsubP) *bsubP = bsub;
|
||||
|
||||
return propagate;
|
||||
}
|
||||
|
||||
KS_DECLARE(void) blade_subscriptionmgr_subscriber_cleanup(blade_subscriptionmgr_t *bsmgr, const char *target)
|
||||
{
|
||||
ks_bool_t unsubbed = KS_FALSE;
|
||||
|
||||
ks_assert(bsmgr);
|
||||
ks_assert(target);
|
||||
|
||||
while (!unsubbed) {
|
||||
ks_hash_t *subscriptions = NULL;
|
||||
const char *event = NULL;
|
||||
const char *protocol = NULL;
|
||||
const char *realm = NULL;
|
||||
|
||||
ks_hash_read_lock(bsmgr->subscriptions);
|
||||
subscriptions = (ks_hash_t *)ks_hash_search(bsmgr->subscriptions_cleanup, (void *)target, KS_UNLOCKED);
|
||||
if (!subscriptions) unsubbed = KS_TRUE;
|
||||
else {
|
||||
void *key = NULL;
|
||||
void *value = NULL;
|
||||
blade_subscription_t *bsub = NULL;
|
||||
|
||||
ks_hash_iterator_t *it = ks_hash_first(subscriptions, KS_UNLOCKED);
|
||||
ks_assert(it);
|
||||
|
||||
ks_hash_this(it, (const void **)&key, NULL, &value);
|
||||
|
||||
bsub = (blade_subscription_t *)ks_hash_search(bsmgr->subscriptions, key, KS_UNLOCKED);
|
||||
ks_assert(bsub);
|
||||
|
||||
// @note allocate these to avoid lifecycle issues when the last subscriber is removed causing the subscription to be removed
|
||||
event = ks_pstrdup(bsmgr->pool, blade_subscription_event_get(bsub));
|
||||
protocol = ks_pstrdup(bsmgr->pool, blade_subscription_protocol_get(bsub));
|
||||
realm = ks_pstrdup(bsmgr->pool, blade_subscription_realm_get(bsub));
|
||||
}
|
||||
ks_hash_read_unlock(bsmgr->subscriptions);
|
||||
|
||||
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);
|
||||
}
|
||||
ks_pool_free(bsmgr->pool, &event);
|
||||
ks_pool_free(bsmgr->pool, &protocol);
|
||||
ks_pool_free(bsmgr->pool, &realm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_subscriptionmgr_broadcast(blade_subscriptionmgr_t *bsmgr, const char *broadcaster_nodeid, const char *excluded_nodeid, const char *event, const char *protocol, const char *realm, cJSON *params, blade_rpc_response_callback_t callback, void *data)
|
||||
{
|
||||
const char *bsub_key = NULL;
|
||||
blade_subscription_t *bsub = NULL;
|
||||
blade_session_t *bs = NULL;
|
||||
|
||||
ks_assert(bsmgr);
|
||||
ks_assert(broadcaster_nodeid);
|
||||
ks_assert(event);
|
||||
ks_assert(protocol);
|
||||
ks_assert(realm);
|
||||
|
||||
bsub_key = ks_psprintf(bsmgr->pool, "%s@%s/%s", protocol, realm, event);
|
||||
|
||||
ks_hash_read_lock(bsmgr->subscriptions);
|
||||
|
||||
bsub = (blade_subscription_t *)ks_hash_search(bsmgr->subscriptions, (void *)bsub_key, KS_UNLOCKED);
|
||||
if (bsub) {
|
||||
ks_hash_t *subscribers = blade_subscription_subscribers_get(bsub);
|
||||
|
||||
ks_assert(subscribers);
|
||||
|
||||
for (ks_hash_iterator_t *it = ks_hash_first(subscribers, KS_UNLOCKED); it; it = ks_hash_next(&it)) {
|
||||
void *key = NULL;
|
||||
void *value = NULL;
|
||||
cJSON *req = NULL;
|
||||
cJSON *req_params = NULL;
|
||||
|
||||
ks_hash_this(it, (const void **)&key, NULL, &value);
|
||||
|
||||
if (excluded_nodeid && !ks_safe_strcasecmp(excluded_nodeid, (const char *)key)) continue;
|
||||
|
||||
if (blade_upstreammgr_localid_compare(blade_handle_upstreammgr_get(bsmgr->handle), (const char *)key)) continue;
|
||||
|
||||
bs = blade_sessionmgr_session_lookup(blade_handle_sessionmgr_get(bsmgr->handle), (const char *)key);
|
||||
if (bs) {
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) broadcast request started\n", blade_session_id_get(bs));
|
||||
|
||||
blade_rpc_request_raw_create(bsmgr->pool, &req, &req_params, NULL, "blade.broadcast");
|
||||
|
||||
cJSON_AddStringToObject(req_params, "broadcaster-nodeid", broadcaster_nodeid);
|
||||
cJSON_AddStringToObject(req_params, "event", event);
|
||||
cJSON_AddStringToObject(req_params, "protocol", protocol);
|
||||
cJSON_AddStringToObject(req_params, "realm", realm);
|
||||
|
||||
if (params) cJSON_AddItemToObject(req_params, "params", cJSON_Duplicate(params, 1));
|
||||
|
||||
blade_session_send(bs, req, callback, data);
|
||||
|
||||
cJSON_Delete(req);
|
||||
|
||||
blade_session_read_unlock(bs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ks_hash_read_unlock(bsmgr->subscriptions);
|
||||
|
||||
ks_pool_free(bsmgr->pool, &bsub_key);
|
||||
|
||||
bs = blade_upstreammgr_session_get(blade_handle_upstreammgr_get(bsmgr->handle));
|
||||
if (bs) {
|
||||
if (!excluded_nodeid || ks_safe_strcasecmp(blade_session_id_get(bs), excluded_nodeid)) {
|
||||
cJSON *req = NULL;
|
||||
cJSON *req_params = NULL;
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) broadcast request started\n", blade_session_id_get(bs));
|
||||
|
||||
blade_rpc_request_raw_create(bsmgr->pool, &req, &req_params, NULL, "blade.broadcast");
|
||||
|
||||
cJSON_AddStringToObject(req_params, "broadcaster-nodeid", broadcaster_nodeid);
|
||||
cJSON_AddStringToObject(req_params, "event", event);
|
||||
cJSON_AddStringToObject(req_params, "protocol", protocol);
|
||||
cJSON_AddStringToObject(req_params, "realm", realm);
|
||||
|
||||
if (params) cJSON_AddItemToObject(req_params, "params", cJSON_Duplicate(params, 1));
|
||||
|
||||
blade_session_send(bs, req, callback, data);
|
||||
|
||||
cJSON_Delete(req);
|
||||
}
|
||||
|
||||
blade_session_read_unlock(bs);
|
||||
}
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/* 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:
|
||||
*/
|
|
@ -476,7 +476,7 @@ void *blade_transport_wss_listeners_thread(ks_thread_t *thread, void *data)
|
|||
}
|
||||
ks_log(KS_LOG_DEBUG, "Connection (%s) started\n", blade_connection_id_get(bc));
|
||||
|
||||
blade_handle_connections_add(bc);
|
||||
blade_connectionmgr_connection_add(blade_handle_connectionmgr_get(btwss->handle), bc);
|
||||
|
||||
blade_connection_state_set(bc, BLADE_CONNECTION_STATE_STARTUP);
|
||||
|
||||
|
@ -577,7 +577,7 @@ ks_status_t blade_transport_wss_onconnect(blade_connection_t **bcP, blade_transp
|
|||
}
|
||||
ks_log(KS_LOG_DEBUG, "Connection (%s) started\n", blade_connection_id_get(bc));
|
||||
|
||||
blade_handle_connections_add(bc);
|
||||
blade_connectionmgr_connection_add(blade_handle_connectionmgr_get(btwss->handle), bc);
|
||||
|
||||
blade_connection_state_set(bc, BLADE_CONNECTION_STATE_STARTUP);
|
||||
|
||||
|
@ -803,7 +803,7 @@ blade_connection_state_hook_t blade_transport_wss_onstate_startup_inbound(blade_
|
|||
}
|
||||
|
||||
if (nodeid) {
|
||||
bs = blade_handle_sessions_lookup(bh, nodeid); // bs comes out read locked if not null to prevent it being cleaned up before we are done
|
||||
bs = blade_sessionmgr_session_lookup(blade_handle_sessionmgr_get(bh), nodeid); // bs comes out read locked if not null to prevent it being cleaned up before we are done
|
||||
if (bs) {
|
||||
if (blade_session_terminating(bs)) {
|
||||
blade_session_read_unlock(bs);
|
||||
|
@ -836,31 +836,21 @@ blade_connection_state_hook_t blade_transport_wss_onstate_startup_inbound(blade_
|
|||
// This is an inbound connection, thus it is always creating a downstream session
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) started\n", nodeid);
|
||||
blade_handle_sessions_add(bs);
|
||||
blade_sessionmgr_session_add(blade_handle_sessionmgr_get(bh), bs);
|
||||
|
||||
// This is primarily to cleanup the routes added to the blade_handle for main routing when a session terminates, these don't have a lot of use otherwise but it will keep the main route table
|
||||
// from having long running write locks when a session cleans up
|
||||
blade_session_route_add(bs, nodeid);
|
||||
// This is the main routing entry to make an identity routable through a session when a message is received for a given identity in this table, these allow efficiently determine which session
|
||||
// a message should pass through when it does not match the local node identities from blade_handle_identity_register(), and must be matched with a call to blade_session_route_add() for cleanup,
|
||||
// additionally when a "blade.register" is received the identity it carries affects these routes along with the sessionid of the downstream session it came through, and "blade.register" would also
|
||||
// This is the main routing entry to make an identity routable through a session when a message is received for a given identity in this table, these allow to efficiently determine which session
|
||||
// a message should pass through when it does not match the local node id from blade_upstreammgr_t, and must be matched with a call to blade_session_route_add() for cleanup, additionally when
|
||||
// a "blade.register" is received the identity it carries affects these routes along with the sessionid of the downstream session it came through, and "blade.register" would also
|
||||
// result in the new identities being added as routes however new entire wildcard subrealm registration would require a special process for matching any identities from those subrealms
|
||||
blade_handle_route_add(bh, nodeid, nodeid);
|
||||
blade_routemgr_route_add(blade_handle_routemgr_get(bh), nodeid, nodeid);
|
||||
|
||||
// iterate the realms from the handle ultimately provided by the master router node, and obtained when establishing upstream sessions (see outbound handler), for each of
|
||||
// these realms an identity based on the sessionid will be created, in the future this process can be adjusted based on authentication which is currently skipped
|
||||
// so for now if a master node provides more than a single realm, all provided realms will be used in addition to any additionally registered identities or entire subrealms
|
||||
realms = blade_handle_realms_get(bh);
|
||||
ks_hash_read_lock(realms);
|
||||
for (it = ks_hash_first(realms, KS_UNLOCKED); it; it = ks_hash_next(&it)) {
|
||||
void *key = NULL;
|
||||
void *value = NULL;
|
||||
|
||||
ks_hash_this(it, (const void **)&key, NULL, &value);
|
||||
|
||||
blade_session_realm_add(bs, (const char *)key);
|
||||
}
|
||||
ks_hash_read_unlock(realms);
|
||||
// iterate and copy the realms ultimately provided by the master router node to the new downstream session, realms are obtained when establishing upstream sessions (see outbound handler), in
|
||||
// the future this process can be adjusted based on authentication which is currently skipped, so for now if a master node provides more than a single realm then all provided realms will be
|
||||
// acceptable for protocol publishing and passing to downstream sessions for their realms
|
||||
blade_upstreammgr_realm_propagate(blade_handle_upstreammgr_get(bh), bs);
|
||||
}
|
||||
|
||||
blade_rpc_response_raw_create(&json_res, &json_result, id);
|
||||
|
@ -869,7 +859,7 @@ blade_connection_state_hook_t blade_transport_wss_onstate_startup_inbound(blade_
|
|||
cJSON_AddStringToObject(json_result, "nodeid", nodeid);
|
||||
|
||||
pool = blade_handle_pool_get(bh);
|
||||
master_nodeid = blade_handle_master_nodeid_copy(bh, pool);
|
||||
blade_upstreammgr_masterid_copy(blade_handle_upstreammgr_get(bh), pool, &master_nodeid);
|
||||
if (!master_nodeid) {
|
||||
ks_log(KS_LOG_DEBUG, "Master nodeid unavailable\n");
|
||||
blade_transport_wss_rpc_error_send(bc, id, -32602, "Master nodeid unavailable");
|
||||
|
@ -1041,7 +1031,7 @@ blade_connection_state_hook_t blade_transport_wss_onstate_startup_outbound(blade
|
|||
|
||||
|
||||
// @todo validate uuid format by parsing, not currently available in uuid functions
|
||||
bs = blade_handle_sessions_lookup(bh, nodeid); // bs comes out read locked if not null to prevent it being cleaned up before we are done
|
||||
bs = blade_sessionmgr_session_lookup(blade_handle_sessionmgr_get(bh), nodeid); // bs comes out read locked if not null to prevent it being cleaned up before we are done
|
||||
if (bs) {
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) located\n", blade_session_id_get(bs));
|
||||
}
|
||||
|
@ -1064,7 +1054,7 @@ blade_connection_state_hook_t blade_transport_wss_onstate_startup_outbound(blade
|
|||
|
||||
// This is an outbound connection, thus it is always creating an upstream session, defined by the sessionid matching the local_nodeid in the handle
|
||||
|
||||
if (blade_handle_local_nodeid_set(bh, nodeid) != KS_STATUS_SUCCESS) {
|
||||
if (blade_upstreammgr_localid_set(blade_handle_upstreammgr_get(bh), nodeid) != KS_STATUS_SUCCESS) {
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) abandoned, upstream already available\n", blade_session_id_get(bs));
|
||||
blade_session_read_unlock(bs);
|
||||
blade_session_hangup(bs);
|
||||
|
@ -1074,14 +1064,14 @@ blade_connection_state_hook_t blade_transport_wss_onstate_startup_outbound(blade
|
|||
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) started\n", blade_session_id_get(bs));
|
||||
|
||||
blade_handle_sessions_add(bs);
|
||||
blade_sessionmgr_session_add(blade_handle_sessionmgr_get(bh), bs);
|
||||
|
||||
blade_handle_master_nodeid_set(bh, master_nodeid);
|
||||
blade_upstreammgr_masterid_set(blade_handle_upstreammgr_get(bh), master_nodeid);
|
||||
|
||||
// iterate realms and register to handle as permitted realms for future registrations
|
||||
for (int index = 0; index < json_result_realms_size; ++index) {
|
||||
cJSON *elem = cJSON_GetArrayItem(json_result_realms, index);
|
||||
blade_handle_realm_register(bh, elem->valuestring);
|
||||
blade_upstreammgr_realm_add(blade_handle_upstreammgr_get(bh), elem->valuestring);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,236 @@
|
|||
/*
|
||||
* 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_transportmgr_s {
|
||||
blade_handle_t *handle;
|
||||
ks_pool_t *pool;
|
||||
|
||||
ks_hash_t *transports; // name, blade_transport_t*
|
||||
blade_transport_t *default_transport; // default wss transport
|
||||
};
|
||||
|
||||
|
||||
static void blade_transportmgr_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
|
||||
{
|
||||
blade_transportmgr_t *btmgr = (blade_transportmgr_t *)ptr;
|
||||
ks_hash_iterator_t *it = NULL;
|
||||
|
||||
ks_assert(btmgr);
|
||||
|
||||
switch (action) {
|
||||
case KS_MPCL_ANNOUNCE:
|
||||
break;
|
||||
case KS_MPCL_TEARDOWN:
|
||||
while ((it = ks_hash_first(btmgr->transports, KS_UNLOCKED)) != NULL) {
|
||||
void *key = NULL;
|
||||
blade_transport_t *value = NULL;
|
||||
|
||||
ks_hash_this(it, (const void **)&key, NULL, (void **)&value);
|
||||
ks_hash_remove(btmgr->transports, key);
|
||||
|
||||
blade_transport_destroy(&value); // must call destroy to close the transport pool, using FREE_VALUE on the hash would attempt to free the transport from the wrong pool
|
||||
}
|
||||
break;
|
||||
case KS_MPCL_DESTROY:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_transportmgr_create(blade_transportmgr_t **btmgrP, blade_handle_t *bh)
|
||||
{
|
||||
ks_pool_t *pool = NULL;
|
||||
blade_transportmgr_t *btmgr = NULL;
|
||||
|
||||
ks_assert(btmgrP);
|
||||
|
||||
ks_pool_open(&pool);
|
||||
ks_assert(pool);
|
||||
|
||||
btmgr = ks_pool_alloc(pool, sizeof(blade_transportmgr_t));
|
||||
btmgr->handle = bh;
|
||||
btmgr->pool = pool;
|
||||
|
||||
ks_hash_create(&btmgr->transports, KS_HASH_MODE_CASE_INSENSITIVE, KS_HASH_FLAG_RWLOCK | KS_HASH_FLAG_DUP_CHECK | KS_HASH_FLAG_FREE_KEY, btmgr->pool);
|
||||
ks_assert(btmgr->transports);
|
||||
|
||||
ks_pool_set_cleanup(pool, btmgr, NULL, blade_transportmgr_cleanup);
|
||||
|
||||
*btmgrP = btmgr;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_transportmgr_destroy(blade_transportmgr_t **btmgrP)
|
||||
{
|
||||
blade_transportmgr_t *btmgr = NULL;
|
||||
ks_pool_t *pool;
|
||||
|
||||
ks_assert(btmgrP);
|
||||
ks_assert(*btmgrP);
|
||||
|
||||
btmgr = *btmgrP;
|
||||
*btmgrP = NULL;
|
||||
|
||||
ks_assert(btmgr);
|
||||
|
||||
pool = btmgr->pool;
|
||||
|
||||
ks_pool_close(&pool);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_transportmgr_startup(blade_transportmgr_t *btmgr, config_setting_t *config)
|
||||
{
|
||||
ks_assert(btmgr);
|
||||
|
||||
for (ks_hash_iterator_t *it = ks_hash_first(btmgr->transports, KS_UNLOCKED); it; it = ks_hash_next(&it)) {
|
||||
void *key = NULL;
|
||||
blade_transport_t *value = NULL;
|
||||
blade_transport_callbacks_t *callbacks = NULL;
|
||||
|
||||
ks_hash_this(it, (const void **)&key, NULL, (void **)&value);
|
||||
|
||||
callbacks = blade_transport_callbacks_get(value);
|
||||
ks_assert(callbacks);
|
||||
|
||||
if (callbacks->onstartup) callbacks->onstartup(value, config);
|
||||
}
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_transportmgr_shutdown(blade_transportmgr_t *btmgr)
|
||||
{
|
||||
ks_assert(btmgr);
|
||||
|
||||
ks_hash_read_lock(btmgr->transports);
|
||||
for (ks_hash_iterator_t *it = ks_hash_first(btmgr->transports, KS_UNLOCKED); it; it = ks_hash_next(&it)) {
|
||||
void *key = NULL;
|
||||
blade_transport_t *value = NULL;
|
||||
blade_transport_callbacks_t *callbacks = NULL;
|
||||
|
||||
ks_hash_this(it, (const void **)&key, NULL, (void **)&value);
|
||||
|
||||
callbacks = blade_transport_callbacks_get(value);
|
||||
ks_assert(callbacks);
|
||||
|
||||
if (callbacks->onshutdown) callbacks->onshutdown(value);
|
||||
}
|
||||
ks_hash_read_unlock(btmgr->transports);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_handle_t *) blade_transportmgr_handle_get(blade_transportmgr_t *btmgr)
|
||||
{
|
||||
ks_assert(btmgr);
|
||||
|
||||
return btmgr->handle;
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_transport_t *) blade_transportmgr_default_get(blade_transportmgr_t *btmgr)
|
||||
{
|
||||
ks_assert(btmgr);
|
||||
|
||||
return btmgr->default_transport;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_transportmgr_default_set(blade_transportmgr_t *btmgr, blade_transport_t *bt)
|
||||
{
|
||||
ks_assert(btmgr);
|
||||
ks_assert(bt);
|
||||
|
||||
btmgr->default_transport = bt;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_transport_t *) blade_transportmgr_transport_lookup(blade_transportmgr_t *btmgr, const char *name, ks_bool_t ordefault)
|
||||
{
|
||||
blade_transport_t *bt = NULL;
|
||||
|
||||
ks_assert(btmgr);
|
||||
|
||||
if (name && name[0]) bt = (blade_transport_t *)ks_hash_search(btmgr->transports, (void *)name, KS_READLOCKED);
|
||||
if (!bt && ordefault) bt = btmgr->default_transport;
|
||||
// @todo if (bt) blade_transport_read_lock(bt);
|
||||
ks_hash_read_unlock(btmgr->transports);
|
||||
|
||||
return bt;
|
||||
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_transportmgr_transport_add(blade_transportmgr_t *btmgr, blade_transport_t *bt)
|
||||
{
|
||||
char *key = NULL;
|
||||
|
||||
ks_assert(btmgr);
|
||||
ks_assert(bt);
|
||||
|
||||
key = ks_pstrdup(btmgr->pool, blade_transport_name_get(bt));
|
||||
ks_hash_insert(btmgr->transports, (void *)key, (void *)bt);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Transport Added: %s\n", key);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_transportmgr_transport_remove(blade_transportmgr_t *btmgr, blade_transport_t *bt)
|
||||
{
|
||||
const char *name = NULL;
|
||||
|
||||
ks_assert(btmgr);
|
||||
ks_assert(bt);
|
||||
|
||||
name = blade_transport_name_get(bt);
|
||||
ks_hash_remove(btmgr->transports, (void *)name);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Transport Removed: %s\n", name);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/* 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:
|
||||
*/
|
|
@ -0,0 +1,323 @@
|
|||
/*
|
||||
* 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_upstreammgr_s {
|
||||
blade_handle_t *handle;
|
||||
ks_pool_t *pool;
|
||||
|
||||
// local node id, can be used to get the upstream session, provided by upstream "blade.connect" response
|
||||
const char *localid;
|
||||
ks_rwl_t *localid_rwl;
|
||||
|
||||
// master node id, provided by upstream "blade.connect" response
|
||||
const char *masterid;
|
||||
ks_rwl_t *masterid_rwl;
|
||||
|
||||
// realms for new nodes, these originate from the master, and are provided by upstream session "blade.connect" response
|
||||
ks_hash_t *realms;
|
||||
};
|
||||
|
||||
|
||||
static void blade_upstreammgr_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
|
||||
{
|
||||
//blade_upstreammgr_t *bumgr = (blade_upstreammgr_t *)ptr;
|
||||
|
||||
//ks_assert(brmgr);
|
||||
|
||||
switch (action) {
|
||||
case KS_MPCL_ANNOUNCE:
|
||||
break;
|
||||
case KS_MPCL_TEARDOWN:
|
||||
break;
|
||||
case KS_MPCL_DESTROY:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_upstreammgr_create(blade_upstreammgr_t **bumgrP, blade_handle_t *bh)
|
||||
{
|
||||
ks_pool_t *pool = NULL;
|
||||
blade_upstreammgr_t *bumgr = NULL;
|
||||
|
||||
ks_assert(bumgrP);
|
||||
|
||||
ks_pool_open(&pool);
|
||||
ks_assert(pool);
|
||||
|
||||
bumgr = ks_pool_alloc(pool, sizeof(blade_upstreammgr_t));
|
||||
bumgr->handle = bh;
|
||||
bumgr->pool = pool;
|
||||
|
||||
//ks_hash_create(&bumgr->routes, KS_HASH_MODE_CASE_INSENSITIVE, KS_HASH_FLAG_RWLOCK | KS_HASH_FLAG_DUP_CHECK | KS_HASH_FLAG_FREE_KEY | KS_HASH_FLAG_FREE_VALUE, bumgr->pool);
|
||||
//ks_assert(bumgr->routes);
|
||||
ks_rwl_create(&bumgr->localid_rwl, bumgr->pool);
|
||||
ks_assert(bumgr->localid_rwl);
|
||||
|
||||
ks_rwl_create(&bumgr->masterid_rwl, bumgr->pool);
|
||||
ks_assert(bumgr->masterid_rwl);
|
||||
|
||||
ks_hash_create(&bumgr->realms, KS_HASH_MODE_CASE_INSENSITIVE, KS_HASH_FLAG_RWLOCK | KS_HASH_FLAG_DUP_CHECK | KS_HASH_FLAG_FREE_KEY, bumgr->pool);
|
||||
ks_assert(bumgr->realms);
|
||||
|
||||
ks_pool_set_cleanup(pool, bumgr, NULL, blade_upstreammgr_cleanup);
|
||||
|
||||
*bumgrP = bumgr;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_upstreammgr_destroy(blade_upstreammgr_t **bumgrP)
|
||||
{
|
||||
blade_upstreammgr_t *bumgr = NULL;
|
||||
ks_pool_t *pool;
|
||||
|
||||
ks_assert(bumgrP);
|
||||
ks_assert(*bumgrP);
|
||||
|
||||
bumgr = *bumgrP;
|
||||
*bumgrP = NULL;
|
||||
|
||||
ks_assert(bumgr);
|
||||
|
||||
pool = bumgr->pool;
|
||||
|
||||
ks_pool_close(&pool);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_handle_t *) blade_upstreammgr_handle_get(blade_upstreammgr_t *bumgr)
|
||||
{
|
||||
ks_assert(bumgr);
|
||||
return bumgr->handle;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_upstreammgr_localid_set(blade_upstreammgr_t *bumgr, const char *id)
|
||||
{
|
||||
ks_status_t ret = KS_STATUS_SUCCESS;
|
||||
|
||||
ks_assert(bumgr);
|
||||
|
||||
ks_rwl_write_lock(bumgr->localid_rwl);
|
||||
if (bumgr->localid && id) {
|
||||
ret = KS_STATUS_NOT_ALLOWED;
|
||||
goto done;
|
||||
}
|
||||
if (!bumgr->localid && !id) {
|
||||
ret = KS_STATUS_DISCONNECTED;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (bumgr->localid) ks_pool_free(bumgr->pool, &bumgr->localid);
|
||||
if (id) bumgr->localid = ks_pstrdup(bumgr->pool, id);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "LocalID: %s\n", id);
|
||||
|
||||
done:
|
||||
ks_rwl_write_unlock(bumgr->localid_rwl);
|
||||
return ret;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_bool_t) blade_upstreammgr_localid_compare(blade_upstreammgr_t *bumgr, const char *id)
|
||||
{
|
||||
ks_bool_t ret = KS_FALSE;
|
||||
|
||||
ks_assert(bumgr);
|
||||
ks_assert(id);
|
||||
|
||||
ks_rwl_read_lock(bumgr->localid_rwl);
|
||||
ret = ks_safe_strcasecmp(bumgr->localid, id) == 0;
|
||||
ks_rwl_read_unlock(bumgr->localid_rwl);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_upstreammgr_localid_copy(blade_upstreammgr_t *bumgr, ks_pool_t *pool, const char **id)
|
||||
{
|
||||
ks_assert(bumgr);
|
||||
ks_assert(pool);
|
||||
ks_assert(id);
|
||||
|
||||
*id = NULL;
|
||||
|
||||
ks_rwl_read_lock(bumgr->localid_rwl);
|
||||
if (bumgr->localid) *id = ks_pstrdup(pool, bumgr->localid);
|
||||
ks_rwl_read_unlock(bumgr->localid_rwl);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_bool_t) blade_upstreammgr_session_established(blade_upstreammgr_t *bumgr)
|
||||
{
|
||||
ks_bool_t ret = KS_FALSE;
|
||||
|
||||
ks_assert(bumgr);
|
||||
|
||||
ks_rwl_read_lock(bumgr->localid_rwl);
|
||||
ret = bumgr->localid != NULL;
|
||||
ks_rwl_read_unlock(bumgr->localid_rwl);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
KS_DECLARE(blade_session_t *) blade_upstreammgr_session_get(blade_upstreammgr_t *bumgr)
|
||||
{
|
||||
blade_session_t *bs = NULL;
|
||||
|
||||
ks_assert(bumgr);
|
||||
|
||||
ks_rwl_read_lock(bumgr->localid_rwl);
|
||||
if (bumgr->localid) bs = blade_sessionmgr_session_lookup(blade_handle_sessionmgr_get(bumgr->handle), bumgr->localid);
|
||||
ks_rwl_read_unlock(bumgr->localid_rwl);
|
||||
|
||||
return bs;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_upstreammgr_masterid_set(blade_upstreammgr_t *bumgr, const char *id)
|
||||
{
|
||||
ks_status_t ret = KS_STATUS_SUCCESS;
|
||||
|
||||
ks_assert(bumgr);
|
||||
|
||||
ks_rwl_write_lock(bumgr->masterid_rwl);
|
||||
if (bumgr->masterid) ks_pool_free(bumgr->pool, &bumgr->masterid);
|
||||
if (id) bumgr->masterid = ks_pstrdup(bumgr->pool, id);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "MasterID: %s\n", id);
|
||||
|
||||
ks_rwl_write_unlock(bumgr->masterid_rwl);
|
||||
return ret;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_bool_t) blade_upstreammgr_masterid_compare(blade_upstreammgr_t *bumgr, const char *id)
|
||||
{
|
||||
ks_bool_t ret = KS_FALSE;
|
||||
|
||||
ks_assert(bumgr);
|
||||
ks_assert(id);
|
||||
|
||||
ks_rwl_read_lock(bumgr->masterid_rwl);
|
||||
ret = ks_safe_strcasecmp(bumgr->masterid, id) == 0;
|
||||
ks_rwl_read_unlock(bumgr->masterid_rwl);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_upstreammgr_masterid_copy(blade_upstreammgr_t *bumgr, ks_pool_t *pool, const char **id)
|
||||
{
|
||||
ks_assert(bumgr);
|
||||
ks_assert(pool);
|
||||
ks_assert(id);
|
||||
|
||||
*id = NULL;
|
||||
|
||||
ks_rwl_read_lock(bumgr->masterid_rwl);
|
||||
if (bumgr->masterid) *id = ks_pstrdup(pool, bumgr->masterid);
|
||||
ks_rwl_read_unlock(bumgr->masterid_rwl);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_upstreammgr_realm_add(blade_upstreammgr_t *bumgr, const char *realm)
|
||||
{
|
||||
char *key = NULL;
|
||||
|
||||
ks_assert(bumgr);
|
||||
ks_assert(realm);
|
||||
|
||||
key = ks_pstrdup(bumgr->pool, realm);
|
||||
ks_hash_insert(bumgr->realms, (void *)key, (void *)KS_TRUE);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Realm Added: %s\n", key);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_upstreammgr_realm_remove(blade_upstreammgr_t *bumgr, const char *realm)
|
||||
{
|
||||
ks_assert(bumgr);
|
||||
ks_assert(realm);
|
||||
|
||||
ks_hash_remove(bumgr->realms, (void *)realm);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Realm Removed: %s\n", realm);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_upstreammgr_realm_clear(blade_upstreammgr_t *bumgr)
|
||||
{
|
||||
ks_hash_iterator_t *it = NULL;
|
||||
|
||||
ks_assert(bumgr);
|
||||
|
||||
while ((it = ks_hash_first(bumgr->realms, KS_UNLOCKED))) {
|
||||
void *key = NULL;
|
||||
void *value = NULL;
|
||||
ks_hash_this(it, (const void **)&key, NULL, &value);
|
||||
ks_log(KS_LOG_DEBUG, "Realm Removed: %s\n", key);
|
||||
ks_hash_remove(bumgr->realms, key);
|
||||
}
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_upstreammgr_realm_propagate(blade_upstreammgr_t *bumgr, blade_session_t *bs)
|
||||
{
|
||||
ks_assert(bumgr);
|
||||
ks_assert(bs);
|
||||
|
||||
ks_hash_read_lock(bumgr->realms);
|
||||
for (ks_hash_iterator_t *it = ks_hash_first(bumgr->realms, KS_UNLOCKED); it; it = ks_hash_next(&it)) {
|
||||
void *key = NULL;
|
||||
void *value = NULL;
|
||||
ks_hash_this(it, (const void **)&key, NULL, &value);
|
||||
blade_session_realm_add(bs, (const char *)key);
|
||||
}
|
||||
ks_hash_read_unlock(bumgr->realms);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/* 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:
|
||||
*/
|
|
@ -47,6 +47,15 @@
|
|||
#include "blade_protocol.h"
|
||||
#include "blade_subscription.h"
|
||||
|
||||
#include "blade_transportmgr.h"
|
||||
#include "blade_rpcmgr.h"
|
||||
#include "blade_routemgr.h"
|
||||
#include "blade_subscriptionmgr.h"
|
||||
#include "blade_upstreammgr.h"
|
||||
#include "blade_mastermgr.h"
|
||||
#include "blade_connectionmgr.h"
|
||||
#include "blade_sessionmgr.h"
|
||||
|
||||
#include "blade_transport_wss.h"
|
||||
|
||||
KS_BEGIN_EXTERN_C
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* 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_CONNECTIONMGR_H_
|
||||
#define _BLADE_CONNECTIONMGR_H_
|
||||
#include <blade.h>
|
||||
|
||||
KS_BEGIN_EXTERN_C
|
||||
KS_DECLARE(ks_status_t) blade_connectionmgr_create(blade_connectionmgr_t **bcmgrP, blade_handle_t *bh);
|
||||
KS_DECLARE(ks_status_t) blade_connectionmgr_destroy(blade_connectionmgr_t **bcmgrP);
|
||||
KS_DECLARE(blade_handle_t *) blade_connectionmgr_handle_get(blade_connectionmgr_t *bcmgr);
|
||||
KS_DECLARE(ks_status_t) blade_connectionmgr_shutdown(blade_connectionmgr_t *bcmgr);
|
||||
KS_DECLARE(blade_connection_t *) blade_connectionmgr_connection_lookup(blade_connectionmgr_t *bcmgr, const char *id);
|
||||
KS_DECLARE(ks_status_t) blade_connectionmgr_connection_add(blade_connectionmgr_t *bcmgr, blade_connection_t *bc);
|
||||
KS_DECLARE(ks_status_t) blade_connectionmgr_connection_remove(blade_connectionmgr_t *bcmgr, blade_connection_t *bc);
|
||||
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:
|
||||
*/
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* 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_MASTERMGR_H_
|
||||
#define _BLADE_MASTERMGR_H_
|
||||
#include <blade.h>
|
||||
|
||||
KS_BEGIN_EXTERN_C
|
||||
KS_DECLARE(ks_status_t) blade_mastermgr_create(blade_mastermgr_t **bmmgrP, blade_handle_t *bh);
|
||||
KS_DECLARE(ks_status_t) blade_mastermgr_destroy(blade_mastermgr_t **bmmgrP);
|
||||
KS_DECLARE(blade_handle_t *) blade_mastermgr_handle_get(blade_mastermgr_t *bmmgr);
|
||||
KS_DECLARE(blade_protocol_t *) blade_mastermgr_protocol_lookup(blade_mastermgr_t *bmmgr, const char *protocol, const char *realm);
|
||||
KS_DECLARE(ks_status_t) blade_mastermgr_controller_add(blade_mastermgr_t *bmmgr, const char *protocol, const char *realm, const char *controller);
|
||||
KS_DECLARE(ks_status_t) blade_mastermgr_controller_remove(blade_mastermgr_t *bmmgr, const char *controller);
|
||||
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:
|
||||
*/
|
|
@ -38,9 +38,9 @@
|
|||
KS_BEGIN_EXTERN_C
|
||||
KS_DECLARE(ks_status_t) blade_protocol_create(blade_protocol_t **bpP, ks_pool_t *pool, const char *name, const char *realm);
|
||||
KS_DECLARE(ks_status_t) blade_protocol_destroy(blade_protocol_t **bpP);
|
||||
KS_DECLARE(ks_hash_t *) blade_protocol_providers_get(blade_protocol_t *bp);
|
||||
KS_DECLARE(ks_status_t) blade_protocol_providers_add(blade_protocol_t *bp, const char *nodeid);
|
||||
KS_DECLARE(ks_status_t) blade_protocol_providers_remove(blade_protocol_t *bp, const char *nodeid);
|
||||
KS_DECLARE(ks_hash_t *) blade_protocol_controllers_get(blade_protocol_t *bp);
|
||||
KS_DECLARE(ks_status_t) blade_protocol_controllers_add(blade_protocol_t *bp, const char *nodeid);
|
||||
KS_DECLARE(ks_status_t) blade_protocol_controllers_remove(blade_protocol_t *bp, const char *nodeid);
|
||||
KS_END_EXTERN_C
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* 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_ROUTEMGR_H_
|
||||
#define _BLADE_ROUTEMGR_H_
|
||||
#include <blade.h>
|
||||
|
||||
KS_BEGIN_EXTERN_C
|
||||
KS_DECLARE(ks_status_t) blade_routemgr_create(blade_routemgr_t **brmgrP, blade_handle_t *bh);
|
||||
KS_DECLARE(ks_status_t) blade_routemgr_destroy(blade_routemgr_t **brmgrP);
|
||||
KS_DECLARE(blade_handle_t *) blade_routemgr_handle_get(blade_routemgr_t *brmgr);
|
||||
KS_DECLARE(blade_session_t *) blade_routemgr_route_lookup(blade_routemgr_t *brmgr, const char *target);
|
||||
KS_DECLARE(ks_status_t) blade_routemgr_route_add(blade_routemgr_t *brmgr, const char *target, const char *router);
|
||||
KS_DECLARE(ks_status_t) blade_routemgr_route_remove(blade_routemgr_t *brmgr, const char *target);
|
||||
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:
|
||||
*/
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* 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_RPCMGR_H_
|
||||
#define _BLADE_RPCMGR_H_
|
||||
#include <blade.h>
|
||||
|
||||
KS_BEGIN_EXTERN_C
|
||||
KS_DECLARE(ks_status_t) blade_rpcmgr_create(blade_rpcmgr_t **brpcmgrP, blade_handle_t *bh);
|
||||
KS_DECLARE(ks_status_t) blade_rpcmgr_destroy(blade_rpcmgr_t **brpcmgrP);
|
||||
KS_DECLARE(blade_handle_t *) blade_rpcmgr_handle_get(blade_rpcmgr_t *brpcmgr);
|
||||
KS_DECLARE(blade_rpc_t *) blade_rpcmgr_corerpc_lookup(blade_rpcmgr_t *brpcmgr, const char *method);
|
||||
KS_DECLARE(ks_status_t) blade_rpcmgr_corerpc_add(blade_rpcmgr_t *brpcmgr, blade_rpc_t *brpc);
|
||||
KS_DECLARE(ks_status_t) blade_rpcmgr_corerpc_remove(blade_rpcmgr_t *brpcmgr, blade_rpc_t *brpc);
|
||||
KS_DECLARE(blade_rpc_t *) blade_rpcmgr_protocolrpc_lookup(blade_rpcmgr_t *brpcmgr, const char *method, const char *protocol, const char *realm);
|
||||
KS_DECLARE(ks_status_t) blade_rpcmgr_protocolrpc_add(blade_rpcmgr_t *brpcmgr, blade_rpc_t *brpc);
|
||||
KS_DECLARE(ks_status_t) blade_rpcmgr_protocolrpc_remove(blade_rpcmgr_t *brpcmgr, blade_rpc_t *brpc);
|
||||
KS_DECLARE(blade_rpc_request_t *) blade_rpcmgr_request_lookup(blade_rpcmgr_t *brpcmgr, const char *id);
|
||||
KS_DECLARE(ks_status_t) blade_rpcmgr_request_add(blade_rpcmgr_t *brpcmgr, blade_rpc_request_t *brpcreq);
|
||||
KS_DECLARE(ks_status_t) blade_rpcmgr_request_remove(blade_rpcmgr_t *brpcmgr, blade_rpc_request_t *brpcreq);
|
||||
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:
|
||||
*/
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* 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_SESSIONMGR_H_
|
||||
#define _BLADE_SESSIONMGR_H_
|
||||
#include <blade.h>
|
||||
|
||||
KS_BEGIN_EXTERN_C
|
||||
KS_DECLARE(ks_status_t) blade_sessionmgr_create(blade_sessionmgr_t **bsmgrP, blade_handle_t *bh);
|
||||
KS_DECLARE(ks_status_t) blade_sessionmgr_destroy(blade_sessionmgr_t **bsmgrP);
|
||||
KS_DECLARE(blade_handle_t *) blade_sessionmgr_handle_get(blade_sessionmgr_t *bsmgr);
|
||||
KS_DECLARE(ks_status_t) blade_sessionmgr_shutdown(blade_sessionmgr_t *bsmgr);
|
||||
KS_DECLARE(blade_session_t *) blade_sessionmgr_session_lookup(blade_sessionmgr_t *bsmgr, const char *id);
|
||||
KS_DECLARE(ks_status_t) blade_sessionmgr_session_add(blade_sessionmgr_t *bsmgr, blade_session_t *bs);
|
||||
KS_DECLARE(ks_status_t) blade_sessionmgr_session_remove(blade_sessionmgr_t *bsmgr, blade_session_t *bs);
|
||||
KS_DECLARE(ks_status_t) blade_sessionmgr_callback_add(blade_sessionmgr_t *bsmgr, void *data, blade_session_callback_t callback, const char **id);
|
||||
KS_DECLARE(ks_status_t) blade_sessionmgr_callback_remove(blade_sessionmgr_t *bsmgr, const char *id);
|
||||
KS_DECLARE(void) blade_sessionmgr_callback_execute(blade_sessionmgr_t *bsmgr, blade_session_t *bs, blade_session_state_condition_t condition);
|
||||
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:
|
||||
*/
|
|
@ -48,56 +48,17 @@ KS_DECLARE(ks_status_t) blade_handle_shutdown(blade_handle_t *bh);
|
|||
KS_DECLARE(ks_pool_t *) blade_handle_pool_get(blade_handle_t *bh);
|
||||
KS_DECLARE(ks_thread_pool_t *) blade_handle_tpool_get(blade_handle_t *bh);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_handle_local_nodeid_set(blade_handle_t *bh, const char *nodeid);
|
||||
KS_DECLARE(ks_bool_t) blade_handle_local_nodeid_compare(blade_handle_t *bh, const char *nodeid);
|
||||
|
||||
KS_DECLARE(const char *) blade_handle_master_nodeid_copy(blade_handle_t *bh, ks_pool_t *pool);
|
||||
KS_DECLARE(ks_status_t) blade_handle_master_nodeid_set(blade_handle_t *bh, const char *nodeid);
|
||||
KS_DECLARE(ks_bool_t) blade_handle_master_nodeid_compare(blade_handle_t *bh, const char *nodeid);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_handle_realm_register(blade_handle_t *bh, const char *realm);
|
||||
KS_DECLARE(ks_status_t) blade_handle_realm_unregister(blade_handle_t *bh, const char *realm);
|
||||
KS_DECLARE(ks_hash_t *) blade_handle_realms_get(blade_handle_t *bh);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_handle_route_add(blade_handle_t *bh, const char *nodeid, const char *sessionid);
|
||||
KS_DECLARE(ks_status_t) blade_handle_route_remove(blade_handle_t *bh, const char *nodeid);
|
||||
KS_DECLARE(blade_session_t *) blade_handle_route_lookup(blade_handle_t *bh, const char *nodeid);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_handle_transport_register(blade_transport_t *bt);
|
||||
KS_DECLARE(ks_status_t) blade_handle_transport_unregister(blade_transport_t *bt);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_handle_corerpc_register(blade_rpc_t *brpc);
|
||||
KS_DECLARE(ks_status_t) blade_handle_corerpc_unregister(blade_rpc_t *brpc);
|
||||
KS_DECLARE(blade_rpc_t *) blade_handle_corerpc_lookup(blade_handle_t *bh, const char *method);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_handle_requests_add(blade_rpc_request_t *brpcreq);
|
||||
KS_DECLARE(ks_status_t) blade_handle_requests_remove(blade_rpc_request_t *brpcreq);
|
||||
KS_DECLARE(blade_rpc_request_t *) blade_handle_requests_lookup(blade_handle_t *bh, const char *id);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_handle_protocolrpc_register(blade_rpc_t *brpc);
|
||||
KS_DECLARE(ks_status_t) blade_handle_protocolrpc_unregister(blade_rpc_t *brpc);
|
||||
KS_DECLARE(blade_rpc_t *) blade_handle_protocolrpc_lookup(blade_handle_t *bh, const char *method, const char *protocol, const char *realm);
|
||||
|
||||
KS_DECLARE(ks_bool_t) blade_handle_subscriber_add(blade_handle_t *bh, blade_subscription_t **bsubP, const char *event, const char *protocol, const char *realm, const char *nodeid);
|
||||
KS_DECLARE(ks_bool_t) blade_handle_subscriber_remove(blade_handle_t *bh, blade_subscription_t **bsubP, const char *event, const char *protocol, const char *realm, const char *nodeid);
|
||||
|
||||
KS_DECLARE(blade_transportmgr_t *) blade_handle_transportmgr_get(blade_handle_t *bh);
|
||||
KS_DECLARE(blade_rpcmgr_t *) blade_handle_rpcmgr_get(blade_handle_t *bh);
|
||||
KS_DECLARE(blade_routemgr_t *) blade_handle_routemgr_get(blade_handle_t *bh);
|
||||
KS_DECLARE(blade_subscriptionmgr_t *) blade_handle_subscriptionmgr_get(blade_handle_t *bh);
|
||||
KS_DECLARE(blade_upstreammgr_t *) blade_handle_upstreammgr_get(blade_handle_t *bh);
|
||||
KS_DECLARE(blade_mastermgr_t *) blade_handle_mastermgr_get(blade_handle_t *bh);
|
||||
KS_DECLARE(blade_connectionmgr_t *) blade_handle_connectionmgr_get(blade_handle_t *bh);
|
||||
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_handle_connections_add(blade_connection_t *bc);
|
||||
KS_DECLARE(ks_status_t) blade_handle_connections_remove(blade_connection_t *bc);
|
||||
KS_DECLARE(blade_connection_t *) blade_handle_connections_lookup(blade_handle_t *bh, const char *id);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_handle_sessions_add(blade_session_t *bs);
|
||||
KS_DECLARE(ks_status_t) blade_handle_sessions_remove(blade_session_t *bs);
|
||||
KS_DECLARE(blade_session_t *) blade_handle_sessions_lookup(blade_handle_t *bh, const char *id);
|
||||
KS_DECLARE(blade_session_t *) blade_handle_sessions_upstream(blade_handle_t *bh);
|
||||
KS_DECLARE(void) blade_handle_sessions_send(blade_handle_t *bh, ks_list_t *sessions, const char *exclude, cJSON *json);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_handle_session_state_callback_register(blade_handle_t *bh, void *data, blade_session_state_callback_t callback, const char **id);
|
||||
KS_DECLARE(ks_status_t) blade_handle_session_state_callback_unregister(blade_handle_t *bh, const char *id);
|
||||
KS_DECLARE(void) blade_handle_session_state_callbacks_execute(blade_session_t *bs, blade_session_state_condition_t condition);
|
||||
|
||||
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_protocol_publish(blade_handle_t *bh, const char *name, const char *realm, blade_rpc_response_callback_t callback, void *data);
|
||||
|
@ -115,7 +76,6 @@ KS_DECLARE(ks_status_t) blade_protocol_subscribe(blade_handle_t *bh, const char
|
|||
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_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_protocol_broadcast_raw(blade_handle_t *bh, const char *broadcaster_nodeid, const char *excluded_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);
|
||||
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* 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_SUBSCRIPTIONMGR_H_
|
||||
#define _BLADE_SUBSCRIPTIONMGR_H_
|
||||
#include <blade.h>
|
||||
|
||||
KS_BEGIN_EXTERN_C
|
||||
KS_DECLARE(ks_status_t) blade_subscriptionmgr_create(blade_subscriptionmgr_t **bsmgrP, blade_handle_t *bh);
|
||||
KS_DECLARE(ks_status_t) blade_subscriptionmgr_destroy(blade_subscriptionmgr_t **bsmgrP);
|
||||
KS_DECLARE(blade_handle_t *) blade_subscriptionmgr_handle_get(blade_subscriptionmgr_t *bsmgr);
|
||||
KS_DECLARE(blade_subscription_t *) blade_subscriptionmgr_subscription_lookup(blade_subscriptionmgr_t *bsmgr, const char *event, const char *protocol, const char *realm);
|
||||
KS_DECLARE(ks_bool_t) blade_subscriptionmgr_subscriber_add(blade_subscriptionmgr_t *bsmgr, blade_subscription_t **bsubP, const char *event, const char *protocol, const char *realm, const char *target);
|
||||
KS_DECLARE(ks_bool_t) blade_subscriptionmgr_subscriber_remove(blade_subscriptionmgr_t *bsmgr, blade_subscription_t **bsubP, const char *event, const char *protocol, const char *realm, const char *target);
|
||||
KS_DECLARE(void) blade_subscriptionmgr_subscriber_cleanup(blade_subscriptionmgr_t *bsmgr, const char *target);
|
||||
KS_DECLARE(ks_status_t) blade_subscriptionmgr_broadcast(blade_subscriptionmgr_t *bsmgr, const char *broadcaster_nodeid, const char *excluded_nodeid, const char *event, const char *protocol, const char *realm, cJSON *params, blade_rpc_response_callback_t callback, void *data);
|
||||
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:
|
||||
*/
|
|
@ -31,8 +31,8 @@
|
|||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _BLADE_MODULE_WSS_H_
|
||||
#define _BLADE_MODULE_WSS_H_
|
||||
#ifndef _BLADE_TRANSPORT_WSS_H_
|
||||
#define _BLADE_TRANSPORT_WSS_H_
|
||||
#include <blade.h>
|
||||
|
||||
KS_BEGIN_EXTERN_C
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* 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_TRANSPORTMGR_H_
|
||||
#define _BLADE_TRANSPORTMGR_H_
|
||||
#include <blade.h>
|
||||
|
||||
KS_BEGIN_EXTERN_C
|
||||
KS_DECLARE(ks_status_t) blade_transportmgr_create(blade_transportmgr_t **btmgrP, blade_handle_t *bh);
|
||||
KS_DECLARE(ks_status_t) blade_transportmgr_destroy(blade_transportmgr_t **btmgrP);
|
||||
KS_DECLARE(ks_status_t) blade_transportmgr_startup(blade_transportmgr_t *btmgr, config_setting_t *config);
|
||||
KS_DECLARE(ks_status_t) blade_transportmgr_shutdown(blade_transportmgr_t *btmgr);
|
||||
KS_DECLARE(blade_handle_t *) blade_transportmgr_handle_get(blade_transportmgr_t *btmgr);
|
||||
KS_DECLARE(blade_transport_t *) blade_transportmgr_default_get(blade_transportmgr_t *btmgr);
|
||||
KS_DECLARE(ks_status_t) blade_transportmgr_default_set(blade_transportmgr_t *btmgr, blade_transport_t *bt);
|
||||
KS_DECLARE(blade_transport_t *) blade_transportmgr_transport_lookup(blade_transportmgr_t *btmgr, const char *name, ks_bool_t ordefault);
|
||||
KS_DECLARE(ks_status_t) blade_transportmgr_transport_add(blade_transportmgr_t *btmgr, blade_transport_t *bt);
|
||||
KS_DECLARE(ks_status_t) blade_transportmgr_transport_remove(blade_transportmgr_t *btmgr, blade_transport_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,9 +50,16 @@ 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_protocol_realm_s blade_protocol_realm_t;
|
||||
//typedef struct blade_protocol_method_s blade_protocol_method_t;
|
||||
|
||||
typedef struct blade_transportmgr_s blade_transportmgr_t;
|
||||
typedef struct blade_rpcmgr_s blade_rpcmgr_t;
|
||||
typedef struct blade_routemgr_s blade_routemgr_t;
|
||||
typedef struct blade_subscriptionmgr_s blade_subscriptionmgr_t;
|
||||
typedef struct blade_upstreammgr_s blade_upstreammgr_t;
|
||||
typedef struct blade_mastermgr_s blade_mastermgr_t;
|
||||
typedef struct blade_connectionmgr_s blade_connectionmgr_t;
|
||||
typedef struct blade_sessionmgr_s blade_sessionmgr_t;
|
||||
typedef struct blade_session_callback_data_s blade_session_callback_data_t;
|
||||
|
||||
typedef ks_bool_t (*blade_rpc_request_callback_t)(blade_rpc_request_t *brpcreq, void *data);
|
||||
typedef ks_bool_t (*blade_rpc_response_callback_t)(blade_rpc_response_t *brpcres, void *data);
|
||||
|
@ -123,7 +130,7 @@ struct blade_transport_callbacks_s {
|
|||
blade_transport_state_callback_t onstate_run_outbound;
|
||||
};
|
||||
|
||||
typedef void (*blade_session_state_callback_t)(blade_session_t *bs, blade_session_state_condition_t condition, void *data);
|
||||
typedef void (*blade_session_callback_t)(blade_session_t *bs, blade_session_state_condition_t condition, void *data);
|
||||
|
||||
|
||||
KS_END_EXTERN_C
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* 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_UPSTREAMMGR_H_
|
||||
#define _BLADE_UPSTREAMMGR_H_
|
||||
#include <blade.h>
|
||||
|
||||
KS_BEGIN_EXTERN_C
|
||||
KS_DECLARE(ks_status_t) blade_upstreammgr_create(blade_upstreammgr_t **bumgrP, blade_handle_t *bh);
|
||||
KS_DECLARE(ks_status_t) blade_upstreammgr_destroy(blade_upstreammgr_t **bumgrP);
|
||||
KS_DECLARE(blade_handle_t *) blade_upstreammgr_handle_get(blade_upstreammgr_t *bumgr);
|
||||
KS_DECLARE(ks_status_t) blade_upstreammgr_localid_set(blade_upstreammgr_t *bumgr, const char *id);
|
||||
KS_DECLARE(ks_bool_t) blade_upstreammgr_localid_compare(blade_upstreammgr_t *bumgr, const char *id);
|
||||
KS_DECLARE(ks_status_t) blade_upstreammgr_localid_copy(blade_upstreammgr_t *bumgr, ks_pool_t *pool, const char **id);
|
||||
KS_DECLARE(ks_bool_t) blade_upstreammgr_session_established(blade_upstreammgr_t *bumgr);
|
||||
KS_DECLARE(blade_session_t *) blade_upstreammgr_session_get(blade_upstreammgr_t *bumgr);
|
||||
KS_DECLARE(ks_status_t) blade_upstreammgr_masterid_set(blade_upstreammgr_t *bumgr, const char *id);
|
||||
KS_DECLARE(ks_bool_t) blade_upstreammgr_masterid_compare(blade_upstreammgr_t *bumgr, const char *id);
|
||||
KS_DECLARE(ks_status_t) blade_upstreammgr_masterid_copy(blade_upstreammgr_t *bumgr, ks_pool_t *pool, const char **id);
|
||||
//KS_DECLARE(ks_hash_t *) blade_upstreammgr_realm_lookup(blade_handle_t *bh);
|
||||
KS_DECLARE(ks_status_t) blade_upstreammgr_realm_add(blade_upstreammgr_t *bumgr, const char *realm);
|
||||
KS_DECLARE(ks_status_t) blade_upstreammgr_realm_remove(blade_upstreammgr_t *bumgr, const char *realm);
|
||||
KS_DECLARE(ks_status_t) blade_upstreammgr_realm_clear(blade_upstreammgr_t *bumgr);
|
||||
KS_DECLARE(ks_status_t) blade_upstreammgr_realm_propagate(blade_upstreammgr_t *bumgr, blade_session_t *bs);
|
||||
|
||||
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:
|
||||
*/
|
|
@ -39,7 +39,7 @@ ks_bool_t test_echo_response_handler(blade_rpc_response_t *brpcres, void *data)
|
|||
bh = blade_rpc_response_handle_get(brpcres);
|
||||
ks_assert(bh);
|
||||
|
||||
bs = blade_handle_sessions_lookup(bh, blade_rpc_response_sessionid_get(brpcres));
|
||||
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);
|
||||
|
@ -64,7 +64,7 @@ ks_bool_t blade_locate_response_handler(blade_rpc_response_t *brpcres, void *dat
|
|||
const char *nodeid = NULL;
|
||||
cJSON *res = NULL;
|
||||
cJSON *res_result = NULL;
|
||||
cJSON *res_result_providers = NULL;
|
||||
cJSON *res_result_controllers = NULL;
|
||||
const char *res_result_protocol = NULL;
|
||||
const char *res_result_realm = NULL;
|
||||
cJSON *params = NULL;
|
||||
|
@ -74,7 +74,7 @@ ks_bool_t blade_locate_response_handler(blade_rpc_response_t *brpcres, void *dat
|
|||
bh = blade_rpc_response_handle_get(brpcres);
|
||||
ks_assert(bh);
|
||||
|
||||
bs = blade_handle_sessions_lookup(bh, blade_rpc_response_sessionid_get(brpcres));
|
||||
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);
|
||||
|
@ -89,13 +89,13 @@ ks_bool_t blade_locate_response_handler(blade_rpc_response_t *brpcres, void *dat
|
|||
res_result_realm = cJSON_GetObjectCstr(res_result, "realm");
|
||||
ks_assert(res_result_realm);
|
||||
|
||||
res_result_providers = cJSON_GetObjectItem(res_result, "providers");
|
||||
ks_assert(res_result_providers);
|
||||
res_result_controllers = cJSON_GetObjectItem(res_result, "controllers");
|
||||
ks_assert(res_result_controllers);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) blade.locate response processing\n", blade_session_id_get(bs));
|
||||
|
||||
for (int index = 0; index < cJSON_GetArraySize(res_result_providers); ++index) {
|
||||
cJSON *elem = cJSON_GetArrayItem(res_result_providers, index);
|
||||
for (int index = 0; index < cJSON_GetArraySize(res_result_controllers); ++index) {
|
||||
cJSON *elem = cJSON_GetArrayItem(res_result_controllers, index);
|
||||
if (elem->type == cJSON_String) {
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) blade.locate (%s@%s) provider (%s)\n", blade_session_id_get(bs), res_result_protocol, res_result_realm, elem->valuestring);
|
||||
nodeid = elem->valuestring;
|
||||
|
@ -121,7 +121,7 @@ ks_bool_t blade_subscribe_response_handler(blade_rpc_response_t *brpcres, void *
|
|||
bh = blade_rpc_response_handle_get(brpcres);
|
||||
ks_assert(bh);
|
||||
|
||||
bs = blade_handle_sessions_lookup(bh, blade_rpc_response_sessionid_get(brpcres));
|
||||
bs = blade_sessionmgr_session_lookup(blade_handle_sessionmgr_get(bh), blade_rpc_response_sessionid_get(brpcres));
|
||||
ks_assert(bs);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) blade.subscribe response processing\n", blade_session_id_get(bs));
|
||||
|
@ -141,7 +141,7 @@ ks_bool_t test_event_request_handler(blade_rpc_request_t *brpcreq, void *data)
|
|||
bh = blade_rpc_request_handle_get(brpcreq);
|
||||
ks_assert(bh);
|
||||
|
||||
bs = blade_handle_sessions_lookup(bh, blade_rpc_request_sessionid_get(brpcreq));
|
||||
bs = blade_sessionmgr_session_lookup(blade_handle_sessionmgr_get(bh), blade_rpc_request_sessionid_get(brpcreq));
|
||||
ks_assert(bs);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) test.event request processing\n", blade_session_id_get(bs));
|
||||
|
|
|
@ -39,7 +39,7 @@ ks_bool_t blade_publish_response_handler(blade_rpc_response_t *brpcres, void *da
|
|||
bh = blade_rpc_response_handle_get(brpcres);
|
||||
ks_assert(bh);
|
||||
|
||||
bs = blade_handle_sessions_lookup(bh, blade_rpc_response_sessionid_get(brpcres));
|
||||
bs = blade_sessionmgr_session_lookup(blade_handle_sessionmgr_get(bh), blade_rpc_response_sessionid_get(brpcres));
|
||||
ks_assert(bs);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) blade.publish response processing\n", blade_session_id_get(bs));
|
||||
|
@ -62,7 +62,7 @@ ks_bool_t test_echo_request_handler(blade_rpc_request_t *brpcreq, void *data)
|
|||
bh = blade_rpc_request_handle_get(brpcreq);
|
||||
ks_assert(bh);
|
||||
|
||||
bs = blade_handle_sessions_lookup(bh, blade_rpc_request_sessionid_get(brpcreq));
|
||||
bs = blade_sessionmgr_session_lookup(blade_handle_sessionmgr_get(bh), blade_rpc_request_sessionid_get(brpcreq));
|
||||
ks_assert(bs);
|
||||
|
||||
// @todo get the inner parameters of a blade.execute request for protocolrpcs
|
||||
|
@ -95,7 +95,7 @@ ks_bool_t test_event_response_handler(blade_rpc_response_t *brpcres, void *data)
|
|||
bh = blade_rpc_response_handle_get(brpcres);
|
||||
ks_assert(bh);
|
||||
|
||||
bs = blade_handle_sessions_lookup(bh, blade_rpc_response_sessionid_get(brpcres));
|
||||
bs = blade_sessionmgr_session_lookup(blade_handle_sessionmgr_get(bh), blade_rpc_response_sessionid_get(brpcres));
|
||||
ks_assert(bs);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) test.event response processing\n", blade_session_id_get(bs));
|
||||
|
@ -240,7 +240,7 @@ void command_publish(blade_handle_t *bh, char *args)
|
|||
ks_assert(args);
|
||||
|
||||
blade_rpc_create(&brpc, bh, "test.echo", "test", "mydomain.com", test_echo_request_handler, NULL);
|
||||
blade_handle_protocolrpc_register(brpc);
|
||||
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);
|
||||
|
|
|
@ -40,7 +40,7 @@ ks_bool_t test_locate_response_handler(blade_rpc_response_t *brpcres, void *data
|
|||
const char *nodeid = NULL;
|
||||
cJSON *res = NULL;
|
||||
cJSON *res_result = NULL;
|
||||
cJSON *res_result_providers = NULL;
|
||||
cJSON *res_result_controllers = NULL;
|
||||
const char *res_result_protocol = NULL;
|
||||
const char *res_result_realm = NULL;
|
||||
//cJSON *params = NULL;
|
||||
|
@ -50,7 +50,7 @@ ks_bool_t test_locate_response_handler(blade_rpc_response_t *brpcres, void *data
|
|||
bh = blade_rpc_response_handle_get(brpcres);
|
||||
ks_assert(bh);
|
||||
|
||||
bs = blade_handle_sessions_lookup(bh, blade_rpc_response_sessionid_get(brpcres));
|
||||
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);
|
||||
|
@ -65,13 +65,13 @@ ks_bool_t test_locate_response_handler(blade_rpc_response_t *brpcres, void *data
|
|||
res_result_realm = cJSON_GetObjectCstr(res_result, "realm");
|
||||
ks_assert(res_result_realm);
|
||||
|
||||
res_result_providers = cJSON_GetObjectItem(res_result, "providers");
|
||||
ks_assert(res_result_providers);
|
||||
res_result_controllers = cJSON_GetObjectItem(res_result, "controllers");
|
||||
ks_assert(res_result_controllers);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) locate (%s@%s) response processing\n", blade_session_id_get(bs), res_result_protocol, res_result_realm);
|
||||
|
||||
for (int index = 0; index < cJSON_GetArraySize(res_result_providers); ++index) {
|
||||
cJSON *elem = cJSON_GetArrayItem(res_result_providers, index);
|
||||
for (int index = 0; index < cJSON_GetArraySize(res_result_controllers); ++index) {
|
||||
cJSON *elem = cJSON_GetArrayItem(res_result_controllers, index);
|
||||
if (elem->type == cJSON_String) {
|
||||
nodeid = elem->valuestring;
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ ks_bool_t test_join_response_handler(blade_rpc_response_t *brpcres, void *data)
|
|||
bh = blade_rpc_response_handle_get(brpcres);
|
||||
ks_assert(bh);
|
||||
|
||||
bs = blade_handle_sessions_lookup(bh, blade_rpc_response_sessionid_get(brpcres));
|
||||
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);
|
||||
|
@ -122,7 +122,7 @@ ks_bool_t test_leave_response_handler(blade_rpc_response_t *brpcres, void *data)
|
|||
bh = blade_rpc_response_handle_get(brpcres);
|
||||
ks_assert(bh);
|
||||
|
||||
bs = blade_handle_sessions_lookup(bh, blade_rpc_response_sessionid_get(brpcres));
|
||||
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);
|
||||
|
@ -146,7 +146,7 @@ ks_bool_t test_talk_response_handler(blade_rpc_response_t *brpcres, void *data)
|
|||
bh = blade_rpc_response_handle_get(brpcres);
|
||||
ks_assert(bh);
|
||||
|
||||
bs = blade_handle_sessions_lookup(bh, blade_rpc_response_sessionid_get(brpcres));
|
||||
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);
|
||||
|
@ -172,7 +172,7 @@ ks_bool_t test_join_broadcast_handler(blade_rpc_request_t *brpcreq, void *data)
|
|||
bh = blade_rpc_request_handle_get(brpcreq);
|
||||
ks_assert(bh);
|
||||
|
||||
bs = blade_handle_sessions_lookup(bh, blade_rpc_request_sessionid_get(brpcreq));
|
||||
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);
|
||||
|
@ -201,7 +201,7 @@ ks_bool_t test_leave_broadcast_handler(blade_rpc_request_t *brpcreq, void *data)
|
|||
bh = blade_rpc_request_handle_get(brpcreq);
|
||||
ks_assert(bh);
|
||||
|
||||
bs = blade_handle_sessions_lookup(bh, blade_rpc_request_sessionid_get(brpcreq));
|
||||
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);
|
||||
|
@ -230,7 +230,7 @@ ks_bool_t test_talk_broadcast_handler(blade_rpc_request_t *brpcreq, void *data)
|
|||
bh = blade_rpc_request_handle_get(brpcreq);
|
||||
ks_assert(bh);
|
||||
|
||||
bs = blade_handle_sessions_lookup(bh, blade_rpc_request_sessionid_get(brpcreq));
|
||||
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);
|
||||
|
|
|
@ -99,7 +99,7 @@ ks_bool_t test_publish_response_handler(blade_rpc_response_t *brpcres, void *dat
|
|||
bh = blade_rpc_response_handle_get(brpcres);
|
||||
ks_assert(bh);
|
||||
|
||||
bs = blade_handle_sessions_lookup(bh, blade_rpc_response_sessionid_get(brpcres));
|
||||
bs = blade_sessionmgr_session_lookup(blade_handle_sessionmgr_get(bh), blade_rpc_response_sessionid_get(brpcres));
|
||||
ks_assert(bs);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Session (%s) publish response processing\n", blade_session_id_get(bs));
|
||||
|
@ -127,7 +127,7 @@ ks_bool_t test_join_request_handler(blade_rpc_request_t *brpcreq, void *data)
|
|||
bh = blade_rpc_request_handle_get(brpcreq);
|
||||
ks_assert(bh);
|
||||
|
||||
bs = blade_handle_sessions_lookup(bh, blade_rpc_request_sessionid_get(brpcreq));
|
||||
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);
|
||||
|
@ -176,7 +176,7 @@ ks_bool_t test_leave_request_handler(blade_rpc_request_t *brpcreq, void *data)
|
|||
bh = blade_rpc_request_handle_get(brpcreq);
|
||||
ks_assert(bh);
|
||||
|
||||
bs = blade_handle_sessions_lookup(bh, blade_rpc_request_sessionid_get(brpcreq));
|
||||
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);
|
||||
|
@ -222,7 +222,7 @@ ks_bool_t test_talk_request_handler(blade_rpc_request_t *brpcreq, void *data)
|
|||
bh = blade_rpc_request_handle_get(brpcreq);
|
||||
ks_assert(bh);
|
||||
|
||||
bs = blade_handle_sessions_lookup(bh, blade_rpc_request_sessionid_get(brpcreq));
|
||||
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);
|
||||
|
@ -315,13 +315,13 @@ int main(int argc, char **argv)
|
|||
ks_sleep_ms(3000);
|
||||
|
||||
blade_rpc_create(&brpc, bh, "test.join", "test", "mydomain.com", test_join_request_handler, test);
|
||||
blade_handle_protocolrpc_register(brpc);
|
||||
blade_rpcmgr_protocolrpc_add(blade_handle_rpcmgr_get(bh), brpc);
|
||||
|
||||
blade_rpc_create(&brpc, bh, "test.leave", "test", "mydomain.com", test_leave_request_handler, test);
|
||||
blade_handle_protocolrpc_register(brpc);
|
||||
blade_rpcmgr_protocolrpc_add(blade_handle_rpcmgr_get(bh), brpc);
|
||||
|
||||
blade_rpc_create(&brpc, bh, "test.talk", "test", "mydomain.com", test_talk_request_handler, test);
|
||||
blade_handle_protocolrpc_register(brpc);
|
||||
blade_rpcmgr_protocolrpc_add(blade_handle_rpcmgr_get(bh), brpc);
|
||||
|
||||
blade_protocol_publish(bh, "test", "mydomain.com", test_publish_response_handler, test);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue