[clock]Utils added.
authorRadoslaw Czerski <r.czerski@samsung.com>
Fri, 5 Aug 2016 09:42:23 +0000 (11:42 +0200)
committerRadoslaw Czerski <r.czerski@samsung.com>
Fri, 5 Aug 2016 09:42:23 +0000 (11:42 +0200)
Change-Id: Ib55d4081b92b72e1fd88bdacc98403ef59ec1075
Signed-off-by: Radoslaw Czerski <r.czerski@samsung.com>
clock/inc/Utils.h [new file with mode: 0644]
clock/project_def.prop
clock/src/Utils.cpp [new file with mode: 0644]
common/inc/Utils/Utils.h [new file with mode: 0644]
common/project_def.prop
common/src/Utils/Utils.cpp [new file with mode: 0644]

diff --git a/clock/inc/Utils.h b/clock/inc/Utils.h
new file mode 100644 (file)
index 0000000..8b9fb7e
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _CLOCK_UTILS_H_
+#define _CLOCK_UTILS_H_
+
+
+namespace common {
+       namespace utils {
+
+               class Utils {
+               public:
+                       /*
+                        * @brief Application sub-directories type.
+                        */
+                       enum AppSubdirectory {
+                               APP_DIR_DATA,
+                               APP_DIR_CACHE,
+                               APP_DIR_RESOURCE,
+                               APP_DIR_SHARED_DATA,
+                               APP_DIR_SHARED_RESOURCE,
+                               APP_DIR_SHARED_TRUSTED,
+                               APP_DIR_EXTERNAL_DATA,
+                               APP_DIR_EXTERNAL_CACHE,
+                               APP_DIR_EXTERNAL_SHARED_DATA,
+                       };
+
+                       /**
+                        * @brief Returns absolute path to resource file located in applications directory.
+                        *
+                        * @param dir type of subdirectory
+                        * @param relative path of resource from starting from given sub dir.
+                        *        eg. for APP_DATA_DIR subdir and relative "database.db" => "/home/owner/apps/org.tizen.clock/data/database.db"
+                        * @return absolute path string.
+                        *
+                        * @note returns statically allocated string
+                        */
+                       static const char *GetAppResourcePath(enum AppSubdirectory dir, const char *relative);
+               };
+       }
+}
+
+
+#endif /* _CLOCK_UTILS_H_ */
index 018afeb..8af2a10 100644 (file)
@@ -9,7 +9,7 @@ type = app
 profile = mobile-3.0
 
 # C Sources
-USER_SRCS = src/clock.c 
+USER_SRCS = src/Clock.c src/Utils.cpp
 USER_SRCS_ABS = 
 
 # EDC Sources
