diff options
Diffstat (limited to 'saltoqd/obexconnection.h')
-rw-r--r-- | saltoqd/obexconnection.h | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/saltoqd/obexconnection.h b/saltoqd/obexconnection.h new file mode 100644 index 0000000..431af9b --- /dev/null +++ b/saltoqd/obexconnection.h @@ -0,0 +1,83 @@ +#ifndef OBEXCONNECTION_H +#define OBEXCONNECTION_H + +#include <QtCore/QQueue> +#include "toqconnection.h" + +typedef void* obex_t; +typedef void* obex_object_t; + +class ObexConnection; + +class ObexTransfer : public QObject +{ + Q_OBJECT + + friend class ObexConnection; + + explicit ObexTransfer(obex_t *obex, obex_object_t *obj, QObject *parent); + ~ObexTransfer(); + +public slots: + void cancel(); + +signals: + void finished(); + void error(int response); + +private: + obex_t *_obex; + obex_object_t *_obj; +}; + +class ObexConnection : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool connected READ isConnected) + +public: + explicit ObexConnection(ToqConnection *conn, QObject *parent = 0); + + bool isConnected() const; + + ObexTransfer *put(const QString &name, const QByteArray &data); + +signals: + void connected(); + void disconnected(); + +private slots: + void tryConnect(); + void handleToqConnected(); + void handleToqDisconnected(); + void handleSocketConnected(); + void handleSocketDisconnected(); + void handleSocketError(QBluetoothSocket::SocketError error); + void handleSocketData(); + void handleTransferDestroyed(); + void handleNextPending(); + +private: + static void handleObexEvent(obex_t *handle, obex_object_t *obj, int mode, int event, int obex_cmd, int obex_rsp); + static int obexConnect(obex_t *handle, void *data); + static int obexDisconnect(obex_t *handle, void *data); + static int obexListen(obex_t *handle, void *data); + static int obexWrite(obex_t *handle, void *data, quint8 *buf, int buflen); + static int obexHandleInput(obex_t *handle, void *data, int timeout); + + ToqConnection *_conn; + QBluetoothSocket *_socket; + QTimer *_reconnectTimer; + obex_t *_obex; + bool _connected; + + QQueue<ObexTransfer*> _pending; + bool _busy; +}; + +inline bool ObexConnection::isConnected() const +{ + return _connected; +} + +#endif // OBEXCONNECTION_H |