summaryrefslogtreecommitdiff
path: root/test/poi-service/poi-contentaccess-module/poi-contentaccess-module-class.h
blob: 124b1c10e55fed7059b3901340b8dbdada7f01f7 (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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/**
* @licence app begin@
* SPDX-License-Identifier: MPL-2.0
*
* \copyright Copyright (C) 2013-2014, PCA Peugeot Citroen
*
* \file poi-contentaccess-module-class.h
*
* \brief This file is part of the poi proof of concept.
*
* \author Philippe Colliot <philippe.colliot@mpsa.com>
*
* \version 1.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:
* 10-02-2014, Philippe Colliot, refinement and migration to the new repository
* <date>, <name>, <description of change>
*
* @licence end@
*/
#ifndef POICONTENTACCESSMODULECLASS_H
#define POICONTENTACCESSMODULECLASS_H


#include "genivi-poiservice-constants.h"
#include "genivi-poiservice-contentaccessmodule_adaptor.h"
#include "genivi-poiservice-poicontentaccess_proxy.h"
#include "poi-common-dbus-data-model.h"

#include <dbus-c++/glib-integration.h>

#include "poi-common-database.h"

#include "poi-common-data-model.h"

#include "mainwindow.h"


// string conversion to numeric: the third parameter of fromString() should be one of std::hex, std::dec or std::oct
template <class T>
bool fromString(T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&))
{
  std::istringstream iss(s);
  return !(iss >> f >> t).fail();
}

using namespace DBus;

class contentAccessModuleServer;
class poiContentAccess;


class  poiContentAccess
: public org::genivi::navigation::poiservice::POIContentAccess_proxy,
  public DBus::IntrospectableProxy,
  public DBus::ObjectProxy
{

public:

    poiContentAccess(DBus::Connection &connection);

    ~poiContentAccess();

private:

};


class  contentAccessModuleServer
: public org::genivi::navigation::poiservice::POIContentAccessModule_adaptor,
  public DBus::IntrospectableAdaptor,
  public DBus::ObjectAdaptor
{
public:
    enum {
        INVALID_HANDLE = 0xFF,
        VALID_HANDLE = 1, //the POC manages only one handle !
        BICYCLE_CATEGORY_ID = 0xFE //the POC manages only one category !
    } CONSTANTS;

    contentAccessModuleServer(DBus::Connection &connection, const char* poiDatabaseFileName);

    ~contentAccessModuleServer();

    DBus_version::DBus_version_t GetVersion();

    void SetLocale(const std::string& languageCode, const std::string& countryCode, const std::string& scriptCode);

    void GetLocale(std::string& languageCode, std::string& countryCode, std::string& scriptCode);

    std::vector< ::DBus::Struct< std::string, std::string , std::string> > GetSupportedLocales();

    std::vector< DBus_categoryIdName::DBus_categoryIdName_t > GetAvailableCategories();

    categoryId_t GetRootCategory();

    std::vector< DBus_categoryIdLevel::DBus_categoryIdLevel_t > GetChildrenCategories(const categoryId_t& category);

    std::vector< DBus_categoryIdLevel::DBus_categoryIdLevel_t > GetParentCategories(const categoryId_t& category);

    categoryId_t createCategory(const DBus_CAMcategory::DBus_CAMcategory_t& category);

    void removeCategories(const std::vector< categoryId_t >& categories);

    void addPOIs(const categoryId_t& unique_id, const std::vector< DBus_PoiAddedDetails::DBus_PoiAddedDetails_t >& poiList);

    void removePOIs(const std::vector< poiId_t >& ids);

    void PoiSearchStarted(const handleId_t& poiSearchHandle, const uint16_t& maxSize, const DBus_geoCoordinate3D::DBus_geoCoordinate3D_t& location, const std::vector< DBus_categoryRadius::DBus_categoryRadius_t >& poiCategories, const std::vector< DBus_attributeDetails::DBus_attributeDetails_t >& poiAttributes, const std::string& inputString, const int32_t& sortOption);

    void PoiSearchCanceled(const handleId_t& poiSearchHandle);

    void ResultListRequested(const camId_t& camId, const handleId_t& poiSearchHandle, const std::vector< attributeId_t >& attributes, int32_t& statusValue, uint16_t& resultListSize, std::vector< DBus_poiCAMDetails::DBus_poiCAMDetails_t >& resultList);

    std::vector< DBus_searchResultDetails::DBus_searchResultDetails_t > PoiDetailsRequested(const std::vector< poiId_t >& source_id);

    void connectToHMI(MainWindow *w);

    void connectCAM(camId_t camId);

    void disconnectCAM();

    std::vector<DBus_CAMcategory::DBus_CAMcategory_t> getCategories();

    void setCategoriesID(std::vector<categoryId_t> categoryIDList);

    std::string getCAMName();

    camId_t getCAMId();


private:

// data conversion routines

    DBus::Variant createVariantString(std::string str);

    DBus::Variant createVariantUint16(uint16_t value);

// search routines

    uint16_t searchAroundALocation(DBus_geoCoordinate3D::geoCoordinate3D_t location,const std::string* inputString);

    uint16_t searchPOIRequest(uint16_t categoryIndex, std::string search_string, DBus_geoCoordinate3D::geoCoordinate3D_t left_bottom_location,DBus_geoCoordinate3D::geoCoordinate3D_t right_top_location);

// error management

    void sendDBusError(const char* message);

    void onError();

//
    bool isCategoryAvailable(categoryId_t id, categoryId_t *category_id);

// geometrical routines


    uint32_t calculateDistance(const DBus_geoCoordinate3D::geoCoordinate3D_t origin, const DBus_geoCoordinate3D::geoCoordinate3D_t target);


    double calculateAngle(const uint32_t radius);

// data

    DBus_version m_version;

    std::string m_languageCode, m_countryCode, m_scriptCode;

    handleId_t m_poiSearchHandle; // the POC is limited to the management of one handle !

    Database *mp_database; // database access
    DBus_geoCoordinate3D::geoCoordinate3D_t m_leftBottomLocation;
    DBus_geoCoordinate3D::geoCoordinate3D_t m_rightTopLocation;

    MainWindow *mp_HMI;

    ushort m_searchStatus;

    DBus_geoCoordinate3D::geoCoordinate3D_t m_centerLocation;

    uint16_t m_totalSize;

    camId_t m_camId;


// buffers
    std::vector< DBus_poiCAMDetails::DBus_poiCAMDetails_t >  m_poiTable; // source_id, name, category, location, distance, attributes
    std::vector< DBus_searchResultDetails::DBus_searchResultDetails_t > m_poiDetailsTable; //details(unique id, name, lat, lon, alt), categories, attributes(name, type, value)


// category and attribute management
    categoryId_t m_availableCategories;
    poi_category_common_t m_availableCategoryTable[MAX_CATEGORIES];
    categoryId_t m_rootCategory;
};



#endif // POIPOCCONTENTACCESSMODULECLASS_H