summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author <philippe colliot>2015-03-25 17:22:46 +0100
committer <philippe colliot>2015-03-25 17:22:46 +0100
commit4ce01f648637ca50a65f0f25e9c6bf60245f178d (patch)
treead5af673611040f5da34eda1d34c23d70356d50b /src
parentdb938087b273e7db503ff829255a7f93e6be0f98 (diff)
downloadpoi-service-4ce01f648637ca50a65f0f25e9c6bf60245f178d.tar.gz
Start implementing connection of poi manager to a sqlite3 database
Diffstat (limited to 'src')
-rw-r--r--src/poi-service/poi-common/poi-common-data-model.h2
-rw-r--r--src/poi-service/poi-common/poi-common-database.cpp2
-rw-r--r--src/poi-service/poi-common/poi-common-database.h2
-rw-r--r--src/poi-service/poi-manager-server/CMakeLists.txt4
-rw-r--r--src/poi-service/poi-manager-server/main.cpp119
-rw-r--r--src/poi-service/poi-manager-server/poi-manager-server-stub.cpp188
-rw-r--r--src/poi-service/poi-manager-server/poi-manager-server-stub.h9
-rw-r--r--src/poi-service/poi-server/main.cpp4
-rw-r--r--src/poi-service/script/poi-database-managed.dbbin0 -> 36864 bytes
9 files changed, 313 insertions, 17 deletions
diff --git a/src/poi-service/poi-common/poi-common-data-model.h b/src/poi-service/poi-common/poi-common-data-model.h
index be54247..e72633a 100644
--- a/src/poi-service/poi-common/poi-common-data-model.h
+++ b/src/poi-service/poi-common/poi-common-data-model.h
@@ -54,7 +54,7 @@ enum ATTRIBUTE_LIST{
};
-// Data types used by the CAM
+// Data types used by the CAM and the server
/**
* \struct category_attribute_t
* \brief attributes.
diff --git a/src/poi-service/poi-common/poi-common-database.cpp b/src/poi-service/poi-common/poi-common-database.cpp
index 0c43220..310a631 100644
--- a/src/poi-service/poi-common/poi-common-database.cpp
+++ b/src/poi-service/poi-common/poi-common-database.cpp
@@ -4,7 +4,7 @@
*
* \copyright Copyright (C) 2013-2014, PCA Peugeot Citroen
*
-* \file database.cpp
+* \file poi-common-database.cpp
*
* \brief This file is part of the poi proof of concept.
*
diff --git a/src/poi-service/poi-common/poi-common-database.h b/src/poi-service/poi-common/poi-common-database.h
index 42f1e52..acad203 100644
--- a/src/poi-service/poi-common/poi-common-database.h
+++ b/src/poi-service/poi-common/poi-common-database.h
@@ -4,7 +4,7 @@
*
* \copyright Copyright (C) 2013-2014, PCA Peugeot Citroen
*
-* \file database.h
+* \file poi-common-database.h
*
* \brief This file is part of the poi proof of concept.
*
diff --git a/src/poi-service/poi-manager-server/CMakeLists.txt b/src/poi-service/poi-manager-server/CMakeLists.txt
index 4e9bde7..c5f5fb0 100644
--- a/src/poi-service/poi-manager-server/CMakeLists.txt
+++ b/src/poi-service/poi-manager-server/CMakeLists.txt
@@ -38,6 +38,7 @@ pkg_check_modules(COMMONAPI "CommonAPI >= 2.1")
pkg_check_modules(COMMONAPI_DBUS "CommonAPI-DBus >= 2.1")
pkg_check_modules(SQLITE3 REQUIRED sqlite3)
pkg_check_modules(GLIBMM glibmm-2.4)
+pkg_check_modules(GOBJECT gobject-2.0)
# Source Files
set(PRJ_SRC_PATH .)
@@ -58,6 +59,7 @@ include_directories(
${COMMONAPI_INCLUDEDIR}/${COMMON_API_VERSION}
${COMMONAPI_DBUS_INCLUDEDIR}
${GLIBMM_INCLUDE_DIRS}
+ ${GOBJECT_INCLUDE_DIRS}
${SQLITE3_INCLUDE_DIRS}
)
@@ -66,12 +68,14 @@ link_directories(
${COMMONAPI_LIBDIR}
${COMMONAPI_DBUS_LIBDIR}
${GLIBMM_LIBRARY_DIRS}
+ ${GOBJECT_LIBRARY_DIRS}
${SQLITE3_LIBRARY_DIRS}
)
set(LIBRARIES
${COMMONAPI_LIBRARIES}
${COMMONAPI_DBUS_LIBRARIES}
+ ${GOBJECT_LIBRARIES}
${GLIBMM_LIBRARIES}
${SQLITE3_LIBRARIES}
)
diff --git a/src/poi-service/poi-manager-server/main.cpp b/src/poi-service/poi-manager-server/main.cpp
index e97ee99..32e7e4e 100644
--- a/src/poi-service/poi-manager-server/main.cpp
+++ b/src/poi-service/poi-manager-server/main.cpp
@@ -24,32 +24,127 @@
*
* @licence end@
*/
+#include <stdbool.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <sys/types.h>
#include <iostream>
+#include <fstream>
+#include <cmath>
#include <thread>
+#include <typeinfo>
+#include <getopt.h>
+
#include <CommonAPI/CommonAPI.h> //Defined in the Common API Runtime library
#include "poi-manager-server-stub.h"
-int main()
+const char* program_name; //file to sink outputs
+
+/**
+ * \fn is_readable (const std::string & file)
+ * \brief Check if file can be opened.
+ *
+ * \param const std::string & file -name of the file
+ * \return true if file readable.
+ */
+bool is_readable( const std::string & file )
+{
+ std::ifstream fi( file.c_str() );
+ return !fi.fail();
+}
+
+/**
+ * \fn print_usage (FILE* stream, int exit_code)
+ * \brief Display the available options.
+ *
+ * \param const FILE* stream -name of stream to use
+ * \param int exit_code -exit code
+ * \return void.
+ */
+void print_usage (FILE* stream, int exit_code)
+{
+ fprintf (stream, "Use: %s options [database]\n",program_name);
+ fprintf (stream,
+ " -h --help Display this message.\n"
+ " -f --file database Open the database.\n");
+ exit (exit_code);
+}
+
+int main(int argc , char** argv )
{
+ // Set the global C and C++ locale to the user-configured locale,
+ // so we can use std::cout with UTF-8, via Glib::ustring, without exceptions.
+ std::locale::global(std::locale(""));
+
+ // Common API data init
std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load();
std::shared_ptr<CommonAPI::Factory> factory = runtime->createFactory();
std::shared_ptr<CommonAPI::ServicePublisher> servicePublisher = runtime->getServicePublisher();
const std::string& serviceAddress = "local:org.genivi.poiservice.POIContentManager:org.genivi.poiservice.POIContentManager";
std::shared_ptr<PoiManagerServerStub> myService = std::make_shared<PoiManagerServerStub>();
- //register Interface for Management of a POI Content Access Module with add/remove features
- bool registerResult = servicePublisher->registerService(myService, serviceAddress, factory);
- if (registerResult != true) {
- std::cerr << "Registering of POI Manager stub failed." << std::endl;
- exit(1);
- }
+ //index used for argument analysis
+ int next_option;
+
+ /* Valid letters for short options. */
+ const char* const short_options = "hf:";
+ /* Valid string for long options. */
+ const struct option long_options[] = {
+ { "help", 0, NULL, 'h' },
+ { "file", 2, NULL, 'f' },
+ { NULL, 0, NULL, 0 } /* Always at the end of the table. */
+ };
+ char* database_filename = NULL; //database filename passed as first argument
+ program_name = argv[0];
+
+ GMainLoop * mainloop ;
+
+ bool registerResult;
+ do {
+ next_option = getopt_long (argc, argv, short_options,
+ long_options, NULL);
+ switch (next_option)
+ {
+ case 'h': /* -h --help */
+ print_usage (stdout, 0);
+ break;
+ case 'f': /* -f --file database*/
+ database_filename = argv[2];
+ if (!is_readable(database_filename))
+ print_usage (stderr, 1);
+ else
+ {
+ myService->initDatabase(database_filename);
- std::cout << "Welcome to Genivi POI Manager simulation (Server part)" << std::endl << std::endl;
+ //register Interface for Management of a POI Content Access Module with add/remove features
+ registerResult = servicePublisher->registerService(myService, serviceAddress, factory);
+ if (registerResult != true) {
+ std::cerr << "Registering of POI Manager stub failed." << std::endl;
+ exit(EXIT_FAILURE);
+ }
- while(true) {
- std::cout << "Waiting for calls... (Abort with CTRL+C)" << std::endl;
- std::this_thread::sleep_for(std::chrono::seconds(60));
+ // Create a new GMainLoop with default context and initial state of "not running "
+ mainloop = g_main_loop_new (g_main_context_default() , FALSE );
+
+ // Send a feedback to the user
+ cout << "poi manager server started" << endl;
+
+ g_main_loop_run ( mainloop );
+
+ }
+ break;
+ case '?': /* Invalid option. */
+ print_usage (stderr, 1);
+ case -1: /* End of options. */
+ break;
+ default: /* Error */
+ print_usage (stderr, 1);
+ }
}
- return 0;
+ while (next_option != -1);
+
+ return EXIT_SUCCESS;
}
diff --git a/src/poi-service/poi-manager-server/poi-manager-server-stub.cpp b/src/poi-service/poi-manager-server/poi-manager-server-stub.cpp
index c368f82..edefd89 100644
--- a/src/poi-service/poi-manager-server/poi-manager-server-stub.cpp
+++ b/src/poi-service/poi-manager-server/poi-manager-server-stub.cpp
@@ -26,11 +26,32 @@
*/
#include "poi-manager-server-stub.h"
+// SQL requests
+const char SQL_REQUEST_GET_AVAILABLE_CATEGORIES[] = "SELECT Id,name FROM poicategory WHERE Id IN (SELECT poicategory_Id FROM belongsto GROUP BY poicategory_Id);";
+const char SQL_REQUEST_GET_CATEGORY_ATTRIBUTES[] = "SELECT Id,name FROM poiattribute WHERE Id IN (SELECT poiattribute_Id FROM hasattribute WHERE poicategory_Id IS ";
+static const char* SQL_REQUEST_GET_AVAILABLE_AREA = "SELECT leftlongitude,bottomlatitude,rightlongitude,toplatitude FROM availablearea;";
+static const char* SQL_REQUEST_GET_PARENT_CATEGORIES = "SELECT parentId FROM poicategorykinship WHERE childId IS ";
+static const char* SQL_REQUEST_GET_CHILD_CATEGORIES = "SELECT childId FROM poicategorykinship WHERE parentId IS ";
+static const char* SQL_REQUEST_GET_CATEGORY_ICONS = "SELECT url,format FROM iconset WHERE Id IS (SELECT iconset_Id FROM isdisplayedas WHERE poicategory_Id IS ";
+
+// 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();
+}
+
+
PoiManagerServerStub::PoiManagerServerStub() {
m_version.versionMajor = 1;
m_version.versionMicro = 0;
m_version.versionMinor = 0;
- m_version.date = "19-12-2012";
+ m_version.date = "19-13-2015";
+ m_rootCategory = ALL_CATEGORIES; //by default
+ m_languageCode = "eng";
+ m_countryCode = "USA";
+ m_scriptCode = "Latn";
}
@@ -63,3 +84,168 @@ void PoiManagerServerStub::getSupportedLocales(const std::shared_ptr<CommonAPI::
localeList.push_back(en_US);
localeList.push_back(fr_FR);
}
+
+void PoiManagerServerStub::getAvailableCategories(const std::shared_ptr<CommonAPI::ClientId> clientId, std::vector<POIServiceTypes::CategoryAndName>& categories)
+{
+ POIServiceTypes::CategoryAndName category;
+ uint16_t index;
+
+ // load categories from the embedded database
+ for (index = 0; index < m_availableCategories; index++)
+ {
+ category.uniqueId = m_availableCategoryTable[index].id;
+ category.topLevel = m_availableCategoryTable[index].top_level;
+ category.name = m_availableCategoryTable[index].name;
+ categories.push_back(category);
+ }
+
+}
+
+
+void PoiManagerServerStub::getRootCategory(const std::shared_ptr<CommonAPI::ClientId> clientId, POIServiceTypes::CategoryID& category)
+{
+ category = m_rootCategory;
+}
+
+bool PoiManagerServerStub::initDatabase(const char* poiDatabaseFileName)
+{
+ mp_database = new Database(poiDatabaseFileName);
+ refreshCategoryList();
+ return true; //maybe add some check of the file here
+}
+
+void PoiManagerServerStub::onError()
+{
+
+}
+
+// refresh the buffer that contains the categories related data, called each time a category is added or removed
+void PoiManagerServerStub::refreshCategoryList()
+{
+ std::string sqlQuery; //SQL request on database
+ std::ostringstream strStream; //temporary stream used for transformation into string
+ vector<vector<string> > query_result, additionnal_query_result;
+ vector<string > query_line, additionnal_query_line;
+ size_t index,sub_index;
+ categoryId_t value;
+ categoryId_t parent,child;
+ category_attribute_common_t attribute;
+
+ // retrieve the available categories (the ones that have at least one record)
+ query_result = mp_database->queryNotUTF(SQL_REQUEST_GET_AVAILABLE_CATEGORIES);
+ if (query_result.empty())
+ {
+ onError(); //database is not well populated
+ //todo something with table ?
+ }
+ else
+ { // Id,name
+ m_availableCategories = query_result.size(); //store the number of categories
+ for (index = 0; index < m_availableCategories; index++)
+ {
+ // read the result of the query and store it
+ query_line = query_result.at(index);
+ fromString<categoryId_t>(value,query_line[0], std::dec);
+ m_availableCategoryTable[index].id = value;
+
+ // retrieve the associated icons (for the moment, just one)
+ sqlQuery = SQL_REQUEST_GET_CATEGORY_ICONS;
+ strStream.str("");
+ strStream << value;
+ sqlQuery += strStream.str();
+ sqlQuery += ");";
+ additionnal_query_result = mp_database->queryNotUTF(sqlQuery.c_str());
+ if (additionnal_query_result.empty())
+ {
+ onError(); //database is not well populated
+ //todo something with table ?
+ }
+ else
+ {
+ additionnal_query_line = additionnal_query_result.at(0);
+ m_availableCategoryTable[index].icon = additionnal_query_line[0] + '.' + additionnal_query_line[1];
+ }
+
+ m_availableCategoryTable[index].name = query_line[1];
+
+ // retrieve the associated attributes
+ sqlQuery = SQL_REQUEST_GET_CATEGORY_ATTRIBUTES;
+ strStream.str("");
+ strStream << m_availableCategoryTable[index].id;
+ sqlQuery += strStream.str();
+ sqlQuery += ");";
+ additionnal_query_result = mp_database->queryNotUTF(sqlQuery.c_str());
+ if (additionnal_query_result.empty())
+ {
+ onError(); //database is not well populated
+ //todo something with table ?
+ }
+ else
+ {
+ for (sub_index = 0; sub_index <additionnal_query_result.size(); sub_index++)
+ {
+ additionnal_query_line = additionnal_query_result.at(sub_index);
+ fromString<attributeId_t>(attribute.id,additionnal_query_line[0], std::dec);
+ attribute.name = additionnal_query_line[1];
+ attribute.isSearched = false;
+ m_availableCategoryTable[index].attributeList.push_back(attribute);
+ }
+ }
+ m_availableCategoryTable[index].top_level = true; //this POC only manages predefined categories
+ m_availableCategoryTable[index].isSearch = false; //for the moment no categories selected
+ }
+ }
+
+ //retrieve the parents of the categories
+ //root category is the only one that is its own parent
+ for (index = 0; index < m_availableCategories; index++)
+ {
+ sqlQuery = SQL_REQUEST_GET_PARENT_CATEGORIES;
+ strStream.str("");
+ strStream << m_availableCategoryTable[index].id;
+ sqlQuery += strStream.str();
+ sqlQuery += ";";
+ query_result = mp_database->queryNotUTF(sqlQuery.c_str());
+ if (query_result.empty())
+ {
+ onError(); //database is not well populated
+ //todo something with table ?
+ }
+ else
+ {
+ for (parent=0;parent<query_result.size();parent++)
+ {
+ query_line = query_result.at(parent);
+ fromString<categoryId_t>(value,query_line[0], std::dec);
+ if (index == value)
+ m_rootCategory = index; //child is parent, so it's the root
+ m_availableCategoryTable[index].parentList.push_back(value);
+ }
+ }
+ }
+
+ //retrieve the children of the categories
+ for (index = 0; index < m_availableCategories; index++)
+ {
+ sqlQuery = SQL_REQUEST_GET_CHILD_CATEGORIES;
+ strStream.str("");
+ strStream << m_availableCategoryTable[index].id;
+ sqlQuery += strStream.str();
+ sqlQuery += ";";
+ query_result = mp_database->queryNotUTF(sqlQuery.c_str());
+ if (query_result.empty())
+ {
+ //no child
+ }
+ else
+ {
+ for (child=0;child<query_result.size();child++)
+ {
+ query_line = query_result.at(child);
+ fromString<categoryId_t>(value,query_line[0], std::dec);
+ m_availableCategoryTable[index].childList.push_back(value);
+ }
+ }
+ }
+
+}
diff --git a/src/poi-service/poi-manager-server/poi-manager-server-stub.h b/src/poi-service/poi-manager-server/poi-manager-server-stub.h
index 45949fd..42c0dc7 100644
--- a/src/poi-service/poi-manager-server/poi-manager-server-stub.h
+++ b/src/poi-service/poi-manager-server/poi-manager-server-stub.h
@@ -49,15 +49,22 @@ public:
void setLocale(const std::shared_ptr<CommonAPI::ClientId> clientId, std::string languageCode, std::string countryCode, std::string scriptCode);
void getLocale(const std::shared_ptr<CommonAPI::ClientId> clientId, std::string& languageCode, std::string& countryCode, std::string& scriptCode);
void getSupportedLocales(const std::shared_ptr<CommonAPI::ClientId> clientId, std::vector<POIServiceTypes::Locales>& localeList);
+ void getAvailableCategories(const std::shared_ptr<CommonAPI::ClientId> clientId, std::vector<POIServiceTypes::CategoryAndName>& categories);
+ void getRootCategory(const std::shared_ptr<CommonAPI::ClientId> clientId, POIServiceTypes::CategoryID& category);
+
+ bool initDatabase(const char* poiDatabaseFileName);
+
private:
NavigationTypes::Version m_version;
std::string m_languageCode, m_countryCode, m_scriptCode;
Database *mp_database; // database access
- POIServiceTypes::CategoryID m_availableCategories;
+ uint16_t m_availableCategories;
poi_category_common_t m_availableCategoryTable[MAX_CATEGORIES];
POIServiceTypes::CategoryID m_rootCategory;
+ void refreshCategoryList();
+ void onError();
};
#endif /* POIMANAGERSERVERSTUBIMPL_H_ */
diff --git a/src/poi-service/poi-server/main.cpp b/src/poi-service/poi-server/main.cpp
index b2b3d4a..2717f0d 100644
--- a/src/poi-service/poi-server/main.cpp
+++ b/src/poi-service/poi-server/main.cpp
@@ -42,6 +42,7 @@
#include "poi-server-class.h"
+
static const char* poiSearch_SERVICE_NAME = "org.genivi.poiservice.POISearch";
static const char* poiSearch_OBJECT_PATH = "/org/genivi/poiservice/POISearch";
static const char* poiConfiguration_SERVICE_NAME = "org.genivi.poiservice.Configuration";
@@ -682,6 +683,9 @@ poiSearchServer::poiSearchServer(DBus::Connection &connection, const char* poiDa
m_rootCategory = 0;
m_searchStatus = GENIVI_POISERVICE_NOT_STARTED;
m_routeHandle = INVALID_HANDLE;
+ m_languageCode = "eng";
+ m_countryCode = "USA";
+ m_scriptCode = "Latn";
// all the pois and the related stuff are included into the database at the startup
// so we can update some tables into the constructor
diff --git a/src/poi-service/script/poi-database-managed.db b/src/poi-service/script/poi-database-managed.db
new file mode 100644
index 0000000..1ce796e
--- /dev/null
+++ b/src/poi-service/script/poi-database-managed.db
Binary files differ