summaryrefslogtreecommitdiff
path: root/saltoqd/obexconnection.h
blob: 45345c9acbe0af18f1a21a8d5a9b38acf8789dfb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#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);

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