static GMutex event_worker_thread_mutex;
static int ewt_var_initialized;
-API int event_send(char *dest, enum event_type type, void *data)
+API int event_send(char *dest, event_type type, void *data)
{
struct module *module;
struct event *event;
g_main_context_wakeup(module->event_worker->context);
}
-API int event_broadcast(enum event_type type, void *data)
+API int event_broadcast(event_type type, void *data)
{
- struct event *event = g_slice_new(struct event);
+ struct event *event;
+
+ if (type >= GLOBAL_EVENT_MAX) {
+ _E("Only global event can be broadcasted");
+ return -EINVAL;
+ }
+
+ event = g_slice_new(struct event);
if (!event) {
_E("Not enough memory");
return -ENOMEM;
/**
* @brief Event list handled by ResourceD-HeadLess
+ * @details Global event is for all modules. It can be broadcasted or sent
+ * to the target module.
+ * On the other hand, local event is only available in
+ * the defining module, so it should not be broadcasted.
+ * Global event must be unique, but local event can be overlapped
+ * between modules.
+ * @notice Define local event in the target module.
*/
enum event_type {
- RDHL_EVENT_TEST = 0, /* For testing. It will be removed */
-
- /* Resource usage */
- RDHL_EVENT_PROCESS_MEMORY_USAGE,
- RDHL_EVENT_PROCESS_CPU_USAGE,
+ GLOBAL_EVENT_NONE = 0,
+ GLOBAL_EVENT_MAX = 0xffff,
+ LOCAL_EVENT_MIN,
+ LOCAL_EVENT_MAX = 0xffffffff,
};
+typedef unsigned int event_type;
typedef GSourceFunc event_handler_func;
/**
*/
struct event {
char *dest;
- enum event_type type;
+ event_type type;
void *data;
gint ref_count;
};
* @param[in] data Delivered data
* @return 0 on success, otherwise a negative error value
*/
-int event_send(char *dest, enum event_type type, void *data);
+int event_send(char *dest, event_type type, void *data);
/**
- * @brief Broadcast event to all modules
+ * @brief Broadcast global event to all modules
* @param[in] type Event type
* @param[in] data Delivered data
* @return 0 on success, otherwise a negative error value
*/
-int event_broadcast(enum event_type type, void *data);
+int event_broadcast(event_type type, void *data);
/**
* @brief Register event worker
#include <log.h>
#include <macro.h>
+#include "proc-usage.h"
#include "proc-usage-dbus.h"
-static void proc_usage_dbus_push_event(enum event_type event_type,
+static void proc_usage_dbus_push_event(event_type event_type,
GDBusMethodInvocation *invocation, GVariant *params)
{
int ret;
static void proc_usage_dbus_memory_usage(GDBusMethodInvocation *invocation, GVariant *params)
{
- proc_usage_dbus_push_event(RDHL_EVENT_PROCESS_MEMORY_USAGE, invocation, params);
+ proc_usage_dbus_push_event(PROC_USAGE_EVENT_PROCESS_MEMORY_USAGE, invocation, params);
}
static void proc_usage_dbus_cpu_usage(GDBusMethodInvocation *invocation, GVariant *params)
{
- proc_usage_dbus_push_event(RDHL_EVENT_PROCESS_CPU_USAGE, invocation, params);
+ proc_usage_dbus_push_event(PROC_USAGE_EVENT_PROCESS_CPU_USAGE, invocation, params);
}
static struct dbus_method proc_usage_dbus_methods[] = {
#define RDHL_DBUS_PATH_PROC RDHL_DBUS_PATH(Process)
#define RDHL_DBUS_INTERFACE_PROC RDHL_DBUS_INTERFACE(process)
-/**
- * @brief Argument pushed in the proc-usage worker queue
- */
-struct proc_usage_event {
- GDBusMethodInvocation *invocation;
- GVariant *params;
-};
-
int proc_usage_dbus_init(void);
#endif /* __RESOURCED_HEADLESS_PROC_USAGE_DBUS_H__ */
#include <macro.h>
#include <module.h>
+#include "proc-usage.h"
#include "proc-usage-dbus.h"
#include "proc-usage-process.h"
}
switch (event->type) {
- case RDHL_EVENT_PROCESS_MEMORY_USAGE:
+ case PROC_USAGE_EVENT_PROCESS_MEMORY_USAGE:
usage = proc_usage_process_get_memory_usages(pue->params);
break;
- case RDHL_EVENT_PROCESS_CPU_USAGE:
+ case PROC_USAGE_EVENT_PROCESS_CPU_USAGE:
usage = proc_usage_process_get_cpu_usages(pue->params);
break;
default:
--- /dev/null
+/*
+ * resourced-headless
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+/**
+ * @file proc-usage.h
+ * @brief Proc-usage module and its event handler
+ */
+
+#ifndef __RESOURCED_HEADLESS_PROC_USAGE_H__
+#define __RESOURCED_HEADLESS_PROC_USAGE_H__
+
+#include <gio/gio.h>
+#include <glib.h>
+
+/**
+ * @brief Local event for proc-usage module
+ */
+enum proc_usage_event_type {
+ PROC_USAGE_EVENT_PROCESS_MEMORY_USAGE = LOCAL_EVENT_MIN,
+ PROC_USAGE_EVENT_PROCESS_CPU_USAGE,
+};
+
+/**
+ * @brief Argument pushed in the proc-usage worker queue
+ */
+struct proc_usage_event {
+ GDBusMethodInvocation *invocation;
+ GVariant *params;
+};
+
+#endif /* __RESOURCED_HEADLESS_PROC_USAGE_H__ */
/* Wait 1 second from now */
#define TIME_TO_WAIT_EVENT (g_get_monotonic_time() + 1000000)
+/**
+ * @brief Local event for test module
+ */
+enum test_event_type {
+ TEST_EVENT_GET_VALUE = 170802,
+};
+
static GCond test_worker_thread_cond;
static GMutex test_worker_thread_mutex;
struct event *event = (struct event *)user_data;
int *arg = (int *)event->data;
- if (event->type == RDHL_EVENT_TEST) {
+ if (event->type == TEST_EVENT_GET_VALUE) {
_I("Test module's event (type = %d) callback is called. Receive %d",
event->type, *arg);
g_cond_signal(&test_worker_thread_cond);
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) {
+ _I("Broadcast local event (arg = %d). It should be failed", *arg_broadcast);
+ if (event_broadcast(TEST_EVENT_GET_VALUE, 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) {
+ _I("Send local event to the test module (arg = %d)", *arg_send);
+ if (event_send("test", TEST_EVENT_GET_VALUE, arg_send) < 0) {
err_code = G_DBUS_ERROR_FAILED;
goto err;
}