Qt 4.8
Public Functions | Protected Functions | Private Slots | Private Functions | Properties | Friends | List of all members
QCoreWlanEngine Class Reference

#include <qcorewlanengine.h>

Inheritance diagram for QCoreWlanEngine:
QBearerEngineImpl QBearerEngine QObject

Public Functions

quint64 bytesReceived (const QString &id)
 
quint64 bytesWritten (const QString &id)
 
QNetworkConfigurationManager::Capabilities capabilities () const
 
void connectToId (const QString &id)
 
QNetworkSessionPrivatecreateSessionBackend ()
 
QNetworkConfigurationPrivatePointer defaultConfiguration ()
 
void disconnectFromId (const QString &id)
 
QString getInterfaceFromId (const QString &id)
 
bool hasIdentifier (const QString &id)
 
Q_INVOKABLE void initialize ()
 
 QCoreWlanEngine (QObject *parent=0)
 
Q_INVOKABLE void requestUpdate ()
 
bool requiresPolling () const
 
QNetworkSession::State sessionStateForId (const QString &id)
 
quint64 startTime (const QString &id)
 
 ~QCoreWlanEngine ()
 
- Public Functions inherited from QBearerEngineImpl
 QBearerEngineImpl (QObject *parent=0)
 
 ~QBearerEngineImpl ()
 
- Public Functions inherited from QBearerEngine
bool configurationsInUse () const
 
 QBearerEngine (QObject *parent=0)
 
virtual ~QBearerEngine ()
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Protected Functions

void startNetworkChangeLoop ()
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 

Private Slots

void doRequestUpdate ()
 
void networksChanged ()
 

Private Functions

quint64 getBytes (const QString &interfaceName, bool b)
 
bool isWifiReady (const QString &dev)
 

Properties

QList< QNetworkConfigurationPrivate * > foundConfigurations
 
bool hasWifi
 
CFRunLoopSourceRef runloopSource
 
bool scanning
 
QScanThreadscanThread
 
SCDynamicStoreRef storeSession
 

Friends

class QScanThread
 

Additional Inherited Members

- Public Types inherited from QBearerEngineImpl
enum  ConnectionError { InterfaceLookupError = 0, ConnectError, OperationNotSupported, DisconnectionError }
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QBearerEngineImpl
void connectionError (const QString &id, QBearerEngineImpl::ConnectionError error)
 
- Signals inherited from QBearerEngine
void configurationAdded (QNetworkConfigurationPrivatePointer config)
 
void configurationChanged (QNetworkConfigurationPrivatePointer config)
 
void configurationRemoved (QNetworkConfigurationPrivatePointer config)
 
void updateCompleted ()
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Variables inherited from QBearerEngine
QHash< QString, QNetworkConfigurationPrivatePointeraccessPointConfigurations
 
QMutex mutex
 
QHash< QString, QNetworkConfigurationPrivatePointersnapConfigurations
 
QHash< QString, QNetworkConfigurationPrivatePointeruserChoiceConfigurations
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 59 of file qcorewlanengine.h.

Constructors and Destructors

◆ QCoreWlanEngine()

QCoreWlanEngine::QCoreWlanEngine ( QObject parent = 0)

Definition at line 397 of file qcorewlanengine_10_6.mm.

398 : QBearerEngineImpl(parent), scanThread(0)
399 {
400  scanThread = new QScanThread(this);
402  this, SLOT(networksChanged()));
403 }
QBearerEngineImpl(QObject *parent=0)
#define SLOT(a)
Definition: qobjectdefs.h:226
QScanThread * scanThread
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
friend class QScanThread

◆ ~QCoreWlanEngine()

QCoreWlanEngine::~QCoreWlanEngine ( )

Definition at line 405 of file qcorewlanengine_10_6.mm.

406 {
407  while (!foundConfigurations.isEmpty())
409  [listener remove];
410  [listener release];
411 }
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
T takeFirst()
Removes the first item in the list and returns it.
Definition: qlist.h:489
static QNSListener * listener
QList< QNetworkConfigurationPrivate * > foundConfigurations

Functions

◆ bytesReceived()

quint64 QCoreWlanEngine::bytesReceived ( const QString id)
virtual

