#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."<<endl;
+ }
+
+ if (condition & G_IO_HUP)
+ {
+ //Hang up. Returning false closes out the GIOChannel.
+ //printf("Callback on G_IO_HUP\n");
+ DebugOut(DebugOut::Warning)<<"socket hangup event..."<<endl;
+ return false;
+ }
+
+ BluetoothSinkPlugin* p = static_cast<BluetoothSinkPlugin*>(data);
+
+ p->canHasData();
+
+ return true;
+}
+
BluetoothSinkPlugin::BluetoothSinkPlugin(AbstractRoutingEngine* re, map<string, string> config)
:AbstractSink(re, config)
{
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)
QByteArray data = socket.read().c_str();
DebugOut()<<"data read: "<<data.constData()<<endl;
+
+ if(data == "ping")
+ socket.write("pong");
}
BtProfileAdaptor::BtProfileAdaptor(BluetoothSinkPlugin *parent)
#include "bluetooth5.h"
#include <serialport.hpp>
-#include <QSocketNotifier>
+
+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."<<endl;
+ }
+
+ if (condition & G_IO_HUP)
+ {
+ //Hang up. Returning false closes out the GIOChannel.
+ //printf("Callback on G_IO_HUP\n");
+ DebugOut(DebugOut::Warning)<<"socket hangup event..."<<endl;
+ return false;
+ }
+
+ DebugOut(0)<<"Data: "<<s->read();
+
+ return true;
+}
int main(int argc, char** argv)
{
Bluetooth5 btdev;
btdev.getDeviceForAddress(addy.toStdString(),[](int fd){
DebugOut(0)<<"I am connected"<<endl;
-
- SerialPort *s = new SerialPort();
s->setDescriptor(fd);
- QSocketNotifier* sock = new QSocketNotifier(fd, QSocketNotifier::Read);
-
- QObject::connect(sock, &QSocketNotifier::activated, [&s](){
- DebugOut(0)<<"data: "<<s->read()<<endl;
- });
-
-
+ GIOChannel *chan = g_io_channel_unix_new(s->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();