} vine_discovery_method_e;
/**
+ * @brief Enumeration for data path method
+ * @since_tizen 6.5
+ */
+typedef enum {
+ VINE_DP_METHOD_DEFAULT = 0,
+ VINE_DP_METHOD_BLE_GATT,
+ VINE_DP_METHOD_UNKNOWN
+} vine_dp_method_e;
+
+/**
* @brief Enumeration for address family
* @since_tizen 6.5
*/
int vine_dp_destroy(vine_dp_h dp);
/**
+ * @brief Sets the data path method
+ * @remarks Default method is websocket
+ * @since_tizen 6.5
+ * @param[in] dp The data path handle
+ * @param[in] method The data path method
+ * @return 0 on success, otherwise a negative error value
+ * @retval #VINE_ERROR_NONE Successful
+ * @retval #VINE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #VINE_ERROR_NOT_SUPPORTED Not supported
+ * @see vine_dp_create()
+ */
+int vine_dp_set_method(vine_dp_h dp, vine_dp_method_e method);
+
+/**
* @brief Gets the Id for DP_TYPE_PUBSUB.
* @remarks This should be called after completing vine_dp_open()
* @since_tizen 6.5
/**
* @brief Opens a datapath.
- * @remarks This works depending on the type of datapath differently.
+ * @remarks This works depending on the type of datapath differently. \
+ * If you want to open VINE_DP_SERVER with BLE GATT, \
+ * BLE service should be registered before.
* If @a dp is a server, a listen port is opened.
* If @a dp is a client, it tries to connect to a server.
* If @a dp is for Publish-Subscribe, it joins to a service which has the same topic.
RET_VAL_IF(user == NULL, VINE_DATA_PATH_ERROR_INVALID_PARAMETER, "user is NULL");
vine_gatt_s *gatt = _create_gatt();
- RET_VAL_IF(gatt == NULL, VINE_DATA_PATH_ERROR_OUT_OF_MEMORY, "Out of memory");
+ RET_VAL_IF(gatt == NULL, VINE_DATA_PATH_ERROR_OPERATION_FAILED, "Failed to create GATT handle");
gatt->user = user;
*handle = gatt;
#ifndef __VINE_DATA_PATH_PLUGIN_H__
#define __VINE_DATA_PATH_PLUGIN_H__
-#ifdef USE_LIBWEBSOCKETS
-#define LIBWEBSOCKETS_PLUGIN_PATH "libvine-plugin-libwebsockets.so"
-#define DATA_PATH_PLUGIN_PATH LIBWEBSOCKETS_PLUGIN_PATH
-#else
-#define DATA_PATH_PLUGIN_PATH ""
-#endif
+#define LWS_PLUGIN_PATH "libvine-plugin-libwebsockets.so"
+#define BLE_GATT_PLUGIN_PATH "libvine-plugin-ble-gatt.so"
#define VINE_DATA_PATH_MAX_BUFFER_SIZE 131072 // 128 * 1024 bytes
class VineDataPathState
{
public:
- VineDataPathState(vine_data_path_h dp, vine_dp_plugin_h plugin);
+ VineDataPathState(vine_data_path_h dp, vine_dp_plugin_h plugin, vine_dp_plugin_fn fn);
virtual ~VineDataPathState();
virtual void enter() = 0;
protected:
vine_data_path_h __dp;
vine_dp_plugin_h __plugin;
+ vine_dp_plugin_fn __fn;
};
// Vine Datapath is in the VineDefaultState when initialized
class VineDefaultState : public VineDataPathState
{
public:
- VineDefaultState(vine_data_path_h dp, vine_dp_plugin_h plugin);
+ VineDefaultState(vine_data_path_h dp, vine_dp_plugin_h plugin, vine_dp_plugin_fn fn);
~VineDefaultState();
void enter();
class VineAcceptedState : public VineDataPathState
{
public:
- VineAcceptedState(vine_data_path_h dp, vine_dp_plugin_h plugin);
+ VineAcceptedState(vine_data_path_h dp, vine_dp_plugin_h plugin, vine_dp_plugin_fn fn);
~VineAcceptedState();
void enter();
class VineConnectedState : public VineDataPathState
{
public:
- VineConnectedState(vine_data_path_h dp, vine_dp_plugin_h plugin);
+ VineConnectedState(vine_data_path_h dp, vine_dp_plugin_h plugin, vine_dp_plugin_fn fn);
~VineConnectedState();
void enter();
class VineAuthRequestedState : public VineDataPathState
{
public:
- VineAuthRequestedState(vine_data_path_h dp, vine_dp_plugin_h plugin);
+ VineAuthRequestedState(vine_data_path_h dp, vine_dp_plugin_h plugin, vine_dp_plugin_fn fn);
~VineAuthRequestedState();
void enter();
class VineAuthRespondedState : public VineDataPathState
{
public:
- VineAuthRespondedState(vine_data_path_h dp, vine_dp_plugin_h plugin);
+ VineAuthRespondedState(vine_data_path_h dp, vine_dp_plugin_h plugin, vine_dp_plugin_fn fn);
~VineAuthRespondedState();
void enter();
class VineAuthFailedState : public VineDataPathState
{
public:
- VineAuthFailedState(vine_data_path_h dp, vine_dp_plugin_h plugin);
+ VineAuthFailedState(vine_data_path_h dp, vine_dp_plugin_h plugin, vine_dp_plugin_fn fn);
~VineAuthFailedState();
void enter();
class VineEstablishedState : public VineDataPathState
{
public:
- VineEstablishedState(vine_data_path_h dp, vine_dp_plugin_h plugin);
+ VineEstablishedState(vine_data_path_h dp, vine_dp_plugin_h plugin, vine_dp_plugin_fn fn);
~VineEstablishedState();
void enter();
void vine_dp_state_set_established_notifier(established_notifier notifier);
void vine_dp_state_set_data_received_notifier(data_received_notifier notifier);
-VineDataPathState *vine_get_default_state(vine_data_path_h dp, vine_dp_plugin_h plugin);
-void start_default_state(vine_data_path_h dp, vine_dp_plugin_h plugin, VineDataPathState *state);
-void start_connected_state(vine_data_path_h dp, vine_dp_plugin_h plugin, VineDataPathState *state);
-void start_accepted_state(vine_data_path_h dp, vine_dp_plugin_h plugin, VineDataPathState *state);
+VineDataPathState *vine_get_default_state(vine_data_path_h dp,
+ vine_dp_plugin_h plugin, vine_dp_plugin_fn fn);
+void start_default_state(vine_data_path_h dp, vine_dp_plugin_h plugin, vine_dp_plugin_fn fn,
+ VineDataPathState *state);
+void start_connected_state(vine_data_path_h dp, vine_dp_plugin_h plugin, vine_dp_plugin_fn fn,
+ VineDataPathState *state);
+void start_accepted_state(vine_data_path_h dp, vine_dp_plugin_h plugin, vine_dp_plugin_fn fn,
+ VineDataPathState *state);
#define __VINE_DATA_PATH_H__
#include "vine.h"
+#include "vine-data-path.h"
#include "vine-data-path-state.h"
#include "vine-event-loop.h"
typedef void (*vine_data_path_connected_cb)(vine_data_path_h datapath, int result, void *user_data);
typedef void (*vine_data_path_terminated_cb)(vine_data_path_h datapath, void *user_data);
+typedef enum {
+ VINE_DATA_PATH_METHOD_LWS = 0, // default
+ VINE_DATA_PATH_METHOD_BLE_GATT,
+ VINE_DATA_PATH_METHOD_UNKNOWN
+} vine_data_path_method_e;
int vine_data_path_init(void);
int vine_data_path_deinit(void);
-int vine_data_path_open(vine_address_family_e addr_family, int port,
+int vine_data_path_open(vine_data_path_method_e method,
+ vine_address_family_e addr_family, int port,
const char *iface_name, int max_conn,
vine_security_h security, const char *host_name,
vine_data_path_opened_cb opened_cb, void *opened_cb_data,
vine_data_path_accepted_cb accepted_cb, void *accepted_cb_data,
vine_data_path_h *opened_datapath,
vine_event_queue_h event_queue);
-int vine_data_path_connect(vine_address_family_e addr_family,
+int vine_data_path_connect(vine_data_path_method_e method,
+ vine_address_family_e addr_family,
const char *ip, int port, const char *iface_name,
vine_security_h security, const char *host_name, const char *token,
vine_data_path_connected_cb callback, void *user_data,
virtual int send(unsigned char *buf, size_t len) = 0;
virtual int recv(unsigned char *buf, size_t buf_len, size_t *read_len) = 0;
+ virtual int set_method(vine_dp_method_e method) = 0;
virtual int get_id(char **id) = 0;
virtual int set_addr_family(vine_address_family_e addr_family) = 0;
virtual int set_remote_ip(vine_address_family_e, const std::string &ip) = 0;
void invoke_received_cb(size_t received_len);
protected:
+ vine_data_path_method_e mMethod;
+
void *mEventQueue;
void *mSecurity;
std::string mIfaceName;
virtual int send(unsigned char *buf, size_t len);
virtual int recv(unsigned char *buf, size_t buf_len, size_t *read_len);
+ virtual int set_method(vine_dp_method_e method);
virtual int get_id(char **id);
virtual int set_addr_family(vine_address_family_e addr_family);
virtual int set_remote_ip(vine_address_family_e, const std::string &ip);
virtual int send(unsigned char *buf, size_t len);
virtual int recv(unsigned char *buf, size_t buf_len, size_t *read_len);
+ virtual int set_method(vine_dp_method_e method);
virtual int get_id(char **id);
virtual int set_addr_family(vine_address_family_e addr_family);
virtual int set_remote_ip(vine_address_family_e, const std::string &ip);
virtual int send(unsigned char *buf, size_t len);
virtual int recv(unsigned char *buf, size_t buf_len, size_t *read_len);
+ virtual int set_method(vine_dp_method_e method);
virtual int get_id(char **id);
virtual int set_addr_family(vine_address_family_e addr_family);
virtual int set_remote_ip(vine_address_family_e, const std::string &ip);
int _vine_dp_create(vine_session_h session, vine_dp_type_e type, vine_dp_h *dp);
int _vine_dp_destroy(vine_dp_h dp);
+int _vine_dp_set_method(vine_dp_h dp, vine_dp_method_e method);
int _vine_dp_get_id(vine_dp_h dp, char **id);
int _vine_dp_set_iface_name(vine_dp_h dp, const char *iface_name);
int _vine_dp_set_addr_family(vine_dp_h dp, vine_address_family_e addr_family);
#include "vine-log.h"
#include "vine-utils.h"
-extern vine_dp_plugin_fn g_dp_plugin_fn;
-
static state_changed_notifier __set_state;
static established_notifier __established;
static data_received_notifier __data_received;
new_state->enter();
}
-VineDataPathState::VineDataPathState(vine_data_path_h dp, vine_dp_plugin_h plugin)
- : __dp(dp), __plugin(plugin)
+VineDataPathState::VineDataPathState(vine_data_path_h dp,
+ vine_dp_plugin_h plugin, vine_dp_plugin_fn fn)
+ : __dp(dp), __plugin(plugin), __fn(fn)
{}
VineDataPathState::~VineDataPathState()
{}
-VineDefaultState::VineDefaultState(vine_data_path_h dp, vine_dp_plugin_h plugin)
- : VineDataPathState(dp, plugin)
+VineDefaultState::VineDefaultState(vine_data_path_h dp,
+ vine_dp_plugin_h plugin, vine_dp_plugin_fn fn)
+ : VineDataPathState(dp, plugin, fn)
{
}
void VineDefaultState::written_cb(size_t bytes)
{}
-VineAcceptedState::VineAcceptedState(vine_data_path_h dp, vine_dp_plugin_h plugin)
- : VineDataPathState(dp, plugin), __sent_frame(0), __accept(0)
+VineAcceptedState::VineAcceptedState(vine_data_path_h dp,
+ vine_dp_plugin_h plugin, vine_dp_plugin_fn fn)
+ : VineDataPathState(dp, plugin, fn), __sent_frame(0), __accept(0)
{
}
VINE_LOGD("+");
switch (__sent_frame) {
case AUTH_OP_REQUEST:
- state_transition(__dp, this, new VineAuthRequestedState(__dp, __plugin));
+ state_transition(__dp, this, new VineAuthRequestedState(__dp, __plugin, __fn));
break;
case AUTH_OP_CONFIRM:
if (__accept == 1)
- state_transition(__dp, this, new VineEstablishedState(__dp, __plugin));
+ state_transition(__dp, this, new VineEstablishedState(__dp, __plugin, __fn));
else
- state_transition(__dp, this, new VineAuthFailedState(__dp, __plugin));
+ state_transition(__dp, this, new VineAuthFailedState(__dp, __plugin, __fn));
break;
default:
VINE_LOGE("Invalid Frame %d", __sent_frame);
void VineAcceptedState::handle_failure(std::string msg)
{
VINE_LOGE("Failure %s", msg.c_str());
- state_transition(__dp, this, new VineAuthFailedState(__dp, __plugin));
+ state_transition(__dp, this, new VineAuthFailedState(__dp, __plugin, __fn));
}
void VineAcceptedState::send_auth_request()
return;
}
- g_dp_plugin_fn.write(__plugin, frame, size);
+ __fn.write(__plugin, frame, size);
release_auth_frame(frame);
}
return;
}
- g_dp_plugin_fn.write(__plugin, frame, size);
+ __fn.write(__plugin, frame, size);
release_auth_frame(frame);
}
-VineConnectedState::VineConnectedState(vine_data_path_h dp, vine_dp_plugin_h plugin)
- : VineDataPathState(dp, plugin), __sent_frame(0)
+VineConnectedState::VineConnectedState(vine_data_path_h dp,
+ vine_dp_plugin_h plugin, vine_dp_plugin_fn fn)
+ : VineDataPathState(dp, plugin, fn), __sent_frame(0)
{
}
VINE_LOGD("+");
switch (__sent_frame) {
case AUTH_OP_RESPONSE:
- state_transition(__dp, this, new VineAuthRespondedState(__dp, __plugin));
+ state_transition(__dp, this, new VineAuthRespondedState(__dp, __plugin, __fn));
break;
default:
VINE_LOGE("Invalid Frame %d", __sent_frame);
void VineConnectedState::handle_failure(std::string msg)
{
VINE_LOGE("Failure %s", msg.c_str());
- state_transition(__dp, this, new VineAuthFailedState(__dp, __plugin));
+ state_transition(__dp, this, new VineAuthFailedState(__dp, __plugin, __fn));
}
void VineConnectedState::read_data(size_t bytes)
{
unsigned char *buf = (unsigned char *)malloc(bytes);
- size_t read_size = g_dp_plugin_fn.read(__plugin, buf, bytes);
+ size_t read_size = __fn.read(__plugin, buf, bytes);
if (bytes != read_size) {
// TODO: Check it
handle_failure("Wrong size");
return;
}
- state_transition(__dp, this, new VineEstablishedState(__dp, __plugin));
+ state_transition(__dp, this, new VineEstablishedState(__dp, __plugin, __fn));
}
void VineConnectedState::send_auth_response()
return;
}
- g_dp_plugin_fn.write(__plugin, frame, size);
+ __fn.write(__plugin, frame, size);
release_auth_frame(frame);
free(psk);
__sent_frame = AUTH_OP_RESPONSE;
}
-VineAuthRequestedState::VineAuthRequestedState(vine_data_path_h dp, vine_dp_plugin_h plugin)
- : VineDataPathState(dp, plugin), __sent_frame(0), __accept(0)
+VineAuthRequestedState::VineAuthRequestedState(vine_data_path_h dp,
+ vine_dp_plugin_h plugin, vine_dp_plugin_fn fn)
+ : VineDataPathState(dp, plugin, fn), __sent_frame(0), __accept(0)
{
}
switch (__sent_frame) {
case AUTH_OP_CONFIRM:
if (__accept == 1)
- state_transition(__dp, this, new VineEstablishedState(__dp, __plugin));
+ state_transition(__dp, this, new VineEstablishedState(__dp, __plugin, __fn));
else
handle_failure("Not Accepted");
break;
void VineAuthRequestedState::handle_failure(std::string msg)
{
VINE_LOGE("Failure %s", msg.c_str());
- state_transition(__dp, this, new VineAuthFailedState(__dp, __plugin));
+ state_transition(__dp, this, new VineAuthFailedState(__dp, __plugin, __fn));
}
void VineAuthRequestedState::read_data(size_t bytes)
{
unsigned char *buf = (unsigned char *)malloc(bytes);
- size_t read_size = g_dp_plugin_fn.read(__plugin, buf, bytes);
+ size_t read_size = __fn.read(__plugin, buf, bytes);
if (bytes != read_size) {
// TODO: Check it
return;
}
- g_dp_plugin_fn.write(__plugin, frame, size);
+ __fn.write(__plugin, frame, size);
release_auth_frame(frame);
__sent_frame = AUTH_OP_CONFIRM;
__accept = accept;
}
-VineAuthRespondedState::VineAuthRespondedState(vine_data_path_h dp, vine_dp_plugin_h plugin)
- : VineDataPathState(dp, plugin)
+VineAuthRespondedState::VineAuthRespondedState(vine_data_path_h dp,
+ vine_dp_plugin_h plugin, vine_dp_plugin_fn fn)
+ : VineDataPathState(dp, plugin, fn)
{
}
void VineAuthRespondedState::handle_failure(std::string msg)
{
VINE_LOGE("Failure %s", msg.c_str());
- state_transition(__dp, this, new VineAuthFailedState(__dp, __plugin));
+ state_transition(__dp, this, new VineAuthFailedState(__dp, __plugin, __fn));
}
void VineAuthRespondedState::read_data(size_t bytes)
{
unsigned char *buf = (unsigned char *)malloc(bytes);
- size_t read_size = g_dp_plugin_fn.read(__plugin, buf, bytes);
+ size_t read_size = __fn.read(__plugin, buf, bytes);
if (bytes != read_size) {
// TODO: Check it
}
__timer.stop();
- state_transition(__dp, this, new VineEstablishedState(__dp, __plugin));
+ state_transition(__dp, this, new VineEstablishedState(__dp, __plugin, __fn));
}
-VineAuthFailedState::VineAuthFailedState(vine_data_path_h dp, vine_dp_plugin_h plugin)
- : VineDataPathState(dp, plugin)
+VineAuthFailedState::VineAuthFailedState(vine_data_path_h dp,
+ vine_dp_plugin_h plugin, vine_dp_plugin_fn fn)
+ : VineDataPathState(dp, plugin, fn)
{
}
VINE_LOGD("+");
}
-VineEstablishedState::VineEstablishedState(vine_data_path_h dp, vine_dp_plugin_h plugin)
- : VineDataPathState(dp, plugin)
+VineEstablishedState::VineEstablishedState(vine_data_path_h dp,
+ vine_dp_plugin_h plugin, vine_dp_plugin_fn fn)
+ : VineDataPathState(dp, plugin, fn)
{
}
int VineEstablishedState::read(unsigned char *buf, size_t buf_len, size_t *read_len)
{
- size_t bytes = g_dp_plugin_fn.read(__plugin, buf, buf_len);
+ size_t bytes = __fn.read(__plugin, buf, buf_len);
*read_len = bytes;
return VINE_ERROR_NONE;
}
int VineEstablishedState::write(unsigned char *buf, size_t len)
{
- g_dp_plugin_fn.write(__plugin, buf, len);
+ __fn.write(__plugin, buf, len);
return VINE_ERROR_NONE;
}
__data_received = notifier;
}
-VineDataPathState *vine_get_default_state(vine_data_path_h dp, vine_dp_plugin_h plugin)
+VineDataPathState *vine_get_default_state(vine_data_path_h dp,
+ vine_dp_plugin_h plugin, vine_dp_plugin_fn fn)
{
- return new VineDefaultState(dp, plugin);
+ return new VineDefaultState(dp, plugin, fn);
}
-void start_default_state(vine_data_path_h dp, vine_dp_plugin_h plugin,
+void start_default_state(vine_data_path_h dp, vine_dp_plugin_h plugin, vine_dp_plugin_fn fn,
VineDataPathState *state)
{
VINE_LOGD("Default");
- state_transition(dp, state, new VineDefaultState(dp, plugin));
+ state_transition(dp, state, new VineDefaultState(dp, plugin, fn));
}
-void start_connected_state(vine_data_path_h dp, vine_dp_plugin_h plugin,
+void start_connected_state(vine_data_path_h dp, vine_dp_plugin_h plugin, vine_dp_plugin_fn fn,
VineDataPathState *state)
{
VINE_LOGD("Connected");
- state_transition(dp, state, new VineConnectedState(dp, plugin));
+ state_transition(dp, state, new VineConnectedState(dp, plugin, fn));
}
-void start_accepted_state(vine_data_path_h dp, vine_dp_plugin_h plugin,
+void start_accepted_state(vine_data_path_h dp, vine_dp_plugin_h plugin, vine_dp_plugin_fn fn,
VineDataPathState *state)
{
VINE_LOGD("Accepted");
- state_transition(dp, state, new VineAcceptedState(dp, plugin));
+ state_transition(dp, state, new VineAcceptedState(dp, plugin, fn));
}
#include "vine-log.h"
#include "vine-utils.h"
+static struct {
+ const char *name;
+ const char *path;
+} __vine_data_path_plugins_info[] = {
+ [VINE_DATA_PATH_METHOD_LWS] = {"Websocket", LWS_PLUGIN_PATH},
+#ifdef BT_SUPPORT
+ [VINE_DATA_PATH_METHOD_BLE_GATT] = {"BLE GATT", BLE_GATT_PLUGIN_PATH},
+#endif
+ {NULL, NULL},
+};
+
+struct {
+ vine_dp_plugin_fn fn;
+ vine_dp_plugin_callbacks callbacks;
+ void (*init)(vine_dp_plugin_fn *fn);
+} __vine_data_path_plugins[] = {
+ {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
+ {NULL, NULL, NULL, NULL, NULL, NULL, NULL}, NULL},
+ {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
+ {NULL, NULL, NULL, NULL, NULL, NULL, NULL}, NULL},
+ {{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
+ {NULL, NULL, NULL, NULL, NULL, NULL, NULL}, NULL},
+};
+
typedef struct {
+ vine_data_path_method_e method;
+ vine_dp_plugin_fn *plugin_fn;
+
vine_address_family_e addr_family;
char *addr;
int port;
vine_data_path_s *connected_dp;
} vine_dp_accepted_event;
-vine_dp_plugin_fn g_dp_plugin_fn = {
- .init = NULL,
- .deinit = NULL,
- .register_callbacks = NULL,
- .process_event = NULL,
- .create = NULL,
- .destroy = NULL,
- .open = NULL,
- .connect = NULL,
- .read = NULL,
- .write = NULL
-};
-
-static vine_dp_plugin_callbacks g_dp_plugin_cbs = {
- .pollfd_cb = NULL,
- .opened_cb = NULL,
- .accepted_cb = NULL,
- .connected_cb = NULL,
- .received_cb = NULL,
- .written_cb = NULL,
- .terminated_cb = NULL,
-};
-
-static void (*__init_plugin)(vine_dp_plugin_fn *fn);
-static vine_data_path_s *_vine_data_path_create(vine_address_family_e addr_family,
+static vine_data_path_s *_vine_data_path_create(vine_data_path_method_e method,
+ vine_address_family_e addr_family,
const char *addr, int port, vine_security_h security,
void *plugin_data, vine_event_queue_h event_queue);
void __vine_dp_poll_handler(int fd, int events, void *user_data)
{
- g_dp_plugin_fn.process_event(fd, events);
+ // TODO: Only LWS plugin supports polling functions.
+ // But, we need to modify pollfd_cb to pass datapath handle as the user_data
+ if (__vine_data_path_plugins[VINE_DATA_PATH_METHOD_LWS].fn.process_event)
+ __vine_data_path_plugins[VINE_DATA_PATH_METHOD_LWS].fn.process_event(fd, events);
}
void __vine_dp_op_handler(int fd, int events, void *user_data)
VINE_LOGE("Read error(%d)", errno);
return;
}
- g_dp_plugin_fn.process_event(fd, events);
+ // TODO: Only LWS plugin supports polling functions.
+ // But, we need to modify pollfd_cb to pass datapath handle as the user_data
+ if (__vine_data_path_plugins[VINE_DATA_PATH_METHOD_LWS].fn.process_event)
+ __vine_data_path_plugins[VINE_DATA_PATH_METHOD_LWS].fn.process_event(fd, events);
}
static void __pollfd_cb(vine_data_path_pollfd_op_e op, int fd, int events)
return VINE_ADDRESS_FAMILY_IPV4;
case VINE_DP_IPV6:
return VINE_ADDRESS_FAMILY_IPV6;
+ case VINE_DP_NOT_IP:
+ default:
+ return VINE_ADDRESS_FAMILY_DEFAULT;
}
- return VINE_ADDRESS_FAMILY_DEFAULT;
}
static void __accepted_cb(vine_dp_addr_family_e addr_family, char *addr,
vine_data_path_s *listen_dp = (vine_data_path_s *)user_data;
VINE_LOGE("listen_dp[%p], security[%p]", listen_dp, listen_dp->security);
- vine_data_path_s *connected_dp = _vine_data_path_create(__convert_addr_family(addr_family),
+ vine_data_path_s *connected_dp = _vine_data_path_create(listen_dp->method,
+ __convert_addr_family(addr_family),
addr, port, listen_dp->security, plugin_data, listen_dp->event_queue);
RET_IF(connected_dp == NULL, "Out of memory");
VINE_LOGD("Start Authentication");
connected_dp->established = notify_accepted;
- start_accepted_state(connected_dp, connected_dp->plugin_handle, connected_dp->state);
+ start_accepted_state(connected_dp, connected_dp->plugin_handle, *connected_dp->plugin_fn,
+ connected_dp->state);
}
static void __invoke_connected_user_cb(void *event, void *user_data)
VINE_LOGD("Start Authentication");
dp->established = notify_connected;
- start_connected_state(dp, dp->plugin_handle, dp->state);
+ start_connected_state(dp, dp->plugin_handle, *dp->plugin_fn, dp->state);
}
static void __invoke_received_user_cb(void *event, void *user_data)
VINE_LOGD("user callback is invoked by event queue.");
- start_default_state(dp, dp->plugin_handle, dp->state);
+ start_default_state(dp, dp->plugin_handle, *dp->plugin_fn, dp->state);
if (dp->terminated_cb)
dp->terminated_cb(dp, dp->terminated_cb_data);
}
static int _load_data_path_plugins(void)
{
- void *handle = dlopen(DATA_PATH_PLUGIN_PATH, RTLD_LAZY | RTLD_NODELETE);
- if (handle) {
- __init_plugin = (void (*)(vine_dp_plugin_fn *))dlsym(handle, "vine_data_path_plugin_init");
- dlclose(handle);
- VINE_LOGI("Loaded %s", DATA_PATH_PLUGIN_PATH);
- } else {
- VINE_LOGE("%s doesn't exist", DATA_PATH_PLUGIN_PATH);
- return VINE_ERROR_OPERATION_FAILED;
+ int loaded = 0;
+
+ for (int i = 0; __vine_data_path_plugins_info[i].path; ++i) {
+ void *handle = dlopen(__vine_data_path_plugins_info[i].path, RTLD_LAZY | RTLD_NODELETE);
+ if (handle) {
+ __vine_data_path_plugins[i].init =
+ (void (*)(vine_dp_plugin_fn *))dlsym(handle, "vine_data_path_plugin_init");
+ dlclose(handle);
+ ++loaded;
+ VINE_LOGI("Loaded %s", __vine_data_path_plugins_info[i].path);
+ } else {
+ VINE_LOGE("%s doesn't exist", __vine_data_path_plugins_info[i].path);
+ }
}
- return VINE_ERROR_NONE;
+ VINE_LOGI("%d plugins are loaded.", loaded);
+ return (loaded > 0 ? VINE_ERROR_NONE : VINE_ERROR_OPERATION_FAILED);
}
int vine_data_path_set_received_cb(
RET_VAL_IF(datapath == NULL, VINE_ERROR_INVALID_PARAMETER, "datapath is NULL");
vine_data_path_s *dp = (vine_data_path_s *)datapath;
- g_dp_plugin_fn.close(dp->plugin_handle);
+ RET_VAL_IF(!dp->plugin_fn || dp->plugin_fn->close,
+ VINE_ERROR_INVALID_PARAMETER, "plugin_fn is NULL");
+ dp->plugin_fn->close(dp->plugin_handle);
return VINE_ERROR_NONE;
}
-static vine_data_path_s *_vine_data_path_create(vine_address_family_e addr_family,
+static vine_data_path_s *_vine_data_path_create(vine_data_path_method_e method,
+ vine_address_family_e addr_family,
const char *addr, int port, vine_security_h security,
void *plugin_data, vine_event_queue_h event_queue)
{
+ RET_VAL_IF(method < VINE_DATA_PATH_METHOD_LWS || method >= VINE_DATA_PATH_METHOD_UNKNOWN,
+ NULL, "Unknown method.");
RET_VAL_IF(addr == NULL, NULL, "addr is NULL");
int ret = VINE_ERROR_NONE;
dp = (vine_data_path_s *)calloc(1, sizeof(vine_data_path_s));
RET_VAL_IF(dp == NULL, NULL, "Out of memory");
+ dp->method = method;
+ dp->plugin_fn = &__vine_data_path_plugins[method].fn;
+ if (!dp->plugin_fn || !dp->plugin_fn->create) {
+ free(dp);
+ return NULL;
+ }
+
dp->addr_family = addr_family;
dp->addr = STRDUP(addr);
if (dp->addr == NULL) {
dp->security = NULL;
}
- ret = g_dp_plugin_fn.create(&dp->plugin_handle, plugin_data, dp);
+ ret = dp->plugin_fn->create(&dp->plugin_handle, plugin_data, dp);
if (ret != VINE_DATA_PATH_ERROR_NONE) {
free(dp->addr);
_vine_security_destroy(dp->security);
return NULL;
}
- dp->state = vine_get_default_state(dp, dp->plugin_handle);
- VINE_LOGD("datapath[%p] is created.", dp);
+ dp->state = vine_get_default_state(dp, dp->plugin_handle, *dp->plugin_fn);
+ VINE_LOGD("datapath[%p] is created. method[%d]", dp, method);
return dp;
}
RET_VAL_IF(datapath == NULL, VINE_ERROR_INVALID_PARAMETER, "datapath is NULL");
vine_data_path_s *dp = (vine_data_path_s *)datapath;
- g_dp_plugin_fn.destroy(dp->plugin_handle);
+ if (dp->plugin_fn && dp->plugin_fn->destroy)
+ dp->plugin_fn->destroy(dp->plugin_handle);
+
dp->plugin_handle = NULL;
free(dp->addr);
dp->addr = NULL;
notify_data_received(dp, bytes);
}
+static int __init_plugins(void)
+{
+ vine_dp_plugin_callbacks callbacks = {
+ .pollfd_cb = __pollfd_cb,
+ .opened_cb = __opened_cb,
+ .accepted_cb = __accepted_cb,
+ .connected_cb = __connected_cb,
+ .received_cb = __received_cb,
+ .written_cb = __written_cb,
+ .terminated_cb = __terminated_cb,
+ };
+
+ for (int i = 0; __vine_data_path_plugins[i].init; ++i) {
+ __vine_data_path_plugins[i].init(&__vine_data_path_plugins[i].fn);
+ if (__vine_data_path_plugins[i].fn.init() != VINE_ERROR_NONE)
+ continue;
+
+ __vine_data_path_plugins[i].callbacks = callbacks;
+ __vine_data_path_plugins[i].fn.register_callbacks(__vine_data_path_plugins[i].callbacks);
+ }
+
+ return VINE_ERROR_NONE;
+}
+
+static void __deinit_plugins(void)
+{
+ for (int i = 0; __vine_data_path_plugins[i].fn.deinit; ++i)
+ __vine_data_path_plugins[i].fn.deinit();
+}
+
int vine_data_path_init(void)
{
int ret = _load_data_path_plugins();
RET_VAL_IF(ret != VINE_ERROR_NONE, ret, "Fail to load plugins");
- __init_plugin(&g_dp_plugin_fn);
- ret = g_dp_plugin_fn.init();
+ ret = __init_plugins();
RET_VAL_IF(ret != VINE_DATA_PATH_ERROR_NONE,
__convert_data_path_error_to_vine_error((vine_data_path_error)ret),
"Filed to init dp-plugin");
- g_dp_plugin_cbs.pollfd_cb = __pollfd_cb;
- g_dp_plugin_cbs.opened_cb = __opened_cb;
- g_dp_plugin_cbs.accepted_cb = __accepted_cb;
- g_dp_plugin_cbs.connected_cb = __connected_cb;
- g_dp_plugin_cbs.received_cb = __received_cb;
- g_dp_plugin_cbs.written_cb = __written_cb;
- g_dp_plugin_cbs.terminated_cb = __terminated_cb;
- g_dp_plugin_fn.register_callbacks(g_dp_plugin_cbs);
-
vine_dp_state_set_state_changed_notifier(__set_state);
vine_dp_state_set_established_notifier(__established);
vine_dp_state_set_data_received_notifier(__data_received);
int vine_data_path_deinit(void)
{
- g_dp_plugin_fn.deinit();
-
+ __deinit_plugins();
return VINE_ERROR_NONE;
}
free(dest->key_path);
}
-int vine_data_path_open(vine_address_family_e addr_family, int port, const char *iface_name,
+int vine_data_path_open(vine_data_path_method_e method,
+ vine_address_family_e addr_family, int port, const char *iface_name,
int max_conn, vine_security_h security, const char *host_name,
vine_data_path_opened_cb opened_cb, void *opened_cb_data,
vine_data_path_accepted_cb accepted_cb, void *accepted_cb_data,
}
vine_data_path_s *dp =
- _vine_data_path_create(addr_family, "", port, security, NULL, event_queue);
+ _vine_data_path_create(method, addr_family, "", port, security, NULL, event_queue);
RET_VAL_IF(dp == NULL, VINE_ERROR_OUT_OF_MEMORY, "Out of memory");
+ RET_VAL_IF(dp->plugin_fn == NULL, VINE_ERROR_INVALID_PARAMETER, "Invalid parameter");
+ RET_VAL_IF(dp->plugin_fn->open == NULL, VINE_ERROR_INVALID_PARAMETER, "Invalid parameter");
vine_dp_ssl ssl = {false, VINE_DP_TLS_VERSION_DEFAULT, 0, NULL, NULL, NULL};
_extract_security_info(security, &ssl);
dp->accepted_cb_data = accepted_cb_data;
// optional
- if (host_name) {
- ret = g_dp_plugin_fn.set_host_name(dp->plugin_handle, host_name);
+ if (host_name && dp->plugin_fn->set_host_name) {
+ ret = dp->plugin_fn->set_host_name(dp->plugin_handle, host_name);
if (ret != VINE_DATA_PATH_ERROR_NONE) {
vine_data_path_destroy(dp);
return __convert_data_path_error_to_vine_error((vine_data_path_error)ret);
}
}
- ret = g_dp_plugin_fn.open(dp->plugin_handle, dp_addr_family, port, iface_name, max_conn, ssl);
+ ret = dp->plugin_fn->open(dp->plugin_handle, dp_addr_family, port, iface_name, max_conn, ssl);
_destroy_security_info(&ssl);
if (ret != VINE_DATA_PATH_ERROR_NONE) {
return VINE_ERROR_NONE;
}
-int vine_data_path_connect(vine_address_family_e addr_family,
+int vine_data_path_connect(vine_data_path_method_e method,
+ vine_address_family_e addr_family,
const char *ip, int port, const char *iface_name,
vine_security_h security, const char *host_name, const char *token,
vine_data_path_connected_cb callback, void *user_data,
vine_data_path_h *connected_datapath, vine_event_queue_h event_queue)
{
vine_data_path_s *dp =
- _vine_data_path_create(addr_family, ip, port, security, NULL, event_queue);
+ _vine_data_path_create(method, addr_family, ip, port, security, NULL, event_queue);
RET_VAL_IF(dp == NULL, VINE_ERROR_OUT_OF_MEMORY, "Out of memory");
+ RET_VAL_IF(dp->plugin_fn == NULL, VINE_ERROR_INVALID_PARAMETER, "Invalid parameter");
+ RET_VAL_IF(dp->plugin_fn->connect == NULL, VINE_ERROR_INVALID_PARAMETER, "Invalid parameter");
RET_VAL_IF(connected_datapath == NULL,
VINE_ERROR_INVALID_PARAMETER, "connected_datapath is NULL");
int ret;
// optional
- if (host_name) {
- ret = g_dp_plugin_fn.set_host_name(dp->plugin_handle, host_name);
+ if (host_name && dp->plugin_fn->set_host_name) {
+ ret = dp->plugin_fn->set_host_name(dp->plugin_handle, host_name);
if (ret != VINE_DATA_PATH_ERROR_NONE) {
vine_data_path_destroy(dp);
return __convert_data_path_error_to_vine_error((vine_data_path_error)ret);
}
}
- if (token) {
- ret = g_dp_plugin_fn.set_token(dp->plugin_handle, token);
+ if (token && dp->plugin_fn->set_token) {
+ ret = dp->plugin_fn->set_token(dp->plugin_handle, token);
if (ret != VINE_DATA_PATH_ERROR_NONE) {
vine_data_path_destroy(dp);
_destroy_security_info(&ssl);
}
}
- ret = g_dp_plugin_fn.connect(dp->plugin_handle,
+ ret = dp->plugin_fn->connect(dp->plugin_handle,
addr_family == VINE_ADDRESS_FAMILY_IPV4 ? VINE_DP_IPV4 : VINE_DP_IPV6,
ip, port, iface_name, ssl);
_destroy_security_info(&ssl);
RET_VAL_IF(token == NULL, VINE_ERROR_INVALID_PARAMETER, "token is NULL");
vine_data_path_s *dp = (vine_data_path_s *)datapath;
- int ret = g_dp_plugin_fn.get_token(dp->plugin_handle, token);
+ if (!dp->plugin_fn || !dp->plugin_fn->get_token)
+ return VINE_ERROR_INVALID_PARAMETER;
+
+ int ret = dp->plugin_fn->get_token(dp->plugin_handle, token);
return __convert_data_path_error_to_vine_error((vine_data_path_error)ret);
}
RET_VAL_IF(port == NULL, VINE_ERROR_INVALID_PARAMETER, "port is NULL");
vine_data_path_s *dp = (vine_data_path_s *)datapath;
+ RET_VAL_IF(!dp->plugin_fn || !dp->plugin_fn->get_local_address_info,
+ VINE_ERROR_INVALID_PARAMETER, "plugin_fn is NULL");
+
vine_error_e error;
int addr_family, local_port;
char local_ip[VINE_MAX_IP_LEN + 1] = {0, };
- int ret = g_dp_plugin_fn.get_local_address_info(dp->plugin_handle,
+ int ret = dp->plugin_fn->get_local_address_info(dp->plugin_handle,
&addr_family, local_ip, &local_port);
error = __convert_data_path_error_to_vine_error((vine_data_path_error)ret);
DPServer::DPServer(void *event_queue)
{
VINE_LOGD("DPServer[%p] is created.", this);
+ mMethod = VINE_DATA_PATH_METHOD_LWS;
mEventQueue = event_queue;
mSecurity = NULL;
mAddrFamily = VINE_ADDRESS_FAMILY_DEFAULT;
vine_data_path_destroy(mDataPath);
}
+int DPServer::set_method(vine_dp_method_e method)
+{
+ if (method < VINE_DP_METHOD_DEFAULT || method >= VINE_DP_METHOD_UNKNOWN)
+ return VINE_ERROR_INVALID_PARAMETER;
+
+ switch (method) {
+ case VINE_DP_METHOD_DEFAULT:
+ mMethod = VINE_DATA_PATH_METHOD_LWS;
+ break;
+ case VINE_DP_METHOD_BLE_GATT:
+ mMethod = VINE_DATA_PATH_METHOD_BLE_GATT;
+ break;
+ default:
+ mMethod = VINE_DATA_PATH_METHOD_LWS;
+ }
+ return VINE_ERROR_NONE;
+}
+
int DPServer::get_id(char **id)
{
return VINE_ERROR_INVALID_OPERATION;
mOpenedCbData = user_data;
mOpenState = VINE_DP_OPEN_STATE_WAIT;
- int ret = vine_data_path_open(mAddrFamily, mListenPort,
+ int ret = vine_data_path_open(mMethod,
+ mAddrFamily, mListenPort,
mIfaceName.size() > 0 ? mIfaceName.c_str() : NULL,
mMaxConnNum, mSecurity, NULL,
_opened_cb, static_cast<void *>(this),
DPClient::DPClient(void *event_queue)
{
VINE_LOGD("DPClient[%p] is created.", this);
+ mMethod = VINE_DATA_PATH_METHOD_LWS;
mEventQueue = event_queue;
mSecurity = NULL;
mAddrFamily = VINE_ADDRESS_FAMILY_DEFAULT;
vine_data_path_destroy(mDataPath);
}
+int DPClient::set_method(vine_dp_method_e method)
+{
+ if (method < VINE_DP_METHOD_DEFAULT || method >= VINE_DP_METHOD_UNKNOWN)
+ return VINE_ERROR_INVALID_PARAMETER;
+
+ switch (method) {
+ case VINE_DP_METHOD_DEFAULT:
+ mMethod = VINE_DATA_PATH_METHOD_LWS;
+ break;
+ case VINE_DP_METHOD_BLE_GATT:
+ mMethod = VINE_DATA_PATH_METHOD_BLE_GATT;
+ break;
+ default:
+ mMethod = VINE_DATA_PATH_METHOD_LWS;
+ }
+ return VINE_ERROR_NONE;
+}
+
int DPClient::get_id(char **id)
{
return VINE_ERROR_INVALID_OPERATION;
mOpenedCbData = user_data;
mOpenState = VINE_DP_OPEN_STATE_WAIT;
- int ret = vine_data_path_connect(mAddrFamily, mPeerIp.c_str(), mPeerPort,
+ int ret = vine_data_path_connect(mMethod,
+ mAddrFamily, mPeerIp.c_str(), mPeerPort,
mIfaceName.size() > 0 ? mIfaceName.c_str() : NULL,
mSecurity, NULL, NULL,
_connected_cb, static_cast<void *>(this), &mDataPath, mEventQueue);
DPPubSub::DPPubSub(void *event_queue)
{
VINE_LOGD("DPPubSub[%p] is created.", this);
+ mMethod = VINE_DATA_PATH_METHOD_LWS;
mEventQueue = event_queue;
mSecurity = NULL;
mIfaceName = "";
close();
}
+int DPPubSub::set_method(vine_dp_method_e method)
+{
+ if (method < VINE_DP_METHOD_DEFAULT || method >= VINE_DP_METHOD_UNKNOWN)
+ return VINE_ERROR_INVALID_PARAMETER;
+
+ if (method == VINE_DP_METHOD_BLE_GATT)
+ return VINE_ERROR_INVALID_OPERATION;
+
+ mMethod = VINE_DATA_PATH_METHOD_LWS;
+ return VINE_ERROR_NONE;
+}
+
void DPPubSub::set_id(const char *id)
{
if (id == NULL || mId.compare(id) == 0)
conn_data->dp = static_cast<void *>(this);
conn_data->service_name = STRDUP(service_name);
- int ret = vine_data_path_connect(mAddrFamily, ip, port, iface_name,
+ int ret = vine_data_path_connect(mMethod,
+ mAddrFamily, ip, port, iface_name,
mSecurity, service_name, mId.c_str(),
_pubsub_connected_cb, (void *)conn_data,
&datapath, mEventQueue);
create_id(service_name);
set_id(service_name);
- int ret = vine_data_path_open(mAddrFamily, mListenPort,
+ int ret = vine_data_path_open(mMethod,
+ mAddrFamily, mListenPort,
mIfaceName.size() > 0 ? mIfaceName.c_str() : NULL,
mMaxConnNum, mSecurity, mId.c_str(),
_pubsub_opened_cb, static_cast<void *>(this),
vine_event_queue_h eq = NULL;
int ret = _vine_session_get_event_queue(session, &eq);
- if (ret != VINE_ERROR_NONE || !eq)
+ // eq can be NULL if glib is used as the eventloop.
+ if (ret != VINE_ERROR_NONE)
return VINE_ERROR_INVALID_PARAMETER;
if (type == VINE_DP_TYPE_SERVER) {
return VINE_ERROR_NONE;
}
+int _vine_dp_set_method(vine_dp_h dp, vine_dp_method_e method)
+{
+ RET_VAL_IF(dp == NULL, VINE_ERROR_INVALID_PARAMETER, "dp is null.");
+
+ DataPath *_dp = static_cast<DataPath *>(dp);
+ return _dp->set_method(method);;
+}
+
int _vine_dp_get_id(vine_dp_h dp, char **id)
{
RET_VAL_IF(dp == NULL, VINE_ERROR_INVALID_PARAMETER, "dp is null.");
return _vine_dp_destroy(dp);
}
+API int vine_dp_set_method(vine_dp_h dp, vine_dp_method_e method)
+{
+ __VINE_FUNC_ENTER__;
+ CHECK_FEATURE_SUPPORTED;
+
+ return _vine_dp_set_method(dp, method);
+}
+
API int vine_dp_get_id(vine_dp_h dp, char **id)
{
__VINE_FUNC_ENTER__;
vine_dp_destroy(dp));
}
+TEST_F(VineDpTest, SetMethodN)
+{
+ EXPECT_EQ(VINE_ERROR_INVALID_PARAMETER, vine_dp_set_method(server_dp, VINE_DP_METHOD_UNKNOWN));
+ EXPECT_EQ(VINE_ERROR_INVALID_PARAMETER, vine_dp_set_method(client_dp, VINE_DP_METHOD_UNKNOWN));
+ EXPECT_EQ(VINE_ERROR_INVALID_OPERATION, vine_dp_set_method(pubsub_dp, VINE_DP_METHOD_BLE_GATT));
+}
+
+TEST_F(VineDpTest, SetMethodP)
+{
+ EXPECT_EQ(VINE_ERROR_NONE, vine_dp_set_method(server_dp, VINE_DP_METHOD_BLE_GATT));
+ EXPECT_EQ(VINE_ERROR_NONE, vine_dp_set_method(client_dp, VINE_DP_METHOD_BLE_GATT));
+ EXPECT_EQ(VINE_ERROR_NONE, vine_dp_set_method(pubsub_dp, VINE_DP_METHOD_DEFAULT));
+}
+
TEST_F(VineDpTest, GetIdN)
{
char *id = NULL;
vine_dp_set_address_family(vine_configs.dp, addr_family);
vine_dp_set_max_connections(vine_configs.dp, tool_config_get_max_conn());
+ if (vine_configs.with_ble)
+ vine_dp_set_method(vine_configs.dp, VINE_DP_METHOD_BLE_GATT);
+
if (type == VINE_DP_TYPE_CLIENT) {
vine_dp_set_remote_port(vine_configs.dp, tool_config_get_port());
vine_dp_set_remote_ip(vine_configs.dp, addr_family,