Reimplemented from QBearerEngineImpl.

Definition at line 833 of file qcorewlanengine_10_6.mm.

834 {
835  QMutexLocker locker(&mutex);
836  const QString interfaceStr = getInterfaceFromId(id);
837  return getBytes(interfaceStr,true);
838 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString getInterfaceFromId(const QString &id)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
quint64 getBytes(const QString &interfaceName, bool b)

◆ bytesWritten()

quint64 QCoreWlanEngine::bytesWritten ( const QString id)
virtual

Reimplemented from QBearerEngineImpl.

Definition at line 826 of file qcorewlanengine_10_6.mm.

827 {
828  QMutexLocker locker(&mutex);
829  const QString interfaceStr = getInterfaceFromId(id);
830  return getBytes(interfaceStr,false);
831 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString getInterfaceFromId(const QString &id)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
quint64 getBytes(const QString &interfaceName, bool b)

◆ capabilities()

QNetworkConfigurationManager::Capabilities QCoreWlanEngine::capabilities ( ) const
virtual

◆ connectToId()

void QCoreWlanEngine::connectToId ( const QString id)
virtual

Implements QBearerEngineImpl.

Definition at line 446 of file qcorewlanengine_10_6.mm.

447 {
448  QMutexLocker locker(&mutex);
449  NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
450  QString interfaceString = getInterfaceFromId(id);
451 
452  CWInterface *wifiInterface =
453  [CWInterface interfaceWithName: (NSString *)QCFString::toCFStringRef(interfaceString)];
454 
455  if ([wifiInterface power]) {
456  NSError *err = nil;
457  NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
458 
459  QString wantedSsid;
460 
462 
463  const QString idHash = QString::number(qHash(QLatin1String("corewlan:") + ptr->name));
464  const QString idHash2 = QString::number(qHash(QLatin1String("corewlan:") + scanThread->getNetworkNameFromSsid(ptr->name)));
465 
466  bool using8021X = false;
467  if (idHash2 != id) {
468  NSArray *array = [CW8021XProfile allUser8021XProfiles];
469 
470  for (NSUInteger i = 0; i < [array count]; ++i) {
471  const QString networkNameHashCheck = QString::number(qHash(QLatin1String("corewlan:") + QCFString::toQString(CFStringRef([[array objectAtIndex:i] userDefinedName]))));
472 
473  const QString ssidHash = QString::number(qHash(QLatin1String("corewlan:") + QCFString::toQString(CFStringRef([[array objectAtIndex:i] ssid]))));
474 
475  if (id == networkNameHashCheck || id == ssidHash) {
476  const QString thisName = scanThread->getSsidFromNetworkName(id);
477  if (thisName.isEmpty())
478  wantedSsid = id;
479  else
480  wantedSsid = thisName;
481 
482  [params setValue: [array objectAtIndex:i] forKey:kCWAssocKey8021XProfile];
483  using8021X = true;
484  break;
485  }
486  }
487  }
488 
489  if (!using8021X) {
490  QString wantedNetwork;
491  QMapIterator<QString, QMap<QString,QString> > i(scanThread->userProfiles);
492  while (i.hasNext()) {
493  i.next();
494  wantedNetwork = i.key();
495  const QString networkNameHash = QString::number(qHash(QLatin1String("corewlan:") + wantedNetwork));
496  if (id == networkNameHash) {
497  wantedSsid = scanThread->getSsidFromNetworkName(wantedNetwork);
498  break;
499  }
500  }
501  }
502  NSDictionary *scanParameters = [NSDictionary dictionaryWithObjectsAndKeys:
503  [NSNumber numberWithBool:YES], kCWScanKeyMerge,
504  [NSNumber numberWithInt:kCWScanTypeFast], kCWScanKeyScanType,
505  [NSNumber numberWithInteger:100], kCWScanKeyRestTime,
506  (NSString *)QCFString::toCFStringRef(wantedSsid), kCWScanKeySSID,
507  nil];
508 
509  NSArray *scanArray = [wifiInterface scanForNetworksWithParameters:scanParameters error:&err];
510 
511  if(!err) {
512  for(uint row=0; row < [scanArray count]; row++ ) {
513  CWNetwork *apNetwork = [scanArray objectAtIndex:row];
514 
515  if(wantedSsid == QCFString::toQString(CFStringRef([apNetwork ssid]))) {
516 
517  if(!using8021X) {
518  SecKeychainAttribute attributes[3];
519 
520  NSString *account = [apNetwork ssid];
521  NSString *keyKind = @"AirPort network password";
522  NSString *keyName = account;
523 
524  attributes[0].tag = kSecAccountItemAttr;
525  attributes[0].data = (void *)[account UTF8String];
526  attributes[0].length = [account length];
527 
528  attributes[1].tag = kSecDescriptionItemAttr;
529  attributes[1].data = (void *)[keyKind UTF8String];
530  attributes[1].length = [keyKind length];
531 
532  attributes[2].tag = kSecLabelItemAttr;
533  attributes[2].data = (void *)[keyName UTF8String];
534  attributes[2].length = [keyName length];
535 
536  SecKeychainAttributeList attributeList = {3,attributes};
537 
538  SecKeychainSearchRef searchRef;
539  SecKeychainSearchCreateFromAttributes(NULL, kSecGenericPasswordItemClass, &attributeList, &searchRef);
540 
541  NSString *password = @"";
542  SecKeychainItemRef searchItem;
543 
544  if (SecKeychainSearchCopyNext(searchRef, &searchItem) == noErr) {
545  UInt32 realPasswordLength;
546  SecKeychainAttribute attributesW[8];
547  attributesW[0].tag = kSecAccountItemAttr;
548  SecKeychainAttributeList listW = {1,attributesW};
549  char *realPassword;
550  OSStatus status = SecKeychainItemCopyContent(searchItem, NULL, &listW, &realPasswordLength,(void **)&realPassword);
551 
552  if (status == noErr) {
553  if (realPassword != NULL) {
554 
555  QByteArray pBuf;
556  pBuf.resize(realPasswordLength);
557  pBuf.prepend(realPassword);
558  pBuf.insert(realPasswordLength,'\0');
559 
560  password = [NSString stringWithUTF8String:pBuf];
561  }
562  SecKeychainItemFreeContent(&listW, realPassword);
563  }
564 
565  CFRelease(searchItem);
566  } else {
567  qDebug() << "SecKeychainSearchCopyNext error";
568  }
569  [params setValue: password forKey: kCWAssocKeyPassphrase];
570  } // end using8021X
571 
572 
573  bool result = [wifiInterface associateToNetwork: apNetwork parameters:[NSDictionary dictionaryWithDictionary:params] error:&err];
574 
575  if(!err) {
576  if(!result) {
578  } else {
579  return;
580  }
581  } else {
582  qDebug() <<"associate ERROR"<< QCFString::toQString(CFStringRef([err localizedDescription ]));
583  }
584  }
585  } //end scan network
586  } else {
587  qDebug() <<"scan ERROR"<< QCFString::toQString(CFStringRef([err localizedDescription ]));
588  }
590  }
591 
592  locker.unlock();
594  [autoreleasepool release];
595 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
uint qHash(const QProcEnvKey &key)
Definition: qprocess_p.h:96
const struct __CFString * CFStringRef
static QString keyName(const QString &rKey)
#define error(msg)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static CFStringRef toCFStringRef(const QString &str)
Definition: qcore_mac.cpp:69
QScanThread * scanThread
static QString toQString(CFStringRef cfstr)
Definition: qcore_mac.cpp:47
static LibLoadStatus status
Definition: qlocale_icu.cpp:69
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QString getSsidFromNetworkName(const QString &name)
QByteArray & prepend(char c)
Prepends the character ch to this byte array.
The QString class provides a Unicode character string.
Definition: qstring.h:83
QChar * data()
Returns a pointer to the data stored in the QString.
Definition: qstring.h:710
Q_CORE_EXPORT void qDebug(const char *,...)
QHash< QString, QNetworkConfigurationPrivatePointer > accessPointConfigurations
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QMap< QString, QMap< QString, QString > > userProfiles
static bool init
#define emit
Definition: qobjectdefs.h:76
unsigned int uint
Definition: qglobal.h:996
const T * ptr(const T &t)
signed long OSStatus
QString getInterfaceFromId(const QString &id)
QString getNetworkNameFromSsid(const QString &ssid)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
void resize(int size)
Sets the size of the byte array to size bytes.
void connectionError(const QString &id, QBearerEngineImpl::ConnectionError error)
QByteArray & insert(int i, char c)
Inserts character ch at index position i in the byte array.

◆ createSessionBackend()

QNetworkSessionPrivate * QCoreWlanEngine::createSessionBackend ( )
virtual

Implements QBearerEngine.

Definition at line 738 of file qcorewlanengine_10_6.mm.

◆ defaultConfiguration()

QNetworkConfigurationPrivatePointer QCoreWlanEngine::defaultConfiguration ( )
virtual

Implements QBearerEngine.

Definition at line 743 of file qcorewlanengine_10_6.mm.

744 {
746 }
QExplicitlySharedDataPointer< QNetworkConfigurationPrivate > QNetworkConfigurationPrivatePointer

◆ disconnectFromId()

void QCoreWlanEngine::disconnectFromId ( const QString id)
virtual

Implements QBearerEngineImpl.

Definition at line 597 of file qcorewlanengine_10_6.mm.

598 {
599  QMutexLocker locker(&mutex);
600 
601  QString interfaceString = getInterfaceFromId(id);
602  NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
603 
604  CWInterface *wifiInterface =
605  [CWInterface interfaceWithName: (NSString *)QCFString::toCFStringRef(interfaceString)];
606 
607  [wifiInterface disassociate];
608  if ([[wifiInterface interfaceState]intValue] != kCWInterfaceStateInactive) {
609  locker.unlock();
611  locker.relock();
612  }
613  [autoreleasepool release];
614 }
static CFStringRef toCFStringRef(const QString &str)
Definition: qcore_mac.cpp:69
The QString class provides a Unicode character string.
Definition: qstring.h:83
static bool init
#define emit
Definition: qobjectdefs.h:76
QString getInterfaceFromId(const QString &id)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
void connectionError(const QString &id, QBearerEngineImpl::ConnectionError error)

◆ doRequestUpdate

void QCoreWlanEngine::doRequestUpdate ( )
privateslot

Definition at line 622 of file qcorewlanengine_10_6.mm.

Referenced by requestUpdate().

623 {
624  QMutexLocker locker(&mutex);
625 
626  NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
627 
628  NSArray *wifiInterfaces = [CWInterface supportedInterfaces];
629  for (uint row = 0; row < [wifiInterfaces count]; ++row) {
630  scanThread->interfaceName = QCFString::toQString(CFStringRef([wifiInterfaces objectAtIndex:row]));
631  scanThread->start();
632  }
633  locker.unlock();
634  if ([wifiInterfaces count] == 0)
635  networksChanged();
636  [autoreleasepool release];
637 }
const struct __CFString * CFStringRef
QScanThread * scanThread
static QString toQString(CFStringRef cfstr)
Definition: qcore_mac.cpp:47
static bool init
unsigned int uint
Definition: qglobal.h:996
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
void start(Priority=InheritPriority)
Begins execution of the thread by calling run().
QString interfaceName

◆ getBytes()

quint64 QCoreWlanEngine::getBytes ( const QString interfaceName,
bool  b 
)
private

Definition at line 894 of file qcorewlanengine_10_6.mm.

Referenced by bytesReceived(), and bytesWritten().

895 {
896  struct ifaddrs *ifAddressList, *ifAddress;
897  struct if_data *if_data;
898 
899  quint64 bytes = 0;
900  ifAddressList = nil;
901  if(getifaddrs(&ifAddressList) == 0) {
902  for(ifAddress = ifAddressList; ifAddress; ifAddress = ifAddress->ifa_next) {
903  if(interfaceName == ifAddress->ifa_name) {
904  if_data = (struct if_data*)ifAddress->ifa_data;
905  if(b) {
906  bytes = if_data->ifi_ibytes;
907  break;
908  } else {
909  bytes = if_data->ifi_obytes;
910  break;
911  }
912  }
913  }
914  freeifaddrs(ifAddressList);
915  }
916  return bytes;
917 }
unsigned __int64 quint64
Definition: qglobal.h:943

◆ getInterfaceFromId()

QString QCoreWlanEngine::getInterfaceFromId ( const QString id)
virtual

Implements QBearerEngineImpl.

Definition at line 432 of file qcorewlanengine_10_6.mm.

Referenced by bytesReceived(), bytesWritten(), connectToId(), and disconnectFromId().

433 {
434  QMutexLocker locker(&mutex);
435 
437 }
QScanThread * scanThread
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
QMap< QString, QString > configurationInterface
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ hasIdentifier()

bool QCoreWlanEngine::hasIdentifier ( const QString id)
virtual

Implements QBearerEngine.

Definition at line 439 of file qcorewlanengine_10_6.mm.

440 {
441  QMutexLocker locker(&mutex);
442 
444 }
QScanThread * scanThread
QMap< QString, QString > configurationInterface
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
bool contains(const Key &key) const
Returns true if the map contains an item with key key; otherwise returns false.
Definition: qmap.h:553

◆ initialize()

void QCoreWlanEngine::initialize ( )

Definition at line 413 of file qcorewlanengine_10_6.mm.

414 {
415  QMutexLocker locker(&mutex);
416  NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
417 
418  if([[CWInterface supportedInterfaces] count] > 0 && !listener) {
420  listener.engine = this;
421  hasWifi = true;
422  } else {
423  hasWifi = false;
424  }
425  storeSession = NULL;
426 
428  [autoreleasepool release];
429 }
static bool init
SCDynamicStoreRef storeSession
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
#define QT_MANGLE_NAMESPACE(name)
Definition: qglobal.h:106
static QNSListener * listener
QCoreWlanEngine * engine

◆ isWifiReady()

bool QCoreWlanEngine::isWifiReady ( const QString dev)
private

Definition at line 639 of file qcorewlanengine_10_6.mm.

640 {
641  QMutexLocker locker(&mutex);
642  bool haswifi = false;
643  if(hasWifi) {
644  NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
645  CWInterface *defaultInterface = [CWInterface interfaceWithName: (NSString *)QCFString::toCFStringRef(wifiDeviceName)];
646  if([defaultInterface power]) {
647  haswifi = true;
648  }
649  [autoreleasepool release];
650  }
651  return haswifi;
652 }
static CFStringRef toCFStringRef(const QString &str)
Definition: qcore_mac.cpp:69
static bool init
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ networksChanged

void QCoreWlanEngine::networksChanged ( )
privateslot

Definition at line 753 of file qcorewlanengine_10_6.mm.

Referenced by doRequestUpdate(), and QCoreWlanEngine().

754 {
755  QMutexLocker locker(&mutex);
756 
757  QStringList previous = accessPointConfigurations.keys();
758 
760  while (!foundConfigurations.isEmpty()) {
761  QNetworkConfigurationPrivate *cpPriv = foundConfigurations.takeFirst();
762 
763  previous.removeAll(cpPriv->id);
764 
765  if (accessPointConfigurations.contains(cpPriv->id)) {
767 
768  bool changed = false;
769 
770  ptr->mutex.lock();
771 
772  if (ptr->isValid != cpPriv->isValid) {
773  ptr->isValid = cpPriv->isValid;
774  changed = true;
775  }
776 
777  if (ptr->name != cpPriv->name) {
778  ptr->name = cpPriv->name;
779  changed = true;
780  }
781 
782  if (ptr->bearerType != cpPriv->bearerType) {
783  ptr->bearerType = cpPriv->bearerType;
784  changed = true;
785  }
786 
787  if (ptr->state != cpPriv->state) {
788  ptr->state = cpPriv->state;
789  changed = true;
790  }
791 
792  ptr->mutex.unlock();
793 
794  if (changed) {
795  locker.unlock();
797  locker.relock();
798  }
799 
800  delete cpPriv;
801  } else {
803 
804  accessPointConfigurations.insert(ptr->id, ptr);
805 
806  locker.unlock();
808  locker.relock();
809  }
810  }
811 
812  while (!previous.isEmpty()) {
814  accessPointConfigurations.take(previous.takeFirst());
815 
816  locker.unlock();
818  locker.relock();
819  }
820 
821  locker.unlock();
823 
824 }
void lock()
Locks the mutex.
Definition: qmutex.cpp:151
QList< QNetworkConfigurationPrivate * > getConfigurations()
QNetworkConfiguration::StateFlags state
void configurationChanged(QNetworkConfigurationPrivatePointer config)
void updateCompleted()
QScanThread * scanThread
QNetworkConfiguration::BearerType bearerType
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QHash< QString, QNetworkConfigurationPrivatePointer > accessPointConfigurations
T takeFirst()
Removes the first item in the list and returns it.
Definition: qlist.h:489
#define emit
Definition: qobjectdefs.h:76
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
void configurationAdded(QNetworkConfigurationPrivatePointer config)
const T * ptr(const T &t)
void unlock()
Unlocks the mutex.
Definition: qmutex.cpp:296
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
void configurationRemoved(QNetworkConfigurationPrivatePointer config)
QList< QNetworkConfigurationPrivate * > foundConfigurations
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.
Definition: qlist.h:770

◆ requestUpdate()

void QCoreWlanEngine::requestUpdate ( )

Definition at line 616 of file qcorewlanengine_10_6.mm.

Referenced by networkChangeCallback().

617 {
619  doRequestUpdate();
620 }
QScanThread * scanThread

◆ requiresPolling()

bool QCoreWlanEngine::requiresPolling ( ) const
virtual

Reimplemented from QBearerEngine.

Definition at line 748 of file qcorewlanengine_10_6.mm.

749 {
750  return true;
751 }

◆ sessionStateForId()

QNetworkSession::State QCoreWlanEngine::sessionStateForId ( const QString id)
virtual

Implements QBearerEngineImpl.

Definition at line 655 of file qcorewlanengine_10_6.mm.

656 {
657  QMutexLocker locker(&mutex);
659 
660  if (!ptr)
662 
663  if (!ptr->isValid) {
667  } else if ((ptr->state & QNetworkConfiguration::Discovered) ==
672  } else if ((ptr->state & QNetworkConfiguration::Undefined) ==
675  }
676 
678 }
QNetworkConfiguration::StateFlags state
QHash< QString, QNetworkConfigurationPrivatePointer > accessPointConfigurations
const T * ptr(const T &t)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ startNetworkChangeLoop()

void QCoreWlanEngine::startNetworkChangeLoop ( )
protected

Definition at line 685 of file qcorewlanengine_10_6.mm.

Referenced by initialize().

686 {
687 
688  SCDynamicStoreContext dynStoreContext = { 0, this/*(void *)storeSession*/, NULL, NULL, NULL };
689  storeSession = SCDynamicStoreCreate(NULL,
690  CFSTR("networkChangeCallback"),
692  &dynStoreContext);
693  if (!storeSession ) {
694  qWarning() << "could not open dynamic store: error:" << SCErrorString(SCError());
695  return;
696  }
697 
698  CFMutableArrayRef notificationKeys;
699  notificationKeys = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
700  CFMutableArrayRef patternsArray;
701  patternsArray = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
702 
703  CFStringRef storeKey;
704  storeKey = SCDynamicStoreKeyCreateNetworkGlobalEntity(NULL,
705  kSCDynamicStoreDomainState,
706  kSCEntNetIPv4);
707  CFArrayAppendValue(notificationKeys, storeKey);
708  CFRelease(storeKey);
709 
710  storeKey = SCDynamicStoreKeyCreateNetworkServiceEntity(NULL,
711  kSCDynamicStoreDomainState,
712  kSCCompAnyRegex,
713  kSCEntNetIPv4);
714  CFArrayAppendValue(patternsArray, storeKey);
715  CFRelease(storeKey);
716 
717  if (!SCDynamicStoreSetNotificationKeys(storeSession , notificationKeys, patternsArray)) {
718  qWarning() << "register notification error:"<< SCErrorString(SCError());
719  CFRelease(storeSession );
720  CFRelease(notificationKeys);
721  CFRelease(patternsArray);
722  return;
723  }
724  CFRelease(notificationKeys);
725  CFRelease(patternsArray);
726 
727  runloopSource = SCDynamicStoreCreateRunLoopSource(NULL, storeSession , 0);
728  if (!runloopSource) {
729  qWarning() << "runloop source error:"<< SCErrorString(SCError());
730  CFRelease(storeSession );
731  return;
732  }
733 
734  CFRunLoopAddSource(CFRunLoopGetCurrent(), runloopSource, kCFRunLoopDefaultMode);
735  return;
736 }
const struct __CFString * CFStringRef
Q_CORE_EXPORT void qWarning(const char *,...)
CFRunLoopSourceRef runloopSource
SCDynamicStoreRef storeSession
void networkChangeCallback(SCDynamicStoreRef, CFArrayRef changedKeys, void *info)

◆ startTime()

quint64 QCoreWlanEngine::startTime ( const QString id)
virtual

Reimplemented from QBearerEngineImpl.

Definition at line 840 of file qcorewlanengine_10_6.mm.

841 {
842  QMutexLocker locker(&mutex);
843  NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
844  quint64 timestamp = 0;
845 
846  NSString *filePath = @"/Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist";
847  NSDictionary* plistDict = [[[NSDictionary alloc] initWithContentsOfFile:filePath] autorelease];
848  if(plistDict == nil)
849  return timestamp;
850  NSString *input = @"KnownNetworks";
851  NSString *timeStampStr = @"_timeStamp";
852 
853  NSString *ssidStr = @"SSID_STR";
854 
855  for (id key in plistDict) {
856  if ([input isEqualToString:key]) {
857 
858  NSDictionary *knownNetworksDict = [plistDict objectForKey:key];
859  if(knownNetworksDict == nil)
860  return timestamp;
861  for (id networkKey in knownNetworksDict) {
862  bool isFound = false;
863  NSDictionary *itemDict = [knownNetworksDict objectForKey:networkKey];
864  if(itemDict == nil)
865  return timestamp;
866  NSInteger dictSize = [itemDict count];
867  id objects[dictSize];
868  id keys[dictSize];
869 
870  [itemDict getObjects:objects andKeys:keys];
871  bool ok = false;
872  for(int i = 0; i < dictSize; i++) {
873  if([ssidStr isEqualToString:keys[i]]) {
874  const QString ident = QString::number(qHash(QLatin1String("corewlan:") + QCFString::toQString(CFStringRef(objects[i]))));
875  if(ident == identifier) {
876  ok = true;
877  }
878  }
879  if(ok && [timeStampStr isEqualToString:keys[i]]) {
880  timestamp = (quint64)[objects[i] timeIntervalSince1970];
881  isFound = true;
882  break;
883  }
884  }
885  if(isFound)
886  break;
887  }
888  }
889  }
890  [autoreleasepool release];
891  return timestamp;
892 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
uint qHash(const QProcEnvKey &key)
Definition: qprocess_p.h:96
const struct __CFString * CFStringRef
static QString toQString(CFStringRef cfstr)
Definition: qcore_mac.cpp:47
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
QStringList keys
unsigned __int64 quint64
Definition: qglobal.h:943
static bool init
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
int key

Friends and Related Functions

◆ QScanThread

friend class QScanThread
friend

Definition at line 61 of file qcorewlanengine.h.

Referenced by QCoreWlanEngine().

Properties

◆ foundConfigurations

QList<QNetworkConfigurationPrivate *> QCoreWlanEngine::foundConfigurations
private

Definition at line 97 of file qcorewlanengine.h.

Referenced by networksChanged(), and ~QCoreWlanEngine().

◆ hasWifi

bool QCoreWlanEngine::hasWifi
private

Definition at line 101 of file qcorewlanengine.h.

Referenced by initialize(), and isWifiReady().

◆ runloopSource

CFRunLoopSourceRef QCoreWlanEngine::runloopSource
private

Definition at line 100 of file qcorewlanengine.h.

Referenced by startNetworkChangeLoop().

◆ scanning

bool QCoreWlanEngine::scanning
private

Definition at line 102 of file qcorewlanengine.h.

◆ scanThread

QScanThread* QCoreWlanEngine::scanThread
private

◆ storeSession

SCDynamicStoreRef QCoreWlanEngine::storeSession
private

Definition at line 99 of file qcorewlanengine.h.

Referenced by initialize(), and startNetworkChangeLoop().


The documentation for this class was generated from the following files: