summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (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 @@
-#include "kprocess.h"
+#include <opie/oprocess.h>
@@ -42,3 +42,3 @@ void Device::attach(){
qWarning("new process to create" );
- m_process = new KProcess();
+ m_process = new OProcess();
*m_process << "hciattach";
@@ -46,9 +46,9 @@ void Device::attach(){
*m_process << m_device << m_mode;
- connect(m_process, SIGNAL( processExited(KProcess*) ),
- this, SLOT( slotExited(KProcess* ) ) );
- connect(m_process, SIGNAL( receivedStdout(KProcess*, char*, int) ),
- this, SLOT(slotStdOut(KProcess*,char*,int ) ) );
- connect(m_process, SIGNAL(receivedStderr(KProcess*, char*, int ) ),
- this, SLOT(slotStdErr(KProcess*,char*,int) ) );
- if(!m_process->start(KProcess::NotifyOnExit, KProcess::AllOutput ) ){
+ connect(m_process, SIGNAL( processExited(OProcess*) ),
+ this, SLOT( slotExited(OProcess* ) ) );
+ connect(m_process, SIGNAL( receivedStdout(OProcess*, char*, int) ),
+ this, SLOT(slotStdOut(OProcess*,char*,int ) ) );
+ connect(m_process, SIGNAL(receivedStderr(OProcess*, char*, int ) ),
+ this, SLOT(slotStdErr(OProcess*,char*,int) ) );
+ if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ){
qWarning("Could not start" );
@@ -76,3 +76,3 @@ QString Device::devName()const {
};
-void Device::slotExited( KProcess* proc)
+void Device::slotExited( OProcess* proc)
{
@@ -90,7 +90,7 @@ void Device::slotExited( KProcess* proc)
// FIXME hardcoded to hci0 now :(
- m_hci = new KProcess( );
+ m_hci = new OProcess( );
*m_hci << "hciconfig";
*m_hci << "hci0 up";
- connect(m_hci, SIGNAL( processExited(KProcess*) ),
- this, SLOT( slotExited(KProcess* ) ) );
+ connect(m_hci, SIGNAL( processExited(OProcess*) ),
+ this, SLOT( slotExited(OProcess* ) ) );
if(!m_hci->start() ){
@@ -127,3 +127,3 @@ void Device::slotExited( KProcess* proc)
}
-void Device::slotStdOut(KProcess* proc, char* chars, int len)
+void Device::slotStdOut(OProcess* proc, char* chars, int len)
{
@@ -138,3 +138,3 @@ void Device::slotStdOut(KProcess* proc, char* chars, int len)
}
-void Device::slotStdErr(KProcess*, char*, int )
+void Device::slotStdErr(OProcess*, char*, int )
{
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 @@
-class KProcess;
+class OProcess;
namespace OpieTooth {
@@ -67,5 +67,5 @@ namespace OpieTooth {
private slots:
- virtual void slotExited( KProcess* );
- virtual void slotStdOut(KProcess*, char*, int );
- virtual void slotStdErr(KProcess*, char*, int );
+ virtual void slotExited( OProcess* );
+ virtual void slotStdOut(OProcess*, char*, int );
+ virtual void slotStdErr(OProcess*, char*, int );
private:
@@ -75,4 +75,4 @@ namespace OpieTooth {
bool m_attached:1;
- KProcess* m_hci;
- KProcess* m_process;
+ OProcess* m_hci;
+ OProcess* m_process;
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
CONFIG += qte warn_on release
-HEADERS = kprocctrl.h kprocess.h device.h manager.h remotedevice.h services.h
-SOURCES = kprocctrl.cpp kprocess.cpp device.cc manager.cc remotedevice.cc services.cc
+HEADERS = device.h manager.h remotedevice.h services.h
+SOURCES = device.cc manager.cc remotedevice.cc services.cc
TARGET = opietooth
@@ -7,2 +7,3 @@ INCLUDEPATH += $(OPIEDIR)/include
DESTDIR = $(QTDIR)/lib$(PROJMAK)
+LIBS = -lopie
#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 @@
+#include <opie/oprocess.h>
@@ -6,6 +7,8 @@ using namespace OpieTooth;
-Manager::Manager( const QString& )
+Manager::Manager( const QString& dev )
: QObject()
{
-
+ m_device = dev;
+ m_hcitool = 0;
+ m_sdp = 0;
}
@@ -14,3 +17,4 @@ Manager::Manager( Device* dev )
{
-
+ m_hcitool = 0;
+ m_sdp = 0;
}
@@ -19,9 +23,11 @@ Manager::Manager()
{
-
+ m_hcitool = 0;
+ m_sdp = 0;
}
Manager::~Manager(){
-
+ delete m_hcitool;
+ delete m_sdp;
}
void Manager::setDevice( const QString& dev ){
-
+ m_device = dev;
}
@@ -31,2 +37,11 @@ void Manager::setDevice( Device* dev ){
void Manager::isConnected( const QString& device ){
+ OProcess* l2ping = new OProcess();
+ l2ping->setName( device.latin1() );
+ *l2ping << "l2ping" << "-c1" << device;
+ connect(l2ping, SIGNAL(processExited(OProcess* ) ),
+ this, SLOT(slotProcessExited(OProcess*) ) );
+ if (!l2ping->start() ) {
+ emit connected( device, false );
+ delete l2ping;
+ }
@@ -46,24 +61,74 @@ void Manager::searchDevices(Device* d ){
void Manager::addService(const QString& name ){
-
-}
-void Manager::addServices(const QStringList& ){
-
+ OProcess proc;
+ proc << "sdptool" << "add" << name;
+ bool bo = true;
+ if (!proc.start(OProcess::DontCare ) )
+ bo = false;
+ emit addedService( name, bo );
+}
+void Manager::addServices(const QStringList& list){
+ QStringList::ConstIterator it;
+ for (it = list.begin(); it != list.end(); ++it )
+ addService( (*it) );
}
void Manager::removeService( const QString& name ){
-
-}
-void Manager::removeServices( const QStringList& ){
-
+ OProcess prc;
+ prc << "sdptool" << "del" << name;
+ bool bo = true;
+ if (!prc.start(OProcess::DontCare ) )
+ bo = false;
+ emit removedService( name, bo );
+}
+void Manager::removeServices( const QStringList& list){
+ QStringList::ConstIterator it;
+ for (it = list.begin(); it != list.end(); ++it )
+ removeService( (*it) );
}
void Manager::searchServices( const QString& remDevice ){
+ OProcess *m_sdp =new OProcess();
+ *m_sdp << "sdptool" << "browse" << remDevice;
+ m_sdp->setName( remDevice.latin1() );
+ connect(m_sdp, SIGNAL(processExited(OProcess*) ),
+ this, SLOT(slotSDPExited(OProcess* ) ) );
+ connect(m_sdp, SIGNAL(receivedStdout(OProcess*, char*, int ) ),
+ this, SLOT(slotSDPOut(OProcess*, char*, int) ) );
+ if (!m_sdp->start() ) {
+ delete m_sdp;
+ Services::ValueList list;
+ emit foundServices( remDevice, list );
+ }
+}
+void Manager::searchServices( const RemoteDevices& dev){
+ searchServices( dev.mac() );
+}
+QString Manager::toDevice( const QString& mac ){
}
-void Manager::searchServices( const RemoteDevices& ){
+QString Manager::toMac( const QString &device ){
}
-QString Manager::toDevice( const QString& mac ){
+void Manager::slotProcessExited(OProcess* proc ) {
+ bool conn= false;
+ if (proc->normalExit() && proc->exitStatus() == 0 )
+ conn = true;
+ QString name = QString::fromLatin1(proc->name() );
+ emit connected( name, conn );
+ delete proc;
}
-QString Manager::toMac( const QString &device ){
+void Manager::slotSDPOut(OProcess* proc, char* ch, int len)
+{
+ QCString str(ch, len+1 );
+ QMap<QString, QString>::Iterator it;
+ it = m_out.find(proc->name() );
+ if ( it != m_out.end() ) {
+ QString string = it.data();
+ string.append( str );
+ m_out.replace( proc->name(), string );
+ }
}
+void Manager::slotSDPExited( OProcess* proc)
+{
+ delete proc;
+}
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 @@
#include <qstring.h>
+#include <qmap.h>
#include <qvaluelist.h>
@@ -11,2 +12,3 @@
+class OProcess;
namespace OpieTooth {
@@ -16,3 +18,3 @@ namespace OpieTooth {
* could do from command line in a OO and asynchronus
- * way.
+ * way.
*/
@@ -29,3 +31,3 @@ Q_OBJECT
* We don't care of Device so you need to delete it
- */
+ */
Manager( Device* dev );
@@ -50,3 +52,4 @@ Q_OBJECT
* device and see if it's up
- * for Remote devices it will ping and see
+ * for Remote devices it will ping and see.
+ * @param either mac or hciX
*/
@@ -58,4 +61,4 @@ Q_OBJECT
- /** this search for devices reachable from the
- * currently managed device
+ /** this searchs for devices reachable from the
+ * currently managed device
* or from device if @param device is not empty
@@ -91,3 +94,3 @@ Q_OBJECT
* search for services on a remote device
- *
+ *
*/
@@ -105,6 +108,16 @@ Q_OBJECT
void connected( const QString& device, bool connected );
- void addedService( const QString& device, const QString& service, bool added );
- void removedService( const QString& device, const QString& service, bool removed );
+ 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, RemoteDevices::ValueList );
+ void foundNothing( const QString& device );
+private slots:
+ void slotProcessExited(OProcess* );
+ void slotSDPExited(OProcess*);
+ void slotSDPOut(OProcess*, char*, int);
+ private:
+ OProcess *m_hcitool;
+ OProcess *m_sdp; // not only one
+ QString m_device;
+ QMap<QString, QString> m_out;
};