diff --git a/clock/src/Utils.cpp b/clock/src/Utils.cpp
new file mode 100644 (file)
index 0000000..a1f3758
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Utils.h"
+
+#include <dlog.h>
+#include <app.h>
+#include <stdlib.h>
+#include <app_common.h>
+#include <Elementary.h>
+#include <limits.h>
+
+using namespace common::utils;
+
+const char *Utils::GetAppResourcePath(enum AppSubdirectory dir, const char *relative)
+{
+       static char buf[PATH_MAX];
+       char *prefix;
+
+       switch (dir) {
+       case APP_DIR_DATA:
+               prefix = app_get_data_path();
+               break;
+       case APP_DIR_CACHE:
+               prefix = app_get_cache_path();
+               break;
+       case APP_DIR_RESOURCE:
+               prefix = app_get_resource_path();
+               break;
+       case APP_DIR_SHARED_DATA:
+               prefix = app_get_shared_data_path();
+               break;
+       case APP_DIR_SHARED_RESOURCE:
+               prefix = app_get_shared_resource_path();
+               break;
+       case APP_DIR_SHARED_TRUSTED:
+               prefix = app_get_shared_trusted_path();
+               break;
+       case APP_DIR_EXTERNAL_DATA:
+               prefix = app_get_external_data_path();
+               break;
+       case APP_DIR_EXTERNAL_CACHE:
+               prefix = app_get_external_cache_path();
+               break;
+       case APP_DIR_EXTERNAL_SHARED_DATA:
+               prefix = app_get_external_shared_data_path();
+               break;
+       default:
+               dlog_print(DLOG_FATAL, LOG_TAG, "Not handled directory type.");
+               return NULL;
+       }
+       size_t res = eina_file_path_join(buf, sizeof(buf), prefix, relative);
+       free(prefix);
+       if (res > sizeof(buf)) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "Path exceeded PATH_MAX");
+               return NULL;
+       }
+
+       return &buf[0];
+}
diff --git a/common/inc/Utils/Utils.h b/common/inc/Utils/Utils.h
new file mode 100644 (file)
index 0000000..8b9fb7e
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _CLOCK_UTILS_H_
+#define _CLOCK_UTILS_H_
+
+
+namespace common {
+       namespace utils {
+
+               class Utils {
+               public:
+                       /*
+                        * @brief Application sub-directories type.
+                        */
+                       enum AppSubdirectory {
+                               APP_DIR_DATA,
+                               APP_DIR_CACHE,
+                               APP_DIR_RESOURCE,
+                               APP_DIR_SHARED_DATA,
+                               APP_DIR_SHARED_RESOURCE,
+                               APP_DIR_SHARED_TRUSTED,
+                               APP_DIR_EXTERNAL_DATA,
+                               APP_DIR_EXTERNAL_CACHE,
+                               APP_DIR_EXTERNAL_SHARED_DATA,
+                       };
+
+                       /**
+                        * @brief Returns absolute path to resource file located in applications directory.
+                        *
+                        * @param dir type of subdirectory
+                        * @param relative path of resource from starting from given sub dir.
+                        *        eg. for APP_DATA_DIR subdir and relative "database.db" => "/home/owner/apps/org.tizen.clock/data/database.db"
+                        * @return absolute path string.
+                        *
+                        * @note returns statically allocated string
+                        */
+                       static const char *GetAppResourcePath(enum AppSubdirectory dir, const char *relative);
+               };
+       }
+}
+
+
+#endif /* _CLOCK_UTILS_H_ */
index 065295b..1ce9240 100644 (file)
@@ -35,7 +35,7 @@ USER_OBJS_ABS =
 
 # User Includes
 ## C Compiler
-USER_INC_DIRS = inc 
+USER_INC_DIRS = inc inc/Utils
 USER_INC_DIRS_ABS = 
 USER_INC_FILES = 
 USER_INC_FILES_ABS = 
diff --git a/common/src/Utils/Utils.cpp b/common/src/Utils/Utils.cpp
new file mode 100644 (file)
index 0000000..a1f3758
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Utils.h"
+
+#include <dlog.h>
+#include <app.h>
+#include <stdlib.h>
+#include <app_common.h>
+#include <Elementary.h>
+#include <limits.h>
+
+using namespace common::utils;
+
+const char *Utils::GetAppResourcePath(enum AppSubdirectory dir, const char *relative)
+{
+       static char buf[PATH_MAX];
+       char *prefix;
+
+       switch (dir) {
+       case APP_DIR_DATA:
+               prefix = app_get_data_path();
+               break;
+       case APP_DIR_CACHE:
+               prefix = app_get_cache_path();
+               break;
+       case APP_DIR_RESOURCE:
+               prefix = app_get_resource_path();
+               break;
+       case APP_DIR_SHARED_DATA:
+               prefix = app_get_shared_data_path();
+               break;
+       case APP_DIR_SHARED_RESOURCE:
+               prefix = app_get_shared_resource_path();
+               break;
+       case APP_DIR_SHARED_TRUSTED:
+               prefix = app_get_shared_trusted_path();
+               break;
+       case APP_DIR_EXTERNAL_DATA:
+               prefix = app_get_external_data_path();
+               break;
+       case APP_DIR_EXTERNAL_CACHE:
+               prefix = app_get_external_cache_path();
+               break;
+       case APP_DIR_EXTERNAL_SHARED_DATA:
+               prefix = app_get_external_shared_data_path();
+               break;
+       default:
+               dlog_print(DLOG_FATAL, LOG_TAG, "Not handled directory type.");
+               return NULL;
+       }
+       size_t res = eina_file_path_join(buf, sizeof(buf), prefix, relative);
+       free(prefix);
+       if (res > sizeof(buf)) {
+               dlog_print(DLOG_ERROR, LOG_TAG, "Path exceeded PATH_MAX");
+               return NULL;
+       }
+
+       return &buf[0];
+}