diff options
author | Javier <dev.git@javispedro.com> | 2015-03-28 21:06:07 +0100 |
---|---|---|
committer | Javier <dev.git@javispedro.com> | 2015-03-28 21:06:07 +0100 |
commit | 1cd1d83ee243db6f3ee929de1346c8e385b2148f (patch) | |
tree | 6943fe89c2d64e262ee0114378f8700ff8ae2c08 /saltoqd/obexconnection.h | |
parent | 08d36eb82a9cc7ef9cc3efe40f26e1a732c8c602 (diff) | |
download | saltoq-1cd1d83ee243db6f3ee929de1346c8e385b2148f.tar.gz saltoq-1cd1d83ee243db6f3ee929de1346c8e385b2148f.zip |
implement fms file transfer (via bt obex push)
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 |