diff --git a/contourd/CMakeLists.txt b/contourd/CMakeLists.txt index bfd0eaca..7a9dbab2 100644 --- a/contourd/CMakeLists.txt +++ b/contourd/CMakeLists.txt @@ -1,160 +1,162 @@ project(contourd) # This should be REQUIRED once we get rid of the hack below find_package(QtMobility) # build stuff # =============================================================================================== include_directories( ${contour_SOURCE_DIR}/contourd/location ${contour_SOURCE_DIR}/contourd/recommendation ${contour_BINARY_DIR} ${QT_INCLUDES} ${KDE4_INCLUDES} ${NEPOMUK_INCLUDE_DIR} ${SOPRANO_INCLUDE_DIR} #hack to find qt-mobility includes. TODO: get cmake macro ${INCLUDE_INSTALL_DIR}/QtMobility ${INCLUDE_INSTALL_DIR}/QtMobility/QtMobility ${QT_INCLUDE_DIR}/QtMobility ${QT_INCLUDE_DIR}/QtMobility/QtMobility #this uses the cmake macro ${QTMOBILITY_INCLUDE_DIR} ) configure_file( config-features.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-features.h ) add_subdirectory(recommendation/plugins) set(recommendationmanager_SRC recommendation/RecommendationManager.cpp recommendation/RecommendationEngine.cpp recommendation/RecommendationItem.cpp recommendation/RecommendationScriptEngine.cpp recommendation/sensors/dbus/DBusSensor.cpp location/LocationManager.cpp location/network-engines/NetworkNotifier.cpp location/network-engines/dummy/DummyNetworkNotifier.cpp location/network-engines/connman/ConnmanNetworkNotifier.cpp + location/network-engines/connman/connman-manager.cpp + location/network-engines/connman/connman-service.cpp main.cpp ) qt4_add_dbus_adaptor( recommendationmanager_SRC recommendation/org.kde.contour.RecommendationManager.xml recommendation/RecommendationManager.h Contour::RecommendationManager ) qt4_add_dbus_adaptor( recommendationmanager_SRC location/org.kde.contour.LocationManager.xml location/LocationManager.h Contour::LocationManager ) qt4_add_dbus_adaptor( recommendationmanager_SRC location/network-engines/dummy/org.kde.LocationManager.DummyNetworkNotifier.xml location/network-engines/dummy/DummyNetworkNotifier.h DummyNetworkNotifier ) qt4_add_dbus_adaptor( recommendationmanager_SRC location/network-engines/connman/org.kde.LocationManager.ConnmanNetworkNotifier.xml location/network-engines/connman/ConnmanNetworkNotifier.h ConnmanNetworkNotifier ) find_file(kext_onto_src kext.trig PATH_SUFFIXES "ontology/kde" PATHS ${CMAKE_INSTALL_PREFIX}/share ENV XDG_DATA_DIRS) soprano_add_ontology(recommendationmanager_SRC ${kext_onto_src} "KExt" "Nepomuk::Vocabulary" "trig" ) soprano_add_ontology(recommendationmanager_SRC ${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/nepomuk/nao.trig "NAO" "Nepomuk::Vocabulary" "trig" ) soprano_add_ontology(recommendationmanager_SRC ${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/nie/nie.trig "NIE" "Nepomuk::Vocabulary" "trig" ) soprano_add_ontology(recommendationmanager_SRC ${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/nie/nco.trig "NCO" "Nepomuk::Vocabulary" "trig" ) ######################################################################## set(ADDITIONAL_LINK_LIBRARIES) set(recommendationmanager_SRC ${recommendationmanager_SRC} location/network-engines/solid/SolidNetworkNotifier.cpp ) set(ADDITIONAL_LINK_LIBRARIES ${ADDITIONAL_LINK_LIBRARIES} ${KDE4_SOLID_LIBS} ) ######################################################################## kde4_add_executable(contour ${recommendationmanager_SRC} ) target_link_libraries( contour ${QT_QTCORE_LIBRARY} ${QT_QTSCRIPT_LIBRARY} ${KDE4_KDECORE_LIBS} ${KDE4_KIO_LIBS} ${SOPRANO_LIBRARIES} ${NEPOMUK_LIBRARIES} ${NEPOMUK_QUERY_LIBRARIES} ${ADDITIONAL_LINK_LIBRARIES} kworkspace solidcontrol solidcontrolifaces QtLocation QtContacts QtSensors ) install(FILES contour-recommendationengine.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR} ) install(FILES contour-recommendationengine-qtscript.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR} ) install(FILES contour.desktop DESTINATION ${AUTOSTART_INSTALL_DIR} ) install(TARGETS contour ${INSTALL_TARGETS_DEFAULT_ARGS} ) message("AAAAAAAA ${DATA_INSTALL_DIR}") install(FILES location/network-engines/connman/org.kde.LocationManager.ConnmanWatcher.py DESTINATION ${DATA_INSTALL_DIR}/locationmanager/ PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ) diff --git a/contourd/location/network-engines/connman/ConnmanNetworkNotifier.cpp b/contourd/location/network-engines/connman/ConnmanNetworkNotifier.cpp index b753920c..45dae3fb 100644 --- a/contourd/location/network-engines/connman/ConnmanNetworkNotifier.cpp +++ b/contourd/location/network-engines/connman/ConnmanNetworkNotifier.cpp @@ -1,102 +1,159 @@ /* * Copyright (C) 2011 Ivan Cukic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, * or (at your option) any later version, as published by the Free * Software Foundation * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include "connman-manager.h" +#include "connman-service.h" + #include "ConnmanNetworkNotifier.h" #include "connmannetworknotifieradaptor.h" #include -#include -#include -#include - #include -#define CONNMAN_WATCHER_EXEC DATA_INSTALL_DIR"/locationmanager/org.kde.LocationManager.ConnmanWatcher.py" -// #define CONNMAN_DBUS_ADDRESS "org.moblin.connman" -#define CONNMAN_DBUS_ADDRESS "net.connman" +// #define CONNMAN_DBUS_SERVICE "org.moblin.connman" +#define CONNMAN_DBUS_SERVICE "net.connman" REGISTER_NETWORK_NOTIFIER(ConnmanNetworkNotifier) class ConnmanNetworkNotifier::Private { public: Private() - : watcher(NULL), process(NULL) + : iface(0), watcher(0) {} + NetConnmanManagerInterface * iface; QDBusServiceWatcher * watcher; - QProcess * process; }; ConnmanNetworkNotifier::ConnmanNetworkNotifier(QObject * parent) : NetworkNotifier(parent), d(new Private()) { } -void ConnmanNetworkNotifier::init() +ConnmanNetworkNotifier::~ConnmanNetworkNotifier() { - kDebug() << "EXECUTABLE:" << CONNMAN_WATCHER_EXEC; + delete d; +} +void ConnmanNetworkNotifier::init() +{ // Hmh, connman doesn't show up when registered. Lets hope it will be online // before the location manager is started - if (!QDBusConnection::systemBus().interface()->isServiceRegistered(CONNMAN_DBUS_ADDRESS)) { - kDebug() << "Watching for" << CONNMAN_DBUS_ADDRESS << "to arrive"; + if (!QDBusConnection::systemBus().interface()->isServiceRegistered(CONNMAN_DBUS_SERVICE)) { + kDebug() << "Watching for" << CONNMAN_DBUS_SERVICE << "to arrive"; d->watcher = new QDBusServiceWatcher( - CONNMAN_DBUS_ADDRESS, + CONNMAN_DBUS_SERVICE, QDBusConnection::systemBus(), QDBusServiceWatcher::WatchForRegistration | QDBusServiceWatcher::WatchForUnregistration | QDBusServiceWatcher::WatchForOwnerChange, this ); kDebug() << "Connecting" << connect(d->watcher, SIGNAL(serviceRegistered(QString)), this, SLOT(enable())); } else { enable(); - } } void ConnmanNetworkNotifier::enable() { kDebug() << "Starting connman listener"; (void) new ConnmanNetworkNotifierAdaptor(this); QDBusConnection::sessionBus().registerObject( QLatin1String("/ConnmanInterface"), this); - d->process = new QProcess(this); - d->process->setProcessChannelMode(QProcess::ForwardedChannels); - d->process->start(CONNMAN_WATCHER_EXEC); + delete d->iface; + d->iface = new NetConnmanManagerInterface(CONNMAN_DBUS_SERVICE, QLatin1String("/"), QDBusConnection::systemBus(), this); + connect(d->iface, SIGNAL(PropertyChanged(QString,QDBusVariant)), SLOT(propertyChanged(QString,QDBusVariant))); + + QDBusReply reply = d->iface->GetProperties(); + if (!reply.isValid()) { + return; + } + QVariantMap properties = reply.value(); + //kDebug() << "Initial state: " << properties["State"].toString(); + propertyChanged("State", QDBusVariant(properties["State"])); } -ConnmanNetworkNotifier::~ConnmanNetworkNotifier() +// monitor when connman connects to a network, or disconnects from it. +// On those events, this method passes the info to the locationmanager daemon +// via the dummy network notifier. +void ConnmanNetworkNotifier::propertyChanged(const QString &name, const QDBusVariant &value) { - delete d; + //kDebug() << name << ": " << value.variant().toString(); + if (name != QLatin1String("State")) { + return; + } + + // we are offline + if (value.variant().toString() != QLatin1String("online")) { + kDebug() << "OFFLINE"; + setWifiName(""); + return; + } + + QDBusReply reply = d->iface->GetProperties(); + if (!reply.isValid()) { + kDebug() << reply.error().message(); + return; + } + + QVariantMap properties = reply.value(); + //kDebug() << "got properties:" << properties.count(); + //kDebug() << "Services ==" << properties["Services"]; + QList services = qdbus_cast >(properties["Services"]); + //kDebug() << services.count() << "services"; + + // searching for active wifi info + foreach (const QDBusObjectPath &s, services) { + //kDebug() << "testing service" << s.path(); + NetConnmanServiceInterface service(CONNMAN_DBUS_SERVICE, s.path(), QDBusConnection::systemBus()); + + if (!service.isValid()) { + continue; + } + //kDebug() << "testing service" << s.path() << "getting properties"; + + QDBusReply reply = service.GetProperties(); + if (!reply.isValid()) { + continue; + } + //kDebug() << "testing service" << s.path() << "testing state"; + + QVariantMap serviceProperties = reply.value(); + if (serviceProperties["State"].toString() == QLatin1String("ready")) { + kDebug() << "CONNECTED TO:" << serviceProperties["Name"]; + setWifiName(serviceProperties["Name"].toString()); + return; + } + } } void ConnmanNetworkNotifier::setWifiName(const QString & accessPoint) { setActiveAccessPoint(accessPoint); } diff --git a/contourd/location/network-engines/connman/ConnmanNetworkNotifier.h b/contourd/location/network-engines/connman/ConnmanNetworkNotifier.h index 9cfe2bff..d7dc6e2c 100644 --- a/contourd/location/network-engines/connman/ConnmanNetworkNotifier.h +++ b/contourd/location/network-engines/connman/ConnmanNetworkNotifier.h @@ -1,51 +1,52 @@ /* * Copyright (C) 2011 Ivan Cukic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, * or (at your option) any later version, as published by the Free * Software Foundation * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef CONNMAN_NETWORK_NOTIFIER_H #define CONNMAN_NETWORK_NOTIFIER_H #include "../NetworkNotifier.h" /** * ConnmanNetworkNotifier */ class ConnmanNetworkNotifier: public NetworkNotifier { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.LocationManager.ConnmanNetworkNotifier") public: ConnmanNetworkNotifier(QObject * parent = NULL); virtual ~ConnmanNetworkNotifier(); public Q_SLOTS: void setWifiName(const QString & accessPoint); protected Q_SLOTS: void enable(); + void propertyChanged(const QString &name, const QDBusVariant &value); protected: void init(); private: class Private; Private * const d; }; #endif // CONNMAN_NETWORK_NOTIFIER_H diff --git a/contourd/location/network-engines/connman/connman-manager.cpp b/contourd/location/network-engines/connman/connman-manager.cpp new file mode 100644 index 00000000..06b57bb7 --- /dev/null +++ b/contourd/location/network-engines/connman/connman-manager.cpp @@ -0,0 +1,26 @@ +/* + * This file was generated by qdbusxml2cpp version 0.7 + * Command line was: qdbusxml2cpp -N -p connman-manager introspection/connman-manager.xml + * + * qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "connman-manager.h" + +/* + * Implementation of interface class NetConnmanManagerInterface + */ + +NetConnmanManagerInterface::NetConnmanManagerInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +NetConnmanManagerInterface::~NetConnmanManagerInterface() +{ +} + diff --git a/contourd/location/network-engines/connman/connman-manager.h b/contourd/location/network-engines/connman/connman-manager.h new file mode 100644 index 00000000..9825319f --- /dev/null +++ b/contourd/location/network-engines/connman/connman-manager.h @@ -0,0 +1,84 @@ +/* + * This file was generated by qdbusxml2cpp version 0.7 + * Command line was: qdbusxml2cpp -N -p connman-manager introspection/connman-manager.xml + * + * qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef CONNMAN_MANAGER_H +#define CONNMAN_MANAGER_H + +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Proxy class for interface net.connman.Manager + */ +class NetConnmanManagerInterface: public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() + { return "net.connman.Manager"; } + +public: + NetConnmanManagerInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0); + + ~NetConnmanManagerInterface(); + +public Q_SLOTS: // METHODS + inline QDBusPendingReply ConnectService(const QVariantMap &network) + { + QList argumentList; + argumentList << qVariantFromValue(network); + return asyncCallWithArgumentList(QLatin1String("ConnectService"), argumentList); + } + + inline QDBusPendingReply<> DisableTechnology(const QString &type) + { + QList argumentList; + argumentList << qVariantFromValue(type); + return asyncCallWithArgumentList(QLatin1String("DisableTechnology"), argumentList); + } + + inline QDBusPendingReply<> EnableTechnology(const QString &type) + { + QList argumentList; + argumentList << qVariantFromValue(type); + return asyncCallWithArgumentList(QLatin1String("EnableTechnology"), argumentList); + } + + inline QDBusPendingReply GetProperties() + { + QList argumentList; + return asyncCallWithArgumentList(QLatin1String("GetProperties"), argumentList); + } + + inline QDBusPendingReply<> RequestScan(const QString &type) + { + QList argumentList; + argumentList << qVariantFromValue(type); + return asyncCallWithArgumentList(QLatin1String("RequestScan"), argumentList); + } + + inline QDBusPendingReply<> SetProperty(const QString &name, const QDBusVariant &value) + { + QList argumentList; + argumentList << qVariantFromValue(name) << qVariantFromValue(value); + return asyncCallWithArgumentList(QLatin1String("SetProperty"), argumentList); + } + +Q_SIGNALS: // SIGNALS + void PropertyChanged(const QString &name, const QDBusVariant &value); +}; + +#endif diff --git a/contourd/location/network-engines/connman/connman-service.cpp b/contourd/location/network-engines/connman/connman-service.cpp new file mode 100644 index 00000000..c4ef65a3 --- /dev/null +++ b/contourd/location/network-engines/connman/connman-service.cpp @@ -0,0 +1,26 @@ +/* + * This file was generated by qdbusxml2cpp version 0.7 + * Command line was: qdbusxml2cpp -N -p connman-service introspection/connman-service.xml + * + * qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#include "connman-service.h" + +/* + * Implementation of interface class NetConnmanServiceInterface + */ + +NetConnmanServiceInterface::NetConnmanServiceInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent) + : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent) +{ +} + +NetConnmanServiceInterface::~NetConnmanServiceInterface() +{ +} + diff --git a/contourd/location/network-engines/connman/connman-service.h b/contourd/location/network-engines/connman/connman-service.h new file mode 100644 index 00000000..f67eb1e6 --- /dev/null +++ b/contourd/location/network-engines/connman/connman-service.h @@ -0,0 +1,95 @@ +/* + * This file was generated by qdbusxml2cpp version 0.7 + * Command line was: qdbusxml2cpp -N -p connman-service introspection/connman-service.xml + * + * qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#ifndef CONNMAN_SERVICE_H +#define CONNMAN_SERVICE_H + +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Proxy class for interface net.connman.Service + */ +class NetConnmanServiceInterface: public QDBusAbstractInterface +{ + Q_OBJECT +public: + static inline const char *staticInterfaceName() + { return "net.connman.Service"; } + +public: + NetConnmanServiceInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0); + + ~NetConnmanServiceInterface(); + +public Q_SLOTS: // METHODS + inline QDBusPendingReply<> ClearProperty(const QString &name) + { + QList argumentList; + argumentList << qVariantFromValue(name); + return asyncCallWithArgumentList(QLatin1String("ClearProperty"), argumentList); + } + + inline QDBusPendingReply<> Connect() + { + QList argumentList; + return asyncCallWithArgumentList(QLatin1String("Connect"), argumentList); + } + + inline QDBusPendingReply<> Disconnect() + { + QList argumentList; + return asyncCallWithArgumentList(QLatin1String("Disconnect"), argumentList); + } + + inline QDBusPendingReply GetProperties() + { + QList argumentList; + return asyncCallWithArgumentList(QLatin1String("GetProperties"), argumentList); + } + + inline QDBusPendingReply<> MoveAfter(const QDBusObjectPath &service) + { + QList argumentList; + argumentList << qVariantFromValue(service); + return asyncCallWithArgumentList(QLatin1String("MoveAfter"), argumentList); + } + + inline QDBusPendingReply<> MoveBefore(const QDBusObjectPath &service) + { + QList argumentList; + argumentList << qVariantFromValue(service); + return asyncCallWithArgumentList(QLatin1String("MoveBefore"), argumentList); + } + + inline QDBusPendingReply<> Remove() + { + QList argumentList; + return asyncCallWithArgumentList(QLatin1String("Remove"), argumentList); + } + + inline QDBusPendingReply<> SetProperty(const QString &name, const QDBusVariant &value) + { + QList argumentList; + argumentList << qVariantFromValue(name) << qVariantFromValue(value); + return asyncCallWithArgumentList(QLatin1String("SetProperty"), argumentList); + } + +Q_SIGNALS: // SIGNALS + void PropertyChanged(const QString &name, const QDBusVariant &value); +}; + +#endif diff --git a/contourd/location/network-engines/connman/introspection/connman-manager.xml b/contourd/location/network-engines/connman/introspection/connman-manager.xml new file mode 100644 index 00000000..5c7e60d3 --- /dev/null +++ b/contourd/location/network-engines/connman/introspection/connman-manager.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/contourd/location/network-engines/connman/introspection/connman-service.xml b/contourd/location/network-engines/connman/introspection/connman-service.xml new file mode 100644 index 00000000..243d88ea --- /dev/null +++ b/contourd/location/network-engines/connman/introspection/connman-service.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/contourd/location/network-engines/connman/org.kde.LocationManager.ConnmanWatcher.py b/contourd/location/network-engines/connman/org.kde.LocationManager.ConnmanWatcher.py deleted file mode 100644 index 8d27e01c..00000000 --- a/contourd/location/network-engines/connman/org.kde.LocationManager.ConnmanWatcher.py +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/python - -# This is a quick and dirty script to monitor when connman -# connects to a network, or disconnects from it. -# On those events, it passes the info to the locationmanager daemon -# via the dummy network notifier - -import gobject -import dbus -import dbus.mainloop.glib - -dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) - -bus = dbus.SystemBus() - -# Getting the main connman object -main_obj = bus.get_object('net.connman', '/') -props = main_obj.GetProperties(dbus_interface='net.connman.Manager') - -def notify_locationmanager(networkName): - global bus - - locationmanager_obj = bus.get_object('org.kde.LocationManager', '/ConnmanInterface') - props = main_obj.setWifiName(networkName) - - -def main_obj_propchg(key, value): - global bus - global main_obj - - if key == "State": - if value == "online" : - # searching for active wifi info - services = main_obj.GetServices(dbus_interface='net.connman.Manager') - for service in services: - for part in service: - if isinstance(part, dbus.Dictionary): - if (part["State"] == "ready"): - print("CONNECTED TO:", part["Name"]) - notify_locationmanager(part["Name"]) - return - - # we are offline - print("OFFLINE") - notify_locationmanager("") - - -bus.add_signal_receiver(main_obj_propchg, dbus_interface = "net.connman.Manager", signal_name = "PropertyChanged") - -loop = gobject.MainLoop() -loop.run()