--- /dev/null
+/*
+ * 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_ */
profile = mobile-3.0
# C Sources
-USER_SRCS = src/clock.c
+USER_SRCS = src/Clock.c src/Utils.cpp
USER_SRCS_ABS =
# EDC Sources
--- /dev/null
+/*
+ * 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];
+}
--- /dev/null
+/*
+ * 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_ */
# 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 =
--- /dev/null
+/*
+ * 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];
+}