Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/intel_lpmd_dbus_interface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@
<method name="LPM_AUTO">
</method>

<method name="GetState">
<arg type="s" name="state" direction="out"/>
</method>

</interface>
</node>
17 changes: 17 additions & 0 deletions src/lpmd_dbus_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,23 @@ lpmd_dbus_handle_method_call(GDBusConnection *connection,
return;
}

if (g_strcmp0(method_name, "GetState") == 0) {
const char *state_names[] = {
[LPMD_OFF] = "OFF",
[LPMD_ON] = "ON",
[LPMD_AUTO] = "AUTO",
[LPMD_FREEZE] = "FREEZE",
[LPMD_RESTORE] = "RESTORE",
[LPMD_TERMINATE] = "TERMINATE",
};
int state = get_lpmd_state();
const char *name = (state >= 0 && state <= LPMD_TERMINATE) ? state_names[state] : "UNKNOWN";

g_dbus_method_invocation_return_value(invocation,
g_variant_new("(s)", name));
return;
}

g_set_error(&error,
G_DBUS_ERROR,
G_DBUS_ERROR_UNKNOWN_METHOD,
Expand Down
38 changes: 33 additions & 5 deletions tools/intel_lpmd_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,42 @@ main(int argc, char **argv)
if (argc < 2) {
fprintf (stderr, "intel_lpmd_control: missing control command\n");
fprintf (stderr, "syntax:\n");
fprintf (stderr, "intel_lpmd_control ON|OFF|AUTO\n");
fprintf (stderr, "intel_lpmd_control ON|OFF|AUTO|STATUS\n");
exit (0);
}

connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
if (connection == NULL)
return FALSE;

if (!strncmp (argv[1], "STATUS", 6)) {
g_autoptr(GVariant) result = NULL;

result = g_dbus_connection_call_sync (connection,
INTEL_LPMD_SERVICE_NAME,
INTEL_LPMD_SERVICE_OBJECT_PATH,
INTEL_LPMD_SERVICE_INTERFACE,
"GetState",
NULL,
G_VARIANT_TYPE ("(s)"),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);

if (error != NULL) {
g_warning ("Fail on connecting lpmd: %s", error->message);
exit (1);
}

const gchar *state;

g_variant_get (result, "(&s)", &state);
g_print ("%s\n", state);

return 0;
}

if (!strncmp (argv[1], "ON", 2))
command = g_string_new ("LPM_FORCE_ON");
else if (!strncmp (argv[1], "OFF", 3))
Expand All @@ -66,10 +98,6 @@ main(int argc, char **argv)
exit (1);
}

connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
if (connection == NULL)
return FALSE;

g_dbus_connection_call_sync (connection,
INTEL_LPMD_SERVICE_NAME,
INTEL_LPMD_SERVICE_OBJECT_PATH,
Expand Down