summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opietooth/lib/manager.cc22
-rw-r--r--noncore/net/opietooth/lib/parser.cc90
-rw-r--r--noncore/net/opietooth/lib/parser.h3
-rw-r--r--noncore/net/opietooth/lib/services.cc66
-rw-r--r--noncore/net/opietooth/lib/services.h15
5 files changed, 142 insertions, 54 deletions
diff --git a/noncore/net/opietooth/lib/manager.cc b/noncore/net/opietooth/lib/manager.cc
index fcd21f6..177c94e 100644
--- a/noncore/net/opietooth/lib/manager.cc
+++ b/noncore/net/opietooth/lib/manager.cc
@@ -1,213 +1,219 @@
+
+
#include <opie/oprocess.h>
+#include "parser.h"
#include "manager.h"
using namespace OpieTooth;
Manager::Manager( const QString& dev )
: QObject()
{
qWarning("created");
m_device = dev;
m_hcitool = 0;
m_sdp = 0;
}
-Manager::Manager( Device* dev )
+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::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(OProcess* ) ),
this, SLOT(slotProcessExited(OProcess*) ) );
if (!l2ping->start() ) {
emit available( device, false );
delete l2ping;
}
}
-void Manager::isAvailable( Device* dev ){
+
+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(OProcess*) ) ,
this, SLOT(slotHCIExited(OProcess* ) ) );
connect( hcitool, SIGNAL(receivedStdout(OProcess*, char*, int ) ),
this, SLOT(slotHCIOut(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::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();
*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(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
delete m_sdp;
Services::ValueList list;
emit foundServices( remDevice, list );
}
}
void Manager::searchServices( const RemoteDevice& dev){
searchServices( dev.mac() );
}
-QString Manager::toDevice( const QString& mac ){
-
+QString Manager::toDevice( const QString& /*mac*/ ){
+ return QString::null;
}
-QString Manager::toMac( const QString &device ){
-
+QString Manager::toMac( const QString &/*device*/ ){
+ return QString::null;
}
void Manager::slotProcessExited(OProcess* proc ) {
bool conn= false;
if (proc->normalExit() && proc->exitStatus() == 0 )
conn = true;
QString name = QString::fromLatin1(proc->name() );
emit available( name, conn );
delete proc;
}
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)
{
Services::ValueList list;
if (proc->normalExit() ) {
QMap<QString, QString>::Iterator it = m_out.find( proc->name() );
if ( it != m_out.end() ) {
list = parseSDPOutput( it.data() );
m_out.remove( it );
}
}
emit foundServices( proc->name(), list );
delete proc;
}
Services::ValueList Manager::parseSDPOutput( const QString& out ) {
Services::ValueList list;
+ Parser parser( out );
+ list = parser.services();
return list;
}
void Manager::slotHCIExited(OProcess* proc ) {
qWarning("process exited");
RemoteDevice::ValueList list;
if (proc->normalExit() ) {
qWarning("normalExit %s", proc->name() );
QMap<QString, QString>::Iterator it = m_devices.find(proc->name() );
if (it != m_devices.end() ) {
qWarning("!= end ;)");
list = parseHCIOutput( it.data() );
m_devices.remove( it );
}
}
emit foundDevices( proc->name(), list );
delete proc;
}
void Manager::slotHCIOut(OProcess* proc, char* ch, int len) {
QCString str( ch, len+1 );
qWarning("hci: %s", str.data() );
QMap<QString, QString>::Iterator it;
it = m_devices.find( proc->name() );
qWarning("proc->name %s", proc->name() );
QString string;
if (it != m_devices.end() ) {
qWarning("slotHCIOut ");
string = it.data();
}
string.append( str );
m_devices.replace( proc->name(), string );
}
RemoteDevice::ValueList Manager::parseHCIOutput(const QString& output ) {
qWarning("parseHCI %s", output.latin1() );
RemoteDevice::ValueList list;
QStringList strList = QStringList::split('\n', output );
QStringList::Iterator it;
QString str;
for ( it = strList.begin(); it != strList.end(); ++it ) {
str = (*it).stripWhiteSpace();
qWarning("OpieTooth %s", str.latin1() );
int pos = str.findRev(':' );
if ( pos > 0 ) {
QString mac = str.left(17 );
str.remove( 0, 17 );
qWarning("mac %s", mac.latin1() );
qWarning("rest:%s", str.latin1() );
RemoteDevice rem( mac , str.stripWhiteSpace() );
list.append( rem );
}
}
return list;
}
diff --git a/noncore/net/opietooth/lib/parser.cc b/noncore/net/opietooth/lib/parser.cc
index 452917b..18d534e 100644
--- a/noncore/net/opietooth/lib/parser.cc
+++ b/noncore/net/opietooth/lib/parser.cc
@@ -1,113 +1,173 @@
#include <qstringlist.h>
#include "parser.h"
using namespace OpieTooth;
+namespace {
+
+
+ // "Test Foo Bar" (0x3456)
+ // @param ret Test Foo Bar
+ // @eturn 13398
+ // tactic find " (
+int convert( const QString& line, QString& ret ) {
+ ret = QString::null;
+ int i = 0;
+ int pos = line.findRev("\" (");
+ if ( pos > 0 ) { // it shouldn't be at pos 0
+ ret = line.left(pos-1 ).stripWhiteSpace();
+ qWarning("ret: %s", ret.latin1() );
+ ret = ret.replace(QRegExp("[\"]"), "");
+ qWarning("ret: %s", ret.latin1() );
+ QString dummy = line.mid(pos + 4 );
+ qWarning("dummy: %s", dummy.latin1() );
+ dummy = dummy.remove( dummy.length() -1, 1 ); // remove the (
+ bool ok;
+ i = dummy.toInt(&ok, 16 );
+ }
+ return i;
+}
+
+};
+
+
Parser::Parser(const QString& output ) {
parse( output );
}
void Parser::setText(const QString& output) {
parse( output );
}
Services::ValueList Parser::services() const {
return m_list;
}
void Parser::parse( const QString& string) {
m_list.clear();
m_complete = true;
QStringList list = QStringList::split('\n', string );
QStringList::Iterator it;
for (it = list.begin(); it != list.end(); ++it ) {
if ( (*it).startsWith("Browsing") ) continue;
if ( (*it).isEmpty() ) { // line is empty because a new Service begins
// now see if complete and add
if (m_complete ) {
m_list.append( m_item );
Services serv;
m_item = serv;
+ m_complete = true;
continue;
}
}
if (parseName( (*it) ) ) ;//continue;
if (parseRecHandle( (*it) ) ) ;//continue;
if (parseClassId( (*it) ) ) ;//continue;
if (parseProtocol( (*it) ) ) ;//continue;
if (parseProfile( (*it) ) ) ;//continue;
}
+ // missed the last one
+ if (m_complete) {
+ m_list.append(m_item );
+ }
}
bool Parser::parseName( const QString& str) {
if (str.startsWith("Service Name:") ) {
m_item.setServiceName( str.mid(13).stripWhiteSpace() );
qWarning(m_item.serviceName() );
return true;
}
return false;
}
bool Parser::parseRecHandle( const QString& str) {
if (str.startsWith("Service RecHandle:" ) ) {
QString out = str.mid(18 ).stripWhiteSpace();
qWarning("out %s", out.latin1() );
int value = out.toInt(&m_ok, 16 );
if (m_ok && (value != -1) )
m_complete = true;
else
m_complete = false;
return true;
m_item.setRecHandle( value );
}
return false;
}
bool Parser::parseClassId( const QString& str) {
if (str.startsWith("Service Class ID List:") ) {
m_classOver = true;
return true;
}else if ( m_classOver ) { // ok now are the informations in place
m_classOver = false;
- QStringList list = QStringList::split('\n', str.stripWhiteSpace() );
-
- if ( list.count() == 2 ) {
- m_item.setClassIdList( list[0] );
- // now let's parse the number (0x1105)
- QString classId= list[1];
- int classIdInt;
- qWarning("%s", list[1].latin1() );
- classId = classId.remove(0, 3 );
- classId = classId.remove( classId.length()-1, 1 );
- qWarning("%s", classId.latin1() );
- m_item.setClassIdList( classId.toInt(&m_ok, 16 ) );
- }
+
+ // "Obex Object Push" (0x1105)
+ // find backwards the " and the from 0 to pos and the mid pos+1
+ // then stripWhiteSpace add name replace '"' with ""
+ // and then convert 0x1105 toInt()
+ QString classes;
+ int ids;
+ ids = convert( str, classes );
+ qWarning("ids %d", ids );
+ m_item.setClassIdList( classes );
+ m_item.setClassIdList( ids );
+
return true;
}else
m_classOver = true;
return false;
}
bool Parser::parseProtocol( const QString& str) {
if (str.startsWith("Protocol Descriptor List:") ) {
m_protocolOver = true;
m_protocolAdded = false;
return true;
- }else if (m_protocolOver && str.startsWith(" ") ) {
+ }else if (m_protocolOver && str.startsWith(" ") ) { // "L2CAP" (0x0100)
qWarning("double protocol filter");
+
if (!m_protocolAdded ) { // the protocol does neither supply a channel nor port so add it now
Services::ProtocolDescriptor desc( m_protName, m_protId );
m_item.insertProtocolDescriptor( desc );
}
m_protocolAdded = false;
+ { // the find function
+ m_protId = convert(str, m_protName );
+ }
return true;
}else if (m_protocolOver && str.startsWith(" ") ) {
qWarning("tripple protocol filter");
m_protocolAdded = true;
+ QString dummy = str.stripWhiteSpace();
+ int pos = dummy.findRev(':');
+ if ( pos > -1 ) {
+ int port = dummy.mid(pos+1 ).stripWhiteSpace().toInt();
+ Services::ProtocolDescriptor desc( m_protName, m_protId, port );
+ m_item.insertProtocolDescriptor( desc );
+ }
return true;
}else if (m_protocolOver ) {
m_protocolOver = false;
}
return false;
}
-bool Parser::parseProfile( const QString& ) {
+bool Parser::parseProfile( const QString& str) {
+ if (str.startsWith("Profile Descriptor List:") ) {
+ m_profOver = true;
+ }else if ( m_profOver && str.startsWith(" ") ) {
+ m_profId = convert( str, m_profName );
+ }else if ( m_profOver && str.startsWith(" ") ) {
+ // now find
+ int pos = str.findRev(':');
+ if ( pos > 0 ) {
+ int dummy = str.mid(pos+1 ).stripWhiteSpace().toInt();
+ qWarning("dummyInt:%d", dummy );
+ Services::ProfileDescriptor desc( m_profName, m_profId, dummy );
+ m_item.insertProfileDescriptor(desc);
+ }
+ }else
+ m_profOver = false;
+
+
return false;
}
diff --git a/noncore/net/opietooth/lib/parser.h b/noncore/net/opietooth/lib/parser.h
index 7642ac3..520a725 100644
--- a/noncore/net/opietooth/lib/parser.h
+++ b/noncore/net/opietooth/lib/parser.h
@@ -1,34 +1,37 @@
#ifndef OpieToothParser_H
#define OpieToothParser_H
#include <services.h>
namespace OpieTooth {
class Parser{
public:
Parser(const QString& output );
~Parser() {};
void setText(const QString& output );
Services::ValueList services()const;
private:
Services::ValueList m_list;
Services m_item;
void parse( const QString& );
bool parseName(const QString& );
bool parseRecHandle( const QString& );
bool parseClassId( const QString& );
bool parseProtocol( const QString& id );
bool parseProfile( const QString& ) ;
bool m_complete:1;
bool m_ok;
bool m_classOver:1;
+ bool m_profOver:1;
bool m_protocolOver:1;
bool m_protocolAdded:1;
QString m_protName;
int m_protId;
+ QString m_profName;
+ int m_profId;
};
};
#endif
diff --git a/noncore/net/opietooth/lib/services.cc b/noncore/net/opietooth/lib/services.cc
index d91e4a1..93ee70a 100644
--- a/noncore/net/opietooth/lib/services.cc
+++ b/noncore/net/opietooth/lib/services.cc
@@ -44,125 +44,139 @@ bool operator==(const Services::ProfileDescriptor& first,
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,
int number,
int 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;
}
int Services::ProtocolDescriptor::id()const {
return m_number;
}
void Services::ProtocolDescriptor::setId( int id ){
m_number = id;
}
int Services::ProtocolDescriptor::port()const {
return m_channel;
}
void Services::ProtocolDescriptor::setPort( int 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 ){
-
+ (*this) = service;
}
Services::~Services(){
}
-Services &Services::operator=( const Services& ){
+Services &Services::operator=( const Services& ser){
+ m_name = ser.m_name;
+ m_recHandle = ser.m_recHandle;
+ m_classList = ser.m_classList;
+ m_classId = ser.m_classId;
+ m_protocols = ser.m_protocols;
+ m_profiles = ser.m_profiles;
return *this;
}
-bool operator==( const Services&,
- const Services& ){
+bool operator==( const Services& one,
+ const Services& two){
+ if ( ( one.recHandle() == two.recHandle() ) &&
+ ( one.classIdListInt() == two.classIdListInt() ) &&
+ ( one.serviceName() == two.serviceName() ) &&
+ ( one.classIdList() == two.classIdList() ) &&
+ ( one.protocolDescriptorList() == two.protocolDescriptorList() ) &&
+ ( one.profileDescriptor() == two.profileDescriptor() ) )
+ return true;
return false;
}
QString Services::serviceName() const{
-
+ return m_name;
}
void Services::setServiceName( const QString& service ){
-
+ m_name = service;
}
int Services::recHandle() const{
-
+ return m_recHandle;
}
-void Services::setRecHandle( int ){
-
+void Services::setRecHandle( int handle){
+ m_recHandle = handle;
}
QString Services::classIdList() const{
-
+ return m_classList;
}
-void Services::setClassIdList( const QString& ){
-
+void Services::setClassIdList( const QString& str){
+ m_classList = str;
}
int Services::classIdListInt() const{
-
+ return m_classId;
}
-void Services::setClassIdList(int ){
-
+void Services::setClassIdList(int id){
+ m_classId = id;
}
-void Services::insertProtocolDescriptor( const ProtocolDescriptor& ){
-
+void Services::insertProtocolDescriptor( const ProtocolDescriptor& prot){
+ m_protocols.append( prot );
}
void Services::clearProtocolDescriptorList(){
-
+ m_protocols.clear();
}
-void Services::removeProtocolDescriptor( const ProtocolDescriptor& ){
-
+void Services::removeProtocolDescriptor( const ProtocolDescriptor& prot){
+ m_protocols.remove( prot );
}
Services::ProtocolDescriptor::ValueList Services::protocolDescriptorList()const{
-
+ return m_protocols;
}
-void Services::insertProfileDescriptor( const ProfileDescriptor& ){
+void Services::insertProfileDescriptor( const ProfileDescriptor& prof){
+ m_profiles.append( prof );
}
void Services::clearProfileDescriptorList(){
-
+ m_profiles.clear();
}
-void Services::removeProfileDescriptor( const ProfileDescriptor& ){
-
+void Services::removeProfileDescriptor( const ProfileDescriptor& prof){
+ m_profiles.remove(prof );
}
Services::ProfileDescriptor::ValueList Services::profileDescriptor() const{
-
+ return m_profiles;
}
diff --git a/noncore/net/opietooth/lib/services.h b/noncore/net/opietooth/lib/services.h
index 65de049..881d383 100644
--- a/noncore/net/opietooth/lib/services.h
+++ b/noncore/net/opietooth/lib/services.h
@@ -2,137 +2,142 @@
#ifndef OpieToothServices_H
#define OpieToothServices_H
#include <qvaluelist.h>
namespace OpieTooth {
/**
* Services lets shows you all available services
* on a remote device
*/
class Services {
/** The profile descriptor
*
*/
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, int idInt, int version );
/**
* copy c'tor
*/
ProfileDescriptor(const ProfileDescriptor& );
/**
* returns the id
*/
QString id()const;
/**
* sets the id
*/
void setId(const QString& id);
/**
* sets the int id
*/
void setId(int );
/**
* reutns the id as int
*/
int idInt()const;
/**
* returns the version
*/
int version()const;
/**
* sets the Version
*/
void setVersion(int version );
/**
* copy operator
*/
ProfileDescriptor &operator=( const ProfileDescriptor& );
/**
* operator==
*/
- friend bool operator==(const ProfileDescriptor&, const ProfileDescriptor& );
+// friend bool operator==(const ProfileDescriptor&, const ProfileDescriptor& );
private:
QString m_id;
int m_idInt;
int m_version;
};
/**
* Protocol Descriptor
*/
class ProtocolDescriptor {
public:
typedef QValueList<ProtocolDescriptor> ValueList;
/**
* c'tor
*/
ProtocolDescriptor();
/**
* name
* number
* channel/port
*/
ProtocolDescriptor(const QString&, int, int port = -1 ); // Q_UINT8 ?
ProtocolDescriptor(const ProtocolDescriptor& );
~ProtocolDescriptor();
QString name()const;
void setName(const QString& );
int id()const;
void setId(int );
int port()const;
void setPort(int );
ProtocolDescriptor &operator=( const ProtocolDescriptor& );
- friend bool operator==( const ProtocolDescriptor&,
- const ProtocolDescriptor& );
+ //friend bool operator==( const ProtocolDescriptor&,
+ // const ProtocolDescriptor& );
private:
QString m_name;
int m_number;
int 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 );
int recHandle()const;
void setRecHandle( int );
QString classIdList()const;
void setClassIdList( const QString& );
int classIdListInt()const;
void setClassIdList(int );
void insertProtocolDescriptor(const ProtocolDescriptor& );
void clearProtocolDescriptorList();
void removeProtocolDescriptor( const ProtocolDescriptor& );
ProtocolDescriptor::ValueList protocolDescriptorList()const;
void insertProfileDescriptor( const ProfileDescriptor& );
void clearProfileDescriptorList();
void removeProfileDescriptor(const ProfileDescriptor& );
ProfileDescriptor::ValueList profileDescriptor()const;
-
-
+ private:
+ QString m_name;
+ int m_recHandle;
+ QString m_classList;
+ int m_classId;
+ QValueList<ProfileDescriptor> m_profiles;
+ QValueList<ProtocolDescriptor> m_protocols;
};
};
#endif