forked from Mirrors/freeswitch
FS-9952: Some work towards client connectivity support, commit is to remove blade_message_t and get RPC stuff updated, code does not compile currently
This commit is contained in:
parent
942ae77bde
commit
418092e1ee
@ -12,14 +12,14 @@ libunqlite_la_LIBADD = -lpthread
|
||||
|
||||
lib_LTLIBRARIES = libblade.la
|
||||
libblade_la_SOURCES = src/blade.c src/blade_stack.c src/bpcp.c src/blade_datastore.c
|
||||
libblade_la_SOURCES += src/blade_message.c src/blade_rpcproto.c
|
||||
libblade_la_SOURCES += src/blade_rpcproto.c
|
||||
libblade_la_SOURCES += src/blade_identity.c src/blade_module.c src/blade_connection.c src/blade_module_wss.c
|
||||
libblade_la_CFLAGS = $(AM_CFLAGS) $(AM_CPPFLAGS)
|
||||
libblade_la_LDFLAGS = -version-info 0:1:0 -lncurses -lpthread -lm -lconfig $(AM_LDFLAGS)
|
||||
libblade_la_LIBADD = libunqlite.la
|
||||
library_includedir = $(prefix)/include
|
||||
library_include_HEADERS = src/include/blade.h src/include/blade_types.h src/include/blade_stack.h
|
||||
library_include_HEADERS += src/include/bpcp.h src/include/blade_datastore.h src/include/blade_message.h src/include/blade_rpcproto.h
|
||||
library_include_HEADERS += src/include/bpcp.h src/include/blade_datastore.h src/include/blade_rpcproto.h
|
||||
library_include_HEADERS += src/include/blade_identity.h src/include/blade_module.h src/include/blade_connection.h
|
||||
library_include_HEADERS += src/include/unqlite.h test/tap.h
|
||||
|
||||
|
@ -87,6 +87,8 @@ KS_DECLARE(ks_status_t) blade_identity_parse(blade_identity_t *bi, const char *u
|
||||
ks_assert(bi);
|
||||
ks_assert(uri);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Parsing URI: %s\n", uri);
|
||||
|
||||
if (bi->uri) {
|
||||
ks_pool_free(bi->pool, &bi->uri);
|
||||
ks_pool_free(bi->pool, &bi->components);
|
||||
@ -97,13 +99,13 @@ KS_DECLARE(ks_status_t) blade_identity_parse(blade_identity_t *bi, const char *u
|
||||
bi->name = tmp;
|
||||
if (!(tmp = strchr(tmp, '@'))) return KS_STATUS_FAIL;
|
||||
*tmp++ = '\0';
|
||||
|
||||
|
||||
bi->domain = tmp2 = tmp;
|
||||
if ((tmp = strchr(tmp, '/'))) {
|
||||
*tmp++ = '\0';
|
||||
bi->resource = tmp2 = tmp;
|
||||
} else tmp = tmp2;
|
||||
|
||||
|
||||
if ((tmp = strchr(tmp, '?'))) {
|
||||
*tmp++ = '\0';
|
||||
|
||||
@ -125,18 +127,41 @@ KS_DECLARE(ks_status_t) blade_identity_parse(blade_identity_t *bi, const char *u
|
||||
}
|
||||
}
|
||||
|
||||
// @todo remove this, temporary for testing
|
||||
ks_log(KS_LOG_DEBUG, " name: %s\n", bi->name);
|
||||
ks_log(KS_LOG_DEBUG, " domain: %s\n", bi->domain);
|
||||
ks_log(KS_LOG_DEBUG, " resource: %s\n", bi->resource);
|
||||
for (ks_hash_iterator_t *it = ks_hash_first(bi->parameters, KS_UNLOCKED); it; it = ks_hash_next(&it)) {
|
||||
const char *key = NULL;
|
||||
const char *val = NULL;
|
||||
|
||||
ks_hash_this(it, (const void **)&key, NULL, (void **)&val);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, " key: %s = %s\n", key, val);
|
||||
}
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_identity_uri(blade_identity_t *bi, const char **uri)
|
||||
KS_DECLARE(const char *) blade_identity_uri(blade_identity_t *bi)
|
||||
{
|
||||
ks_assert(bi);
|
||||
ks_assert(uri);
|
||||
|
||||
*uri = bi->uri;
|
||||
return bi->uri;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_identity_parameter_get(blade_identity_t *bi, const char *key, const char **value)
|
||||
{
|
||||
ks_assert(bi);
|
||||
ks_assert(key);
|
||||
ks_assert(value);
|
||||
|
||||
*value = (const char *)ks_hash_search(bi->parameters, (void *)key, KS_UNLOCKED);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
|
@ -1,129 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007-2014, Anthony Minessale II
|
||||
* 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_message_s {
|
||||
ks_pool_t *pool;
|
||||
blade_handle_t *handle;
|
||||
|
||||
void *data;
|
||||
ks_size_t data_length;
|
||||
ks_size_t data_size;
|
||||
};
|
||||
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_message_destroy(blade_message_t **bmP)
|
||||
{
|
||||
blade_message_t *bm = NULL;
|
||||
|
||||
ks_assert(bmP);
|
||||
|
||||
bm = *bmP;
|
||||
*bmP = NULL;
|
||||
|
||||
ks_assert(bm);
|
||||
|
||||
if (bm->data) ks_pool_free(bm->pool, &bm->data);
|
||||
|
||||
ks_pool_free(bm->pool, &bm);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_message_create(blade_message_t **bmP, ks_pool_t *pool, blade_handle_t *handle)
|
||||
{
|
||||
blade_message_t *bm = NULL;
|
||||
|
||||
ks_assert(bmP);
|
||||
ks_assert(pool);
|
||||
ks_assert(handle);
|
||||
|
||||
bm = ks_pool_alloc(pool, sizeof(*bm));
|
||||
bm->pool = pool;
|
||||
bm->handle = handle;
|
||||
*bmP = bm;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_message_discard(blade_message_t **bm)
|
||||
{
|
||||
ks_assert(bm);
|
||||
ks_assert(*bm);
|
||||
|
||||
return blade_handle_message_discard((*bm)->handle, bm);
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_message_set(blade_message_t *bm, void *data, ks_size_t data_length)
|
||||
{
|
||||
ks_assert(bm);
|
||||
ks_assert(data);
|
||||
ks_assert(data_length > 0);
|
||||
|
||||
// @todo fail on a max message size?
|
||||
|
||||
if (data_length > bm->data_size) {
|
||||
// @todo talk to tony about adding flags to ks_pool_resize_ex to prevent the memcpy, don't need to copy old memory here
|
||||
// otherwise switch to a new allocation instead of resizing
|
||||
bm->data = ks_pool_resize(bm->pool, bm->data, data_length);
|
||||
ks_assert(bm->data);
|
||||
bm->data_size = data_length;
|
||||
}
|
||||
memcpy(bm->data, data, data_length);
|
||||
bm->data_length = data_length;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_message_get(blade_message_t *bm, void **data, ks_size_t *data_length)
|
||||
{
|
||||
ks_assert(bm);
|
||||
|
||||
*data = bm->data;
|
||||
*data_length = bm->data_length;
|
||||
|
||||
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:
|
||||
*/
|
@ -33,6 +33,7 @@
|
||||
|
||||
#include "blade.h"
|
||||
|
||||
#define BLADE_MODULE_WSS_TRANSPORT_NAME "wss"
|
||||
#define BLADE_MODULE_WSS_ENDPOINTS_MULTIHOME_MAX 16
|
||||
|
||||
typedef struct blade_module_wss_s blade_module_wss_t;
|
||||
@ -130,8 +131,6 @@ static blade_module_callbacks_t g_module_wss_callbacks =
|
||||
|
||||
static blade_transport_callbacks_t g_transport_wss_callbacks =
|
||||
{
|
||||
"wss",
|
||||
|
||||
blade_transport_wss_on_connect,
|
||||
blade_transport_wss_on_rank,
|
||||
blade_transport_wss_on_send,
|
||||
@ -374,7 +373,7 @@ KS_DECLARE(ks_status_t) blade_module_wss_on_startup(blade_module_t *bm, config_s
|
||||
KS_PRI_NORMAL,
|
||||
bm_wss->pool) != KS_STATUS_SUCCESS) return KS_STATUS_FAIL;
|
||||
|
||||
blade_handle_transport_register(bm_wss->handle, bm_wss->transport_callbacks);
|
||||
blade_handle_transport_register(bm_wss->handle, bm, BLADE_MODULE_WSS_TRANSPORT_NAME, bm_wss->transport_callbacks);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
@ -389,7 +388,7 @@ KS_DECLARE(ks_status_t) blade_module_wss_on_shutdown(blade_module_t *bm)
|
||||
|
||||
bm_wss = (blade_module_wss_t *)blade_module_data_get(bm);
|
||||
|
||||
blade_handle_transport_unregister(bm_wss->handle, bm_wss->transport_callbacks);
|
||||
blade_handle_transport_unregister(bm_wss->handle, BLADE_MODULE_WSS_TRANSPORT_NAME);
|
||||
|
||||
if (bm_wss->listeners_thread) {
|
||||
bm_wss->shutdown = KS_TRUE;
|
||||
@ -580,6 +579,7 @@ ks_status_t blade_transport_wss_on_connect(blade_connection_t **bcP, blade_modul
|
||||
*bcP = NULL;
|
||||
|
||||
// @todo connect-out equivilent of accept
|
||||
ks_log(KS_LOG_DEBUG, "Connect Callback: %s\n", blade_identity_uri(target));
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
@ -48,12 +48,89 @@ struct blade_handle_s {
|
||||
config_setting_t *config_datastore;
|
||||
|
||||
ks_hash_t *transports;
|
||||
ks_q_t *messages_discarded;
|
||||
|
||||
blade_datastore_t *datastore;
|
||||
};
|
||||
|
||||
|
||||
typedef struct blade_handle_transport_registration_s blade_handle_transport_registration_t;
|
||||
struct blade_handle_transport_registration_s {
|
||||
ks_pool_t *pool;
|
||||
|
||||
blade_module_t *module;
|
||||
blade_transport_callbacks_t *callbacks;
|
||||
};
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_handle_transport_registration_create(blade_handle_transport_registration_t **bhtrP,
|
||||
ks_pool_t *pool,
|
||||
blade_module_t *module,
|
||||
blade_transport_callbacks_t *callbacks)
|
||||
{
|
||||
blade_handle_transport_registration_t *bhtr = NULL;
|
||||
|
||||
ks_assert(bhtrP);
|
||||
ks_assert(pool);
|
||||
ks_assert(module);
|
||||
ks_assert(callbacks);
|
||||
|
||||
bhtr = ks_pool_alloc(pool, sizeof(blade_handle_transport_registration_t));
|
||||
bhtr->pool = pool;
|
||||
bhtr->module = module;
|
||||
bhtr->callbacks = callbacks;
|
||||
|
||||
*bhtrP = bhtr;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_handle_transport_registration_destroy(blade_handle_transport_registration_t **bhtrP)
|
||||
{
|
||||
blade_handle_transport_registration_t *bhtr = NULL;
|
||||
|
||||
ks_assert(bhtrP);
|
||||
|
||||
bhtr = *bhtrP;
|
||||
*bhtrP = NULL;
|
||||
|
||||
ks_assert(bhtr);
|
||||
|
||||
ks_pool_free(bhtr->pool, &bhtr);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_handle_create(blade_handle_t **bhP, ks_pool_t *pool, ks_thread_pool_t *tpool)
|
||||
{
|
||||
bhpvt_flag_t newflags = BH_NONE;
|
||||
blade_handle_t *bh = NULL;
|
||||
|
||||
ks_assert(bhP);
|
||||
|
||||
if (!pool) {
|
||||
newflags |= BH_MYPOOL;
|
||||
ks_pool_open(&pool);
|
||||
}
|
||||
if (!tpool) {
|
||||
newflags |= BH_MYTPOOL;
|
||||
ks_thread_pool_create(&tpool, BLADE_HANDLE_TPOOL_MIN, BLADE_HANDLE_TPOOL_MAX, BLADE_HANDLE_TPOOL_STACK, KS_PRI_NORMAL, BLADE_HANDLE_TPOOL_IDLE);
|
||||
ks_assert(tpool);
|
||||
}
|
||||
|
||||
bh = ks_pool_alloc(pool, sizeof(blade_handle_t));
|
||||
bh->flags = newflags;
|
||||
bh->pool = pool;
|
||||
bh->tpool = tpool;
|
||||
|
||||
ks_hash_create(&bh->transports, KS_HASH_MODE_CASE_INSENSITIVE, KS_HASH_FLAG_NOLOCK | KS_HASH_FLAG_DUP_CHECK, bh->pool);
|
||||
ks_assert(bh->transports);
|
||||
|
||||
*bhP = bh;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_handle_destroy(blade_handle_t **bhP)
|
||||
{
|
||||
blade_handle_t *bh = NULL;
|
||||
@ -72,11 +149,6 @@ KS_DECLARE(ks_status_t) blade_handle_destroy(blade_handle_t **bhP)
|
||||
|
||||
blade_handle_shutdown(bh);
|
||||
|
||||
if (bh->messages_discarded) {
|
||||
// @todo make sure messages are cleaned up
|
||||
ks_q_destroy(&bh->messages_discarded);
|
||||
}
|
||||
|
||||
ks_hash_destroy(&bh->transports);
|
||||
|
||||
if (bh->tpool && (flags & BH_MYTPOOL)) ks_thread_pool_destroy(&bh->tpool);
|
||||
@ -90,40 +162,6 @@ KS_DECLARE(ks_status_t) blade_handle_destroy(blade_handle_t **bhP)
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_handle_create(blade_handle_t **bhP, ks_pool_t *pool, ks_thread_pool_t *tpool)
|
||||
{
|
||||
bhpvt_flag_t newflags = BH_NONE;
|
||||
blade_handle_t *bh = NULL;
|
||||
|
||||
ks_assert(bhP);
|
||||
|
||||
if (!pool) {
|
||||
newflags |= BH_MYPOOL;
|
||||
ks_pool_open(&pool);
|
||||
}
|
||||
if (!tpool) {
|
||||
newflags |= BH_MYTPOOL;
|
||||
ks_thread_pool_create(&tpool, BLADE_HANDLE_TPOOL_MIN, BLADE_HANDLE_TPOOL_MAX, BLADE_HANDLE_TPOOL_STACK, KS_PRI_NORMAL, BLADE_HANDLE_TPOOL_IDLE);
|
||||
ks_assert(tpool);
|
||||
}
|
||||
|
||||
bh = ks_pool_alloc(pool, sizeof(*bh));
|
||||
bh->flags = newflags;
|
||||
bh->pool = pool;
|
||||
bh->tpool = tpool;
|
||||
|
||||
ks_hash_create(&bh->transports, KS_HASH_MODE_CASE_INSENSITIVE, KS_HASH_FLAG_NOLOCK | KS_HASH_FLAG_DUP_CHECK, bh->pool);
|
||||
ks_assert(bh->transports);
|
||||
|
||||
// @todo check thresholds from config, for now just ensure it doesn't grow out of control, allow 100 discarded messages
|
||||
ks_q_create(&bh->messages_discarded, bh->pool, 100);
|
||||
ks_assert(bh->messages_discarded);
|
||||
|
||||
*bhP = bh;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
ks_status_t blade_handle_config(blade_handle_t *bh, config_setting_t *config)
|
||||
{
|
||||
config_setting_t *service = NULL;
|
||||
@ -134,8 +172,6 @@ ks_status_t blade_handle_config(blade_handle_t *bh, config_setting_t *config)
|
||||
if (!config) return KS_STATUS_FAIL;
|
||||
if (!config_setting_is_group(config)) return KS_STATUS_FAIL;
|
||||
|
||||
// @todo config for messages_discarded threshold (ie, message count, message memory, etc)
|
||||
|
||||
service = config_setting_get_member(config, "service");
|
||||
|
||||
datastore = config_setting_get_member(config, "datastore");
|
||||
@ -173,6 +209,7 @@ KS_DECLARE(ks_status_t) blade_handle_shutdown(blade_handle_t *bh)
|
||||
{
|
||||
ks_assert(bh);
|
||||
|
||||
// @todo cleanup registered transports
|
||||
if (blade_handle_datastore_available(bh)) blade_datastore_destroy(&bh->datastore);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
@ -190,79 +227,82 @@ KS_DECLARE(ks_thread_pool_t *) blade_handle_tpool_get(blade_handle_t *bh)
|
||||
return bh->tpool;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_handle_transport_register(blade_handle_t *bh, blade_transport_callbacks_t *callbacks)
|
||||
KS_DECLARE(ks_status_t) blade_handle_transport_register(blade_handle_t *bh, blade_module_t *bm, const char *name, blade_transport_callbacks_t *callbacks)
|
||||
{
|
||||
blade_handle_transport_registration_t *bhtr = NULL;
|
||||
blade_handle_transport_registration_t *bhtr_old = NULL;
|
||||
|
||||
ks_assert(bh);
|
||||
ks_assert(bm);
|
||||
ks_assert(name);
|
||||
ks_assert(callbacks);
|
||||
|
||||
blade_handle_transport_registration_create(&bhtr, bh->pool, bm, callbacks);
|
||||
ks_assert(bhtr);
|
||||
|
||||
ks_hash_write_lock(bh->transports);
|
||||
ks_hash_insert(bh->transports, (void *)callbacks->name, callbacks);
|
||||
bhtr_old = ks_hash_search(bh->transports, (void *)name, KS_UNLOCKED);
|
||||
if (bhtr_old) ks_hash_remove(bh->transports, (void *)name);
|
||||
ks_hash_insert(bh->transports, (void *)name, bhtr);
|
||||
ks_hash_write_unlock(bh->transports);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Transport Registered: %s\n", callbacks->name);
|
||||
if (bhtr_old) blade_handle_transport_registration_destroy(&bhtr_old);
|
||||
|
||||
ks_log(KS_LOG_DEBUG, "Transport Registered: %s\n", name);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_handle_transport_unregister(blade_handle_t *bh, blade_transport_callbacks_t *callbacks)
|
||||
KS_DECLARE(ks_status_t) blade_handle_transport_unregister(blade_handle_t *bh, const char *name)
|
||||
{
|
||||
blade_handle_transport_registration_t *bhtr = NULL;
|
||||
|
||||
ks_assert(bh);
|
||||
ks_assert(callbacks);
|
||||
ks_assert(name);
|
||||
|
||||
ks_hash_write_lock(bh->transports);
|
||||
ks_hash_remove(bh->transports, (void *)callbacks->name);
|
||||
bhtr = ks_hash_search(bh->transports, (void *)name, KS_UNLOCKED);
|
||||
if (bhtr) ks_hash_remove(bh->transports, (void *)name);
|
||||
ks_hash_write_unlock(bh->transports);
|
||||
|
||||
if (bhtr) blade_handle_transport_registration_destroy(&bhtr);
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_handle_connect(blade_handle_t *bh, blade_connection_t **bcP, blade_identity_t *target)
|
||||
{
|
||||
ks_status_t ret = KS_STATUS_SUCCESS;
|
||||
blade_handle_transport_registration_t *bhtr = NULL;
|
||||
const char *tname = NULL;
|
||||
|
||||
ks_assert(bh);
|
||||
ks_assert(target);
|
||||
|
||||
ks_hash_read_lock(bh->transports);
|
||||
// @todo find transport for target, check if target specifies explicit transport parameter first, otherwise use onrank and keep highest ranked callbacks
|
||||
|
||||
blade_identity_parameter_get(target, "transport", &tname);
|
||||
if (tname) {
|
||||
bhtr = ks_hash_search(bh->transports, (void *)tname, KS_UNLOCKED);
|
||||
if (!bhtr) {
|
||||
// @todo error logging, target has an explicit transport that is not available in the local transports registry
|
||||
// discuss later whether this scenario should still attempt other transports when target is explicit
|
||||
}
|
||||
} else {
|
||||
for (ks_hash_iterator_t *it = ks_hash_first(bh->transports, KS_UNLOCKED); it; it = ks_hash_next(&it)) {
|
||||
// @todo use onrank (or replace with whatever method is used for determining what transport to use) and keep highest ranked callbacks
|
||||
}
|
||||
}
|
||||
ks_hash_read_unlock(bh->transports);
|
||||
|
||||
// transport_callbacks->onconnect(bcP, target);
|
||||
// @todo need to be able to get to the blade_module_t from the callbacks, may require envelope around registration of callbacks to include module
|
||||
// this is required because onconnect transport callback needs to be able to get back to the module data to create the connection being returned
|
||||
if (bhtr) ret = bhtr->callbacks->onconnect(bcP, bhtr->module, target);
|
||||
else ret = KS_STATUS_FAIL;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
return ret;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_handle_message_claim(blade_handle_t *bh, blade_message_t **message, void *data, ks_size_t data_length)
|
||||
{
|
||||
blade_message_t *msg = NULL;
|
||||
|
||||
ks_assert(bh);
|
||||
ks_assert(message);
|
||||
ks_assert(data);
|
||||
|
||||
*message = NULL;
|
||||
|
||||
if (ks_q_trypop(bh->messages_discarded, (void **)&msg) != KS_STATUS_SUCCESS || !msg) blade_message_create(&msg, bh->pool, bh);
|
||||
ks_assert(msg);
|
||||
|
||||
if (blade_message_set(msg, data, data_length) != KS_STATUS_SUCCESS) return KS_STATUS_FAIL;
|
||||
|
||||
*message = msg;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_handle_message_discard(blade_handle_t *bh, blade_message_t **message)
|
||||
{
|
||||
ks_assert(bh);
|
||||
ks_assert(message);
|
||||
ks_assert(*message);
|
||||
|
||||
// @todo check thresholds for discarded messages, if the queue is full just destroy the message for now (currently 100 messages)
|
||||
if (ks_q_push(bh->messages_discarded, *message) != KS_STATUS_SUCCESS) blade_message_destroy(message);
|
||||
|
||||
*message = NULL;
|
||||
|
||||
return KS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -40,13 +40,11 @@
|
||||
#include "unqlite.h"
|
||||
#include "blade_types.h"
|
||||
#include "blade_stack.h"
|
||||
#include "blade_message.h"
|
||||
#include "blade_datastore.h"
|
||||
#include "bpcp.h"
|
||||
|
||||
#include "blade_identity.h"
|
||||
#include "blade_module.h"
|
||||
#include "blade_connection.h"
|
||||
#include "blade_datastore.h"
|
||||
#include "bpcp.h"
|
||||
|
||||
KS_BEGIN_EXTERN_C
|
||||
|
||||
|
@ -39,7 +39,8 @@ KS_BEGIN_EXTERN_C
|
||||
KS_DECLARE(ks_status_t) blade_identity_create(blade_identity_t **biP, ks_pool_t *pool);
|
||||
KS_DECLARE(ks_status_t) blade_identity_destroy(blade_identity_t **biP);
|
||||
KS_DECLARE(ks_status_t) blade_identity_parse(blade_identity_t *bi, const char *uri);
|
||||
KS_DECLARE(ks_status_t) blade_identity_uri(blade_identity_t *bi, const char **uri);
|
||||
KS_DECLARE(const char *) blade_identity_uri(blade_identity_t *bi);
|
||||
KS_DECLARE(ks_status_t) blade_identity_parameter_get(blade_identity_t *bi, const char *key, const char **value);
|
||||
KS_END_EXTERN_C
|
||||
|
||||
#endif
|
||||
|
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2007-2014, Anthony Minessale II
|
||||
* 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_MESSAGE_H_
|
||||
#define _BLADE_MESSAGE_H_
|
||||
#include <blade.h>
|
||||
|
||||
KS_BEGIN_EXTERN_C
|
||||
KS_DECLARE(ks_status_t) blade_message_create(blade_message_t **bmP, ks_pool_t *pool, blade_handle_t *handle);
|
||||
KS_DECLARE(ks_status_t) blade_message_destroy(blade_message_t **bmP);
|
||||
KS_DECLARE(ks_status_t) blade_message_set(blade_message_t *bm, void *data, ks_size_t data_length);
|
||||
KS_DECLARE(ks_status_t) blade_message_get(blade_message_t *bm, void **data, ks_size_t *data_length);
|
||||
KS_DECLARE(ks_status_t) blade_message_discard(blade_message_t **bm);
|
||||
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,11 +48,9 @@ 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_transport_register(blade_handle_t *bh, blade_transport_callbacks_t *callbacks);
|
||||
KS_DECLARE(ks_status_t) blade_handle_transport_unregister(blade_handle_t *bh, blade_transport_callbacks_t *callbacks);
|
||||
KS_DECLARE(ks_status_t) blade_handle_transport_register(blade_handle_t *bh, blade_module_t *bm, const char *name, blade_transport_callbacks_t *callbacks);
|
||||
KS_DECLARE(ks_status_t) blade_handle_transport_unregister(blade_handle_t *bh, const char *name);
|
||||
|
||||
KS_DECLARE(ks_status_t) blade_handle_message_claim(blade_handle_t *bh, blade_message_t **message, void *data, ks_size_t data_length);
|
||||
KS_DECLARE(ks_status_t) blade_handle_message_discard(blade_handle_t *bh, blade_message_t **message);
|
||||
|
||||
KS_DECLARE(ks_bool_t) blade_handle_datastore_available(blade_handle_t *bh);
|
||||
KS_DECLARE(ks_status_t) blade_handle_datastore_store(blade_handle_t *bh, const void *key, int32_t key_length, const void *data, int64_t data_length);
|
||||
|
@ -45,7 +45,6 @@ typedef struct blade_module_callbacks_s blade_module_callbacks_t;
|
||||
typedef struct blade_transport_callbacks_s blade_transport_callbacks_t;
|
||||
typedef struct blade_connection_s blade_connection_t;
|
||||
|
||||
typedef struct blade_message_s blade_message_t;
|
||||
typedef struct blade_datastore_s blade_datastore_t;
|
||||
|
||||
typedef ks_bool_t (*blade_datastore_fetch_callback_t)(blade_datastore_t *bds, const void *data, uint32_t data_length, void *userdata);
|
||||
@ -105,8 +104,6 @@ typedef ks_status_t (*blade_transport_receive_callback_t)(blade_connection_t *bc
|
||||
typedef blade_connection_state_hook_t (*blade_transport_state_callback_t)(blade_connection_t *bc, blade_connection_state_condition_t condition);
|
||||
|
||||
struct blade_transport_callbacks_s {
|
||||
const char *name;
|
||||
|
||||
blade_transport_connect_callback_t onconnect;
|
||||
blade_transport_rank_callback_t onrank;
|
||||
blade_transport_send_callback_t onsend;
|
||||
|
@ -46,6 +46,7 @@ int main(int argc, char **argv)
|
||||
config_t config;
|
||||
config_setting_t *config_blade = NULL;
|
||||
blade_module_t *mod_wss = NULL;
|
||||
//blade_identity_t *id = NULL;
|
||||
|
||||
ks_global_set_default_logger(KS_LOG_LEVEL_DEBUG);
|
||||
|
||||
@ -53,6 +54,9 @@ int main(int argc, char **argv)
|
||||
|
||||
blade_handle_create(&bh, NULL, NULL);
|
||||
|
||||
//blade_identity_create(&id, blade_handle_pool_get(bh));
|
||||
//blade_identity_parse(id, "test@domain.com/laptop?transport=wss&host=127.0.0.1&port=1234");
|
||||
|
||||
// @todo load config file, and lookup "blade" setting to put into config_blade
|
||||
config_init(&config);
|
||||
if (!config_read_file(&config, "bladec.cfg")) {
|
||||
|
Loading…
Reference in New Issue
Block a user