Signal proxy dies

28 views
Skip to first unread message

Samuel Navarro

unread,
Nov 20, 2019, 7:22:13 AM11/20/19
to Dbus-cxx
Hello all,

I'm afraid I can't update to 2.0 version because I'm using c++11.

About the older version, I'm having some trouble dealing with signals.
I have an application which creates a signal proxy in order to receive the signal sent by other dbus application. The problem is that the signal just works for the first time. Once I've received the signal, if it's sent again, for a second time, I don't receive it.

What do I need to do to receive the singal more than once?

Here is the implementation I have done:


// Signal Receiver application
int main() {

DBus::init();
DBus::Dispatcher::pointer dispatcher = DBus::Dispatcher::create();
DBus::Connection::pointer connection = dispatcher->create_connection(DBus::BUS_SESSION);

int ret = connection->request_name(busname, DBUS_NAME_FLAG_REPLACE_EXISTING );

if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret)
  return;

DBus::signal_proxy<void, uint8_t, std::vector<uint8_t>, uint8_t>::pointer signal = connection->create_signal_proxy<void, uint8_t, std::vector<uint8_t>, uint8_t>("
interface.emitter.signal", "SignalName");

signal->connect(sigc::mem_fun(object, &method));

for(;;){}
}



// Signal emitter application
int main {

DBus::init();
DBus::Dispatcher::pointer dispatcher = DBus::Dispatcher::create();
DBus::Connection::pointer connection = dispatcher->create_connection(DBus::BUS_SESSION);

int ret = connection->request_name( "the.signal.emitter", DBUS_NAME_FLAG_REPLACE_EXISTING );

if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret)
   return;

DBus::Object::pointer objectR = connection->create_object("/the/signal/emitter");

DBus::signal<void, uint8_t, std::vector<uint8_t>, uint8_t>::pointer dbus_signal;

dbus_signal = connection->create_signal<void, uint8_t, std::vector<uint8_t>, uint8_t>("/the/signal/emitter", "interface.emitter.signal", "SignalName");

for(;;) {}
}

Samuel Navarro

unread,
Nov 20, 2019, 9:58:17 AM11/20/19
to Dbus-cxx
Hi again,

I've nocited that the problem is not coming from the signal proxy created.
The problem comes from other class(a caller object) I'm calling inside the method that handles the signal. That method was connected to the signal here:

signal->connect(sigc::mem_fun(object, &method));

Inside the 'method' I do the following, in orther to call other dbus application with different bus and path:

      Exe::pointer exe;
   if(flag == 0)
      exe = Executer::create(busname, path);
   else
      exe = Executer::create(busname2, path2);
   exe->execute(flag, dir);

The exe class looks like this:

class Exe: public DBus::ObjectProxy
{
public:

    typedef DBusCxxPointer<Exe> pointer;
    virtual ~Exe();

    static pointer create(const std::string & busName, const std::string & path)
    {
       DBus::init();
       DBus::Dispatcher::pointer dispatcher = DBus::Dispatcher::create();
       DBus::Connection::pointer connection = dispatcher->create_connection( DBus::BUS_SESSION );
       return pointer(new Exe(connection, busName, path));
    }

    void execute(const uint8_t & flag, const uint8_t & dir)
    {
       return (*this->m_method_execute)(flag, direction);
    }

protected:

    Exe(const DBus::Connection::pointer & conn, const std::string & busName, const std::string & path);
    DBus::MethodProxy<void, uint8_t, uint8_t>::pointer m_method_execute;
};



To sum up what's happening:
When my dbus application receives the signal, it calls another dbus application, in that moment it stops from receiving the signal.
I've checked to not to call the other dbus application when I receive the signal and it works fine, I'm able to receive the signal again and again.

Robert Middleton

unread,
Nov 20, 2019, 11:06:16 AM11/20/19
to Samuel Navarro, Dbus-cxx
If I'm understanding you correctly, you're calling DBus::init again,
correct? You should only call that method once, and also only create
one dispatcher object. I think your 'create' method needs to be
something like this:

static pointer create(DBus::Connection::pointer conn, const
std::string & busName, const std::string & path){
return pointer(new Exe(connection, busName, path));
}

-Robert Middleton
> --
> You received this message because you are subscribed to the Google Groups "Dbus-cxx" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to dbus-cxx+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/dbus-cxx/1be7dfb3-00b8-4526-93f3-8c9a2759776f%40googlegroups.com.
Message has been deleted

Samuel Navarro

unread,
Nov 21, 2019, 4:02:18 AM11/21/19
to Dbus-cxx
Hello Robert,

You are right, I was calling DBus init twice. That was because I could not access the dispatcher object created first, so I needed to create a new one.
Is it possible to create 2 connections just calling init once?.

For now, I'm giving free access to the connection so I can pass it to the create method. I've modified the create as you said and it works fine.

Thank you!
Reply all
Reply to author
Forward
0 new messages