2016-11-28 21:35:09 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2007-2014, Anthony Minessale II
|
|
|
|
* All rights reserved.
|
2017-02-28 23:37:19 +00:00
|
|
|
*
|
2016-11-28 21:35:09 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
2017-02-28 23:37:19 +00:00
|
|
|
*
|
2016-11-28 21:35:09 +00:00
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
2017-02-28 23:37:19 +00:00
|
|
|
*
|
2016-11-28 21:35:09 +00:00
|
|
|
* * 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.
|
2017-02-28 23:37:19 +00:00
|
|
|
*
|
2016-11-28 21:35:09 +00:00
|
|
|
* * 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.
|
2017-02-28 23:37:19 +00:00
|
|
|
*
|
|
|
|
*
|
2016-11-28 21:35:09 +00:00
|
|
|
* 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_TYPES_H_
|
|
|
|
#define _BLADE_TYPES_H_
|
|
|
|
#include <ks.h>
|
2017-02-10 14:13:22 +00:00
|
|
|
#include <libconfig.h>
|
2016-11-28 21:35:09 +00:00
|
|
|
|
|
|
|
KS_BEGIN_EXTERN_C
|
|
|
|
|
|
|
|
typedef struct blade_handle_s blade_handle_t;
|
2017-02-09 17:08:07 +00:00
|
|
|
typedef struct blade_identity_s blade_identity_t;
|
|
|
|
typedef struct blade_module_s blade_module_t;
|
|
|
|
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;
|
2017-02-21 16:37:50 +00:00
|
|
|
typedef struct blade_session_s blade_session_t;
|
|
|
|
typedef struct blade_request_s blade_request_t;
|
|
|
|
typedef struct blade_response_s blade_response_t;
|
2017-03-07 18:45:52 +00:00
|
|
|
typedef struct blade_space_s blade_space_t;
|
|
|
|
typedef struct blade_method_s blade_method_t;
|
|
|
|
|
|
|
|
|
|
|
|
typedef ks_bool_t (*blade_request_callback_t)(blade_request_t *breq);
|
|
|
|
typedef ks_bool_t (*blade_response_callback_t)(blade_response_t *bres);
|
2017-02-09 17:08:07 +00:00
|
|
|
|
2017-01-16 17:33:41 +00:00
|
|
|
typedef struct blade_datastore_s blade_datastore_t;
|
2016-11-28 21:35:09 +00:00
|
|
|
|
2017-01-17 18:20:43 +00:00
|
|
|
typedef ks_bool_t (*blade_datastore_fetch_callback_t)(blade_datastore_t *bds, const void *data, uint32_t data_length, void *userdata);
|
|
|
|
|
2017-02-09 17:08:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
BLADE_CONNECTION_STATE_NONE,
|
|
|
|
BLADE_CONNECTION_STATE_DISCONNECT,
|
|
|
|
BLADE_CONNECTION_STATE_NEW,
|
|
|
|
BLADE_CONNECTION_STATE_CONNECT,
|
|
|
|
BLADE_CONNECTION_STATE_ATTACH,
|
|
|
|
BLADE_CONNECTION_STATE_DETACH,
|
|
|
|
BLADE_CONNECTION_STATE_READY,
|
|
|
|
} blade_connection_state_t;
|
|
|
|
|
|
|
|
typedef enum {
|
2017-02-10 02:17:20 +00:00
|
|
|
BLADE_CONNECTION_DIRECTION_INBOUND,
|
|
|
|
BLADE_CONNECTION_DIRECTION_OUTBOUND,
|
2017-02-09 17:08:07 +00:00
|
|
|
} blade_connection_direction_t;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
BLADE_CONNECTION_STATE_CONDITION_PRE,
|
|
|
|
BLADE_CONNECTION_STATE_CONDITION_POST,
|
|
|
|
} blade_connection_state_condition_t;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
BLADE_CONNECTION_STATE_HOOK_SUCCESS,
|
|
|
|
BLADE_CONNECTION_STATE_HOOK_DISCONNECT,
|
|
|
|
BLADE_CONNECTION_STATE_HOOK_BYPASS,
|
|
|
|
} blade_connection_state_hook_t;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
BLADE_CONNECTION_RANK_POOR,
|
|
|
|
BLADE_CONNECTION_RANK_AVERAGE,
|
|
|
|
BLADE_CONNECTION_RANK_GOOD,
|
|
|
|
BLADE_CONNECTION_RANK_GREAT,
|
|
|
|
} blade_connection_rank_t;
|
|
|
|
|
2017-02-21 16:37:50 +00:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
BLADE_SESSION_STATE_NONE,
|
|
|
|
BLADE_SESSION_STATE_DESTROY,
|
|
|
|
BLADE_SESSION_STATE_HANGUP,
|
2017-02-21 21:20:44 +00:00
|
|
|
BLADE_SESSION_STATE_CONNECT,
|
2017-02-21 16:37:50 +00:00
|
|
|
BLADE_SESSION_STATE_ATTACH,
|
|
|
|
BLADE_SESSION_STATE_DETACH,
|
|
|
|
BLADE_SESSION_STATE_READY,
|
|
|
|
} blade_session_state_t;
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-02-09 17:08:07 +00:00
|
|
|
typedef ks_status_t (*blade_module_load_callback_t)(blade_module_t **bmP, blade_handle_t *bh);
|
|
|
|
typedef ks_status_t (*blade_module_unload_callback_t)(blade_module_t *bm);
|
|
|
|
typedef ks_status_t (*blade_module_startup_callback_t)(blade_module_t *bm, config_setting_t *config);
|
|
|
|
typedef ks_status_t (*blade_module_shutdown_callback_t)(blade_module_t *bm);
|
|
|
|
|
|
|
|
struct blade_module_callbacks_s {
|
|
|
|
blade_module_load_callback_t onload;
|
|
|
|
blade_module_unload_callback_t onunload;
|
|
|
|
blade_module_startup_callback_t onstartup;
|
|
|
|
blade_module_shutdown_callback_t onshutdown;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-02-23 23:01:22 +00:00
|
|
|
typedef ks_status_t (*blade_transport_connect_callback_t)(blade_connection_t **bcP, blade_module_t *bm, blade_identity_t *target, const char *session_id);
|
2017-02-09 17:08:07 +00:00
|
|
|
typedef blade_connection_rank_t (*blade_transport_rank_callback_t)(blade_connection_t *bc, blade_identity_t *target);
|
2017-02-21 16:37:50 +00:00
|
|
|
typedef ks_status_t (*blade_transport_send_callback_t)(blade_connection_t *bc, cJSON *json);
|
2017-02-10 02:17:20 +00:00
|
|
|
typedef ks_status_t (*blade_transport_receive_callback_t)(blade_connection_t *bc, cJSON **json);
|
|
|
|
typedef blade_connection_state_hook_t (*blade_transport_state_callback_t)(blade_connection_t *bc, blade_connection_state_condition_t condition);
|
2017-02-09 17:08:07 +00:00
|
|
|
|
|
|
|
struct blade_transport_callbacks_s {
|
|
|
|
blade_transport_connect_callback_t onconnect;
|
|
|
|
blade_transport_rank_callback_t onrank;
|
2017-02-10 02:17:20 +00:00
|
|
|
blade_transport_send_callback_t onsend;
|
|
|
|
blade_transport_receive_callback_t onreceive;
|
|
|
|
|
|
|
|
blade_transport_state_callback_t onstate_disconnect_inbound;
|
|
|
|
blade_transport_state_callback_t onstate_disconnect_outbound;
|
|
|
|
blade_transport_state_callback_t onstate_new_inbound;
|
|
|
|
blade_transport_state_callback_t onstate_new_outbound;
|
|
|
|
blade_transport_state_callback_t onstate_connect_inbound;
|
|
|
|
blade_transport_state_callback_t onstate_connect_outbound;
|
|
|
|
blade_transport_state_callback_t onstate_attach_inbound;
|
|
|
|
blade_transport_state_callback_t onstate_attach_outbound;
|
|
|
|
blade_transport_state_callback_t onstate_detach_inbound;
|
|
|
|
blade_transport_state_callback_t onstate_detach_outbound;
|
|
|
|
blade_transport_state_callback_t onstate_ready_inbound;
|
|
|
|
blade_transport_state_callback_t onstate_ready_outbound;
|
2017-02-09 17:08:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-02-21 16:37:50 +00:00
|
|
|
struct blade_request_s {
|
2017-02-28 23:37:19 +00:00
|
|
|
blade_handle_t *handle;
|
2017-02-21 16:37:50 +00:00
|
|
|
ks_pool_t *pool;
|
|
|
|
const char *session_id;
|
|
|
|
|
|
|
|
cJSON *message;
|
|
|
|
const char *message_id; // pulled from message for easier keying
|
2017-03-07 18:45:52 +00:00
|
|
|
blade_response_callback_t callback;
|
2017-02-21 16:37:50 +00:00
|
|
|
// @todo ttl to wait for response before injecting an error response locally
|
|
|
|
// @todo rpc response callback
|
|
|
|
};
|
|
|
|
|
|
|
|
struct blade_response_s {
|
2017-02-28 23:37:19 +00:00
|
|
|
blade_handle_t *handle;
|
2017-02-21 16:37:50 +00:00
|
|
|
ks_pool_t *pool;
|
|
|
|
const char *session_id;
|
|
|
|
blade_request_t *request;
|
|
|
|
|
|
|
|
cJSON *message;
|
|
|
|
};
|
|
|
|
|
2016-11-28 21:35:09 +00:00
|
|
|
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:
|
|
|
|
*/
|