I am trying to receive the network state signal from the NetworkManager.
https://developer.gnome.org/NetworkM...r.StateChanged
I looked at the posts on the forum for Signals & Slots examples. But, could not find one where the signal is being emitted by a service that runs as a system service.
Any help is greatly appreciated.
Thank you
My code is as follows:
class DBus_Access_Manager: public QObject {
public:
unsigned int eventCounter;
unsigned int timeCounter;
DBus_Access_Manager(unsigned int counter, unsigned int timeCount) {
eventCounter = counter;
timeCounter = timeCount;
}
unsigned int getEventCounter(void) {
return eventCounter;
}
unsigned int getTimeCounter(void) {
return timeCounter;
}
void incrementTimeCounter(void) {
timeCounter++;
}
public slots:
void deviceStateChanged(unsigned int newState, unsigned int reason, unsigned int oldState);
void deviceStateChanged(unsigned int newState);
void deviceStateChanged(unsigned int *newState);
};
void DBus_Access_Manager::deviceStateChanged(unsigned int newState, unsigned int reason, unsigned int oldState) {
eventCounter++;
qDebug() << "Device state changed:: 3:: " << newState << " " << reason << " " << oldState;
}
void DBus_Access_Manager::deviceStateChanged(unsigned int newState) {
eventCounter++;
qDebug() << "Device state changed:: 1:: " << newState;
}
void DBus_Access_Manager::deviceStateChanged(unsigned int* newState) {
eventCounter++;
qDebug() << "Device state changed:: 1P:: " << *newState;
}
int main(int argc, char **argv)
{
QCoreApplication nmTestApp(argc, argv);
QDBusConnection systemBus = QDBusConnection::systemBus();
if (!systemBus.isConnected()) {
qDebug() << "!!!!!!!!!!!\n System Bus not connected.Terminating ...\n!!!!!!!!!!!!!!!!!!!!!";
return 1;
}
else {
qDebug() << "!!!!!!!!!!!\n System Bus connected\n!!!!!!!!!!!!!!!!!!!!!";
}
QStringList systemServiceNames = systemBus.interface()->registeredServiceNames();
qDebug() << "System bus Registered Service names: " << systemServiceNames << "\n\n";
//bool result;
DBus_Access_Manager nmObject(10, 100);
QStringList networkDeviceList;
// if ( deviceTypeResponseList[0] == NM_DEVICE_TYPE_ETHERNET)
{
QDBusInterface *ethernetInterface = new QDBusInterface(networkManagerService,
ethernetDevicePath,
nmDeviceInterface,
systemBus);
//&nmObject);
if(ethernetInterface->isValid()) {
qDebug() << "Interface "" << nmDeviceInterface << "" is Valid";
systemBus.connect(networkManagerService, ethernetDevicePath, nmDeviceInterface,
"StateChanged", &nmObject,
SLOT(deviceStateChanged(unsigned int, unsigned int, unsigned int)));
}
}
#if 0
qDebug() << "\n\n\n ..... Starting 30 second Delay Starting ....";
qDebug() << "Event Counter: " << nmObject.getEventCounter() << " Time Counter: " << nmObject.getTimeCounter() << " .... \n\n";
QTime dieTime= QTime::currentTime().addSecs(30);
while (QTime::currentTime() < dieTime) {
QCoreApplication:rocessEvents(QEventLoop::AllEvents, 100);
nmObject.incrementTimeCounter();
}
qDebug() << "\n\n\n ..... End 30 second Delay .... ";
qDebug() << "Event Counter: " << nmObject.getEventCounter() << " Time Counter: " << nmObject.getTimeCounter() << " .... \n\n";
#else
qDebug() << "\n\n\n ..... Waiting for Signal .... \n\n";
nmTestApp.exec();
#endif
return 0;
}
Bookmarks