Created
April 19, 2018 20:47
-
-
Save melvyniandrag/f341bda0f75e74cf46ca98103672046d to your computer and use it in GitHub Desktop.
Get Volume of VLC over DBus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
g++ thisFile.cpp -I/usr/include/glib-2.0 \ | |
-I/usr/lib/x86_64-linux-gnu/glib-2.0/include/ \ | |
-lglib-2.0 -lgio-2.0 -lgobject-2.0 | |
*/ | |
#include <iostream> | |
#include <gio/gio.h> | |
static GMainLoop* loop = NULL; | |
int main() | |
{ | |
g_autoptr( GDBusConnection ) conn = NULL; | |
g_autoptr( GError ) error = NULL; | |
conn = g_bus_get_sync( G_BUS_TYPE_SESSION, NULL, &error ); | |
g_assert_no_error( error ); | |
if (conn == NULL) | |
std::cout << "Error!" <<std::endl; | |
g_autoptr( GError ) error5 = NULL; | |
g_autoptr( GDBusProxy ) proxy3 = NULL; | |
proxy3 = g_dbus_proxy_new_sync( conn, | |
G_DBUS_PROXY_FLAGS_NONE, | |
NULL, | |
"org.mpris.MediaPlayer2.vlc", | |
"/org/mpris/MediaPlayer2", | |
"org.freedesktop.DBus.Properties", | |
NULL, | |
&error5 ); | |
g_assert_no_error( error5 ); | |
if( proxy3 == NULL ) | |
std::cout << "Error!!" << std::endl; | |
GVariant* ret2 = NULL; | |
g_autoptr( GError ) error6 = NULL; | |
ret2 = g_dbus_proxy_call_sync( proxy3, | |
"Get", | |
g_variant_new("(ss)", "org.mpris.MediaPlayer2.Player", "Volume"), | |
G_DBUS_CALL_FLAGS_NONE, | |
-1, | |
NULL, | |
&error6 ); | |
g_assert_no_error( error6 ); | |
// <sorcery> | |
gdouble d; | |
g_assert (ret2 != NULL); | |
std::cout << "Type of ret2: " << g_variant_get_type_string (ret2) << std::endl; | |
GVariant* ret3 = NULL; | |
ret3 = g_variant_get_child_value( ret2, 0 ); | |
std::cout << "Type of ret3: " << g_variant_get_type_string (ret3) << std::endl; | |
GVariant* ret4 = NULL; | |
ret4 = g_variant_get_variant( ret3 ); | |
std::cout << "Type of ret4: " << g_variant_get_type_string (ret4) << std::endl; | |
//g_assert_cmpstr (g_variant_get_type_string (ret3), ==, "(d)"); | |
d = g_variant_get_double ( ret4 ); | |
//g_variant_unref (ret2); | |
//g_variant_unref (ret3); | |
std::cout << "Volume: " << d << std::endl; | |
//</sorcery> | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment