Skip to content

Commit

Permalink
add Counter API
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorn Potter committed Dec 21, 2012
1 parent 8e08ecc commit 8127255
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 2 deletions.
64 changes: 64 additions & 0 deletions libconnman-qt/counter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright © 2012, Jolla.
*
* This program is licensed under the terms and conditions of the
* Apache License, version 2.0. The full text of the Apache License is at
* http://www.apache.org/licenses/LICENSE-2.0
*
*/

#include <QtDBus/QDBusConnection>

#include "counter.h"

static const char COUNTER_PATH[] = "/ConnectivityCounter";

Counter::Counter(QObject *parent) :
QObject(parent),
m_manager(NetworkManagerFactory::createInstance())
{
new CounterAdaptor(this);
QDBusConnection::systemBus().registerObject(COUNTER_PATH, this);

if (m_manager->isAvailable()) {
m_manager->registerCounter(QString(COUNTER_PATH),1024,5);
}
}

Counter::~Counter()
{
}

void Counter::serviceUsage(const QString &servicePath, const QVariantMap &counters, bool roaming)
{
Q_EMIT counterChanged(servicePath, counters, roaming);
}


CounterAdaptor::CounterAdaptor(Counter* parent)
: QDBusAbstractAdaptor(parent),
m_counter(parent)
{
}

CounterAdaptor::~CounterAdaptor()
{
}

void CounterAdaptor::Release()
{
}

void CounterAdaptor::Usage(const QDBusObjectPath &service_path,
const QVariantMap &home,
const QVariantMap &roaming)
{
if (roaming.isEmpty()) {
// home
m_counter->serviceUsage(service_path.path(), home, false);
} else {
//roaming
m_counter->serviceUsage(service_path.path(), roaming, true);
}
}

60 changes: 60 additions & 0 deletions libconnman-qt/counter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright © 2012, Jolla.
*
* This program is licensed under the terms and conditions of the
* Apache License, version 2.0. The full text of the Apache License is at
* http://www.apache.org/licenses/LICENSE-2.0
*
*/

#ifndef COUNTER_H
#define COUNTER_H

#include <QObject>
#include <QVariantMap>
#include <QtDBus/QDBusAbstractAdaptor>
#include <QtDBus/QDBusObjectPath>

#include <networkmanager.h>

class Counter : public QObject
{
Q_OBJECT
Q_DISABLE_COPY(Counter)
public:
explicit Counter(/*const QString &serviceName, */QObject *parent = 0);
virtual ~Counter();

void serviceUsage(const QString &servicePath, const QVariantMap &counters, bool roaming);

signals:
// void usage
void counterChanged(const QString servicePath, const QVariantMap &counters, bool roaming);

public slots:

private:
NetworkManager* m_manager;
};


class CounterAdaptor : public QDBusAbstractAdaptor
{
Q_OBJECT;
Q_CLASSINFO("D-Bus Interface", "net.connman.Counter");

public:
explicit CounterAdaptor(Counter* parent);
virtual ~CounterAdaptor();

public slots:
void Release();
void Usage(const QDBusObjectPath &service_path,
const QVariantMap &home,
const QVariantMap &roaming);

private:
Counter* m_counter;
friend class CounterAdaptor;
};
#endif // COUNTER_H
6 changes: 4 additions & 2 deletions libconnman-qt/libconnman-qt.pro
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ HEADERS += manager.h \
clockproxy.h \
clockmodel.h \
debug.h \
useragent.h
useragent.h \
counter.h

SOURCES += \
networkmanager.cpp \
Expand All @@ -40,7 +41,8 @@ SOURCES += \
clockmodel.cpp \
commondbustypes.cpp \
debug.cpp \
useragent.cpp
useragent.cpp \
counter.cpp

target.path = $$INSTALL_ROOT$$PREFIX/lib

Expand Down
12 changes: 12 additions & 0 deletions libconnman-qt/networkmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,3 +441,15 @@ void NetworkManager::unregisterAgent(const QString &path)
if(m_manager)
m_manager->UnregisterAgent(QDBusObjectPath(path));
}

void NetworkManager::registerCounter(const QString &path, quint32 accuracy,quint32 period)
{
if(m_manager)
m_manager->RegisterCounter(QDBusObjectPath(path),accuracy, period);
}

void NetworkManager::unregisterCounter(const QString &path)
{
if(m_manager)
m_manager->UnregisterCounter(QDBusObjectPath(path));
}
2 changes: 2 additions & 0 deletions libconnman-qt/networkmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public slots:
void setOfflineMode(const bool &offlineMode);
void registerAgent(const QString &path);
void unregisterAgent(const QString &path);
void registerCounter(const QString &path, quint32 accuracy,quint32 period);
void unregisterCounter(const QString &path);

signals:
void availabilityChanged(bool available);
Expand Down

0 comments on commit 8127255

Please sign in to comment.