summaryrefslogtreecommitdiff
path: root/test/html-based-panel/node-cpp-lbs-modules/dbus-proxies/DemonstratorProxy.cpp
blob: dc0096c8ab01f6fc01ea481b6b7d1bab9b94d32a (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
/**
* @licence app begin@
* SPDX-License-Identifier: MPL-2.0
*
* \copyright Copyright (C) 2016, PCA Peugeot Citroen
*
* \file main.cpp
*
* \brief This file is part of the Navigation Web API proof of concept.
*
* \author Philippe Colliot <philippe.colliot@mpsa.com>
*
* \version 0.1
*
* This Source Code Form is subject to the terms of the
* Mozilla Public License (MPL), 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/.
*
* For further information see http://www.genivi.org/.
*
* List of changes:
* <date>, <name>, <description of change>
*
* @licence end@
*/
#include <node.h>

#include "DemonstratorProxy.hpp"
#include "../FuelStopAdvisorWrapper.hpp"

using namespace v8;
using namespace std;

static DBus::Glib::BusDispatcher *dispatcher;
static DBus::Connection *connection;
static DBus::Glib::BusDispatcher *amb_dispatcher;
static DBus::Connection *amb_connection;

FuelStopAdvisorProxy::FuelStopAdvisorProxy(DBus::Connection &connection, DemonstratorProxy *demonstratorProxy)
    :    DBus::ObjectProxy(connection,
                           "/org/genivi/demonstrator/FuelStopAdvisor",
                           "org.genivi.demonstrator.FuelStopAdvisor")
{
    mp_demonstratorProxy = demonstratorProxy;
}

void FuelStopAdvisorProxy::TripDataResetted(const uint8_t& number)
{
    mp_demonstratorProxy->TripDataResetted(number);
}

void FuelStopAdvisorProxy::TripDataUpdated(const uint8_t& number)
{
    mp_demonstratorProxy->TripDataUpdated(number);
}

void FuelStopAdvisorProxy::FuelStopAdvisorWarning(const bool& destinationCantBeReached)
{
    mp_demonstratorProxy->FuelStopAdvisorWarning(destinationCantBeReached);
}

ManagerProxy::ManagerProxy(DBus::Connection &connection, DemonstratorProxy *demonstratorProxy)
    : DBus::ObjectProxy(connection,
                        "/",
                        "org.automotive.message.broker")
{
    mp_demonstratorProxy = demonstratorProxy;
}

DemonstratorProxy::DemonstratorProxy(FuelStopAdvisorWrapper *fuelStopAdvisorWrapper)
{
    dispatcher = new DBus::Glib::BusDispatcher();
    DBus::default_dispatcher = dispatcher;
    dispatcher->attach(NULL);
    connection = new DBus::Connection(DBus::Connection::SessionBus());
    connection->setup(dispatcher);
    mp_fuelStopAdvisorWrapper = fuelStopAdvisorWrapper;
    mp_fuelStopAdvisorProxy = new FuelStopAdvisorProxy(*connection,this);

    amb_dispatcher = new DBus::Glib::BusDispatcher();
    DBus::default_dispatcher = amb_dispatcher;
    amb_dispatcher->attach(NULL);
    amb_connection = new DBus::Connection(DBus::Connection::SessionBus());
    amb_connection->setup(amb_dispatcher);

    mp_managerProxy = new ManagerProxy(*amb_connection, this);

    mp_managerProxy->m_fuel = mp_managerProxy->FindObject("Fuel");
    mp_managerProxy->m_odometer = mp_managerProxy->FindObject("Odometer");
    mp_managerProxy->m_engine_speed = mp_managerProxy->FindObject("EngineSpeed");

    mp_managerProxy->mp_fuel_properties = new Properties(*amb_connection,mp_managerProxy->m_fuel[0]);
    mp_managerProxy->mp_odometer_properties = new Properties(*amb_connection,mp_managerProxy->m_odometer[0]);
    mp_managerProxy->mp_engine_speed_properties = new Properties(*amb_connection,mp_managerProxy->m_engine_speed[0]);

}

DemonstratorProxy::~DemonstratorProxy()
{
    delete mp_fuelStopAdvisorProxy;
    delete mp_managerProxy;
    delete connection;
    delete dispatcher;
}

void DemonstratorProxy::TripDataResetted(const uint8_t& number)
{
    mp_fuelStopAdvisorWrapper->TripDataResetted(number);
}

void DemonstratorProxy::TripDataUpdated(const uint8_t& number)
{
    mp_fuelStopAdvisorWrapper->TripDataUpdated(number);
}

void DemonstratorProxy::FuelStopAdvisorWarning(const bool& destinationCantBeReached)
{
    mp_fuelStopAdvisorWrapper->FuelStopAdvisorWarning(destinationCantBeReached);
}