From: Jaeyun Date: Wed, 24 Aug 2022 09:39:56 +0000 (+0900) Subject: [CodeClean] separate util functions X-Git-Tag: accepted/tizen/unified/20220908.124834~19 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fe73df6050f83c2642a7961d84b29e8137b1a780;p=platform%2Fupstream%2Fnnstreamer-edge.git [CodeClean] separate util functions Separate utility functions - header for log and utility. Signed-off-by: Jaeyun --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4f42aa5..4626f2d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,6 +3,7 @@ SET(NNS_EDGE_LIB_NAME nnstreamer-edge) SET(NNS_EDGE_SRCS ${NNS_EDGE_SRC_DIR}/nnstreamer-edge-common.c ${NNS_EDGE_SRC_DIR}/nnstreamer-edge-internal.c + ${NNS_EDGE_SRC_DIR}/nnstreamer-edge-util.c ) IF(ENABLE_PAHO_MQTT) diff --git a/src/libnnstreamer-edge/nnstreamer-edge-common.c b/src/libnnstreamer-edge/nnstreamer-edge-common.c index 227ecc9..4bce06d 100644 --- a/src/libnnstreamer-edge/nnstreamer-edge-common.c +++ b/src/libnnstreamer-edge/nnstreamer-edge-common.c @@ -10,177 +10,9 @@ * @bug No known bugs except for NYI items */ -#define _GNU_SOURCE -#include - #include "nnstreamer-edge-common.h" - -/** - * @brief Internal util function to get available port number. - */ -int -nns_edge_get_available_port (void) -{ - struct sockaddr_in sin; - int port = 0, sock; - socklen_t len = sizeof (struct sockaddr); - - sin.sin_family = AF_INET; - sin.sin_addr.s_addr = INADDR_ANY; - sin.sin_port = 0; - - sock = socket (AF_INET, SOCK_STREAM, 0); - if (sock < 0) { - nns_edge_loge ("Failed to get available port, socket creation failure."); - return 0; - } - - if (bind (sock, (struct sockaddr *) &sin, sizeof (struct sockaddr)) == 0) { - if (getsockname (sock, (struct sockaddr *) &sin, &len) == 0) { - port = ntohs (sin.sin_port); - nns_edge_logi ("Available port number: %d", port); - } else { - nns_edge_logw ("Failed to read local socket info."); - } - } - close (sock); - - return port; -} - -/** - * @brief Get host string (host:port). Caller should release returned string using nns_edge_free(). - */ -char * -nns_edge_get_host_string (const char *host, const int port) -{ - return nns_edge_strdup_printf ("%s:%d", host, port); -} - -/** - * @brief Parse string and get host string (host:port). - */ -void -nns_edge_parse_host_string (const char *host_str, char **host, int *port) -{ - char *p = strchr (host_str, ':'); - - if (p) { - *host = nns_edge_strndup (host_str, (p - host_str)); - *port = (int) strtoll (p + 1, NULL, 10); - } -} - -/** - * @brief Parse string and get port number. Return negative value when failed to get port number. - */ -int -nns_edge_parse_port_number (const char *port_str) -{ - int port; - - if (!port_str) - return -1; - - port = (int) strtoll (port_str, NULL, 10); - - if (port <= 0 || port > 65535) { - nns_edge_loge ("Invalid port number %d.", port); - port = -1; - } - - return port; -} - -/** - * @brief Free allocated memory. - */ -void -nns_edge_free (void *data) -{ - if (data) - free (data); -} - -/** - * @brief Allocate new memory and copy bytes. - * @note Caller should release newly allocated memory using nns_edge_free(). - */ -void * -nns_edge_memdup (const void *data, size_t size) -{ - void *mem = NULL; - - if (data && size > 0) { - mem = malloc (size); - - if (mem) { - memcpy (mem, data, size); - } else { - nns_edge_loge ("Failed to allocate memory (%zd).", size); - } - } - - return mem; -} - -/** - * @brief Allocate new memory and copy string. - * @note Caller should release newly allocated string using nns_edge_free(). - */ -char * -nns_edge_strdup (const char *str) -{ - char *new_str = NULL; - - if (str) - new_str = nns_edge_strndup (str, strlen (str)); - - return new_str; -} - -/** - * @brief Allocate new memory and copy bytes of string. - * @note Caller should release newly allocated string using nns_edge_free(). - */ -char * -nns_edge_strndup (const char *str, size_t len) -{ - char *new_str = NULL; - - if (str) { - new_str = (char *) malloc (len + 1); - - if (new_str) { - strncpy (new_str, str, len); - new_str[len] = '\0'; - } else { - nns_edge_loge ("Failed to allocate memory (%zd).", len + 1); - } - } - - return new_str; -} - -/** - * @brief Allocate new memory and print formatted string. - * @note Caller should release newly allocated string using nns_edge_free(). - */ -char * -nns_edge_strdup_printf (const char *format, ...) -{ - char *new_str = NULL; - va_list args; - int len; - - va_start (args, format); - len = vasprintf (&new_str, format, args); - if (len < 0) - new_str = NULL; - va_end (args); - - return new_str; -} +#include "nnstreamer-edge-log.h" +#include "nnstreamer-edge-util.h" /** * @brief Internal function to find node in the list. diff --git a/src/libnnstreamer-edge/nnstreamer-edge-common.h b/src/libnnstreamer-edge/nnstreamer-edge-common.h index 32c1c70..37b37ea 100644 --- a/src/libnnstreamer-edge/nnstreamer-edge-common.h +++ b/src/libnnstreamer-edge/nnstreamer-edge-common.h @@ -9,42 +9,19 @@ * @author Gichan Jang * @bug No known bugs except for NYI items * @note This file is internal header for nnstreamer edge utils. DO NOT export this file. + * @todo Rename this to nnstreamer-edge-meta after separating util functions. */ #ifndef __NNSTREAMER_EDGE_COMMON_H__ #define __NNSTREAMER_EDGE_COMMON_H__ #include /** @todo remove glib */ -#include -#include -#include -#include -#include #include "nnstreamer-edge.h" #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ -/** - * @brief Utility to silence unused parameter warning for intentionally unused parameters (e.g., callback functions of a framework) - */ -#ifndef UNUSED -#define UNUSED(expr) do { (void)(expr); } while (0) -#endif - -#define STR_IS_VALID(s) ((s) && (s)[0] != '\0') -#define SAFE_FREE(p) do { if (p) { free (p); (p) = NULL; } } while (0) - -#define NNS_EDGE_MAGIC 0xfeedfeed -#define NNS_EDGE_MAGIC_DEAD 0xdeaddead -#define NNS_EDGE_MAGIC_IS_VALID(h) ((h) && (h)->magic == NNS_EDGE_MAGIC) - -#define nns_edge_lock_init(h) do { pthread_mutex_init (&(h)->lock, NULL); } while (0) -#define nns_edge_lock_destroy(h) do { pthread_mutex_destroy (&(h)->lock); } while (0) -#define nns_edge_lock(h) do { pthread_mutex_lock (&(h)->lock); } while (0) -#define nns_edge_unlock(h) do { pthread_mutex_unlock (&(h)->lock); } while (0) - typedef void *nns_edge_broker_h; /** @@ -98,120 +75,6 @@ typedef struct { nns_edge_raw_data_s data; } nns_edge_event_s; -#define TAG_NAME "nnstreamer-edge" - -#if defined(__TIZEN__) -#include - -#define nns_edge_logd(...) dlog_print (DLOG_DEBUG, TAG_NAME, __VA_ARGS__) -#define nns_edge_logi(...) dlog_print (DLOG_INFO, TAG_NAME, __VA_ARGS__) -#define nns_edge_logw(...) dlog_print (DLOG_WARN, TAG_NAME, __VA_ARGS__) -#define nns_edge_loge(...) dlog_print (DLOG_ERROR, TAG_NAME, __VA_ARGS__) -#define nns_edge_logf(...) dlog_print (DLOG_FATAL, TAG_NAME, __VA_ARGS__) -#elif defined(__ANDROID__) -#include - -#define nns_edge_logd(...) __android_log_print (ANDROID_LOG_DEBUG, TAG_NAME, __VA_ARGS__) -#define nns_edge_logi(...) __android_log_print (ANDROID_LOG_INFO, TAG_NAME, __VA_ARGS__) -#define nns_edge_logw(...) __android_log_print (ANDROID_LOG_WARN, TAG_NAME, __VA_ARGS__) -#define nns_edge_loge(...) __android_log_print (ANDROID_LOG_ERROR, TAG_NAME, __VA_ARGS__) -#define nns_edge_logf(...) __android_log_print (ANDROID_LOG_FATAL, TAG_NAME, __VA_ARGS__) -#else -/** - * @brief Internal enumeration for log message. - */ -typedef enum { - NE_LOG_DEBUG = 0, - NE_LOG_INFO, - NE_LOG_WARNING, - NE_LOG_ERROR, - NE_LOG_FATAL, - NE_LOG_NONE -} nns_edge_log_level_e; - -/** - * @brief Internal util function to print log message. - */ -static inline void -nns_edge_print_log (nns_edge_log_level_e level, const char *fmt, ...) -{ - const char *level_str[] = { - [NE_LOG_DEBUG] = "DEBUG", - [NE_LOG_INFO] = "INFO", - [NE_LOG_WARNING] = "WARNING", - [NE_LOG_ERROR] = "ERROR", - [NE_LOG_FATAL] = "FATAL", - [NE_LOG_NONE] = "DEBUG", - }; - - va_list args; - - /** @todo expand log util and handle log level (debug, release) */ - va_start (args, fmt); - - printf ("[%s][%s] ", level_str[level], TAG_NAME); - vprintf (fmt, args); - printf ("\n"); - - va_end (args); -} - -#define nns_edge_logi(...) nns_edge_print_log (NE_LOG_INFO, __VA_ARGS__) -#define nns_edge_logw(...) nns_edge_print_log (NE_LOG_WARNING, __VA_ARGS__) -#define nns_edge_loge(...) nns_edge_print_log (NE_LOG_ERROR, __VA_ARGS__) -#define nns_edge_logd(...) nns_edge_print_log (NE_LOG_DEBUG, __VA_ARGS__) -#define nns_edge_logf(...) nns_edge_print_log (NE_LOG_FATAL, __VA_ARGS__) -#endif - -/** - * @brief Internal util function to get available port number. - */ -int nns_edge_get_available_port (void); - -/** - * @brief Get host string (host:port). Caller should release returned string using nns_edge_free(). - */ -char *nns_edge_get_host_string (const char *host, const int port); - -/** - * @brief Parse string and get host string (host:port). - */ -void nns_edge_parse_host_string (const char *host_str, char **host, int *port); - -/** - * @brief Parse string and get port number. Return negative value when failed to get port number. - */ -int nns_edge_parse_port_number (const char *port_str); - -/** - * @brief Free allocated memory. - */ -void nns_edge_free (void *data); - -/** - * @brief Allocate new memory and copy bytes. - * @note Caller should release newly allocated memory using nns_edge_free(). - */ -void *nns_edge_memdup (const void *data, size_t size); - -/** - * @brief Allocate new memory and copy string. - * @note Caller should release newly allocated string using nns_edge_free(). - */ -char *nns_edge_strdup (const char *str); - -/** - * @brief Allocate new memory and copy bytes of string. - * @note Caller should release newly allocated string using nns_edge_free(). - */ -char *nns_edge_strndup (const char *str, size_t len); - -/** - * @brief Allocate new memory and print formatted string. - * @note Caller should release newly allocated string using nns_edge_free(). - */ -char *nns_edge_strdup_printf (const char *format, ...); - /** * @brief Internal function to initialize metadata structure. */ diff --git a/src/libnnstreamer-edge/nnstreamer-edge-internal.c b/src/libnnstreamer-edge/nnstreamer-edge-internal.c index 6fb4775..e5d05a6 100644 --- a/src/libnnstreamer-edge/nnstreamer-edge-internal.c +++ b/src/libnnstreamer-edge/nnstreamer-edge-internal.c @@ -14,7 +14,8 @@ #include #include -#include "nnstreamer-edge-common.h" +#include "nnstreamer-edge-log.h" +#include "nnstreamer-edge-util.h" #include "nnstreamer-edge-internal.h" #define N_BACKLOG 10 diff --git a/src/libnnstreamer-edge/nnstreamer-edge-log.h b/src/libnnstreamer-edge/nnstreamer-edge-log.h new file mode 100644 index 0000000..a1422b5 --- /dev/null +++ b/src/libnnstreamer-edge/nnstreamer-edge-log.h @@ -0,0 +1,91 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/** + * Copyright (C) 2022 Samsung Electronics Co., Ltd. All Rights Reserved. + * + * @file nnstreamer-edge-log.h + * @date 24 August 2022 + * @brief Log util. + * @see https://github.com/nnstreamer/nnstreamer-edge + * @author Jaeyun Jung + * @note This file is internal header for nnstreamer-edge. DO NOT export this file. + */ + +#ifndef __NNSTREAMER_EDGE_LOG_H__ +#define __NNSTREAMER_EDGE_LOG_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#define TAG_NAME "nnstreamer-edge" + +#if defined(__TIZEN__) +#include + +#define nns_edge_logd(...) dlog_print (DLOG_DEBUG, TAG_NAME, __VA_ARGS__) +#define nns_edge_logi(...) dlog_print (DLOG_INFO, TAG_NAME, __VA_ARGS__) +#define nns_edge_logw(...) dlog_print (DLOG_WARN, TAG_NAME, __VA_ARGS__) +#define nns_edge_loge(...) dlog_print (DLOG_ERROR, TAG_NAME, __VA_ARGS__) +#define nns_edge_logf(...) dlog_print (DLOG_FATAL, TAG_NAME, __VA_ARGS__) +#elif defined(__ANDROID__) +#include + +#define nns_edge_logd(...) __android_log_print (ANDROID_LOG_DEBUG, TAG_NAME, __VA_ARGS__) +#define nns_edge_logi(...) __android_log_print (ANDROID_LOG_INFO, TAG_NAME, __VA_ARGS__) +#define nns_edge_logw(...) __android_log_print (ANDROID_LOG_WARN, TAG_NAME, __VA_ARGS__) +#define nns_edge_loge(...) __android_log_print (ANDROID_LOG_ERROR, TAG_NAME, __VA_ARGS__) +#define nns_edge_logf(...) __android_log_print (ANDROID_LOG_FATAL, TAG_NAME, __VA_ARGS__) +#else +/** + * @brief Internal enumeration for log message. + */ +typedef enum { + NE_LOG_DEBUG = 0, + NE_LOG_INFO, + NE_LOG_WARNING, + NE_LOG_ERROR, + NE_LOG_FATAL, + NE_LOG_NONE +} nns_edge_log_level_e; + +/** + * @brief Internal util function to print log message. + */ +static inline void +nns_edge_print_log (nns_edge_log_level_e level, const char *fmt, ...) +{ + const char *level_str[] = { + [NE_LOG_DEBUG] = "DEBUG", + [NE_LOG_INFO] = "INFO", + [NE_LOG_WARNING] = "WARNING", + [NE_LOG_ERROR] = "ERROR", + [NE_LOG_FATAL] = "FATAL", + [NE_LOG_NONE] = "DEBUG", + }; + + va_list args; + + /** @todo expand log util and handle log level (debug, release) */ + va_start (args, fmt); + + printf ("[%s][%s] ", level_str[level], TAG_NAME); + vprintf (fmt, args); + printf ("\n"); + + va_end (args); +} + +#define nns_edge_logi(...) nns_edge_print_log (NE_LOG_INFO, __VA_ARGS__) +#define nns_edge_logw(...) nns_edge_print_log (NE_LOG_WARNING, __VA_ARGS__) +#define nns_edge_loge(...) nns_edge_print_log (NE_LOG_ERROR, __VA_ARGS__) +#define nns_edge_logd(...) nns_edge_print_log (NE_LOG_DEBUG, __VA_ARGS__) +#define nns_edge_logf(...) nns_edge_print_log (NE_LOG_FATAL, __VA_ARGS__) +#endif + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* __NNSTREAMER_EDGE_LOG_H__ */ diff --git a/src/libnnstreamer-edge/nnstreamer-edge-mqtt.c b/src/libnnstreamer-edge/nnstreamer-edge-mqtt.c index 9f6a009..09acaeb 100644 --- a/src/libnnstreamer-edge/nnstreamer-edge-mqtt.c +++ b/src/libnnstreamer-edge/nnstreamer-edge-mqtt.c @@ -14,10 +14,10 @@ #error "This file can be built with Paho MQTT library." #endif -#include #include -#include "nnstreamer-edge-common.h" #include "nnstreamer-edge-internal.h" +#include "nnstreamer-edge-log.h" +#include "nnstreamer-edge-util.h" /** * @brief Data structure for mqtt broker handle. @@ -43,7 +43,6 @@ mqtt_cb_message_arrived (void *context, char *topic, int topic_len, UNUSED (topic); UNUSED (topic_len); - UNUSED (message); eh = (nns_edge_handle_s *) context; if (!NNS_EDGE_MAGIC_IS_VALID (eh) || !eh->broker_h) { diff --git a/src/libnnstreamer-edge/nnstreamer-edge-util.c b/src/libnnstreamer-edge/nnstreamer-edge-util.c new file mode 100644 index 0000000..9cfa4a8 --- /dev/null +++ b/src/libnnstreamer-edge/nnstreamer-edge-util.c @@ -0,0 +1,183 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/** + * Copyright (C) 2022 Samsung Electronics Co., Ltd. All Rights Reserved. + * + * @file nnstreamer-edge-util.c + * @date 24 August 2022 + * @brief Utility functions. + * @see https://github.com/nnstreamer/nnstreamer-edge + * @author Jaeyun Jung + */ + +#define _GNU_SOURCE +#include + +#include "nnstreamer-edge-log.h" +#include "nnstreamer-edge-util.h" + +/** + * @brief Internal util function to get available port number. + */ +int +nns_edge_get_available_port (void) +{ + struct sockaddr_in sin; + int port = 0, sock; + socklen_t len = sizeof (struct sockaddr); + + sin.sin_family = AF_INET; + sin.sin_addr.s_addr = INADDR_ANY; + sin.sin_port = 0; + + sock = socket (AF_INET, SOCK_STREAM, 0); + if (sock < 0) { + nns_edge_loge ("Failed to get available port, socket creation failure."); + return 0; + } + + if (bind (sock, (struct sockaddr *) &sin, sizeof (struct sockaddr)) == 0) { + if (getsockname (sock, (struct sockaddr *) &sin, &len) == 0) { + port = ntohs (sin.sin_port); + nns_edge_logi ("Available port number: %d", port); + } else { + nns_edge_logw ("Failed to read local socket info."); + } + } + close (sock); + + return port; +} + +/** + * @brief Get host string (host:port). Caller should release returned string using nns_edge_free(). + */ +char * +nns_edge_get_host_string (const char *host, const int port) +{ + return nns_edge_strdup_printf ("%s:%d", host, port); +} + +/** + * @brief Parse string and get host string (host:port). + */ +void +nns_edge_parse_host_string (const char *host_str, char **host, int *port) +{ + char *p = strchr (host_str, ':'); + + if (p) { + *host = nns_edge_strndup (host_str, (p - host_str)); + *port = (int) strtoll (p + 1, NULL, 10); + } +} + +/** + * @brief Parse string and get port number. Return negative value when failed to get port number. + */ +int +nns_edge_parse_port_number (const char *port_str) +{ + int port; + + if (!port_str) + return -1; + + port = (int) strtoll (port_str, NULL, 10); + + if (port <= 0 || port > 65535) { + nns_edge_loge ("Invalid port number %d.", port); + port = -1; + } + + return port; +} + +/** + * @brief Free allocated memory. + */ +void +nns_edge_free (void *data) +{ + if (data) + free (data); +} + +/** + * @brief Allocate new memory and copy bytes. + * @note Caller should release newly allocated memory using nns_edge_free(). + */ +void * +nns_edge_memdup (const void *data, size_t size) +{ + void *mem = NULL; + + if (data && size > 0) { + mem = malloc (size); + + if (mem) { + memcpy (mem, data, size); + } else { + nns_edge_loge ("Failed to allocate memory (%zd).", size); + } + } + + return mem; +} + +/** + * @brief Allocate new memory and copy string. + * @note Caller should release newly allocated string using nns_edge_free(). + */ +char * +nns_edge_strdup (const char *str) +{ + char *new_str = NULL; + + if (str) + new_str = nns_edge_strndup (str, strlen (str)); + + return new_str; +} + +/** + * @brief Allocate new memory and copy bytes of string. + * @note Caller should release newly allocated string using nns_edge_free(). + */ +char * +nns_edge_strndup (const char *str, size_t len) +{ + char *new_str = NULL; + + if (str) { + new_str = (char *) malloc (len + 1); + + if (new_str) { + strncpy (new_str, str, len); + new_str[len] = '\0'; + } else { + nns_edge_loge ("Failed to allocate memory (%zd).", len + 1); + } + } + + return new_str; +} + +/** + * @brief Allocate new memory and print formatted string. + * @note Caller should release newly allocated string using nns_edge_free(). + */ +char * +nns_edge_strdup_printf (const char *format, ...) +{ + char *new_str = NULL; + va_list args; + int len; + + va_start (args, format); + len = vasprintf (&new_str, format, args); + if (len < 0) + new_str = NULL; + va_end (args); + + return new_str; +} diff --git a/src/libnnstreamer-edge/nnstreamer-edge-util.h b/src/libnnstreamer-edge/nnstreamer-edge-util.h new file mode 100644 index 0000000..97aa77d --- /dev/null +++ b/src/libnnstreamer-edge/nnstreamer-edge-util.h @@ -0,0 +1,98 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/** + * Copyright (C) 2022 Samsung Electronics Co., Ltd. All Rights Reserved. + * + * @file nnstreamer-edge-util.h + * @date 24 August 2022 + * @brief Utility functions. + * @see https://github.com/nnstreamer/nnstreamer-edge + * @author Jaeyun Jung + * @note This file is internal header for nnstreamer-edge. DO NOT export this file. + */ + +#ifndef __NNSTREAMER_EDGE_UTIL_H__ +#define __NNSTREAMER_EDGE_UTIL_H__ + +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** + * @brief Utility to silence unused parameter warning for intentionally unused parameters (e.g., callback functions of a framework) + */ +#ifndef UNUSED +#define UNUSED(expr) do { (void)(expr); } while (0) +#endif + +#define STR_IS_VALID(s) ((s) && (s)[0] != '\0') +#define SAFE_FREE(p) do { if (p) { free (p); (p) = NULL; } } while (0) + +#define NNS_EDGE_MAGIC 0xfeedfeed +#define NNS_EDGE_MAGIC_DEAD 0xdeaddead +#define NNS_EDGE_MAGIC_IS_VALID(h) ((h) && (h)->magic == NNS_EDGE_MAGIC) + +#define nns_edge_lock_init(h) do { pthread_mutex_init (&(h)->lock, NULL); } while (0) +#define nns_edge_lock_destroy(h) do { pthread_mutex_destroy (&(h)->lock); } while (0) +#define nns_edge_lock(h) do { pthread_mutex_lock (&(h)->lock); } while (0) +#define nns_edge_unlock(h) do { pthread_mutex_unlock (&(h)->lock); } while (0) + +/** + * @brief Get available port number. + */ +int nns_edge_get_available_port (void); + +/** + * @brief Get host string (host:port). Caller should release returned string using nns_edge_free(). + */ +char *nns_edge_get_host_string (const char *host, const int port); + +/** + * @brief Parse string and get host string (host:port). + */ +void nns_edge_parse_host_string (const char *host_str, char **host, int *port); + +/** + * @brief Parse string and get port number. Return negative value when failed to get port number. + */ +int nns_edge_parse_port_number (const char *port_str); + +/** + * @brief Free allocated memory. + */ +void nns_edge_free (void *data); + +/** + * @brief Allocate new memory and copy bytes. + * @note Caller should release newly allocated memory using nns_edge_free(). + */ +void *nns_edge_memdup (const void *data, size_t size); + +/** + * @brief Allocate new memory and copy string. + * @note Caller should release newly allocated string using nns_edge_free(). + */ +char *nns_edge_strdup (const char *str); + +/** + * @brief Allocate new memory and copy bytes of string. + * @note Caller should release newly allocated string using nns_edge_free(). + */ +char *nns_edge_strndup (const char *str, size_t len); + +/** + * @brief Allocate new memory and print formatted string. + * @note Caller should release newly allocated string using nns_edge_free(). + */ +char *nns_edge_strdup_printf (const char *format, ...); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* __NNSTREAMER_EDGE_UTIL_H__ */ diff --git a/tests/unittest_nnstreamer-edge.cc b/tests/unittest_nnstreamer-edge.cc index 6d58fcb..e686dc0 100644 --- a/tests/unittest_nnstreamer-edge.cc +++ b/tests/unittest_nnstreamer-edge.cc @@ -11,6 +11,8 @@ #include "nnstreamer-edge.h" #include "nnstreamer-edge-common.h" #include "nnstreamer-edge-internal.h" +#include "nnstreamer-edge-log.h" +#include "nnstreamer-edge-util.h" /** * @brief Data struct for unittest.