From b15f8a613d83a2f3957fef515e20981f636b908b Mon Sep 17 00:00:00 2001 From: zecke Date: Sat, 15 Jun 2002 20:06:04 +0000 Subject: isCOnnected, add and remove Service + first bits of service browsing done --- (limited to 'noncore/net/opietooth/lib/manager.cc') 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,34 +1,49 @@ +#include #include "manager.h" using namespace OpieTooth; -Manager::Manager( const QString& ) +Manager::Manager( const QString& dev ) : QObject() { - + m_device = dev; + m_hcitool = 0; + m_sdp = 0; } Manager::Manager( Device* dev ) : QObject() { - + m_hcitool = 0; + m_sdp = 0; } Manager::Manager() : QObject() { - + m_hcitool = 0; + m_sdp = 0; } Manager::~Manager(){ - + delete m_hcitool; + delete m_sdp; } void Manager::setDevice( const QString& dev ){ - + m_device = dev; } 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; + } } void Manager::isConnected( Device* dev ){ @@ -44,26 +59,76 @@ 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::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; +} -- cgit v0.9.0.2