summaryrefslogtreecommitdiff
authorzecke <zecke>2002-06-03 20:14:29 (UTC)
committer zecke <zecke>2002-06-03 20:14:29 (UTC)
commit7080f9f10443d7a8e61d01b5a1c0e9c972f6baca (patch) (unidiff)
tree36f8b2ab579028bba027c0432da2ae41f09b9b4d
parent8d5f42d770abca69d490774f4b1fc8284e7a86be (diff)
downloadopie-7080f9f10443d7a8e61d01b5a1c0e9c972f6baca.zip
opie-7080f9f10443d7a8e61d01b5a1c0e9c972f6baca.tar.gz
opie-7080f9f10443d7a8e61d01b5a1c0e9c972f6baca.tar.bz2
attaching and detaching is now working
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/opietooth/lib/device.cc54
-rw-r--r--noncore/net/opietooth/lib/device.h1
-rw-r--r--noncore/net/opietooth/lib/lib.pro4
-rw-r--r--noncore/net/opietooth/lib/manager.h3
-rw-r--r--noncore/net/opietooth/lib/remotedevice.cc48
-rw-r--r--noncore/net/opietooth/lib/remotedevice.h6
-rw-r--r--noncore/net/opietooth/lib/services.cc168
-rw-r--r--noncore/net/opietooth/lib/services.h18
8 files changed, 286 insertions, 16 deletions
diff --git a/noncore/net/opietooth/lib/device.cc b/noncore/net/opietooth/lib/device.cc
index 468f191..e3d7f3b 100644
--- a/noncore/net/opietooth/lib/device.cc
+++ b/noncore/net/opietooth/lib/device.cc
@@ -7,8 +7,24 @@
7 7
8using namespace OpieTooth; 8using namespace OpieTooth;
9 9
10namespace {
11 int parsePid( const QCString& par ){
12 int id=0;
13 QString string( par );
14 QStringList list = QStringList::split( '\n', string );
15 for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ){
16 if( !(*it).startsWith("CSR") ){
17 id = (*it).toInt();
18 break;
19 }
20 }
21 return id;
22 }
23}
24
10Device::Device(const QString &device, const QString &mode ) 25Device::Device(const QString &device, const QString &mode )
11 : QObject(0, "device" ) { 26 : QObject(0, "device" ) {
27 qWarning("OpieTooth::Device create" );
12 m_hci = 0; 28 m_hci = 0;
13 m_process = 0; 29 m_process = 0;
14 m_attached = false; 30 m_attached = false;
@@ -20,7 +36,10 @@ Device::~Device(){
20 detach(); 36 detach();
21} 37}
22void Device::attach(){ 38void Device::attach(){
23 if(m_process != 0 ){ 39 qWarning("attaching %s %s", m_device.latin1(), m_mode.latin1() );
40 if(m_process == 0 ){
41 m_output.resize(0);
42 qWarning("new process to create" );
24 m_process = new KProcess(); 43 m_process = new KProcess();
25 *m_process << "hciattach"; 44 *m_process << "hciattach";
26 *m_process << "-p"; 45 *m_process << "-p";
@@ -32,6 +51,7 @@ void Device::attach(){
32 connect(m_process, SIGNAL(receivedStderr(KProcess*, char*, int ) ), 51 connect(m_process, SIGNAL(receivedStderr(KProcess*, char*, int ) ),
33 this, SLOT(slotStdErr(KProcess*,char*,int) ) ); 52 this, SLOT(slotStdErr(KProcess*,char*,int) ) );
34 if(!m_process->start(KProcess::NotifyOnExit, KProcess::AllOutput ) ){ 53 if(!m_process->start(KProcess::NotifyOnExit, KProcess::AllOutput ) ){
54 qWarning("Could not start" );
35 delete m_process; 55 delete m_process;
36 m_process = 0; 56 m_process = 0;
37 } 57 }
@@ -41,10 +61,13 @@ void Device::detach(){
41 delete m_hci; 61 delete m_hci;
42 delete m_process; 62 delete m_process;
43 // kill the pid we got 63 // kill the pid we got
44 if(m_attached ) 64 if(m_attached ){
45 //kill the pid 65 //kill the pid
66 qWarning( "killing" );
46 kill(pid, 9); 67 kill(pid, 9);
47} 68}
69 qWarning("detached" );
70}
48bool Device::isLoaded()const{ 71bool Device::isLoaded()const{
49 return m_attached; 72 return m_attached;
50} 73}
@@ -53,10 +76,15 @@ QString Device::devName()const {
53}; 76};
54void Device::slotExited( KProcess* proc) 77void Device::slotExited( KProcess* proc)
55{ 78{
79 qWarning("prcess exited" );
56 if(proc== m_process ){ 80 if(proc== m_process ){
57 if( m_process->normalExit() ){ // normal exit 81 if( m_process->normalExit() ){ // normal exit
58 int ret = m_process->exitStatus(); 82 int ret = m_process->exitStatus();
59 if( ret == 0 ){ // attached 83 if( ret == 0 ){ // attached
84 qWarning("attached" );
85 qWarning("Output: %s", m_output.data() );
86 pid = parsePid( m_output );
87 qWarning("Pid = %d", pid );
60 // now hciconfig hci0 up ( determine hciX FIXME) 88 // now hciconfig hci0 up ( determine hciX FIXME)
61 // and call hciconfig hci0 up 89 // and call hciconfig hci0 up
62 // FIXME hardcoded to hci0 now :( 90 // FIXME hardcoded to hci0 now :(
@@ -65,6 +93,11 @@ void Device::slotExited( KProcess* proc)
65 *m_hci << "hci0 up"; 93 *m_hci << "hci0 up";
66 connect(m_hci, SIGNAL( processExited(KProcess*) ), 94 connect(m_hci, SIGNAL( processExited(KProcess*) ),
67 this, SLOT( slotExited(KProcess* ) ) ); 95 this, SLOT( slotExited(KProcess* ) ) );
96 if(!m_hci->start() ){
97 qWarning("could not start" );
98 m_attached = false;
99 emit device("hci0", false );
100 }
68 }else{ 101 }else{
69 m_attached = false; 102 m_attached = false;
70 emit device("hci0", false ); 103 emit device("hci0", false );
@@ -74,11 +107,16 @@ void Device::slotExited( KProcess* proc)
74 delete m_process; 107 delete m_process;
75 m_process = 0; 108 m_process = 0;
76 }else if(proc== m_hci ){ 109 }else if(proc== m_hci ){
110 qWarning("M HCI exited" );
77 if( m_hci->normalExit() ){ 111 if( m_hci->normalExit() ){
78 int ret = m_hci->normalExit(); 112 qWarning("normal exit" );
113 int ret = m_hci->exitStatus();
79 if( ret == 0 ){ 114 if( ret == 0 ){
115 qWarning("attached really really attached" );
116 m_attached = true;
80 emit device("hci0", true ); 117 emit device("hci0", true );
81 }else{ 118 }else{
119 qWarning( "failed" );
82 emit device("hci0", false ); 120 emit device("hci0", false );
83 m_attached = false; 121 m_attached = false;
84 } 122 }
@@ -89,16 +127,16 @@ void Device::slotExited( KProcess* proc)
89} 127}
90void Device::slotStdOut(KProcess* proc, char* chars, int len) 128void Device::slotStdOut(KProcess* proc, char* chars, int len)
91{ 129{
130 qWarning("std out" );
92 if( len <1 ) 131 if( len <1 )
93 return; 132 return;
94 if(proc == m_process ){ 133 if(proc == m_process ){
95 QCString string( chars, len+1 ); 134 QCString string( chars, len+1 ); // \0 == +1
96 if(string.left(3) != "CSR" ){ // it's the pid 135 qWarning("output: %s", string.data() );
97 pid = string.toInt(); 136 m_output.append( string.data() );
98 };
99 } 137 }
100} 138}
101void Device::slotStdErr(KProcess*, char*, int ) 139void Device::slotStdErr(KProcess*, char*, int )
102{ 140{
103 141 qWarning("std err" );
104} 142}
diff --git a/noncore/net/opietooth/lib/device.h b/noncore/net/opietooth/lib/device.h
index 010db40..8498b14 100644
--- a/noncore/net/opietooth/lib/device.h
+++ b/noncore/net/opietooth/lib/device.h
@@ -78,6 +78,7 @@ namespace OpieTooth {
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 }; 82 };
82}; 83};
83 84
diff --git a/noncore/net/opietooth/lib/lib.pro b/noncore/net/opietooth/lib/lib.pro
index 7cededf..a70c7ab 100644
--- a/noncore/net/opietooth/lib/lib.pro
+++ b/noncore/net/opietooth/lib/lib.pro
@@ -1,7 +1,7 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qte warn_on release 2CONFIG += qte warn_on release
3 HEADERS = kprocctrl.h kprocess.h device.h 3 HEADERS = kprocctrl.h kprocess.h device.h manager.h remotedevice.h services.h
4 SOURCES = kprocctrl.cpp kprocess.cpp device.cc 4 SOURCES = kprocctrl.cpp kprocess.cpp device.cc manager.cc remotedevice.cc services.cc
5 TARGET = opietooth 5 TARGET = opietooth
6INCLUDEPATH += $(OPIEDIR)/include 6INCLUDEPATH += $(OPIEDIR)/include
7DESTDIR = $(QTDIR)/lib$(PROJMAK) 7DESTDIR = $(QTDIR)/lib$(PROJMAK)
diff --git a/noncore/net/opietooth/lib/manager.h b/noncore/net/opietooth/lib/manager.h
index 5586680..6c5e27f 100644
--- a/noncore/net/opietooth/lib/manager.h
+++ b/noncore/net/opietooth/lib/manager.h
@@ -6,6 +6,9 @@
6#include <qstring.h> 6#include <qstring.h>
7#include <qvaluelist.h> 7#include <qvaluelist.h>
8 8
9#include "remotedevice.h"
10#include "services.h"
11
9namespace OpieTooth { 12namespace OpieTooth {
10 class Device; 13 class Device;
11 /** Manager manages a blueZ device (hci0 for example) 14 /** Manager manages a blueZ device (hci0 for example)
diff --git a/noncore/net/opietooth/lib/remotedevice.cc b/noncore/net/opietooth/lib/remotedevice.cc
new file mode 100644
index 0000000..0045904
--- a/dev/null
+++ b/noncore/net/opietooth/lib/remotedevice.cc
@@ -0,0 +1,48 @@
1
2#include "remotedevice.h"
3
4using namespace OpieTooth;
5
6bool operator==(const RemoteDevices& rem1, const RemoteDevices& rem2){
7 if( ( rem1.mac() == rem2.mac() ) && (rem1.name() == rem2.name() ) )
8 return true;
9
10 return false;
11}
12
13RemoteDevices::RemoteDevices(){
14
15}
16RemoteDevices::RemoteDevices(const RemoteDevices& ole ){
17 (*this) = ole;
18}
19RemoteDevices::RemoteDevices(const QString &mac, const QString& name ){
20 m_mac = mac;
21 m_name = name;
22}
23RemoteDevices::~RemoteDevices(){
24
25}
26bool RemoteDevices::isEmpty() const {
27 if( m_name.isEmpty() && m_mac.isEmpty() )
28 return true;
29 return false;
30};
31RemoteDevices& RemoteDevices::operator=( const RemoteDevices& rem1){
32 m_name = rem1.m_name;
33 m_mac = rem1.m_mac;
34 return *this;
35
36}
37QString RemoteDevices::mac() const {
38 return m_mac;
39}
40void RemoteDevices::setMac( const QString& mac ){
41 m_mac = mac;
42}
43QString RemoteDevices::name() const{
44 return m_name;
45}
46void RemoteDevices::setName( const QString& name ){
47 m_name = name;
48}
diff --git a/noncore/net/opietooth/lib/remotedevice.h b/noncore/net/opietooth/lib/remotedevice.h
index 8e5baa5..96a27de 100644
--- a/noncore/net/opietooth/lib/remotedevice.h
+++ b/noncore/net/opietooth/lib/remotedevice.h
@@ -13,11 +13,15 @@ namespace OpieTooth{
13 RemoteDevices(const QString &mac, const QString &name ); 13 RemoteDevices(const QString &mac, const QString &name );
14 ~RemoteDevices(); 14 ~RemoteDevices();
15 friend bool operator==(const RemoteDevices&, const RemoteDevices&); 15 friend bool operator==(const RemoteDevices&, const RemoteDevices&);
16 RemoteDevies &operator=(const RemoteDevices& ); 16 RemoteDevices &operator=(const RemoteDevices& );
17 bool isEmpty()const;
17 QString mac()const; 18 QString mac()const;
18 void setMac(const QString& mac ); 19 void setMac(const QString& mac );
19 QString name()const; 20 QString name()const;
20 void setName( const QString& name ); 21 void setName( const QString& name );
22 private:
23 QString m_name;
24 QString m_mac;
21 }; 25 };
22}; 26};
23 27
diff --git a/noncore/net/opietooth/lib/services.cc b/noncore/net/opietooth/lib/services.cc
new file mode 100644
index 0000000..75c1bd6
--- a/dev/null
+++ b/noncore/net/opietooth/lib/services.cc
@@ -0,0 +1,168 @@
1
2#include "services.h"
3
4using namespace OpieTooth;
5
6
7Services::ProfileDescriptor::ProfileDescriptor(){
8
9}
10Services::ProfileDescriptor::ProfileDescriptor(const QString &id, uint idInt, uint version ){
11 m_id = id;
12 m_idInt = idInt;
13 m_version = version;
14}
15Services::ProfileDescriptor::ProfileDescriptor( const ProfileDescriptor& rem){
16 (*this) = rem;
17}
18QString Services::ProfileDescriptor::id() const {
19 return m_id;
20}
21void Services::ProfileDescriptor::setId( const QString& id ){
22 m_id = id;
23}
24void Services::ProfileDescriptor::setId(uint id ){
25 m_idInt = id;
26}
27uint Services::ProfileDescriptor::idInt()const{
28 return m_idInt;
29}
30uint Services::ProfileDescriptor::version() const{
31 return m_version;
32}
33void Services::ProfileDescriptor::setVersion(uint version){
34 m_version = version;
35}
36Services::ProfileDescriptor& Services::ProfileDescriptor::operator=( const Services::ProfileDescriptor& prof){
37 m_id = prof.m_id;
38 m_idInt = prof.m_idInt;
39 m_version = prof.m_version;
40 return *this;
41}
42bool operator==(const Services::ProfileDescriptor& first,
43 const Services::ProfileDescriptor& second ){
44
45 if( (first.id() == second.id() ) &&
46 (first.version() == second.version() ) &&
47 (first.idInt() == second.idInt() ) )
48 return true;
49 return false;
50}
51
52Services::ProtocolDescriptor::ProtocolDescriptor(){
53 m_number = 0;
54 m_channel = 0;
55}
56Services::ProtocolDescriptor::ProtocolDescriptor(const QString& name,
57 uint number,
58 uint channel){
59 m_name = name;
60 m_number = number;
61 m_channel = channel;
62}
63Services::ProtocolDescriptor::ProtocolDescriptor( const ProtocolDescriptor& ole ){
64 (*this) = ole;
65}
66Services::ProtocolDescriptor::~ProtocolDescriptor(){
67
68}
69QString Services::ProtocolDescriptor::name() const{
70 return m_name;
71}
72void Services::ProtocolDescriptor::setName(const QString& name ){
73 m_name = name;
74}
75uint Services::ProtocolDescriptor::id()const {
76 return m_number;
77}
78void Services::ProtocolDescriptor::setId( uint id ){
79 m_number = id;
80}
81uint Services::ProtocolDescriptor::port()const {
82 return m_channel;
83}
84void Services::ProtocolDescriptor::setPort( uint port ){
85 m_channel = port;
86}
87Services::ProtocolDescriptor &Services::ProtocolDescriptor::operator=( const Services::ProtocolDescriptor& desc ){
88 m_name = desc.m_name;
89 m_channel = desc.m_channel;
90 m_number = desc.m_number;
91 return *this;
92}
93bool operator==( const Services::ProtocolDescriptor &first,
94 const Services::ProtocolDescriptor &second ){
95 if( ( first.name() == second.name() ) &&
96 ( first.id() == second.id() ) &&
97 ( first.port() == second.port() ) )
98 return true;
99
100 return false;
101
102}
103
104Services::Services(){
105
106}
107Services::Services(const Services& service ){
108
109}
110Services::~Services(){
111
112}
113Services &Services::operator=( const Services& ){
114 return *this;
115}
116bool operator==( const Services&,
117 const Services& ){
118 return false;
119}
120QString Services::serviceName() const{
121
122}
123void Services::setServiceName( const QString& service ){
124
125}
126int Services::recHandle() const{
127
128}
129void Services::setRecHandle( int ){
130
131}
132QString Services::classIdList() const{
133
134}
135void Services::setClassIdList( const QString& ){
136
137}
138int Services::classIdListInt() const{
139
140}
141void Services::setClassIdList(int ){
142
143}
144void Services::insertProtocolDescriptor( const ProtocolDescriptor& ){
145
146}
147void Services::clearProtocolDescriptorList(){
148
149}
150void Services::removeProtocolDescriptor( const ProtocolDescriptor& ){
151
152}
153Services::ProtocolDescriptor::ValueList Services::protocolDescriptorList()const{
154
155}
156
157void Services::insertProfileDescriptor( const ProfileDescriptor& ){
158
159}
160void Services::clearProfileDescriptorList(){
161
162}
163void Services::removeProfileDescriptor( const ProfileDescriptor& ){
164
165}
166Services::ProfileDescriptor::ValueList Services::profileDescriptor() const{
167
168}
diff --git a/noncore/net/opietooth/lib/services.h b/noncore/net/opietooth/lib/services.h
index 4a4dea8..8e9378a 100644
--- a/noncore/net/opietooth/lib/services.h
+++ b/noncore/net/opietooth/lib/services.h
@@ -14,7 +14,7 @@ namespace OpieTooth {
14 /** The profile descriptor 14 /** The profile descriptor
15 * 15 *
16 */ 16 */
17 class ProfileDesriptor{ 17 class ProfileDescriptor{
18 public: 18 public:
19 /** typedef */ 19 /** typedef */
20 typedef QValueList<ProfileDescriptor> ValueList; 20 typedef QValueList<ProfileDescriptor> ValueList;
@@ -59,11 +59,15 @@ namespace OpieTooth {
59 /** 59 /**
60 * copy operator 60 * copy operator
61 */ 61 */
62 ProfileDescriptor &operator=( const ProfileDescriptor ); 62 ProfileDescriptor &operator=( const ProfileDescriptor& );
63 /** 63 /**
64 * operator== 64 * operator==
65 */ 65 */
66 friend bool operator==(const ProfileDescriptor&, const ProfileDescriptor& ); 66 friend bool operator==(const ProfileDescriptor&, const ProfileDescriptor& );
67 private:
68 QString m_id;
69 uint m_idInt;
70 uint m_version;
67 }; 71 };
68 /** 72 /**
69 * Protocol Descriptor 73 * Protocol Descriptor
@@ -81,7 +85,7 @@ namespace OpieTooth {
81 * channel/port 85 * channel/port
82 */ 86 */
83 ProtocolDescriptor(const QString&, uint, uint channel ); // Q_UINT8 ? 87 ProtocolDescriptor(const QString&, uint, uint channel ); // Q_UINT8 ?
84 ProtocolDescriptot(const ProtocolDescriptor& ); 88 ProtocolDescriptor(const ProtocolDescriptor& );
85 ~ProtocolDescriptor(); 89 ~ProtocolDescriptor();
86 QString name()const; 90 QString name()const;
87 void setName(const QString& ); 91 void setName(const QString& );
@@ -90,8 +94,12 @@ namespace OpieTooth {
90 uint port()const; 94 uint port()const;
91 void setPort(uint ); 95 void setPort(uint );
92 ProtocolDescriptor &operator=( const ProtocolDescriptor& ); 96 ProtocolDescriptor &operator=( const ProtocolDescriptor& );
93 friend bool operator==( const ProtocolDescription&, 97 friend bool operator==( const ProtocolDescriptor&,
94 const ProtocolDescription& ); 98 const ProtocolDescriptor& );
99 private:
100 QString m_name;
101 uint m_number;
102 uint m_channel;
95 }; 103 };
96 104
97 public: 105 public: