void StatusEventHandler::event(bps_event_t *event) {
    bool status = false;
    const char* language = "";
    const char* country = "";
    const char* locale = "";
    const char* interface = "";
    const char* type = "none";
    double latitude = 0;
    double longitude= 0;

    if (bps_event_get_domain(event) == geolocation_get_domain()) {
           if(event == NULL || bps_event_get_code(event) != GEOLOCATION_INFO) {
               qDebug() << "NO INFORMATION PROVIDED";
               return;
           }
               latitude = geolocation_event_get_latitude(event);
               longitude = geolocation_event_get_longitude(event);
               double accuracy = geolocation_event_get_accuracy(event);

               double altitude = geolocation_event_get_altitude(event);
               bool altitude_valid =
                          geolocation_event_is_altitude_valid(event);

               double altitude_accuracy =
                           geolocation_event_get_altitude_accuracy(event);
               bool altitude_accuracy_valid =
                           geolocation_event_is_altitude_accuracy_valid(event);

               double heading = geolocation_event_get_heading(event);
               bool heading_valid =
                           geolocation_event_is_heading_valid(event);

               double speed = geolocation_event_get_speed(event);
               bool speed_valid = geolocation_event_is_speed_valid(event);

               double num_satellites =
                           geolocation_event_get_num_satellites_used(event);
               bool num_satellites_valid =
                           geolocation_event_is_num_satellites_valid(event);

               emit geolocationUpdated(latitude,longitude);
       }
    if (bps_event_get_domain(event) == netstatus_get_domain()) {
        if (NETSTATUS_INFO == bps_event_get_code(event)) {
            netstatus_info_t *info = netstatus_event_get_info(event);
            if (info)
            {
                status = netstatus_info_get_availability(info);
                interface = netstatus_info_get_default_interface(info);

                netstatus_interface_details_t *details;

                int success = netstatus_get_interface_details(interface, &details);
                if (success == BPS_SUCCESS) {
                    switch (netstatus_interface_get_type(details)) {

                    case NETSTATUS_INTERFACE_TYPE_UNKNOWN:
                        type = "Unknown";
                        break;

                    case NETSTATUS_INTERFACE_TYPE_WIRED:
                        type = "Wired";
                        break;

                    case NETSTATUS_INTERFACE_TYPE_WIFI:
                        type = "Wi-Fi";
                        break;

                    case NETSTATUS_INTERFACE_TYPE_BLUETOOTH_DUN:
                        type = "Bluetooth";
                        break;

                    case NETSTATUS_INTERFACE_TYPE_USB:
                        type = "USB";
                        break;

                    case NETSTATUS_INTERFACE_TYPE_VPN:
                        type = "VPN";
                        break;

                    case NETSTATUS_INTERFACE_TYPE_BB:
                        type = "BB";
                        break;

                    case NETSTATUS_INTERFACE_TYPE_CELLULAR:
                        type = "Cellular";
                        break;

                    case NETSTATUS_INTERFACE_TYPE_P2P:
                        type = "P2P";
                        break;
                    }
                }

                netstatus_free_interface_details(&details);
                emit networkStatusUpdated(status, type);
            }
        }
    } else if (bps_event_get_domain(event) == locale_get_domain()) {
        if (LOCALE_INFO == bps_event_get_code(event)) {
            language = locale_event_get_language(event);
            country = locale_event_get_country(event);
            locale = locale_event_get_locale(event);
            emit localeUpdated(language, country, locale);
        }
    }
}
示例#2
0
void QBBEngine::updateConfiguration(const char *interface)
{
    netstatus_interface_details_t *details = 0;

    if (netstatus_get_interface_details(interface, &details) != BPS_SUCCESS) {
        qBearerDebug() << Q_FUNC_INFO << "cannot retrieve details for interface" << interface;

        return;
    }

    const QString name = QString::fromLatin1(netstatus_interface_get_name(details));
    const QString id = idForName(name);


    const int numberOfIpAddresses = netstatus_interface_get_num_ip_addresses(details);
    const bool isConnected = netstatus_interface_is_connected(details);
    const netstatus_interface_type_t type = netstatus_interface_get_type(details);

    netstatus_free_interface_details(&details);

    QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Defined;

    if (isConnected && (numberOfIpAddresses > 0))
        state |= QNetworkConfiguration::Active;

    QMutexLocker locker(&mutex);

    if (accessPointConfigurations.contains(id)) {
        QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id);

        bool changed = false;

        QMutexLocker ptrLocker(&ptr->mutex);

        if (!ptr->isValid) {
            ptr->isValid = true;
            changed = true;
        }

        if (ptr->name != name) {
            ptr->name = name;
            changed = true;
        }

        if (ptr->id != id) {
            ptr->id = id;
            changed = true;
        }

        if (ptr->state != state) {
            ptr->state = state;
            changed = true;
        }

        ptrLocker.unlock();

        locker.unlock();

        if (changed) {
            qBearerDebug() << Q_FUNC_INFO << "configuration changed:" << interface;

            Q_EMIT configurationChanged(ptr);
        } else {
            qBearerDebug() << Q_FUNC_INFO << "configuration has not changed.";
        }

        return;
    }

    QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate);

    ptr->name = name;
    ptr->isValid = true;
    ptr->id = id;
    ptr->state = state;
    ptr->type = QNetworkConfiguration::InternetAccessPoint;
    ptr->bearerType = interfaceType(type);

    accessPointConfigurations.insert(id, ptr);
    configurationInterface.insert(id, name);

    locker.unlock();

    qBearerDebug() << Q_FUNC_INFO << "configuration added:" << interface;

    Q_EMIT configurationAdded(ptr);
}
示例#3
0
void QBBEngine::updateConfiguration(const char *interface)
{
    netstatus_interface_details_t *details = 0;

    if (netstatus_get_interface_details(interface, &details) != BPS_SUCCESS) {
        qBearerDebug() << Q_FUNC_INFO << "cannot retrieve details for interface" << interface;

        return;
    }

    const QString name = QString::fromLatin1(netstatus_interface_get_name(details));
    const QString id = idForName(name);


    const netstatus_interface_type_t type = netstatus_interface_get_type(details);
    const netstatus_ip_status_t ipStatus = netstatus_interface_get_ip_status(details);

    netstatus_free_interface_details(&details);

    QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Defined;

    if (ipStatus == NETSTATUS_IP_STATUS_OK)
        state |= QNetworkConfiguration::Active;

    QMutexLocker locker(&mutex);

    if (accessPointConfigurations.contains(id)) {
        QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id);

        bool changed = false;

        QMutexLocker ptrLocker(&ptr->mutex);

        if (!ptr->isValid) {
            ptr->isValid = true;
            changed = true;
        }

        if (ptr->name != name) {
            ptr->name = name;
            changed = true;
        }

        if (ptr->id != id) {
            ptr->id = id;
            changed = true;
        }

        if (ptr->state != state) {
            ptr->state = state;
            changed = true;
        }

        const netstatus_ip_status_t oldIpStatus = ptr->oldIpStatus;
        ptr->oldIpStatus = ipStatus;

        ptrLocker.unlock();

        locker.unlock();

        if (changed) {
            qBearerDebug() << Q_FUNC_INFO << "configuration changed:" << interface;

            Q_EMIT configurationChanged(ptr);
        } else {
            // maybe Wifi has changed but gateway not yet ready etc.
            qBearerDebug() << Q_FUNC_INFO << "configuration has not changed.";
            if (oldIpStatus != ipStatus) { // if IP status changed
                if (ipStatus != NETSTATUS_IP_STATUS_OK
                        && ipStatus != NETSTATUS_IP_STATUS_ERROR_NOT_UP
                        && ipStatus != NETSTATUS_IP_STATUS_ERROR_NOT_CONFIGURED) {
                    // work around race condition in netstatus API by just checking
                    // again in 300 ms
                    QTimer::singleShot(300, this, SLOT(doRequestUpdate()));
                }
            }
        }

        return;
    }

    QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate);

    ptr->name = name;
    ptr->isValid = true;
    ptr->id = id;
    ptr->state = state;
    ptr->type = QNetworkConfiguration::InternetAccessPoint;
    ptr->bearerType = interfaceType(type);

    accessPointConfigurations.insert(id, ptr);
    configurationInterface.insert(id, name);

    locker.unlock();

    qBearerDebug() << Q_FUNC_INFO << "configuration added:" << interface;

    Q_EMIT configurationAdded(ptr);
}
void ConnectionInfo::event(bps_event_t *event) {
	bool status = false;
	const char* interface = "";
	Type type = Unknown;
	netstatus_interface_details_t* details = NULL;

	// Verify that the event coming in is a network status event.
	if (bps_event_get_domain(event) == netstatus_get_domain()) {
		// Using the BPS event code of the network status event,
		// verify that the event is a network information event.
		if (NETSTATUS_INFO == bps_event_get_code(event)) {
			// Retrieve the network status information, and verify
			// that the procedure is successful.
			if (BPS_SUCCESS == netstatus_get_info(&info)) {
				status = netstatus_info_get_availability(info);
				interface = netstatus_info_get_default_interface(info);
				int success = netstatus_get_interface_details(interface,
						&details);

				if (success == BPS_SUCCESS) {
					switch (netstatus_interface_get_type(details)) {
					case NETSTATUS_INTERFACE_TYPE_WIRED:
						type = Wired;
						break;

					case NETSTATUS_INTERFACE_TYPE_WIFI:
						type = Wifi;
						break;

					case NETSTATUS_INTERFACE_TYPE_BLUETOOTH_DUN:
						type = Bluetooth;
						break;

					case NETSTATUS_INTERFACE_TYPE_USB:
					case NETSTATUS_INTERFACE_TYPE_BB:
						type = Usb;
						break;

					case NETSTATUS_INTERFACE_TYPE_VPN:
						type = VPN;
						break;

					case NETSTATUS_INTERFACE_TYPE_CELLULAR:
						type = Cellular;
						break;

					case NETSTATUS_INTERFACE_TYPE_P2P:
					case NETSTATUS_INTERFACE_TYPE_UNKNOWN:
						type = Unknown;
						break;
					}
					netstatus_free_info(&info);
				}
			}

			// Emit the signal to trigger networkStatusUpdated slot.
			this->setConnected(status);
			this->setInterfaceType(type);
		}
	}
}