author | korovkin <korovkin> | 2006-03-25 18:10:13 (UTC) |
---|---|---|
committer | korovkin <korovkin> | 2006-03-25 18:10:13 (UTC) |
commit | c4f82599db775f52c7e04cce09c7c45ecc89ccfd (patch) (unidiff) | |
tree | 81d48e5363a2135bb6820510ae7f5dee9999e8f2 /noncore/net/opietooth/manager/rfcommconfhandler.cpp | |
parent | da3c4a6231882bc56266162415a8d1a2a1bf0293 (diff) | |
download | opie-c4f82599db775f52c7e04cce09c7c45ecc89ccfd.zip opie-c4f82599db775f52c7e04cce09c7c45ecc89ccfd.tar.gz opie-c4f82599db775f52c7e04cce09c7c45ecc89ccfd.tar.bz2 |
Added RFCOMM binding table functionality.
Diffstat (limited to 'noncore/net/opietooth/manager/rfcommconfhandler.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/opietooth/manager/rfcommconfhandler.cpp | 92 |
1 files changed, 68 insertions, 24 deletions
diff --git a/noncore/net/opietooth/manager/rfcommconfhandler.cpp b/noncore/net/opietooth/manager/rfcommconfhandler.cpp index f82d2c8..054b446 100644 --- a/noncore/net/opietooth/manager/rfcommconfhandler.cpp +++ b/noncore/net/opietooth/manager/rfcommconfhandler.cpp | |||
@@ -11,12 +11,13 @@ using namespace OpieTooth; | |||
11 | // move to lib | 11 | // move to lib |
12 | 12 | ||
13 | 13 | ||
14 | RfCommConfObject::RfCommConfObject( int number, QString mac, int channel, QString comment ) { | 14 | RfCommConfObject::RfCommConfObject(int number, QString mac, int channel, |
15 | QString comment, bool bind) { | ||
15 | m_number = number; | 16 | m_number = number; |
16 | m_mac = mac; | 17 | m_mac = mac; |
17 | m_channel = channel; | 18 | m_channel = channel; |
18 | m_comment = comment; | 19 | m_comment = comment; |
19 | // m_foundEntries = 0; | 20 | m_doBind = bind; |
20 | } | 21 | } |
21 | 22 | ||
22 | void RfCommConfObject::setNumber( int number ) { | 23 | void RfCommConfObject::setNumber( int number ) { |
@@ -41,7 +42,6 @@ RfCommConfObject::~RfCommConfObject() { | |||
41 | 42 | ||
42 | 43 | ||
43 | RfCommConfHandler::RfCommConfHandler( const QString & filename ) { | 44 | RfCommConfHandler::RfCommConfHandler( const QString & filename ) { |
44 | |||
45 | m_filename = filename; | 45 | m_filename = filename; |
46 | load(); | 46 | load(); |
47 | } | 47 | } |
@@ -52,19 +52,32 @@ RfCommConfHandler::~RfCommConfHandler() { | |||
52 | 52 | ||
53 | void RfCommConfHandler::save( QMap<QString, RfCommConfObject*> devices ) { | 53 | void RfCommConfHandler::save( QMap<QString, RfCommConfObject*> devices ) { |
54 | 54 | ||
55 | QFile rfCommConf( "/tmp/test" ); | 55 | //// For debugging purposes |
56 | //// QFile rfCommConf( "/mnt/net/opie/bin/rfcomm.conf" ); | ||
57 | QFile rfCommConf( m_filename ); | ||
56 | QTextStream outStream( &rfCommConf ); | 58 | QTextStream outStream( &rfCommConf ); |
57 | if ( rfCommConf.open( IO_WriteOnly ) ) { | 59 | if ( rfCommConf.open( IO_WriteOnly ) ) { |
58 | |||
59 | QMap<QString, RfCommConfObject*>::Iterator it; | 60 | QMap<QString, RfCommConfObject*>::Iterator it; |
61 | outStream << "#\n"; | ||
62 | outStream << "# RFCOMM configuration file.\n"; | ||
63 | outStream << "#\n"; | ||
64 | outStream << "# $Id$\n"; | ||
65 | outStream << "#\n\n"; | ||
60 | for( it = devices.begin(); it != devices.end(); ++it ) { | 66 | for( it = devices.begin(); it != devices.end(); ++it ) { |
61 | outStream << "rfcomm" + QString("%1").arg( it.data()->number() ) + " {\n"; | 67 | outStream << "rfcomm" + QString("%1").arg( it.data()->number() ) + " {\n"; |
62 | outStream << " device " + it.data()->mac() + ";\n"; | 68 | outStream << "\t# Automatically bind the device at startup\n"; |
63 | outStream << " channel " + QString( "%1" ).arg( it.data()->channel() ) + ";\n"; | 69 | outStream << "\tbind " << ((it.data()->isBind())? "yes": "no") << ";\n"; |
64 | outStream << " comment \"" + it.data()->comment() + "\";\n"; | 70 | outStream << "\n"; |
71 | outStream << "\t# Bluetooth address of the device\n"; | ||
72 | outStream << "\tdevice " + it.data()->mac() + ";\n"; | ||
73 | outStream << "\n"; | ||
74 | outStream << "\t# RFCOMM channel for the connection\n"; | ||
75 | outStream << "\tchannel\t" + QString( "%1" ).arg( it.data()->channel() ) + ";\n"; | ||
76 | outStream << "\n"; | ||
77 | outStream << "\t# Description of the connection\n"; | ||
78 | outStream << "\tcomment \"" + it.data()->comment() + "\";\n"; | ||
65 | outStream << "}\n\n"; | 79 | outStream << "}\n\n"; |
66 | } | 80 | } |
67 | |||
68 | rfCommConf.close(); | 81 | rfCommConf.close(); |
69 | } | 82 | } |
70 | } | 83 | } |
@@ -75,38 +88,67 @@ QMap<QString, RfCommConfObject*> RfCommConfHandler::foundEntries() { | |||
75 | } | 88 | } |
76 | 89 | ||
77 | void RfCommConfHandler::load() { | 90 | void RfCommConfHandler::load() { |
78 | 91 | //Keywords | |
79 | QFile rfCommConf( m_filename ); | 92 | QCString k_rfcomm("rfcomm"); |
93 | QCString k_device("device "); | ||
94 | QCString k_channel("channel "); | ||
95 | QCString k_comment("comment "); | ||
96 | QCString k_bind("bind "); | ||
97 | |||
98 | m_foundEntries.clear(); | ||
99 | QFile rfCommConf(m_filename); //File we read | ||
80 | if ( rfCommConf.open( IO_ReadOnly ) ) { | 100 | if ( rfCommConf.open( IO_ReadOnly ) ) { |
81 | 101 | ||
82 | QStringList list; | 102 | QStringList list; |
83 | QTextStream inStream( &rfCommConf ); | 103 | QTextStream inStream( &rfCommConf ); |
84 | list = QStringList::split( "\n", inStream.read() ); | 104 | list = QStringList::split( "\n", inStream.read() ); |
85 | 105 | ||
86 | QString number; | ||
87 | QString mac; | 106 | QString mac; |
88 | QString channel; | 107 | QString channel; |
89 | QString comment; | 108 | QString comment; |
109 | QString bind; | ||
110 | bool bbind; | ||
111 | QString number; | ||
90 | 112 | ||
91 | for ( QStringList::Iterator line=list.begin(); line != list.end(); line++ ) { | 113 | for (QStringList::Iterator line = list.begin(); |
114 | line != list.end(); line++) { | ||
92 | 115 | ||
93 | QString tmpLine = ( *line ).stripWhiteSpace(); | 116 | QString tmpLine = (*line).simplifyWhiteSpace(); |
94 | 117 | ||
95 | if ( tmpLine.startsWith("rfcomm") ) { | 118 | if (tmpLine.startsWith(k_rfcomm)) { |
96 | QString number = tmpLine.mid( 6,1 ); | 119 | number = tmpLine.mid( k_rfcomm.length(), 1 ); |
97 | odebug << tmpLine << oendl; | 120 | odebug << tmpLine << oendl; |
98 | odebug << "TEST " + number << oendl; | 121 | odebug << "device " << number << oendl; |
99 | } else if ( tmpLine.startsWith( "}" ) ) { | 122 | } else if ( tmpLine.startsWith( "}" ) ) { |
100 | m_foundEntries.insert( number, new RfCommConfObject( number.toInt(), mac, channel.toInt(), comment ) ); | 123 | m_foundEntries.insert(number, |
101 | } else if ( tmpLine.startsWith( "device" ) ) { | 124 | new RfCommConfObject(number.toInt(), mac, channel.toInt(), |
102 | mac = tmpLine.mid( 7, 17 ); | 125 | comment, bbind)); |
126 | } else if ( tmpLine.startsWith(k_device) ) { | ||
127 | mac = tmpLine.mid(k_device.length(), | ||
128 | tmpLine.find(';') - k_device.length()); | ||
103 | odebug << "mac" + mac << oendl; | 129 | odebug << "mac" + mac << oendl; |
104 | } else if ( tmpLine.startsWith( "channel" ) ) { | 130 | } else if ( tmpLine.startsWith(k_channel) ) { |
105 | channel = tmpLine.mid( 8, 1 ); | 131 | channel = tmpLine.mid(k_channel.length(), |
132 | tmpLine.find(';') - k_channel.length()); | ||
106 | odebug << "Channel :" << channel << oendl; | 133 | odebug << "Channel :" << channel << oendl; |
107 | } else if ( tmpLine.startsWith( "comment" ) ) { | 134 | } else if ( tmpLine.startsWith(k_comment) ) { |
108 | comment = tmpLine.mid( 9, tmpLine.find( ';' ) - 9 - 1 ); | 135 | comment = tmpLine.mid(k_comment.length(), |
136 | tmpLine.find(';') - k_comment.length()); | ||
137 | if (comment.left(1) == "\"") | ||
138 | comment.remove(0, 1); | ||
139 | if (comment.right(1) == "\"") | ||
140 | comment.remove(comment.length() - 1, 1); | ||
109 | odebug << "Comment: " + comment << oendl; | 141 | odebug << "Comment: " + comment << oendl; |
142 | } else if ( tmpLine.startsWith(k_bind) ) { | ||
143 | bind = tmpLine.mid(k_bind.length(), | ||
144 | tmpLine.find(';') - k_bind.length()); | ||
145 | if (bind == "no") | ||
146 | bbind = false; | ||
147 | else if (bind == "yes") | ||
148 | bbind = true; | ||
149 | else | ||
150 | bbind = true; | ||
151 | odebug << "bind: " + bind << oendl; | ||
110 | } | 152 | } |
111 | } | 153 | } |
112 | rfCommConf.close(); | 154 | rfCommConf.close(); |
@@ -114,3 +156,5 @@ void RfCommConfHandler::load() { | |||
114 | save( m_foundEntries ); | 156 | save( m_foundEntries ); |
115 | odebug << QString( "ENTries: %1").arg( m_foundEntries.count() ) << oendl; | 157 | odebug << QString( "ENTries: %1").arg( m_foundEntries.count() ) << oendl; |
116 | } | 158 | } |
159 | |||
160 | //eof | ||