Separate custom connection implementation and update callbacks.
Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
* The user should implement the functions and provide them using nns_edge_custom_get_instance().
* Refer to the example in nnstreamer-edge-custom-test.c for more details.
*/
-typedef struct _NnsEdgeCustomDef
+typedef struct
{
const char *(*nns_edge_custom_get_description) ();
int (*nns_edge_custom_create) (void **priv);
int (*nns_edge_custom_is_connected) (void *priv);
int (*nns_edge_custom_set_event_cb) (void *priv, nns_edge_event_cb cb, void *user_data);
int (*nns_edge_custom_send_data) (void *priv, nns_edge_data_h data_h);
- int (*nns_edge_custom_set_option) (void *priv, const char *key, const char *value);
- char *(*nns_edge_custom_get_option) (void *priv, const char *key);
+ int (*nns_edge_custom_set_info) (void *priv, const char *key, const char *value);
+ int (*nns_edge_custom_get_info) (void *priv, const char *key, char **value);
} nns_edge_custom_s;
/**
* @brief Get nns edge custom connection instance.
*/
-void* nns_edge_custom_get_instance ();
+const nns_edge_custom_s * nns_edge_custom_get_instance (void);
#ifdef __cplusplus
}
# nnstreamer-edge sources
NNSTREAMER_EDGE_SRCS := \
+ $(NNSTREAMER_EDGE_ROOT)/src/libnnstreamer-edge/nnstreamer-edge-custom-impl.c \
$(NNSTREAMER_EDGE_ROOT)/src/libnnstreamer-edge/nnstreamer-edge-data.c \
$(NNSTREAMER_EDGE_ROOT)/src/libnnstreamer-edge/nnstreamer-edge-event.c \
$(NNSTREAMER_EDGE_ROOT)/src/libnnstreamer-edge/nnstreamer-edge-internal.c \
# NNStreamer-Edge library
SET(NNS_EDGE_SRCS
+ ${NNS_EDGE_SRC_DIR}/nnstreamer-edge-custom-impl.c
${NNS_EDGE_SRC_DIR}/nnstreamer-edge-metadata.c
${NNS_EDGE_SRC_DIR}/nnstreamer-edge-data.c
${NNS_EDGE_SRC_DIR}/nnstreamer-edge-event.c
--- /dev/null
+/* SPDX-License-Identifier: Apache-2.0 */
+/**
+ * Copyright (C) 2024 Samsung Electronics Co., Ltd. All Rights Reserved.
+ *
+ * @file nnstreamer-edge-custom-impl.c
+ * @date 14 Aug 2024
+ * @brief Internal interface to support communication using custom library.
+ * @see https://github.com/nnstreamer/nnstreamer
+ * @author Gichan Jang <gichan2.jang@samsung.com>
+ * @bug No known bugs except for NYI items
+ */
+
+#include <dlfcn.h>
+
+#include "nnstreamer-edge-custom-impl.h"
+#include "nnstreamer-edge-log.h"
+
+typedef const nns_edge_custom_s *custom_get_instance (void);
+
+/**
+ * @brief Internal function to load custom library.
+ */
+static int
+_load_custom_library (custom_connection_s * custom, const char *lib_path)
+{
+ void *handle;
+ nns_edge_custom_s *custom_h;
+ int ret = NNS_EDGE_ERROR_UNKNOWN;
+
+ handle = dlopen (lib_path, RTLD_LAZY);
+ if (NULL == handle) {
+ nns_edge_loge ("Failed to open custom library: %s", dlerror ());
+ goto error;
+ }
+
+ custom_get_instance *get_instance =
+ (custom_get_instance *) dlsym (handle, "nns_edge_custom_get_instance");
+ if (!get_instance) {
+ nns_edge_loge ("Failed to find nns_edge_custom_get_instance: %s",
+ dlerror ());
+ goto error;
+ }
+
+ custom_h = (nns_edge_custom_s *) get_instance ();
+ if (!custom_h) {
+ nns_edge_loge ("Failed to get custom instance from library.");
+ goto error;
+ }
+
+ custom->dl_handle = handle;
+ custom->instance = custom_h;
+ ret = NNS_EDGE_ERROR_NONE;
+
+error:
+ if (NNS_EDGE_ERROR_NONE != ret) {
+ if (handle)
+ dlclose (handle);
+ }
+
+ return ret;
+}
+
+/**
+ * @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_s *custom_h;
+ int ret;
+
+ ret = _load_custom_library (custom, lib_path);
+ if (NNS_EDGE_ERROR_NONE != ret) {
+ nns_edge_loge
+ ("Failed to load custom library. Please check the library path or permission.");
+ goto error;
+ }
+
+ custom_h = custom->instance;
+
+ ret = custom_h->nns_edge_custom_create (&custom->priv);
+ if (NNS_EDGE_ERROR_NONE != ret) {
+ nns_edge_loge ("Failed to create custom connection handle.");
+ }
+
+error:
+ if (NNS_EDGE_ERROR_NONE != ret) {
+ nns_edge_custom_release (custom);
+ }
+
+ return ret;
+}
+
+/**
+ * @brief Internal function to release custom connection.
+ */
+int
+nns_edge_custom_release (custom_connection_s * custom)
+{
+ nns_edge_custom_s *custom_h;
+ int ret;
+
+ if (!custom || !custom->instance)
+ return NNS_EDGE_ERROR_INVALID_PARAMETER;
+
+ custom_h = custom->instance;
+
+ ret = custom_h->nns_edge_custom_close (custom->priv);
+ if (NNS_EDGE_ERROR_NONE != ret) {
+ nns_edge_loge ("Failed to stop custom connection.");
+ }
+
+ if (custom->dl_handle) {
+ dlclose (custom->dl_handle);
+ }
+
+ custom->dl_handle = NULL;
+ custom->instance = NULL;
+ custom->priv = NULL;
+
+ return ret;
+}
+
+/**
+ * @brief Internal function to start custom connection.
+ */
+int
+nns_edge_custom_start (custom_connection_s * custom)
+{
+ nns_edge_custom_s *custom_h;
+ int ret;
+
+ if (!custom || !custom->instance)
+ return NNS_EDGE_ERROR_INVALID_PARAMETER;
+
+ custom_h = custom->instance;
+
+ ret = custom_h->nns_edge_custom_start (custom->priv);
+ if (NNS_EDGE_ERROR_NONE != ret) {
+ nns_edge_loge ("Failed to start custom connection.");
+ }
+
+ return ret;
+}
+
+/**
+ * @brief Internal function to stop custom connection.
+ */
+int
+nns_edge_custom_stop (custom_connection_s * custom)
+{
+ nns_edge_custom_s *custom_h;
+ int ret;
+
+ if (!custom || !custom->instance)
+ return NNS_EDGE_ERROR_INVALID_PARAMETER;
+
+ custom_h = custom->instance;
+
+ ret = custom_h->nns_edge_custom_stop (custom->priv);
+ if (NNS_EDGE_ERROR_NONE != ret) {
+ nns_edge_loge ("Failed to stop custom connection.");
+ }
+
+ return 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_event_cb cb, void *user_data)
+{
+ nns_edge_custom_s *custom_h;
+ int ret;
+
+ if (!custom || !custom->instance)
+ return NNS_EDGE_ERROR_INVALID_PARAMETER;
+
+ custom_h = custom->instance;
+
+ ret = custom_h->nns_edge_custom_set_event_cb (custom->priv, cb, user_data);
+ if (NNS_EDGE_ERROR_NONE != ret) {
+ nns_edge_loge ("Failed to set event callback to custom connection.");
+ }
+
+ return ret;
+}
+
+/**
+ * @brief Internal function to connect custom connection.
+ */
+int
+nns_edge_custom_connect (custom_connection_s * custom)
+{
+ nns_edge_custom_s *custom_h;
+ int ret;
+
+ if (!custom || !custom->instance)
+ return NNS_EDGE_ERROR_INVALID_PARAMETER;
+
+ custom_h = custom->instance;
+
+ ret = custom_h->nns_edge_custom_connect (custom->priv);
+ if (NNS_EDGE_ERROR_NONE != ret) {
+ nns_edge_loge ("Failed to connect custom connection.");
+ }
+
+ return ret;
+}
+
+/**
+ * @brief Internal function to check custom connection.
+ */
+int
+nns_edge_custom_is_connected (custom_connection_s * custom)
+{
+ nns_edge_custom_s *custom_h;
+
+ if (!custom || !custom->instance)
+ return NNS_EDGE_ERROR_INVALID_PARAMETER;
+
+ custom_h = custom->instance;
+
+ return custom_h->nns_edge_custom_is_connected (custom->priv);
+}
+
+/**
+ * @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_s *custom_h;
+ int ret;
+
+ if (!custom || !custom->instance)
+ return NNS_EDGE_ERROR_INVALID_PARAMETER;
+
+ custom_h = custom->instance;
+
+ ret = custom_h->nns_edge_custom_send_data (custom->priv, data_h);
+ if (NNS_EDGE_ERROR_NONE != ret) {
+ nns_edge_loge ("Failed to send data to custom connection.");
+ }
+
+ return ret;
+}
+
+/**
+ * @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)
+{
+ nns_edge_custom_s *custom_h;
+ int ret = NNS_EDGE_ERROR_NOT_SUPPORTED;
+
+ if (!custom || !custom->instance)
+ return NNS_EDGE_ERROR_INVALID_PARAMETER;
+
+ custom_h = custom->instance;
+
+ if (custom_h->nns_edge_custom_set_info) {
+ ret = custom_h->nns_edge_custom_set_info (custom->priv, key, value);
+ if (NNS_EDGE_ERROR_NONE != ret) {
+ nns_edge_loge ("Failed to set information to custom connection.");
+ }
+ }
+
+ return ret;
+}
+
+/**
+ * @brief Internal function to get information from custom connection.
+ */
+int
+nns_edge_custom_get_info (custom_connection_s * custom, const char *key,
+ char **value)
+{
+ nns_edge_custom_s *custom_h;
+ int ret = NNS_EDGE_ERROR_NOT_SUPPORTED;
+
+ if (!custom || !custom->instance)
+ return NNS_EDGE_ERROR_INVALID_PARAMETER;
+
+ custom_h = custom->instance;
+
+ if (custom_h->nns_edge_custom_get_info) {
+ ret = custom_h->nns_edge_custom_get_info (custom->priv, key, value);
+ if (NNS_EDGE_ERROR_NONE != ret) {
+ nns_edge_loge ("Failed to get information from custom connection.");
+ }
+ }
+
+ return ret;
+}
--- /dev/null
+/* SPDX-License-Identifier: Apache-2.0 */
+/**
+ * Copyright (C) 2024 Samsung Electronics Co., Ltd. All Rights Reserved.
+ *
+ * @file nnstreamer-edge-custom-impl.h
+ * @date 21 Aug 2024
+ * @brief Internal interface to support communication using custom library.
+ * @see https://github.com/nnstreamer/nnstreamer
+ * @author Gichan Jang <gichan2.jang@samsung.com>
+ * @bug No known bugs except for NYI items
+ */
+
+#ifndef __NNSTREAMER_EDGE_CUSTOM_IMPL_H__
+#define __NNSTREAMER_EDGE_CUSTOM_IMPL_H__
+
+#include "nnstreamer-edge-custom.h"
+
+#ifdef __cplusplus
+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;
+
+/**
+ * @brief Internal function to load custom connection from library.
+ */
+int nns_edge_custom_load (custom_connection_s *custom, const char *lib_path);
+
+/**
+ * @brief Internal function to release custom connection.
+ */
+int nns_edge_custom_release (custom_connection_s *custom);
+
+/**
+ * @brief Internal function to start custom connection.
+ */
+int nns_edge_custom_start (custom_connection_s *custom);
+
+/**
+ * @brief Internal function to stop custom connection.
+ */
+int nns_edge_custom_stop (custom_connection_s *custom);
+
+/**
+ * @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);
+
+/**
+ * @brief Internal function to connect custom connection.
+ */
+int nns_edge_custom_connect (custom_connection_s *custom);
+
+/**
+ * @brief Internal function to check custom connection.
+ */
+int nns_edge_custom_is_connected (custom_connection_s *custom);
+
+/**
+ * @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);
+
+/**
+ * @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);
+
+/**
+ * @brief Internal function to get information from custom connection.
+ */
+int nns_edge_custom_get_info (custom_connection_s *custom, const char *key, char **value);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __NNSTREAMER_EDGE_CUSTOM_IMPL_H__ */
#include "nnstreamer-edge-queue.h"
#include "nnstreamer-edge-aitt.h"
#include "nnstreamer-edge-mqtt.h"
-#include "nnstreamer-edge-custom.h"
+#include "nnstreamer-edge-custom-impl.h"
#ifndef MSG_NOSIGNAL
#define MSG_NOSIGNAL 0
*/
#define N_BACKLOG 10
-/**
- * @brief Data structure for edge custom connection.
- */
-typedef struct
-{
- void *dl_handle;
- void *instance;
- void *priv;
-} custom_connection_s;
-
/**
* @brief Data structure for edge handle.
*/
nns_edge_loge ("Failed to send data via MQTT connection.");
break;
case NNS_EDGE_CONNECT_TYPE_CUSTOM:
- {
- nns_edge_custom_s *custom_h = (nns_edge_custom_s *) eh->custom.instance;
-
- if (custom_h) {
- ret = custom_h->nns_edge_custom_send_data (eh->custom.priv, data_h);
- if (NNS_EDGE_ERROR_NONE != ret)
- nns_edge_loge ("Failed to send data via custom connection.");
- }
+ ret = nns_edge_custom_send_data (&eh->custom, data_h);
+ if (NNS_EDGE_ERROR_NONE != ret)
+ nns_edge_loge ("Failed to send data via custom connection.");
break;
- }
default:
break;
}
return ret;
}
-/**
- * @brief Load custom lib and get edge custom instance.
- */
-static int
-_nns_edge_load_custom_library (nns_edge_handle_s * eh, const char *lib_path)
-{
- void *handle;
- nns_edge_custom_s *custom_h;
-
- handle = dlopen (lib_path, RTLD_LAZY);
- if (NULL == handle) {
- nns_edge_loge ("Failed to open custom lib: %s", dlerror ());
- return NNS_EDGE_ERROR_UNKNOWN;
- }
-
- void *(*custom_get_instance) () =
- (void *(*)()) dlsym (handle, "nns_edge_custom_get_instance");
- if (!custom_get_instance) {
- nns_edge_loge ("Failed to find nns_edge_custom_get_instance: %s",
- dlerror ());
- dlclose (handle);
- return NNS_EDGE_ERROR_UNKNOWN;
- }
-
- custom_h = (nns_edge_custom_s *) custom_get_instance ();
- if (!custom_h) {
- nns_edge_loge ("Failed to get custom instance from library.");
- dlclose (handle);
- return NNS_EDGE_ERROR_UNKNOWN;
- }
-
- eh->custom.dl_handle = handle;
- eh->custom.instance = custom_h;
-
- return NNS_EDGE_ERROR_NONE;
-}
-
/**
* @brief Create edge custom handle.
*/
{
int ret = NNS_EDGE_ERROR_NONE;
nns_edge_handle_s *eh;
- nns_edge_custom_s *custom_h;
if (node_type < 0 || node_type >= NNS_EDGE_NODE_TYPE_UNKNOWN) {
nns_edge_loge ("Invalid param, set exact node type.");
eh = (nns_edge_handle_s *) (*edge_h);
eh->connect_type = NNS_EDGE_CONNECT_TYPE_CUSTOM;
- ret = _nns_edge_load_custom_library (eh, lib_path);
- if (NNS_EDGE_ERROR_NONE != ret) {
- nns_edge_loge
- ("Failed to load custom lib. Please check the custom lib path or permission.");
- goto error;
- }
-
- custom_h = (nns_edge_custom_s *) eh->custom.instance;
- ret = custom_h->nns_edge_custom_create (&eh->custom.priv);
- if (NNS_EDGE_ERROR_NONE != ret) {
- nns_edge_loge ("Failed to create custom connection handle.");
- }
-
-error:
+ ret = nns_edge_custom_load (&eh->custom, lib_path);
if (ret != NNS_EDGE_ERROR_NONE)
nns_edge_release_handle (eh);
nns_edge_loge ("Failed to create edge handle.");
return ret;
}
- eh = (nns_edge_handle_s *) * edge_h;
+ eh = (nns_edge_handle_s *) (*edge_h);
eh->connect_type = connect_type;
if (NNS_EDGE_CONNECT_TYPE_AITT == connect_type) {
return ret;
}
-/**
- * @brief Start the nnstreamer edge custom.
- */
-static int
-_nns_edge_custom_start (nns_edge_handle_s * eh)
-{
- int ret = NNS_EDGE_ERROR_INVALID_PARAMETER;
- nns_edge_custom_s *custom_h = (nns_edge_custom_s *) eh->custom.instance;
-
- if (custom_h)
- ret = custom_h->nns_edge_custom_start (eh->custom.priv);
-
- if (NNS_EDGE_ERROR_NONE != ret) {
- nns_edge_loge ("Failed to start edge custom connection.");
- return ret;
- }
-
- ret = custom_h->nns_edge_custom_set_event_cb (eh->custom.priv, eh->event_cb,
- eh->user_data);
- if (NNS_EDGE_ERROR_NONE != ret) {
- nns_edge_loge ("Failed to set event callback to custom connection.");
- return ret;
- }
-
- ret = _nns_edge_create_send_thread (eh);
-
- return ret;
-}
-
/**
* @brief Start the nnstreamer edge.
*/
nns_edge_lock (eh);
if (NNS_EDGE_CONNECT_TYPE_CUSTOM == eh->connect_type) {
- ret = _nns_edge_custom_start (edge_h);
- if (NNS_EDGE_ERROR_NONE != ret) {
- nns_edge_loge ("Failed to start edge custom connection");
- }
+ ret = nns_edge_custom_start (&eh->custom);
+ if (NNS_EDGE_ERROR_NONE == ret)
+ ret = _nns_edge_create_send_thread (eh);
+
+ if (NNS_EDGE_ERROR_NONE != ret)
+ nns_edge_loge ("Failed to start edge custom connection.");
goto done;
}
return ret;
}
-/**
- * @brief Stop the nnstreamer edge custom connection.
- */
-static int
-_nns_edge_custom_stop (nns_edge_handle_s * eh)
-{
- int ret = NNS_EDGE_ERROR_INVALID_PARAMETER;
- nns_edge_custom_s *custom_h = (nns_edge_custom_s *) eh->custom.instance;
-
- if (custom_h)
- ret = custom_h->nns_edge_custom_stop (eh->custom.priv);
-
- if (NNS_EDGE_ERROR_NONE != ret) {
- nns_edge_loge ("Failed to stop nns edge custom connection.");
- }
-
- return ret;
-}
-
/**
* @brief Stop the nnstreamer edge.
*/
}
if (NNS_EDGE_CONNECT_TYPE_CUSTOM == eh->connect_type) {
- ret = _nns_edge_custom_stop (eh);
+ ret = nns_edge_custom_stop (&eh->custom);
}
- eh->is_started = FALSE;
+ if (NNS_EDGE_ERROR_NONE == ret)
+ eh->is_started = FALSE;
done:
nns_edge_unlock (eh);
return ret;
}
-static void
-_nns_edge_custom_release (nns_edge_handle_s * eh)
-{
- int ret = NNS_EDGE_ERROR_INVALID_PARAMETER;
- nns_edge_custom_s *custom_h = (nns_edge_custom_s *) eh->custom.instance;
-
- if (custom_h)
- ret = custom_h->nns_edge_custom_close (eh->custom.priv);
-
- if (NNS_EDGE_ERROR_NONE != ret) {
- nns_edge_loge ("Failed to stop nns edge custom connection.");
- }
-
- if (eh->custom.dl_handle)
- dlclose (eh->custom.dl_handle);
-
- eh->custom.dl_handle = NULL;
- eh->custom.instance = NULL;
- eh->custom.priv = NULL;
-}
-
/**
* @brief Release the given handle.
*/
}
break;
case NNS_EDGE_CONNECT_TYPE_CUSTOM:
- _nns_edge_custom_release (eh);
+ nns_edge_custom_release (&eh->custom);
break;
default:
break;
NNS_EDGE_EVENT_CALLBACK_RELEASED, NULL, 0, NULL);
if (ret != NNS_EDGE_ERROR_NONE) {
nns_edge_loge ("Failed to set new event callback.");
- nns_edge_unlock (eh);
- return ret;
+ goto error;
+ }
+
+ if (NNS_EDGE_CONNECT_TYPE_CUSTOM == eh->connect_type) {
+ ret = nns_edge_custom_set_event_callback (&eh->custom, cb, user_data);
+ if (NNS_EDGE_ERROR_NONE != ret) {
+ goto error;
+ }
}
eh->event_cb = cb;
eh->user_data = user_data;
+error:
nns_edge_unlock (eh);
- return NNS_EDGE_ERROR_NONE;
+ return ret;
}
/**
goto done;
}
} else if (NNS_EDGE_CONNECT_TYPE_CUSTOM == eh->connect_type) {
- nns_edge_custom_s *custom_h = (nns_edge_custom_s *) eh->custom.instance;
-
- if (custom_h)
- ret = custom_h->nns_edge_custom_connect (eh->custom.priv);
- else
- ret = NNS_EDGE_ERROR_INVALID_PARAMETER;
-
+ ret = nns_edge_custom_connect (&eh->custom);
if (ret != NNS_EDGE_ERROR_NONE) {
- nns_edge_loge ("Failed to connect to custom connection.");
goto done;
}
} else {
return NNS_EDGE_ERROR_NONE;
if (NNS_EDGE_CONNECT_TYPE_CUSTOM == eh->connect_type) {
- nns_edge_custom_s *custom_h = (nns_edge_custom_s *) eh->custom.instance;
-
- if (custom_h)
- return custom_h->nns_edge_custom_is_connected (eh->custom.priv);
- else
- return NNS_EDGE_ERROR_CONNECTION_FAILURE;
+ return nns_edge_custom_is_connected (&eh->custom);
}
conn_data = (nns_edge_conn_data_s *) eh->connections;
if (ret == NNS_EDGE_ERROR_NONE &&
NNS_EDGE_CONNECT_TYPE_CUSTOM == eh->connect_type) {
- nns_edge_custom_s *custom_h = (nns_edge_custom_s *) eh->custom.instance;
-
- if (!custom_h) {
- ret = NNS_EDGE_ERROR_UNKNOWN;
- } else if (custom_h->nns_edge_custom_set_option) {
- ret = custom_h->nns_edge_custom_set_option (eh->custom.priv, key, value);
- }
+ /* Pass value to custom library and ignore error. */
+ nns_edge_custom_set_info (&eh->custom, key, value);
}
nns_edge_unlock (eh);
if (ret == NNS_EDGE_ERROR_NONE &&
NNS_EDGE_CONNECT_TYPE_CUSTOM == eh->connect_type) {
- nns_edge_custom_s *custom_h = (nns_edge_custom_s *) eh->custom.instance;
+ char *val = NULL;
- if (!custom_h) {
- ret = NNS_EDGE_ERROR_UNKNOWN;
- } else if (custom_h->nns_edge_custom_get_option) {
- /* Release old value, then get from custom library. */
+ if (nns_edge_custom_get_info (&eh->custom, key, &val) ==
+ NNS_EDGE_ERROR_NONE) {
+ /* Replace value from custom library. */
SAFE_FREE (*value);
- *value = custom_h->nns_edge_custom_get_option (eh->custom.priv, key);
+ *value = val;
}
}
nns_edge_custom_close (void *priv)
{
if (!priv) {
- nns_edge_loge ("Invalid param, priv should not be null.");
+ nns_edge_loge ("Invalid param, handle should not be null.");
return NNS_EDGE_ERROR_INVALID_PARAMETER;
}
nns_edge_custom_test_s *custom_h = (nns_edge_custom_test_s *) priv;
nns_edge_custom_start (void *priv)
{
if (!priv) {
- nns_edge_loge ("Invalid param, priv should not be null.");
+ nns_edge_loge ("Invalid param, handle should not be null.");
return NNS_EDGE_ERROR_INVALID_PARAMETER;
}
nns_edge_custom_test_s *custom_h = (nns_edge_custom_test_s *) priv;
nns_edge_custom_stop (void *priv)
{
if (!priv) {
- nns_edge_loge ("Invalid param, priv should not be null.");
+ nns_edge_loge ("Invalid param, handle should not be null.");
return NNS_EDGE_ERROR_INVALID_PARAMETER;
}
nns_edge_custom_test_s *custom_h = (nns_edge_custom_test_s *) priv;
nns_edge_custom_connect (void *priv)
{
if (!priv) {
- nns_edge_loge ("Invalid param, priv is NULL");
+ nns_edge_loge ("Invalid param, handle should not be null.");
return NNS_EDGE_ERROR_INVALID_PARAMETER;
}
nns_edge_custom_test_s *custom_h = (nns_edge_custom_test_s *) priv;
static int
nns_edge_custom_set_event_cb (void *priv, nns_edge_event_cb cb, void *user_data)
{
- if (!priv || !cb) {
- nns_edge_loge ("Invalid param, cb(%p)", cb);
+ if (!priv) {
+ nns_edge_loge ("Invalid param, handle should not be null.");
return NNS_EDGE_ERROR_INVALID_PARAMETER;
}
nns_edge_custom_send_data (void *priv, nns_edge_data_h data_h)
{
if (!priv || !data_h) {
- nns_edge_loge ("Invalid param, data_h(%p)", data_h);
+ nns_edge_loge ("Invalid param, handle or data should not be null.");
return NNS_EDGE_ERROR_INVALID_PARAMETER;
}
}
static int
-nns_edge_custom_set_option (void *priv, const char *key, const char *value)
+nns_edge_custom_set_info (void *priv, const char *key, const char *value)
{
if (!priv || !key || !value) {
- nns_edge_loge ("Invalid param, key(%s), value(%s)", key, value);
+ nns_edge_loge ("Invalid param, handle, key or value should not be null.");
return NNS_EDGE_ERROR_INVALID_PARAMETER;
}
nns_edge_custom_test_s *custom_h = (nns_edge_custom_test_s *) priv;
if (strcasecmp (key, "PEER_ADDRESS") == 0) {
SAFE_FREE (custom_h->peer_address);
custom_h->peer_address = nns_edge_strdup (value);
- } else {
- nns_edge_loge ("key(%s) does not supported.", key);
- return NNS_EDGE_ERROR_INVALID_PARAMETER;
+ return NNS_EDGE_ERROR_NONE;
}
- return NNS_EDGE_ERROR_NONE;
+ nns_edge_loge ("The key '%s' is not supported.", key);
+ return NNS_EDGE_ERROR_INVALID_PARAMETER;
}
-static char *
-nns_edge_custom_get_option (void *priv, const char *key)
+static int
+nns_edge_custom_get_info (void *priv, const char *key, char **value)
{
- if (!priv || !key) {
- nns_edge_loge ("Invalid param, key(%s)", key);
- return NULL;
+ if (!priv || !key || !value) {
+ nns_edge_loge ("Invalid param, handle, key or value should not be null.");
+ return NNS_EDGE_ERROR_INVALID_PARAMETER;
}
nns_edge_custom_test_s *custom_h = (nns_edge_custom_test_s *) priv;
- if (strcasecmp (key, "PEER_ADDRESS") == 0)
- return nns_edge_strdup (custom_h->peer_address);
- return NULL;
+ if (strcasecmp (key, "PEER_ADDRESS") == 0) {
+ *value = nns_edge_strdup (custom_h->peer_address);
+ return NNS_EDGE_ERROR_NONE;
+ }
+
+ nns_edge_loge ("The key '%s' is not supported.", key);
+ return NNS_EDGE_ERROR_INVALID_PARAMETER;
}
nns_edge_custom_s edge_custom_h = {
.nns_edge_custom_is_connected = nns_edge_custom_is_connected,
.nns_edge_custom_set_event_cb = nns_edge_custom_set_event_cb,
.nns_edge_custom_send_data = nns_edge_custom_send_data,
- .nns_edge_custom_set_option = nns_edge_custom_set_option,
- .nns_edge_custom_get_option = nns_edge_custom_get_option
+ .nns_edge_custom_set_info = nns_edge_custom_set_info,
+ .nns_edge_custom_get_info = nns_edge_custom_get_info
};
-void *
+const nns_edge_custom_s *
nns_edge_custom_get_instance ()
{
return &edge_custom_h;