summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore 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
@@ -1,104 +1,142 @@
#include <signal.h>
#include "kprocess.h"
#include "device.h"
using namespace OpieTooth;
+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 ){
+ if( !(*it).startsWith("CSR") ){
+ id = (*it).toInt();
+ break;
+ }
+ }
+ return id;
+ }
+}
+
Device::Device(const QString &device, const QString &mode )
: QObject(0, "device" ) {
+ qWarning("OpieTooth::Device create" );
m_hci = 0;
m_process = 0;
m_attached = false;
m_device = device;
m_mode = mode;
attach();
}
Device::~Device(){
detach();
}
void Device::attach(){
- if(m_process != 0 ){
+ qWarning("attaching %s %s", m_device.latin1(), m_mode.latin1() );
+ if(m_process == 0 ){
+ m_output.resize(0);
+ qWarning("new process to create" );
m_process = new KProcess();
*m_process << "hciattach";
*m_process << "-p";
*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 ) ){
+ 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 )
+ 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( KProcess* proc)
{
+ qWarning("prcess exited" );
if(proc== m_process ){
if( m_process->normalExit() ){ // normal exit
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 KProcess( );
*m_hci << "hciconfig";
*m_hci << "hci0 up";
connect(m_hci, SIGNAL( processExited(KProcess*) ),
this, SLOT( slotExited(KProcess* ) ) );
+ if(!m_hci->start() ){
+ qWarning("could not start" );
+ m_attached = false;
+ emit device("hci0", false );
+ }
}else{
m_attached = false;
emit device("hci0", false );
}
}
delete m_process;
m_process = 0;
}else if(proc== m_hci ){
+ qWarning("M HCI exited" );
if( m_hci->normalExit() ){
- int ret = m_hci->normalExit();
+ qWarning("normal exit" );
+ int ret = m_hci->exitStatus();
if( ret == 0 ){
+ qWarning("attached really really attached" );
+ m_attached = true;
emit device("hci0", true );
}else{
+ qWarning( "failed" );
emit device("hci0", false );
m_attached = false;
}
}// normal exit
delete m_hci;
m_hci = 0;
}
}
void Device::slotStdOut(KProcess* proc, char* chars, int len)
{
+ qWarning("std out" );
if( len <1 )
return;
if(proc == m_process ){
- QCString string( chars, len+1 );
- if(string.left(3) != "CSR" ){ // it's the pid
- pid = string.toInt();
- };
+ QCString string( chars, len+1 ); // \0 == +1
+ qWarning("output: %s", string.data() );
+ m_output.append( string.data() );
}
}
void Device::slotStdErr(KProcess*, char*, int )
{
-
+ qWarning("std err" );
}
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
@@ -69,16 +69,17 @@ namespace OpieTooth {
virtual void slotStdOut(KProcess*, char*, int );
virtual void slotStdErr(KProcess*, char*, int );
private:
class Private;
Private *d;
QString m_device;
bool m_attached:1;
KProcess* m_hci;
KProcess* m_process;
QString m_devId;
QString m_mode;
pid_t pid;
+ QCString m_output;
};
};
#endif
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,8 +1,8 @@
TEMPLATE = lib
CONFIG += qte warn_on release
-HEADERS = kprocctrl.h kprocess.h device.h
-SOURCES = kprocctrl.cpp kprocess.cpp device.cc
+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
TARGET = opietooth
INCLUDEPATH += $(OPIEDIR)/include
DESTDIR = $(QTDIR)/lib$(PROJMAK)
#VERSION = 0.0.0
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
@@ -1,20 +1,23 @@
#ifndef OpieToothManager_H
#define OpieToothManager_H
#include <qobject.h>
#include <qstring.h>
#include <qvaluelist.h>
+#include "remotedevice.h"
+#include "services.h"
+
namespace OpieTooth {
class Device;
/** Manager manages a blueZ device (hci0 for example)
* with 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
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 @@
+
+#include "remotedevice.h"
+
+using namespace OpieTooth;
+
+bool operator==(const RemoteDevices& rem1, const RemoteDevices& rem2){
+ if( ( rem1.mac() == rem2.mac() ) && (rem1.name() == rem2.name() ) )
+ return true;
+
+ return false;
+}
+
+RemoteDevices::RemoteDevices(){
+
+}
+RemoteDevices::RemoteDevices(const RemoteDevices& ole ){
+ (*this) = ole;
+}
+RemoteDevices::RemoteDevices(const QString &mac, const QString& name ){
+ m_mac = mac;
+ m_name = name;
+}
+RemoteDevices::~RemoteDevices(){
+
+}
+bool RemoteDevices::isEmpty() const {
+ if( m_name.isEmpty() && m_mac.isEmpty() )
+ return true;
+ return false;
+};
+RemoteDevices& RemoteDevices::operator=( const RemoteDevices& rem1){
+ m_name = rem1.m_name;
+ m_mac = rem1.m_mac;
+ return *this;
+
+}
+QString RemoteDevices::mac() const {
+ return m_mac;
+}
+void RemoteDevices::setMac( const QString& mac ){
+ m_mac = mac;
+}
+QString RemoteDevices::name() const{
+ return m_name;
+}
+void RemoteDevices::setName( const QString& name ){
+ m_name = name;
+}
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
@@ -4,21 +4,25 @@
#include <qvaluelist.h>
namespace OpieTooth{
class RemoteDevices {
public:
typedef QValueList<RemoteDevices> ValueList;
RemoteDevices();
RemoteDevices(const RemoteDevices& );
RemoteDevices(const QString &mac, const QString &name );
~RemoteDevices();
friend bool operator==(const RemoteDevices&, const RemoteDevices&);
- RemoteDevies &operator=(const RemoteDevices& );
+ RemoteDevices &operator=(const RemoteDevices& );
+ bool isEmpty()const;
QString mac()const;
void setMac(const QString& mac );
QString name()const;
void setName( const QString& name );
+ private:
+ QString m_name;
+ QString m_mac;
};
};
#endif
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 @@
+
+#include "services.h"
+
+using namespace OpieTooth;
+
+
+Services::ProfileDescriptor::ProfileDescriptor(){
+
+}
+Services::ProfileDescriptor::ProfileDescriptor(const QString &id, uint idInt, uint version ){
+ m_id = id;
+ m_idInt = idInt;
+ m_version = version;
+}
+Services::ProfileDescriptor::ProfileDescriptor( const ProfileDescriptor& rem){
+ (*this) = rem;
+}
+QString Services::ProfileDescriptor::id() const {
+ return m_id;
+}
+void Services::ProfileDescriptor::setId( const QString& id ){
+ m_id = id;
+}
+void Services::ProfileDescriptor::setId(uint id ){
+ m_idInt = id;
+}
+uint Services::ProfileDescriptor::idInt()const{
+ return m_idInt;
+}
+uint Services::ProfileDescriptor::version() const{
+ return m_version;
+}
+void Services::ProfileDescriptor::setVersion(uint version){
+ m_version = version;
+}
+Services::ProfileDescriptor& Services::ProfileDescriptor::operator=( const Services::ProfileDescriptor& prof){
+ m_id = prof.m_id;
+ m_idInt = prof.m_idInt;
+ m_version = prof.m_version;
+ return *this;
+}
+bool operator==(const Services::ProfileDescriptor& first,
+ const Services::ProfileDescriptor& second ){
+
+ if( (first.id() == second.id() ) &&
+ (first.version() == second.version() ) &&
+ (first.idInt() == second.idInt() ) )
+ return true;
+ return false;
+}
+
+Services::ProtocolDescriptor::ProtocolDescriptor(){
+ m_number = 0;
+ m_channel = 0;
+}
+Services::ProtocolDescriptor::ProtocolDescriptor(const QString& name,
+ uint number,
+ uint channel){
+ m_name = name;
+ m_number = number;
+ m_channel = channel;
+}
+Services::ProtocolDescriptor::ProtocolDescriptor( const ProtocolDescriptor& ole ){
+ (*this) = ole;
+}
+Services::ProtocolDescriptor::~ProtocolDescriptor(){
+
+}
+QString Services::ProtocolDescriptor::name() const{
+ return m_name;
+}
+void Services::ProtocolDescriptor::setName(const QString& name ){
+ m_name = name;
+}
+uint Services::ProtocolDescriptor::id()const {
+ return m_number;
+}
+void Services::ProtocolDescriptor::setId( uint id ){
+ m_number = id;
+}
+uint Services::ProtocolDescriptor::port()const {
+ return m_channel;
+}
+void Services::ProtocolDescriptor::setPort( uint port ){
+ m_channel = port;
+}
+Services::ProtocolDescriptor &Services::ProtocolDescriptor::operator=( const Services::ProtocolDescriptor& desc ){
+ m_name = desc.m_name;
+ m_channel = desc.m_channel;
+ m_number = desc.m_number;
+ return *this;
+}
+bool operator==( const Services::ProtocolDescriptor &first,
+ const Services::ProtocolDescriptor &second ){
+ if( ( first.name() == second.name() ) &&
+ ( first.id() == second.id() ) &&
+ ( first.port() == second.port() ) )
+ return true;
+
+ return false;
+
+}
+
+Services::Services(){
+
+}
+Services::Services(const Services& service ){
+
+}
+Services::~Services(){
+
+}
+Services &Services::operator=( const Services& ){
+ return *this;
+}
+bool operator==( const Services&,
+ const Services& ){
+ return false;
+}
+QString Services::serviceName() const{
+
+}
+void Services::setServiceName( const QString& service ){
+
+}
+int Services::recHandle() const{
+
+}
+void Services::setRecHandle( int ){
+
+}
+QString Services::classIdList() const{
+
+}
+void Services::setClassIdList( const QString& ){
+
+}
+int Services::classIdListInt() const{
+
+}
+void Services::setClassIdList(int ){
+
+}
+void Services::insertProtocolDescriptor( const ProtocolDescriptor& ){
+
+}
+void Services::clearProtocolDescriptorList(){
+
+}
+void Services::removeProtocolDescriptor( const ProtocolDescriptor& ){
+
+}
+Services::ProtocolDescriptor::ValueList Services::protocolDescriptorList()const{
+
+}
+
+void Services::insertProfileDescriptor( const ProfileDescriptor& ){
+
+}
+void Services::clearProfileDescriptorList(){
+
+}
+void Services::removeProfileDescriptor( const ProfileDescriptor& ){
+
+}
+Services::ProfileDescriptor::ValueList Services::profileDescriptor() const{
+
+}
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
@@ -5,25 +5,25 @@
#include <qvaluelist.h>
namespace OpieTooth {
/**
* Services lets shows you all available services
* on a remote device
*/
class Services {
/** The profile descriptor
*
*/
- class ProfileDesriptor{
+ class ProfileDescriptor{
public:
/** typedef */
typedef QValueList<ProfileDescriptor> ValueList;
/** c'tor for QValueList */
ProfileDescriptor();
/**
* c'tor
* @param id The id or name ("Lan Access Using PPP")
* @param idInt The id as uint ( 0x1102 )
* @param version Version of the Profile ( 1 )
*/
ProfileDescriptor(const QString &id, uint idInt, uint version );
@@ -50,57 +50,65 @@ namespace OpieTooth {
uint idInt()const;
/**
* returns the version
*/
uint version()const;
/**
* sets the Version
*/
void setVersion(uint version );
/**
* copy operator
*/
- ProfileDescriptor &operator=( const ProfileDescriptor );
+ ProfileDescriptor &operator=( const ProfileDescriptor& );
/**
* operator==
*/
friend bool operator==(const ProfileDescriptor&, const ProfileDescriptor& );
+ private:
+ QString m_id;
+ uint m_idInt;
+ uint m_version;
};
/**
* Protocol Descriptor
*/
class ProtocolDescriptor {
public:
typedef QValueList<ProtocolDescriptor> ValueList;
/**
* c'tor
*/
ProtocolDescriptor();
/**
* name
* number
* channel/port
*/
ProtocolDescriptor(const QString&, uint, uint channel ); // Q_UINT8 ?
- ProtocolDescriptot(const ProtocolDescriptor& );
+ ProtocolDescriptor(const ProtocolDescriptor& );
~ProtocolDescriptor();
QString name()const;
void setName(const QString& );
uint id()const;
void setId(uint );
uint port()const;
void setPort(uint );
ProtocolDescriptor &operator=( const ProtocolDescriptor& );
- friend bool operator==( const ProtocolDescription&,
- const ProtocolDescription& );
+ friend bool operator==( const ProtocolDescriptor&,
+ const ProtocolDescriptor& );
+ private:
+ QString m_name;
+ uint m_number;
+ uint m_channel;
};
public:
typedef QValueList<Services> ValueList;
Services();
Services(const Services& service );
~Services();
Services &operator=( const Services& );
friend bool operator==(const Services&, const Services& );
QString serviceName()const;
void setServiceName( const QString& service );