author | mickeyl <mickeyl> | 2004-02-24 22:56:24 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-02-24 22:56:24 (UTC) |
commit | 96ba6fcf27c785282c3fe05557df8b384df06852 (patch) (unidiff) | |
tree | 9b25648f8518c8d152d4774ac05f81548828f3d5 /libopie2 | |
parent | a1a6a1013eae9a4ca4607f2d656c98821a30f431 (diff) | |
download | opie-96ba6fcf27c785282c3fe05557df8b384df06852.zip opie-96ba6fcf27c785282c3fe05557df8b384df06852.tar.gz opie-96ba6fcf27c785282c3fe05557df8b384df06852.tar.bz2 |
API extension: ONetwork::isPresent( const char* name )
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 23 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.h | 4 |
2 files changed, 21 insertions, 6 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index 915814d..e5b091f 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp | |||
@@ -131,32 +131,43 @@ ONetworkInterface* ONetwork::interface( const QString& iface ) const | |||
131 | } | 131 | } |
132 | 132 | ||
133 | 133 | ||
134 | ONetwork* ONetwork::instance() | 134 | ONetwork* ONetwork::instance() |
135 | { | 135 | { |
136 | if ( !_instance ) _instance = new ONetwork(); | 136 | if ( !_instance ) _instance = new ONetwork(); |
137 | return _instance; | 137 | return _instance; |
138 | } | 138 | } |
139 | 139 | ||
140 | 140 | ||
141 | ONetwork::InterfaceIterator ONetwork::iterator() const | 141 | ONetwork::InterfaceIterator ONetwork::iterator() const |
142 | { | 142 | { |
143 | return ONetwork::InterfaceIterator( _interfaces ); | 143 | return ONetwork::InterfaceIterator( _interfaces ); |
144 | } | 144 | } |
145 | 145 | ||
146 | 146 | ||
147 | bool ONetwork::isPresent( const char* name ) const | ||
148 | { | ||
149 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); | ||
150 | struct ifreq ifr; | ||
151 | memset( &ifr, 0, sizeof( struct ifreq ) ); | ||
152 | strcpy( (char*) &ifr.ifr_name, name ); | ||
153 | int result = ::ioctl( sfd, SIOCGIFFLAGS, &ifr ); | ||
154 | return result != -1; | ||
155 | } | ||
156 | |||
157 | |||
147 | bool ONetwork::isWirelessInterface( const char* name ) const | 158 | bool ONetwork::isWirelessInterface( const char* name ) const |
148 | { | 159 | { |
149 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); | 160 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); |
150 | struct iwreq iwr; | 161 | struct iwreq iwr; |
151 | memset( &iwr, 0, sizeof( struct iwreq ) ); | 162 | memset( &iwr, 0, sizeof( struct iwreq ) ); |
152 | strcpy( (char*) &iwr.ifr_name, name ); | 163 | strcpy( (char*) &iwr.ifr_name, name ); |
153 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); | 164 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); |
154 | return result != -1; | 165 | return result != -1; |
155 | } | 166 | } |
156 | 167 | ||
157 | /*====================================================================================== | 168 | /*====================================================================================== |
158 | * ONetworkInterface | 169 | * ONetworkInterface |
159 | *======================================================================================*/ | 170 | *======================================================================================*/ |
160 | 171 | ||
161 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) | 172 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) |
162 | :QObject( parent, name ), | 173 | :QObject( parent, name ), |
@@ -569,37 +580,37 @@ void OWirelessNetworkInterface::buildPrivateList() | |||
569 | owarn << "OWirelessNetworkInterface::buildPrivateList(): Can't get private ioctl information." << oendl; | 580 | owarn << "OWirelessNetworkInterface::buildPrivateList(): Can't get private ioctl information." << oendl; |
570 | return; | 581 | return; |
571 | } | 582 | } |
572 | 583 | ||
573 | for ( int i = 0; i < _iwr.u.data.length; ++i ) | 584 | for ( int i = 0; i < _iwr.u.data.length; ++i ) |
574 | { | 585 | { |
575 | new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); | 586 | new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); |
576 | } | 587 | } |
577 | odebug << "OWirelessNetworkInterface::buildPrivateList(): Private ioctl list constructed." << oendl; | 588 | odebug << "OWirelessNetworkInterface::buildPrivateList(): Private ioctl list constructed." << oendl; |
578 | } | 589 | } |
579 | 590 | ||
580 | 591 | ||
581 | void OWirelessNetworkInterface::dumpInformation() const | 592 | void OWirelessNetworkInterface::dumpInformation() const |
582 | { | 593 | { |
583 | odebug << "OWirelessNetworkInterface::() -------------- dumping information block ----------------" << oendl; | 594 | odebug << "OWirelessNetworkInterface::() -------------- dumping information block ----------------" << oendl; |
584 | 595 | ||
585 | qDebug( " - driver's idea of maximum throughput is %d bps = %d byte/s = %d Kb/s = %f.2 Mb/s", | 596 | qDebug( " - driver's idea of maximum throughput is %d bps = %d byte/s = %d Kb/s = %f.2 Mb/s", |
586 | _range.throughput, _range.throughput / 8, _range.throughput / 8 / 1024, float( _range.throughput ) / 8.0 / 1024.0 / 1024.0 ); | 597 | _range.throughput, _range.throughput / 8, _range.throughput / 8 / 1024, float( _range.throughput ) / 8.0 / 1024.0 / 1024.0 ); |
587 | qDebug( " - driver for '%s' (V%d) has been compiled against WE V%d", | 598 | qDebug( " - driver for '%s' (V%d) has been compiled against WE V%d", |
588 | name(), _range.we_version_source, _range.we_version_compiled ); | 599 | name(), _range.we_version_source, _range.we_version_compiled ); |
589 | 600 | ||
590 | if ( _range.we_version_compiled != WIRELESS_EXT ) | 601 | if ( _range.we_version_compiled != WIRELESS_EXT ) |
591 | { | 602 | { |
592 | owarn << "Version mismatch! WE_DRIVER = " << _range.we_version_compiled << " and WE_OPIENET = " << WIRELESS_EXT << oendl; | 603 | owarn << "Version mismatch! WE_DRIVER = " << _range.we_version_compiled << " and WE_OPIENET = " << WIRELESS_EXT << oendl; |
593 | } | 604 | } |
594 | 605 | ||
595 | odebug << "OWirelessNetworkInterface::() ---------------------------------------------------------" << oendl; | 606 | odebug << "OWirelessNetworkInterface::() ---------------------------------------------------------" << oendl; |
596 | } | 607 | } |
597 | 608 | ||
598 | 609 | ||
599 | int OWirelessNetworkInterface::channel() const | 610 | int OWirelessNetworkInterface::channel() const |
600 | { | 611 | { |
601 | //FIXME: When monitoring enabled, then use it | 612 | //FIXME: When monitoring enabled, then use it |
602 | //FIXME: to gather the current RF channel | 613 | //FIXME: to gather the current RF channel |
603 | //FIXME: Until then, get active channel from hopper. | 614 | //FIXME: Until then, get active channel from hopper. |
604 | if ( _hopper && _hopper->isActive() ) | 615 | if ( _hopper && _hopper->isActive() ) |
605 | return _hopper->channel(); | 616 | return _hopper->channel(); |
@@ -959,49 +970,49 @@ OStationList* OWirelessNetworkInterface::scanNetwork() | |||
959 | we = (struct iw_event*) &buffer[offset]; | 970 | we = (struct iw_event*) &buffer[offset]; |
960 | } | 971 | } |
961 | return stations; | 972 | return stations; |
962 | 973 | ||
963 | return stations; | 974 | return stations; |
964 | 975 | ||
965 | } | 976 | } |
966 | else | 977 | else |
967 | { | 978 | { |
968 | odebug << " - no results (timeout) :(" << oendl; | 979 | odebug << " - no results (timeout) :(" << oendl; |
969 | return stations; | 980 | return stations; |
970 | } | 981 | } |
971 | } | 982 | } |
972 | 983 | ||
973 | 984 | ||
974 | int OWirelessNetworkInterface::signalStrength() const | 985 | int OWirelessNetworkInterface::signalStrength() const |
975 | { | 986 | { |
976 | iw_statistics stat; | 987 | iw_statistics stat; |
977 | ::memset( &stat, 0, sizeof stat ); | 988 | ::memset( &stat, 0, sizeof stat ); |
978 | _iwr.u.data.pointer = (char*) &stat; | 989 | _iwr.u.data.pointer = (char*) &stat; |
979 | _iwr.u.data.flags = 0; | 990 | _iwr.u.data.flags = 0; |
980 | _iwr.u.data.length = sizeof stat; | 991 | _iwr.u.data.length = sizeof stat; |
981 | 992 | ||
982 | if ( !wioctl( SIOCGIWSTATS ) ) | 993 | if ( !wioctl( SIOCGIWSTATS ) ) |
983 | { | 994 | { |
984 | return -1; | 995 | return -1; |
985 | } | 996 | } |
986 | 997 | ||
987 | int max = _range.max_qual.qual; | 998 | int max = _range.max_qual.qual; |
988 | int cur = stat.qual.qual; | 999 | int cur = stat.qual.qual; |
989 | int lev = stat.qual.level; //FIXME: Do something with them? | 1000 | int lev = stat.qual.level; //FIXME: Do something with them? |
990 | int noi = stat.qual.noise; //FIXME: Do something with them? | 1001 | int noi = stat.qual.noise; //FIXME: Do something with them? |
991 | 1002 | ||
992 | return cur*100/max; | 1003 | return cur*100/max; |
993 | } | 1004 | } |
994 | 1005 | ||
995 | 1006 | ||
996 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const | 1007 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const |
997 | { | 1008 | { |
998 | #ifndef NODEBUG | 1009 | #ifndef NODEBUG |
999 | int result = ::ioctl( _sfd, call, &iwreq ); | 1010 | int result = ::ioctl( _sfd, call, &iwreq ); |
1000 | 1011 | ||
1001 | if ( result == -1 ) | 1012 | if ( result == -1 ) |
1002 | odebug << "ONetworkInterface::wioctl (" << name() << ") call '" | 1013 | odebug << "ONetworkInterface::wioctl (" << name() << ") call '" |
1003 | << debugmapper->map( call ) << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl; | 1014 | << debugmapper->map( call ) << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl; |
1004 | else | 1015 | else |
1005 | odebug << "ONetworkInterface::wioctl (" << name() << ") call '" | 1016 | odebug << "ONetworkInterface::wioctl (" << name() << ") call '" |
1006 | << debugmapper->map( call ) << "' - Status: Ok." << oendl; | 1017 | << debugmapper->map( call ) << "' - Status: Ok." << oendl; |
1007 | 1018 | ||
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h index 0a51108..93b129f 100644 --- a/libopie2/opienet/onetwork.h +++ b/libopie2/opienet/onetwork.h | |||
@@ -81,32 +81,36 @@ class ONetwork : public QObject | |||
81 | typedef QDictIterator<ONetworkInterface> InterfaceIterator; | 81 | typedef QDictIterator<ONetworkInterface> InterfaceIterator; |
82 | 82 | ||
83 | public: | 83 | public: |
84 | /** | 84 | /** |
85 | * @returns the number of available interfaces | 85 | * @returns the number of available interfaces |
86 | */ | 86 | */ |
87 | int count() const; | 87 | int count() const; |
88 | /** | 88 | /** |
89 | * @returns a pointer to the (one and only) @ref ONetwork instance. | 89 | * @returns a pointer to the (one and only) @ref ONetwork instance. |
90 | */ | 90 | */ |
91 | static ONetwork* instance(); | 91 | static ONetwork* instance(); |
92 | /** | 92 | /** |
93 | * @returns an iterator usable for iterating through all network interfaces. | 93 | * @returns an iterator usable for iterating through all network interfaces. |
94 | */ | 94 | */ |
95 | InterfaceIterator iterator() const; | 95 | InterfaceIterator iterator() const; |
96 | /** | 96 | /** |
97 | * @returns true, if the @a interface is present. | ||
98 | */ | ||
99 | bool isPresent( const char* interface ) const; | ||
100 | /** | ||
97 | * @returns true, if the @a interface supports the wireless extension protocol. | 101 | * @returns true, if the @a interface supports the wireless extension protocol. |
98 | */ | 102 | */ |
99 | bool isWirelessInterface( const char* interface ) const; | 103 | bool isWirelessInterface( const char* interface ) const; |
100 | /** | 104 | /** |
101 | * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found. | 105 | * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found. |
102 | * @see ONetworkInterface | 106 | * @see ONetworkInterface |
103 | */ | 107 | */ |
104 | ONetworkInterface* interface( const QString& interface ) const; | 108 | ONetworkInterface* interface( const QString& interface ) const; |
105 | /** | 109 | /** |
106 | * @internal Rebuild the internal interface database | 110 | * @internal Rebuild the internal interface database |
107 | * @note Sometimes it might be useful to call this from client code, | 111 | * @note Sometimes it might be useful to call this from client code, |
108 | * e.g. after issuing a cardctl insert | 112 | * e.g. after issuing a cardctl insert |
109 | */ | 113 | */ |
110 | void synchronize(); | 114 | void synchronize(); |
111 | /** | 115 | /** |
112 | * @returns the wireless extension version used at compile time. | 116 | * @returns the wireless extension version used at compile time. |