author | zecke <zecke> | 2002-06-03 20:14:29 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-06-03 20:14:29 (UTC) |
commit | 7080f9f10443d7a8e61d01b5a1c0e9c972f6baca (patch) (unidiff) | |
tree | 36f8b2ab579028bba027c0432da2ae41f09b9b4d /noncore | |
parent | 8d5f42d770abca69d490774f4b1fc8284e7a86be (diff) | |
download | opie-7080f9f10443d7a8e61d01b5a1c0e9c972f6baca.zip opie-7080f9f10443d7a8e61d01b5a1c0e9c972f6baca.tar.gz opie-7080f9f10443d7a8e61d01b5a1c0e9c972f6baca.tar.bz2 |
attaching and detaching is now working
-rw-r--r-- | noncore/net/opietooth/lib/device.cc | 54 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/device.h | 1 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/lib.pro | 4 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/manager.h | 3 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/remotedevice.cc | 48 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/remotedevice.h | 6 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/services.cc | 168 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/services.h | 18 |
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 | |||
@@ -8,6 +8,22 @@ | |||
8 | using namespace OpieTooth; | 8 | using namespace OpieTooth; |
9 | 9 | ||
10 | namespace { | ||
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 | |||
10 | Device::Device(const QString &device, const QString &mode ) | 25 | Device::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; |
@@ -21,5 +37,8 @@ Device::~Device(){ | |||
21 | } | 37 | } |
22 | void Device::attach(){ | 38 | void 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"; |
@@ -33,4 +52,5 @@ void Device::attach(){ | |||
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; |
@@ -42,7 +62,10 @@ void Device::detach(){ | |||
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); |
68 | } | ||
69 | qWarning("detached" ); | ||
47 | } | 70 | } |
48 | bool Device::isLoaded()const{ | 71 | bool Device::isLoaded()const{ |
@@ -54,8 +77,13 @@ QString Device::devName()const { | |||
54 | void Device::slotExited( KProcess* proc) | 77 | void 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 |
@@ -66,4 +94,9 @@ void Device::slotExited( KProcess* proc) | |||
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; |
@@ -75,9 +108,14 @@ void Device::slotExited( KProcess* proc) | |||
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; |
@@ -90,15 +128,15 @@ void Device::slotExited( KProcess* proc) | |||
90 | void Device::slotStdOut(KProcess* proc, char* chars, int len) | 128 | void 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 | } |
101 | void Device::slotStdErr(KProcess*, char*, int ) | 139 | void 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 | |||
@@ -79,4 +79,5 @@ namespace OpieTooth { | |||
79 | QString m_mode; | 79 | QString m_mode; |
80 | pid_t pid; | 80 | pid_t pid; |
81 | QCString m_output; | ||
81 | }; | 82 | }; |
82 | }; | 83 | }; |
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,6 +1,6 @@ | |||
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 | 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 |
6 | INCLUDEPATH += $(OPIEDIR)/include | 6 | INCLUDEPATH += $(OPIEDIR)/include |
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 | |||
@@ -7,4 +7,7 @@ | |||
7 | #include <qvaluelist.h> | 7 | #include <qvaluelist.h> |
8 | 8 | ||
9 | #include "remotedevice.h" | ||
10 | #include "services.h" | ||
11 | |||
9 | namespace OpieTooth { | 12 | namespace OpieTooth { |
10 | class Device; | 13 | class Device; |
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 | |||
4 | using namespace OpieTooth; | ||
5 | |||
6 | bool 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 | |||
13 | RemoteDevices::RemoteDevices(){ | ||
14 | |||
15 | } | ||
16 | RemoteDevices::RemoteDevices(const RemoteDevices& ole ){ | ||
17 | (*this) = ole; | ||
18 | } | ||
19 | RemoteDevices::RemoteDevices(const QString &mac, const QString& name ){ | ||
20 | m_mac = mac; | ||
21 | m_name = name; | ||
22 | } | ||
23 | RemoteDevices::~RemoteDevices(){ | ||
24 | |||
25 | } | ||
26 | bool RemoteDevices::isEmpty() const { | ||
27 | if( m_name.isEmpty() && m_mac.isEmpty() ) | ||
28 | return true; | ||
29 | return false; | ||
30 | }; | ||
31 | RemoteDevices& RemoteDevices::operator=( const RemoteDevices& rem1){ | ||
32 | m_name = rem1.m_name; | ||
33 | m_mac = rem1.m_mac; | ||
34 | return *this; | ||
35 | |||
36 | } | ||
37 | QString RemoteDevices::mac() const { | ||
38 | return m_mac; | ||
39 | } | ||
40 | void RemoteDevices::setMac( const QString& mac ){ | ||
41 | m_mac = mac; | ||
42 | } | ||
43 | QString RemoteDevices::name() const{ | ||
44 | return m_name; | ||
45 | } | ||
46 | void 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 | |||
@@ -14,9 +14,13 @@ namespace OpieTooth{ | |||
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 | }; |
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 | |||
4 | using namespace OpieTooth; | ||
5 | |||
6 | |||
7 | Services::ProfileDescriptor::ProfileDescriptor(){ | ||
8 | |||
9 | } | ||
10 | Services::ProfileDescriptor::ProfileDescriptor(const QString &id, uint idInt, uint version ){ | ||
11 | m_id = id; | ||
12 | m_idInt = idInt; | ||
13 | m_version = version; | ||
14 | } | ||
15 | Services::ProfileDescriptor::ProfileDescriptor( const ProfileDescriptor& rem){ | ||
16 | (*this) = rem; | ||
17 | } | ||
18 | QString Services::ProfileDescriptor::id() const { | ||
19 | return m_id; | ||
20 | } | ||
21 | void Services::ProfileDescriptor::setId( const QString& id ){ | ||
22 | m_id = id; | ||
23 | } | ||
24 | void Services::ProfileDescriptor::setId(uint id ){ | ||
25 | m_idInt = id; | ||
26 | } | ||
27 | uint Services::ProfileDescriptor::idInt()const{ | ||
28 | return m_idInt; | ||
29 | } | ||
30 | uint Services::ProfileDescriptor::version() const{ | ||
31 | return m_version; | ||
32 | } | ||
33 | void Services::ProfileDescriptor::setVersion(uint version){ | ||
34 | m_version = version; | ||
35 | } | ||
36 | Services::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 | } | ||
42 | bool 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 | |||
52 | Services::ProtocolDescriptor::ProtocolDescriptor(){ | ||
53 | m_number = 0; | ||
54 | m_channel = 0; | ||
55 | } | ||
56 | Services::ProtocolDescriptor::ProtocolDescriptor(const QString& name, | ||
57 | uint number, | ||
58 | uint channel){ | ||
59 | m_name = name; | ||
60 | m_number = number; | ||
61 | m_channel = channel; | ||
62 | } | ||
63 | Services::ProtocolDescriptor::ProtocolDescriptor( const ProtocolDescriptor& ole ){ | ||
64 | (*this) = ole; | ||
65 | } | ||
66 | Services::ProtocolDescriptor::~ProtocolDescriptor(){ | ||
67 | |||
68 | } | ||
69 | QString Services::ProtocolDescriptor::name() const{ | ||
70 | return m_name; | ||
71 | } | ||
72 | void Services::ProtocolDescriptor::setName(const QString& name ){ | ||
73 | m_name = name; | ||
74 | } | ||
75 | uint Services::ProtocolDescriptor::id()const { | ||
76 | return m_number; | ||
77 | } | ||
78 | void Services::ProtocolDescriptor::setId( uint id ){ | ||
79 | m_number = id; | ||
80 | } | ||
81 | uint Services::ProtocolDescriptor::port()const { | ||
82 | return m_channel; | ||
83 | } | ||
84 | void Services::ProtocolDescriptor::setPort( uint port ){ | ||
85 | m_channel = port; | ||
86 | } | ||
87 | Services::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 | } | ||
93 | bool 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 | |||
104 | Services::Services(){ | ||
105 | |||
106 | } | ||
107 | Services::Services(const Services& service ){ | ||
108 | |||
109 | } | ||
110 | Services::~Services(){ | ||
111 | |||
112 | } | ||
113 | Services &Services::operator=( const Services& ){ | ||
114 | return *this; | ||
115 | } | ||
116 | bool operator==( const Services&, | ||
117 | const Services& ){ | ||
118 | return false; | ||
119 | } | ||
120 | QString Services::serviceName() const{ | ||
121 | |||
122 | } | ||
123 | void Services::setServiceName( const QString& service ){ | ||
124 | |||
125 | } | ||
126 | int Services::recHandle() const{ | ||
127 | |||
128 | } | ||
129 | void Services::setRecHandle( int ){ | ||
130 | |||
131 | } | ||
132 | QString Services::classIdList() const{ | ||
133 | |||
134 | } | ||
135 | void Services::setClassIdList( const QString& ){ | ||
136 | |||
137 | } | ||
138 | int Services::classIdListInt() const{ | ||
139 | |||
140 | } | ||
141 | void Services::setClassIdList(int ){ | ||
142 | |||
143 | } | ||
144 | void Services::insertProtocolDescriptor( const ProtocolDescriptor& ){ | ||
145 | |||
146 | } | ||
147 | void Services::clearProtocolDescriptorList(){ | ||
148 | |||
149 | } | ||
150 | void Services::removeProtocolDescriptor( const ProtocolDescriptor& ){ | ||
151 | |||
152 | } | ||
153 | Services::ProtocolDescriptor::ValueList Services::protocolDescriptorList()const{ | ||
154 | |||
155 | } | ||
156 | |||
157 | void Services::insertProfileDescriptor( const ProfileDescriptor& ){ | ||
158 | |||
159 | } | ||
160 | void Services::clearProfileDescriptorList(){ | ||
161 | |||
162 | } | ||
163 | void Services::removeProfileDescriptor( const ProfileDescriptor& ){ | ||
164 | |||
165 | } | ||
166 | Services::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 | |||
@@ -15,5 +15,5 @@ namespace OpieTooth { | |||
15 | * | 15 | * |
16 | */ | 16 | */ |
17 | class ProfileDesriptor{ | 17 | class ProfileDescriptor{ |
18 | public: | 18 | public: |
19 | /** typedef */ | 19 | /** typedef */ |
@@ -60,9 +60,13 @@ namespace OpieTooth { | |||
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 | /** |
@@ -82,5 +86,5 @@ namespace OpieTooth { | |||
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; |
@@ -91,6 +95,10 @@ namespace OpieTooth { | |||
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 | ||