From: Kevron Rees Date: Tue, 27 May 2014 18:40:39 +0000 (-0700) Subject: use gio for watching fd X-Git-Tag: submit/tizen_ivi/20140619.111013~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2dddacdbb338b5aafd29b07fabbec34a9d21dd80;p=profile%2Fivi%2Fautomotive-message-broker.git use gio for watching fd --- diff --git a/plugins/bluetooth/bluetoothplugin.cpp b/plugins/bluetooth/bluetoothplugin.cpp index ca98229..76c3076 100644 --- a/plugins/bluetooth/bluetoothplugin.cpp +++ b/plugins/bluetooth/bluetoothplugin.cpp @@ -34,6 +34,30 @@ using namespace std; #include "debugout.h" +bool readCallback(GIOChannel *source, GIOCondition condition, gpointer data) +{ +// DebugOut(5) << "Polling..." << condition << endl; + + if(condition & G_IO_ERR) + { + DebugOut(DebugOut::Error)<<"GpsNmeaSource polling error."<(data); + + p->canHasData(); + + return true; +} + BluetoothSinkPlugin::BluetoothSinkPlugin(AbstractRoutingEngine* re, map config) :AbstractSink(re, config) { @@ -89,9 +113,10 @@ void BluetoothSinkPlugin::newConnection(string path, QDBusUnixFileDescriptor fd, socket.setDescriptor(fd.fileDescriptor()); - QSocketNotifier *notifier = new QSocketNotifier(fd.fileDescriptor(), QSocketNotifier::Read, this); - - connect(notifier,&QSocketNotifier::activated,this, &BluetoothSinkPlugin::canHasData); + GIOChannel *chan = g_io_channel_unix_new(socket.fileDescriptor()); + g_io_add_watch(chan, GIOCondition(G_IO_IN | G_IO_HUP | G_IO_ERR),(GIOFunc)readCallback, this); + g_io_channel_set_close_on_unref(chan, true); + g_io_channel_unref(chan); } void BluetoothSinkPlugin::requestDisconnection(string path) @@ -105,6 +130,9 @@ void BluetoothSinkPlugin::canHasData() QByteArray data = socket.read().c_str(); DebugOut()<<"data read: "< -#include + +SerialPort *s = new SerialPort(); + +bool readCallback(GIOChannel *source, GIOCondition condition, gpointer data) +{ +// DebugOut(5) << "Polling..." << condition << endl; + + if(condition & G_IO_ERR) + { + DebugOut(DebugOut::Error)<<"GpsNmeaSource polling error."<read(); + + return true; +} int main(int argc, char** argv) { @@ -18,18 +41,14 @@ int main(int argc, char** argv) Bluetooth5 btdev; btdev.getDeviceForAddress(addy.toStdString(),[](int fd){ DebugOut(0)<<"I am connected"<setDescriptor(fd); - QSocketNotifier* sock = new QSocketNotifier(fd, QSocketNotifier::Read); - - QObject::connect(sock, &QSocketNotifier::activated, [&s](){ - DebugOut(0)<<"data: "<read()<fileDescriptor()); + g_io_add_watch(chan, GIOCondition(G_IO_IN | G_IO_HUP | G_IO_ERR),(GIOFunc)readCallback, nullptr); + g_io_channel_set_close_on_unref(chan, true); + g_io_channel_unref(chan); + s->write("ping"); }); return app.exec();