Define handle for custom connection to hide internal structure.
Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
#include "nnstreamer-edge-log.h"
#include "nnstreamer-edge-util.h"
+/**
+ * @brief Internal data structure for edge custom connection.
+ */
+typedef struct
+{
+ void *dl_handle;
+ nns_edge_custom_s *instance;
+ void *priv;
+} custom_connection_s;
+
typedef const nns_edge_custom_s *custom_get_instance (void);
/**
* @brief Internal function to load custom connection from library.
*/
int
-nns_edge_custom_load (custom_connection_s * custom, const char *lib_path)
+nns_edge_custom_load (const char *lib_path,
+ nns_edge_custom_connection_h * handle)
{
+ custom_connection_s *custom;
nns_edge_custom_s *custom_h;
int ret;
if (!STR_IS_VALID (lib_path))
return NNS_EDGE_ERROR_INVALID_PARAMETER;
- if (!custom)
+ if (!handle)
return NNS_EDGE_ERROR_INVALID_PARAMETER;
+ custom = (custom_connection_s *) calloc (1, sizeof (custom_connection_s));
+ if (!custom) {
+ nns_edge_loge ("Failed to allocate memory for edge custom connection.");
+ return NNS_EDGE_ERROR_OUT_OF_MEMORY;
+ }
+
ret = _load_custom_library (custom, lib_path);
if (NNS_EDGE_ERROR_NONE != ret) {
nns_edge_loge
}
error:
- if (NNS_EDGE_ERROR_NONE != ret) {
+ if (NNS_EDGE_ERROR_NONE == ret) {
+ *handle = custom;
+ } else {
nns_edge_custom_release (custom);
}
* @brief Internal function to release custom connection.
*/
int
-nns_edge_custom_release (custom_connection_s * custom)
+nns_edge_custom_release (nns_edge_custom_connection_h handle)
{
+ custom_connection_s *custom = (custom_connection_s *) handle;
nns_edge_custom_s *custom_h;
int ret;
custom->instance = NULL;
custom->priv = NULL;
+ free (custom);
return ret;
}
* @brief Internal function to start custom connection.
*/
int
-nns_edge_custom_start (custom_connection_s * custom)
+nns_edge_custom_start (nns_edge_custom_connection_h handle)
{
+ custom_connection_s *custom = (custom_connection_s *) handle;
nns_edge_custom_s *custom_h;
int ret;
* @brief Internal function to stop custom connection.
*/
int
-nns_edge_custom_stop (custom_connection_s * custom)
+nns_edge_custom_stop (nns_edge_custom_connection_h handle)
{
+ custom_connection_s *custom = (custom_connection_s *) handle;
nns_edge_custom_s *custom_h;
int ret;
* @brief Internal function to set the event callback of custom connection.
*/
int
-nns_edge_custom_set_event_callback (custom_connection_s * custom,
+nns_edge_custom_set_event_callback (nns_edge_custom_connection_h handle,
nns_edge_event_cb cb, void *user_data)
{
+ custom_connection_s *custom = (custom_connection_s *) handle;
nns_edge_custom_s *custom_h;
int ret;
* @brief Internal function to connect custom connection.
*/
int
-nns_edge_custom_connect (custom_connection_s * custom)
+nns_edge_custom_connect (nns_edge_custom_connection_h handle)
{
+ custom_connection_s *custom = (custom_connection_s *) handle;
nns_edge_custom_s *custom_h;
int ret;
* @brief Internal function to check custom connection.
*/
int
-nns_edge_custom_is_connected (custom_connection_s * custom)
+nns_edge_custom_is_connected (nns_edge_custom_connection_h handle)
{
+ custom_connection_s *custom = (custom_connection_s *) handle;
nns_edge_custom_s *custom_h;
if (!custom || !custom->instance)
* @brief Internal function to send data to custom connection.
*/
int
-nns_edge_custom_send_data (custom_connection_s * custom, nns_edge_data_h data_h)
+nns_edge_custom_send_data (nns_edge_custom_connection_h handle,
+ nns_edge_data_h data_h)
{
+ custom_connection_s *custom = (custom_connection_s *) handle;
nns_edge_custom_s *custom_h;
int ret;
* @brief Internal function to set information to custom connection.
*/
int
-nns_edge_custom_set_info (custom_connection_s * custom, const char *key,
+nns_edge_custom_set_info (nns_edge_custom_connection_h handle, const char *key,
const char *value)
{
+ custom_connection_s *custom = (custom_connection_s *) handle;
nns_edge_custom_s *custom_h;
int ret = NNS_EDGE_ERROR_NOT_SUPPORTED;
* @brief Internal function to get information from custom connection.
*/
int
-nns_edge_custom_get_info (custom_connection_s * custom, const char *key,
+nns_edge_custom_get_info (nns_edge_custom_connection_h handle, const char *key,
char **value)
{
+ custom_connection_s *custom = (custom_connection_s *) handle;
nns_edge_custom_s *custom_h;
int ret = NNS_EDGE_ERROR_NOT_SUPPORTED;
extern "C" {
#endif /* __cplusplus */
-/**
- * @brief Data structure for edge custom connection.
- */
-typedef struct
-{
- void *dl_handle;
- nns_edge_custom_s *instance;
- void *priv;
-} custom_connection_s;
+typedef void *nns_edge_custom_connection_h;
#if defined(ENABLE_CUSTOM_CONNECTION)
/**
* @brief Internal function to load custom connection from library.
*/
-int nns_edge_custom_load (custom_connection_s *custom, const char *lib_path);
+int nns_edge_custom_load (const char *lib_path, nns_edge_custom_connection_h *handle);
/**
* @brief Internal function to release custom connection.
*/
-int nns_edge_custom_release (custom_connection_s *custom);
+int nns_edge_custom_release (nns_edge_custom_connection_h handle);
/**
* @brief Internal function to start custom connection.
*/
-int nns_edge_custom_start (custom_connection_s *custom);
+int nns_edge_custom_start (nns_edge_custom_connection_h handle);
/**
* @brief Internal function to stop custom connection.
*/
-int nns_edge_custom_stop (custom_connection_s *custom);
+int nns_edge_custom_stop (nns_edge_custom_connection_h handle);
/**
* @brief Internal function to set the event callback of custom connection.
*/
-int nns_edge_custom_set_event_callback (custom_connection_s *custom, nns_edge_event_cb cb, void *user_data);
+int nns_edge_custom_set_event_callback (nns_edge_custom_connection_h handle, nns_edge_event_cb cb, void *user_data);
/**
* @brief Internal function to connect custom connection.
*/
-int nns_edge_custom_connect (custom_connection_s *custom);
+int nns_edge_custom_connect (nns_edge_custom_connection_h handle);
/**
* @brief Internal function to check custom connection.
*/
-int nns_edge_custom_is_connected (custom_connection_s *custom);
+int nns_edge_custom_is_connected (nns_edge_custom_connection_h handle);
/**
* @brief Internal function to send data to custom connection.
*/
-int nns_edge_custom_send_data (custom_connection_s *custom, nns_edge_data_h data_h);
+int nns_edge_custom_send_data (nns_edge_custom_connection_h handle, nns_edge_data_h data_h);
/**
* @brief Internal function to set information to custom connection.
*/
-int nns_edge_custom_set_info (custom_connection_s *custom, const char *key, const char *value);
+int nns_edge_custom_set_info (nns_edge_custom_connection_h handle, const char *key, const char *value);
/**
* @brief Internal function to get information from custom connection.
*/
-int nns_edge_custom_get_info (custom_connection_s *custom, const char *key, char **value);
+int nns_edge_custom_get_info (nns_edge_custom_connection_h handle, const char *key, char **value);
#else
#define nns_edge_custom_load(...) (NNS_EDGE_ERROR_NOT_SUPPORTED)
#define nns_edge_custom_release(...) (NNS_EDGE_ERROR_NOT_SUPPORTED)
void *broker_h;
/* Data for custom connection */
- custom_connection_s custom;
+ nns_edge_custom_connection_h custom_connection_h;
} nns_edge_handle_s;
/**
nns_edge_loge ("Failed to send data via MQTT connection.");
break;
case NNS_EDGE_CONNECT_TYPE_CUSTOM:
- ret = nns_edge_custom_send_data (&eh->custom, data_h);
+ ret = nns_edge_custom_send_data (eh->custom_connection_h, data_h);
if (NNS_EDGE_ERROR_NONE != ret)
nns_edge_loge ("Failed to send data via custom connection.");
break;
eh->sending = false;
eh->listener_fd = -1;
eh->caps_str = nns_edge_strdup ("");
- eh->custom.dl_handle = NULL;
- eh->custom.instance = NULL;
- eh->custom.priv = NULL;
+ eh->custom_connection_h = NULL;
ret = nns_edge_metadata_create (&eh->metadata);
if (ret != NNS_EDGE_ERROR_NONE) {
eh = (nns_edge_handle_s *) (*edge_h);
eh->connect_type = NNS_EDGE_CONNECT_TYPE_CUSTOM;
- ret = nns_edge_custom_load (&eh->custom, lib_path);
+ ret = nns_edge_custom_load (lib_path, &eh->custom_connection_h);
if (ret != NNS_EDGE_ERROR_NONE)
nns_edge_release_handle (eh);
nns_edge_lock (eh);
if (NNS_EDGE_CONNECT_TYPE_CUSTOM == eh->connect_type) {
- ret = nns_edge_custom_start (&eh->custom);
+ ret = nns_edge_custom_start (eh->custom_connection_h);
if (NNS_EDGE_ERROR_NONE == ret)
ret = _nns_edge_create_send_thread (eh);
}
if (NNS_EDGE_CONNECT_TYPE_CUSTOM == eh->connect_type) {
- ret = nns_edge_custom_stop (&eh->custom);
+ ret = nns_edge_custom_stop (eh->custom_connection_h);
}
if (NNS_EDGE_ERROR_NONE == ret)
}
break;
case NNS_EDGE_CONNECT_TYPE_CUSTOM:
- if (nns_edge_custom_release (&eh->custom) !=
+ if (nns_edge_custom_release (eh->custom_connection_h) !=
NNS_EDGE_ERROR_NONE) {
nns_edge_logw ("Failed to close custom connection.");
}
eh->event_cb = NULL;
eh->user_data = NULL;
eh->broker_h = NULL;
+ eh->custom_connection_h = NULL;
nns_edge_queue_destroy (eh->send_queue);
eh->send_queue = NULL;
}
if (NNS_EDGE_CONNECT_TYPE_CUSTOM == eh->connect_type) {
- ret = nns_edge_custom_set_event_callback (&eh->custom, cb, user_data);
+ ret = nns_edge_custom_set_event_callback (eh->custom_connection_h,
+ cb, user_data);
if (NNS_EDGE_ERROR_NONE != ret) {
goto error;
}
}
}
} else if (NNS_EDGE_CONNECT_TYPE_CUSTOM == eh->connect_type) {
- ret = nns_edge_custom_connect (&eh->custom);
+ ret = nns_edge_custom_connect (eh->custom_connection_h);
if (ret != NNS_EDGE_ERROR_NONE) {
goto done;
}
return NNS_EDGE_ERROR_NONE;
if (NNS_EDGE_CONNECT_TYPE_CUSTOM == eh->connect_type) {
- return nns_edge_custom_is_connected (&eh->custom);
+ return nns_edge_custom_is_connected (eh->custom_connection_h);
}
conn_data = (nns_edge_conn_data_s *) eh->connections;
if (ret == NNS_EDGE_ERROR_NONE &&
NNS_EDGE_CONNECT_TYPE_CUSTOM == eh->connect_type) {
/* Pass value to custom library and ignore error. */
- if (nns_edge_custom_set_info (&eh->custom, key, value) !=
+ if (nns_edge_custom_set_info (eh->custom_connection_h, key, value) !=
NNS_EDGE_ERROR_NONE) {
nns_edge_logw ("Failed to set info '%s' in custom connection.", key);
}
NNS_EDGE_CONNECT_TYPE_CUSTOM == eh->connect_type) {
char *val = NULL;
- if (nns_edge_custom_get_info (&eh->custom, key, &val) ==
+ if (nns_edge_custom_get_info (eh->custom_connection_h, key, &val) ==
NNS_EDGE_ERROR_NONE) {
/* Replace value from custom library. */
SAFE_FREE (*value);
*/
#include <gtest/gtest.h>
+#include "nnstreamer-edge-custom-impl.h"
#include "nnstreamer-edge-custom.h"
#include "nnstreamer-edge-data.h"
#include "nnstreamer-edge-event.h"
EXPECT_EQ (NNS_EDGE_ERROR_NONE, ret);
}
+/**
+ * @brief Load edge custom - invalid param.
+ */
+TEST (edgeCustom, loadInvalidParam01_n)
+{
+ int ret;
+ nns_edge_custom_connection_h handle;
+
+ ret = nns_edge_custom_load (NULL, &handle);
+ EXPECT_NE (NNS_EDGE_ERROR_NONE, ret);
+}
+
+/**
+ * @brief Load edge custom - invalid param.
+ */
+TEST (edgeCustom, loadInvalidParam02_n)
+{
+ int ret;
+ nns_edge_custom_connection_h handle;
+
+ ret = nns_edge_custom_load ("", &handle);
+ EXPECT_NE (NNS_EDGE_ERROR_NONE, ret);
+}
+
+/**
+ * @brief Load edge custom - invalid param.
+ */
+TEST (edgeCustom, loadInvalidParam03_n)
+{
+ int ret;
+
+ ret = nns_edge_custom_load ("libnnstreamer-edge-custom-test.so", NULL);
+ EXPECT_NE (NNS_EDGE_ERROR_NONE, ret);
+}
+
+/**
+ * @brief Release edge custom - invalid param.
+ */
+TEST (edgeCustom, releaseInvalidParam01_n)
+{
+ int ret;
+
+ ret = nns_edge_custom_release (NULL);
+ EXPECT_NE (NNS_EDGE_ERROR_NONE, ret);
+}
+
+/**
+ * @brief Start edge custom - invalid param.
+ */
+TEST (edgeCustom, startInvalidParam01_n)
+{
+ int ret;
+
+ ret = nns_edge_custom_start (NULL);
+ EXPECT_NE (NNS_EDGE_ERROR_NONE, ret);
+}
+
+/**
+ * @brief Stop edge custom - invalid param.
+ */
+TEST (edgeCustom, stopInvalidParam01_n)
+{
+ int ret;
+
+ ret = nns_edge_custom_stop (NULL);
+ EXPECT_NE (NNS_EDGE_ERROR_NONE, ret);
+}
+
+/**
+ * @brief Set event callback of edge custom - invalid param.
+ */
+TEST (edgeCustom, setEventCbInvalidParam01_n)
+{
+ int ret;
+
+ ret = nns_edge_custom_set_event_callback (NULL, NULL, NULL);
+ EXPECT_NE (NNS_EDGE_ERROR_NONE, ret);
+}
+
+/**
+ * @brief Connect edge custom - invalid param.
+ */
+TEST (edgeCustom, connectInvalidParam01_n)
+{
+ int ret;
+
+ ret = nns_edge_custom_connect (NULL);
+ EXPECT_NE (NNS_EDGE_ERROR_NONE, ret);
+}
+
+/**
+ * @brief Check connection of edge custom - invalid param.
+ */
+TEST (edgeCustom, isConnectedInvalidParam01_n)
+{
+ int ret;
+
+ ret = nns_edge_custom_is_connected (NULL);
+ EXPECT_NE (NNS_EDGE_ERROR_NONE, ret);
+}
+
+/**
+ * @brief Send data using edge custom - invalid param.
+ */
+TEST (edgeCustom, sendDataInvalidParam01_n)
+{
+ int ret;
+ nns_edge_data_h data_h;
+
+ ret = nns_edge_data_create (&data_h);
+ EXPECT_EQ (NNS_EDGE_ERROR_NONE, ret);
+
+ ret = nns_edge_custom_send_data (NULL, data_h);
+ EXPECT_NE (NNS_EDGE_ERROR_NONE, ret);
+
+ ret = nns_edge_data_destroy (data_h);
+ EXPECT_EQ (NNS_EDGE_ERROR_NONE, ret);
+}
+
+/**
+ * @brief Send data using edge custom - invalid param.
+ */
+TEST (edgeCustom, sendDataInvalidParam02_n)
+{
+ int ret;
+ nns_edge_custom_connection_h handle;
+
+ ret = nns_edge_custom_load ("libnnstreamer-edge-custom-test.so", &handle);
+ EXPECT_EQ (NNS_EDGE_ERROR_NONE, ret);
+
+ ret = nns_edge_custom_send_data (handle, NULL);
+ EXPECT_NE (NNS_EDGE_ERROR_NONE, ret);
+
+ ret = nns_edge_custom_release (handle);
+ EXPECT_EQ (NNS_EDGE_ERROR_NONE, ret);
+}
+
+/**
+ * @brief Set info using edge custom - invalid param.
+ */
+TEST (edgeCustom, setInfoInvalidParam01_n)
+{
+ int ret;
+
+ ret = nns_edge_custom_set_info (NULL, "test-key", "test-value");
+ EXPECT_NE (NNS_EDGE_ERROR_NONE, ret);
+}
+
+/**
+ * @brief Set info using edge custom - invalid param.
+ */
+TEST (edgeCustom, setInfoInvalidParam02_n)
+{
+ int ret;
+ nns_edge_custom_connection_h handle;
+
+ ret = nns_edge_custom_load ("libnnstreamer-edge-custom-test.so", &handle);
+ EXPECT_EQ (NNS_EDGE_ERROR_NONE, ret);
+
+ ret = nns_edge_custom_set_info (handle, NULL, "test-value");
+ EXPECT_NE (NNS_EDGE_ERROR_NONE, ret);
+ ret = nns_edge_custom_set_info (handle, "", "test-value");
+ EXPECT_NE (NNS_EDGE_ERROR_NONE, ret);
+
+ ret = nns_edge_custom_release (handle);
+ EXPECT_EQ (NNS_EDGE_ERROR_NONE, ret);
+}
+
+/**
+ * @brief Set info using edge custom - invalid param.
+ */
+TEST (edgeCustom, setInfoInvalidParam03_n)
+{
+ int ret;
+ nns_edge_custom_connection_h handle;
+
+ ret = nns_edge_custom_load ("libnnstreamer-edge-custom-test.so", &handle);
+ EXPECT_EQ (NNS_EDGE_ERROR_NONE, ret);
+
+ ret = nns_edge_custom_set_info (handle, "test-key", NULL);
+ EXPECT_NE (NNS_EDGE_ERROR_NONE, ret);
+ ret = nns_edge_custom_set_info (handle, "test-key", "");
+ EXPECT_NE (NNS_EDGE_ERROR_NONE, ret);
+
+ ret = nns_edge_custom_release (handle);
+ EXPECT_EQ (NNS_EDGE_ERROR_NONE, ret);
+}
+
+/**
+ * @brief Get info using edge custom - invalid param.
+ */
+TEST (edgeCustom, getInfoInvalidParam01_n)
+{
+ int ret;
+ char *value;
+
+ ret = nns_edge_custom_get_info (NULL, "test-key", &value);
+ EXPECT_NE (NNS_EDGE_ERROR_NONE, ret);
+}
+
+/**
+ * @brief Get info using edge custom - invalid param.
+ */
+TEST (edgeCustom, getInfoInvalidParam02_n)
+{
+ int ret;
+ char *value;
+ nns_edge_custom_connection_h handle;
+
+ ret = nns_edge_custom_load ("libnnstreamer-edge-custom-test.so", &handle);
+ EXPECT_EQ (NNS_EDGE_ERROR_NONE, ret);
+
+ ret = nns_edge_custom_get_info (handle, NULL, &value);
+ EXPECT_NE (NNS_EDGE_ERROR_NONE, ret);
+ ret = nns_edge_custom_get_info (handle, "", &value);
+ EXPECT_NE (NNS_EDGE_ERROR_NONE, ret);
+
+ ret = nns_edge_custom_release (handle);
+ EXPECT_EQ (NNS_EDGE_ERROR_NONE, ret);
+}
+
+/**
+ * @brief Get info using edge custom - invalid param.
+ */
+TEST (edgeCustom, getInfoInvalidParam03_n)
+{
+ int ret;
+ nns_edge_custom_connection_h handle;
+
+ ret = nns_edge_custom_load ("libnnstreamer-edge-custom-test.so", &handle);
+ EXPECT_EQ (NNS_EDGE_ERROR_NONE, ret);
+
+ ret = nns_edge_custom_get_info (handle, "test-key", NULL);
+ EXPECT_NE (NNS_EDGE_ERROR_NONE, ret);
+
+ ret = nns_edge_custom_release (handle);
+ EXPECT_EQ (NNS_EDGE_ERROR_NONE, ret);
+}
+
/**
* @brief Main gtest
*/