This probably has a simple answer, but I do not know what to search for to find it..
I am using This c++ dbus wrapper to control the Audio player Clementine (on linux).
slightly adapting their example client shown here(literally changing a few strings and types) I can control Clementine just fine.
My confusion is in the definition of the methods, done with this notation:
DBus::MethodProxy<double,double,double>& add_proxy
= *(object->create_method<double,double,double>("dbuscxx.Quickstart","add"));
This woks fine when everything in one main method, but when I am trying to make a helper class, and I cannot figure out how to do it. Here is what I have:
//Mpris.hpp
#ifndef MPRIS_HPP
#define MPRIS_HPP
#include <dbus-cxx.h>
using namespace std;
using namespace DBus;
class Mpris
{
public:
Mpris(string bus_name, string interface_name);
MethodProxy<string>& identify;
private:
Dispatcher::pointer dispatcher;
Connection::pointer connection;
ObjectProxy::pointer Root;
ObjectProxy::pointer TrackList;
ObjectProxy::pointer Player;
};
#endif
I
//Mpris.cpp
#include "Mpris.hpp"
Mpris::Mpris(string bus_name, string interface_name)
{
dispatcher = Dispatcher::create();
connection = dispatcher->create_connection(DBus::BUS_SESSION);
Root = connection->create_object_proxy(bus_name, "/");
TrackList = connection->create_object_proxy(bus_name,
"/TrackList");
Player = connection->create_object_proxy(bus_name,
"/Player");
MethodProxy<string> &identify = *(Root->create_method<string>(interface_name,
"Identify"));
}
Test:
//MprisTest.cpp
#include "Mpris.hpp"
#include <iostream>
using namespace std;
int main(int arg, char **argv)
{
Mpris mpris("org.mpris.clementine", "org.freedesktop.MediaPlayer");
cout << mpris.identify() << endl;
return 0;
}
This obviously fails to compile.
$ g++ -g -Wall Mpris.cpp MprisTest.cpp -o MprisTest `pkg-config --libs --cflags dbus-cxx-1.0`
Mpris.cpp: In constructor ‘Mpris::Mpris(std::string, std::string)’:
Mpris.cpp:5:1: error: uninitialized reference member in ‘class DBus::MethodProxy<std::basic_string<char> >&’ [-fpermissive]
Mpris::Mpris(string bus_name, string interface_name)
^
In file included from Mpris.cpp:3:0:
Mpris.hpp:15:23: note: ‘DBus::MethodProxy<std::basic_string<char> >& Mpris::identify’ should be initialized
MethodProxy<string>& identify;
^
How do I properly define all these proxy methods in my helper class? Once again, I'm sure this is a simple concept I just don't quite understand.