summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonatan Pålsson <jonatan.palsson@pelagicore.com>2014-02-07 14:09:24 +0100
committerJonatan Pålsson <jonatan.palsson@pelagicore.com>2014-02-07 14:09:24 +0100
commit999720ae99f222a6e0bd35bb49c850f4fbda8367 (patch)
tree32c66aeb4b094dddb960a0ef11a399df22388d2e
parent40eef78114d4f2e89783bb0b6be8831e03083249 (diff)
downloadbrowser-poc-999720ae99f222a6e0bd35bb49c850f4fbda8367.tar.gz
Added CacheManager
-rw-r--r--browser/browserhelper.cpp5
-rw-r--r--browser/cachemanager.cpp22
-rw-r--r--browser/cachemanager.h10
-rw-r--r--browser/unit-tests/cachemanagerdbus/cachemanagerdbus.pro13
-rw-r--r--browser/unit-tests/cachemanagerdbus/testcachemanagerdbus.cpp37
-rw-r--r--browser/unit-tests/cachemanagerdbus/testcachemanagerdbus.h30
-rw-r--r--common/ICacheManager.xml35
-rw-r--r--common/browserdefs.h42
-rw-r--r--common/cachemanagerdbus.cpp65
-rw-r--r--common/cachemanagerdbus.h44
10 files changed, 295 insertions, 8 deletions
diff --git a/browser/browserhelper.cpp b/browser/browserhelper.cpp
index 97dcb7d..f83aa30 100644
--- a/browser/browserhelper.cpp
+++ b/browser/browserhelper.cpp
@@ -69,6 +69,11 @@ browserhelper::browserhelper(QString instanceId, QObject *parent) :
new IUserInputAdaptor(ui);
br->ui = ui;
+ connect(cm, SIGNAL(onCachePolicyChanged(conn::brw::CACHE_POLICY)),
+ br, SLOT (cachePolicyChanged (conn::brw::CACHE_POLICY)));
+ connect(cm, SIGNAL(onClearCache(void)),
+ br, SLOT (clearCache (void)));
+
connect(wpw, SIGNAL(setOutputWebview(QString)), br, SLOT(setView(QString)));
connect(ui, SIGNAL(setOutputWebview(QString)), br, SLOT(setView(QString)));
}
diff --git a/browser/cachemanager.cpp b/browser/cachemanager.cpp
index cefcd89..5d29d62 100644
--- a/browser/cachemanager.cpp
+++ b/browser/cachemanager.cpp
@@ -13,13 +13,14 @@
#include <QObject>
#include <QDBusContext>
+#include <QDebug>
#include "cachemanager.h"
#include "../common/browserdefs.h"
cachemanager::cachemanager(QObject *parent) :
QObject(parent)
- {
+{
m_config = new BrowserConfig();
}
@@ -27,7 +28,18 @@ qlonglong cachemanager::getCacheSize(){
return m_config->getValue<qlonglong>(BrowserConfig::CONFIG_CACHESIZE);
}
-conn::brw::CACHE_POLICY cachemanager::getCachePolicy(){}
-conn::brw::ERROR_IDS cachemanager::getMaximumCacheSize(){}
-conn::brw::ERROR_IDS cachemanager::setCachePolicy(conn::brw::CACHE_POLICY){}
-conn::brw::ERROR_IDS cachemanager::clearCache(){}
+conn::brw::CACHE_POLICY cachemanager::getCachePolicy(){
+ qDebug() << "Getting cache policy";
+ return conn::brw::CP_CACHE_ONLY;
+}
+qlonglong cachemanager::getMaximumCacheSize(){}
+conn::brw::ERROR_IDS cachemanager::setCachePolicy(conn::brw::CACHE_POLICY pol)
+{
+ emit onCachePolicyChanged(pol);
+ qDebug() << "TODO: setCachePolicy";
+}
+conn::brw::ERROR_IDS cachemanager::clearCache()
+{
+ emit onClearCache();
+ qDebug() << "TODO: clearCache";
+}
diff --git a/browser/cachemanager.h b/browser/cachemanager.h
index af6d431..4e46224 100644
--- a/browser/cachemanager.h
+++ b/browser/cachemanager.h
@@ -29,12 +29,16 @@ public:
signals:
void onCacheChanged();
+ // Intenal signals
+ void onCachePolicyChanged(conn::brw::CACHE_POLICY);
+ void onClearCache();
+
public Q_SLOTS:
qlonglong getCacheSize();
conn::brw::CACHE_POLICY getCachePolicy();
- conn::brw::ERROR_IDS getMaximumCacheSize();
- conn::brw::ERROR_IDS setCachePolicy(conn::brw::CACHE_POLICY);
- conn::brw::ERROR_IDS clearCache();
+ qlonglong getMaximumCacheSize();
+ conn::brw::ERROR_IDS setCachePolicy(conn::brw::CACHE_POLICY);
+ conn::brw::ERROR_IDS clearCache();
private:
BrowserConfig *m_config = NULL;
diff --git a/browser/unit-tests/cachemanagerdbus/cachemanagerdbus.pro b/browser/unit-tests/cachemanagerdbus/cachemanagerdbus.pro
new file mode 100644
index 0000000..3f1a770
--- /dev/null
+++ b/browser/unit-tests/cachemanagerdbus/cachemanagerdbus.pro
@@ -0,0 +1,13 @@
+CONFIG += qtestlib debug qt
+TEMPLATE = app
+TARGET = cachemanagerdbus-tests
+INCLUDEPATH += . ../../../common/
+QT += dbus webkitwidgets
+
+my_dbus_interfaces.files += ../../../common/ICacheManager.xml
+my_dbus_interfaces.header_flags = -i ../../../common/browserdefs.h
+DBUS_INTERFACES += my_dbus_interfaces
+
+# Input
+HEADERS += testcachemanagerdbus.h ../../../common/cachemanagerdbus.h
+SOURCES += testcachemanagerdbus.cpp ../../../common/cachemanagerdbus.cpp
diff --git a/browser/unit-tests/cachemanagerdbus/testcachemanagerdbus.cpp b/browser/unit-tests/cachemanagerdbus/testcachemanagerdbus.cpp
new file mode 100644
index 0000000..194d380
--- /dev/null
+++ b/browser/unit-tests/cachemanagerdbus/testcachemanagerdbus.cpp
@@ -0,0 +1,37 @@
+/**
+ * Copyright (C) 2014, Pelagicore
+ *
+ * Author: Jonatan Palsson <jonatan.palsson@pelagicore.com>
+ *
+ * This file is part of the GENIVI project Browser Proof-Of-Concept
+ * For further information, see http://genivi.org/
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <QSignalSpy>
+#include <QDebug>
+#include <QProcess>
+
+#include "testcachemanagerdbus.h"
+
+//////////// Setup & teardown /////////////
+
+void TestCacheManagerDBus::initTestCase () {
+ m_cdb = new CacheManagerDbus();
+ m_cdb->connectdbussession("1");
+}
+
+void TestCacheManagerDBus::cleanupTestCase() {
+ delete m_cdb;
+}
+
+///////////////// Test cases ///////////////
+
+void TestCacheManagerDBus::testGetCacheSize() {
+ m_cdb->getCacheSize();
+}
+
+QTEST_MAIN (TestCacheManagerDBus);
diff --git a/browser/unit-tests/cachemanagerdbus/testcachemanagerdbus.h b/browser/unit-tests/cachemanagerdbus/testcachemanagerdbus.h
new file mode 100644
index 0000000..bc36121
--- /dev/null
+++ b/browser/unit-tests/cachemanagerdbus/testcachemanagerdbus.h
@@ -0,0 +1,30 @@
+/**
+ * Copyright (C) 2014, Pelagicore
+ *
+ * Author: Jonatan Palsson <jonatan.palsson@pelagicore.com>
+ *
+ * This file is part of the GENIVI project Browser Proof-Of-Concept
+ * For further information, see http://genivi.org/
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <QtTest/QtTest>
+#include "../../../common/cachemanagerdbus.h"
+#include "../../../common/browserdefs.h"
+
+class TestCacheManagerDBus: public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void initTestCase();
+ void cleanupTestCase();
+
+ void testGetCacheSize();
+
+private:
+ CacheManagerDbus *m_cdb = NULL;
+};
diff --git a/common/ICacheManager.xml b/common/ICacheManager.xml
new file mode 100644
index 0000000..6c08979
--- /dev/null
+++ b/common/ICacheManager.xml
@@ -0,0 +1,35 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+
+<node>
+ <interface name="conn.brw.ICacheManager">
+
+ <method name="getCacheSize">
+ <arg name="retval" type="t" direction="out"/>
+ </method>
+
+ <method name="getMaximumCacheSize">
+ <arg name="retval" type="t" direction="out"/>
+ </method>
+
+ <method name="getCachePolicy">
+ <arg name="retval" type="(i)" direction="out"/>
+ <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="conn::brw::CACHE_POLICY" />
+ </method>
+
+ <method name="setCachePolicy">
+ <arg name="retval" type="(i)" direction="out"/>
+ <arg name="a_eCachePolicy" type="(i)" direction="in"/>
+ <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="conn::brw::CACHE_POLICY" />
+ <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="conn::brw::ERROR_IDS" />
+ </method>
+
+ <method name="clearCache">
+ <arg name="retval" type="(i)" direction="out"/>
+ <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="conn::brw::ERROR_IDS" />
+ </method>
+
+ <signal name="onCacheChanged" />
+
+ </interface>
+</node>
+
diff --git a/common/browserdefs.h b/common/browserdefs.h
index 2756e97..c72e05d 100644
--- a/common/browserdefs.h
+++ b/common/browserdefs.h
@@ -537,6 +537,47 @@ namespace conn {
CP_CACHE_ONLY = 0x01,
CP_ONLINE_ONLY = 0x02
};
+
+ //## operation operator>>(QDBusArgument,CACHE_POLICY)
+ inline const QDBusArgument& operator>>(const QDBusArgument& args, CACHE_POLICY& cachePolicy) {
+ //#[ operation operator>>(QDBusArgument,CACHE_POLICY)
+ args.beginStructure();
+ int temp =0;
+ args>>temp;
+ switch (temp )
+ {
+ case CP_ONLINE_CACHE:
+ {
+ cachePolicy = CP_ONLINE_CACHE;
+ }
+ break;
+ case CP_CACHE_ONLY :
+ {
+ cachePolicy = CP_CACHE_ONLY;
+ }
+ break;
+ case CP_ONLINE_ONLY:
+ {
+ cachePolicy = CP_ONLINE_ONLY;
+ }
+ break;
+ }
+
+ args.endStructure();
+ return args;
+ //#]
+ }
+
+ //## operation operator<<(QDBusArgument,CACHE_POLICY)
+ inline const QDBusArgument& operator<<(QDBusArgument& args, CACHE_POLICY cachePolicy) {
+ //#[ operation operator<<(QDBusArgument,CACHE_POLICY)
+ args.beginStructure();
+ int param = cachePolicy;
+ args << param;
+ args.endStructure();
+ return args;
+ //#]
+ }
}
}
@@ -554,5 +595,6 @@ Q_DECLARE_METATYPE(conn::brw::BrowserActions)
Q_DECLARE_METATYPE(conn::brw::OBJECT_HANDLE)
Q_DECLARE_METATYPE(conn::brw::ObjectHandleList)
Q_DECLARE_METATYPE(conn::brw::SelectableOption);
+Q_DECLARE_METATYPE(conn::brw::CACHE_POLICY);
#endif // BROWSERDEFS_H
diff --git a/common/cachemanagerdbus.cpp b/common/cachemanagerdbus.cpp
new file mode 100644
index 0000000..9f43174
--- /dev/null
+++ b/common/cachemanagerdbus.cpp
@@ -0,0 +1,65 @@
+/**
+ * Copyright (C) 2014, Pelagicore
+ *
+ * Author: Jonatan Pålsson <jonatan.palsson@pelagicore.com>
+ *
+ * This file is part of the GENIVI project Browser Proof-Of-Concept
+ * For further information, see http://genivi.org/
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <QDBusMetaType>
+#include <QtQml>
+
+#include "cachemanagerdbus.h"
+
+#include "../common/browserdefs.h"
+
+CacheManagerDbus::CacheManagerDbus(QObject *parent) :
+ QObject(parent), m_instanceId("1"), m_isconnected(false)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ registertypes();
+}
+
+void CacheManagerDbus::registertypes() {
+ qDBusRegisterMetaType<conn::brw::CACHE_POLICY>();
+}
+
+void CacheManagerDbus::connectdbussession(QString id) {
+ qDebug() << __PRETTY_FUNCTION__ << id;
+
+ m_instanceId = id;
+
+ QString *dbusservicename = new QString("genivi.poc.browser" + m_instanceId);
+
+ m_cachemanager = new conn::brw::ICacheManager(*dbusservicename, "/Browser/ICacheManager",
+ QDBusConnection::sessionBus(), this);
+ m_isconnected = true;
+ if(!m_cachemanager->isValid()) {
+ qDebug() << "failed create object /Browser/ICacheManager";
+ m_isconnected = false;
+ }
+ connect(m_cachemanager, SIGNAL(onCacheChanged(void)), this, SLOT(cacheChanged(void)));
+}
+
+
+qlonglong CacheManagerDbus::getCacheSize() {
+ qDebug() << __PRETTY_FUNCTION__;
+
+ qulonglong ret;
+ QDBusReply<qulonglong> reply = m_cachemanager->getCacheSize();
+
+ if(reply.isValid()) {
+ ret = reply.value();
+ qDebug() << "ERROR_IDS " << ret;
+ } else {
+ QDBusError error = reply.error();
+ qDebug() << "ERROR " << error.name() << error.message();
+ }
+ return ret;
+}
diff --git a/common/cachemanagerdbus.h b/common/cachemanagerdbus.h
new file mode 100644
index 0000000..42eb321
--- /dev/null
+++ b/common/cachemanagerdbus.h
@@ -0,0 +1,44 @@
+/**
+ * Copyright (C) 2014, Pelagicore
+ *
+ * Author: Jonatan Pålsson <jonatan.palsson@pelagicore.com>
+ *
+ * This file is part of the GENIVI project Browser Proof-Of-Concept
+ * For further information, see http://genivi.org/
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef CACHEMANAGERDBUS_H
+#define CACHEMANAGERDBUS_H
+
+#include <QObject>
+#include <QQmlListProperty>
+
+#include "icachemanager_interface.h"
+#include "../common/bookmark.h"
+
+class CacheManagerDbus : public QObject
+{
+ Q_OBJECT
+
+public:
+ explicit CacheManagerDbus(QObject *parent = 0);
+
+ void connectdbussession(QString id);
+ Q_INVOKABLE qlonglong getCacheSize();
+
+signals:
+ void onCacheChanged();
+
+private:
+ QString m_instanceId;
+ bool m_isconnected;
+ conn::brw::ICacheManager *m_cachemanager = NULL;
+
+ void registertypes();
+};
+
+#endif // CACHEMANAGERDBUS_H