static bool __get_job();
static bool __get_all_job();
static bool __toggle_job_cb();
+static bool __publish_context();
static void __start_job_cb(ctx_sched_h scheduler, ctx_sched_job_h job, bool timeout, void *cbData);
static void __start_job_cb_with_finish(ctx_sched_h scheduler, ctx_sched_job_h job, bool timeout, void *cbData);
static gboolean __main(gpointer data)
{
g_print("\n");
- g_print("-------------------------------------------\n");
+ g_print("----------------------------------------------\n");
g_print(" (a) add a job (r) remove a job\n");
g_print(" (s) start a job (t) stop a job\n");
g_print(" (g) get a job (G) get all jobs\n");
- g_print(" (c) toggle callbacks (q) quit\n");
- g_print("-------------------------------------------\n");
+ g_print(" (c) toggle callbacks (p) publish context\n");
+ g_print("----------------------------------------------\n");
- std::string choice = read_str(" a/r/s/t/g/G/c/q ? ");
+ std::string choice = read_str(" a/r/s/t/g/G/c/p/(q)uit ? ");
g_print("\n");
switch (choice.front()) {
case 'c':
run_test_case("/scheduler/toggle_job_cb", __toggle_job_cb);
break;
+ case 'p':
+ run_test_case("/scheduler/publish_context", __publish_context);
+ break;
case 'q':
stop_mainloop();
return G_SOURCE_REMOVE;
return 0;
}
- error = ctx_sched_set_job_cb(__scheduler, __start_job_cb, __stop_job_cb, NULL);
- if (error != E_NONE) {
- ctx_sched_destroy(__scheduler);
- g_print(RED("ctx_sched_set_job_cb() failed\n"));
- return 0;
- }
-
g_idle_add(__main, NULL);
start_mainloop();
g_print(" 2. Periodic job, app-control\n");
g_print(" 3. On-demand job, DBus method call, one-time\n");
g_print(" 4. On-demand job, notification\n");
+ g_print("\n");
+ g_print(" 5. DBus action test (trigger: earjack)\n");
+ g_print(" 6. App-control action test (trigger: earjack, target: gallery)\n");
+ g_print(" 7. Notification action test (trigger: earjack)\n");
+ g_print(" 8. Custom trigger test\n");
+ g_print(" 9. Custom requirement test (trigger: earjack)\n");
+ g_print("\n");
ctx_sched_job_h job = sched::create_job(__scheduler, read_int(" ? "));
ASSERT(job != NULL);
return true;
}
+bool __publish_context()
+{
+ static bool flag = false;
+
+ int error = E_NONE;
+ const char* payload = NULL;
+
+ flag = !flag;
+
+ if (flag) {
+ payload = "{\"IsConnected\": 1}";
+ } else {
+ payload = "{\"IsConnected\": 0}";
+ }
+
+ error = ctx_sched_publish_context_json(__scheduler, TEST_CUSTOM_URI, payload);
+ ASSERT_CMPINT(error, ==, E_NONE);
+
+ return true;
+}
+
void __start_job_cb(ctx_sched_h scheduler, ctx_sched_job_h job, bool timeout, void *cbData)
{
g_print("> A job has been executed (timeout: %s).\n", timeout ? "yes" : "no");
static bool __create_on_demand_dbus_job(ctx_sched_h scheduler, ctx_sched_job_h* job);
static bool __create_on_demand_notification_job(ctx_sched_h scheduler, ctx_sched_job_h* job);
-// Hidden test cases
static bool __create_dbus_test(ctx_sched_h scheduler, ctx_sched_job_h* job);
static bool __create_app_control_test(ctx_sched_h scheduler, ctx_sched_job_h* job);
static bool __create_notification_test(ctx_sched_h scheduler, ctx_sched_job_h* job);
+static bool __create_custom_trigger_test(ctx_sched_h scheduler, ctx_sched_job_h* job);
+static bool __create_custom_requirement_test(ctx_sched_h scheduler, ctx_sched_job_h* job);
ctx_sched_job_h sched::create_job(ctx_sched_h scheduler, int num)
{
case 7:
success = __create_notification_test(scheduler, &job);
break;
+ case 8:
+ success = __create_custom_trigger_test(scheduler, &job);
+ break;
+ case 9:
+ success = __create_custom_requirement_test(scheduler, &job);
+ break;
default:
g_print("> Bad choice\n");
break;
return true;
}
+
+bool __create_custom_trigger_test(ctx_sched_h scheduler, ctx_sched_job_h* job)
+{
+ int error = E_NONE;
+ bool supported = false;
+ ctx_sched_job_context_h jobContext = NULL;
+
+ error = ctx_sched_job_create_on_demand(job);
+ ASSERT_CMPINT(error, ==, E_NONE);
+
+ error = ctx_sched_job_trigger_is_supported(scheduler, TEST_CUSTOM_URI, &supported);
+ ASSERT_RETURN(error == E_NONE, NULL);
+ ASSERT_RETURN(supported, NULL);
+
+ error = ctx_sched_job_trigger_create(TEST_CUSTOM_URI, &jobContext);
+ ASSERT_RETURN(error == E_NONE, NULL);
+ ASSERT_RETURN(jobContext != NULL, NULL);
+
+ ctx_sched_job_context_prepare_attribute_int(jobContext, CTX_SCHED_ATTR_NAME_IS_CONNECTED);
+ ctx_sched_job_context_attribute_add_eq_int(jobContext, CTX_SCHED_ATTR_NAME_IS_CONNECTED, CTX_SCHED_ATTR_VALUE_TRUE);
+
+ error = ctx_sched_job_add_trigger(*job, jobContext);
+ if (error != E_NONE)
+ ctx_sched_job_context_destroy(jobContext);
+ ASSERT_CMPINT(error, ==, E_NONE);
+
+ error = ctx_sched_job_set_notification(*job, "Job Scheduler", "Custom Trigger Test", NULL, NULL);
+ ASSERT_CMPINT(error, ==, E_NONE);
+
+ return true;
+}
+
+bool __create_custom_requirement_test(ctx_sched_h scheduler, ctx_sched_job_h* job)
+{
+ int error = E_NONE;
+ bool success = __create_action_test(scheduler, job);
+ ASSERT(success);
+
+ ctx_sched_job_context_h jobContext = NULL;
+
+ error = ctx_sched_job_requirement_create(TEST_CUSTOM_URI, false, &jobContext);
+ ASSERT_RETURN(error == E_NONE, NULL);
+ ASSERT_RETURN(jobContext != NULL, NULL);
+
+ ctx_sched_job_context_prepare_attribute_int(jobContext, CTX_SCHED_ATTR_NAME_IS_CONNECTED);
+ ctx_sched_job_context_attribute_add_eq_int(jobContext, CTX_SCHED_ATTR_NAME_IS_CONNECTED, CTX_SCHED_ATTR_VALUE_TRUE);
+
+ error = ctx_sched_job_add_requirement(*job, jobContext);
+ if (error != E_NONE)
+ ctx_sched_job_context_destroy(jobContext);
+ ASSERT_CMPINT(error, ==, E_NONE);
+
+ error = ctx_sched_job_set_notification(*job, "Job Scheduler", "Custom Requirement Test", NULL, NULL);
+ ASSERT_CMPINT(error, ==, E_NONE);
+
+ return true;
+}