summaryrefslogtreecommitdiff
path: root/noncore/net
authorzecke <zecke>2002-06-15 20:06:04 (UTC)
committer zecke <zecke>2002-06-15 20:06:04 (UTC)
commitb15f8a613d83a2f3957fef515e20981f636b908b (patch) (unidiff)
tree6d2e6743ceb4c3cb299944efc4b2925e5f40412d /noncore/net
parentef75752efaef84e4b7350f9768f3cb3c4fd744af (diff)
downloadopie-b15f8a613d83a2f3957fef515e20981f636b908b.zip
opie-b15f8a613d83a2f3957fef515e20981f636b908b.tar.gz
opie-b15f8a613d83a2f3957fef515e20981f636b908b.tar.bz2
isCOnnected, add and remove Service + first bits of service browsing done
Diffstat (limited to 'noncore/net') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opietooth/lib/device.cc30
-rw-r--r--noncore/net/opietooth/lib/device.h12
-rw-r--r--noncore/net/opietooth/lib/lib.pro5
-rw-r--r--noncore/net/opietooth/lib/manager.cc99
-rw-r--r--noncore/net/opietooth/lib/manager.h29
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
@@ -3,3 +3,3 @@
3 3
4#include "kprocess.h" 4#include <opie/oprocess.h>
5 5
@@ -42,3 +42,3 @@ void Device::attach(){
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";
@@ -46,9 +46,9 @@ void Device::attach(){
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" );
@@ -76,3 +76,3 @@ QString Device::devName()const {
76}; 76};
77void Device::slotExited( KProcess* proc) 77void Device::slotExited( OProcess* proc)
78{ 78{
@@ -90,7 +90,7 @@ void Device::slotExited( KProcess* proc)
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() ){
@@ -127,3 +127,3 @@ void Device::slotExited( KProcess* proc)
127} 127}
128void Device::slotStdOut(KProcess* proc, char* chars, int len) 128void Device::slotStdOut(OProcess* proc, char* chars, int len)
129{ 129{
@@ -138,3 +138,3 @@ void Device::slotStdOut(KProcess* proc, char* chars, int len)
138} 138}
139void Device::slotStdErr(KProcess*, char*, int ) 139void Device::slotStdErr(OProcess*, char*, int )
140{ 140{
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
@@ -10,3 +10,3 @@
10 10
11class KProcess; 11class OProcess;
12namespace OpieTooth { 12namespace OpieTooth {
@@ -67,5 +67,5 @@ namespace OpieTooth {
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:
@@ -75,4 +75,4 @@ namespace OpieTooth {
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;
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
@@ -2,4 +2,4 @@ TEMPLATE = lib
2CONFIG += qte warn_on release 2CONFIG += 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
@@ -7,2 +7,3 @@ INCLUDEPATH += $(OPIEDIR)/include
7DESTDIR = $(QTDIR)/lib$(PROJMAK) 7DESTDIR = $(QTDIR)/lib$(PROJMAK)
8LIBS = -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 +1,2 @@
1#include <opie/oprocess.h>
1 2
@@ -6,6 +7,8 @@ using namespace OpieTooth;
6 7
7Manager::Manager( const QString& ) 8Manager::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}
@@ -14,3 +17,4 @@ Manager::Manager( Device* dev )
14{ 17{
15 18 m_hcitool = 0;
19 m_sdp = 0;
16} 20}
@@ -19,9 +23,11 @@ Manager::Manager()
19{ 23{
20 24 m_hcitool = 0;
25 m_sdp = 0;
21} 26}
22Manager::~Manager(){ 27Manager::~Manager(){
23 28 delete m_hcitool;
29 delete m_sdp;
24} 30}
25void Manager::setDevice( const QString& dev ){ 31void Manager::setDevice( const QString& dev ){
26 32 m_device = dev;
27} 33}
@@ -31,2 +37,11 @@ void Manager::setDevice( Device* dev ){
31void Manager::isConnected( const QString& device ){ 37void 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
@@ -46,24 +61,74 @@ void Manager::searchDevices(Device* d ){
46void Manager::addService(const QString& name ){ 61void Manager::addService(const QString& name ){
47 62 OProcess proc;
48} 63 proc << "sdptool" << "add" << name;
49void Manager::addServices(const QStringList& ){ 64 bool bo = true;
50 65 if (!proc.start(OProcess::DontCare ) )
66 bo = false;
67 emit addedService( name, bo );
68}
69void Manager::addServices(const QStringList& list){
70 QStringList::ConstIterator it;
71 for (it = list.begin(); it != list.end(); ++it )
72 addService( (*it) );
51} 73}
52void Manager::removeService( const QString& name ){ 74void Manager::removeService( const QString& name ){
53 75 OProcess prc;
54} 76 prc << "sdptool" << "del" << name;
55void Manager::removeServices( const QStringList& ){ 77 bool bo = true;
56 78 if (!prc.start(OProcess::DontCare ) )
79 bo = false;
80 emit removedService( name, bo );
81}
82void Manager::removeServices( const QStringList& list){
83 QStringList::ConstIterator it;
84 for (it = list.begin(); it != list.end(); ++it )
85 removeService( (*it) );
57} 86}
58void Manager::searchServices( const QString& remDevice ){ 87void 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}
101void Manager::searchServices( const RemoteDevices& dev){
102 searchServices( dev.mac() );
103}
104QString Manager::toDevice( const QString& mac ){
59 105
60} 106}
61void Manager::searchServices( const RemoteDevices& ){ 107QString Manager::toMac( const QString &device ){
62 108
63} 109}
64QString Manager::toDevice( const QString& mac ){ 110void 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}
67QString Manager::toMac( const QString &device ){ 119void 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}
131void 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
@@ -6,2 +6,3 @@
6#include <qstring.h> 6#include <qstring.h>
7#include <qmap.h>
7#include <qvaluelist.h> 8#include <qvaluelist.h>
@@ -11,2 +12,3 @@
11 12
13class OProcess;
12namespace OpieTooth { 14namespace OpieTooth {
@@ -16,3 +18,3 @@ namespace OpieTooth {
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 */
@@ -29,3 +31,3 @@ Q_OBJECT
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 );
@@ -50,3 +52,4 @@ Q_OBJECT
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 */
@@ -58,4 +61,4 @@ Q_OBJECT
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
@@ -91,3 +94,3 @@ Q_OBJECT
91 * search for services on a remote device 94 * search for services on a remote device
92 * 95 *
93 */ 96 */
@@ -105,6 +108,16 @@ Q_OBJECT
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 );
114private 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 };