sensord: add tokenize function to sensor::utils 04/124604/2
authorkibak.yoon <kibak.yoon@samsung.com>
Wed, 12 Apr 2017 01:59:22 +0000 (10:59 +0900)
committerKibak Yoon <kibak.yoon@samsung.com>
Wed, 12 Apr 2017 02:20:49 +0000 (19:20 -0700)
Change-Id: I8f646d00a241f23a8ee2ca3725102fecf8ec220c
Signed-off-by: kibak.yoon <kibak.yoon@samsung.com>
src/shared/sensor_utils.cpp
src/shared/sensor_utils.h

index 2b2781f..6ef0504 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "sensor_utils.h"
 
+#include <glib.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/types.h>
@@ -29,7 +30,9 @@
 
 #include <sensor_types.h>
 
+#ifndef PATH_MAX
 #define PATH_MAX 256
+#endif
 
 /* TODO: move and define string type to sensor_type.h */
 static std::map<sensor_type_t, const char *> types = {
@@ -199,3 +202,20 @@ const char* sensor::utils::get_client_name(void)
 
        return client_name;
 }
+
+std::vector<std::string> sensor::utils::tokenize(const std::string &in, const char *delim)
+{
+       std::vector<std::string> tokens;
+       char *input = g_strdup(in.c_str());
+
+       char *save = NULL;
+       char *token = strtok_r(input, delim, &save);
+
+       while (token != NULL) {
+               tokens.push_back(token);
+               token = strtok_r(NULL, delim, &save);
+       }
+
+       g_free(input);
+       return tokens;
+}
index c6ab64d..7e31f6d 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <time.h>
 #include <sensor_types.h>
+#include <string>
+#include <vector>
 
 namespace sensor {
 
@@ -33,6 +35,8 @@ namespace utils {
 
        const char* get_client_name(void);
        bool get_proc_name(pid_t pid, char *process_name);
+
+       std::vector<std::string> tokenize(const std::string &in, const char *delim);
 }
 
 }