一、参考列表


meego-cellular-ofono-qt

connman-qt
meego-ux-setting中的cellularSetting部分

合计来说一共就这三个包含了,connman-server、connman-manager、org.ofono.connectcontext、org.ofono.connectmanager四种d-bus的各种接口的各种使用方法

dbus之xml文件参考地址

二、代码

    connectcontext.xml

system(qdbusxml2cpp -c ConnectionContext -p connectioncontext -N connectioncontext.xml)



connectmanager.xml




由于QArrayOfPathProperties总是出错,所以放弃了使用XML的代理d-bus的实现方法。


ofonodbustest.cpp


#include "ofonodbustest.h"

ofonodbustest::ofonodbustest(QObject *parent) :
    QObject(parent)
{
}


QDBusArgument &operator<<(QDBusArgument &argument, const OfonoModemStruct &modem)
{
    argument.beginStructure();
    argument << modem.path << modem.properties;
    argument.endStructure();
    return argument;
}

const QDBusArgument &operator>>(const QDBusArgument &argument, OfonoModemStruct &modem)
{
    argument.beginStructure();
    argument >> modem.path >> modem.properties;
    argument.endStructure();
    return argument;
}


void ofonodbustest::setError(const QString& errorName, const QString& errorMessage)
{
    m_errorName = errorName;
    m_errorMessage = errorMessage;
}

void ofonodbustest::setPropertyResp()
{
    m_pendingProperty = QString();
    // emit nothing; we will get a PropertyChanged signal
}

void ofonodbustest::setPropertyErr(const QDBusError& error)
{
    QString prop = m_pendingProperty;
    setError(error.name(), error.message());
    m_pendingProperty = QString();
    emit setPropertyFailed(prop);
}
void ofonodbustest::enableTechnology(void)
{
    //Step1: Get Modems
    qDebug("Step1: Start to connect gprs/3g. ");
    QDBusReply replyGetModems;
    OfonoModemList modemsGetModems;
    QDBusMessage requestGetModems;

    qDBusRegisterMetaType();
    qDBusRegisterMetaType();

    requestGetModems = QDBusMessage::createMethodCall("org.ofono", "/", "org.ofono.Manager", "GetModems");
    replyGetModems = QDBusConnection::systemBus().call(requestGetModems);
    modemsGetModems = replyGetModems;
    foreach(OfonoModemStruct modem, modemsGetModems) {
        m_modems << modem.path.path();
    }


    //Step2: Get contexts
    //2: "Python": contexts = connman.GetContexts()
    qDebug("Step2: Start to get contexts.");
    QDBusInterface interfaceOfonoConnman("org.ofono", m_modems.at(0), "org.ofono.ConnectionManager",QDBusConnection::systemBus());
    QDBusReply  replyGetContexts = interfaceOfonoConnman.call("GetContexts");
    OfonoModemList contexts = replyGetContexts.value();
    if(contexts.count() < 1)
    {
        //"Python": print "No context available"
        qDebug()<<"CellularSettings::ERROR: could not get active context";
    }



    //Step3: Set Powered->已验证以下代码可用,不过没什么作用
    // connman.SetProperty("Powered", dbus.Boolean(1))
//    qDebug("Step3: Set Powered.");
//    QList argumentList;
//    argumentList << qVariantFromValue(QString("Powered")) << qVariantFromValue(QDBusVariant(QVariant(true)));
//    qDebug("Step3: Set argumentList.");
//    QDBusReply replyOfonoConnman = interfaceOfonoConnman.asyncCallWithArgumentList(QLatin1String("SetProperty"), argumentList);
//    if(replyOfonoConnman.error().isValid())
//    {
//        qDebug()<SetProperty(QString("Active"),QDBusVariant(QVariant(true)));
    if(replyContext.error().isValid())
    {
        qDebug()<


ofonodbustest.h


#ifndef OFONODBUSTEST_H
#define OFONODBUSTEST_H

#include "connectioncontext.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#define SET_PROPERTY_TIMEOUT 300000

struct OfonoModemStruct {
    QDBusObjectPath path;
    QVariantMap properties;
};

typedef QList OfonoModemList;
Q_DECLARE_METATYPE(OfonoModemStruct)
Q_DECLARE_METATYPE(OfonoModemList)

class ofonodbustest : public QObject
{
    Q_OBJECT

public:
    explicit ofonodbustest(QObject *parent = 0);
    void enableTechnology(void);

signals:
    void setPropertyFailed(const QString &name);

public slots:
    void setError(const QString &errorName, const QString &errorMessage);

private slots:
    void setPropertyResp();
    void setPropertyErr(const QDBusError& error);

protected:
   QString m_errorName;
   QString m_errorMessage;

private:
    QString m_pendingProperty;
    QStringList m_modems;
};

#endif // OFONODBUSTEST_H


pro 文件



TEMPLATE = app

TARGET = activate-context-qt

OBJECTS_DIR = tmp
MOC_DIR = tmp

QT -= gui

QT +=   dbus \
        xml \
        xmlpatterns

CONFIG += qt \
        dbus

SOURCES += \
    mian.cpp \
    ofonodbustest.cpp \
    connectioncontext.cpp

HEADERS += \
    ofonodbustest.h \
    connectioncontext.h

OTHER_FILES +=  connectioncontext.xml

system(qdbusxml2cpp -c ConnectionContext -p connectioncontext -N connectioncontext.xml)
system(qdbusxml2cpp -c ConnectionManager -p connectionmanager -N connectionmanager.xml)
12-29 21:01