ADD_CUSTOM_TARGET (distclean @echo cleaning for source distribution)
ADD_CUSTOM_COMMAND(
- DEPENDS clean
+ DEPENDS clean
COMMENT "distribution clean"
COMMAND find
- ARGS .
+ ARGS .
-not -name config.cmake -and \(
-name tester.c -or
-name Testing -or
)
ENDIF(UNIX)
-
#include <unistd.h>
#include <time.h>
+#include <bundle.h>
#include <aul.h>
#include <alarm.h>
#include <dlog.h>
alarm_foreach_item_cb_context* foreach_cb_context = NULL;
if (user_data == NULL)
- {
return 0;
- }
foreach_cb_context = (alarm_foreach_item_cb_context*)user_data;
- if (foreach_cb_context != NULL && *(foreach_cb_context->foreach_break) == false)
- {
+ if (foreach_cb_context != NULL && *(foreach_cb_context->foreach_break) == false) {
if (foreach_cb_context->cb(alarm_id, foreach_cb_context->user_data) == false)
- {
*(foreach_cb_context->foreach_break) = true;
- }
}
return 0;
static int convert_error_code_to_alarm(const char* function, alarm_error_t alarm_error)
{
- switch(alarm_error)
- {
+ switch (alarm_error) {
case ERR_ALARM_INVALID_PARAM:
case ERR_ALARM_INVALID_REPEAT:
LOGE("[%s] INVALID_PARAMETER(0x%08x)", function, ALARM_ERROR_INVALID_PARAMETER);
return ALARM_ERROR_INVALID_PARAMETER;
break;
-
case ERR_ALARM_INVALID_ID:
LOGE("[%s] INVALID_PARAMETER(0x%08x)", function, ALARM_ERROR_INVALID_PARAMETER);
return ALARM_ERROR_INVALID_PARAMETER;
break;
-
case ERR_ALARM_INVALID_TIME:
LOGE("[%s] INVALID_TIME(0x%08x)", function, ALARM_ERROR_INVALID_TIME);
return ALARM_ERROR_INVALID_TIME;
break;
-
case ERR_ALARM_INVALID_DATE:
LOGE("[%s] INVALID_DATE(0x%08x)", function, ALARM_ERROR_INVALID_DATE);
return ALARM_ERROR_INVALID_DATE;
break;
-
case ERR_ALARM_NO_SERVICE_NAME:
LOGE("[%s] INVALID_PARAMETER(0x%08x)", function, ALARM_ERROR_INVALID_PARAMETER);
return ALARM_ERROR_INVALID_PARAMETER;
break;
-
case ERR_ALARM_SYSTEM_FAIL:
LOGE("[%s] CONNECTION_FAIL(0x%08x)", function, ALARM_ERROR_CONNECTION_FAIL);
return ALARM_ERROR_CONNECTION_FAIL;
break;
-
case ERR_ALARM_NO_PERMISSION:
LOGE("[%s] PERMISSION_DENIED(0x%08x)", function, ALARM_ERROR_PERMISSION_DENIED);
return ALARM_ERROR_PERMISSION_DENIED;
break;
-
+ case ERR_ALARM_NOT_PERMITTED_APP:
+ LOGE("[%s] NOT_PERMITTED_APP(0x%08x)", function, ALARM_ERROR_NOT_PERMITTED_APP);
+ return ALARM_ERROR_NOT_PERMITTED_APP;
+ break;
case ALARMMGR_RESULT_SUCCESS:
return ALARM_ERROR_NONE;
break;
-
default:
return ALARM_ERROR_INVALID_PARAMETER;
}
-
-}
-
-static int _remove_alarm_cb(alarm_id_t alarm_id, void* user_param)
-{
- return alarmmgr_remove_alarm(alarm_id);
}
int alarm_get_scheduled_date(int alarm_id, struct tm* date)
alarm_error_t result;
time_t due_time = 0;
- if (date == NULL)
- {
+ if (date == NULL) {
LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
return ALARM_ERROR_INVALID_PARAMETER;
- }
+ }
result = alarmmgr_get_next_duetime(alarm_id, &due_time);
if (result != ALARMMGR_RESULT_SUCCESS)
- {
return convert_error_code_to_alarm(__FUNCTION__, result);
- }
localtime_r(&due_time, date);
return ALARM_ERROR_NONE;
-
}
int alarm_get_scheduled_period(int alarm_id, int* period)
alarm_repeat_mode_t mode;
int value;
- if (period == NULL)
- {
+ if (period == NULL) {
LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
return ALARM_ERROR_INVALID_PARAMETER;
}
entry = alarmmgr_create_alarm();
result = alarmmgr_get_info(alarm_id, entry);
- if (result != ALARMMGR_RESULT_SUCCESS)
- {
+ if (result != ALARMMGR_RESULT_SUCCESS) {
if (entry != NULL)
- {
alarmmgr_free_alarm(entry);
- }
+
return convert_error_code_to_alarm(__FUNCTION__, result);
}
result = alarmmgr_get_repeat_mode(entry, &mode, &value);
- if (result != ALARMMGR_RESULT_SUCCESS)
- {
+ if (result != ALARMMGR_RESULT_SUCCESS) {
if (entry != NULL)
- {
alarmmgr_free_alarm(entry);
- }
+
return convert_error_code_to_alarm(__FUNCTION__, result);
}
result = alarmmgr_free_alarm(entry);
- if(result != ALARMMGR_RESULT_SUCCESS)
- {
+ if (result != ALARMMGR_RESULT_SUCCESS) {
if (entry != NULL)
- {
alarmmgr_free_alarm(entry);
- }
+
return convert_error_code_to_alarm(__FUNCTION__, result);
}
(*period) = value;
return ALARM_ERROR_NONE;
-
}
int alarm_schedule_after_delay(app_control_h app_control, int delay, int period, int *alarm_id)
bundle *bundle_data;
int result = 0;
- if (app_control == NULL)
- {
+ if (app_control == NULL) {
LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
return ALARM_ERROR_INVALID_PARAMETER;
}
- if (app_control_to_bundle(app_control, &bundle_data) != APP_CONTROL_ERROR_NONE)
- {
+ if (app_control_to_bundle(app_control, &bundle_data) != APP_CONTROL_ERROR_NONE) {
LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
return ALARM_ERROR_INVALID_PARAMETER;
}
- result = alarmmgr_add_alarm_appsvc(ALARM_TYPE_DEFAULT, delay, period, bundle_data, alarm_id);
+ result = alarmmgr_add_alarm_appsvc(ALARM_TYPE_DEFAULT | ALARM_TYPE_INEXACT, delay, period, bundle_data, alarm_id);
return convert_error_code_to_alarm(__FUNCTION__, result);
}
bundle *bundle_data;
int result;
- if (app_control == NULL || date == NULL)
- {
+ if (app_control == NULL || date == NULL) {
LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
return ALARM_ERROR_INVALID_PARAMETER;
}
- if (app_control_to_bundle(app_control, &bundle_data) != APP_CONTROL_ERROR_NONE)
- {
+ if (app_control_to_bundle(app_control, &bundle_data) != APP_CONTROL_ERROR_NONE) {
LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
return ALARM_ERROR_INVALID_PARAMETER;
}
alarm_info = alarmmgr_create_alarm();
internal_time.year = date->tm_year + 1900;
- internal_time.month = date->tm_mon +1;
+ internal_time.month = date->tm_mon + 1;
internal_time.day = date->tm_mday;
internal_time.hour = date->tm_hour;
internal_time.min = date->tm_min;
internal_time.sec = date->tm_sec;
- result = alarmmgr_set_time(alarm_info,internal_time);
+ result = alarmmgr_set_time(alarm_info, internal_time);
- if (result < 0)
- {
+ if (result < 0) {
alarmmgr_free_alarm(alarm_info);
return convert_error_code_to_alarm(__FUNCTION__, result);
}
if (period_in_second > 0)
- {
result = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_REPEAT, period_in_second);
- }
else
- {
result = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_ONCE, period_in_second);
- }
- if (result < 0)
- {
+ if (result < 0) {
alarmmgr_free_alarm(alarm_info);
return convert_error_code_to_alarm(__FUNCTION__, result);
}
result = alarmmgr_set_type(alarm_info, ALARM_TYPE_DEFAULT);
-
- if (result < 0)
- {
+ if (result < 0) {
alarmmgr_free_alarm(alarm_info);
return convert_error_code_to_alarm(__FUNCTION__, result);
}
result = alarmmgr_add_alarm_appsvc_with_localtime(alarm_info, bundle_data, alarm_id);
-
- if (result < 0)
- {
+ if (result < 0) {
alarmmgr_free_alarm(alarm_info);
return convert_error_code_to_alarm(__FUNCTION__, result);
}
alarmmgr_free_alarm(alarm_info);
return ALARM_ERROR_NONE;
}
+
int alarm_schedule_once_after_delay(app_control_h app_control, int delay, int *alarm_id)
{
bundle *bundle_data;
}
result = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_ONCE, 0);
-
if (result < 0) {
alarmmgr_free_alarm(alarm_info);
return convert_error_code_to_alarm(__FUNCTION__, result);
}
result = alarmmgr_set_type(alarm_info, ALARM_TYPE_DEFAULT);
-
if (result < 0) {
alarmmgr_free_alarm(alarm_info);
return convert_error_code_to_alarm(__FUNCTION__, result);
}
result = alarmmgr_add_alarm_appsvc_with_localtime(alarm_info, bundle_data, alarm_id);
-
if (result < 0) {
alarmmgr_free_alarm(alarm_info);
return convert_error_code_to_alarm(__FUNCTION__, result);
{
int result;
- result = alarmmgr_enum_alarm_ids( _remove_alarm_cb, NULL);
+ result = alarmmgr_remove_all();
return convert_error_code_to_alarm(__FUNCTION__, result);
}
int result;
bool foreach_break = false;
- if (callback == NULL)
- {
+ if (callback == NULL) {
LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
return ALARM_ERROR_INVALID_PARAMETER;
}
- //alarm_registered_alarm_cb_broker
+ /* alarm_registered_alarm_cb_broker */
alarm_foreach_item_cb_context foreach_cb_context = {
.cb = callback,
.user_data = user_data,
{
time_t now;
- if (date == NULL)
- {
+ if (date == NULL) {
LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
return ALARM_ERROR_INVALID_PARAMETER;
}
return ALARM_ERROR_NONE;
}
-
-int alarm_schedule_with_recurrence_week_flag(app_control_h app_control, struct tm *date, int week_flag,int *alarm_id)
+int alarm_schedule_with_recurrence_week_flag(app_control_h app_control, struct tm *date, int week_flag, int *alarm_id)
{
alarm_date_t internal_time;
alarm_entry_t* alarm_info;
bundle *bundle_data;
int result;
- if (app_control == NULL || date == NULL)
- {
+ if (app_control == NULL || date == NULL) {
LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
return ALARM_ERROR_INVALID_PARAMETER;
}
- if (app_control_to_bundle(app_control, &bundle_data) != APP_CONTROL_ERROR_NONE)
- {
+ if (app_control_to_bundle(app_control, &bundle_data) != APP_CONTROL_ERROR_NONE) {
LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
return ALARM_ERROR_INVALID_PARAMETER;
}
alarm_info = alarmmgr_create_alarm();
internal_time.year = date->tm_year + 1900;
- internal_time.month = date->tm_mon +1;
+ internal_time.month = date->tm_mon + 1;
internal_time.day = date->tm_mday;
internal_time.hour = date->tm_hour;
internal_time.min = date->tm_min;
internal_time.sec = date->tm_sec;
- result = alarmmgr_set_time(alarm_info,internal_time);
-
- if (result < 0)
- {
+ result = alarmmgr_set_time(alarm_info, internal_time);
+ if (result < 0) {
alarmmgr_free_alarm(alarm_info);
return convert_error_code_to_alarm(__FUNCTION__, result);
}
if (week_flag > 0)
- {
result = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_WEEKLY, week_flag);
- }
- if (result < 0)
- {
+ if (result < 0) {
alarmmgr_free_alarm(alarm_info);
return convert_error_code_to_alarm(__FUNCTION__, result);
}
result = alarmmgr_set_type(alarm_info, ALARM_TYPE_DEFAULT);
-
- if (result < 0)
- {
+ if (result < 0) {
alarmmgr_free_alarm(alarm_info);
return convert_error_code_to_alarm(__FUNCTION__, result);
}
result = alarmmgr_add_alarm_appsvc_with_localtime(alarm_info, bundle_data, alarm_id);
-
alarmmgr_free_alarm(alarm_info);
+
return convert_error_code_to_alarm(__FUNCTION__, result);
}
alarm_repeat_mode_t mode;
int value;
- if(week_flag == NULL)
- {
+ if (week_flag == NULL) {
LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER);
return ALARM_ERROR_INVALID_PARAMETER;
}
entry = alarmmgr_create_alarm();
result = alarmmgr_get_info(alarm_id, entry);
- if(result != ALARMMGR_RESULT_SUCCESS)
- {
+ if (result != ALARMMGR_RESULT_SUCCESS) {
if (entry != NULL)
- {
alarmmgr_free_alarm(entry);
- }
+
return convert_error_code_to_alarm(__FUNCTION__, result);
}
result = alarmmgr_get_repeat_mode(entry, &mode, &value);
- if(mode != ALARM_REPEAT_MODE_WEEKLY)
- {
+ if (mode != ALARM_REPEAT_MODE_WEEKLY) {
if (entry != NULL)
- {
alarmmgr_free_alarm(entry);
- }
+
return ALARM_ERROR_INVALID_PARAMETER;
}
- if(result != ALARMMGR_RESULT_SUCCESS)
- {
+ if (result != ALARMMGR_RESULT_SUCCESS) {
if (entry != NULL)
- {
alarmmgr_free_alarm(entry);
- }
+
return convert_error_code_to_alarm(__FUNCTION__, result);
}
result = alarmmgr_free_alarm(entry);
- if(result != ALARMMGR_RESULT_SUCCESS)
- {
+ if (result != ALARMMGR_RESULT_SUCCESS) {
if (entry != NULL)
- {
alarmmgr_free_alarm(entry);
- }
+
return convert_error_code_to_alarm(__FUNCTION__, result);
}
int alarm_get_app_control(int alarm_id, app_control_h *app_control)
{
- bundle *b = NULL;
- int error_code = 0;
+ bundle *b = NULL;
+ int error_code = 0;
- b = alarmmgr_get_alarm_appsvc_info(alarm_id, &error_code);
-
- if(error_code != ALARMMGR_RESULT_SUCCESS)
- {
- return convert_error_code_to_alarm(__FUNCTION__, error_code);
- }
-
- if(b == NULL)
- {
- return ALARM_ERROR_INVALID_PARAMETER;
- }
+ if (app_control == NULL)
+ return ALARM_ERROR_INVALID_PARAMETER;
- error_code = app_control_create_request(b, app_control);
+ b = alarmmgr_get_alarm_appsvc_info(alarm_id, &error_code);
+ if (error_code != ALARMMGR_RESULT_SUCCESS)
+ return convert_error_code_to_alarm(__FUNCTION__, error_code);
- if(error_code != APP_CONTROL_ERROR_NONE)
- {
- return ALARM_ERROR_OUT_OF_MEMORY;
- }
+ if (b == NULL)
+ return ALARM_ERROR_INVALID_PARAMETER;
- bundle_free(b);
+ error_code = app_control_create_request(b, app_control);
+ if (error_code != APP_CONTROL_ERROR_NONE) {
+ bundle_free(b);
+ return ALARM_ERROR_OUT_OF_MEMORY;
+ }
- return ALARM_ERROR_NONE;
+ bundle_free(b);
+ return ALARM_ERROR_NONE;
}
* 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.
+ * limitations under the License.
*/
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libintl.h>
-
#include <dlog.h>
-
#include <app_internal.h>
#ifdef LOG_TAG
static const char* app_error_to_string(app_error_e error)
{
- switch (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 :
+ 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);
- }
+ 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);
- }
+ LOGE("[%s] %s(0x%08x)", function, app_error_to_string(error), error);
return error;
}
{
app_device_orientation_e dev_orientation;
- switch (rm)
- {
+ switch (rm) {
case APPCORE_RM_PORTRAIT_NORMAL:
dev_orientation = APP_DEVICE_ORIENTATION_0;
break;
-
case APPCORE_RM_PORTRAIT_REVERSE:
dev_orientation = APP_DEVICE_ORIENTATION_180;
break;
-
case APPCORE_RM_LANDSCAPE_NORMAL:
dev_orientation = APP_DEVICE_ORIENTATION_270;
break;
-
case APPCORE_RM_LANDSCAPE_REVERSE:
dev_orientation = APP_DEVICE_ORIENTATION_90;
break;
-
default:
dev_orientation = APP_DEVICE_ORIENTATION_0;
break;
return APP_ERROR_NONE;
}
+int app_event_get_suspended_state(app_event_info_h event_info, app_suspended_state_e *state)
+{
+ if (event_info == NULL || state == NULL)
+ return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
+
+ if (event_info->type != APP_EVENT_SUSPENDED_STATE_CHANGED)
+ return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "event type mismatching");
+
+ if (*(enum appcore_suspended_state *)(event_info->value) == APPCORE_SUSPENDED_STATE_WILL_ENTER_SUSPEND)
+ *state = APP_SUSPENDED_STATE_WILL_ENTER;
+ else if (*(enum appcore_suspended_state *)(event_info->value) == APPCORE_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND)
+ *state = APP_SUSPENDED_STATE_DID_EXIT;
+
+ return APP_ERROR_NONE;
+}
* 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.
+ * limitations under the License.
*/
#include <stdio.h>
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;
{
app_finalizer_h finalizer_node = &finalizer_head;
- while (finalizer_node->next)
- {
- if (finalizer_node->next->callback == callback)
- {
+ 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);
}
finalizer_node = finalizer_node->next;
- }
+ }
return APP_ERROR_INVALID_PARAMETER;
}
app_finalizer_h finalizer_executed;
app_finalizer_cb finalizer_cb = NULL;
- if(finalizer_node)
+ if (finalizer_node)
finalizer_node = finalizer_node->next;
- while (finalizer_node)
- {
+ while (finalizer_node) {
finalizer_cb = finalizer_node->callback;
finalizer_cb(finalizer_node->data);
finalizer_head.next = NULL;
}
-
if (appid == NULL)
return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- // com.vendor.name -> name
+ /* com.vendor.name -> name */
name_token = strrchr(appid, '.');
-
if (name_token == NULL)
return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
name_token++;
*name = strdup(name_token);
-
if (*name == NULL)
return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the application ID");
*id = strdup(id_buf);
-
if (*id == NULL)
return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
char *label = NULL;
pkgmgrinfo_appinfo_h appinfo = NULL;
- if(name == NULL)
+ if (name == NULL)
return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
if (app_get_id(&appid) != 0)
pkgmgrinfo_pkginfo_h pkginfo = NULL;
pkgmgrinfo_appinfo_h appinfo = NULL;
- if(version == NULL)
+ if (version == NULL)
return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
if (app_get_id(&appid) != 0)
#include <errno.h>
#include <bundle.h>
+#include <bundle_internal.h>
#include <aul.h>
#include <appsvc.h>
#include <aul_svc.h>
static const char* app_control_error_to_string(app_control_error_e error)
{
- switch (error)
- {
+ switch (error) {
case APP_CONTROL_ERROR_NONE:
return "NONE";
-
case APP_CONTROL_ERROR_INVALID_PARAMETER:
return "INVALID_PARAMETER";
-
case APP_CONTROL_ERROR_OUT_OF_MEMORY:
return "OUT_OF_MEMORY";
-
case APP_CONTROL_ERROR_APP_NOT_FOUND:
return "APP_NOT_FOUND";
-
case APP_CONTROL_ERROR_KEY_NOT_FOUND:
return "KEY_NOT_FOUND";
-
case APP_CONTROL_ERROR_KEY_REJECTED:
return "KEY_REJECTED";
-
case APP_CONTROL_ERROR_INVALID_DATA_TYPE:
return "INVALID_DATA_TYPE";
-
case APP_CONTROL_ERROR_LAUNCH_REJECTED:
return "LAUNCH_REJECTED";
-
case APP_CONTROL_ERROR_PERMISSION_DENIED:
return "PERMISSION_DENIED";
-
case APP_CONTROL_ERROR_LAUNCH_FAILED:
return "LAUNCH_FAILED";
-
case APP_CONTROL_ERROR_TIMED_OUT:
return "TIMED_OUT";
-
case APP_CONTROL_ERROR_IO_ERROR:
return "IO ERROR";
-
- default :
+ default:
return "UNKNOWN";
}
}
int app_control_error(app_control_error_e error, const char* function, const char *description)
{
if (description)
- {
LOGE("[%s] %s(0x%08x) : %s", function, app_control_error_to_string(error), error, description);
- }
- else
- {
+ else {
if (error == APP_CONTROL_ERROR_KEY_NOT_FOUND)
LOGW("[%s] %s(0x%08x)", function, app_control_error_to_string(error), error);
else
static int app_control_validate_extra_data(const char *data)
{
if (data == NULL || data[0] == '\0')
- {
return APP_CONTROL_ERROR_INVALID_PARAMETER;
- }
return APP_CONTROL_ERROR_NONE;
}
static int app_control_validate(app_control_h app_control)
{
if (app_control == NULL || app_control->data == NULL)
- {
return APP_CONTROL_ERROR_INVALID_PARAMETER;
- }
return APP_CONTROL_ERROR_NONE;
}
int app_control_validate_internal_key(const char *key)
{
if (strncmp(BUNDLE_KEY_PREFIX_AUL, key, strlen(BUNDLE_KEY_PREFIX_AUL)) == 0)
- {
return -1;
- }
if (strncmp(BUNDLE_KEY_PREFIX_SERVICE, key, strlen(BUNDLE_KEY_PREFIX_SERVICE)) == 0)
- {
return -1;
- }
return 0;
}
void *user_data;
app_control_reply_cb reply_cb;
- if (appsvc_data == NULL)
- {
+ if (appsvc_data == NULL) {
app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid app_control reply");
return;
}
- if (app_control_create_reply(appsvc_bundle, &reply) != 0)
- {
+ if (app_control_create_reply(appsvc_bundle, &reply) != 0) {
app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to create app_control reply");
return;
}
request_context = appsvc_data;
request = request_context->app_control;
- switch (appsvc_result)
- {
+ switch (appsvc_result) {
case APPSVC_RES_OK:
result = APP_CONTROL_RESULT_SUCCEEDED;
break;
-
case APPSVC_RES_NOT_OK:
result = APP_CONTROL_RESULT_FAILED;
break;
-
case APPSVC_RES_CANCEL:
result = APP_CONTROL_RESULT_CANCELED;
break;
-
default:
result = APP_CONTROL_RESULT_CANCELED;
break;
reply_cb = request_context->reply_cb;
if (reply_cb != NULL)
- {
reply_cb(request, reply, result, user_data);
- }
else
- {
app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid callback ");
- }
app_control_destroy(reply);
if (request_context->app_control != NULL)
- {
app_control_destroy(request_context->app_control);
- }
free(request_context);
}
struct app_control_s *app_control_request;
if (app_control == NULL)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
app_control_request = malloc(sizeof(struct app_control_s));
-
if (app_control_request == NULL)
- {
return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a app_control handle");
- }
app_control_request->type = APP_CONTROL_TYPE_REQUEST;
if (data != NULL)
- {
app_control_request->data = bundle_dup(data);
- }
else
- {
app_control_request->data = bundle_create();
- }
- if (app_control_request->data == NULL)
- {
+ if (app_control_request->data == NULL) {
free(app_control_request);
return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a bundle");
}
const char *operation;
if (data == NULL || app_control == NULL)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
app_control_event = malloc(sizeof(struct app_control_s));
-
if (app_control_event == NULL)
- {
return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a app_control handle");
- }
app_control_event->type = APP_CONTROL_TYPE_EVENT;
app_control_event->data = bundle_dup(data);
app_control_event->id = app_control_new_id();
operation = appsvc_get_operation(app_control_event->data);
-
if (operation == NULL)
- {
appsvc_set_operation(app_control_event->data, APP_CONTROL_OPERATION_DEFAULT);
- }
*app_control = app_control_event;
struct app_control_s *app_control_reply;
if (data == NULL || app_control == NULL)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
app_control_reply = malloc(sizeof(struct app_control_s));
-
if (app_control_reply == NULL)
- {
return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a app_control handle");
- }
app_control_reply->type = APP_CONTROL_TYPE_REPLY;
app_control_reply->data = bundle_dup(data);
int app_control_destroy(app_control_h app_control)
{
if (app_control_validate(app_control))
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
- if (app_control->type == APP_CONTROL_TYPE_REQUEST && app_control->launch_pid > 0 &&
- bundle_get_val(app_control->data, AUL_SVC_K_LAUNCH_RESULT_APP_STARTED) == NULL)
- {
+ if (app_control->type == APP_CONTROL_TYPE_REQUEST && app_control->launch_pid > 0
+ && bundle_get_val(app_control->data, AUL_SVC_K_LAUNCH_RESULT_APP_STARTED) == NULL)
aul_remove_caller_cb(app_control->launch_pid);
- }
bundle_free(app_control->data);
app_control->data = NULL;
int app_control_to_bundle(app_control_h app_control, bundle **data)
{
if (app_control_validate(app_control) || data == NULL)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
*data = app_control->data;
int app_control_set_operation(app_control_h app_control, const char *operation)
{
if (app_control_validate(app_control))
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
- if (operation != NULL)
- {
+ if (operation != NULL) {
if (appsvc_set_operation(app_control->data, operation) != 0)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid operation");
- }
- }
- else
- {
+ } else {
bundle_del(app_control->data, BUNDLE_KEY_OPERATION);
}
const char *operation_value;
if (app_control_validate(app_control) || operation == NULL)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
operation_value = appsvc_get_operation(app_control->data);
-
if (operation_value != NULL)
- {
*operation = strdup(operation_value);
- }
else
- {
*operation = NULL;
- }
return APP_CONTROL_ERROR_NONE;
}
-
int app_control_set_uri(app_control_h app_control, const char *uri)
{
if (app_control_validate(app_control))
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
- if (uri != NULL)
- {
+ if (uri != NULL) {
if (appsvc_set_uri(app_control->data, uri) != 0)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid URI");
- }
- }
- else
- {
+ } else {
bundle_del(app_control->data, BUNDLE_KEY_URI);
}
return APP_CONTROL_ERROR_NONE;
}
-
int app_control_get_uri(app_control_h app_control, char **uri)
{
const char *uri_value;
if (app_control_validate(app_control) || uri == NULL)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
uri_value = appsvc_get_uri(app_control->data);
-
if (uri_value != NULL)
- {
*uri = strdup(uri_value);
- }
else
- {
*uri = NULL;
- }
return APP_CONTROL_ERROR_NONE;
}
-
int app_control_set_mime(app_control_h app_control, const char *mime)
{
if (app_control_validate(app_control))
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
- if (mime != NULL)
- {
+ if (mime != NULL) {
if (appsvc_set_mime(app_control->data, mime) != 0)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid MIME type");
- }
- }
- else
- {
+ } else {
bundle_del(app_control->data, BUNDLE_KEY_MIME);
}
return APP_CONTROL_ERROR_NONE;
}
-
int app_control_get_mime(app_control_h app_control, char **mime)
{
const char *mime_value;
if (app_control_validate(app_control) || mime == NULL)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
mime_value = appsvc_get_mime(app_control->data);
-
if (mime_value != NULL)
- {
*mime = strdup(mime_value);
- }
else
- {
*mime = NULL;
- }
return APP_CONTROL_ERROR_NONE;
}
-
int app_control_set_category(app_control_h app_control, const char *category)
{
if (app_control_validate(app_control))
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
- if (category != NULL)
- {
+ if (category != NULL) {
if (appsvc_set_category(app_control->data, category) != 0)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid Category");
- }
- }
- else
- {
+ } else {
bundle_del(app_control->data, BUNDLE_KEY_CATEGORY);
}
return APP_CONTROL_ERROR_NONE;
}
-
int app_control_get_category(app_control_h app_control, char **category)
{
const char *category_value;
if (app_control_validate(app_control) || category == NULL)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
category_value = appsvc_get_category(app_control->data);
-
if (category_value != NULL)
- {
*category = strdup(category_value);
- }
else
- {
*category = NULL;
- }
return APP_CONTROL_ERROR_NONE;
}
-
int app_control_set_package(app_control_h app_control, const char *package)
{
- // TODO: this function must be deprecated
+ /* TODO: this function must be deprecated */
return app_control_set_app_id(app_control, package);
}
int app_control_get_package(app_control_h app_control, char **package)
{
- // TODO: this function must be deprecated
+ /* TODO: this function must be deprecated */
return app_control_get_app_id(app_control, package);
}
-
int app_control_set_app_id(app_control_h app_control, const char *app_id)
{
if (app_control_validate(app_control))
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
- if (app_id != NULL)
- {
+ if (app_id != NULL) {
if (appsvc_set_appid(app_control->data, app_id) != 0)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid application ID");
- }
- }
- else
- {
+ } else {
bundle_del(app_control->data, BUNDLE_KEY_PACKAGE);
}
return APP_CONTROL_ERROR_NONE;
}
-
int app_control_get_app_id(app_control_h app_control, char **app_id)
{
const char *app_id_value;
if (app_control_validate(app_control) || app_id == NULL)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
app_id_value = appsvc_get_appid(app_control->data);
-
if (app_id_value != NULL)
- {
*app_id = strdup(app_id_value);
- }
else
- {
*app_id = NULL;
- }
return APP_CONTROL_ERROR_NONE;
}
int app_control_set_window(app_control_h app_control, unsigned int id)
{
if (app_control_validate(app_control))
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
- if (id > 0)
- {
+ if (id > 0) {
if (appsvc_allow_transient_app(app_control->data, id) != 0)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid id");
- }
- }
- else
- {
+ } else {
bundle_del(app_control->data, BUNDLE_KEY_WINDOW);
}
const char *window_id;
if (app_control_validate(app_control) || id == NULL)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
window_id = bundle_get_val(app_control->data, BUNDLE_KEY_WINDOW);
-
if (window_id != NULL)
- {
*id = atoi(window_id);
- }
else
- {
*id = 0;
- }
return APP_CONTROL_ERROR_NONE;
}
app_control_h app_control_clone;
if (app_control_validate(app_control) || clone == NULL)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
app_control_clone = malloc(sizeof(struct app_control_s));
-
if (app_control_clone == NULL)
- {
return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a app_control handle");
- }
app_control_clone->id = app_control_new_id();
app_control_clone->type = app_control->type;
request_context = (app_control_request_context_h)data;
- if (app_control_create_event(request_context->app_control->data, &reply) != 0)
- {
+ if (app_control_create_event(request_context->app_control->data, &reply) != 0) {
app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to create app_control event");
return;
}
ret = aul_app_get_appid_bypid(launched_pid, callee, sizeof(callee));
- if (ret < 0) {
+ if (ret < 0)
LOGE("aul_app_get_appid_bypid failed: %d", launched_pid);
- }
app_control_set_app_id(reply, callee);
LOGI("app control async result callback callee pid:%d", launched_pid);
reply_cb = request_context->reply_cb;
if (reply_cb != NULL)
- {
reply_cb(request, reply, result, user_data);
- }
else
- {
app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid callback ");
- }
app_control_destroy(reply);
}
int app_control_send_launch_request(app_control_h app_control, app_control_reply_cb callback, void *user_data)
{
const char *operation;
-
bool implicit_default_operation = false;
int launch_pid;
-
app_control_request_context_h request_context = NULL;
if (app_control_validate(app_control))
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
operation = appsvc_get_operation(app_control->data);
- if (operation == NULL)
- {
+ if (operation == NULL) {
implicit_default_operation = true;
operation = APP_CONTROL_OPERATION_DEFAULT;
}
if (!strcmp(operation, APP_CONTROL_OPERATION_LAUNCH_ON_EVENT))
- {
return app_control_error(APP_CONTROL_ERROR_LAUNCH_REJECTED, __FUNCTION__,
"Not supported operation value");
- }
- // TODO: Check the privilege for call operation
+ /* TODO: Check the privilege for call operation */
- // operation : default
- if (!strcmp(operation, APP_CONTROL_OPERATION_DEFAULT))
- {
+ /* operation : default */
+ if (!strcmp(operation, APP_CONTROL_OPERATION_DEFAULT)) {
const char *appid = appsvc_get_appid(app_control->data);
if (appid == NULL)
- {
return app_control_error(APP_CONTROL_ERROR_APP_NOT_FOUND, __FUNCTION__, "package must be specified if the operation is default value");
- }
}
- if (callback != NULL)
- {
+ if (callback != NULL) {
app_control_h request_clone = NULL;
request_context = calloc(1, sizeof(struct app_control_request_context_s));
-
if (request_context == NULL)
- {
return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
- }
request_context->reply_cb = callback;
- if (app_control_clone(&request_clone, app_control) != APP_CONTROL_ERROR_NONE)
- {
+ if (app_control_clone(&request_clone, app_control) != APP_CONTROL_ERROR_NONE) {
free(request_context);
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to clone the app_control request handle");
}
}
if (implicit_default_operation == true)
- {
appsvc_set_operation(app_control->data, APP_CONTROL_OPERATION_DEFAULT);
- }
launch_pid = appsvc_usr_run_service(app_control->data, app_control->id, callback ? app_control_request_result_broker : NULL, request_context, getuid());
-
if (implicit_default_operation == true)
- {
bundle_del(app_control->data, BUNDLE_KEY_OPERATION);
- }
- if (launch_pid < 0)
- {
+ if (launch_pid < 0) {
if (launch_pid == APPSVC_RET_ENOMATCH)
- {
return app_control_error(APP_CONTROL_ERROR_APP_NOT_FOUND, __FUNCTION__, NULL);
- }
else if (launch_pid == APPSVC_RET_EILLACC)
- {
return app_control_error(APP_CONTROL_ERROR_PERMISSION_DENIED, __FUNCTION__, NULL);
- }
else if (launch_pid == APPSVC_RET_EINVAL)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
else
- {
return app_control_error(APP_CONTROL_ERROR_LAUNCH_REJECTED, __FUNCTION__, NULL);
- }
}
app_control->launch_pid = launch_pid;
return APP_CONTROL_ERROR_NONE;
}
-
int app_control_send_terminate_request(app_control_h app_control)
{
if (app_control_validate(app_control))
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
if (app_control->type != APP_CONTROL_TYPE_REQUEST || app_control->launch_pid < 0)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
appsvc_subapp_terminate_request_pid(app_control->launch_pid);
int value_array_length = 0;
int value_array_index = 0;
- if (reply_data == NULL)
- {
+ if (reply_data == NULL) {
app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
return false;
}
- if (appsvc_data_is_array(app_control->data, key))
- {
+ if (appsvc_data_is_array(app_control->data, key)) {
app_control_get_extra_data_array(app_control, 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++)
- {
+ for (value_array_index = 0; value_array_index < value_array_length; value_array_index++)
free(value_array[value_array_index]);
- }
free(value_array);
- }
- else
- {
+ } else {
app_control_get_extra_data(app_control, key, &value);
appsvc_add_data(reply_data, key, value);
free(value);
int ret = 0;
if (app_control_validate(reply) || app_control_validate(request))
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
if (result == APP_CONTROL_RESULT_APP_STARTED)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "APP_CONTROL_RESULT_APP_STARTED is not allowed to use");
- }
if (appsvc_create_result_bundle(request->data, &reply_data) != 0)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to create a result bundle");
- }
app_control_foreach_extra_data(reply, app_control_copy_reply_data_cb, reply_data);
- switch (result)
- {
+ switch (result) {
case APP_CONTROL_RESULT_SUCCEEDED:
appsvc_result = APPSVC_RES_OK;
break;
-
case APP_CONTROL_RESULT_FAILED:
appsvc_result = APPSVC_RES_NOT_OK;
break;
-
case APP_CONTROL_RESULT_CANCELED:
appsvc_result = APPSVC_RES_CANCEL;
break;
-
default:
appsvc_result = APPSVC_RES_CANCEL;
break;
}
ret = appsvc_send_result(reply_data, appsvc_result);
- if (ret < 0)
- {
+ bundle_free(reply_data);
+ if (ret < 0) {
if (ret == APPSVC_RET_EINVAL)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
else
- {
return app_control_error(APP_CONTROL_ERROR_LAUNCH_REJECTED, __FUNCTION__, NULL);
- }
}
return APP_CONTROL_ERROR_NONE;
int app_control_add_extra_data(app_control_h app_control, const char *key, const char *value)
{
if (app_control_validate(app_control) || app_control_validate_extra_data(key) || app_control_validate_extra_data(value))
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
if (app_control_validate_internal_key(key))
- {
return app_control_error(APP_CONTROL_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use");
- }
- if (appsvc_get_data(app_control->data, key) != NULL)
- {
- // overwrite any existing value
+ if (appsvc_get_data(app_control->data, key) != NULL) {
+ /* overwrite any existing value */
bundle_del(app_control->data, key);
}
if (appsvc_add_data(app_control->data, key, value) != 0)
- {
return app_control_error(APP_CONTROL_ERROR_KEY_REJECTED, __FUNCTION__, "failed to add data to the appsvc handle");
- }
return APP_CONTROL_ERROR_NONE;
}
int app_control_add_extra_data_array(app_control_h app_control, const char *key, const char* value[], int length)
{
if (app_control_validate(app_control) || app_control_validate_extra_data(key))
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
if (value == NULL || length <= 0)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid array");
- }
if (app_control_validate_internal_key(key))
- {
return app_control_error(APP_CONTROL_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use");
- }
- if (appsvc_get_data_array(app_control->data, key, NULL) != NULL)
- {
- // overwrite any existing value
- bundle_del(app_control->data,key);
+ if (appsvc_get_data_array(app_control->data, key, NULL) != NULL) {
+ /* overwrite any existing value */
+ bundle_del(app_control->data, key);
}
if (appsvc_add_data_array(app_control->data, key, value, length) != 0)
- {
return app_control_error(APP_CONTROL_ERROR_KEY_REJECTED, __FUNCTION__, "failed to add array data to the appsvc handle");
- }
return APP_CONTROL_ERROR_NONE;
}
-
int app_control_remove_extra_data(app_control_h app_control, const char *key)
{
if (app_control_validate(app_control) || app_control_validate_extra_data(key))
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
if (app_control_validate_internal_key(key))
- {
return app_control_error(APP_CONTROL_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use");
- }
if (bundle_del(app_control->data, key))
- {
return app_control_error(APP_CONTROL_ERROR_KEY_NOT_FOUND, __FUNCTION__, NULL);
- }
return APP_CONTROL_ERROR_NONE;
}
-
int app_control_get_extra_data(app_control_h app_control, const char *key, char **value)
{
const char *data_value;
if (app_control_validate(app_control) || app_control_validate_extra_data(key) || value == NULL)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
-
if (app_control_validate_internal_key(key))
- {
return app_control_error(APP_CONTROL_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use");
- }
data_value = appsvc_get_data(app_control->data, key);
-
- if (data_value == NULL)
- {
+ if (data_value == NULL) {
if (errno == ENOTSUP)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_DATA_TYPE, __FUNCTION__, NULL);
- }
else
- {
return app_control_error(APP_CONTROL_ERROR_KEY_NOT_FOUND, __FUNCTION__, NULL);
- }
}
*value = strdup(data_value);
return APP_CONTROL_ERROR_NONE;
}
-
int app_control_get_extra_data_array(app_control_h app_control, const char *key, char ***value, int *length)
{
const char **array_data;
int i;
if (app_control_validate(app_control) || app_control_validate_extra_data(key))
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
if (value == NULL || length == 0)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
if (app_control_validate_internal_key(key))
- {
return app_control_error(APP_CONTROL_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use");
- }
array_data = appsvc_get_data_array(app_control->data, key, &array_data_length);
-
- if (array_data == NULL)
- {
+ if (array_data == NULL) {
if (errno == ENOTSUP)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_DATA_TYPE, __FUNCTION__, NULL);
- }
else
- {
return app_control_error(APP_CONTROL_ERROR_KEY_NOT_FOUND, __FUNCTION__, NULL);
- }
}
array_data_clone = calloc(array_data_length, sizeof(char*));
-
if (array_data_clone == NULL)
- {
return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
- }
- for (i=0; i<array_data_length; i++)
- {
+ for (i = 0; i < array_data_length; i++) {
if (array_data[i] != NULL)
- {
array_data_clone[i] = strdup(array_data[i]);
- }
}
*value = array_data_clone;
return APP_CONTROL_ERROR_NONE;
}
-
int app_control_is_extra_data_array(app_control_h app_control, const char *key, bool *array)
{
if (app_control_validate(app_control) || app_control_validate_extra_data(key) || array == NULL)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
if (app_control_validate_internal_key(key))
- {
return app_control_error(APP_CONTROL_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use");
- }
if (!appsvc_data_is_array(app_control->data, key))
- {
*array = false;
- }
else
- {
*array = true;
- }
return APP_CONTROL_ERROR_NONE;
}
-
typedef struct {
app_control_h app_control;
app_control_extra_data_cb callback;
app_control_extra_data_cb extra_data_cb;
if (key == NULL || !(type == BUNDLE_TYPE_STR || type == BUNDLE_TYPE_STR_ARRAY))
- {
return;
- }
foreach_context = (foreach_context_extra_data_t*)user_data;
-
if (foreach_context->foreach_break == true)
- {
return;
- }
if (app_control_validate_internal_key(key))
- {
return;
- }
extra_data_cb = foreach_context->callback;
- if (extra_data_cb != NULL)
- {
+ if (extra_data_cb != NULL) {
bool stop_foreach = false;
stop_foreach = !extra_data_cb(foreach_context->app_control, key, foreach_context->user_data);
foreach_context->foreach_break = stop_foreach;
}
-
}
-
int app_control_foreach_extra_data(app_control_h app_control, app_control_extra_data_cb callback, void *user_data)
{
foreach_context_extra_data_t foreach_context = {
};
if (app_control_validate(app_control) || callback == NULL)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
bundle_foreach(app_control->data, app_control_cb_broker_bundle_iterator, &foreach_context);
foreach_context_launchable_app_t *foreach_context;
app_control_app_matched_cb app_matched_cb;
- if (package == NULL || data == NULL)
- {
+ if (package == NULL || data == NULL) {
app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
return -1;
}
foreach_context = (foreach_context_launchable_app_t*)data;
-
if (foreach_context->foreach_break == true)
- {
return -1;
- }
app_matched_cb = foreach_context->callback;
-
- if (app_matched_cb != NULL)
- {
+ if (app_matched_cb != NULL) {
bool stop_foreach = false;
stop_foreach = !app_matched_cb(foreach_context->app_control, package, foreach_context->user_data);
};
if (app_control_validate(app_control) || callback == NULL)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
appsvc_usr_get_list(app_control->data, app_control_cb_broker_foreach_app_matched, &foreach_context, getuid());
return APP_CONTROL_ERROR_NONE;
}
-
int app_control_get_caller(app_control_h app_control, char **package)
{
const char *bundle_value;
char *package_dup;
if (app_control_validate(app_control) || package == NULL)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
if (app_control->type != APP_CONTROL_TYPE_EVENT)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid app_control handle type");
- }
-
- bundle_value = bundle_get_val(app_control->data, AUL_K_CALLER_APPID);
- if (bundle_value == NULL)
- {
- return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to retrieve the appid of the caller");
- }
- package_dup = strdup(bundle_value);
+ bundle_value = bundle_get_val(app_control->data, AUL_K_CALLER_APPID);
+ if (bundle_value == NULL)
+ return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to retrieve the appid of the caller");
- if (package_dup == NULL)
- {
- return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
- }
+ package_dup = strdup(bundle_value);
+ if (package_dup == NULL)
+ return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
- *package = package_dup;
+ *package = package_dup;
return APP_CONTROL_ERROR_NONE;
}
-
int app_control_is_reply_requested(app_control_h app_control, bool *requested)
{
const char *bundle_value;
if (app_control_validate(app_control) || requested == NULL)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
if (app_control->type != APP_CONTROL_TYPE_EVENT)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid app_control handle type");
- }
bundle_value = bundle_get_val(app_control->data, AUL_K_WAIT_RESULT);
-
if (bundle_value != NULL)
- {
*requested = true;
- }
else
- {
*requested = false;
- }
return APP_CONTROL_ERROR_NONE;
}
bundle *data_dup = NULL;
if (app_control_validate(app_control) || data == NULL)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
data_dup = bundle_dup(data);
-
if (data_dup == NULL)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to duplicate the bundle");
- }
if (app_control->data != NULL)
- {
bundle_free(app_control->data);
- }
app_control->data = data_dup;
bundle *data_dup = NULL;
if (app_control_validate(app_control) || data == NULL)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
data_dup = bundle_dup(app_control->data);
-
if (data_dup == NULL)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to duplicate the bundle");
- }
*data = data_dup;
int ret;
if (app_control_validate(app_control))
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
ret = appsvc_request_transient_app(app_control->data, callee_id, (appsvc_host_res_fn)cbfunc, data);
-
if (ret < 0)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
return APP_CONTROL_ERROR_NONE;
}
int ret;
if (app_control_validate(app_control))
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
ret = aul_svc_subscribe_launch_result(app_control->data, AUL_SVC_K_LAUNCH_RESULT_APP_STARTED);
-
if (ret < 0)
- {
return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
return APP_CONTROL_ERROR_NONE;
}
switch (error) {
case EVENT_ERROR_NONE:
return "NONE";
-
case EVENT_ERROR_INVALID_PARAMETER:
return "INVALID_PARAMETER";
-
case EVENT_ERROR_OUT_OF_MEMORY:
return "OUT_OF_MEMORY";
-
case EVENT_ERROR_TIMED_OUT:
return "TIMED_OUT";
-
case EVENT_ERROR_IO_ERROR:
return "IO ERROR";
-
case EVENT_ERROR_PERMISSION_DENIED:
return "PERMISSION DENIED";
-
default:
return "UNKNOWN";
}
_initialized = 1;
}
- if (event_handler == NULL || event_name == NULL || callback == NULL) {
+ if (event_handler == NULL || event_name == NULL || callback == NULL)
return event_error(EVENT_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
handler = calloc(1, sizeof(event_handler_s));
- if (handler == NULL) {
+ if (handler == NULL)
return event_error(EVENT_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
- }
pthread_mutex_lock(®ister_sync_lock);
earlier_callback = callback;
pthread_mutex_unlock(®ister_sync_lock);
if (ret < 0) {
free(handler);
- if (ret == ES_R_ENOTPERMITTED) {
+ if (ret == ES_R_ENOTPERMITTED)
return event_error(EVENT_ERROR_PERMISSION_DENIED, __FUNCTION__, NULL);
- } else {
+ else
return event_error(EVENT_ERROR_IO_ERROR, __FUNCTION__, NULL);
- }
}
handler->event_name = strdup(event_name);
return EVENT_ERROR_NONE;
}
- if (event_handler == NULL) {
+ if (event_handler == NULL)
return event_error(EVENT_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
ret = eventsystem_unregister_application_event(event_handler->reg_id);
- if (ret < 0) {
+ if (ret < 0)
return event_error(EVENT_ERROR_IO_ERROR, __FUNCTION__, NULL);
- }
GList *handler_list = (GList *)g_hash_table_lookup(interested_event_table,
event_handler->event_name);
int event_publish_app_event(const char *event_name, bundle *event_data)
{
- if (event_data == NULL || event_name == NULL) {
+ if (event_data == NULL || event_name == NULL)
return event_error(EVENT_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
- if (eventsystem_send_user_event(event_name, event_data, false) < 0) {
+ if (eventsystem_send_user_event(event_name, event_data, false) < 0)
return event_error(EVENT_ERROR_IO_ERROR, __FUNCTION__, NULL);
- }
return EVENT_ERROR_NONE;
}
int event_publish_trusted_app_event(const char *event_name, bundle *event_data)
{
- if (event_data == NULL || event_name == NULL) {
+ if (event_data == NULL || event_name == NULL)
return event_error(EVENT_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
- if (eventsystem_send_user_event(event_name, event_data, true) < 0) {
+ if (eventsystem_send_user_event(event_name, event_data, true) < 0)
return event_error(EVENT_ERROR_IO_ERROR, __FUNCTION__, NULL);
- }
return EVENT_ERROR_NONE;
}
* 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.
+ * limitations under the License.
*/
*/
typedef void (*app_control_cb) (app_control_h app_control, void *user_data);
-
-/**
- * @brief Called when other application send the launch request to the application.
- *
- * @details When the application is launched, this callback function is called after the main loop of application starts up.
- * The passed service handle describes the launch request and contains the information about why the application is launched.
- * If the launch request is sent to the application on running or pause state,
- * this callback function can be called again to notify that the application is asked to be launched.
- *
- * The application could be explicitly launched by the user from the application launcher or be launched to perform the specific operation by other application.
- * The application is responsible for handling the each launch request and responding appropriately.
- * Using the Service API, the application can get the information what has to perform.
- * If the application is launched from the application launcher or explicitly launched by other application,
- * the passed service handle may include only the default operation (#SERVICE_OPERATION_DEFAULT) without any data
- * For more information, see The @ref CAPI_SERVICE_MODULE API description.
- *
- * @param[in] service The handle to the service
- * @param[in] user_data The user data passed from the callback registration function
- * @see app_efl_main()
- * @see #app_event_callback_s
- * @see @ref CAPI_SERVICE_MODULE API
- */
-typedef void (*app_service_cb) (service_h service, void *user_data);
-
-
-/**
- * @brief Called when the system memory is running low.
- *
- * @details
- * When low memory event is dispatched, the application should immediately save state and release resources to save as much memory as possible. \n
- * If enough memory is not reclaimed during low memory conditions, the system will terminate some of the applications to reclaim the memory.
- *
- * @param[in] user_data The user data passed from the callback registration function
- * @see app_efl_main()
- * @see #app_event_callback_s
- */
-typedef void (*app_low_memory_cb) (void *user_data);
-
-
-/**
- * @brief Called when the battery power is running low.
- * @details When the battery level falls below 5%, it is called.
- *
- * @param[in] user_data The user data passed from the callback registration function
- * @see app_efl_main()
- * @see #app_event_callback_s
- */
-typedef void (*app_low_battery_cb) (void *user_data);
-
-
-/**
- * @brief Called when the orientation of device changes.
- *
- * @param[in] orientation The orientation of device
- * @param[in] user_data The user data passed from the callback registration function
- * @see app_efl_main()
- * @see #app_event_callback_s
- */
-typedef void (*app_device_orientation_cb) (app_device_orientation_e orientation, void *user_data);
-
-
-/**
- * @brief Called when language setting changes.
- *
- * @param [in] user_data The user data passed from the callback registration function
- * @see app_efl_main()
- * @see #app_event_callback_s
- */
-typedef void (*app_language_changed_cb) (void *user_data);
-
-
-/**
- * @brief Called when region format setting changes.
- *
- * @param [in] user_data The user data passed from the callback registration function
- * @see app_efl_main()
- * @see #app_event_callback_s
- */
-typedef void (*app_region_format_changed_cb) (void *user_data);
-
-
-/**
- * @brief The structure type to contain the set of callback functions for handling application events.
- * @details It is one of the input parameters of the app_efl_main() function.
- *
- * @see app_efl_main()
- * @see app_create_cb()
- * @see app_pause_cb()
- * @see app_resume_cb()
- * @see app_terminate_cb()
- * @see app_service_cb()
- * @see app_low_memory_cb()
- * @see app_low_battery_cb()
- * @see app_device_orientation_cb()
- * @see app_language_changed_cb()
- * @see app_region_format_changed_cb()
- */
-typedef struct
-{
- app_create_cb create; /**< This callback function is called at the start of the application. */
- app_terminate_cb terminate; /**< This callback function is called once after the main loop of application exits. */
- app_pause_cb pause; /**< This callback function is called each time the application is completely obscured by another application and becomes invisible to the user. */
- app_resume_cb resume; /**< This callback function is called each time the application becomes visible to the user. */
- app_service_cb service; /**< This callback function is called when other application send the launch request to the application. */
- app_low_memory_cb low_memory; /**< The registered callback function is called when the system runs low on memory. */
- app_low_battery_cb low_battery; /**< The registered callback function is called when battery is low. */
- app_device_orientation_cb device_orientation; /**< The registered callback function is called when the orientation of device changes */
- app_language_changed_cb language_changed; /**< The registered callback function is called when language setting changes. */
- app_region_format_changed_cb region_format_changed; /**< The registered callback function is called when region format setting is changes. */
-} app_event_callback_s;
-
/**
* @brief The structure type containing the set of callback functions for handling application lifecycle events.
* @details It is one of the input parameters of the ui_app_main() function.
* @see app_terminate_cb()
* @see app_control_cb()
*/
-typedef struct
-{
+typedef struct {
app_create_cb create; /**< This callback function is called at the start of the application. */
app_terminate_cb terminate; /**< This callback function is called once after the main loop of the application exits. */
app_pause_cb pause; /**< This callback function is called each time the application is completely obscured by another application and becomes invisible to the user. */
app_control_cb app_control; /**< This callback function is called when another application sends the launch request to the application. */
} ui_app_lifecycle_callback_s;
-
-/**
- * @brief Runs the main loop of application until app_efl_exit() is called
- *
- * @details This function is the main entry point of the Tizen application.
- * The app_create_cb() callback function is called to initialize the application before the main loop of application starts up.
- * After the app_create_cb() callback function returns true, the main loop starts up and the app_service_cb() callback function is subsequently called.
- * If the app_create_cb() callback function returns false, the main loop doesn't start up and app_terminate_cb() callback function is called
- *
- * @param [in] argc The argument count
- * @param [in] argv The argument vector
- * @param [in] callback The set of callback functions to handle application events
- * @param [in] user_data The user data to be passed to the callback functions
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #APP_ERROR_NONE Successful
- * @retval #APP_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #APP_ERROR_INVALID_CONTEXT The application is illegally launched, not launched by the launch system.
- * @retval #APP_ERROR_ALREADY_RUNNING The main loop already starts
- *
- * @see app_create_cb()
- * @see app_terminate_cb()
- * @see app_pause_cb()
- * @see app_resume_cb()
- * @see app_service_cb()
- * @see app_low_memory_cb()
- * @see app_low_battery_cb()
- * @see app_device_orientation_cb()
- * @see app_language_changed_cb()
- * @see app_region_format_changed_cb()
- * @see app_efl_exit()
- * @see #app_event_callback_s
- */
-int app_efl_main(int *argc, char ***argv, app_event_callback_s *callback, void *user_data);
-
-
-/**
- * @brief Exits the main loop of application.
- *
- * @details The main loop of application stops and app_terminate_cb() is invoked
- * @see app_efl_main()
- * @see app_terminate_cb()
- */
-void app_efl_exit(void);
-
-
/**
* @brief Gets the current device orientation.
*
*/
app_device_orientation_e app_get_device_orientation(void);
-
-/**
- * @brief Sets whether reclaiming system cache is enabled in the pause state.
- *
- * @details If the reclaiming system cache is enabled, the system caches are released as possible when the application's state changes to the pause state.
- *
- * @remarks The reclaiming system cache is enabled by default
- *
- * @param [in] enable whether reclaiming system cache is enabled
- */
-void app_set_reclaiming_system_cache_on_pause(bool enable);
-
/**
* @brief Runs the application's main loop until ui_app_exit() is called.
*
* @brief Enumeration for Alarm Error.
* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
*/
-typedef enum
-{
+typedef enum {
ALARM_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
ALARM_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
ALARM_ERROR_INVALID_TIME = TIZEN_ERROR_APPLICATION | 0x05, /**< Invalid time */
ALARM_ERROR_INVALID_DATE = TIZEN_ERROR_APPLICATION | 0x06, /**< Invalid date */
ALARM_ERROR_CONNECTION_FAIL = TIZEN_ERROR_APPLICATION | 0x07, /**< The alarm service connection failed */
+ ALARM_ERROR_NOT_PERMITTED_APP = TIZEN_ERROR_APPLICATION | 0x08, /**< Application is not permitted. (Since 2.4) */
ALARM_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
ALARM_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED /**< Permission denied */
} alarm_error_e;
* @brief Enumeration for Alarm Week Flag, the days of the week.
* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
*/
-typedef enum
-{
+typedef enum {
ALARM_WEEK_FLAG_SUNDAY = 0x01, /**< Sunday */
ALARM_WEEK_FLAG_MONDAY = 0x02, /**< Monday */
ALARM_WEEK_FLAG_TUESDAY = 0x04, /**< Tuesday */
* @privlevel public
* @privilege %http://tizen.org/privilege/alarm.set
* @remarks If the application is uninstalled after setting an alarm, the alarm is cancelled automatically.
+ * If the operation of @a app_control is not specified, #APP_CONTROL_OPERATION_DEFAULT is used for the launch request.
+ * If the operation of @a app_control is #APP_CONTROL_OPERATION_DEFAULT, the package information is mandatory to explicitly launch the application.
+ * Since 2.4, this api does not support exact period and delay for minimizing the wakeups of the device. The system can adjust when the alarm expires.
+ * If you want to trigger an alarm exactly, see @see alarm_schedule_once_after_delay()
+ * Since 2.4 If @a app_control is specified with service-application, the application is only allowed to run on which has Background Category.
+ * Since 2.4 If the appid of @a app_control is not specified, this api is not allowed. In other words, the explicit @a app_control is only allowed.
*
* @param[in] app_control The destination app_control to perform a specific task when the alarm is triggered
- * @param[in] delay The amount of time before the first execution (in seconds)
- * @param[in] period The amount of time between subsequent alarms (in seconds)
- * @param[out] alarm_id The alarm ID that uniquely identifies an alarm
+ * @param[in] delay The amount of time before the first execution (in seconds). Since 2.4, Although this is inexact, the alarm will not fire before this time
+ * @param[in] period The amount of time between subsequent alarms (in seconds). Since 2.4, This value does not guarantee the accuracy. The actual interval is calculated by the OS. The minimum value is 600sec
+ * @param[out] alarm_id The alarm ID that uniquely identifies an alarm.
* @return @c 0 on success,
* otherwise a negative error value
* @retval #ALARM_ERROR_NONE Successful
* @retval #ALARM_ERROR_INVALID_TIME Triggered time is invalid
* @retval #ALARM_ERROR_CONNECTION_FAIL Failed to connect to an alarm server
* @retval #ALARM_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #ALARM_ERROR_NOT_PERMITTED_APP @a app_control is not permitted
* @see alarm_cancel()
* @see alarm_cancel_all()
* @see alarm_get_scheduled_date()
- * @see alarm_get_scheduled_period()
*/
int alarm_schedule_after_delay(app_control_h app_control, int delay, int period, int *alarm_id);
* @privlevel public
* @privilege %http://tizen.org/privilege/alarm.set
* @remarks If the application is uninstalled after setting an alarm, the alarm is cancelled automatically.
+ * If the operation of @a app_control is not specified, #APP_CONTROL_OPERATION_DEFAULT is used for the launch request.
+ * If the operation of @a app_control is #APP_CONTROL_OPERATION_DEFAULT, the package information is mandatory to explicitly launch the application.
+ * If the appid of @a app_control is not specified, this api is not allowed. In other words, the explicit @a app_control is only allowed.
+ * The @a app_control only supports UI application with this api. If @a app_control is not UI application, #ALARM_ERROR_NOT_PERMITTED_APP returned.
+ * When the alarm is expired, Alarm Manager will turn on LCD to prohibit background jobs.
*
* @param[in] app_control The destination app_control to perform a specific task when the alarm is triggered
* @param[in] delay The amount of time before the execution (in seconds)
* @retval #ALARM_ERROR_INVALID_TIME Triggered time is invalid
* @retval #ALARM_ERROR_CONNECTION_FAIL Failed to connect to an alarm server
* @retval #ALARM_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #ALARM_ERROR_NOT_PERMITTED_APP @a app_control is not permitted. @a app_control for UI application is only permitted.
* @see alarm_cancel()
* @see alarm_cancel_all()
* @see alarm_get_scheduled_date()
- * @see alarm_get_scheduled_period()
*/
int alarm_schedule_once_after_delay(app_control_h app_control, int delay, int *alarm_id);
* @remarks If application is uninstalled after setting an alarm, the alarm is cancelled automatically.
* If the operation of @a app_control is not specified, #APP_CONTROL_OPERATION_DEFAULT is used for the launch request.
* If the operation of @a app_control is #APP_CONTROL_OPERATION_DEFAULT, the package information is mandatory to explicitly launch the application.
+ * If the appid of @a app_control is not specified, this api is not allowed. In other words, the explicit @a app_control is only allowed.
+ * The @a app_control only supports UI application with this api. If @a app_control is not UI application, #ALARM_ERROR_NOT_PERMITTED_APP returned.
+ * When the alarm is expired, Alarm Manager will turn on LCD to prohibit background jobs.
*
* @param[in] app_control The destination app_control to perform specific work when the alarm is triggered
* @param[in] date The first active alarm time
* @retval #ALARM_ERROR_INVALID_DATE Triggered date is invalid
* @retval #ALARM_ERROR_CONNECTION_FAIL Failed to connect to an alarm server
* @retval #ALARM_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #ALARM_ERROR_NOT_PERMITTED_APP @a app_control is not permitted. @a app_control for UI application is only permitted.
* @see alarm_cancel()
* @see alarm_cancel_all()
* @see alarm_get_scheduled_date()
- * @see alarm_get_scheduled_period()
*/
int alarm_schedule_once_at_date(app_control_h app_control, struct tm *date, int *alarm_id);
* @see alarm_get_scheduled_date()
* @see #alarm_week_flag_e
*/
-int alarm_schedule_with_recurrence_week_flag(app_control_h app_control, struct tm *date, int week_flag,int *alarm_id);
-
+int alarm_schedule_with_recurrence_week_flag(app_control_h app_control, struct tm *date, int week_flag, int *alarm_id);
/**
* @brief Gets the recurrence days of the week.
* an error (error code #ALARM_ERROR_INVALID_PARAMETER) will occur because this alarm is scheduled with no recurrence.
* If the operation of @a app_control is not specified, #APP_CONTROL_OPERATION_DEFAULT is used for the launch request.
* If the operation of @a app_control is #APP_CONTROL_OPERATION_DEFAULT, the package information is mandatory to explicitly launch the application.
+ * Since 2.4, The @a app_control only supports UI application with this api. If @a app_control is not UI application, #ALARM_ERROR_NOT_PERMITTED_APP returned.
+ * When the alarm is expired, Alarm Manager will turn on LCD to prohibit background jobs.
+ * Since 2.4, If the appid of @a app_control is not specified, this api is not allowed. In other words, the explicit @a app_control is only allowed.
* @param[in] alarm_id The alarm ID returned when the alarm is scheduled
* @param[out] week_flag The recurrence days of the week, @a week_flag may be a combination of days, like #ALARM_WEEK_FLAG_TUESDAY | #ALARM_WEEK_FLAG_FRIDAY
* @return @c 0 on success,
* otherwise a negative error value
* @retval #ALARM_ERROR_NONE Successful
* @retval #ALARM_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #ALARM_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #ALARM_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #ALARM_ERROR_NOT_PERMITTED_APP @a app_control is not permitted. @a app_control for UI application is only permitted.
* @see alarm_schedule_with_recurrence_week_flag()
* @see #alarm_week_flag_e
*/
* @return @c 0 on success,
* otherwise a negative error value
* @retval #ALARM_ERROR_NONE Successful
+ * @retval #ALARM_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #ALARM_ERROR_CONNECTION_FAIL Failed to connect to an alarm server
* @retval #ALARM_ERROR_PERMISSION_DENIED Permission denied
* @see alarm_schedule_at_date()
* @brief Enumeration for system events
* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
*/
-typedef enum
-{
+typedef enum {
APP_EVENT_LOW_MEMORY, /**< The low memory event */
APP_EVENT_LOW_BATTERY, /**< The low battery event */
APP_EVENT_LANGUAGE_CHANGED, /**< The system language changed event */
APP_EVENT_DEVICE_ORIENTATION_CHANGED, /**< The device orientation changed event */
APP_EVENT_REGION_FORMAT_CHANGED, /**< The region format changed event */
+ APP_EVENT_SUSPENDED_STATE_CHANGED, /**< The suspended state changed event of the application (since 2.4)
+ @see app_event_get_suspended_state */
} app_event_type_e;
-
/**
* @brief Enumeration for device orientation.
* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
*/
-typedef enum
-{
+typedef enum {
APP_DEVICE_ORIENTATION_0 = 0, /**< The device is oriented in a natural position */
APP_DEVICE_ORIENTATION_90 = 90, /**< The device's left side is at the top */
APP_DEVICE_ORIENTATION_180 = 180, /**< The device is upside down */
APP_DEVICE_ORIENTATION_270 = 270, /**< The device's right side is at the top */
} app_device_orientation_e;
-
/**
* @brief Enumeration for low memory status.
* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
*/
-typedef enum
-{
+typedef enum {
APP_EVENT_LOW_MEMORY_NORMAL = 0x01, /**< Normal status */
APP_EVENT_LOW_MEMORY_SOFT_WARNING = 0x02, /**< Soft warning status */
APP_EVENT_LOW_MEMORY_HARD_WARNING = 0x04, /**< Hard warning status */
} app_event_low_memory_status_e;
-
/**
* @brief Enumeration for battery status.
* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
*/
-typedef enum
-{
+typedef enum {
APP_EVENT_LOW_BATTERY_POWER_OFF = 1, /**< The battery status is under 1% */
APP_EVENT_LOW_BATTERY_CRITICAL_LOW, /**< The battery status is under 5% */
} app_event_low_battery_status_e;
+/**
+ * @brief Enumeration for suspended state
+ * @since_tizen 2.4
+ */
+typedef enum {
+ APP_SUSPENDED_STATE_WILL_ENTER = 0, /**< Application will enter the suspended state */
+ APP_SUSPENDED_STATE_DID_EXIT, /**< Application did exit from the suspended state */
+} app_suspended_state_e;
/**
* @brief The event handler that returned from add event handler function
* @see app_event_get_language
* @see app_event_get_region_format
* @see app_event_get_device_orientation
+ * @see app_event_get_suspended_state
*/
typedef struct app_event_info* app_event_info_h;
*
* @see app_add_event_handler
* @see app_event_info_h
+ *
+ * @remarks If the given @a event_info has #APP_SUSPENDED_STATE_WILL_ENTER value,
+ * the application should not call any asynchronous operations in this callback.
+ * After the callback returns, process of the application will be changed to suspended
+ * state immediately. Thus, asynchronous operations may work incorrectly. (since 2.4)
+ *
*/
typedef void (*app_event_cb)(app_event_info_h event_info, void *user_data);
/**
+ * @brief Gets the suspended state of the application from given event info.
+ *
+ * @since_tizen 2.4
+ * @param[in] event_info The handle for getting the suspended state
+ * @param[out] state The suspended state of the application
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #APP_ERROR_NONE Successful
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #APP_ERROR_INVALID_CONTEXT Invalid event context
+ *
+ * @remarks The application should not use any asynchronous operations in #APP_SUSPENDED_STATE_WILL_ENTER event.
+ * Because applications will be changed to suspended state just after #APP_SUSPENDED_STATE_WILL_ENTER,
+ * asynchronous calls are not guaranteed to work properly.
+ */
+int app_event_get_suspended_state(app_event_info_h event_info, app_suspended_state_e *state);
+
+
+/**
* @brief Gets the ID of the application.
*
* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
* @remarks The returned path should be released. @n
* The important files stored in the application's external data directory should be
* encrypted because they can be exported via the external sdcard.
+ * @remarks To access the path returned by this function requires the privilege
+ * that is "http://tizen.org/privilege/externalstorage.appdata".
*
* @return The absolute path to the application's external data directory, @n
* otherwise a null pointer if the memory is insufficient
* Setting application while the application is running. @n
* The important files stored in the application's external cache directory should be
* encrypted because they can be exported via the external sdcard.
+ * @remarks To access the path returned by this function requires the privilege
+ * that is "http://tizen.org/privilege/externalstorage.appdata".
*
* @return The absolute path to the application's external cache directory, @n
* otherwise a null pointer if the memory is insufficient
/**
+ * @deprecated Deprecated since 2.4.
* @brief Gets the absolute path to the application's external shared data directory which is
* used to share data with other applications.
* @details An application can read and write its own files in the application's external shared
* data directory and others can only read the files.
* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
* @remarks The specified @a path should be released.
+ * @remarks To access the path returned by this function requires the privilege
+ * that is "http://tizen.org/privilege/externalstorage.appdata".
+ * @remarks The function may not work as intended in certain devices due to some implementation issues.
*
* @return The absolute path to the application's external shared data directory, @n
* otherwise a null pointer if the memory is insufficient
* @brief Enumeration for App Control Error.
* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
*/
-typedef enum
-{
+typedef enum {
APP_CONTROL_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
APP_CONTROL_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
APP_CONTROL_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
* @see app_control_enable_app_started_result_event()
* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
*/
-typedef enum
-{
+typedef enum {
APP_CONTROL_RESULT_APP_STARTED = 1, /**< Callee application launched actually (Since 2.4) */
APP_CONTROL_RESULT_SUCCEEDED = 0, /**< Operation succeeded */
APP_CONTROL_RESULT_FAILED = -1, /**< Operation failed by the callee */
*/
/**
+ * @brief Definition for app_control data: Connect the previous app with the next app when the sub-app is terminated.
+ * @details If a sub-app is terminated, framework will connect the previous app with the next app.
+ * By default, this flag is 'false'
+ */
+#define APP_CONTROL_DATA_REROUTE "__K_REROUTE__"
+
+/**
+ * @brief Definition for app_control data: The flag for attaching app.
+ * @details If this flag is set, callee app will be attached to caller app for a while and it will be detached when callee app is lowered.
+ * By default, this flag is 'false'
+ */
+#define APP_CONTROL_DATA_SHIFT_WINDOW "__K_SHIFT_WINDOW"
+
+/**
+ * @brief Definition for app_control data : The flag for supporting recycling processes.
+ * @details By default, this flag is 'false'. Once it is set to 'true', launched sub-app process will be reused even if it was lowered later.
+ *
+ */
+#define APP_CONTROL_DATA_RECYCLE "__K_RECYCLE"
+
+/**
* @brief Replaces all data in the app_control with the bundle
*
* @remarks This function clears all data in the app_control and adds all key-value pairs in the bundle into the app_control
* @brief Enumeration for Event Error.
* @since_tizen 2.4
*/
-typedef enum
-{
+typedef enum {
EVENT_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
EVENT_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
EVENT_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
--- /dev/null
+/*
+ * 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.
+ */
+
+
+#ifndef __TIZEN_APPFW_APP_EXTENSION_H__
+#define __TIZEN_APPFW_APP_EXTENSION_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Gets the preinitialized window object.
+ *
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @remarks This API only supports BASIC type window.
+ *
+ * @param[in] win_name The name to be set for the preinitialized window
+ *
+ * @return A @a window object on success,
+ * otherwise @c NULL
+ */
+void *app_get_preinitialized_window(const char *win_name);
+
+/**
+ * @brief Gets the preinitialized background object added to the preinitialized window.
+ *
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @remarks This API should be called after calling app_get_preinitizlized_window().
+ *
+ * @return A @a background object on success,
+ * otherwise @c NULL
+ */
+void *app_get_preinitialized_background(void);
+
+/**
+ * @brief Gets the preinitialized conformant widget added to the preinitialized window.
+ *
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @remarks This API should be called after calling app_get_preinitizlized_window().
+ *
+ * @return A conformant object on success,
+ * otherwise @c NULL
+ */
+void *app_get_preinitialized_conformant(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_APPFW_APP_EXTENSION_H__ */
#ifndef __TIZEN_APPFW_APP_INTERNAL_H__
#define __TIZEN_APPFW_APP_INTERNAL_H__
+#include <app.h>
#include <appcore-common.h>
#include <tzplatform_config.h>
-// GNU gettext macro is already defined at appcore-common.h
+/* GNU gettext macro is already defined at appcore-common.h */
#ifdef _
#undef _
#endif
-#include <app.h>
-
#ifdef __cplusplus
extern "C" {
#endif
void app_finalizer_execute(void);
+int app_get_package(char **package);
+
+/**
+ * @internal
+ * @brief Called when the system memory is running low.
+ *
+ * @details When a low memory event is dispatched, the application should immediately save state and release resources to save as much memory as possible. \n
+ * If enough memory is not reclaimed during low memory conditions, the system will terminate some of the applications to reclaim the memory.
+ *
+ * @since_tizen 2.3
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see app_main()
+ * @see #app_event_callback_s
+ */
+typedef void (*app_low_memory_cb) (void *user_data);
+
+/**
+ * @internal
+ * @brief Called when the battery power is running low.
+ * @details When the battery level falls below 5%, it is called.
+ *
+ * @since_tizen 2.3
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see app_main()
+ * @see #app_event_callback_s
+ */
+typedef void (*app_low_battery_cb) (void *user_data);
+
+/**
+ * @internal
+ * @brief Called when the orientation of the device changes.
+ *
+ * @since_tizen 2.3
+ * @param[in] orientation The orientation of the device
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see app_main()
+ * @see #app_event_callback_s
+ */
+typedef void (*app_device_orientation_cb) (app_device_orientation_e orientation, void *user_data);
+
+/**
+ * @internal
+ * @brief Called when language setting changes.
+ *
+ * @since_tizen 2.3
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see app_main()
+ * @see #app_event_callback_s
+ */
+typedef void (*app_language_changed_cb) (void *user_data);
+
+/**
+ * @internal
+ * @brief Called when region format setting changes.
+ *
+ * @since_tizen 2.3
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see app_main()
+ * @see #app_event_callback_s
+ */
+typedef void (*app_region_format_changed_cb) (void *user_data);
+
+/**
+ * @internal
+ * @brief The structure type containing the set of callback functions for handling application events.
+ * @details It is one of the input parameters of the app_main() function.
+ *
+ * @since_tizen 2.3
+ * @see app_main()
+ * @see app_create_cb()
+ * @see app_pause_cb()
+ * @see app_resume_cb()
+ * @see app_terminate_cb()
+ * @see app_control_cb()
+ * @see app_low_memory_cb()
+ * @see app_low_battery_cb()
+ * @see app_device_orientation_cb()
+ * @see app_language_changed_cb()
+ * @see app_region_format_changed_cb()
+ */
+typedef struct {
+ app_create_cb create; /**< This callback function is called at the start of the application. */
+ app_terminate_cb terminate; /**< This callback function is called once after the main loop of the application exits. */
+ app_pause_cb pause; /**< This callback function is called each time the application is completely obscured by another application and becomes invisible to the user. */
+ app_resume_cb resume; /**< This callback function is called each time the application becomes visible to the user. */
+ app_control_cb app_control; /**< This callback function is called when another application sends the launch request to the application. */
+ app_low_memory_cb low_memory; /**< The registered callback function is called when the system runs low on memory. */
+ app_low_battery_cb low_battery; /**< The registered callback function is called when the battery is low. */
+ app_device_orientation_cb device_orientation; /**< The registered callback function is called when the orientation of the device changes */
+ app_language_changed_cb language_changed; /**< The registered callback function is called when language setting changes. */
+ app_region_format_changed_cb region_format_changed; /**< The registered callback function is called when region format setting changes. */
+} app_event_callback_s;
+
+/**
+ * @internal
+ * @brief Runs the application's main loop until app_exit() is called.
+ *
+ * @details This function is the main entry point of the Tizen application.
+ * The app_create_cb() callback function is called to initialize the application before the main loop of application starts up.
+ * After the app_create_cb() callback function returns true, the main loop starts up and the app_control_cb() callback function is subsequently called.
+ * If the app_create_cb() callback function returns false, the main loop doesn't start up and app_terminate_cb() callback function is called.
+ *
+ * @since_tizen 2.3
+ * @param[in] argc The argument count
+ * @param[in] argv The argument vector
+ * @param[in] callback The set of callback functions to handle application events
+ * @param[in] user_data The user data to be passed to the callback functions
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #APP_ERROR_NONE Successful
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #APP_ERROR_INVALID_CONTEXT The application is illegally launched, not launched by the launch system
+ * @retval #APP_ERROR_ALREADY_RUNNING The main loop already starts
+ *
+ * @see app_create_cb()
+ * @see app_terminate_cb()
+ * @see app_pause_cb()
+ * @see app_resume_cb()
+ * @see app_control_cb()
+ * @see app_low_memory_cb()
+ * @see app_low_battery_cb()
+ * @see app_device_orientation_cb()
+ * @see app_language_changed_cb()
+ * @see app_region_format_changed_cb()
+ * @see app_exit()
+ * @see #app_event_callback_s
+ */
+int app_main(int argc, char **argv, app_event_callback_s *callback, void *user_data);
+
+/**
+ * @internal
+ * @brief Runs the application's main loop until app_efl_exit() is called.
+ *
+ * @details This function is the main entry point of the Tizen application.
+ * The app_create_cb() callback function is called to initialize the application before the main loop of the application starts up.
+ * After the app_create_cb() callback function returns @c true, the main loop starts up and the app_control_cb() callback function is subsequently called.
+ * If the app_create_cb() callback function returns @c false, the main loop doesn't start up and the app_terminate_cb() callback function is called.
+ *
+ * @since_tizen 2.3
+ * @param[in] argc The argument count
+ * @param[in] argv The argument vector
+ * @param[in] callback The set of callback functions to handle application events
+ * @param[in] user_data The user data to be passed to the callback functions
+ *
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #APP_ERROR_NONE Successful
+ * @retval #APP_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #APP_ERROR_INVALID_CONTEXT The application is illegally launched, not launched by the launch system
+ * @retval #APP_ERROR_ALREADY_RUNNING The main loop has already started
+ *
+ * @see app_create_cb()
+ * @see app_terminate_cb()
+ * @see app_pause_cb()
+ * @see app_resume_cb()
+ * @see app_control_cb()
+ * @see app_low_memory_cb()
+ * @see app_low_battery_cb()
+ * @see app_device_orientation_cb()
+ * @see app_language_changed_cb()
+ * @see app_region_format_changed_cb()
+ * @see app_efl_exit()
+ * @see #app_event_callback_s
+ */
+int app_efl_main(int *argc, char ***argv, app_event_callback_s *callback, void *user_data);
+
+/**
+ * @internal
+ * @brief Exits the main loop of application.
+ *
+ * @details The main loop of application stops and app_terminate_cb() is invoked.
+ * @since_tizen 2.3
+ * @see app_main()
+ * @see app_terminate_cb()
+ */
+void app_exit(void);
+
+/**
+ * @internal
+ * @brief Exits the main loop of the application.
+ *
+ * @details The main loop of the application stops and app_terminate_cb() is invoked.
+ * @since_tizen 2.3
+ * @see app_efl_main()
+ * @see app_terminate_cb()
+ */
+void app_efl_exit(void);
+
#ifdef __cplusplus
}
#endif
* @brief Enumeration for Preference Error.
* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
*/
-typedef enum
-{
+typedef enum {
PREFERENCE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
PREFERENCE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
PREFERENCE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
#define BUF_LEN (4096)
#define PREF_DIR ".pref/"
-#define PREFERENCE_KEY_PATH_LEN 1024
-#define ERR_LEN 128
+#define PREFERENCE_KEY_PATH_LEN 1024
+#define ERR_LEN 128
#define PREF_DB_NAME ".pref.db"
#define PREF_TBL_NAME "pref"
*/
#define PREFERENCE_ERROR_FILE_LOCK -29
-typedef enum
-{
+typedef enum {
PREFERENCE_TYPE_NONE = 0,
PREFERENCE_TYPE_STRING,
PREFERENCE_TYPE_INT,
PREFERENCE_TYPE_BOOLEAN,
} preference_type_e;
-typedef struct _pref_changed_cb_node_t{
+typedef struct _pref_changed_cb_node_t {
char *key;
preference_changed_cb cb;
void *user_data;
} pref_changed_cb_node_t;
typedef struct _keynode_t {
- char *keyname; /**< Keyname for keynode */
- int type; /**< Keynode type */
- union {
- int i; /**< Integer type */
- int b; /**< Bool type */
- double d; /**< Double type */
- char *s; /**< String type */
- } value; /**< Value for keynode */
- struct _keynode_t *next; /**< Next keynode */
+ char *keyname; /**< Keyname for keynode */
+ int type; /**< Keynode type */
+ union {
+ int i; /**< Integer type */
+ int b; /**< Bool type */
+ double d; /**< Double type */
+ char *s; /**< String type */
+ } value; /**< Value for keynode */
+ struct _keynode_t *next; /**< Next keynode */
} keynode_t;
/**
* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
*/
typedef struct _keylist_t {
- int num; /**< Number of list */
- keynode_t *head; /**< Head node */
- keynode_t *cursor; /**< Cursor node */
+ int num; /**< Number of list */
+ keynode_t *head; /**< Head node */
+ keynode_t *cursor; /**< Cursor node */
} keylist_t;
* otherwise a negative error value
* @retval #APP_RESOURCE_ERROR_NONE Successful
* @retval #APP_RESOURCE_ERROR_INVALID_PARAMETER Invalid Parameter
- * @retval #APP_RESOURCE_ERROR_IO_ERROR Internal I/O Error
+ * @retval #APP_RESOURCE_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #APP_RESOURCE_ERROR_IO_ERROR Internal I/O Error or failed to find valid resource
* @see app_resource_manager_init()
*/
int app_resource_manager_get(app_resource_e type, const char *id, char **path);
* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
*/
-typedef enum
-{
+typedef enum {
APP_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
APP_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
APP_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
static char *g_pref_dir_path = NULL;
enum preference_op_t {
- PREFERENCE_OP_GET = 0,
- PREFERENCE_OP_SET = 1
+ PREFERENCE_OP_GET = 0,
+ PREFERENCE_OP_SET = 1
};
#ifdef PREFERENCE_TIMECHECK
inline void _preference_keynode_free(keynode_t *keynode)
{
- if(keynode) {
+ if (keynode) {
if (keynode->keyname)
free(keynode->keyname);
if (keynode->type == PREFERENCE_TYPE_STRING && keynode->value.s)
char *convert_key = NULL;
FILE *fp = NULL;
- if( (fp = fopen(path, "r")) == NULL ) {
+ if ((fp = fopen(path, "r")) == NULL)
return PREFERENCE_ERROR_FILE_OPEN;
- }
read_size = fread((void *)&keyname_len, sizeof(int), 1, fp);
if (read_size <= 0 || keyname_len > PREFERENCE_KEY_PATH_LEN) {
gchar *convert_key;
char *keyname = keynode->keyname;
- if(!keyname) {
+ if (!keyname) {
LOGE("keyname is null");
return PREFERENCE_ERROR_WRONG_PREFIX;
}
fd = open(path, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
umask(temp);
- if(fd == -1) {
+ if (fd == -1) {
char err_buf[ERR_LEN] = {0,};
strerror_r(errno, err_buf, sizeof(err_buf));
ERR("open(rdwr,create) error: %d(%s)", errno, err_buf);
struct flock l;
l.l_type = type;
- l.l_start= 0; /*Start at begin*/
+ l.l_start = 0; /*Start at begin*/
l.l_whence = SEEK_SET;
l.l_len = 0; /*Do it with whole file*/
struct flock l;
l.l_type = type;
- l.l_start= 0; /*Start at begin*/
+ l.l_start = 0; /*Start at begin*/
l.l_whence = SEEK_SET;
l.l_len = 0; /*Do it with whole file*/
- if(fcntl(fd, F_GETLK, &l) < 0) {
+ if (fcntl(fd, F_GETLK, &l) < 0) {
WARN("error in getting lock info");
return -1;
}
- if(l.l_type == F_UNLCK)
+ if (l.l_type == F_UNLCK)
return 0;
else
return l.l_pid;
}
-
static int _preference_set_read_lock(int fd)
{
return _preference_set_file_lock(fd, F_RDLCK);
{
int is_busy_err = 0;
- if (preference_errno == PREFERENCE_ERROR_FILE_OPEN)
- {
- switch (io_errno)
- {
- case ENOENT :
- {
- if(op_type == PREFERENCE_OP_SET)
- {
- int rc = 0;
- char path[PATH_MAX] = {0,};
- rc = _preference_get_key_path(keynode, path);
- if (rc != PREFERENCE_ERROR_NONE) {
- ERR("_preference_get_key_path error");
- _preference_log_subject_label();
- break;
- }
-
- rc = _preference_set_key_check_pref_dir();
- if (rc != PREFERENCE_ERROR_NONE) {
- ERR("_preference_set_key_check_pref_dir() failed.");
- _preference_log_subject_label();
- break;
- }
-
- rc = _preference_set_key_creation(path);
- if (rc != PREFERENCE_ERROR_NONE) {
- ERR("_preference_set_key_creation error : %s", path);
- _preference_log_subject_label();
- break;
- }
- INFO("%s key is created", keynode->keyname);
-
- is_busy_err = 1;
+ if (preference_errno == PREFERENCE_ERROR_FILE_OPEN) {
+ switch (io_errno) {
+ case ENOENT:
+ if (op_type == PREFERENCE_OP_SET) {
+ int rc = 0;
+ char path[PATH_MAX] = {0,};
+ rc = _preference_get_key_path(keynode, path);
+ if (rc != PREFERENCE_ERROR_NONE) {
+ ERR("_preference_get_key_path error");
+ _preference_log_subject_label();
+ break;
}
- break;
- }
- case EACCES :
- {
- _preference_log_subject_label();
- break;
- }
- case EAGAIN :
- case EMFILE :
- case ENFILE :
- case ETXTBSY :
- {
+
+ rc = _preference_set_key_check_pref_dir();
+ if (rc != PREFERENCE_ERROR_NONE) {
+ ERR("_preference_set_key_check_pref_dir() failed.");
+ _preference_log_subject_label();
+ break;
+ }
+
+ rc = _preference_set_key_creation(path);
+ if (rc != PREFERENCE_ERROR_NONE) {
+ ERR("_preference_set_key_creation error : %s", path);
+ _preference_log_subject_label();
+ break;
+ }
+ INFO("%s key is created", keynode->keyname);
+
is_busy_err = 1;
}
+ break;
+ case EACCES:
+ _preference_log_subject_label();
+ break;
+ case EAGAIN:
+ case EMFILE:
+ case ENFILE:
+ case ETXTBSY:
+ is_busy_err = 1;
}
- }
- else if (preference_errno == PREFERENCE_ERROR_FILE_CHMOD)
- {
- switch (io_errno)
- {
- case EINTR :
- case EBADF :
- {
- is_busy_err = 1;
- }
+ } else if (preference_errno == PREFERENCE_ERROR_FILE_CHMOD) {
+ switch (io_errno) {
+ case EINTR:
+ case EBADF:
+ is_busy_err = 1;
}
- }
- else if (preference_errno == PREFERENCE_ERROR_FILE_LOCK)
- {
- switch (io_errno)
- {
- case EBADF :
- case EAGAIN :
- case ENOLCK :
- {
- is_busy_err = 1;
- }
+ } else if (preference_errno == PREFERENCE_ERROR_FILE_LOCK) {
+ switch (io_errno) {
+ case EBADF:
+ case EAGAIN:
+ case ENOLCK:
+ is_busy_err = 1;
}
- }
- else if (preference_errno == PREFERENCE_ERROR_FILE_WRITE)
- {
- switch (io_errno)
- {
- case 0 :
- case EAGAIN :
- case EINTR :
- case EIO :
- case ENOMEM :
- {
- is_busy_err = 1;
- }
+ } else if (preference_errno == PREFERENCE_ERROR_FILE_WRITE) {
+ switch (io_errno) {
+ case 0:
+ case EAGAIN:
+ case EINTR:
+ case EIO:
+ case ENOMEM:
+ is_busy_err = 1;
}
- }
- else if (preference_errno == PREFERENCE_ERROR_FILE_FREAD)
- {
- switch (io_errno)
- {
- case EAGAIN :
- case EINTR :
- case EIO :
- {
- is_busy_err = 1;
- }
+ } else if (preference_errno == PREFERENCE_ERROR_FILE_FREAD) {
+ switch (io_errno) {
+ case EAGAIN:
+ case EINTR:
+ case EIO:
+ is_busy_err = 1;
}
- }
- else
- {
+ } else {
is_busy_err = 0;
}
- if (is_busy_err == 1) {
+ if (is_busy_err == 1)
return 1;
- }
- else
- {
+ else {
char err_buf[ERR_LEN] = {0,};
strerror_r(errno, err_buf, sizeof(err_buf));
- ERR("key(%s), check retry err: %d/(%d/%s).",keynode->keyname, preference_errno, io_errno, err_buf);
+ ERR("key(%s), check retry err: %d/(%d/%s).", keynode->keyname, preference_errno, io_errno, err_buf);
return 0;
}
}
int retry_cnt = 0;
size_t keyname_len = 0;
-retry_open :
+retry_open:
errno = 0;
err_no = 0;
func_ret = PREFERENCE_ERROR_NONE;
ret = _preference_get_key_path(keynode, path);
retv_if(ret != PREFERENCE_ERROR_NONE, ret);
- if( (fp = fopen(path, "r+")) == NULL ) {
+ if ((fp = fopen(path, "r+")) == NULL) {
func_ret = PREFERENCE_ERROR_FILE_OPEN;
err_no = errno;
goto out_return;
}
-retry :
+retry:
errno = 0;
err_no = 0;
func_ret = PREFERENCE_ERROR_NONE;
if (ret <= 0) is_write_error = 1;
break;
case PREFERENCE_TYPE_STRING:
- ret = fprintf(fp,"%s",keynode->value.s);
- if (ret < strlen(keynode->value.s)) is_write_error = 1;
+ ret = fprintf(fp, "%s", keynode->value.s);
+ if (ret < strlen(keynode->value.s))
+ is_write_error = 1;
if (ftruncate(fileno(fp), ret) == -1)
is_write_error = 1;
break;
- default :
+ default:
func_ret = PREFERENCE_ERROR_WRONG_TYPE;
goto out_unlock;
}
fflush(fp);
-out_unlock :
+out_unlock:
ret = _preference_set_unlock(fileno(fp));
if (ret == -1) {
func_ret = PREFERENCE_ERROR_FILE_LOCK;
goto out_return;
}
-out_return :
+out_return:
if (func_ret != PREFERENCE_ERROR_NONE) {
strerror_r(err_no, err_buf, 100);
if (_preference_check_retry_err(keynode, func_ret, err_no, PREFERENCE_OP_SET)) {
} else {
ERR("_preference_set_key_filesys(%d-%s) step(%d) failed(%d / %s)\n", keynode->type, keynode->keyname, func_ret, err_no, err_buf);
}
- } else {
- if(retry_cnt > 0) {
- DBG("_preference_set_key_filesys ok with retry cnt(%d)", retry_cnt);
- }
+ } else if (retry_cnt > 0) {
+ DBG("_preference_set_key_filesys ok with retry cnt(%d)", retry_cnt);
}
if (fp) {
int retry_cnt = 0;
int read_size = 0;
size_t keyname_len = 0;
+ int value_int = 0;
+ double value_dbl = 0;
+ char file_buf[BUF_LEN] = {0,};
+ char *value = NULL;
+ int value_size = 0;
-retry_open :
+retry_open:
errno = 0;
func_ret = PREFERENCE_ERROR_NONE;
ret = _preference_get_key_path(keynode, path);
retv_if(ret != PREFERENCE_ERROR_NONE, ret);
- if( (fp = fopen(path, "r")) == NULL ) {
+ if ((fp = fopen(path, "r")) == NULL) {
func_ret = PREFERENCE_ERROR_FILE_OPEN;
err_no = errno;
goto out_return;
}
-retry :
+retry:
err_no = 0;
func_ret = PREFERENCE_ERROR_NONE;
read_size = fread((void *)&keyname_len, sizeof(int), 1, fp);
if ((read_size <= 0) || (read_size > sizeof(int))) {
- if(!ferror(fp)) {
+ if (!ferror(fp))
errno = ENODATA;
- }
+
err_no = errno;
func_ret = PREFERENCE_ERROR_FILE_FREAD;
goto out_unlock;
ret = fseek(fp, keyname_len, SEEK_CUR);
if (ret) {
- if(!ferror(fp)) {
+ if (!ferror(fp))
errno = ENODATA;
- }
+
err_no = errno;
func_ret = PREFERENCE_ERROR_FILE_FREAD;
goto out_unlock;
read_size = fread((void *)&type, sizeof(int), 1, fp);
if (read_size <= 0) {
- if(!ferror(fp)) {
+ if (!ferror(fp))
errno = ENODATA;
- }
+
err_no = errno;
func_ret = PREFERENCE_ERROR_FILE_FREAD;
goto out_unlock;
}
/* read data value */
- switch(type)
- {
- case PREFERENCE_TYPE_INT:
- {
- int value_int = 0;
- read_size = fread((void*)&value_int, sizeof(int), 1, fp);
- if ((read_size <= 0) || (read_size > sizeof(int))) {
- if (!ferror(fp)) {
- LOGW("number of read items for value is wrong. err : %d", errno);
- }
- err_no = errno;
- func_ret = PREFERENCE_ERROR_FILE_FREAD;
- goto out_unlock;
- } else {
- _preference_keynode_set_value_int(keynode, value_int);
- }
-
- break;
+ switch (type) {
+ case PREFERENCE_TYPE_INT:
+ read_size = fread((void*)&value_int, sizeof(int), 1, fp);
+ if ((read_size <= 0) || (read_size > sizeof(int))) {
+ if (!ferror(fp))
+ LOGW("number of read items for value is wrong. err : %d", errno);
+
+ err_no = errno;
+ func_ret = PREFERENCE_ERROR_FILE_FREAD;
+ goto out_unlock;
+ } else {
+ _preference_keynode_set_value_int(keynode, value_int);
}
- case PREFERENCE_TYPE_DOUBLE:
- {
- double value_dbl = 0;
- read_size = fread((void*)&value_dbl, sizeof(double), 1, fp);
- if ((read_size <= 0) || (read_size > sizeof(double))) {
- if (!ferror(fp)) {
- LOGW("number of read items for value is wrong. err : %d", errno);
- }
- err_no = errno;
- func_ret = PREFERENCE_ERROR_FILE_FREAD;
- goto out_unlock;
- } else {
- _preference_keynode_set_value_double(keynode, value_dbl);
- }
- break;
+ break;
+ case PREFERENCE_TYPE_DOUBLE:
+ read_size = fread((void*)&value_dbl, sizeof(double), 1, fp);
+ if ((read_size <= 0) || (read_size > sizeof(double))) {
+ if (!ferror(fp))
+ LOGW("number of read items for value is wrong. err : %d", errno);
+
+ err_no = errno;
+ func_ret = PREFERENCE_ERROR_FILE_FREAD;
+ goto out_unlock;
+ } else {
+ _preference_keynode_set_value_double(keynode, value_dbl);
}
- case PREFERENCE_TYPE_BOOLEAN:
- {
- int value_int = 0;
- read_size = fread((void*)&value_int, sizeof(int), 1, fp);
- if ((read_size <= 0) || (read_size > sizeof(int))) {
- if (!ferror(fp)) {
- LOGW("number of read items for value is wrong. err : %d", errno);
- }
- err_no = errno;
- func_ret = PREFERENCE_ERROR_FILE_FREAD;
- goto out_unlock;
- } else {
- _preference_keynode_set_value_boolean(keynode, value_int);
- }
- break;
+ break;
+ case PREFERENCE_TYPE_BOOLEAN:
+ read_size = fread((void*)&value_int, sizeof(int), 1, fp);
+ if ((read_size <= 0) || (read_size > sizeof(int))) {
+ if (!ferror(fp))
+ LOGW("number of read items for value is wrong. err : %d", errno);
+
+ err_no = errno;
+ func_ret = PREFERENCE_ERROR_FILE_FREAD;
+ goto out_unlock;
+ } else {
+ _preference_keynode_set_value_boolean(keynode, value_int);
}
- case PREFERENCE_TYPE_STRING:
- {
- char file_buf[BUF_LEN] = {0,};
- char *value = NULL;
- int value_size = 0;
-
- while(fgets(file_buf, sizeof(file_buf), fp))
- {
- if (value) {
- value_size = value_size + strlen(file_buf);
- value = (char *) realloc(value, value_size);
- if (value == NULL) {
- func_ret = PREFERENCE_ERROR_OUT_OF_MEMORY;
- break;
- }
- strncat(value, file_buf, strlen(file_buf));
- } else {
- value_size = strlen(file_buf) + 1;
- value = (char *)malloc(value_size);
- if (value == NULL) {
- func_ret = PREFERENCE_ERROR_OUT_OF_MEMORY;
- break;
- }
- memset(value, 0x00, value_size);
- strncpy(value, file_buf, strlen(file_buf));
- }
- }
- if (ferror(fp)) {
- err_no = errno;
- func_ret = PREFERENCE_ERROR_FILE_FGETS;
+ break;
+ case PREFERENCE_TYPE_STRING:
+ while (fgets(file_buf, sizeof(file_buf), fp)) {
+ if (value) {
+ value_size = value_size + strlen(file_buf);
+ value = (char *) realloc(value, value_size);
+ if (value == NULL) {
+ func_ret = PREFERENCE_ERROR_OUT_OF_MEMORY;
+ break;
+ }
+ strncat(value, file_buf, strlen(file_buf));
} else {
- if (value) {
- _preference_keynode_set_value_string(keynode, value);
- } else {
- _preference_keynode_set_value_string(keynode, "");
+ value_size = strlen(file_buf) + 1;
+ value = (char *)malloc(value_size);
+ if (value == NULL) {
+ func_ret = PREFERENCE_ERROR_OUT_OF_MEMORY;
+ break;
}
+ memset(value, 0x00, value_size);
+ strncpy(value, file_buf, strlen(file_buf));
}
- if (value)
- free(value);
+ }
- break;
+ if (ferror(fp)) {
+ err_no = errno;
+ func_ret = PREFERENCE_ERROR_FILE_FGETS;
+ } else {
+ if (value)
+ _preference_keynode_set_value_string(keynode, value);
+ else
+ _preference_keynode_set_value_string(keynode, "");
}
- default :
- func_ret = PREFERENCE_ERROR_WRONG_TYPE;
+ if (value)
+ free(value);
+
+ break;
+ default:
+ func_ret = PREFERENCE_ERROR_WRONG_TYPE;
}
-out_unlock :
+out_unlock:
ret = _preference_set_unlock(fileno(fp));
if (ret == -1) {
func_ret = PREFERENCE_ERROR_FILE_LOCK;
}
-out_return :
+out_return:
if (func_ret != PREFERENCE_ERROR_NONE) {
strerror_r(err_no, err_buf, 100);
goto retry;
else
goto retry_open;
- }
- else {
+ } else {
ERR("_preference_get_key_filesys(%s) step(%d) faild(%d / %s) over the retry count.",
keynode->keyname, func_ret, err_no, err_buf);
}
if (ret == PREFERENCE_ERROR_NONE) {
g_posix_errno = PREFERENCE_ERROR_NONE;
g_preference_errno = PREFERENCE_ERROR_NONE;
- }
- else {
+ } else {
if (io_errno == ENOENT)
ret = PREFERENCE_ERROR_NO_KEY;
else
func_ret = PREFERENCE_ERROR_INVALID_PARAMETER;
}
- if(tempstr) {
+ if (tempstr) {
*value = strdup(tempstr);
INFO("%s(%s) success", key, value);
}
do {
ret = remove(path);
- if(ret == -1) {
+ if (ret == -1) {
char err_buf[ERR_LEN] = {0,};
strerror_r(errno, err_buf, sizeof(err_buf));
ERR("preference_remove() failed. ret=%d(%s), key(%s)", errno, err_buf, key);
func_ret = PREFERENCE_ERROR_NONE;
break;
}
- } while(err_retry--);
+ } while (err_retry--);
END_TIME_CHECK;
char err_buf[ERR_LEN] = {0,};
pref_dir_path = _preference_get_pref_dir_path();
- if (!pref_dir_path)
- {
+ if (!pref_dir_path) {
LOGE("_preference_get_pref_dir_path() failed.");
return PREFERENCE_ERROR_IO_ERROR;
}
dir = opendir(pref_dir_path);
- if (dir == NULL)
- {
+ if (dir == NULL) {
strerror_r(errno, err_buf, sizeof(err_buf));
LOGE("opendir() failed. pref_path: %s, error: %d(%s)", pref_dir_path, errno, err_buf);
return PREFERENCE_ERROR_IO_ERROR;
}
keynode_t* pKeyNode = _preference_keynode_new();
- if (pKeyNode == NULL)
- {
+ if (pKeyNode == NULL) {
ERR("key malloc fail");
closedir(dir);
return PREFERENCE_ERROR_OUT_OF_MEMORY;
}
- while (readdir_r(dir, &dent, &result) == 0 && result != NULL)
- {
+ while (readdir_r(dir, &dent, &result) == 0 && result != NULL) {
const char *entry = dent.d_name;
char *keyname = NULL;
char path[PATH_MAX] = {0,};
- if (entry[0] == '.') {
+ if (entry[0] == '.')
continue;
- }
snprintf(path, PATH_MAX-1, "%s%s", pref_dir_path, entry);
func_ret = PREFERENCE_ERROR_NONE;
break;
}
- } while(err_retry--);
+ } while (err_retry--);
free(keyname);
}
LOGE("NO_KEY(0x%08x) : fail to find given key(%s)", PREFERENCE_ERROR_NO_KEY, key);
_preference_keynode_free(pKeyNode);
return PREFERENCE_ERROR_NO_KEY;
- } else if(errno != 0) {
+ } else if (errno != 0) {
ERR("preference_notify_key_changed : key(%s) add notify fail", key);
_preference_keynode_free(pKeyNode);
return PREFERENCE_ERROR_IO_ERROR;
return PREFERENCE_ERROR_IO_ERROR;
}
- while(readdir_r(dir, &dent, &result) == 0 && result != NULL) {
+ while (readdir_r(dir, &dent, &result) == 0 && result != NULL) {
const char *entry = dent.d_name;
char *keyname = NULL;
char path[PATH_MAX] = {0,};
- if (entry[0] == '.') {
+ if (entry[0] == '.')
continue;
- }
snprintf(path, PATH_MAX-1, "%s%s", pref_dir_path, entry);
static void _finish(void *data)
{
- if (pref_db != NULL)
- {
+ if (pref_db != NULL) {
sqlite3_close(pref_db);
pref_db = NULL;
}
static int _busy_handler(void *pData, int count)
{
- if(5 - count > 0) {
- LOGD("Busy Handler Called! : PID(%d) / CNT(%d)\n", getpid(), count+1);
- usleep((count+1)*100000);
+ if (5 - count > 0) {
+ LOGD("Busy Handler Called! : PID(%d) / CNT(%d)\n", getpid(), count + 1);
+ usleep((count + 1) * 100000);
return 1;
} else {
LOGD("Busy Handler will be returned SQLITE_BUSY error : PID(%d) \n", getpid());
int ret;
char *errmsg;
- if ((data_path = app_get_data_path()) == NULL)
- {
+ if ((data_path = app_get_data_path()) == NULL) {
LOGE("IO_ERROR(0x%08x) : fail to get data directory", PREFERENCE_ERROR_IO_ERROR);
return PREFERENCE_ERROR_IO_ERROR;
}
free(data_path);
ret = sqlite3_open(db_path, &pref_db);
- if (ret != SQLITE_OK)
- {
+ if (ret != SQLITE_OK) {
LOGE("IO_ERROR(0x%08x) : fail to open db(%s)", PREFERENCE_ERROR_IO_ERROR, sqlite3_errmsg(pref_db));
pref_db = NULL;
return PREFERENCE_ERROR_IO_ERROR;
}
ret = sqlite3_busy_handler(pref_db, _busy_handler, NULL);
- if (ret != SQLITE_OK) {
+ if (ret != SQLITE_OK)
LOGW("IO_ERROR(0x%08x) : fail to register busy handler(%s)\n", PREFERENCE_ERROR_IO_ERROR, sqlite3_errmsg(pref_db));
- }
ret = sqlite3_exec(pref_db, "CREATE TABLE IF NOT EXISTS pref ( pref_key TEXT PRIMARY KEY, pref_type TEXT, pref_data TEXT)",
- NULL, NULL, &errmsg);
- if (ret != SQLITE_OK)
- {
+ NULL, NULL, &errmsg);
+ if (ret != SQLITE_OK) {
LOGE("IO_ERROR(0x%08x) : fail to create db table(%s)", PREFERENCE_ERROR_IO_ERROR, errmsg);
sqlite3_free(errmsg);
sqlite3_close(pref_db);
bool exist = false;
sqlite3_stmt *stmt;
- if (key == NULL || key[0] == '\0' || data == NULL)
- {
+ if (key == NULL || key[0] == '\0' || data == NULL) {
LOGE("INVALID_PARAMETER(0x%08x)", PREFERENCE_ERROR_INVALID_PARAMETER);
return PREFERENCE_ERROR_INVALID_PARAMETER;
}
/* insert data or update data if data already exist */
ret = preference_is_existing(key, &exist);
if (ret != PREFERENCE_ERROR_NONE)
- {
return ret;
- }
- // to use sqlite3_update_hook, we have to use INSERT/UPDATE operation instead of REPLACE operation
+ /* to use sqlite3_update_hook, we have to use INSERT/UPDATE operation instead of REPLACE operation */
if (exist)
- {
buf = sqlite3_mprintf("UPDATE %s SET %s=?, %s=? WHERE %s=?;",
PREF_TBL_NAME, PREF_F_TYPE_NAME, PREF_F_DATA_NAME, PREF_F_KEY_NAME);
- }
else
- {
buf = sqlite3_mprintf("INSERT INTO %s (%s, %s, %s) values (?, ?, ?);",
PREF_TBL_NAME, PREF_F_KEY_NAME, PREF_F_TYPE_NAME, PREF_F_DATA_NAME);
- }
- if (buf == NULL)
- {
+ if (buf == NULL) {
LOGE("IO_ERROR(0x%08x) : fail to create query string", PREFERENCE_ERROR_IO_ERROR);
return PREFERENCE_ERROR_IO_ERROR;
}
return PREFERENCE_ERROR_IO_ERROR;
}
- if(exist)
- {
+ if (exist) {
ret = sqlite3_bind_text(stmt, 1, type, strlen(type), SQLITE_STATIC);
- if(ret != SQLITE_OK) {
+ if (ret != SQLITE_OK) {
LOGE("IO_ERROR(0x%08x) : fail to bind(1) query (%d/%s)",
PREFERENCE_ERROR_IO_ERROR,
sqlite3_extended_errcode(pref_db),
return PREFERENCE_ERROR_IO_ERROR;
}
ret = sqlite3_bind_text(stmt, 2, data, strlen(data), SQLITE_STATIC);
- if(ret != SQLITE_OK) {
+ if (ret != SQLITE_OK) {
LOGE("IO_ERROR(0x%08x) : fail to bind(2) query (%d/%s)",
PREFERENCE_ERROR_IO_ERROR,
sqlite3_extended_errcode(pref_db),
return PREFERENCE_ERROR_IO_ERROR;
}
ret = sqlite3_bind_text(stmt, 3, key, strlen(key), SQLITE_STATIC);
- if(ret != SQLITE_OK) {
+ if (ret != SQLITE_OK) {
LOGE("IO_ERROR(0x%08x) : fail to bind(3) query (%d/%s)",
PREFERENCE_ERROR_IO_ERROR,
sqlite3_extended_errcode(pref_db),
sqlite3_finalize(stmt);
return PREFERENCE_ERROR_IO_ERROR;
}
- }
- else
- {
+ } else {
ret = sqlite3_bind_text(stmt, 1, key, strlen(key), SQLITE_STATIC);
- if(ret != SQLITE_OK) {
+ if (ret != SQLITE_OK) {
LOGE("IO_ERROR(0x%08x) : fail to bind(1) query (%d/%s)",
PREFERENCE_ERROR_IO_ERROR,
sqlite3_extended_errcode(pref_db),
return PREFERENCE_ERROR_IO_ERROR;
}
ret = sqlite3_bind_text(stmt, 2, type, strlen(type), SQLITE_STATIC);
- if(ret != SQLITE_OK) {
+ if (ret != SQLITE_OK) {
LOGE("IO_ERROR(0x%08x) : fail to bind(2) query (%d/%s)",
PREFERENCE_ERROR_IO_ERROR,
sqlite3_extended_errcode(pref_db),
return PREFERENCE_ERROR_IO_ERROR;
}
ret = sqlite3_bind_text(stmt, 3, data, strlen(data), SQLITE_STATIC);
- if(ret != SQLITE_OK) {
+ if (ret != SQLITE_OK) {
LOGE("IO_ERROR(0x%08x) : fail to bind(3) query (%d/%s)",
PREFERENCE_ERROR_IO_ERROR,
sqlite3_extended_errcode(pref_db),
}
sqlite3_finalize(stmt);
- if(buf) {
+ if (buf) {
sqlite3_free(buf);
buf = NULL;
}
return PREFERENCE_ERROR_NONE;
}
-//static int _read_data(const char *key, preference_type_e *type, char *data)
+/* static int _read_data(const char *key, preference_type_e *type, char *data) */
static int _read_data(const char *key, char *type, char *data)
{
int ret;
int columns;
char *errmsg;
- if (key == NULL || key[0] == '\0' || data == NULL)
- {
+ if (key == NULL || key[0] == '\0' || data == NULL) {
LOGE("INVALID_PARAMETER(0x%08x)", PREFERENCE_ERROR_INVALID_PARAMETER);
return PREFERENCE_ERROR_INVALID_PARAMETER;
}
- if (pref_db == NULL)
- {
- if (_initialize() != PREFERENCE_ERROR_NONE)
- {
+ if (pref_db == NULL) {
+ if (_initialize() != PREFERENCE_ERROR_NONE) {
LOGE("IO_ERROR(0x%08x) : fail to initialize db", PREFERENCE_ERROR_IO_ERROR);
return PREFERENCE_ERROR_IO_ERROR;
}
buf = sqlite3_mprintf("SELECT %s, %s, %s FROM %s WHERE %s=%Q;",
PREF_F_KEY_NAME, PREF_F_TYPE_NAME, PREF_F_DATA_NAME, PREF_TBL_NAME, PREF_F_KEY_NAME, key);
-
- if (buf == NULL)
- {
+ if (buf == NULL) {
LOGE("IO_ERROR(0x%08x) : fail to create query string", PREFERENCE_ERROR_IO_ERROR);
return PREFERENCE_ERROR_IO_ERROR;
}
ret = sqlite3_get_table(pref_db, buf, &result, &rows, &columns, &errmsg);
sqlite3_free(buf);
- if (ret != SQLITE_OK)
- {
+ if (ret != SQLITE_OK) {
LOGE("IO_ERROR(0x%08x) : fail to read data (%s)", PREFERENCE_ERROR_IO_ERROR, errmsg);
sqlite3_free(errmsg);
return PREFERENCE_ERROR_IO_ERROR;
}
- if (rows == 0)
- {
+ if (rows == 0) {
LOGE("NO_KEY(0x%08x) : fail to find given key(%s)", PREFERENCE_ERROR_NO_KEY, key);
sqlite3_free_table(result);
return PREFERENCE_ERROR_NO_KEY;
}
- snprintf(type, 2, "%s", result[4]); // get type value
- snprintf(data, BUF_LEN, "%s", result[5]); // get data value
+ snprintf(type, 2, "%s", result[4]); /* get type value */
+ snprintf(data, BUF_LEN, "%s", result[5]); /* get data value */
sqlite3_free_table(result);
}
ret = _read_data(key, type, data);
- if (ret == PREFERENCE_ERROR_NONE)
- {
+ if (ret == PREFERENCE_ERROR_NONE) {
if (atoi(type) == PREFERENCE_TYPE_INT)
- {
*value = atoi(data);
- }
- else
- {
+ else {
LOGE("INVALID_PARAMETER(0x%08x) : param type(%d)", PREFERENCE_ERROR_INVALID_PARAMETER, atoi(type));
return PREFERENCE_ERROR_INVALID_PARAMETER;
}
}
ret = _read_data(key, type, data);
- if (ret == PREFERENCE_ERROR_NONE)
- {
- if (atoi(type) == PREFERENCE_TYPE_DOUBLE)
- {
+ if (ret == PREFERENCE_ERROR_NONE) {
+ if (atoi(type) == PREFERENCE_TYPE_DOUBLE) {
locale_t loc = newlocale(LC_NUMERIC_MASK, "C", NULL);
uselocale(loc);
freelocale(loc);
uselocale(LC_GLOBAL_LOCALE);
- }
- else
- {
+ } else {
LOGE("INVALID_PARAMETER(0x%08x) : param type(%d)", PREFERENCE_ERROR_INVALID_PARAMETER, atoi(type));
return PREFERENCE_ERROR_INVALID_PARAMETER;
}
char type[2];
snprintf(type, 2, "%d", PREFERENCE_TYPE_STRING);
- if (strlen(value) > (BUF_LEN-1))
- {
+ if (strlen(value) > (BUF_LEN-1)) {
LOGE("INVALID_PARAMETER(0x%08x) : param type(%d)", PREFERENCE_ERROR_INVALID_PARAMETER, atoi(type));
return PREFERENCE_ERROR_INVALID_PARAMETER;
}
int ret;
- if (value == NULL)
- {
+ if (value == NULL) {
LOGE("INVALID_PARAMETER(0x%08x)", PREFERENCE_ERROR_INVALID_PARAMETER);
return PREFERENCE_ERROR_INVALID_PARAMETER;
}
ret = _read_data(key, type, data);
- if (ret == PREFERENCE_ERROR_NONE)
- {
- if (atoi(type) == PREFERENCE_TYPE_STRING)
- {
+ if (ret == PREFERENCE_ERROR_NONE) {
+ if (atoi(type) == PREFERENCE_TYPE_STRING) {
*value = strdup(data);
- if (value == NULL)
- {
+ if (value == NULL) {
LOGE("OUT_OF_MEMORY(0x%08x)", PREFERENCE_ERROR_OUT_OF_MEMORY);
return PREFERENCE_ERROR_OUT_OF_MEMORY;
}
- }
- else
- {
+ } else {
LOGE("INVALID_PARAMETER(0x%08x) : param type(%d)", PREFERENCE_ERROR_INVALID_PARAMETER, atoi(type));
return PREFERENCE_ERROR_INVALID_PARAMETER;
}
{
char type[2];
char data[BUF_LEN];
+
snprintf(type, 2, "%d", PREFERENCE_TYPE_BOOLEAN);
snprintf(data, BUF_LEN, "%d", value);
+
return _write_data(key, type, data);
}
{
char type[2];
char data[BUF_LEN];
-
int ret;
if (value == NULL) {
}
ret = _read_data(key, type, data);
- if (ret == PREFERENCE_ERROR_NONE)
- {
+ if (ret == PREFERENCE_ERROR_NONE) {
if (atoi(type) == PREFERENCE_TYPE_BOOLEAN)
- {
*value = (bool)atoi(data);
- }
- else
- {
+ else {
LOGE("INVALID_PARAMETER(0x%08x) : param type(%d)", PREFERENCE_ERROR_INVALID_PARAMETER, atoi(type));
return PREFERENCE_ERROR_INVALID_PARAMETER;
}
return ret;
}
-
-// TODO: below operation is too heavy, let's find the light way to check.
+/* TODO: below operation is too heavy, let's find the light way to check. */
int preference_is_existing(const char *key, bool *exist)
{
int ret;
int columns;
char *errmsg;
- if (key == NULL || key[0] == '\0' || exist == NULL)
- {
+ if (key == NULL || key[0] == '\0' || exist == NULL) {
LOGE("INVALID_PARAMETER(0x%08x)", PREFERENCE_ERROR_INVALID_PARAMETER);
return PREFERENCE_ERROR_INVALID_PARAMETER;
}
- if (pref_db == NULL)
- {
- if (_initialize() != PREFERENCE_ERROR_NONE)
- {
+ if (pref_db == NULL) {
+ if (_initialize() != PREFERENCE_ERROR_NONE) {
LOGE("IO_ERROR(0x%08x) : fail to initialize db", PREFERENCE_ERROR_IO_ERROR);
return PREFERENCE_ERROR_IO_ERROR;
}
/* check data is exist */
buf = sqlite3_mprintf("SELECT %s FROM %s WHERE %s=%Q;", PREF_F_KEY_NAME, PREF_TBL_NAME, PREF_F_KEY_NAME, key);
-
- if (buf == NULL)
- {
+ if (buf == NULL) {
LOGE("IO_ERROR(0x%08x) : fail to create query string", PREFERENCE_ERROR_IO_ERROR);
return PREFERENCE_ERROR_IO_ERROR;
}
ret = sqlite3_get_table(pref_db, buf, &result, &rows, &columns, &errmsg);
sqlite3_free(buf);
- if (ret != SQLITE_OK)
- {
+ if (ret != SQLITE_OK) {
LOGE("IO_ERROR(0x%08x) : fail to read data(%s)", PREFERENCE_ERROR_IO_ERROR, errmsg);
sqlite3_free(errmsg);
return PREFERENCE_ERROR_IO_ERROR;
}
if (rows > 0)
- {
*exist = true;
- }
else
- {
*exist = false;
- }
sqlite3_free_table(result);
return PREFERENCE_ERROR_NONE;
{
pref_changed_cb_node_t *tmp_node;
- if (key == NULL || key[0] == '\0' )
- {
+ if (key == NULL || key[0] == '\0')
return NULL;
- }
tmp_node = head;
-
- while (tmp_node)
- {
+ while (tmp_node) {
if (strcmp(tmp_node->key, key) == 0)
- {
break;
- }
+
tmp_node = tmp_node->next;
}
return tmp_node;
}
-
static int _add_node(const char *key, preference_changed_cb cb, void *user_data)
{
pref_changed_cb_node_t *tmp_node;
- if (key == NULL || key[0] == '\0' || cb == NULL)
- {
+ if (key == NULL || key[0] == '\0' || cb == NULL) {
LOGE("INVALID_PARAMETER(0x%08x)", PREFERENCE_ERROR_INVALID_PARAMETER);
return PREFERENCE_ERROR_INVALID_PARAMETER;
}
tmp_node = _find_node(key);
-
- if (tmp_node != NULL)
- {
+ if (tmp_node != NULL) {
tmp_node->cb = cb;
tmp_node->user_data = user_data;
- }
- else
- {
+ } else {
tmp_node = (pref_changed_cb_node_t*)malloc(sizeof(pref_changed_cb_node_t));
- if (tmp_node == NULL)
- {
+ if (tmp_node == NULL) {
LOGE("OUT_OF_MEMORY(0x%08x)", PREFERENCE_ERROR_OUT_OF_MEMORY);
return PREFERENCE_ERROR_OUT_OF_MEMORY;
}
tmp_node->key = strdup(key);
- if (tmp_node->key == NULL)
- {
+ if (tmp_node->key == NULL) {
free(tmp_node);
LOGE("OUT_OF_MEMORY(0x%08x)", PREFERENCE_ERROR_OUT_OF_MEMORY);
return PREFERENCE_ERROR_OUT_OF_MEMORY;
{
pref_changed_cb_node_t *tmp_node;
- if (key == NULL || key[0] == '\0' )
- {
+ if (key == NULL || key[0] == '\0') {
LOGE("INVALID_PARAMETER(0x%08x)", PREFERENCE_ERROR_INVALID_PARAMETER);
return PREFERENCE_ERROR_INVALID_PARAMETER;
}
tmp_node = _find_node(key);
-
if (tmp_node == NULL)
- {
return PREFERENCE_ERROR_NONE;
- }
if (tmp_node->prev != NULL)
- {
tmp_node->prev->next = tmp_node->next;
- }
else
- {
head = tmp_node->next;
- }
if (tmp_node->next != NULL)
- {
tmp_node->next->prev = tmp_node->prev;
- }
if (tmp_node->key)
- {
free(tmp_node->key);
- }
free(tmp_node);
return PREFERENCE_ERROR_NONE;
}
-
static void _remove_all_node(void)
{
pref_changed_cb_node_t *tmp_node;
- while (head)
- {
+ while (head) {
tmp_node = head;
head = tmp_node->next;
if (tmp_node->key)
- {
free(tmp_node->key);
- }
free(tmp_node);
}
}
-
static void _update_cb(void *data, int action, char const *db_name, char const *table_name, sqlite_int64 rowid)
{
int ret;
char *errmsg;
pref_changed_cb_node_t *tmp_node;
- // skip INSERT/DELETE event
+ /* skip INSERT/DELETE event */
if (action != SQLITE_UPDATE)
- {
return;
- }
- if (strcmp(table_name, PREF_TBL_NAME) != 0)
- {
+ if (strcmp(table_name, PREF_TBL_NAME) != 0) {
SECURE_LOGE("given table name (%s) is not same", table_name);
return;
}
buf = sqlite3_mprintf("SELECT %s FROM %s WHERE rowid='%lld';", PREF_F_KEY_NAME, PREF_TBL_NAME, rowid);
if (buf == NULL)
- {
return;
- }
+
ret = sqlite3_get_table(pref_db, buf, &result, &rows, &columns, &errmsg);
sqlite3_free(buf);
- if (ret != SQLITE_OK)
- {
+ if (ret != SQLITE_OK) {
LOGI("fail to read data(%s)", errmsg);
sqlite3_free(errmsg);
return;
}
- if (rows == 0)
- {
+ if (rows == 0) {
sqlite3_free_table(result);
return;
}
tmp_node = _find_node(result[1]);
-
if (tmp_node != NULL && tmp_node->cb != NULL)
- {
tmp_node->cb(result[1], tmp_node->user_data);
- }
sqlite3_free_table(result);
}
-
int preference_remove(const char *key)
{
int ret;
ret = preference_is_existing(key, &exist);
if (ret != PREFERENCE_ERROR_NONE)
- {
return ret;
- }
if (!exist)
- {
return PREFERENCE_ERROR_NO_KEY;
- }
/* insert data or update data if data already exist */
buf = sqlite3_mprintf("DELETE FROM %s WHERE %s = ?",
PREF_TBL_NAME, PREF_F_KEY_NAME, key);
- if (buf == NULL)
- {
+ if (buf == NULL) {
LOGE("IO_ERROR(0x%08x) : fail to create query string", PREFERENCE_ERROR_IO_ERROR);
return PREFERENCE_ERROR_IO_ERROR;
}
}
ret = sqlite3_bind_text(stmt, 1, key, strlen(key), SQLITE_STATIC);
- if(ret != SQLITE_OK) {
+ if (ret != SQLITE_OK) {
LOGE("IO_ERROR(0x%08x) : fail to bind(1) query (%d/%s)",
PREFERENCE_ERROR_IO_ERROR,
sqlite3_extended_errcode(pref_db),
}
sqlite3_finalize(stmt);
- if(buf) {
+ if (buf) {
sqlite3_free(buf);
buf = NULL;
}
- // if exist, remove changed cb
- _remove_node(key);
+ /* if exist, remove changed cb */
+ _remove_node(key);
return PREFERENCE_ERROR_NONE;
}
-
int preference_remove_all(void)
{
int ret;
char *buf;
char *errmsg;
- if (pref_db == NULL)
- {
- if (_initialize() != PREFERENCE_ERROR_NONE)
- {
+ if (pref_db == NULL) {
+ if (_initialize() != PREFERENCE_ERROR_NONE) {
LOGE("IO_ERROR(0x%08x) : fail to initialize db", PREFERENCE_ERROR_IO_ERROR);
return PREFERENCE_ERROR_IO_ERROR;
}
/* insert data or update data if data already exist */
buf = sqlite3_mprintf("DELETE FROM %s;", PREF_TBL_NAME);
- if (buf == NULL)
- {
+ if (buf == NULL) {
LOGE("IO_ERROR(0x%08x) : fail to create query string", PREFERENCE_ERROR_IO_ERROR);
return PREFERENCE_ERROR_IO_ERROR;
}
ret = sqlite3_exec(pref_db, buf, NULL, NULL, &errmsg);
sqlite3_free(buf);
- if (ret != SQLITE_OK)
- {
+ if (ret != SQLITE_OK) {
LOGE("IO_ERROR(0x%08x) : fail to delete data (%s)", PREFERENCE_ERROR_IO_ERROR, errmsg);
sqlite3_free(errmsg);
return PREFERENCE_ERROR_IO_ERROR;
}
- // if exist, remove changed cb
+ /* if exist, remove changed cb */
_remove_all_node();
return PREFERENCE_ERROR_NONE;
}
-
int preference_set_changed_cb(const char *key, preference_changed_cb callback, void *user_data)
{
int ret;
ret = preference_is_existing(key, &exist);
if (ret != PREFERENCE_ERROR_NONE)
- {
return ret;
- }
- if (!exist)
- {
+ if (!exist) {
LOGE("NO_KEY(0x%08x) : fail to find given key(%s)", PREFERENCE_ERROR_NO_KEY, key);
return PREFERENCE_ERROR_NO_KEY;
}
- if (!is_update_hook_registered)
- {
+ if (!is_update_hook_registered) {
sqlite3_update_hook(pref_db, _update_cb, NULL);
is_update_hook_registered = true;
}
ret = preference_is_existing(key, &exist);
if (ret != PREFERENCE_ERROR_NONE)
- {
return ret;
- }
- if (!exist)
- {
+ if (!exist) {
LOGE("NO_KEY(0x%08x) : fail to find given key(%s)", PREFERENCE_ERROR_NO_KEY, key);
return PREFERENCE_ERROR_NO_KEY;
}
char *errmsg;
int i;
- if (callback == NULL)
- {
+ if (callback == NULL) {
LOGE("INVALID_PARAMETER(0x%08x)", PREFERENCE_ERROR_INVALID_PARAMETER);
return PREFERENCE_ERROR_INVALID_PARAMETER;
}
- if (pref_db == NULL)
- {
- if (_initialize() != PREFERENCE_ERROR_NONE)
- {
+ if (pref_db == NULL) {
+ if (_initialize() != PREFERENCE_ERROR_NONE) {
LOGE("IO_ERROR(0x%08x) : fail to initialize db", PREFERENCE_ERROR_IO_ERROR);
return PREFERENCE_ERROR_IO_ERROR;
}
}
buf = sqlite3_mprintf("SELECT %s FROM %s;", PREF_F_KEY_NAME, PREF_TBL_NAME);
- if (buf == NULL)
- {
+ if (buf == NULL) {
LOGE("IO_ERROR(0x%08x) : fail to create query string", PREFERENCE_ERROR_IO_ERROR);
return PREFERENCE_ERROR_IO_ERROR;
}
ret = sqlite3_get_table(pref_db, buf, &result, &rows, &columns, &errmsg);
sqlite3_free(buf);
- if (ret != SQLITE_OK)
- {
+ if (ret != SQLITE_OK) {
LOGE("IO_ERROR(0x%08x) : fail to read data (%s)", PREFERENCE_ERROR_IO_ERROR, errmsg);
sqlite3_free(errmsg);
return PREFERENCE_ERROR_IO_ERROR;
}
- for (i = 1; i <= rows; i++)
- {
+ for (i = 1; i <= rows; i++) {
if (callback(result[i], user_data) != true)
- {
break;
- }
}
sqlite3_free_table(result);
return PREFERENCE_ERROR_NONE;
}
-
break;
}
- if ( (t) && (t->wd == ie.wd) && (t->keyname) ) {
+ if ((t) && (t->wd == ie.wd) && (t->keyname)) {
res = _preference_keynode_set_keyname(keynode, t->keyname);
if (res != PREFERENCE_ERROR_NONE) {
goto out_func;
}
- if ((ie.mask & IN_DELETE_SELF))
- {
+ if ((ie.mask & IN_DELETE_SELF)) {
res = _preference_kdb_del_notify(keynode);
if (res != PREFERENCE_ERROR_NONE)
ERR("_preference_kdb_del_notify() failed(%d)", res);
- }
- else
- {
+ } else {
res = _preference_get_key(keynode);
if (res != PREFERENCE_ERROR_NONE)
ERR("_preference_get_key() failed(%d)", res);
INFO("key(%s) is changed. cb(%p) called", t->keyname, t->cb);
t->cb(t->keyname, t->cb_data);
}
- }
- else if ( (t) && (t->keyname == NULL) ) { /* for debugging */
+ } else if ((t) && (t->keyname == NULL)) { /* for debugging */
ERR("preference keyname is null.");
}
out_func:
n->cb = cb;
g_notilist = g_list_append(g_notilist, n);
- if (!g_notilist) {
+ if (!g_notilist)
ERR("g_list_append fail");
- }
INFO("cb(%p) is added for %s. tot cb cnt : %d\n", cb, n->keyname, g_list_length(g_notilist));
t.wd = wd;
noti_list = g_list_find_custom(g_notilist, &t, (GCompareFunc)_preference_inoti_comp_with_wd);
- if(noti_list) {
+ if (noti_list) {
del++;
n = noti_list->data;
g_free(n);
r = inotify_rm_watch(_kdb_inoti_fd, wd);
- if(r == -1) {
+ if (r == -1) {
strerror_r(errno, err_buf, sizeof(err_buf));
ERR("Error: inotify_rm_watch [%s]: %s", keyname, err_buf);
func_ret = PREFERENCE_ERROR_IO_ERROR;
keyname, g_list_length(g_notilist));
}
- if(g_list_length(g_notilist) == 0) {
+ if (g_list_length(g_notilist) == 0) {
close(_kdb_inoti_fd);
_kdb_inoti_fd = 0;
pthread_mutex_unlock(&_kdb_g_ns_mutex);
- if(del == 0) {
+ if (del == 0) {
errno = ENOENT;
func_ret = PREFERENCE_ERROR_IO_ERROR;
}
* 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.
+ * limitations under the License.
*/
app_device_orientation_e dev_orientation = APP_DEVICE_ORIENTATION_0;
if (appcore_get_rotation_state(&rm) == 0)
- {
dev_orientation = app_convert_appcore_rm(rm);
- }
return dev_orientation;
}
-
* 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.
+ * limitations under the License.
*/
-
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define LOG_TAG "CAPI_APPFW_APPLICATION"
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_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 {
static int app_appcore_reset(bundle *appcore_bundle, void *data);
static int app_appcore_low_memory(void *event, void *data);
-static int app_appcore_low_battery(void *evnet, void *data);
+static int app_appcore_low_battery(void *event, void *data);
static int app_appcore_rotation_event(void *event, enum appcore_rm rm, void *data);
-static int app_appcore_lang_changed(void *evnet, void *data);
+static int app_appcore_lang_changed(void *event, void *data);
static int app_appcore_region_changed(void *event, void *data);
static void app_set_appcore_event_cb(app_context_h app_context);
static void app_unset_appcore_event_cb(void);
+int app_main(int argc, char **argv, app_event_callback_s *callback, void *user_data)
+{
+ return app_efl_main(&argc, &argv, callback, user_data);
+}
int app_efl_main(int *argc, char ***argv, app_event_callback_s *callback, void *user_data)
{
};
if (argc == NULL || argv == NULL || callback == NULL)
- {
return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
if (callback->create == NULL)
- {
return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "app_create_cb() callback must be registered");
- }
if (app_context.state != APP_STATE_NOT_RUNNING)
- {
return app_error(APP_ERROR_ALREADY_RUNNING, __FUNCTION__, NULL);
- }
if (app_get_id(&(app_context.package)) != APP_ERROR_NONE)
- {
return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package");
- }
-
- if (app_get_package_app_name(app_context.package, &(app_context.app_name)) != APP_ERROR_NONE)
- {
+
+ if (app_get_package_app_name(app_context.package, &(app_context.app_name)) != APP_ERROR_NONE) {
+ free(app_context.package);
return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package's app name");
}
return APP_ERROR_NONE;
}
+void app_exit(void)
+{
+ app_efl_exit();
+}
void app_efl_exit(void)
{
elm_exit();
}
-
int app_appcore_create(void *data)
{
app_context_h app_context = data;
char locale_dir[TIZEN_PATH_MAX] = {0, };
if (app_context == NULL)
- {
return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
- }
app_set_appcore_event_cb(app_context);
appcore_set_i18n(app_context->app_name, locale_dir);
create_cb = app_context->callback->create;
-
if (create_cb == NULL || create_cb(app_context->data) == false)
- {
return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "app_create_cb() returns false");
- }
app_context->state = APP_STATE_RUNNING;
app_terminate_cb terminate_cb;
if (app_context == NULL)
- {
return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
- }
terminate_cb = app_context->callback->terminate;
if (terminate_cb != NULL)
- {
terminate_cb(app_context->data);
- }
- app_unset_appcore_event_cb();
+ app_unset_appcore_event_cb();
app_finalizer_execute();
app_pause_cb pause_cb;
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->data);
- }
return APP_ERROR_NONE;
}
app_resume_cb resume_cb;
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->data);
- }
return APP_ERROR_NONE;
}
-
int app_appcore_reset(bundle *appcore_bundle, void *data)
{
app_context_h app_context = data;
- app_service_cb service_cb;
- service_h service;
+ app_control_cb callback;
+ app_control_h app_control;
if (app_context == NULL)
- {
return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
- }
- if (service_create_event(appcore_bundle, &service) != APP_ERROR_NONE)
- {
+ if (app_control_create_event(appcore_bundle, &app_control) != APP_ERROR_NONE)
return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to create a service handle from the bundle");
- }
-
- service_cb = app_context->callback->service;
- if (service_cb != NULL)
- {
- service_cb(service, app_context->data);
- }
+ callback = app_context->callback->app_control;
+ if (callback != NULL)
+ callback(app_control, app_context->data);
- service_destroy(service);
+ app_control_destroy(app_control);
return APP_ERROR_NONE;
}
-
int app_appcore_low_memory(void *event_info, void *data)
{
app_context_h app_context = data;
app_low_memory_cb low_memory_cb;
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->data);
- }
return APP_ERROR_NONE;
}
app_low_battery_cb low_battery_cb;
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->data);
- }
return APP_ERROR_NONE;
}
app_device_orientation_cb device_orientation_cb;
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)
- {
+ if (device_orientation_cb != NULL) {
app_device_orientation_e dev_orientation;
dev_orientation = app_convert_appcore_rm(rm);
app_language_changed_cb lang_changed_cb;
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->data);
- }
return APP_ERROR_NONE;
}
app_region_format_changed_cb region_changed_cb;
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->data);
- }
return APP_ERROR_NONE;
}
-
void app_set_appcore_event_cb(app_context_h app_context)
{
if (app_context->callback->low_memory != NULL)
- {
appcore_set_event_callback(APPCORE_EVENT_LOW_MEMORY, app_appcore_low_memory, app_context);
- }
if (app_context->callback->low_battery != NULL)
- {
appcore_set_event_callback(APPCORE_EVENT_LOW_BATTERY, app_appcore_low_battery, app_context);
- }
if (app_context->callback->device_orientation != NULL)
- {
appcore_set_rotation_cb(app_appcore_rotation_event, app_context);
- }
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_REGION_CHANGE, NULL, NULL);
}
-#define UI_APP_EVENT_MAX 5
+#define UI_APP_EVENT_MAX 6
static Eina_List *handler_list[UI_APP_EVENT_MAX] = {NULL, };
-static int _initialized = 0;
+static int handler_initialized = 0;
+static int appcore_initialized = 0;
struct ui_app_context {
char *package;
for (i = 0; i < UI_APP_EVENT_MAX; i++) {
EINA_LIST_FREE(handler_list[i], handler)
- free(handler);
+ if (handler)
+ free(handler);
}
eina_shutdown();
return APP_ERROR_NONE;
}
+static int _ui_app_appcore_suspended_state_changed(void *event_info, void *data)
+{
+ Eina_List *l;
+ app_event_handler_h handler;
+ struct app_event_info event;
+
+ LOGI("_ui_app_appcore_suspended_state_changed");
+ LOGI("[__SUSPEND__] suspended state: %d (0: suspend, 1: wake)", *(int*)event_info);
+
+ event.type = APP_EVENT_SUSPENDED_STATE_CHANGED;
+ event.value = event_info;
+
+ EINA_LIST_FOREACH(handler_list[APP_EVENT_SUSPENDED_STATE_CHANGED], l, handler) {
+ handler->cb(&event, handler->data);
+ }
+
+ return APP_ERROR_NONE;
+}
+
+static void _ui_app_appcore_set_event_cb(app_event_type_e event_type)
+{
+ switch (event_type) {
+ case APP_EVENT_LOW_MEMORY:
+ appcore_set_event_callback(APPCORE_EVENT_LOW_MEMORY, _ui_app_appcore_low_memory, NULL);
+ break;
+ case APP_EVENT_LOW_BATTERY:
+ appcore_set_event_callback(APPCORE_EVENT_LOW_BATTERY, _ui_app_appcore_low_battery, NULL);
+ break;
+ case APP_EVENT_LANGUAGE_CHANGED:
+ appcore_set_event_callback(APPCORE_EVENT_LANG_CHANGE, _ui_app_appcore_lang_changed, NULL);
+ break;
+ case APP_EVENT_DEVICE_ORIENTATION_CHANGED:
+ appcore_set_rotation_cb(_ui_app_appcore_rotation_event, NULL);
+ break;
+ case APP_EVENT_REGION_FORMAT_CHANGED:
+ appcore_set_event_callback(APPCORE_EVENT_REGION_CHANGE, _ui_app_appcore_region_changed, NULL);
+ break;
+ case APP_EVENT_SUSPENDED_STATE_CHANGED:
+ LOGI("[__SUSPEND__]");
+ appcore_set_event_callback(APPCORE_EVENT_SUSPENDED_STATE_CHANGE, _ui_app_appcore_suspended_state_changed, NULL);
+ break;
+ default:
+ break;
+ }
+}
+
+static void _ui_app_appcore_unset_event_cb(app_event_type_e event_type)
+{
+ switch (event_type) {
+ case APP_EVENT_LOW_MEMORY:
+ appcore_set_event_callback(APPCORE_EVENT_LOW_MEMORY, NULL, NULL);
+ break;
+ case APP_EVENT_LOW_BATTERY:
+ appcore_set_event_callback(APPCORE_EVENT_LOW_BATTERY, NULL, NULL);
+ break;
+ case APP_EVENT_LANGUAGE_CHANGED:
+ appcore_set_event_callback(APPCORE_EVENT_LANG_CHANGE, NULL, NULL);
+ break;
+ case APP_EVENT_DEVICE_ORIENTATION_CHANGED:
+ appcore_unset_rotation_cb();
+ break;
+ case APP_EVENT_REGION_FORMAT_CHANGED:
+ appcore_set_event_callback(APPCORE_EVENT_REGION_CHANGE, NULL, NULL);
+ break;
+ case APP_EVENT_SUSPENDED_STATE_CHANGED:
+ LOGI("[__SUSPEND__]");
+ appcore_set_event_callback(APPCORE_EVENT_SUSPENDED_STATE_CHANGE, NULL, NULL);
+ break;
+ default:
+ break;
+ }
+}
static void _ui_app_set_appcore_event_cb(void)
{
- appcore_set_event_callback(APPCORE_EVENT_LOW_MEMORY, _ui_app_appcore_low_memory, NULL);
- appcore_set_event_callback(APPCORE_EVENT_LOW_BATTERY, _ui_app_appcore_low_battery, NULL);
- appcore_set_rotation_cb(_ui_app_appcore_rotation_event, NULL);
- appcore_set_event_callback(APPCORE_EVENT_LANG_CHANGE, _ui_app_appcore_lang_changed, NULL);
- appcore_set_event_callback(APPCORE_EVENT_REGION_CHANGE, _ui_app_appcore_region_changed, NULL);
+ _ui_app_appcore_set_event_cb(APP_EVENT_LOW_MEMORY);
+ _ui_app_appcore_set_event_cb(APP_EVENT_LANGUAGE_CHANGED);
+ _ui_app_appcore_set_event_cb(APP_EVENT_REGION_FORMAT_CHANGED);
+
+ if (eina_list_count(handler_list[APP_EVENT_LOW_BATTERY]) > 0)
+ _ui_app_appcore_set_event_cb(APP_EVENT_LOW_BATTERY);
+ if (eina_list_count(handler_list[APP_EVENT_DEVICE_ORIENTATION_CHANGED]) > 0)
+ _ui_app_appcore_set_event_cb(APP_EVENT_DEVICE_ORIENTATION_CHANGED);
+ if (eina_list_count(handler_list[APP_EVENT_SUSPENDED_STATE_CHANGED]) > 0)
+ _ui_app_appcore_set_event_cb(APP_EVENT_SUSPENDED_STATE_CHANGED);
}
static void _ui_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);
+ _ui_app_appcore_unset_event_cb(APP_EVENT_LOW_MEMORY);
+ _ui_app_appcore_unset_event_cb(APP_EVENT_LANGUAGE_CHANGED);
+ _ui_app_appcore_unset_event_cb(APP_EVENT_REGION_FORMAT_CHANGED);
+
+ if (eina_list_count(handler_list[APP_EVENT_LOW_BATTERY]) > 0)
+ _ui_app_appcore_unset_event_cb(APP_EVENT_LOW_BATTERY);
+ if (eina_list_count(handler_list[APP_EVENT_DEVICE_ORIENTATION_CHANGED]) > 0)
+ _ui_app_appcore_unset_event_cb(APP_EVENT_DEVICE_ORIENTATION_CHANGED);
+ if (eina_list_count(handler_list[APP_EVENT_SUSPENDED_STATE_CHANGED]) > 0)
+ _ui_app_appcore_unset_event_cb(APP_EVENT_SUSPENDED_STATE_CHANGED);
}
static int _ui_app_appcore_create(void *data)
if (app_context == NULL)
return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
+ appcore_initialized = 1;
_ui_app_set_appcore_event_cb();
create_cb = app_context->callback->create;
app_finalizer_execute();
- if (_initialized) {
+ if (handler_initialized) {
_free_handler_list();
- _initialized = 0;
+ handler_initialized = 0;
}
return APP_ERROR_NONE;
struct ui_app_context *app_context = data;
app_control_cb callback;
app_control_h app_control;
+ int ret;
if (app_context == NULL)
return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
- if (app_control_create_event(appcore_bundle, &app_control) != APP_ERROR_NONE)
- return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to create an app_control handle from the bundle");
+ if (appcore_bundle) {
+ if (app_control_create_event(appcore_bundle, &app_control) != APP_ERROR_NONE)
+ return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to create an app_control handle from the bundle");
+ } else {
+ ret = app_control_create(&app_control);
+ if (ret != APP_ERROR_NONE)
+ return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create an app_control");
+ }
callback = app_context->callback->app_control;
app_event_handler_h handler;
Eina_List *l_itr;
- if (!_initialized) {
+ if (!handler_initialized) {
eina_init();
- _initialized = 1;
+ handler_initialized = 1;
}
if (event_handler == NULL || callback == NULL)
return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
- if (event_type < APP_EVENT_LOW_MEMORY || event_type > APP_EVENT_REGION_FORMAT_CHANGED)
+ if (event_type < APP_EVENT_LOW_MEMORY || event_type > APP_EVENT_SUSPENDED_STATE_CHANGED)
return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid event type");
EINA_LIST_FOREACH(handler_list[event_type], l_itr, handler) {
handler->type = event_type;
handler->cb = callback;
handler->data = user_data;
+
+ if (appcore_initialized && eina_list_count(handler_list[event_type]) == 0)
+ _ui_app_appcore_set_event_cb(event_type);
+
handler_list[event_type] = eina_list_append(handler_list[event_type], handler);
*event_handler = handler;
if (event_handler == NULL)
return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "handler is null");
- if (!_initialized) {
+ if (!handler_initialized) {
LOGI("handler list is not initialized");
return APP_ERROR_NONE;
}
type = event_handler->type;
- if (type < APP_EVENT_LOW_MEMORY || type > APP_EVENT_REGION_FORMAT_CHANGED)
+ if (type < APP_EVENT_LOW_MEMORY || type > APP_EVENT_SUSPENDED_STATE_CHANGED)
return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid handler");
EINA_LIST_FOREACH_SAFE(handler_list[type], l_itr, l_next, handler) {
if (handler == event_handler) {
free(handler);
handler_list[type] = eina_list_remove_list(handler_list[type], l_itr);
+
+ if (appcore_initialized && eina_list_count(handler_list[type]) == 0)
+ _ui_app_appcore_unset_event_cb(type);
+
return APP_ERROR_NONE;
}
}
#include <appcore-common.h>
#include <appcore-efl.h>
+#include <aul.h>
+
+#include "app_extension.h"
#ifdef LOG_TAG
#undef LOG_TAG
#define LOG_TAG "CAPI_APPFW_APPLICATION"
-void app_set_reclaiming_system_cache_on_pause(bool enable)
+void *app_get_preinitialized_window(const char *win_name)
{
- appcore_set_system_resource_reclaiming(enable);
+ if (aul_get_preinit_window(win_name) == NULL)
+ return NULL;
+
+ appcore_set_preinit_window_name(win_name);
+ return aul_get_preinit_window(win_name);
}
+void *app_get_preinitialized_background(void)
+{
+ return aul_get_preinit_background();
+}
+
+void *app_get_preinitialized_conformant(void)
+{
+ return aul_get_preinit_conformant();
+}