Add util function to get the version of nnstreamer-edge.
TODO:
Add version info while sending or receiving data between the connected devices.
Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
SET(NNS_EDGE_FLAGS "-DDEBUG=0")
ENDIF()
+STRING(REPLACE "." ";" VERSION_LIST ${VERSION})
+LIST(GET VERSION_LIST 0 VERSION_MAJOR)
+LIST(GET VERSION_LIST 1 VERSION_MINOR)
+LIST(GET VERSION_LIST 2 VERSION_MICRO)
+
+SET(NNS_EDGE_FLAGS "${NNS_EDGE_FLAGS} -DVERSION_MAJOR=${VERSION_MAJOR} -DVERSION_MINOR=${VERSION_MINOR} -DVERSION_MICRO=${VERSION_MICRO}")
+
# Set as-needed option
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--as-needed")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--as-needed")
*/
void nns_edge_set_log_level (nns_edge_log_level_e level);
+/**
+ * @brief Get the version of nnstreamer-edge.
+ * @param[out] major MAJOR.minor.micro, won't set if it's null.
+ * @param[out] minor major.MINOR.micro, won't set if it's null.
+ * @param[out] micro major.minor.MICRO, won't set if it's null.
+ */
+void nns_edge_get_version (unsigned int *major, unsigned int *minor, unsigned int *micro);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
return _id;
}
+/**
+ * @brief Get the version of nnstreamer-edge.
+ */
+void
+nns_edge_get_version (unsigned int *major, unsigned int *minor,
+ unsigned int *micro)
+{
+ if (major)
+ *major = VERSION_MAJOR;
+ if (minor)
+ *minor = VERSION_MINOR;
+ if (micro)
+ *micro = VERSION_MICRO;
+}
+
+/**
+ * @brief Generate the version key.
+ */
+uint64_t
+nns_edge_generate_version_key (void)
+{
+ unsigned int major, minor, micro;
+
+ nns_edge_get_version (&major, &minor, µ);
+
+ return (0xefdd000000000000ULL | (micro << 24) | (major << 12) | minor);
+}
+
+/**
+ * @brief Parse the version key.
+ */
+bool
+nns_edge_parse_version_key (const uint64_t version_key, unsigned int *major,
+ unsigned int *minor, unsigned int *micro)
+{
+ if ((version_key & 0xffff000000000000ULL) != 0xefdd000000000000ULL)
+ return false;
+
+ if (minor)
+ *minor = (unsigned int) (version_key & 0xfff);
+ if (major)
+ *major = (unsigned int) ((version_key >> 12) & 0xfff);
+ if (micro)
+ *micro = (unsigned int) ((version_key >> 24) & 0xfff);
+
+ return true;
+}
+
/**
* @brief Internal util function to get available port number.
*/
#include <netinet/tcp.h>
#include <netinet/in.h>
#include <pthread.h>
+#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
*/
int64_t nns_edge_generate_id (void);
+/**
+ * @brief Generate the version key.
+ */
+uint64_t nns_edge_generate_version_key (void);
+
+/**
+ * @brief Parse the version key.
+ */
+bool nns_edge_parse_version_key (const uint64_t version_key, unsigned int *major, unsigned int *minor, unsigned int *micro);
+
/**
* @brief Get available port number.
*/
EXPECT_TRUE (nns_edge_queue_destroy (queue_h));
}
+/**
+ * @brief Util to get the version.
+ */
+TEST(edgeUtil, getVersion)
+{
+ unsigned int major1, minor1, micro1;
+ unsigned int major2, minor2, micro2;
+ uint64_t ver_key;
+
+ nns_edge_get_version (&major1, &minor1, µ1);
+ ver_key = nns_edge_generate_version_key ();
+ EXPECT_TRUE (nns_edge_parse_version_key (ver_key, &major2, &minor2, µ2));
+ EXPECT_EQ (major1, major2);
+ EXPECT_EQ (minor1, minor2);
+ EXPECT_EQ (micro1, micro2);
+}
+
/**
* @brief Main gtest
*/