summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKim Kibum <kb0929.kim@samsung.com>2012-04-29 16:58:19 +0900
committerKim Kibum <kb0929.kim@samsung.com>2012-04-29 16:58:19 +0900
commitb7d00f250a7c4012b018ccbfdeebd976f1bd907f (patch)
tree69b3c6c47bd0b1482933b353460b3c95b10ecb65 /src
parent5d87d7db1c2dd537832b1ec22343511f53f25c58 (diff)
downloadapplication-b7d00f250a7c4012b018ccbfdeebd976f1bd907f.tar.gz
application-b7d00f250a7c4012b018ccbfdeebd976f1bd907f.tar.bz2
application-b7d00f250a7c4012b018ccbfdeebd976f1bd907f.zip
upload tizen1.0 source
Diffstat (limited to 'src')
-rwxr-xr-xsrc/app_error.c72
-rwxr-xr-xsrc/app_finalizer.c105
-rwxr-xr-xsrc/app_main.c372
-rwxr-xr-xsrc/app_package.c43
-rwxr-xr-xsrc/app_resource.c157
-rwxr-xr-xsrc/preference.c2
-rwxr-xr-xsrc/service.c450
7 files changed, 619 insertions, 582 deletions
diff --git a/src/app_error.c b/src/app_error.c
new file mode 100755
index 0000000..c7e137c
--- /dev/null
+++ b/src/app_error.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2011 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <libintl.h>
+
+#include <dlog.h>
+
+#include <app_private.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "TIZEN_N_APPLICATION"
+
+static const char* app_error_to_string(app_error_e error)
+{
+ switch (error)
+ {
+ case APP_ERROR_NONE:
+ return "NONE";
+
+ case APP_ERROR_INVALID_PARAMETER:
+ return "INVALID_PARAMETER";
+
+ case APP_ERROR_OUT_OF_MEMORY:
+ return "OUT_OF_MEMORY";
+
+ case APP_ERROR_INVALID_CONTEXT:
+ return "INVALID_CONTEXT";
+
+ case APP_ERROR_NO_SUCH_FILE:
+ return "NO_SUCH_FILE";
+
+ case APP_ERROR_ALREADY_RUNNING:
+ return "ALREADY_RUNNING";
+
+ default :
+ return "UNKNOWN";
+ }
+}
+
+int app_error(app_error_e error, const char* function, const char *description)
+{
+ if (description)
+ {
+ LOGE("[%s] %s(0x%08x) : %s", function, app_error_to_string(error), error, description);
+ }
+ else
+ {
+ LOGE("[%s] %s(0x%08x)", function, app_error_to_string(error), error);
+ }
+
+ return error;
+}
diff --git a/src/app_finalizer.c b/src/app_finalizer.c
new file mode 100755
index 0000000..264c9f2
--- /dev/null
+++ b/src/app_finalizer.c
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2011 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <libintl.h>
+
+#include <app_private.h>
+
+typedef struct _app_finalizer_s_ {
+ app_finalizer_cb callback;
+ void *data;
+ struct _app_finalizer_s_ *next;
+} app_finalizer_s;
+
+typedef app_finalizer_s *app_finalizer_h;
+
+static app_finalizer_s finalizer_head = {
+ .callback = NULL,
+ .data = NULL,
+ .next = NULL
+};
+
+int app_finalizer_add(app_finalizer_cb callback, void *data)
+{
+ app_finalizer_h finalizer_tail = &finalizer_head;
+ app_finalizer_h finalizer_new;
+
+ finalizer_new = malloc(sizeof(app_finalizer_s));
+
+ if (finalizer_new == NULL)
+ {
+ return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
+ }
+
+ finalizer_new->callback = callback;
+ finalizer_new->data = data;
+ finalizer_new->next = NULL;
+
+ while (finalizer_tail->next)
+ {
+ finalizer_tail = finalizer_tail->next;
+ }
+
+ finalizer_tail->next = finalizer_new;
+
+ return APP_ERROR_NONE;
+}
+
+int app_finalizer_remove(app_finalizer_cb callback)
+{
+ app_finalizer_h finalizer_node = &finalizer_head;
+
+ while (finalizer_node->next)
+ {
+ if (finalizer_node->next->callback == callback)
+ {
+ app_finalizer_h removed_node = finalizer_node->next;
+ finalizer_node->next = removed_node->next;
+ free(removed_node);
+ return APP_ERROR_NONE;
+ }
+
+ finalizer_node = finalizer_node->next;
+ }
+
+ return APP_ERROR_INVALID_PARAMETER;
+}
+
+void app_finalizer_execute(void)
+{
+ app_finalizer_h finalizer_node = &finalizer_head;
+ app_finalizer_h finalizer_executed;
+ app_finalizer_cb finalizer_cb = NULL;
+
+ while (finalizer_node->next)
+ {
+ finalizer_cb = finalizer_node->next->callback;
+
+ finalizer_cb(finalizer_node->next->data);
+
+ finalizer_executed = finalizer_node->next;
+
+ finalizer_node = finalizer_node->next;
+
+ free(finalizer_executed);
+ }
+
+ finalizer_head.next = NULL;
+}
+
diff --git a/src/app_main.c b/src/app_main.c
index 84369d3..e9a9cb8 100755
--- a/src/app_main.c
+++ b/src/app_main.c
@@ -40,310 +40,272 @@
#define LOG_TAG "TIZEN_N_APPLICATION"
-#define TERMINATE_TASK_MAX 8
-
typedef enum {
APP_STATE_NOT_RUNNING, // The application has been launched or was running but was terminated
APP_STATE_CREATING, // The application is initializing the resources on app_create_cb callback
APP_STATE_RUNNING, // The application is running in the foreground and background
} app_state_e;
-typedef struct app_context_s {
- struct appcore_ops appcore;
+typedef struct {
char *package;
- char *project_name;
- app_event_callback_s *callbacks;
+ char *app_name;
app_state_e state;
- void *user_data;
- app_terminate_task_t terminate_task[TERMINATE_TASK_MAX];
-} *app_context_h;
-
-static int app_cb_broker_appcore_create(void *data);
-static int app_cb_broker_appcore_pause(void *data);
-static int app_cb_broker_appcore_resume(void *data);
-static int app_cb_broker_appcore_terminate(void *data);
-static int app_cb_broker_appcore_reset(bundle *appcore_bundle, void *data);
-
-static int app_cb_broker_appcore_low_memory(void *data);
-static int app_cb_broker_appcore_low_battery(void *data);
-static int app_cb_broker_appcore_rotation_event(enum appcore_rm rm, void *data);
-static int app_cb_broker_appcore_lang_changed(void *data);
-static int app_cb_broker_appcore_region_changed(void *data);
-
-static void app_set_appcore_event_cb(void);
-static void app_unset_appcore_event_cb(void);
+ app_event_callback_s *callback;
+ void *data;
+} app_context_s;
-static struct app_context_s app_context = {
- .appcore.create = app_cb_broker_appcore_create,
- .appcore.terminate = app_cb_broker_appcore_terminate,
- .appcore.pause = app_cb_broker_appcore_pause,
- .appcore.resume = app_cb_broker_appcore_resume,
- .appcore.reset = app_cb_broker_appcore_reset,
- .package = NULL,
- .callbacks = NULL,
- .state = APP_STATE_NOT_RUNNING,
- .user_data = NULL
-};
+typedef app_context_s *app_context_h;
+static int app_appcore_create(void *data);
+static int app_appcore_pause(void *data);
+static int app_appcore_resume(void *data);
+static int app_appcore_terminate(void *data);
+static int app_appcore_reset(bundle *appcore_bundle, void *data);
-static void app_reset_app_context()
-{
- int i;
+static int app_appcore_low_memory(void *data);
+static int app_appcore_low_battery(void *data);
+static int app_appcore_rotation_event(enum appcore_rm rm, void *data);
+static int app_appcore_lang_changed(void *data);
+static int app_appcore_region_changed(void *data);
- if (app_context.package != NULL)
- {
- free(app_context.package);
- }
-
- if (app_context.project_name != NULL)
- {
- free(app_context.project_name);
- }
-
- app_context.callbacks = NULL;
- app_context.user_data = NULL;
- app_context.state = APP_STATE_NOT_RUNNING;
-
- for (i=0; i<TERMINATE_TASK_MAX; i++)
- {
- app_context.terminate_task[i].cb = NULL;
- app_context.terminate_task[i].data = NULL;
- }
-}
+static void app_set_appcore_event_cb(app_context_h app_context);
+static void app_unset_appcore_event_cb(void);
int app_efl_main(int *argc, char ***argv, app_event_callback_s *callback, void *user_data)
{
- char *package = NULL;;
- char *project_name = NULL;
+ app_context_s app_context = {
+ .package = NULL,
+ .app_name = NULL,
+ .state = APP_STATE_NOT_RUNNING,
+ .callback = callback,
+ .data = user_data
+ };
+
+ struct appcore_ops appcore_context = {
+ .data = &app_context,
+ .create = app_appcore_create,
+ .terminate = app_appcore_terminate,
+ .pause = app_appcore_pause,
+ .resume = app_appcore_resume,
+ .reset = app_appcore_reset,
+ };
if (argc == NULL || argv == NULL || callback == NULL)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, APP_ERROR_INVALID_PARAMETER);
- return APP_ERROR_INVALID_PARAMETER;
+ return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
if (callback->create == NULL)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, APP_ERROR_INVALID_PARAMETER);
- return APP_ERROR_INVALID_PARAMETER;
+ return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "app_create_cb() callback must be registered");
}
if (app_context.state != APP_STATE_NOT_RUNNING)
{
- LOGE("[%s] ALREADY_RUNNING(0x%08x)", __FUNCTION__, APP_ERROR_ALREADY_RUNNING);
- return APP_ERROR_ALREADY_RUNNING;
+ return app_error(APP_ERROR_ALREADY_RUNNING, __FUNCTION__, NULL);
}
- if (app_get_package(&package) != 0)
+ if (app_get_package(&(app_context.package)) != APP_ERROR_NONE)
{
- LOGE("[%s] INVALID_CONTEXT(0x%08x)", __FUNCTION__, APP_ERROR_INVALID_CONTEXT);
- return APP_ERROR_INVALID_CONTEXT;
+ return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package");
}
-
- app_context.package = package;
- if (app_get_project_name(package, &project_name) != 0)
+ if (app_get_package_app_name(app_context.package, &(app_context.app_name)) != APP_ERROR_NONE)
{
- LOGE("[%s] INVALID_CONTEXT(0x%08x)", __FUNCTION__, APP_ERROR_INVALID_CONTEXT);
- return APP_ERROR_INVALID_CONTEXT;
+ return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package's app name");
}
- app_context.project_name = project_name;
-
app_context.state = APP_STATE_CREATING;
- app_context.callbacks = callback;
- app_context.user_data = user_data;
- appcore_efl_main(app_context.project_name, argc, argv, &(app_context.appcore));
+ appcore_efl_main(app_context.app_name, argc, argv, &appcore_context);
- app_reset_app_context();
+ free(app_context.package);
+ free(app_context.app_name);
return APP_ERROR_NONE;
}
+
void app_efl_exit(void)
{
elm_exit();
}
-static void app_set_appcore_event_cb()
+
+int app_appcore_create(void *data)
{
- if (app_context.callbacks->low_memory != NULL)
- {
- appcore_set_event_callback(APPCORE_EVENT_LOW_MEMORY, app_cb_broker_appcore_low_memory, NULL);
- }
+ app_context_h app_context = data;
+ app_create_cb create_cb;
+ char locale_dir[TIZEN_PATH_MAX] = {0, };
- if (app_context.callbacks->low_battery != NULL)
+ if (app_context == NULL)
{
- appcore_set_event_callback(APPCORE_EVENT_LOW_BATTERY, app_cb_broker_appcore_low_battery, NULL);
+ return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
}
- if (app_context.callbacks->device_orientation != NULL)
- {
- appcore_set_rotation_cb(app_cb_broker_appcore_rotation_event, NULL);
- }
+ app_set_appcore_event_cb(app_context);
- if (app_context.callbacks->language_changed != NULL)
- {
- appcore_set_event_callback(APPCORE_EVENT_LANG_CHANGE, app_cb_broker_appcore_lang_changed, NULL);
- }
+ snprintf(locale_dir, TIZEN_PATH_MAX, PATH_FMT_LOCALE_DIR, app_context->package);
+ appcore_set_i18n(app_context->app_name, locale_dir);
+
+ create_cb = app_context->callback->create;
- if (app_context.callbacks->region_format_changed != NULL)
+ if (create_cb == NULL || create_cb(app_context->data) == false)
{
- appcore_set_event_callback(APPCORE_EVENT_REGION_CHANGE, app_cb_broker_appcore_region_changed, NULL);
+ return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "app_create_cb() returns false");
}
-}
-static void app_unset_appcore_event_cb(void)
-{
- appcore_set_event_callback(APPCORE_EVENT_LOW_MEMORY, NULL, NULL);
- appcore_set_event_callback(APPCORE_EVENT_LOW_BATTERY, NULL, NULL);
- appcore_unset_rotation_cb();
- appcore_set_event_callback(APPCORE_EVENT_LANG_CHANGE, NULL, NULL);
- appcore_set_event_callback(APPCORE_EVENT_REGION_CHANGE, NULL, NULL);
-}
+ app_context->state = APP_STATE_RUNNING;
+ return APP_ERROR_NONE;
+}
-int app_cb_broker_appcore_create(void *data)
+int app_appcore_terminate(void *data)
{
- app_create_cb create_cb;
- char locale_dir[TIZEN_PATH_MAX] = {0, };
-
- app_set_appcore_event_cb();
-
- snprintf(locale_dir, TIZEN_PATH_MAX, PATH_FMT_LOCALE_DIR, app_context.package);
- appcore_set_i18n(app_context.project_name, locale_dir);
-
- create_cb = app_context.callbacks->create;
+ app_context_h app_context = data;
+ app_terminate_cb terminate_cb;
- if (create_cb != NULL && create_cb(app_context.user_data) == true)
+ if (app_context == NULL)
{
- app_context.state = APP_STATE_RUNNING;
- return 0;
+ return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
}
- return -1;
-}
-
-int app_cb_broker_appcore_terminate(void *data)
-{
- app_terminate_cb terminate_cb;
- int i;
-
- terminate_cb = app_context.callbacks->terminate;
+ terminate_cb = app_context->callback->terminate;
if (terminate_cb != NULL)
{
- terminate_cb(app_context.user_data);
+ terminate_cb(app_context->data);
}
app_unset_appcore_event_cb();
- for (i=0; i<TERMINATE_TASK_MAX; i++)
- {
- if (app_context.terminate_task[i].cb != NULL)
- {
- app_terminate_task_cb task_cb;
-
- task_cb = app_context.terminate_task[i].cb;
-
- if (task_cb != NULL)
- {
- task_cb(app_context.terminate_task[i].data);
- }
- }
- }
+ app_finalizer_execute();
- return 0;
+ return APP_ERROR_NONE;
}
-int app_cb_broker_appcore_pause(void *data)
+int app_appcore_pause(void *data)
{
+ app_context_h app_context = data;
app_pause_cb pause_cb;
- pause_cb = app_context.callbacks->pause;
+ if (app_context == NULL)
+ {
+ return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
+ }
+
+ pause_cb = app_context->callback->pause;
if (pause_cb != NULL)
{
- pause_cb(app_context.user_data);
+ pause_cb(app_context->data);
}
- return 0;
+ return APP_ERROR_NONE;
}
-int app_cb_broker_appcore_resume(void *data)
+int app_appcore_resume(void *data)
{
+ app_context_h app_context = data;
app_resume_cb resume_cb;
- resume_cb = app_context.callbacks->resume;
+ if (app_context == NULL)
+ {
+ return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
+ }
+
+ resume_cb = app_context->callback->resume;
if (resume_cb != NULL)
{
- resume_cb(app_context.user_data);
+ resume_cb(app_context->data);
}
- return 0;
+ return APP_ERROR_NONE;
}
-int app_cb_broker_appcore_reset(bundle *appcore_bundle, void *data)
+int app_appcore_reset(bundle *appcore_bundle, void *data)
{
+ app_context_h app_context = data;
app_service_cb service_cb;
service_h service;
- if (service_create_event(appcore_bundle, &service) != 0)
+ if (app_context == NULL)
+ {
+ return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
+ }
+
+ if (service_create_event(appcore_bundle, &service) != APP_ERROR_NONE)
{
- LOGE("[%s] fail to create service handle from bundle", __FUNCTION__);
- return -1;
+ return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to create a service handle from the bundle");
}
- service_cb = app_context.callbacks->service;
+ service_cb = app_context->callback->service;
if (service_cb != NULL)
{
- service_cb(service, app_context.user_data);
+ service_cb(service, app_context->data);
}
service_destroy(service);
- return 0;
+ return APP_ERROR_NONE;
}
-int app_cb_broker_appcore_low_memory(void *data)
+int app_appcore_low_memory(void *data)
{
+ app_context_h app_context = data;
app_low_memory_cb low_memory_cb;
- low_memory_cb = app_context.callbacks->low_memory;
+ if (app_context == NULL)
+ {
+ return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
+ }
+
+ low_memory_cb = app_context->callback->low_memory;
if (low_memory_cb != NULL)
{
- low_memory_cb(app_context.user_data);
+ low_memory_cb(app_context->data);
}
- return 0;
+ return APP_ERROR_NONE;
}
-int app_cb_broker_appcore_low_battery(void *data)
+int app_appcore_low_battery(void *data)
{
+ app_context_h app_context = data;
app_low_battery_cb low_battery_cb;
- low_battery_cb = app_context.callbacks->low_battery;
+ if (app_context == NULL)
+ {
+ return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
+ }
+
+ low_battery_cb = app_context->callback->low_battery;
if (low_battery_cb != NULL)
{
- low_battery_cb(app_context.user_data);
+ low_battery_cb(app_context->data);
}
- return 0;
+ return APP_ERROR_NONE;
}
-int app_cb_broker_appcore_rotation_event(enum appcore_rm rm, void *data)
+int app_appcore_rotation_event(enum appcore_rm rm, void *data)
{
+ app_context_h app_context = data;
app_device_orientation_cb device_orientation_cb;
- device_orientation_cb = app_context.callbacks->device_orientation;
+ if (app_context == NULL)
+ {
+ return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
+ }
+
+ device_orientation_cb = app_context->callback->device_orientation;
if (device_orientation_cb != NULL)
{
@@ -351,56 +313,86 @@ int app_cb_broker_appcore_rotation_event(enum appcore_rm rm, void *data)
dev_orientation = app_convert_appcore_rm(rm);
- device_orientation_cb(dev_orientation, app_context.user_data);
+ device_orientation_cb(dev_orientation, app_context->data);
}
- return 0;
+ return APP_ERROR_NONE;
}
-int app_cb_broker_appcore_lang_changed(void *data)
+int app_appcore_lang_changed(void *data)
{
+ app_context_h app_context = data;
app_language_changed_cb lang_changed_cb;
- lang_changed_cb = app_context.callbacks->language_changed;
+ if (app_context == NULL)
+ {
+ return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
+ }
+
+ lang_changed_cb = app_context->callback->language_changed;
if (lang_changed_cb != NULL)
{
- lang_changed_cb(app_context.user_data);
+ lang_changed_cb(app_context->data);
}
- return 0;
+ return APP_ERROR_NONE;
}
-int app_cb_broker_appcore_region_changed(void *data)
+int app_appcore_region_changed(void *data)
{
+ app_context_h app_context = data;
app_region_format_changed_cb region_changed_cb;
- region_changed_cb = app_context.callbacks->region_format_changed;
+ if (app_context == NULL)
+ {
+ return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
+ }
+
+ region_changed_cb = app_context->callback->region_format_changed;
if (region_changed_cb != NULL)
{
- region_changed_cb(app_context.user_data);
+ region_changed_cb(app_context->data);
}
- return 0;
+ return APP_ERROR_NONE;
}
-int app_add_terminate_task(app_terminate_task_cb callback, void *data)
+void app_set_appcore_event_cb(app_context_h app_context)
{
- int i;
+ if (app_context->callback->low_memory != NULL)
+ {
+ appcore_set_event_callback(APPCORE_EVENT_LOW_MEMORY, app_appcore_low_memory, app_context);
+ }
- for (i=0; i<TERMINATE_TASK_MAX; i++)
+ if (app_context->callback->low_battery != NULL)
{
- if (app_context.terminate_task[i].cb == NULL)
- {
- app_context.terminate_task[i].cb = callback;
- app_context.terminate_task[i].data = data;
- return 0;
- }
+ appcore_set_event_callback(APPCORE_EVENT_LOW_BATTERY, app_appcore_low_battery, app_context);
}
- LOGE("[%s] fail to add terminate-task", __FUNCTION__);
+ if (app_context->callback->device_orientation != NULL)
+ {
+ appcore_set_rotation_cb(app_appcore_rotation_event, app_context);
+ }
- return -1;
+ if (app_context->callback->language_changed != NULL)
+ {
+ appcore_set_event_callback(APPCORE_EVENT_LANG_CHANGE, app_appcore_lang_changed, app_context);
+ }
+
+ if (app_context->callback->region_format_changed != NULL)
+ {
+ appcore_set_event_callback(APPCORE_EVENT_REGION_CHANGE, app_appcore_region_changed, app_context);
+ }
+}
+
+void app_unset_appcore_event_cb(void)
+{
+ appcore_set_event_callback(APPCORE_EVENT_LOW_MEMORY, NULL, NULL);
+ appcore_set_event_callback(APPCORE_EVENT_LOW_BATTERY, NULL, NULL);
+ appcore_unset_rotation_cb();
+ appcore_set_event_callback(APPCORE_EVENT_LANG_CHANGE, NULL, NULL);
+ appcore_set_event_callback(APPCORE_EVENT_REGION_CHANGE, NULL, NULL);
}
diff --git a/src/app_package.c b/src/app_package.c
index 6ff776f..b1b0646 100755
--- a/src/app_package.c
+++ b/src/app_package.c
@@ -38,14 +38,13 @@
#define LOG_TAG "TIZEN_N_APPLICATION"
-int app_get_project_name(const char *package, char **name)
+int app_get_package_app_name(const char *package, char **name)
{
char *name_token = NULL;
if (package == NULL)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, APP_ERROR_INVALID_PARAMETER);
- return APP_ERROR_INVALID_PARAMETER;
+ return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
// com.vendor.name -> name
@@ -53,8 +52,7 @@ int app_get_project_name(const char *package, char **name)
if (name_token == NULL)
{
- LOGE("[%s] INVALID_CONTEXT(0x%08x)", __FUNCTION__, APP_ERROR_INVALID_CONTEXT);
- return APP_ERROR_INVALID_CONTEXT;
+ return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
}
name_token++;
@@ -63,8 +61,7 @@ int app_get_project_name(const char *package, char **name)
if (*name == NULL)
{
- LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, APP_ERROR_OUT_OF_MEMORY);
- return APP_ERROR_OUT_OF_MEMORY;
+ return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
}
return APP_ERROR_NONE;
@@ -76,8 +73,7 @@ int app_get_package(char **package)
if (package == NULL)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, APP_ERROR_INVALID_PARAMETER);
- return APP_ERROR_INVALID_PARAMETER;
+ return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
if (package_buf[0] == '\0')
@@ -87,22 +83,20 @@ int app_get_package(char **package)
if (package_buf[0] == '\0')
{
- LOGE("[%s] INVALID_CONTEXT(0x%08x) : failed to get the package of the application", __FUNCTION__, APP_ERROR_INVALID_CONTEXT);
- return APP_ERROR_INVALID_CONTEXT;
+ return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package");
}
*package = strdup(package_buf);
if (*package == NULL)
{
- LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, APP_ERROR_OUT_OF_MEMORY);
- return APP_ERROR_OUT_OF_MEMORY;
+ return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
}
return APP_ERROR_NONE;
}
-static int app_get_appinfo(const char *package, ail_prop_str_e property, char **value)
+static int app_get_appinfo(const char *package, const char *property, char **value)
{
ail_appinfo_h appinfo;
char *appinfo_value;
@@ -110,15 +104,13 @@ static int app_get_appinfo(const char *package, ail_prop_str_e property, char **
if (ail_package_get_appinfo(package, &appinfo) != 0)
{
- LOGE("[%s] INVALID_CONTEXT(0x%08x) : failed to get app-info", __FUNCTION__, APP_ERROR_INVALID_CONTEXT);
- return APP_ERROR_INVALID_CONTEXT;
+ return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get app-info");
}
if (ail_appinfo_get_str(appinfo, property, &appinfo_value) != 0)
{
ail_package_destroy_appinfo(appinfo);
- LOGE("[%s] INVALID_CONTEXT(0x%08x) : failed to get app-property", __FUNCTION__, APP_ERROR_INVALID_CONTEXT);
- return APP_ERROR_INVALID_CONTEXT;
+ return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get app-property");
}
appinfo_value_dup = strdup(appinfo_value);
@@ -127,8 +119,7 @@ static int app_get_appinfo(const char *package, ail_prop_str_e property, char **
if (appinfo_value_dup == NULL)
{
- LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, APP_ERROR_OUT_OF_MEMORY);
- return APP_ERROR_OUT_OF_MEMORY;
+ return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
}
*value = appinfo_value_dup;
@@ -143,14 +134,12 @@ int app_get_name(char **name)
if(name == NULL)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, APP_ERROR_INVALID_PARAMETER);
- return APP_ERROR_INVALID_PARAMETER;
+ return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
if (app_get_package(&package) != 0)
{
- LOGE("[%s] INVALID_CONTEXT(0x%08x)", __FUNCTION__, APP_ERROR_INVALID_CONTEXT);
- return APP_ERROR_INVALID_CONTEXT;
+ return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package");
}
retval = app_get_appinfo(package, AIL_PROP_NAME_STR, name);
@@ -170,14 +159,12 @@ int app_get_version(char **version)
if(version == NULL)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, APP_ERROR_INVALID_PARAMETER);
- return APP_ERROR_INVALID_PARAMETER;
+ return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
if (app_get_package(&package) != 0)
{
- LOGE("[%s] INVALID_CONTEXT(0x%08x)", __FUNCTION__, APP_ERROR_INVALID_CONTEXT);
- return APP_ERROR_INVALID_CONTEXT;
+ return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package");
}
retval = app_get_appinfo(package, AIL_PROP_VERSION_STR, version);
diff --git a/src/app_resource.c b/src/app_resource.c
index 4a78ee3..6999ccd 100755
--- a/src/app_resource.c
+++ b/src/app_resource.c
@@ -37,132 +37,141 @@
#define LOG_TAG "TIZEN_N_APPLICATION"
-static char* app_get_resource_directory()
+static const char *INSTALLED_PATH = "/opt/apps";
+static const char *RES_DIRECTORY_NAME = "res";
+static const char *DATA_DIRECTORY_NAME = "data";
+
+static char * app_get_root_directory(char *buffer, int size)
{
- static char *resource_directory = NULL;
+ char *package = NULL;
+ char root_directory[TIZEN_PATH_MAX] = {0, };
- if (resource_directory == NULL)
+ if (app_get_package(&package) != APP_ERROR_NONE)
{
- char *resource_directory_tmp;
- char *package = NULL;
-
- if (app_get_package(&package) != APP_ERROR_NONE)
- {
- LOGE("[%s] INVALID_CONTEXT(0x%08x)", __FUNCTION__, APP_ERROR_INVALID_CONTEXT);
- return NULL;
- }
-
- resource_directory_tmp = calloc(1, sizeof(char) * TIZEN_PATH_MAX);
-
- if (resource_directory_tmp == NULL)
- {
- LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, APP_ERROR_OUT_OF_MEMORY);
- return NULL;
- }
-
- snprintf(resource_directory_tmp, TIZEN_PATH_MAX, PATH_FMT_RES_DIR, package);
-
- if (package != NULL)
- {
- free(package);
- }
-
- resource_directory = resource_directory_tmp;
+ app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package");
+ return NULL;
}
- return resource_directory;
-}
+ snprintf(root_directory, sizeof(root_directory), "%s/%s", INSTALLED_PATH, package);
-char* app_get_resource(const char *resource, char *buffer, int size)
-{
- char *resource_directory;
- int abs_path_size;
+ free(package);
- if (resource == NULL)
+ if (size < strlen(root_directory)+1)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid resource", __FUNCTION__, APP_ERROR_INVALID_PARAMETER);
+ app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "the buffer is not big enough");
return NULL;
}
- if (buffer == NULL || size <= 0)
- {
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid buffer", __FUNCTION__, APP_ERROR_INVALID_PARAMETER);
- return NULL;
- }
+ snprintf(buffer, size, "%s", root_directory);
- resource_directory = app_get_resource_directory();
+ return buffer;
+}
+
+static char* app_get_resource_directory(char *buffer, int size)
+{
+ char root_directory[TIZEN_PATH_MAX] = {0, };
+ char resource_directory[TIZEN_PATH_MAX] = {0, };
- if (resource_directory == NULL)
+ if (app_get_root_directory(root_directory, sizeof(root_directory)) == NULL)
{
- LOGE("[%s] INVALID_CONTEXT(0x%08x) : failed to get the path to the resource directory", __FUNCTION__, APP_ERROR_INVALID_CONTEXT);
+ app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the root directory of the application");
return NULL;
}
- abs_path_size = strlen(resource_directory)+ strlen("/") + strlen(resource);
+ snprintf(resource_directory, sizeof(resource_directory), "%s/%s", root_directory, RES_DIRECTORY_NAME);
- if (size <= abs_path_size)
+ if (size < strlen(resource_directory) +1)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : the buffer is not big enough", __FUNCTION__, APP_ERROR_INVALID_PARAMETER);
+ app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "the buffer is not big enough");
return NULL;
}
- snprintf(buffer, size, "%s/%s", resource_directory, resource);
+ snprintf(buffer, size, "%s", resource_directory);
return buffer;
}
char* app_get_data_directory(char *buffer, int size)
{
- static char *abs_path = NULL;
+ static char data_directory[TIZEN_PATH_MAX] = {0, };
+ static int data_directory_length = 0;
- if (buffer == NULL || size <= 0)
+ if (data_directory[0] == '\0')
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid buffer", __FUNCTION__, APP_ERROR_INVALID_PARAMETER);
- return NULL;
- }
+ char *root_directory = NULL;
- if (abs_path == NULL)
- {
- char *package;
- char *abs_path_tmp;
+ root_directory = calloc(1, TIZEN_PATH_MAX);
- if (app_get_package(&package) != 0)
+ if (root_directory == NULL)
{
- LOGE("[%s] INVALID_CONTEXT(0x%08x)", __FUNCTION__, APP_ERROR_INVALID_CONTEXT);
+ app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
return NULL;
}
- abs_path_tmp = calloc(1, sizeof(char) * TIZEN_PATH_MAX);
-
- if (abs_path_tmp == NULL)
+ if (app_get_root_directory(root_directory, TIZEN_PATH_MAX) == NULL)
{
- LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, APP_ERROR_OUT_OF_MEMORY);
+ free(root_directory);
+ app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the path to the root directory");
return NULL;
}
- snprintf(abs_path_tmp, TIZEN_PATH_MAX, PATH_FMT_DATA_DIR, package);
+ snprintf(data_directory, sizeof(data_directory), "%s/%s", root_directory, DATA_DIRECTORY_NAME);
- if (package != NULL)
- {
- free(package);
- }
+ data_directory_length = strlen(data_directory);
- abs_path = abs_path_tmp;
+ free(root_directory);
}
- if (abs_path == NULL)
+ if (size < data_directory_length+1)
{
- LOGE("[%s] INVALID_CONTEXT(0x%08x) : failed to get the absolute path to the data directory", __FUNCTION__, APP_ERROR_INVALID_CONTEXT);
+ app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "the buffer is not big enough");
return NULL;
}
- if (size <= strlen(abs_path))
+ snprintf(buffer, size, "%s", data_directory);
+
+ return buffer;
+}
+
+char* app_get_resource(const char *resource, char *buffer, int size)
+{
+ static char resource_directory[TIZEN_PATH_MAX] = {0, };
+ static int resource_directory_length = 0;
+
+ int resource_path_length = 0;
+
+ if (resource == NULL)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : the buffer is not big enough", __FUNCTION__, APP_ERROR_INVALID_PARAMETER);
+ app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
return NULL;
}
- snprintf(buffer, size, "%s", abs_path);
+ if (buffer == NULL || size <= 0)
+ {
+ app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+ return NULL;
+ }
+
+ if (resource_directory[0] == '\0')
+ {
+ if (app_get_resource_directory(resource_directory, sizeof(resource_directory)) == NULL)
+ {
+ app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the path to the resource directory");
+ return NULL;
+ }
+
+ resource_directory_length = strlen(resource_directory);
+ }
+
+ resource_path_length = resource_directory_length + strlen("/") + strlen(resource);
+
+ if (size < resource_path_length+1)
+ {
+ app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "the buffer is not big enough");
+ return NULL;
+ }
+
+ snprintf(buffer, size, "%s/%s", resource_directory, resource);
return buffer;
}
diff --git a/src/preference.c b/src/preference.c
index 4abbd82..63b779b 100755
--- a/src/preference.c
+++ b/src/preference.c
@@ -81,7 +81,7 @@ static int _initialize(void)
return PREFERENCE_ERROR_IO_ERROR;
}
- app_add_terminate_task(_finish, NULL);
+ app_finalizer_add(_finish, NULL);
return PREFERENCE_ERROR_NONE;
}
diff --git a/src/service.c b/src/service.c
index a0398b1..e53312c 100755
--- a/src/service.c
+++ b/src/service.c
@@ -64,6 +64,50 @@ typedef struct service_request_context_s {
static int service_create_reply(bundle *data, struct service_s **service);
+static const char* service_error_to_string(service_error_e error)
+{
+ switch (error)
+ {
+ case SERVICE_ERROR_NONE:
+ return "NONE";
+
+ case SERVICE_ERROR_INVALID_PARAMETER:
+ return "INVALID_PARAMETER";
+
+ case SERVICE_ERROR_OUT_OF_MEMORY:
+ return "OUT_OF_MEMORY";
+
+ case SERVICE_ERROR_APP_NOT_FOUND:
+ return "APP_NOT_FOUND";
+
+ case SERVICE_ERROR_KEY_NOT_FOUND:
+ return "KEY_NOT_FOUND";
+
+ case SERVICE_ERROR_KEY_REJECTED:
+ return "KEY_REJECTED";
+
+ case SERVICE_ERROR_INVALID_DATA_TYPE:
+ return "INVALID_DATA_TYPE";
+
+ default :
+ return "UNKNOWN";
+ }
+}
+
+int service_error(service_error_e error, const char* function, const char *description)
+{
+ if (description)
+ {
+ LOGE("[%s] %s(0x%08x) : %s", function, service_error_to_string(error), error, description);
+ }
+ else
+ {
+ LOGE("[%s] %s(0x%08x)", function, service_error_to_string(error), error);
+ }
+
+ return error;
+}
+
static int service_validate_extra_data(const char *data)
{
if (data == NULL || data[0] == '\0')
@@ -109,20 +153,20 @@ static void service_request_result_broker(bundle *appsvc_bundle, int appsvc_requ
{
service_request_context_h request_context;
service_h request;
- service_h reply;
+ service_h reply = NULL;
service_result_e result;
void *user_data;
service_reply_cb reply_cb;
if (appsvc_data == NULL)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid service reply", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid service reply");
return;
}
if (service_create_reply(appsvc_bundle, &reply) != 0)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : failed to create service reply", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to create service reply");
return;
}
@@ -158,7 +202,7 @@ static void service_request_result_broker(bundle *appsvc_bundle, int appsvc_requ
}
else
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid callback", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid callback ");
}
}
@@ -175,16 +219,14 @@ int service_create_request(bundle *data, service_h *service)
if (service == NULL)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
service_request = malloc(sizeof(struct service_s));
if (service_request == NULL)
{
- LOGE("[%s] OUT_OF_MEMORY(0x%08x) : failed to create a service handle", __FUNCTION__, SERVICE_ERROR_OUT_OF_MEMORY);
- return SERVICE_ERROR_OUT_OF_MEMORY;
+ return service_error(SERVICE_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a service handle");
}
service_request->type = SERVICE_TYPE_REQUEST;
@@ -201,8 +243,7 @@ int service_create_request(bundle *data, service_h *service)
if (service_request->data == NULL)
{
free(service_request);
- LOGE("[%s] OUT_OF_MEMORY(0x%08x) : failed to create a bundle handle", __FUNCTION__);
- return SERVICE_ERROR_OUT_OF_MEMORY;
+ return service_error(SERVICE_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a bundle");
}
service_request->id = service_new_id();
@@ -220,16 +261,14 @@ int service_create_event(bundle *data, struct service_s **service)
if (data == NULL || service == NULL)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
service_event = malloc(sizeof(struct service_s));
if (service_event == NULL)
{
- LOGE("[%s] OUT_OF_MEMORY(0x%08x) : failed to create a service handle", __FUNCTION__, SERVICE_ERROR_OUT_OF_MEMORY);
- return SERVICE_ERROR_OUT_OF_MEMORY;
+ return service_error(SERVICE_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a service handle");
}
service_event->type = SERVICE_TYPE_EVENT;
@@ -259,16 +298,14 @@ static int service_create_reply(bundle *data, struct service_s **service)
if (data == NULL || service == NULL)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
service_reply = malloc(sizeof(struct service_s));
if (service_reply == NULL)
{
- LOGE("[%s] OUT_OF_MEMORY(0x%08x) : failed to create a service handle", __FUNCTION__, SERVICE_ERROR_OUT_OF_MEMORY);
- return SERVICE_ERROR_OUT_OF_MEMORY;
+ return service_error(SERVICE_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a service handle");
}
service_reply->type = SERVICE_TYPE_REPLY;
@@ -284,8 +321,7 @@ int service_destroy(service_h service)
{
if (service_valiate_service(service))
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
bundle_free(service->data);
@@ -297,16 +333,9 @@ int service_destroy(service_h service)
int service_to_bundle(service_h service, bundle **data)
{
- if (service_valiate_service(service))
+ if (service_valiate_service(service) || data == NULL)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
- }
-
- if (data == NULL)
- {
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid output param", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
*data = service->data;
@@ -318,16 +347,14 @@ int service_set_operation(service_h service, const char *operation)
{
if (service_valiate_service(service))
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
if (operation != NULL)
{
if (appsvc_set_operation(service->data, operation) != 0)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid operation", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid operation");
}
}
else
@@ -342,16 +369,9 @@ int service_get_operation(service_h service, char **operation)
{
const char *operation_value;
- if (service_valiate_service(service))
+ if (service_valiate_service(service) || operation == NULL)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
- }
-
- if (operation == NULL)
- {
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid operation", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
operation_value = appsvc_get_operation(service->data);
@@ -373,16 +393,14 @@ int service_set_uri(service_h service, const char *uri)
{
if (service_valiate_service(service))
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
if (uri != NULL)
{
if (appsvc_set_uri(service->data, uri) != 0)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x : invalid URI)", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid URI");
}
}
else
@@ -398,16 +416,9 @@ int service_get_uri(service_h service, char **uri)
{
const char *uri_value;
- if (service_valiate_service(service))
+ if (service_valiate_service(service) || uri == NULL)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
- }
-
- if (uri == NULL)
- {
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid URI", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
uri_value = appsvc_get_uri(service->data);
@@ -429,16 +440,14 @@ int service_set_mime(service_h service, const char *mime)
{
if (service_valiate_service(service))
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
if (mime != NULL)
{
if (appsvc_set_mime(service->data, mime) != 0)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid MIME type", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid MIME type");
}
}
else
@@ -454,16 +463,9 @@ int service_get_mime(service_h service, char **mime)
{
const char *mime_value;
- if (service_valiate_service(service))
+ if (service_valiate_service(service) || mime == NULL)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
- }
-
- if (mime == NULL)
- {
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid MIME type", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
mime_value = appsvc_get_mime(service->data);
@@ -485,16 +487,14 @@ int service_set_package(service_h service, const char *package)
{
if (service_valiate_service(service))
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
if (package != NULL)
{
if (appsvc_set_pkgname(service->data, package) != 0)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid package", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid package");
}
}
else
@@ -509,16 +509,9 @@ int service_get_package(service_h service, char **package)
{
const char *package_value;
- if (service_valiate_service(service))
- {
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
- }
-
- if (package == NULL)
+ if (service_valiate_service(service) || package == NULL)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid package", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
package_value = appsvc_get_pkgname(service->data);
@@ -539,24 +532,16 @@ int service_clone(service_h *clone, service_h service)
{
service_h service_clone;
- if (service_valiate_service(service))
- {
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
- }
-
- if (clone == NULL)
+ if (service_valiate_service(service) || clone == NULL)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
service_clone = malloc(sizeof(struct service_s));
if (service_clone == NULL)
{
- LOGE("[%s] OUT_OF_MEMORY(0x%08x) : failed to create a service handle", __FUNCTION__, SERVICE_ERROR_OUT_OF_MEMORY);
- return SERVICE_ERROR_OUT_OF_MEMORY;
+ return service_error(SERVICE_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a service handle");
}
service_clone->id = service_new_id();
@@ -579,10 +564,11 @@ int service_send_launch_request(service_h service, service_reply_cb callback, vo
bool implicit_default_operation = false;
int launch_pid;
+ service_request_context_h request_context = NULL;
+
if (service_valiate_service(service))
{
- LOGE("[%s] INVALID_PARAMETER : invalid handle", __FUNCTION__);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
operation = appsvc_get_operation(service->data);
@@ -600,27 +586,12 @@ int service_send_launch_request(service_h service, service_reply_cb callback, vo
// operation : default
if (!strcmp(operation, SERVICE_OPERATION_DEFAULT))
{
- if (package == NULL || package[0] == '\0')
+ if (package == NULL)
{
- LOGE("[%s] APP_NOT_FOUND(0x%08x) : package must be specified if the operation is default", __FUNCTION__, SERVICE_ERROR_APP_NOT_FOUND);
- return SERVICE_ERROR_APP_NOT_FOUND;
+ return service_error(SERVICE_ERROR_APP_NOT_FOUND, __FUNCTION__, "package must be specified if the operation is default value");
}
}
- if (package != NULL && package[0] != '\0')
- {
- if (aul_app_is_running(package))
- {
- if (aul_open_app(package) <= 0)
- {
- LOGE("[%s] APP_NOT_FOUND(0x%08x) : resume the application(%s)", __FUNCTION__, SERVICE_ERROR_APP_NOT_FOUND, package);
- return SERVICE_ERROR_APP_NOT_FOUND;
- }
- }
- }
-
- service_request_context_h request_context = NULL;
-
if (callback != NULL)
{
request_context = calloc(1, sizeof(struct service_request_context_s));
@@ -628,8 +599,7 @@ int service_send_launch_request(service_h service, service_reply_cb callback, vo
if (request_context == NULL)
{
- LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, SERVICE_ERROR_OUT_OF_MEMORY);
- return SERVICE_ERROR_OUT_OF_MEMORY;
+ return service_error(SERVICE_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
}
request_context->reply_cb = callback;
@@ -651,9 +621,7 @@ int service_send_launch_request(service_h service, service_reply_cb callback, vo
if (launch_pid < 0)
{
- LOGE("[%s] APP_NOT_FOUND(0x%08x) : operation(%s) package(%s) uri(%s) mime(%s)",
- __FUNCTION__, SERVICE_ERROR_APP_NOT_FOUND, operation, package, uri, mime);
- return SERVICE_ERROR_APP_NOT_FOUND;
+ return service_error(SERVICE_ERROR_APP_NOT_FOUND, __FUNCTION__, NULL);
}
return SERVICE_ERROR_NONE;
@@ -661,32 +629,35 @@ int service_send_launch_request(service_h service, service_reply_cb callback, vo
static bool service_copy_reply_data_cb(service_h service, const char *key, void *user_data)
{
- bundle *reply_data;
- bool array = false;
- char *value;
- const char **value_array;
- int value_array_length;
+ bundle *reply_data = user_data;
+ char *value = NULL;
+ char **value_array = NULL;
+ int value_array_length = 0;
+ int value_array_index = 0;
- if (user_data == NULL)
+ if (reply_data == NULL)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
return false;
}
- reply_data = user_data;
-
- if (!service_is_extra_data_array(service, key, &array))
+ if (appsvc_data_is_array(service->data, key))
{
- if (array == true)
- {
- service_get_extra_data_array(service, key, (char***)&value_array, &value_array_length);
- appsvc_add_data_array(reply_data, key, value_array, value_array_length);
- }
- else
+ service_get_extra_data_array(service, key, &value_array, &value_array_length);
+ appsvc_add_data_array(reply_data, key, (const char**)value_array, value_array_length);
+
+ for (value_array_index=0; value_array_index < value_array_length; value_array_index++)
{
- service_get_extra_data(service, key, &value);
- appsvc_add_data(reply_data, key, value);
+ free(value_array[value_array_index]);
}
+
+ free(value_array);
+ }
+ else
+ {
+ service_get_extra_data(service, key, &value);
+ appsvc_add_data(reply_data, key, value);
+ free(value);
}
return true;
@@ -697,43 +668,35 @@ int service_reply_to_launch_request(service_h reply, service_h request, service_
bundle *reply_data;
int appsvc_result;
- if (service_valiate_service(reply))
- {
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid reply handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
- }
-
- if (service_valiate_service(request))
+ if (service_valiate_service(reply) || service_valiate_service(request))
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid request handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
if (appsvc_create_result_bundle(request->data, &reply_data) != 0)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : failed to create result bundle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to create a result bundle");
}
service_foreach_extra_data(reply, service_copy_reply_data_cb, reply_data);
switch (result)
{
- case SERVICE_RESULT_SUCCEEDED:
- appsvc_result = APPSVC_RES_OK;
- break;
+ case SERVICE_RESULT_SUCCEEDED:
+ appsvc_result = APPSVC_RES_OK;
+ break;
- case SERVICE_RESULT_FAILED:
- appsvc_result = APPSVC_RES_NOT_OK;
- break;
+ case SERVICE_RESULT_FAILED:
+ appsvc_result = APPSVC_RES_NOT_OK;
+ break;
- case SERVICE_RESULT_CANCELED:
- appsvc_result = APPSVC_RES_CANCEL;
- break;
+ case SERVICE_RESULT_CANCELED:
+ appsvc_result = APPSVC_RES_CANCEL;
+ break;
- default:
- appsvc_result = APPSVC_RES_CANCEL;
- break;
+ default:
+ appsvc_result = APPSVC_RES_CANCEL;
+ break;
}
appsvc_send_result(reply_data, appsvc_result);
@@ -744,28 +707,14 @@ int service_reply_to_launch_request(service_h reply, service_h request, service_
int service_add_extra_data(service_h service, const char *key, const char *value)
{
- if (service_valiate_service(service))
+ if (service_valiate_service(service) || service_validate_extra_data(key) || service_validate_extra_data(value))
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
- }
-
- if (service_validate_extra_data(key))
- {
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
if (service_validate_internal_key(key))
{
- LOGE("[%s] KEY_REJECTED(0x%08x) : key(%s) rejected", __FUNCTION__, SERVICE_ERROR_KEY_REJECTED, key);
- return SERVICE_ERROR_KEY_REJECTED;
- }
-
- if (service_validate_extra_data(value))
- {
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid value", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use");
}
if (appsvc_get_data(service->data, key) != NULL)
@@ -776,9 +725,7 @@ int service_add_extra_data(service_h service, const char *key, const char *value
if (appsvc_add_data(service->data, key, value) != 0)
{
- LOGE("[%s] KEY_REJECTED(0x%08x) : key(%s)/value(%s) is rejected from appsvc",
- __FUNCTION__, SERVICE_ERROR_KEY_REJECTED, key, value);
- return SERVICE_ERROR_KEY_REJECTED;
+ return service_error(SERVICE_ERROR_KEY_REJECTED, __FUNCTION__, "failed to add data to the appsvc handle");
}
return SERVICE_ERROR_NONE;
@@ -787,30 +734,21 @@ int service_add_extra_data(service_h service, const char *key, const char *value
int service_add_extra_data_array(service_h service, const char *key, const char* value[], int length)
{
- if (service_valiate_service(service))
+ if (service_valiate_service(service) || service_validate_extra_data(key))
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
- if (service_validate_extra_data(key))
+ if (value == NULL || length <= 0)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
- }
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid array");
+ }
if (service_validate_internal_key(key))
{
- LOGE("[%s] KEY_REJECTED(0x%08x) : key(%s) rejected", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER, key);
- return SERVICE_ERROR_KEY_REJECTED;
+ return service_error(SERVICE_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use");
}
- if (value == NULL || length <= 0)
- {
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid array", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
- }
-
if (appsvc_get_data_array(service->data, key, NULL) != NULL)
{
// overwrite any existing value
@@ -819,8 +757,7 @@ int service_add_extra_data_array(service_h service, const char *key, const char*
if (appsvc_add_data_array(service->data, key, value, length) != 0)
{
- LOGE("[%s] KEY_REJECTED(0x%08x) : key(%s) is rejected from appsvc", __FUNCTION__, SERVICE_ERROR_KEY_REJECTED, key);
- return SERVICE_ERROR_KEY_REJECTED;
+ return service_error(SERVICE_ERROR_KEY_REJECTED, __FUNCTION__, "failed to add array data to the appsvc handle");
}
return SERVICE_ERROR_NONE;
@@ -829,28 +766,19 @@ int service_add_extra_data_array(service_h service, const char *key, const char*
int service_remove_extra_data(service_h service, const char *key)
{
- if (service_valiate_service(service))
- {
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
- }
-
- if (service_validate_extra_data(key))
+ if (service_valiate_service(service) || service_validate_extra_data(key))
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
if (service_validate_internal_key(key))
{
- LOGE("[%s] KEY_REJECTED(0x%08x) : key(%s) rejected", __FUNCTION__, SERVICE_ERROR_KEY_REJECTED, key);
- return SERVICE_ERROR_KEY_REJECTED;
+ return service_error(SERVICE_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use");
}
if (bundle_del(service->data, key))
{
- LOGE("[%s] KEY_NOT_FOUND(0x%08x) : key(%s)", __FUNCTION__, SERVICE_ERROR_KEY_NOT_FOUND, key);
- return SERVICE_ERROR_KEY_NOT_FOUND;
+ return service_error(SERVICE_ERROR_KEY_NOT_FOUND, __FUNCTION__, NULL);
}
return SERVICE_ERROR_NONE;
@@ -861,28 +789,15 @@ int service_get_extra_data(service_h service, const char *key, char **value)
{
const char *data_value;
- if (service_valiate_service(service))
+ if (service_valiate_service(service) || service_validate_extra_data(key) || value == NULL)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
- if (service_validate_extra_data(key))
- {
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
- }
if (service_validate_internal_key(key))
{
- LOGE("[%s] KEY_REJECTED(0x%08x) : key(%s) rejected", __FUNCTION__, SERVICE_ERROR_KEY_REJECTED, key);
- return SERVICE_ERROR_KEY_REJECTED;
- }
-
- if (value == NULL)
- {
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid value", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use");
}
data_value = appsvc_get_data(service->data, key);
@@ -891,13 +806,11 @@ int service_get_extra_data(service_h service, const char *key, char **value)
{
if (errno == ENOTSUP)
{
- LOGE("[%s] INVALID_DATA_TYPE(0x%08x) : key(%s)", __FUNCTION__, SERVICE_ERROR_INVALID_DATA_TYPE, key);
- return SERVICE_ERROR_INVALID_DATA_TYPE;
+ return service_error(SERVICE_ERROR_INVALID_DATA_TYPE, __FUNCTION__, NULL);
}
else
{
- LOGE("[%s] KEY_NOT_FOUND(0x%08x) : key(%s)", __FUNCTION__, SERVICE_ERROR_INVALID_DATA_TYPE, key);
- return SERVICE_ERROR_KEY_NOT_FOUND;
+ return service_error(SERVICE_ERROR_KEY_NOT_FOUND, __FUNCTION__, NULL);
}
}
@@ -914,28 +827,19 @@ int service_get_extra_data_array(service_h service, const char *key, char ***val
char **array_data_clone;
int i;
- if (service_valiate_service(service))
+ if (service_valiate_service(service) || service_validate_extra_data(key))
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
- if (service_validate_extra_data(key))
+ if (value == NULL || length == 0)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
if (service_validate_internal_key(key))
{
- LOGE("[%s] KEY_REJECTED(0x%08x) : key(%s) rejected", __FUNCTION__, SERVICE_ERROR_KEY_REJECTED, key);
- return SERVICE_ERROR_KEY_REJECTED;
- }
-
- if (value == NULL || length == 0)
- {
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid value", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use");
}
array_data = appsvc_get_data_array(service->data, key, &array_data_length);
@@ -944,13 +848,11 @@ int service_get_extra_data_array(service_h service, const char *key, char ***val
{
if (errno == ENOTSUP)
{
- LOGE("[%s] INVALID_DATA_TYPE(0x%08x) : key(%s)", __FUNCTION__, SERVICE_ERROR_INVALID_DATA_TYPE, key);
- return SERVICE_ERROR_INVALID_DATA_TYPE;
+ return service_error(SERVICE_ERROR_INVALID_DATA_TYPE, __FUNCTION__, NULL);
}
else
{
- LOGE("[%s] KEY_NOT_FOUND(0x%08x) : key(%s)", __FUNCTION__, SERVICE_ERROR_KEY_NOT_FOUND, key);
- return SERVICE_ERROR_KEY_NOT_FOUND;
+ return service_error(SERVICE_ERROR_KEY_NOT_FOUND, __FUNCTION__, NULL);
}
}
@@ -958,8 +860,7 @@ int service_get_extra_data_array(service_h service, const char *key, char ***val
if (array_data_clone == NULL)
{
- LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __FUNCTION__, SERVICE_ERROR_OUT_OF_MEMORY);
- return SERVICE_ERROR_OUT_OF_MEMORY;
+ return service_error(SERVICE_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
}
for (i=0; i<array_data_length; i++)
@@ -979,38 +880,23 @@ int service_get_extra_data_array(service_h service, const char *key, char ***val
int service_is_extra_data_array(service_h service, const char *key, bool *array)
{
- if (service_valiate_service(service))
- {
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
- }
-
- if (service_validate_extra_data(key))
+ if (service_valiate_service(service) || service_validate_extra_data(key) || array == NULL)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
- if (array == NULL)
+ if (service_validate_internal_key(key))
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid output param", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
- }
+ return service_error(SERVICE_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use");
+ }
- if (!service_validate_internal_key(key))
+ if (!appsvc_data_is_array(service->data, key))
{
- if (!appsvc_data_is_array(service->data, key))
- {
- *array = false;
- }
- else
- {
- *array = true;
- }
+ *array = false;
}
else
{
- *array = false;
+ *array = true;
}
return SERVICE_ERROR_NONE;
@@ -1069,16 +955,9 @@ int service_foreach_extra_data(service_h service, service_extra_data_cb callback
.foreach_break = false
};
- if (service_valiate_service(service))
+ if (service_valiate_service(service) || callback == NULL)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
- }
-
- if (callback == NULL)
- {
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid callback", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
bundle_foreach(service->data, service_cb_broker_bundle_iterator, &foreach_context);
@@ -1100,7 +979,7 @@ int service_cb_broker_foreach_app_matched(const char *package, void *data)
if (package == NULL || data == NULL)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
+ service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
return -1;
}
@@ -1134,16 +1013,9 @@ int service_foreach_app_matched(service_h service, service_app_matched_cb callba
.foreach_break = false
};
- if (service_valiate_service(service))
- {
- LOGE( "[%s] INVALID_PARAMETER(0x%08x) : invalid handle", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
- }
-
- if (callback == NULL)
+ if (service_valiate_service(service) || callback == NULL)
{
- LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid callback", __FUNCTION__, SERVICE_ERROR_INVALID_PARAMETER);
- return SERVICE_ERROR_INVALID_PARAMETER;
+ return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
appsvc_get_list(service->data, service_cb_broker_foreach_app_matched, &foreach_context);