summaryrefslogtreecommitdiff
path: root/common/cachemanagerdbus.cpp
blob: 643163443908e59f22de9513f2e6158f1380e6bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/**
 * 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>();
    qDBusRegisterMetaType<conn::brw::ERROR_IDS>();
}

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)));
}


qulonglong 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;
}

conn::brw::CACHE_POLICY CacheManagerDbus::getCachePolicy() {
    qDebug() << __PRETTY_FUNCTION__;

    conn::brw::CACHE_POLICY ret;
    QDBusReply<conn::brw::CACHE_POLICY> reply = m_cachemanager->getCachePolicy();

    if(reply.isValid()) {
        ret = reply.value();
        qDebug() << "ERROR_IDS " << ret;
    } else {
        QDBusError error = reply.error();
        qDebug() << "ERROR " << error.name() << error.message();
    }
    return ret;
}

void CacheManagerDbus::setCachePolicy(conn::brw::CACHE_POLICY policy) {
    qDebug() << __PRETTY_FUNCTION__;

    QDBusReply<conn::brw::ERROR_IDS> reply = m_cachemanager->setCachePolicy(policy);

    if(reply.isValid()) {
        conn::brw::ERROR_IDS ret;
        ret = reply.value();
        qDebug() << "ERROR_IDS " << ret;
    } else {
        QDBusError error = reply.error();
        qDebug() << "ERROR " << error.name() << error.message();
    }
}

qulonglong CacheManagerDbus::getMaximumCacheSize() {
    qDebug() << __PRETTY_FUNCTION__;

    qlonglong ret;
    QDBusReply<qulonglong> reply = m_cachemanager->getMaximumCacheSize();

    if(reply.isValid()) {
        ret = reply.value();
        qDebug() << "ERROR_IDS " << ret;
    } else {
        QDBusError error = reply.error();
        qDebug() << "ERROR " << error.name() << error.message();
    }
    return ret;
}

void CacheManagerDbus::clearCache() {
    qDebug() << __PRETTY_FUNCTION__;

    QDBusReply<conn::brw::ERROR_IDS> reply = m_cachemanager->clearCache();

    if(reply.isValid()) {
        conn::brw::ERROR_IDS ret;
        ret = reply.value();
        qDebug() << "ERROR_IDS " << ret;
    } else {
        QDBusError error = reply.error();
        qDebug() << "ERROR " << error.name() << error.message();
    }
}