#define RDHL_DBUS_PATH_TEST RDHL_DBUS_PATH(Test)
#define RDHL_DBUS_INTERFACE_TEST RDHL_DBUS_INTERFACE(test)
+/* Wait 1 second from now */
+#define TIME_TO_WAIT_EVENT (g_get_monotonic_time() + 1000000)
+
+static GCond test_worker_thread_cond;
+static GMutex test_worker_thread_mutex;
+
gboolean test_event_handler(gpointer user_data)
{
struct event *event = (struct event *)user_data;
int *arg = (int *)event->data;
- if (event->type == RDHL_EVENT_TEST)
+ if (event->type == RDHL_EVENT_TEST) {
_I("Test module's event (type = %d) callback is called. Receive %d",
event->type, *arg);
+ g_cond_signal(&test_worker_thread_cond);
+ }
return TRUE;
}
-void test_dbus_method_handler(GDBusMethodInvocation *invocation, GVariant *params)
+void test_dbus_method(GDBusMethodInvocation *invocation, GVariant *params)
{
GVariantIter *iter = NULL;
gsize size;
g_dbus_method_invocation_return_value(invocation, g_variant_new("(ii)", sum, mul));
}
+void test_event(GDBusMethodInvocation *invocation, GVariant *params)
+{
+ int *arg_broadcast = malloc(sizeof(int));
+ int *arg_send = malloc(sizeof(int));
+ gint err_code;
+
+ g_assert(arg_broadcast && arg_send);
+
+ /* Broadcast event */
+ g_mutex_lock(&test_worker_thread_mutex);
+ *arg_broadcast = 623;
+ _I("Broadcast event (arg = %d)", *arg_broadcast);
+ if (event_broadcast(RDHL_EVENT_TEST, arg_broadcast) < 0) {
+ err_code = G_DBUS_ERROR_FAILED;
+ goto err;
+ }
+ if (!g_cond_wait_until(&test_worker_thread_cond, &test_worker_thread_mutex,
+ TIME_TO_WAIT_EVENT)) {
+ err_code = G_DBUS_ERROR_TIMEOUT;
+ goto err;
+ }
+ g_mutex_unlock(&test_worker_thread_mutex);
+
+ /* Send event */
+ g_mutex_lock(&test_worker_thread_mutex);
+ *arg_send = 731;
+ _I("Send event to the test module (arg = %d)", *arg_send);
+ if (event_send("test", RDHL_EVENT_TEST, arg_send) < 0) {
+ err_code = G_DBUS_ERROR_FAILED;
+ goto err;
+ }
+ if (!g_cond_wait_until(&test_worker_thread_cond, &test_worker_thread_mutex,
+ TIME_TO_WAIT_EVENT)) {
+ err_code = G_DBUS_ERROR_TIMEOUT;
+ goto err;
+ }
+ g_mutex_unlock(&test_worker_thread_mutex);
+
+ g_dbus_method_invocation_return_value(invocation,
+ g_variant_new("(s)", "Event test : success"));
+ return;
+err:
+ g_mutex_unlock(&test_worker_thread_mutex);
+ g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR,
+ err_code, "Event test : fail");
+}
+
static struct dbus_method test_dbus_methods[] = {
- { "TestMethod", "ai", "ii", test_dbus_method_handler },
+ { "DBusMethodTest", "ai", "ii", test_dbus_method },
+ { "EventTest", NULL, "s", test_event },
};
-void test_dbus_signal_handler(GVariant *params)
+void test_dbus_signal(GVariant *params)
{
int arg;
}
static struct dbus_signal test_dbus_signals[] = {
- { "TestSignal", test_dbus_signal_handler },
+ { "DBusSignalTest", test_dbus_signal },
};
int __INIT__ test_init(void)
dbus_register_signals(RDHL_DBUS_PATH_TEST, RDHL_DBUS_INTERFACE_TEST,
test_dbus_signals, ARRAY_SIZE(test_dbus_signals));
+ g_cond_init(&test_worker_thread_cond);
+ g_mutex_init(&test_worker_thread_mutex);
+
_I("Test module is initialized!");
return 0;