summaryrefslogtreecommitdiff
path: root/noncore/net/opietooth/lib/manager.h
blob: 930eb566c62b0c6da989801bb6873e31b4d5b0fe (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173

#ifndef OpieToothManager_H
#define OpieToothManager_H

#include <qobject.h>
#include <qstring.h>
#include <qmap.h>
#include <qvaluelist.h>

#include "connection.h"
#include "remotedevice.h"
#include "services.h"

namespace Opie {namespace Core {class OProcess;}}
namespace OpieTooth {
    class Device;
    /** Manager manages a blueZ device (hci0 for example)
     *  without Manager you can control the things you
     *  could do from command line in a OO and asynchronus
     *  way.
     */
    class Manager : public QObject {
        Q_OBJECT
    public:
        /** c'tor whichs create a new Manager
         *  @param device is the device to use. Either a mac or blueZ device name
         *
         */
        Manager( const QString &device );

        /** c'tor
         * @param dev The Device to be managed
         * We don't care of Device so you need to delete it
         */
        Manager( Device* dev );

        /**
         * c'tor
         */
        Manager();

        ~Manager();

        /** Set the manager to control a new device
         *  @param device the new device to control (hci0 )
         */
        void setDevice( const QString& device );

        /**
         * Convience functions for setting a new device
         */
        void setDevice( Device *dev );

        /**
         * Wether or not a device is connected. The function
         * is asynchron
         * If device is empty it will take the currently managed
         * device and see if it's up
         * for Remote devices it will ping and see.
         * @param either mac or hciX
         */
        void isAvailable(const QString& device= QString::null );

        /**
         * same as above
         */
        void isAvailable(Device *dev );

        /** this searchs for devices reachable from the
         *  currently managed device
         *  or from device if @param device is not empty
         */
        void searchDevices(const QString& device= QString::null );
        /** same as above
         *
         */
        void searchDevices(Device *d );

        /**
         * This will add the service @param name
         * to the sdpd daemon
         * It will start the daemon if necessary
         */
        void addService(const QString &name );

        /**
         * This will add the services @param names
         * to the sdpd daemon
         * It will start the daemon if necessary
         */
        void addServices( const QStringList& names );

        /**
         * This removes a service from the sdps
         */
        void removeService(const QString &name );

        /**
         * Removes a list from the sdpd
         */
        void removeServices(const QStringList& );

        /**
         * search for services on a remote device
         *
         */
        void searchServices( const QString& remDevice );

        /**
         * search for services on a remote device
         */
        void searchServices( const RemoteDevice& );

        /**
         * Starts to connect to the device
         * in @param
         */
        void connectTo(const QString& );

        /**
         * Searches for active connections
         * the result is emitted with the
         * connections signal
         */
        void searchConnections();

	void signalStrength( const QString &mac );
//// not implemented yet
        /*static*/ QString toDevice( const QString& mac );
        /*static*/ QString toMac( const QString &device );
//// not implemented yet over

    signals:
        // device either mac or dev name
        // the first device is the device which you access
        void available( const QString& device, bool connected );
        void addedService(  const QString& service, bool added );
        void removedService( const QString& service, bool removed );
        void foundServices( const QString& device, Services::ValueList );
        void foundDevices( const QString& device, RemoteDevice::ValueList );
        void connections( ConnectionState::ValueList );
	void signalStrength( const QString& mac, const QString& strengh );

private slots:
        void slotProcessExited(Opie::Core::OProcess* );

        void slotSDPExited(Opie::Core::OProcess*);
        void slotSDPOut(Opie::Core::OProcess*, char*, int);

        void slotHCIExited(Opie::Core::OProcess* );
        void slotHCIOut(Opie::Core::OProcess*, char*, int );

        void slotConnectionExited(Opie::Core::OProcess* );
        void slotConnectionOutput(Opie::Core::OProcess*, char*, int );

	void slotSignalStrengthOutput( Opie::Core::OProcess*, char*, int );
	void slotSignalStrengthExited( Opie::Core::OProcess* );
    private:
        Services::ValueList parseSDPOutput( const QString& );
        RemoteDevice::ValueList parseHCIOutput( const QString& );
        ConnectionState::ValueList parseConnections( const QString& );
        Opie::Core::OProcess *m_hcitool;
        Opie::Core::OProcess *m_sdp; // not only one
        QString m_device;
	QMap<QString, int> m_signalStrength;
        QMap<QString, QString> m_out;
        QMap<QString, QString> m_devices;
	QMap<Opie::Core::OProcess*, QString> m_signalMac;
        QString m_hcitoolCon;
    };
};

#endif