summaryrefslogtreecommitdiff
path: root/src/navigation/map-viewer/session-plugin/genivi_mapviewer_session.cxx
blob: 678f28892fc5532abf98a397a110f06d54f2c554 (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
129
130
131
132
133
/**
* @licence app begin@
* SPDX-License-Identifier: MPL-2.0
*
* \copyright Copyright (C) 2013-2014, PCA Peugeot Citroen
*
* \file genivi_mapviewer_session.cxx
*
* \brief This file is part of the Navit POC.
*
* \author Martin Schaller <martin.schaller@it-schaller.de>
*
* \version 1.0
*
* 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 <dbus-c++/glib-integration.h>
#include "genivi-mapviewer-constants.h"
#include "genivi-mapviewer-session_adaptor.h"
#include <config.h>
#define USE_PLUGINS 1
#include <navit/debug.h>
#include <navit/plugin.h>
#include <navit/event.h>

#include "navigation-common-dbus.h"

#if (!DEBUG_ENABLED)
#undef dbg
#define dbg(level,...) ;
#endif

static DBus::Glib::BusDispatcher dispatcher;
static DBus::Connection *conn;

static std::map<uint32_t, std::string *> handles;

class  Session
: public org::genivi::navigation::mapviewer::Session_adaptor,
  public DBus::IntrospectableAdaptor,
  public DBus::ObjectAdaptor
{
	public:
	Session(DBus::Connection &connection)
	: DBus::ObjectAdaptor(connection, "/org/genivi/mapviewer")
	{
	}

	::DBus::Struct< uint16_t, uint16_t, uint16_t, std::string > GetVersion()
	{
		::DBus::Struct< uint16_t, uint16_t, uint16_t, std::string > Version;
		dbg(lvl_debug,"enter\n");
		Version._1=3;
		Version._2=0;
		Version._3=0;
		Version._4="07-06-2013";
		return Version;
	}

    void CreateSession(const std::string& client, int32_t& error, uint32_t& sessionHandle)
	{
		dbg(lvl_debug,"enter\n");
        sessionHandle=1;
        while (handles[sessionHandle]) {
            sessionHandle++;
            if (sessionHandle == 256)
				throw DBus::Error("org.genivi.navigation.mapviewer.Session.Error.NoMoreSessionHandles","Out of session handles");
		}
        handles[sessionHandle]=new std::string(client);
        error=0; //not implemented yet
	}

    DBusCommonAPIEnumeration GetSessionStatus(const uint32_t& SessionHandle)
	{
		if (handles[SessionHandle])
			return GENIVI_MAPVIEWER_AVAILABLE;
		else
			return GENIVI_MAPVIEWER_NOT_AVAILABLE;
	}

    int32_t DeleteSession(const uint32_t& SessionHandle)
	{
		dbg(lvl_debug,"enter\n");
		if (!handles[SessionHandle])
			throw DBus::Error("org.genivi.navigation.mapviewer.Session.Error.NotAvailableSessionHandle","Session handle invalid");
		delete(handles[SessionHandle]);
		handles[SessionHandle]=NULL;
		SessionDeleted(SessionHandle);
        return(0); //not implemented yet
	}

    std::vector< ::DBus::Struct< uint32_t, std::string > >
	GetAllSessions()
	{
        std::vector< ::DBus::Struct< uint32_t, std::string > > ret;
		std::map<uint32_t, std::string *>::const_iterator it;
		for(it = handles.begin(); it != handles.end(); it++) {
            ::DBus::Struct< uint32_t, std::string > session;
			if (it->second) {
				session._1=it->first;
				session._2=*it->second;
				ret.push_back(session);
			}
		}
		return ret;
	}
};

static class Session *server;


void
plugin_init(void)
{
	event_request_system("glib","genivi_mapviewersession");
	dispatcher.attach(NULL);
	DBus::default_dispatcher = &dispatcher;
	conn = new DBus::Connection(DBus::Connection::SessionBus());
	conn->setup(&dispatcher);
	conn->request_name("org.genivi.navigation.mapviewer.Session");
	server=new Session(*conn);
}