[Edge] Replace caps info
authorgichan <gichan2.jang@samsung.com>
Wed, 20 Jul 2022 05:48:10 +0000 (14:48 +0900)
committerjaeyun-jung <39614140+jaeyun-jung@users.noreply.github.com>
Wed, 20 Jul 2022 06:36:40 +0000 (15:36 +0900)
Replace caps info instead of appedning the string.

Signed-off-by: gichan <gichan2.jang@samsung.com>
include/nnstreamer-edge.h
src/libnnstreamer-edge/nnstreamer-edge-internal.c

index 7b69a614791b9965fe35a0f0169faeb1c3aa53fe..1aa9987590a3466dc5df46ac164b1906f5f3fe7b 100644 (file)
@@ -149,6 +149,11 @@ int nns_edge_get_topic (nns_edge_h edge_h, char **topic);
  */
 int nns_edge_set_info (nns_edge_h edge_h, const char *key, const char *value);
 
+/**
+ * @brief Get nnstreamer edge info.
+ */
+int nns_edge_get_info (nns_edge_h edge_h, const char *key, char **value);
+
 /**
  * @brief Get the nnstreamer edge event type.
  */
index 23c146e7658e18280ea619d4a9fc12dc588b037d..82bccbbe14c59fab98935a79d89ef74376eee2cc 100644 (file)
@@ -1372,7 +1372,6 @@ int
 nns_edge_set_info (nns_edge_h edge_h, const char *key, const char *value)
 {
   nns_edge_handle_s *eh;
-  char *ret_str = NULL;
 
   eh = (nns_edge_handle_s *) edge_h;
   if (!eh) {
@@ -1403,9 +1402,8 @@ nns_edge_set_info (nns_edge_h edge_h, const char *key, const char *value)
    * @todo Change key-value set as json or hash table.
    */
   if (0 == g_ascii_strcasecmp (key, "CAPS")) {
-    ret_str = nns_edge_strdup_printf ("%s%s", _STR_NULL (eh->caps_str), value);
     SAFE_FREE (eh->caps_str);
-    eh->caps_str = ret_str;
+    eh->caps_str = nns_edge_strdup (value);
   } else if (0 == g_ascii_strcasecmp (key, "IP")) {
     SAFE_FREE (eh->recv_ip);
     eh->recv_ip = nns_edge_strdup (value);
@@ -1422,6 +1420,59 @@ nns_edge_set_info (nns_edge_h edge_h, const char *key, const char *value)
   return NNS_EDGE_ERROR_NONE;
 }
 
+
+/**
+ * @brief Get nnstreamer edge info.
+ */
+int
+nns_edge_get_info (nns_edge_h edge_h, const char *key, char **value)
+{
+  nns_edge_handle_s *eh;
+
+  eh = (nns_edge_handle_s *) edge_h;
+  if (!eh) {
+    nns_edge_loge ("Invalid param, given edge handle is null.");
+    return NNS_EDGE_ERROR_INVALID_PARAMETER;
+  }
+
+  if (!STR_IS_VALID (key)) {
+    nns_edge_loge ("Invalid param, given key is invalid.");
+    return NNS_EDGE_ERROR_INVALID_PARAMETER;
+  }
+
+  if (!value) {
+    nns_edge_loge ("Invalid param, given value is invalid.");
+    return NNS_EDGE_ERROR_INVALID_PARAMETER;
+  }
+
+  nns_edge_lock (eh);
+
+  if (!NNS_EDGE_MAGIC_IS_VALID (eh)) {
+    nns_edge_loge ("Invalid param, given edge handle is invalid.");
+    nns_edge_unlock (eh);
+    return NNS_EDGE_ERROR_INVALID_PARAMETER;
+  }
+
+  /**
+   * @todo User handles (replace or append) the capability of edge handle.
+   * @todo Change key-value set as json or hash table.
+   */
+  if (0 == g_ascii_strcasecmp (key, "CAPS")) {
+    *value = nns_edge_strdup (eh->caps_str);
+  } else if (0 == g_ascii_strcasecmp (key, "IP")) {
+    *value = nns_edge_strdup (eh->recv_ip);
+  } else if (0 == g_ascii_strcasecmp (key, "PORT")) {
+    *value = nns_edge_strdup_printf ("%d", eh->recv_port);
+  } else if (0 == g_ascii_strcasecmp (key, "TOPIC")) {
+    *value = nns_edge_strdup (eh->topic);
+  } else {
+    nns_edge_logw ("Failed to get edge info. Unknown key: %s", key);
+  }
+
+  nns_edge_unlock (eh);
+  return NNS_EDGE_ERROR_NONE;
+}
+
 /**
  * @brief Respond to a request.
  */