author | zecke <zecke> | 2002-06-15 20:06:04 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-06-15 20:06:04 (UTC) |
commit | b15f8a613d83a2f3957fef515e20981f636b908b (patch) (unidiff) | |
tree | 6d2e6743ceb4c3cb299944efc4b2925e5f40412d | |
parent | ef75752efaef84e4b7350f9768f3cb3c4fd744af (diff) | |
download | opie-b15f8a613d83a2f3957fef515e20981f636b908b.zip opie-b15f8a613d83a2f3957fef515e20981f636b908b.tar.gz opie-b15f8a613d83a2f3957fef515e20981f636b908b.tar.bz2 |
isCOnnected, add and remove Service + first bits of service browsing done
-rw-r--r-- | noncore/net/opietooth/lib/device.cc | 30 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/device.h | 12 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/lib.pro | 5 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/manager.cc | 99 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/manager.h | 29 |
5 files changed, 127 insertions, 48 deletions
diff --git a/noncore/net/opietooth/lib/device.cc b/noncore/net/opietooth/lib/device.cc index e3d7f3b..5234996 100644 --- a/noncore/net/opietooth/lib/device.cc +++ b/noncore/net/opietooth/lib/device.cc | |||
@@ -1,142 +1,142 @@ | |||
1 | 1 | ||
2 | #include <signal.h> | 2 | #include <signal.h> |
3 | 3 | ||
4 | #include "kprocess.h" | 4 | #include <opie/oprocess.h> |
5 | 5 | ||
6 | #include "device.h" | 6 | #include "device.h" |
7 | 7 | ||
8 | using namespace OpieTooth; | 8 | using namespace OpieTooth; |
9 | 9 | ||
10 | namespace { | 10 | namespace { |
11 | int parsePid( const QCString& par ){ | 11 | int parsePid( const QCString& par ){ |
12 | int id=0; | 12 | int id=0; |
13 | QString string( par ); | 13 | QString string( par ); |
14 | QStringList list = QStringList::split( '\n', string ); | 14 | QStringList list = QStringList::split( '\n', string ); |
15 | for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ){ | 15 | for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ){ |
16 | if( !(*it).startsWith("CSR") ){ | 16 | if( !(*it).startsWith("CSR") ){ |
17 | id = (*it).toInt(); | 17 | id = (*it).toInt(); |
18 | break; | 18 | break; |
19 | } | 19 | } |
20 | } | 20 | } |
21 | return id; | 21 | return id; |
22 | } | 22 | } |
23 | } | 23 | } |
24 | 24 | ||
25 | Device::Device(const QString &device, const QString &mode ) | 25 | Device::Device(const QString &device, const QString &mode ) |
26 | : QObject(0, "device" ) { | 26 | : QObject(0, "device" ) { |
27 | qWarning("OpieTooth::Device create" ); | 27 | qWarning("OpieTooth::Device create" ); |
28 | m_hci = 0; | 28 | m_hci = 0; |
29 | m_process = 0; | 29 | m_process = 0; |
30 | m_attached = false; | 30 | m_attached = false; |
31 | m_device = device; | 31 | m_device = device; |
32 | m_mode = mode; | 32 | m_mode = mode; |
33 | attach(); | 33 | attach(); |
34 | } | 34 | } |
35 | Device::~Device(){ | 35 | Device::~Device(){ |
36 | detach(); | 36 | detach(); |
37 | } | 37 | } |
38 | void Device::attach(){ | 38 | void Device::attach(){ |
39 | qWarning("attaching %s %s", m_device.latin1(), m_mode.latin1() ); | 39 | qWarning("attaching %s %s", m_device.latin1(), m_mode.latin1() ); |
40 | if(m_process == 0 ){ | 40 | if(m_process == 0 ){ |
41 | m_output.resize(0); | 41 | m_output.resize(0); |
42 | qWarning("new process to create" ); | 42 | qWarning("new process to create" ); |
43 | m_process = new KProcess(); | 43 | m_process = new OProcess(); |
44 | *m_process << "hciattach"; | 44 | *m_process << "hciattach"; |
45 | *m_process << "-p"; | 45 | *m_process << "-p"; |
46 | *m_process << m_device << m_mode; | 46 | *m_process << m_device << m_mode; |
47 | connect(m_process, SIGNAL( processExited(KProcess*) ), | 47 | connect(m_process, SIGNAL( processExited(OProcess*) ), |
48 | this, SLOT( slotExited(KProcess* ) ) ); | 48 | this, SLOT( slotExited(OProcess* ) ) ); |
49 | connect(m_process, SIGNAL( receivedStdout(KProcess*, char*, int) ), | 49 | connect(m_process, SIGNAL( receivedStdout(OProcess*, char*, int) ), |
50 | this, SLOT(slotStdOut(KProcess*,char*,int ) ) ); | 50 | this, SLOT(slotStdOut(OProcess*,char*,int ) ) ); |
51 | connect(m_process, SIGNAL(receivedStderr(KProcess*, char*, int ) ), | 51 | connect(m_process, SIGNAL(receivedStderr(OProcess*, char*, int ) ), |
52 | this, SLOT(slotStdErr(KProcess*,char*,int) ) ); | 52 | this, SLOT(slotStdErr(OProcess*,char*,int) ) ); |
53 | if(!m_process->start(KProcess::NotifyOnExit, KProcess::AllOutput ) ){ | 53 | if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ){ |
54 | qWarning("Could not start" ); | 54 | qWarning("Could not start" ); |
55 | delete m_process; | 55 | delete m_process; |
56 | m_process = 0; | 56 | m_process = 0; |
57 | } | 57 | } |
58 | }; | 58 | }; |
59 | } | 59 | } |
60 | void Device::detach(){ | 60 | void Device::detach(){ |
61 | delete m_hci; | 61 | delete m_hci; |
62 | delete m_process; | 62 | delete m_process; |
63 | // kill the pid we got | 63 | // kill the pid we got |
64 | if(m_attached ){ | 64 | if(m_attached ){ |
65 | //kill the pid | 65 | //kill the pid |
66 | qWarning( "killing" ); | 66 | qWarning( "killing" ); |
67 | kill(pid, 9); | 67 | kill(pid, 9); |
68 | } | 68 | } |
69 | qWarning("detached" ); | 69 | qWarning("detached" ); |
70 | } | 70 | } |
71 | bool Device::isLoaded()const{ | 71 | bool Device::isLoaded()const{ |
72 | return m_attached; | 72 | return m_attached; |
73 | } | 73 | } |
74 | QString Device::devName()const { | 74 | QString Device::devName()const { |
75 | return QString::fromLatin1("hci0"); | 75 | return QString::fromLatin1("hci0"); |
76 | }; | 76 | }; |
77 | void Device::slotExited( KProcess* proc) | 77 | void Device::slotExited( OProcess* proc) |
78 | { | 78 | { |
79 | qWarning("prcess exited" ); | 79 | qWarning("prcess exited" ); |
80 | if(proc== m_process ){ | 80 | if(proc== m_process ){ |
81 | if( m_process->normalExit() ){ // normal exit | 81 | if( m_process->normalExit() ){ // normal exit |
82 | int ret = m_process->exitStatus(); | 82 | int ret = m_process->exitStatus(); |
83 | if( ret == 0 ){ // attached | 83 | if( ret == 0 ){ // attached |
84 | qWarning("attached" ); | 84 | qWarning("attached" ); |
85 | qWarning("Output: %s", m_output.data() ); | 85 | qWarning("Output: %s", m_output.data() ); |
86 | pid = parsePid( m_output ); | 86 | pid = parsePid( m_output ); |
87 | qWarning("Pid = %d", pid ); | 87 | qWarning("Pid = %d", pid ); |
88 | // now hciconfig hci0 up ( determine hciX FIXME) | 88 | // now hciconfig hci0 up ( determine hciX FIXME) |
89 | // and call hciconfig hci0 up | 89 | // and call hciconfig hci0 up |
90 | // FIXME hardcoded to hci0 now :( | 90 | // FIXME hardcoded to hci0 now :( |
91 | m_hci = new KProcess( ); | 91 | m_hci = new OProcess( ); |
92 | *m_hci << "hciconfig"; | 92 | *m_hci << "hciconfig"; |
93 | *m_hci << "hci0 up"; | 93 | *m_hci << "hci0 up"; |
94 | connect(m_hci, SIGNAL( processExited(KProcess*) ), | 94 | connect(m_hci, SIGNAL( processExited(OProcess*) ), |
95 | this, SLOT( slotExited(KProcess* ) ) ); | 95 | this, SLOT( slotExited(OProcess* ) ) ); |
96 | if(!m_hci->start() ){ | 96 | if(!m_hci->start() ){ |
97 | qWarning("could not start" ); | 97 | qWarning("could not start" ); |
98 | m_attached = false; | 98 | m_attached = false; |
99 | emit device("hci0", false ); | 99 | emit device("hci0", false ); |
100 | } | 100 | } |
101 | }else{ | 101 | }else{ |
102 | m_attached = false; | 102 | m_attached = false; |
103 | emit device("hci0", false ); | 103 | emit device("hci0", false ); |
104 | 104 | ||
105 | } | 105 | } |
106 | } | 106 | } |
107 | delete m_process; | 107 | delete m_process; |
108 | m_process = 0; | 108 | m_process = 0; |
109 | }else if(proc== m_hci ){ | 109 | }else if(proc== m_hci ){ |
110 | qWarning("M HCI exited" ); | 110 | qWarning("M HCI exited" ); |
111 | if( m_hci->normalExit() ){ | 111 | if( m_hci->normalExit() ){ |
112 | qWarning("normal exit" ); | 112 | qWarning("normal exit" ); |
113 | int ret = m_hci->exitStatus(); | 113 | int ret = m_hci->exitStatus(); |
114 | if( ret == 0 ){ | 114 | if( ret == 0 ){ |
115 | qWarning("attached really really attached" ); | 115 | qWarning("attached really really attached" ); |
116 | m_attached = true; | 116 | m_attached = true; |
117 | emit device("hci0", true ); | 117 | emit device("hci0", true ); |
118 | }else{ | 118 | }else{ |
119 | qWarning( "failed" ); | 119 | qWarning( "failed" ); |
120 | emit device("hci0", false ); | 120 | emit device("hci0", false ); |
121 | m_attached = false; | 121 | m_attached = false; |
122 | } | 122 | } |
123 | }// normal exit | 123 | }// normal exit |
124 | delete m_hci; | 124 | delete m_hci; |
125 | m_hci = 0; | 125 | m_hci = 0; |
126 | } | 126 | } |
127 | } | 127 | } |
128 | void Device::slotStdOut(KProcess* proc, char* chars, int len) | 128 | void Device::slotStdOut(OProcess* proc, char* chars, int len) |
129 | { | 129 | { |
130 | qWarning("std out" ); | 130 | qWarning("std out" ); |
131 | if( len <1 ) | 131 | if( len <1 ) |
132 | return; | 132 | return; |
133 | if(proc == m_process ){ | 133 | if(proc == m_process ){ |
134 | QCString string( chars, len+1 ); // \0 == +1 | 134 | QCString string( chars, len+1 ); // \0 == +1 |
135 | qWarning("output: %s", string.data() ); | 135 | qWarning("output: %s", string.data() ); |
136 | m_output.append( string.data() ); | 136 | m_output.append( string.data() ); |
137 | } | 137 | } |
138 | } | 138 | } |
139 | void Device::slotStdErr(KProcess*, char*, int ) | 139 | void Device::slotStdErr(OProcess*, char*, int ) |
140 | { | 140 | { |
141 | qWarning("std err" ); | 141 | qWarning("std err" ); |
142 | } | 142 | } |
diff --git a/noncore/net/opietooth/lib/device.h b/noncore/net/opietooth/lib/device.h index 8498b14..c0e2658 100644 --- a/noncore/net/opietooth/lib/device.h +++ b/noncore/net/opietooth/lib/device.h | |||
@@ -1,85 +1,85 @@ | |||
1 | 1 | ||
2 | #ifndef OpieToothDevice_H | 2 | #ifndef OpieToothDevice_H |
3 | #define OpieToothDevice_H | 3 | #define OpieToothDevice_H |
4 | 4 | ||
5 | #include <qobject.h> | 5 | #include <qobject.h> |
6 | #include <qstring.h> | 6 | #include <qstring.h> |
7 | #include <qvaluelist.h> | 7 | #include <qvaluelist.h> |
8 | 8 | ||
9 | #include <sys/types.h> | 9 | #include <sys/types.h> |
10 | 10 | ||
11 | class KProcess; | 11 | class OProcess; |
12 | namespace OpieTooth { | 12 | namespace OpieTooth { |
13 | /** | 13 | /** |
14 | * Device takes care of attaching serial | 14 | * Device takes care of attaching serial |
15 | * devices to the blueZ stack. | 15 | * devices to the blueZ stack. |
16 | * After attaching it hciconfig ups it | 16 | * After attaching it hciconfig ups it |
17 | */ | 17 | */ |
18 | class Device : public QObject { | 18 | class Device : public QObject { |
19 | Q_OBJECT | 19 | Q_OBJECT |
20 | 20 | ||
21 | public: | 21 | public: |
22 | 22 | ||
23 | /** | 23 | /** |
24 | * Brings up an device. | 24 | * Brings up an device. |
25 | * Usage example: new Device(/dev/ttySB0, csr) | 25 | * Usage example: new Device(/dev/ttySB0, csr) |
26 | * | 26 | * |
27 | * @param &device QString the device name | 27 | * @param &device QString the device name |
28 | * @param &mode QString the mode | 28 | * @param &mode QString the mode |
29 | */ | 29 | */ |
30 | Device(const QString &device, const QString& mode); | 30 | Device(const QString &device, const QString& mode); |
31 | 31 | ||
32 | /** | 32 | /** |
33 | * unloads the device | 33 | * unloads the device |
34 | */ | 34 | */ |
35 | ~Device(); | 35 | ~Device(); |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * attach the device | 38 | * attach the device |
39 | */ | 39 | */ |
40 | void attach(); | 40 | void attach(); |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * detach the device | 43 | * detach the device |
44 | */ | 44 | */ |
45 | void detach(); | 45 | void detach(); |
46 | 46 | ||
47 | /** | 47 | /** |
48 | * Is the device loaded? | 48 | * Is the device loaded? |
49 | * @return bool, if the device is loaded | 49 | * @return bool, if the device is loaded |
50 | */ | 50 | */ |
51 | bool isLoaded()const; | 51 | bool isLoaded()const; |
52 | 52 | ||
53 | /** | 53 | /** |
54 | * Returns the device name | 54 | * Returns the device name |
55 | * @return QString, the device name | 55 | * @return QString, the device name |
56 | */ | 56 | */ |
57 | QString devName()const ; // hci0 | 57 | QString devName()const ; // hci0 |
58 | 58 | ||
59 | signals: | 59 | signals: |
60 | 60 | ||
61 | /** | 61 | /** |
62 | * Signals devicename and up status | 62 | * Signals devicename and up status |
63 | * @return &device QString, Devicename | 63 | * @return &device QString, Devicename |
64 | * @return up bool, if the device is up or not. | 64 | * @return up bool, if the device is up or not. |
65 | */ | 65 | */ |
66 | void device(const QString& device, bool up ); | 66 | void device(const QString& device, bool up ); |
67 | private slots: | 67 | private slots: |
68 | virtual void slotExited( KProcess* ); | 68 | virtual void slotExited( OProcess* ); |
69 | virtual void slotStdOut(KProcess*, char*, int ); | 69 | virtual void slotStdOut(OProcess*, char*, int ); |
70 | virtual void slotStdErr(KProcess*, char*, int ); | 70 | virtual void slotStdErr(OProcess*, char*, int ); |
71 | private: | 71 | private: |
72 | class Private; | 72 | class Private; |
73 | Private *d; | 73 | Private *d; |
74 | QString m_device; | 74 | QString m_device; |
75 | bool m_attached:1; | 75 | bool m_attached:1; |
76 | KProcess* m_hci; | 76 | OProcess* m_hci; |
77 | KProcess* m_process; | 77 | OProcess* m_process; |
78 | QString m_devId; | 78 | QString m_devId; |
79 | QString m_mode; | 79 | QString m_mode; |
80 | pid_t pid; | 80 | pid_t pid; |
81 | QCString m_output; | 81 | QCString m_output; |
82 | }; | 82 | }; |
83 | }; | 83 | }; |
84 | 84 | ||
85 | #endif | 85 | #endif |
diff --git a/noncore/net/opietooth/lib/lib.pro b/noncore/net/opietooth/lib/lib.pro index a70c7ab..f2cde06 100644 --- a/noncore/net/opietooth/lib/lib.pro +++ b/noncore/net/opietooth/lib/lib.pro | |||
@@ -1,8 +1,9 @@ | |||
1 | TEMPLATE = lib | 1 | TEMPLATE = lib |
2 | CONFIG += qte warn_on release | 2 | CONFIG += qte warn_on release |
3 | HEADERS = kprocctrl.h kprocess.h device.h manager.h remotedevice.h services.h | 3 | HEADERS = device.h manager.h remotedevice.h services.h |
4 | SOURCES = kprocctrl.cpp kprocess.cpp device.cc manager.cc remotedevice.cc services.cc | 4 | SOURCES = device.cc manager.cc remotedevice.cc services.cc |
5 | TARGET = opietooth | 5 | TARGET = opietooth |
6 | INCLUDEPATH += $(OPIEDIR)/include | 6 | INCLUDEPATH += $(OPIEDIR)/include |
7 | DESTDIR = $(QTDIR)/lib$(PROJMAK) | 7 | DESTDIR = $(QTDIR)/lib$(PROJMAK) |
8 | LIBS = -lopie | ||
8 | #VERSION = 0.0.0 | 9 | #VERSION = 0.0.0 |
diff --git a/noncore/net/opietooth/lib/manager.cc b/noncore/net/opietooth/lib/manager.cc index 882af81..eeeab19 100644 --- a/noncore/net/opietooth/lib/manager.cc +++ b/noncore/net/opietooth/lib/manager.cc | |||
@@ -1,69 +1,134 @@ | |||
1 | #include <opie/oprocess.h> | ||
1 | 2 | ||
2 | #include "manager.h" | 3 | #include "manager.h" |
3 | 4 | ||
4 | 5 | ||
5 | using namespace OpieTooth; | 6 | using namespace OpieTooth; |
6 | 7 | ||
7 | Manager::Manager( const QString& ) | 8 | Manager::Manager( const QString& dev ) |
8 | : QObject() | 9 | : QObject() |
9 | { | 10 | { |
10 | 11 | m_device = dev; | |
12 | m_hcitool = 0; | ||
13 | m_sdp = 0; | ||
11 | } | 14 | } |
12 | Manager::Manager( Device* dev ) | 15 | Manager::Manager( Device* dev ) |
13 | : QObject() | 16 | : QObject() |
14 | { | 17 | { |
15 | 18 | m_hcitool = 0; | |
19 | m_sdp = 0; | ||
16 | } | 20 | } |
17 | Manager::Manager() | 21 | Manager::Manager() |
18 | : QObject() | 22 | : QObject() |
19 | { | 23 | { |
20 | 24 | m_hcitool = 0; | |
25 | m_sdp = 0; | ||
21 | } | 26 | } |
22 | Manager::~Manager(){ | 27 | Manager::~Manager(){ |
23 | 28 | delete m_hcitool; | |
29 | delete m_sdp; | ||
24 | } | 30 | } |
25 | void Manager::setDevice( const QString& dev ){ | 31 | void Manager::setDevice( const QString& dev ){ |
26 | 32 | m_device = dev; | |
27 | } | 33 | } |
28 | void Manager::setDevice( Device* dev ){ | 34 | void Manager::setDevice( Device* dev ){ |
29 | 35 | ||
30 | } | 36 | } |
31 | void Manager::isConnected( const QString& device ){ | 37 | void Manager::isConnected( const QString& device ){ |
38 | OProcess* l2ping = new OProcess(); | ||
39 | l2ping->setName( device.latin1() ); | ||
40 | *l2ping << "l2ping" << "-c1" << device; | ||
41 | connect(l2ping, SIGNAL(processExited(OProcess* ) ), | ||
42 | this, SLOT(slotProcessExited(OProcess*) ) ); | ||
43 | if (!l2ping->start() ) { | ||
44 | emit connected( device, false ); | ||
45 | delete l2ping; | ||
46 | } | ||
32 | 47 | ||
33 | } | 48 | } |
34 | void Manager::isConnected( Device* dev ){ | 49 | void Manager::isConnected( Device* dev ){ |
35 | 50 | ||
36 | 51 | ||
37 | } | 52 | } |
38 | void Manager::searchDevices( const QString& device ){ | 53 | void Manager::searchDevices( const QString& device ){ |
39 | 54 | ||
40 | } | 55 | } |
41 | 56 | ||
42 | void Manager::searchDevices(Device* d ){ | 57 | void Manager::searchDevices(Device* d ){ |
43 | 58 | ||
44 | 59 | ||
45 | } | 60 | } |
46 | void Manager::addService(const QString& name ){ | 61 | void Manager::addService(const QString& name ){ |
47 | 62 | OProcess proc; | |
48 | } | 63 | proc << "sdptool" << "add" << name; |
49 | void Manager::addServices(const QStringList& ){ | 64 | bool bo = true; |
50 | 65 | if (!proc.start(OProcess::DontCare ) ) | |
66 | bo = false; | ||
67 | emit addedService( name, bo ); | ||
68 | } | ||
69 | void Manager::addServices(const QStringList& list){ | ||
70 | QStringList::ConstIterator it; | ||
71 | for (it = list.begin(); it != list.end(); ++it ) | ||
72 | addService( (*it) ); | ||
51 | } | 73 | } |
52 | void Manager::removeService( const QString& name ){ | 74 | void Manager::removeService( const QString& name ){ |
53 | 75 | OProcess prc; | |
54 | } | 76 | prc << "sdptool" << "del" << name; |
55 | void Manager::removeServices( const QStringList& ){ | 77 | bool bo = true; |
56 | 78 | if (!prc.start(OProcess::DontCare ) ) | |
79 | bo = false; | ||
80 | emit removedService( name, bo ); | ||
81 | } | ||
82 | void Manager::removeServices( const QStringList& list){ | ||
83 | QStringList::ConstIterator it; | ||
84 | for (it = list.begin(); it != list.end(); ++it ) | ||
85 | removeService( (*it) ); | ||
57 | } | 86 | } |
58 | void Manager::searchServices( const QString& remDevice ){ | 87 | void Manager::searchServices( const QString& remDevice ){ |
88 | OProcess *m_sdp =new OProcess(); | ||
89 | *m_sdp << "sdptool" << "browse" << remDevice; | ||
90 | m_sdp->setName( remDevice.latin1() ); | ||
91 | connect(m_sdp, SIGNAL(processExited(OProcess*) ), | ||
92 | this, SLOT(slotSDPExited(OProcess* ) ) ); | ||
93 | connect(m_sdp, SIGNAL(receivedStdout(OProcess*, char*, int ) ), | ||
94 | this, SLOT(slotSDPOut(OProcess*, char*, int) ) ); | ||
95 | if (!m_sdp->start() ) { | ||
96 | delete m_sdp; | ||
97 | Services::ValueList list; | ||
98 | emit foundServices( remDevice, list ); | ||
99 | } | ||
100 | } | ||
101 | void Manager::searchServices( const RemoteDevices& dev){ | ||
102 | searchServices( dev.mac() ); | ||
103 | } | ||
104 | QString Manager::toDevice( const QString& mac ){ | ||
59 | 105 | ||
60 | } | 106 | } |
61 | void Manager::searchServices( const RemoteDevices& ){ | 107 | QString Manager::toMac( const QString &device ){ |
62 | 108 | ||
63 | } | 109 | } |
64 | QString Manager::toDevice( const QString& mac ){ | 110 | void Manager::slotProcessExited(OProcess* proc ) { |
111 | bool conn= false; | ||
112 | if (proc->normalExit() && proc->exitStatus() == 0 ) | ||
113 | conn = true; | ||
65 | 114 | ||
115 | QString name = QString::fromLatin1(proc->name() ); | ||
116 | emit connected( name, conn ); | ||
117 | delete proc; | ||
66 | } | 118 | } |
67 | QString Manager::toMac( const QString &device ){ | 119 | void Manager::slotSDPOut(OProcess* proc, char* ch, int len) |
120 | { | ||
121 | QCString str(ch, len+1 ); | ||
122 | QMap<QString, QString>::Iterator it; | ||
123 | it = m_out.find(proc->name() ); | ||
124 | if ( it != m_out.end() ) { | ||
125 | QString string = it.data(); | ||
126 | string.append( str ); | ||
127 | m_out.replace( proc->name(), string ); | ||
128 | } | ||
68 | 129 | ||
69 | } | 130 | } |
131 | void Manager::slotSDPExited( OProcess* proc) | ||
132 | { | ||
133 | delete proc; | ||
134 | } | ||
diff --git a/noncore/net/opietooth/lib/manager.h b/noncore/net/opietooth/lib/manager.h index 6c5e27f..03375c5 100644 --- a/noncore/net/opietooth/lib/manager.h +++ b/noncore/net/opietooth/lib/manager.h | |||
@@ -1,113 +1,126 @@ | |||
1 | 1 | ||
2 | #ifndef OpieToothManager_H | 2 | #ifndef OpieToothManager_H |
3 | #define OpieToothManager_H | 3 | #define OpieToothManager_H |
4 | 4 | ||
5 | #include <qobject.h> | 5 | #include <qobject.h> |
6 | #include <qstring.h> | 6 | #include <qstring.h> |
7 | #include <qmap.h> | ||
7 | #include <qvaluelist.h> | 8 | #include <qvaluelist.h> |
8 | 9 | ||
9 | #include "remotedevice.h" | 10 | #include "remotedevice.h" |
10 | #include "services.h" | 11 | #include "services.h" |
11 | 12 | ||
13 | class OProcess; | ||
12 | namespace OpieTooth { | 14 | namespace OpieTooth { |
13 | class Device; | 15 | class Device; |
14 | /** Manager manages a blueZ device (hci0 for example) | 16 | /** Manager manages a blueZ device (hci0 for example) |
15 | * with Manager you can control the things you | 17 | * with Manager you can control the things you |
16 | * could do from command line in a OO and asynchronus | 18 | * could do from command line in a OO and asynchronus |
17 | * way. | 19 | * way. |
18 | */ | 20 | */ |
19 | class Manager : public QObject { | 21 | class Manager : public QObject { |
20 | Q_OBJECT | 22 | Q_OBJECT |
21 | public: | 23 | public: |
22 | /** c'tor whichs create a new Manager | 24 | /** c'tor whichs create a new Manager |
23 | * @param device is the device to use. Either a mac or blueZ device name | 25 | * @param device is the device to use. Either a mac or blueZ device name |
24 | * | 26 | * |
25 | */ | 27 | */ |
26 | Manager( const QString &device ); | 28 | Manager( const QString &device ); |
27 | /** c'tor | 29 | /** c'tor |
28 | * @param dev The Device to be managed | 30 | * @param dev The Device to be managed |
29 | * We don't care of Device so you need to delete it | 31 | * We don't care of Device so you need to delete it |
30 | */ | 32 | */ |
31 | Manager( Device* dev ); | 33 | Manager( Device* dev ); |
32 | /** | 34 | /** |
33 | * c'tor | 35 | * c'tor |
34 | */ | 36 | */ |
35 | Manager(); | 37 | Manager(); |
36 | ~Manager(); | 38 | ~Manager(); |
37 | 39 | ||
38 | /** Set the manager to control a new device | 40 | /** Set the manager to control a new device |
39 | * @param device the new device to control (hci0 ) | 41 | * @param device the new device to control (hci0 ) |
40 | */ | 42 | */ |
41 | void setDevice( const QString& device ); | 43 | void setDevice( const QString& device ); |
42 | /** | 44 | /** |
43 | * Convience functions for setting a new device | 45 | * Convience functions for setting a new device |
44 | */ | 46 | */ |
45 | void setDevice( Device *dev ); | 47 | void setDevice( Device *dev ); |
46 | /** | 48 | /** |
47 | * Wether or not a device is connected. The function | 49 | * Wether or not a device is connected. The function |
48 | * is asynchron | 50 | * is asynchron |
49 | * If device is empty it will take the currently managed | 51 | * If device is empty it will take the currently managed |
50 | * device and see if it's up | 52 | * device and see if it's up |
51 | * for Remote devices it will ping and see | 53 | * for Remote devices it will ping and see. |
54 | * @param either mac or hciX | ||
52 | */ | 55 | */ |
53 | void isConnected(const QString& device= QString::null ); | 56 | void isConnected(const QString& device= QString::null ); |
54 | /** | 57 | /** |
55 | * same as above | 58 | * same as above |
56 | */ | 59 | */ |
57 | void isConnected(Device *dev ); | 60 | void isConnected(Device *dev ); |
58 | 61 | ||
59 | /** this search for devices reachable from the | 62 | /** this searchs for devices reachable from the |
60 | * currently managed device | 63 | * currently managed device |
61 | * or from device if @param device is not empty | 64 | * or from device if @param device is not empty |
62 | */ | 65 | */ |
63 | void searchDevices(const QString& device= QString::null ); | 66 | void searchDevices(const QString& device= QString::null ); |
64 | /** same as above | 67 | /** same as above |
65 | * | 68 | * |
66 | */ | 69 | */ |
67 | void searchDevices(Device *d ); | 70 | void searchDevices(Device *d ); |
68 | 71 | ||
69 | /** | 72 | /** |
70 | * This will add the service @param name | 73 | * This will add the service @param name |
71 | * to the sdpd daemon | 74 | * to the sdpd daemon |
72 | * It will start the daemon if necessary | 75 | * It will start the daemon if necessary |
73 | */ | 76 | */ |
74 | void addService(const QString &name ); | 77 | void addService(const QString &name ); |
75 | /** | 78 | /** |
76 | * This will add the services @param names | 79 | * This will add the services @param names |
77 | * to the sdpd daemon | 80 | * to the sdpd daemon |
78 | * It will start the daemon if necessary | 81 | * It will start the daemon if necessary |
79 | */ | 82 | */ |
80 | void addServices( const QStringList& names ); | 83 | void addServices( const QStringList& names ); |
81 | /** | 84 | /** |
82 | * This removes a service from the sdps | 85 | * This removes a service from the sdps |
83 | */ | 86 | */ |
84 | void removeService(const QString &name ); | 87 | void removeService(const QString &name ); |
85 | /** | 88 | /** |
86 | * Removes a list from the sdpd | 89 | * Removes a list from the sdpd |
87 | */ | 90 | */ |
88 | void removeServices(const QStringList& ); | 91 | void removeServices(const QStringList& ); |
89 | 92 | ||
90 | /** | 93 | /** |
91 | * search for services on a remote device | 94 | * search for services on a remote device |
92 | * | 95 | * |
93 | */ | 96 | */ |
94 | void searchServices( const QString& remDevice ); | 97 | void searchServices( const QString& remDevice ); |
95 | /** | 98 | /** |
96 | * search for services on a remote device | 99 | * search for services on a remote device |
97 | */ | 100 | */ |
98 | void searchServices( const RemoteDevices& ); | 101 | void searchServices( const RemoteDevices& ); |
99 | /*static*/ QString toDevice( const QString& mac ); | 102 | /*static*/ QString toDevice( const QString& mac ); |
100 | /*static*/ QString toMac( const QString &device ); | 103 | /*static*/ QString toMac( const QString &device ); |
101 | 104 | ||
102 | signals: | 105 | signals: |
103 | // device either mac or dev name | 106 | // device either mac or dev name |
104 | // the first device is the device which you access | 107 | // the first device is the device which you access |
105 | void connected( const QString& device, bool connected ); | 108 | void connected( const QString& device, bool connected ); |
106 | void addedService( const QString& device, const QString& service, bool added ); | 109 | void addedService( const QString& service, bool added ); |
107 | void removedService( const QString& device, const QString& service, bool removed ); | 110 | void removedService( const QString& service, bool removed ); |
108 | void foundServices( const QString& device, Services::ValueList ); | 111 | void foundServices( const QString& device, Services::ValueList ); |
109 | void foundDevices( const QString& device, RemoteDevices::ValueList ); | 112 | void foundDevices( const QString& device, RemoteDevices::ValueList ); |
113 | void foundNothing( const QString& device ); | ||
114 | private slots: | ||
115 | void slotProcessExited(OProcess* ); | ||
116 | void slotSDPExited(OProcess*); | ||
117 | void slotSDPOut(OProcess*, char*, int); | ||
118 | private: | ||
119 | OProcess *m_hcitool; | ||
120 | OProcess *m_sdp; // not only one | ||
121 | QString m_device; | ||
122 | QMap<QString, QString> m_out; | ||
110 | }; | 123 | }; |
111 | }; | 124 | }; |
112 | 125 | ||
113 | #endif | 126 | #endif |