author | zecke <zecke> | 2002-07-13 12:54:47 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-07-13 12:54:47 (UTC) |
commit | d7f3722f9b7913731978437085b14cc2cccbfa24 (patch) (side-by-side diff) | |
tree | 1b190105693609cc01d1ad9730e8925e957209c9 | |
parent | 8be0a8e108eaf8ff99301aa175298ddeb48eae67 (diff) | |
download | opie-d7f3722f9b7913731978437085b14cc2cccbfa24.zip opie-d7f3722f9b7913731978437085b14cc2cccbfa24.tar.gz opie-d7f3722f9b7913731978437085b14cc2cccbfa24.tar.bz2 |
LIB updates
Class IdList per Service can have more than one line
-rw-r--r-- | noncore/net/opietooth/lib/parser.cc | 8 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/services.cc | 26 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/services.h | 13 |
3 files changed, 22 insertions, 25 deletions
diff --git a/noncore/net/opietooth/lib/parser.cc b/noncore/net/opietooth/lib/parser.cc index 00ec84a..0699309 100644 --- a/noncore/net/opietooth/lib/parser.cc +++ b/noncore/net/opietooth/lib/parser.cc @@ -1,196 +1,194 @@ #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 ) { // qWarning("called"); ret = QString::null; int i = 0; int pos = line.findRev("\" ("); if ( pos > 0 ) { // it shouldn't be at pos 0 ret = line.left(pos ).stripWhiteSpace(); // qWarning("ret: %s", ret.latin1() ); ret = ret.replace(QRegExp("[\"]"), ""); //qWarning("ret: %s", ret.latin1() ); QString dummy = line.mid(pos + 5 ); //qWarning("dummy: %s", dummy.latin1() ); dummy = dummy.replace(QRegExp("[)]"), ""); //qWarning("dummy: %s", dummy.latin1() ); // dummy = dummy.remove( dummy.length() -2, 1 ); // remove the ) bool ok; i = dummy.toInt(&ok, 16 ); //if (ok ) { // qWarning("converted %d", i); //}else qWarning("failed" ); //qWarning("exiting"); return i; } //qWarning("output %d", i ); 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,TRUE ); QStringList::Iterator it; for (it = list.begin(); it != list.end(); ++it ) { qWarning("line:%s:line", (*it).latin1() ); if ( (*it).startsWith("Browsing") ) continue; if ( (*it).stripWhiteSpace().isEmpty() ) { // line is empty because a new Service begins qWarning("could add"); // now see if complete and add if (m_complete ) { if (!m_item.serviceName().isEmpty() ) 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) { qWarning("adding"); if (!m_item.serviceName().isEmpty() ) m_list.append(m_item ); } QValueList<Services>::Iterator it2; if (m_list.isEmpty() ) qWarning("m_list is empty"); for (it2 = m_list.begin(); it2 != m_list.end(); ++it2 ) { qWarning("name %s", (*it2).serviceName().latin1() ); } } 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.mid(2).toInt(&m_ok, 16 ); if (m_ok && (value != -1) ) m_complete = true; else m_complete = false; qWarning("rec handle %d", value); m_item.setRecHandle( value ); return true; } 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 + }else if ( m_classOver && str.startsWith(" " ) ){ // ok now are the informations in place - m_classOver = false; // "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 ); + m_item.insertClassId( ids, classes ); return true; }else - m_classOver = true; + m_classOver = false; 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(" ") ) { // "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& 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/services.cc b/noncore/net/opietooth/lib/services.cc index 93ee70a..23b760b 100644 --- a/noncore/net/opietooth/lib/services.cc +++ b/noncore/net/opietooth/lib/services.cc @@ -1,182 +1,180 @@ #include "services.h" using namespace OpieTooth; Services::ProfileDescriptor::ProfileDescriptor(){ } Services::ProfileDescriptor::ProfileDescriptor(const QString &id, int idInt, int 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(int id ){ m_idInt = id; } int Services::ProfileDescriptor::idInt()const{ return m_idInt; } int Services::ProfileDescriptor::version() const{ return m_version; } void Services::ProfileDescriptor::setVersion(int 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, 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& ser){ m_name = ser.m_name; m_recHandle = ser.m_recHandle; - m_classList = ser.m_classList; - m_classId = ser.m_classId; + m_classIds = ser.m_classIds; m_protocols = ser.m_protocols; m_profiles = ser.m_profiles; return *this; } 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() ) ) + ( one.profileDescriptor() == two.profileDescriptor() ) + /* ( one.classIdList() == two.classIdList() ) */ ) 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 handle){ m_recHandle = handle; } -QString Services::classIdList() const{ - return m_classList; +QMap<int, QString> Services::classIdList()const { + return m_classIds; +}; +void Services::insertClassId( int id, const QString& str ) { + m_classIds.insert( id, str ); } -void Services::setClassIdList( const QString& str){ - m_classList = str; +void Services::removeClassId(int id) { + m_classIds.remove( id ); } -int Services::classIdListInt() const{ - return m_classId; -} -void Services::setClassIdList(int id){ - m_classId = id; +void Services::clearClassId() { + m_classIds.clear(); } void Services::insertProtocolDescriptor( const ProtocolDescriptor& prot){ m_protocols.append( prot ); } void Services::clearProtocolDescriptorList(){ m_protocols.clear(); } void Services::removeProtocolDescriptor( const ProtocolDescriptor& prot){ m_protocols.remove( prot ); } Services::ProtocolDescriptor::ValueList Services::protocolDescriptorList()const{ return m_protocols; } void Services::insertProfileDescriptor( const ProfileDescriptor& prof){ m_profiles.append( prof ); } void Services::clearProfileDescriptorList(){ m_profiles.clear(); } 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 881d383..7cce5e1 100644 --- a/noncore/net/opietooth/lib/services.h +++ b/noncore/net/opietooth/lib/services.h @@ -1,143 +1,144 @@ #ifndef OpieToothServices_H #define OpieToothServices_H +#include <qmap.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& ); 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& ); 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 ); + + QMap<int, QString> classIdList()const; + void insertClassId( int id, const QString& className ); + void removeClassId( int id ); + void clearClassId(); 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: + QMap<int, QString> m_classIds; QString m_name; int m_recHandle; - QString m_classList; - int m_classId; QValueList<ProfileDescriptor> m_profiles; QValueList<ProtocolDescriptor> m_protocols; }; }; #endif |