Exclude some lines from lcov
[platform/core/api/job-scheduler.git] / src / job_scheduler.c
index 349d330..97345fd 100644 (file)
@@ -252,7 +252,7 @@ static bundle *__get_bundle_from_job(ctx_sched_job_h job)
 
        b = bundle_decode(b_raw, len);
        if (b == NULL)
-               _E("Failed to decode bundle raw(%s)", b_raw);
+               _E("Failed to decode bundle raw(%s)", b_raw); /* LCOV_EXCL_LINE */
 
        free(b_raw);
 
@@ -314,15 +314,19 @@ static void __start_job_cb(ctx_sched_h scheduler, ctx_sched_job_h job,
 
        b = __get_bundle_from_job(job);
        if (b == NULL) {
+               /* LCOV_EXCL_START */
                ctx_sched_job_destroy(job);
                return;
+               /* LCOV_EXCL_STOP */
        }
 
        job_id = bundle_get_val(b, AUL_K_JOB_ID);
        if (job_id == NULL) {
+               /* LCOV_EXCL_START */
                ctx_sched_job_destroy(job);
                bundle_free(b);
                return;
+               /* LCOV_EXCL_STOP */
        }
 
        if (!g_hash_table_contains(__handle.job_id_table, job_id))
@@ -343,15 +347,19 @@ static void __stop_job_cb(ctx_sched_h scheduler, ctx_sched_job_h job,
 
        b = __get_bundle_from_job(job);
        if (b == NULL) {
+               /* LCOV_EXCL_START */
                ctx_sched_job_destroy(job);
                return;
+               /* LCOV_EXCL_STOP */
        }
 
        job_id = bundle_get_val(b, AUL_K_JOB_ID);
        if (job_id == NULL) {
+               /* LCOV_EXCL_START */
                ctx_sched_job_destroy(job);
                bundle_free(b);
                return;
+               /* LCOV_EXCL_STOP */
        }
 
        service_app_job_raise(SERVICE_APP_JOB_STATUS_STOP, job_id, b);
@@ -366,18 +374,22 @@ static int __init_scheduler(ctx_sched_h *scheduler)
 
        r = ctx_sched_create(&handle);
        if (r != 0)
-               return r;
+               return r; /* LCOV_EXCL_LINE */
 
        r = ctx_sched_foreach_job(handle, __foreach_job_cb, NULL);
        if (r != 0 && r != TIZEN_ERROR_NO_DATA) {
+               /* LCOV_EXCL_START */
                ctx_sched_destroy(handle);
                return r;
+               /* LCOV_EXCL_STOP */
        }
 
        r = ctx_sched_set_job_cb(handle, __start_job_cb, __stop_job_cb, NULL);
        if (r != 0) {
+               /* LCOV_EXCL_START */
                ctx_sched_destroy(handle);
                return r;
+               /* LCOV_EXCL_STOP */
        }
 
        *scheduler = handle;
@@ -394,24 +406,30 @@ API int job_scheduler_init(void)
 
        r = app_get_id(&__handle.app_id);
        if (r != APP_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                return job_error(JOB_ERROR_IO_ERROR, __FUNCTION__,
                                __LINE__, NULL);
+               /* LCOV_EXCL_STOP */
        }
 
        __handle.job_id_table = g_hash_table_new_full(g_str_hash, g_str_equal,
                        free, NULL);
        if (__handle.job_id_table == NULL) {
+               /* LCOV_EXCL_START */
                free(__handle.app_id);
                return job_error(JOB_ERROR_OUT_OF_MEMORY, __FUNCTION__,
                                __LINE__, NULL);
+               /* LCOV_EXCL_STOP */
        }
 
        r = __init_scheduler(&__handle.scheduler);
        if (r != 0) {
+               /* LCOV_EXCL_START */
                g_hash_table_destroy(__handle.job_id_table);
                free(__handle.app_id);
                return job_error(JOB_ERROR_IO_ERROR, __FUNCTION__,
                                __LINE__, NULL);
+               /* LCOV_EXCL_STOP */
        }
 
        __handle.initialized = true;
@@ -461,20 +479,26 @@ static int __job_add_app_control(ctx_sched_job_h job, job_info_h job_info,
 
        r = aul_svc_set_operation(b, AUL_SVC_OPERATION_DEFAULT);
        if (r != AUL_SVC_RET_OK) {
+               /* LCOV_EXCL_START */
                _E("Failed to set operation");
                return JOB_ERROR_OUT_OF_MEMORY;
+               /* LCOV_EXCL_STOP */
        }
 
        r = aul_svc_set_appid(b, __handle.app_id);
        if (r != AUL_SVC_RET_OK) {
+               /* LCOV_EXCL_START */
                _E("Failed to add appid(%s)", __handle.app_id);
                return JOB_ERROR_OUT_OF_MEMORY;
+               /* LCOV_EXCL_STOP */
        }
 
        r = ctx_sched_job_set_app_control(job, b);
        if (r != 0) {
+               /* LCOV_EXCL_START */
                _E("Failed to set app control (%d)", r);
                return JOB_ERROR_IO_ERROR;
+               /* LCOV_EXCL_STOP */
        }
 
        return JOB_ERROR_NONE;
@@ -496,9 +520,11 @@ static int __job_add_user_data(ctx_sched_job_h job, job_info_h job_info,
 
        r = ctx_sched_job_set_user_data(job, (const char *)b_raw, len);
        if (r != 0) {
+               /* LCOV_EXCL_START */
                _E("Failed to set user data");
                free(b_raw);
                return JOB_ERROR_IO_ERROR;
+               /* LCOV_EXCL_STOP */
        }
        free(b_raw);
 
@@ -550,8 +576,10 @@ static int __job_add_persistent(ctx_sched_job_h job, job_info_h job_info,
 
        r = ctx_sched_job_set_persistent(job, persistent);
        if (r != 0) {
+               /* LCOV_EXCL_START */
                _E("Failed to set persistent (%d)", r);
                return r;
+               /* LCOV_EXCL_STOP */
        }
 
        if (persistent)
@@ -573,8 +601,10 @@ static int __job_add_one_time(ctx_sched_job_h job, job_info_h job_info,
 
        r = ctx_sched_job_set_one_time(job, once);
        if (r != 0) {
+               /* LCOV_EXCL_START */
                _E("Failed to set one time (%d)", r);
                return r;
+               /* LCOV_EXCL_STOP */
        }
 
        if (once)
@@ -597,8 +627,10 @@ static int __job_add_requirement_timeout(ctx_sched_job_h job,
 
        r = ctx_sched_job_set_requirement_timeout(job, timeout);
        if (r != 0) {
+               /* LCOV_EXCL_START */
                _E("Failed to set requirement timeout (%d)", r);
                return r;
+               /* LCOV_EXCL_STOP */
        }
 
        if (timeout) {
@@ -616,14 +648,18 @@ static int __add_str_attr_ne(ctx_sched_job_context_h context,
 
        r = ctx_sched_job_context_prepare_attribute_str(context, name);
        if (r != 0) {
+               /* LCOV_EXCL_START */
                _E("Failed to prepare string attribute(%s) - %d", name, r);
                return r;
+               /* LCOV_EXCL_STOP */
        }
 
        r = ctx_sched_job_context_attribute_add_ne_str(context, name, value);
        if (r != 0) {
+               /* LCOV_EXCL_START */
                _E("Failed to add string value(%s) - %d", value, r);
                return r;
+               /* LCOV_EXCL_STOP */
        }
 
        return JOB_ERROR_NONE;
@@ -636,14 +672,18 @@ static int __add_str_attr_eq(ctx_sched_job_context_h context,
 
        r = ctx_sched_job_context_prepare_attribute_str(context, name);
        if (r != 0) {
+               /* LCOV_EXCL_START */
                _E("Failed to prepare string attribute(%s) - %d", name, r);
                return r;
+               /* LCOV_EXCL_STOP */
        }
 
        r = ctx_sched_job_context_attribute_add_eq_str(context, name, value);
        if (r != 0) {
+               /* LCOV_EXCL_START */
                _E("Failed to add string value(%s) - %d", value, r);
                return r;
+               /* LCOV_EXCL_STOP */
        }
 
        return JOB_ERROR_NONE;
@@ -656,14 +696,18 @@ static int __add_int_attr_eq(ctx_sched_job_context_h context,
 
        r = ctx_sched_job_context_prepare_attribute_int(context, name);
        if (r != 0) {
+               /* LCOV_EXCL_START */
                _E("Failed to prepare integer attribute(%s) - %d", name, r);
                return r;
+               /* LCOV_EXCL_STOP */
        }
 
        r = ctx_sched_job_context_attribute_add_eq_int(context, name, value);
        if (r != 0) {
+               /* LCOV_EXCL_START */
                _E("Failed to add integer value(%s) - %d", value, r);
                return r;
+               /* LCOV_EXCL_STOP */
        }
 
        return JOB_ERROR_NONE;
@@ -687,8 +731,10 @@ static int __job_add_requires_battery_not_low(ctx_sched_job_h job,
        r = ctx_sched_job_requirement_create(CTX_SCHED_URI_BATTERY, false,
                        &requirement);
        if (r != 0) {
+               /* LCOV_EXCL_START */
                _E("Failed to create requirement (%d)", r);
                return r;
+               /* LCOV_EXCL_STOP */
        }
 
        if (battery_not_low) {
@@ -699,15 +745,19 @@ static int __job_add_requires_battery_not_low(ctx_sched_job_h job,
                                CTX_SCHED_ATTR_VALUE_HIGH);
        }
        if (r != JOB_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                ctx_sched_job_context_destroy(requirement);
                return r;
+               /* LCOV_EXCL_STOP */
        }
 
        r = ctx_sched_job_add_requirement(job, requirement);
        if (r != 0) {
+               /* LCOV_EXCL_START */
                _E("Failed to add requirement (%d)", r);
                ctx_sched_job_context_destroy(requirement);
                return r;
+               /* LCOV_EXCL_STOP */
        }
 
        if (battery_not_low)
@@ -736,22 +786,28 @@ static int __job_add_requires_charging(ctx_sched_job_h job,
        r = ctx_sched_job_requirement_create(CTX_SCHED_URI_BATTERY, false,
                        &requirement);
        if (r != 0) {
+               /* LCOV_EXCL_START */
                _E("Failed to create requirement (%d)", r);
                return r;
+               /* LCOV_EXCL_STOP */
        }
 
        r = __add_int_attr_eq(requirement, CTX_SCHED_ATTR_NAME_IS_CHARGING,
                        charging);
        if (r != JOB_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                ctx_sched_job_context_destroy(requirement);
                return r;
+               /* LCOV_EXCL_STOP */
        }
 
        r = ctx_sched_job_add_requirement(job, requirement);
        if (r != 0) {
+               /* LCOV_EXCL_START */
                _E("Failed to add requirement (%d)", r);
                ctx_sched_job_context_destroy(requirement);
                return r;
+               /* LCOV_EXCL_STOP */
        }
 
        if (charging)
@@ -780,8 +836,10 @@ static int __job_add_requires_wifi_connection(ctx_sched_job_h job,
        r = ctx_sched_job_requirement_create(CTX_SCHED_URI_WIFI, false,
                        &requirement);
        if (r != 0) {
+               /* LCOV_EXCL_START */
                _E("Failed to create requirement (%d)", r);
                return r;
+               /* LCOV_EXCL_STOP */
        }
 
        if (wifi_connection) {
@@ -792,15 +850,19 @@ static int __job_add_requires_wifi_connection(ctx_sched_job_h job,
                                CTX_SCHED_ATTR_VALUE_CONNECTED);
        }
        if (r != JOB_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                ctx_sched_job_context_destroy(requirement);
                return r;
+               /* LCOV_EXCL_STOP */
        }
 
        r = ctx_sched_job_add_requirement(job, requirement);
        if (r != 0) {
+               /* LCOV_EXCL_START */
                _E("Failed to add requirement (%d)", r);
                ctx_sched_job_context_destroy(requirement);
                return r;
+               /* LCOV_EXCL_STOP */
        }
 
        if (wifi_connection)
@@ -820,8 +882,10 @@ static int __add_trigger_event(ctx_sched_job_h job, job_trigger_event_e event,
        r = ctx_sched_job_trigger_create(job_trigger_map[event].uri,
                        &trigger);
        if (r != 0) {
+               /* LCOV_EXCL_START */
                _E("Failed to create trigger (%d)", r);
                return r;
+               /* LCOV_EXCL_STOP */
        }
 
        if (job_trigger_map[event].attr_type == ATTR_TYPE_INTEGER) {
@@ -838,9 +902,11 @@ static int __add_trigger_event(ctx_sched_job_h job, job_trigger_event_e event,
 
        r = ctx_sched_job_add_trigger(job, trigger);
        if (r != 0) {
+               /* LCOV_EXCL_START */
                _E("Failed to add trigger (%d)", r);
                ctx_sched_job_context_destroy(trigger);
                return r;
+               /* LCOV_EXCL_STOP */
        }
 
        bundle_add(b, job_trigger_map[event].key, "true");
@@ -900,15 +966,19 @@ static ctx_sched_job_h __create_job(job_info_h job_info, const char *job_id)
 
        b = bundle_create();
        if (b == NULL) {
+               /* LCOV_EXCL_START */
                _E("Failed to create bundle");
                return NULL;
+               /* LCOV_EXCL_STOP */
        }
 
        r = bundle_add(b, AUL_K_JOB_ID, job_id);
        if (r != BUNDLE_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                _E("Failed to add job id(%s)", job_id);
                bundle_free(b);
                return NULL;
+               /* LCOV_EXCL_STOP */
        }
 
        job_info_get_periodic(job_info, &interval);
@@ -920,18 +990,22 @@ static ctx_sched_job_h __create_job(job_info_h job_info, const char *job_id)
                r = ctx_sched_job_create_periodic(interval, 0, &job);
        }
        if (r != 0) {
+               /* LCOV_EXCL_START */
                _E("Failed to create job (%d)", r);
                bundle_free(b);
                return NULL;
+               /* LCOV_EXCL_STOP */
        }
 
        for (i = 0; i < ARRAY_SIZE(job_constructor); ++i) {
                if (job_constructor[i]) {
                        r = job_constructor[i](job, job_info, b);
                        if (r != JOB_ERROR_NONE) {
+                               /* LCOV_EXCL_START */
                                ctx_sched_job_destroy(job);
                                bundle_free(b);
                                return NULL;
+                               /* LCOV_EXCL_STOP */
                        }
                }
        }
@@ -963,18 +1037,23 @@ API int job_scheduler_schedule(job_info_h job_info, const char *job_id)
 
        job = __create_job(job_info, job_id);
        if (job == NULL) {
+               /* LCOV_EXCL_START */
                return job_error(JOB_ERROR_OUT_OF_MEMORY, __FUNCTION__,
                                __LINE__, NULL);
+               /* LCOV_EXCL_STOP */
        }
 
        r = job_info_set_job_id(job_info, job_id);
        if (r != JOB_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                ctx_sched_job_destroy(job);
                return job_error(r, __FUNCTION__, __LINE__, NULL);
+               /* LCOV_EXCL_STOP */
        }
 
        r = ctx_sched_schedule(__handle.scheduler, job, &id);
        if (r != 0) {
+               /* LCOV_EXCL_START */
                ctx_sched_job_destroy(job);
                if (r == JOB_ERROR_PERMISSION_DENIED) {
                        return job_error(JOB_ERROR_PERMISSION_DENIED,
@@ -983,6 +1062,7 @@ API int job_scheduler_schedule(job_info_h job_info, const char *job_id)
                        return job_error(JOB_ERROR_IO_ERROR,
                                        __FUNCTION__, __LINE__, NULL);
                }
+               /* LCOV_EXCL_STOP */
        }
        ctx_sched_job_destroy(job);
        g_hash_table_insert(__handle.job_id_table, strdup(job_id),
@@ -1014,8 +1094,10 @@ API int job_scheduler_cancel(const char *job_id)
 
        r = ctx_sched_cancel(__handle.scheduler, id);
        if (r != 0) {
+               /* LCOV_EXCL_START */
                return job_error(JOB_ERROR_IO_ERROR, __FUNCTION__,
                                __LINE__, NULL);
+               /* LCOV_EXCL_STOP */
        }
 
        g_hash_table_remove(__handle.job_id_table, job_id);
@@ -1034,8 +1116,10 @@ API int job_scheduler_cancel_all(void)
 
        r = ctx_sched_cancel_all(__handle.scheduler);
        if (r != 0) {
+               /* LCOV_EXCL_START */
                return job_error(JOB_ERROR_IO_ERROR, __FUNCTION__,
                                __LINE__, NULL);
+               /* LCOV_EXCL_STOP */
        }
 
        g_hash_table_remove_all(__handle.job_id_table);
@@ -1066,14 +1150,18 @@ API int job_scheduler_notify_job_finished(const char *job_id)
 
        r = ctx_sched_job_finished(__handle.scheduler, id);
        if (r != 0) {
+               /* LCOV_EXCL_START */
                return job_error(JOB_ERROR_IO_ERROR, __FUNCTION__,
                                __LINE__, NULL);
+               /* LCOV_EXCL_STOP */
        }
 
        r = service_app_job_finished(job_id);
        if (r != 0) {
+               /* LCOV_EXCL_START */
                return job_error(JOB_ERROR_IO_ERROR, __FUNCTION__,
                                __LINE__, NULL);
+               /* LCOV_EXCL_STOP */
        }
 
        return JOB_ERROR_NONE;
@@ -1092,28 +1180,36 @@ static void __foreach_job_id_cb(gpointer key, gpointer value,
 
        r = ctx_sched_get_job(__handle.scheduler, id, &job);
        if (r != 0) {
+               /* LCOV_EXCL_START */
                _E("Failed to get job from job id(%s:%d)", job_id, id);
                return;
+               /* LCOV_EXCL_STOP */
        }
 
        b = __get_bundle_from_job(job);
        if (b == NULL) {
+               /* LCOV_EXCL_START */
                ctx_sched_job_destroy(job);
                return;
+               /* LCOV_EXCL_STOP */
        }
        ctx_sched_job_destroy(job);
 
        r = job_info_create_with_bundle(b, &job_info);
        if (r != JOB_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                bundle_free(b);
                return;
+               /* LCOV_EXCL_STOP */
        }
        bundle_free(b);
 
        r = job_info_set_job_id(job_info, job_id);
        if (r != JOB_ERROR_NONE) {
+               /* LCOV_EXCL_START */
                job_info_destroy(job_info);
                return;
+               /* LCOV_EXCL_STOP */
        }
 
        *list = g_list_append(*list, job_info);
@@ -1190,16 +1286,20 @@ static struct job_service_s *__create_job_service(const char *job_id,
 
        service = calloc(1, sizeof(struct job_service_s));
        if (service == NULL) {
+               /* LCOV_EXCL_START */
                _E("Out of memory");
                return NULL;
+               /* LCOV_EXCL_STOP */
        }
 
        service->handle = service_app_add_job_handler(job_id, __job_service_cb,
                        service);
        if (service->handle == NULL) {
+               /* LCOV_EXCL_START */
                _E("Out of memory");
                free(service);
                return NULL;
+               /* LCOV_EXCL_STOP */
        }
 
        service->callback = *callback;
@@ -1240,8 +1340,10 @@ API int job_scheduler_service_add(const char *job_id,
 
        service = __create_job_service(job_id, callback, user_data);
        if (service == NULL) {
+               /* LCOV_EXCL_START */
                return job_error(JOB_ERROR_OUT_OF_MEMORY, __FUNCTION__,
                                __LINE__, NULL);
+               /* LCOV_EXCL_STOP */
        }
 
        __handle.job_service_list = g_list_append(__handle.job_service_list,
@@ -1268,8 +1370,10 @@ API int job_scheduler_service_remove(job_service_h job_service)
        }
 
        if (!__handle.initialized) {
+               /* LCOV_EXCL_START */
                return job_error(JOB_ERROR_NOT_INITIALIZED, __FUNCTION__,
                                __LINE__, NULL);
+               /* LCOV_EXCL_STOP */
        }
 
        __handle.job_service_list = g_list_remove(__handle.job_service_list,
@@ -1298,13 +1402,17 @@ int job_scheduler_verify_requirement(const char *uri)
        r = ctx_sched_job_requirement_is_supported(__handle.scheduler,
                        uri, &supported);
        if (r != 0) {
+               /* LCOV_EXCL_START */
                return job_error(JOB_ERROR_IO_ERROR, __FUNCTION__,
                                __LINE__, NULL);
+               /* LCOV_EXCL_STOP */
        }
 
        if (!supported) {
+               /* LCOV_EXCL_START */
                return job_error(JOB_ERROR_NOT_SUPPORTED, __FUNCTION__,
                                __LINE__, NULL);
+               /* LCOV_EXCL_STOP */
        }
 
        return JOB_ERROR_NONE;
@@ -1328,13 +1436,17 @@ int job_scheduler_verify_trigger(const char *uri)
        r = ctx_sched_job_trigger_is_supported(__handle.scheduler,
                        uri, &supported);
        if (r != 0) {
+               /* LCOV_EXCL_START */
                return job_error(JOB_ERROR_IO_ERROR, __FUNCTION__,
                                __LINE__, NULL);
+               /* LCOV_EXCL_STOP */
        }
 
        if (!supported) {
+               /* LCOV_EXCL_START */
                return job_error(JOB_ERROR_NOT_SUPPORTED, __FUNCTION__,
                                __LINE__, NULL);
+               /* LCOV_EXCL_STOP */
        }
 
        return JOB_ERROR_NONE;
@@ -1351,40 +1463,52 @@ static int __init_cynara(void)
        r = cynara_creds_self_get_client(CLIENT_METHOD_DEFAULT,
                        &__cynara.client);
        if (r != CYNARA_API_SUCCESS) {
+               /* LCOV_EXCL_START */
                _E("Failed to get client");
                return -1;
+               /* LCOV_EXCL_STOP */
        }
 
        r = cynara_creds_self_get_user(CLIENT_METHOD_DEFAULT, &__cynara.user);
        if (r != CYNARA_API_SUCCESS) {
+               /* LCOV_EXCL_START */
                _E("Failed to get user");
                goto err;
+               /* LCOV_EXCL_STOP */
        }
 
        __cynara.session = cynara_session_from_pid(getpid());
        if (__cynara.session == NULL) {
+               /* LCOV_EXCL_START */
                _E("Failed to get session");
                goto err;
+               /* LCOV_EXCL_STOP */
        }
 
        r = cynara_configuration_create(&conf);
        if (r != CYNARA_API_SUCCESS) {
+               /* LCOV_EXCL_START */
                _E("Failed to create cynara configuration");
                goto err;
+               /* LCOV_EXCL_STOP */
        }
 
        r = cynara_configuration_set_cache_size(conf, 10);
        if (r != CYNARA_API_SUCCESS) {
+               /* LCOV_EXCL_START */
                _E("Failed to set cache size");
                goto err;
+               /* LCOV_EXCL_STOP */
        }
 
        r = cynara_initialize(&__cynara.handle, conf);
        cynara_configuration_destroy(conf);
        conf = NULL;
        if (r != CYNARA_API_SUCCESS) {
+               /* LCOV_EXCL_START */
                _E("Failed to initialize cynara");
                goto err;
+               /* LCOV_EXCL_STOP */
        }
 
        __cynara.initialized = true;
@@ -1393,6 +1517,7 @@ static int __init_cynara(void)
 
        return 0;
 err:
+       /* LCOV_EXCL_START */
        if (conf)
                cynara_configuration_destroy(conf);
 
@@ -1412,6 +1537,7 @@ err:
        }
 
        return -1;
+       /* LCOV_EXCL_STOP */
 }
 
 static void __finish_cynara(void)
@@ -1456,8 +1582,10 @@ int job_scheduler_verify_privilege(const char *priv)
        r = cynara_check(__cynara.handle, __cynara.client, __cynara.session,
                        __cynara.user, priv);
        if (r != CYNARA_API_ACCESS_ALLOWED) {
+               /* LCOV_EXCL_START */
                _E("Failed to check cynara access (%d)", r);
                return JOB_ERROR_PERMISSION_DENIED;
+               /* LCOV_EXCL_STOP */
        }
 
        return JOB_ERROR_NONE;