summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/opietooth/lib/device.cc2
-rw-r--r--noncore/net/opietooth/lib/device.h2
-rw-r--r--noncore/net/opietooth/lib/manager.cc3
-rw-r--r--noncore/net/opietooth/lib/manager.h2
4 files changed, 4 insertions, 5 deletions
diff --git a/noncore/net/opietooth/lib/device.cc b/noncore/net/opietooth/lib/device.cc
index 18d26e4..04c50d9 100644
--- a/noncore/net/opietooth/lib/device.cc
+++ b/noncore/net/opietooth/lib/device.cc
@@ -1,106 +1,106 @@
#include <signal.h>
#include <opie2/oprocess.h>
#include "device.h"
using namespace OpieTooth;
-using namespace Opie::Core;
+using Opie::Core::OProcess;
namespace {
int parsePid( const QCString& par ){
int id=0;
QString string( par );
QStringList list = QStringList::split( '\n', string );
for( QStringList::Iterator it = list.begin(); it != list.end(); ++it ){
qWarning("parsePID: %s", (*it).latin1() );
if( !(*it).startsWith("CSR") ){
id = (*it).toInt();
break;
}
}
return id;
}
}
Device::Device(const QString &device, const QString &mode, const QString &speed )
: QObject(0, "device") {
qWarning("OpieTooth::Device create" );
m_hci = 0;
m_process = 0;
m_attached = false;
m_device = device;
m_mode = mode;
m_speed = speed;
attach();
}
Device::~Device(){
detach();
}
void Device::attach(){
qWarning("attaching %s %s %s", m_device.latin1(), m_mode.latin1(), m_speed.latin1() );
if(m_process == 0 ){
m_output.resize(0);
qWarning("new process to create" );
m_process = new OProcess();
*m_process << "hciattach";
*m_process << "-p";
*m_process << m_device << m_mode << m_speed;
connect(m_process, SIGNAL( processExited(Opie::Core::OProcess*) ),
this, SLOT( slotExited(Opie::Core::OProcess* ) ) );
connect(m_process, SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int) ),
this, SLOT(slotStdOut(Opie::Core::OProcess*,char*,int ) ) );
connect(m_process, SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int ) ),
this, SLOT(slotStdErr(Opie::Core::OProcess*,char*,int) ) );
if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ){
qWarning("Could not start" );
delete m_process;
m_process = 0;
}
};
}
void Device::detach(){
delete m_hci;
delete m_process;
// kill the pid we got
if(m_attached ){
//kill the pid
qWarning( "killing" );
kill(pid, 9);
}
qWarning("detached" );
}
bool Device::isLoaded()const{
return m_attached;
}
QString Device::devName()const {
return QString::fromLatin1("hci0");
};
void Device::slotExited( OProcess* proc)
{
qWarning("prcess exited" );
if(proc== m_process ){
qWarning("proc == m_process" );
if( m_process->normalExit() ){ // normal exit
qWarning("normalExit" );
int ret = m_process->exitStatus();
if( ret == 0 ){ // attached
qWarning("attached" );
qWarning("Output: %s", m_output.data() );
pid = parsePid( m_output );
qWarning("Pid = %d", pid );
// now hciconfig hci0 up ( determine hciX FIXME)
// and call hciconfig hci0 up
// FIXME hardcoded to hci0 now :(
m_hci = new OProcess( );
*m_hci << "hciconfig";
*m_hci << "hci0 up";
connect(m_hci, SIGNAL( processExited(Opie::Core::OProcess*) ),
this, SLOT( slotExited(Opie::Core::OProcess* ) ) );
if(!m_hci->start() ){
qWarning("could not start" );
m_attached = false;
emit device("hci0", false );
}
diff --git a/noncore/net/opietooth/lib/device.h b/noncore/net/opietooth/lib/device.h
index f3339fc..3631c97 100644
--- a/noncore/net/opietooth/lib/device.h
+++ b/noncore/net/opietooth/lib/device.h
@@ -1,88 +1,88 @@
#ifndef OpieToothDevice_H
#define OpieToothDevice_H
#include <qobject.h>
#include <qstring.h>
#include <qvaluelist.h>
#include <sys/types.h>
-namespace Opie {namespace Core {class Opie::Core::OProcess;}}
+namespace Opie {namespace Core {class OProcess;}}
namespace OpieTooth {
/**
* Device takes care of attaching serial
* devices to the blueZ stack.
* After attaching it hciconfig ups it
*/
class Device : public QObject {
Q_OBJECT
public:
/**
* Brings up an device.
* Usage example: new Device(/dev/ttySB0, csr)
*
* @param &device QString the device name
* @param &mode QString the mode
* @param &speed QString the speed of the device, can be left blank
*/
Device(const QString &device, const QString& mode, const QString& speed);
/**
* unloads the device
*/
~Device();
/**
* attach the device
*/
void attach();
/**
* detach the device
*/
void detach();
/**
* Is the device loaded?
* @return bool, if the device is loaded
*/
bool isLoaded()const;
/**
* Returns the device name
* @return QString, the device name
*/
QString devName()const ; // hci0
signals:
/**
* Signals devicename and up status
* @return &device QString, Devicename
* @return up bool, if the device is up or not.
*/
void device(const QString& device, bool up );
private slots:
virtual void slotExited( Opie::Core::OProcess* );
virtual void slotStdOut(Opie::Core::OProcess*, char*, int );
virtual void slotStdErr(Opie::Core::OProcess*, char*, int );
private:
class Private;
Private *d;
QString m_device;
bool m_attached:1;
Opie::Core::OProcess* m_hci;
Opie::Core::OProcess* m_process;
QString m_devId;
QString m_mode;
QString m_speed;
pid_t pid;
QCString m_output;
};
};
#endif
diff --git a/noncore/net/opietooth/lib/manager.cc b/noncore/net/opietooth/lib/manager.cc
index 7c9ea5b..18e1df9 100644
--- a/noncore/net/opietooth/lib/manager.cc
+++ b/noncore/net/opietooth/lib/manager.cc
@@ -1,108 +1,107 @@
#include <opie2/oprocess.h>
#include "parser.h"
#include "manager.h"
using namespace OpieTooth;
-using namespace Opie::Core;
-using namespace Opie::Core;
+using Opie::Core::OProcess;
Manager::Manager( const QString& dev )
: QObject()
{
qWarning("created");
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::isAvailable( const QString& device ){
OProcess* l2ping = new OProcess();
l2ping->setName( device.latin1() );
*l2ping << "l2ping" << "-c1" << device;
connect(l2ping, SIGNAL(processExited(Opie::Core::OProcess* ) ),
this, SLOT(slotProcessExited(Opie::Core::OProcess*) ) );
if (!l2ping->start() ) {
emit available( device, false );
delete l2ping;
}
}
void Manager::isAvailable( Device* /*dev*/ ){
}
void Manager::searchDevices( const QString& device ){
qWarning("search devices");
OProcess* hcitool = new OProcess();
hcitool->setName( device.isEmpty() ? "hci0" : device.latin1() );
*hcitool << "hcitool" << "scan";
connect( hcitool, SIGNAL(processExited(Opie::Core::OProcess*) ) ,
this, SLOT(slotHCIExited(Opie::Core::OProcess* ) ) );
connect( hcitool, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ),
this, SLOT(slotHCIOut(Opie::Core::OProcess*, char*, int ) ) );
if (!hcitool->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
qWarning("could not start");
RemoteDevice::ValueList list;
emit foundDevices( device, list );
delete hcitool;
}
}
void Manager::searchDevices(Device* /*d*/ ){
}
void Manager::addService(const QString& name ){
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 ){
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();
diff --git a/noncore/net/opietooth/lib/manager.h b/noncore/net/opietooth/lib/manager.h
index 9b1c714..930eb56 100644
--- a/noncore/net/opietooth/lib/manager.h
+++ b/noncore/net/opietooth/lib/manager.h
@@ -1,110 +1,110 @@
#ifndef OpieToothManager_H
#define OpieToothManager_H
#include <qobject.h>
#include <qstring.h>
#include <qmap.h>
#include <qvaluelist.h>
#include "connection.h"
#include "remotedevice.h"
#include "services.h"
-namespace Opie {namespace Core {class Opie::Core::OProcess;}}
+namespace Opie {namespace Core {class OProcess;}}
namespace OpieTooth {
class Device;
/** Manager manages a blueZ device (hci0 for example)
* without Manager you can control the things you
* could do from command line in a OO and asynchronus
* way.
*/
class Manager : public QObject {
Q_OBJECT
public:
/** c'tor whichs create a new Manager
* @param device is the device to use. Either a mac or blueZ device name
*
*/
Manager( const QString &device );
/** c'tor
* @param dev The Device to be managed
* We don't care of Device so you need to delete it
*/
Manager( Device* dev );
/**
* c'tor
*/
Manager();
~Manager();
/** Set the manager to control a new device
* @param device the new device to control (hci0 )
*/
void setDevice( const QString& device );
/**
* Convience functions for setting a new device
*/
void setDevice( Device *dev );
/**
* Wether or not a device is connected. The function
* is asynchron
* If device is empty it will take the currently managed
* device and see if it's up
* for Remote devices it will ping and see.
* @param either mac or hciX
*/
void isAvailable(const QString& device= QString::null );
/**
* same as above
*/
void isAvailable(Device *dev );
/** this searchs for devices reachable from the
* currently managed device
* or from device if @param device is not empty
*/
void searchDevices(const QString& device= QString::null );
/** same as above
*
*/
void searchDevices(Device *d );
/**
* This will add the service @param name
* to the sdpd daemon
* It will start the daemon if necessary
*/
void addService(const QString &name );
/**
* This will add the services @param names
* to the sdpd daemon
* It will start the daemon if necessary
*/
void addServices( const QStringList& names );
/**
* This removes a service from the sdps
*/
void removeService(const QString &name );
/**
* Removes a list from the sdpd
*/
void removeServices(const QStringList& );
/**
* search for services on a remote device
*
*/
void searchServices( const QString& remDevice );
/**
* search for services on a remote device