#define RESOURCED_BUS_NAME "org.tizen.resourced"
#define RESOURCED_USAGE_OBJECT_NAME "/Org/Tizen/ResourceD/Process"
#define RESOURCED_USAGE_INTERFACE_NAME "org.tizen.resourced.process"
-#define RESOURCED_MEMORY_USAGE_METHOD "ProcMemoryUsage"
-#define RESOURCED_CPU_USAGE_METHOD "ProcCpuUsage"
#define DBUS_REPLY_TIMEOUT (120 * 1000)
-#define MEMORY_USAGE 1
-#define CPU_USAGE 2
+
+typedef enum {
+ USAGE_TYPE_PROCESS_MEMORY,
+ USAGE_TYPE_PROCESS_CPU,
+} runtime_info_usage_type_e;
+
+typedef struct {
+ const char *method_name;
+ const char *caption;
+} runtime_info_dbus_info_s;
+
+/* The index of this array must be matched with runtime_info_usage_type_e */
+static const runtime_info_dbus_info_s dbus_info[] = {
+ { "ProcMemoryUsage", "process memory" },
+ { "ProcCpuUsage", "process cpu" },
+};
#define kBtoKiB(val) (int)(((long long)val * 1024)/1000)
#define pagetoKiB(val) (int)((long long)val * 4096 / 1000)
* Creates the method call to resourced and receives the reply (if successful)
* Return the received reply (if received) else NULL to signify failed call to resourced
*/
-static DBusMessage *runtime_info_dbus_process_usage_info(int *pid, int size, int info, int *error)
+static DBusMessage *runtime_info_dbus_process_usage_info(int *pid, int size,
+ runtime_info_usage_type_e type, int *error)
{
DBusConnection *conn;
DBusMessage *msg;
//LCOV_EXCL_STOP
}
- if (info == MEMORY_USAGE) {
- _D("Process %d: received query to get process memory info of %d processes",
- getpid(), size);
- msg = dbus_message_new_method_call(RESOURCED_BUS_NAME,
- RESOURCED_USAGE_OBJECT_NAME,
- RESOURCED_USAGE_INTERFACE_NAME,
- RESOURCED_MEMORY_USAGE_METHOD);
- } else if (info == CPU_USAGE) {
- _D("Process %d: received query to get process cpu usage of %d processes",
- getpid(), size);
- msg = dbus_message_new_method_call(RESOURCED_BUS_NAME,
- RESOURCED_USAGE_OBJECT_NAME,
- RESOURCED_USAGE_INTERFACE_NAME,
- RESOURCED_CPU_USAGE_METHOD);
- } else {
- _E("INVALID_PARAMETER(0x%08x): info parameter should be %d or %d",
- MEMORY_USAGE, CPU_USAGE, RUNTIME_INFO_ERROR_INVALID_PARAMETER);
+ if (type != USAGE_TYPE_PROCESS_MEMORY && type != USAGE_TYPE_PROCESS_CPU) {
+ //LCOV_EXCL_START : system error
+ _E("INVALID_PARAMETER(0x%08x): invalid info parameter",
+ RUNTIME_INFO_ERROR_INVALID_PARAMETER);
*error = RUNTIME_INFO_ERROR_INVALID_PARAMETER;
return NULL;
+ //LCOV_EXCL_STOP
}
+ _D("Process %d: received query to get %s usage of %d processes",
+ getpid(), dbus_info[type].caption, size);
+
+ msg = dbus_message_new_method_call(RESOURCED_BUS_NAME,
+ RESOURCED_USAGE_OBJECT_NAME,
+ RESOURCED_USAGE_INTERFACE_NAME,
+ dbus_info[type].method_name);
if (!msg) {
+ //LCOV_EXCL_START : system error
_E("DBUS_METHOD_CALL: not able to create method call (%s:%s-%s)",
RESOURCED_USAGE_OBJECT_NAME, RESOURCED_USAGE_INTERFACE_NAME,
- RESOURCED_MEMORY_USAGE_METHOD);
+ dbus_info[type].method_name);
*error = RUNTIME_INFO_ERROR_OUT_OF_MEMORY;
return NULL;
+ //LCOV_EXCL_STOP
}
ret = dbus_message_append_args(msg, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32, &pid,
dbus_error_init(&err);
*error = 0;
- if (info == MEMORY_USAGE)
- _D("Process %d: Sending dbus message to resourced for process memory usage info",
- getpid());
- else
- _D("Process %d: Sending dbus message to resourced for process cpu usage info",
- getpid());
+ _D("Process %d: Sending dbus message to resourced for %s usage info",
+ getpid(), dbus_info[type].caption);
+
reply = dbus_connection_send_with_reply_and_block(conn, msg,
DBUS_REPLY_TIMEOUT, &err);
if (!reply)
*info = NULL;
/* Get the needed information from resourced daemon using dbus */
- replymsg = runtime_info_dbus_process_usage_info(pid, size, MEMORY_USAGE, &error);
+ replymsg = runtime_info_dbus_process_usage_info(pid, size, USAGE_TYPE_PROCESS_MEMORY, &error);
if (!replymsg) {
//LCOV_EXCL_START : system error
_E("DBUS_METHOD_CALL: call to resourced not successful");
*usage = NULL;
/* Get the needed information from resourced daemon using dbus */
- replymsg = runtime_info_dbus_process_usage_info(pid, size, CPU_USAGE, &error);
+ replymsg = runtime_info_dbus_process_usage_info(pid, size, USAGE_TYPE_PROCESS_CPU, &error);
if (!replymsg) {
//LCOV_EXCL_START : system error