dbus-cxx logo
signal_receiver_raw.cpp

This example is part of a series of examples that demonstrate signal emission/handling in a variety of ways.This group of examples are:

Here is this example:

/***************************************************************************
* Copyright (C) 2007,2008,2009 by Rick L. Vinyard, Jr. *
* rvinyard@cs.nmsu.edu *
* *
* This file is part of the dbus-cxx library. *
* *
* The dbus-cxx library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* version 3 as published by the Free Software Foundation. *
* *
* The dbus-cxx library is distributed in the hope that it will be *
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty *
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this software. If not see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include <dbus-cxx.h>
#include <iostream>
#include <unistd.h>
int main()
{
std::string val;
// add a rule for which messages we want to see
connection->add_match( "type='signal',interface='test.signal.Type'" ); // see signals from the given interface
connection->flush();
// loop listening for signals being emmitted
while ( true ) {
// non blocking read of the next available message
connection->read_write( 0 );
msg = connection->pop_message();
// loop again if we haven't read a message
if ( not msg or not msg->is_valid() ) {
sleep( 1 );
continue;
}
// check if the message is a signal from the correct interface
// and with the correct name
if ( msg->is_signal( "test.signal.Type", "Test" ) ) {
// read the parameters
msg >> val;
std::cout << "Got Signal with value " << val << std::endl;
}
}
return 0;
}

Generated on Sun Mar 19 2017 14:54:26 for dbus-cxx by doxygen 1.8.8