diff options
-rw-r--r-- | src/freetextsearch-service/CMakeLists.txt | 104 | ||||
-rw-r--r-- | src/freetextsearch-service/FreeTextSearchStubImpl.cpp | 213 | ||||
-rw-r--r-- | src/freetextsearch-service/FreeTextSearchStubImpl.hpp | 55 | ||||
-rw-r--r-- | src/freetextsearch-service/main.cpp | 37 | ||||
-rw-r--r-- | src/poi-service/poi-manager-server/poi-manager-server-stub.cpp | 2 | ||||
-rw-r--r-- | src/poi-service/poi-manager-server/poi-manager-server-stub.h | 2 | ||||
-rw-r--r-- | test/freetextsearch-service/CMakeLists.txt | 104 | ||||
-rw-r--r-- | test/freetextsearch-service/main.cpp | 326 | ||||
-rw-r--r-- | test/poi-service/poi-manager-client/main.cpp | 2 |
9 files changed, 843 insertions, 2 deletions
diff --git a/src/freetextsearch-service/CMakeLists.txt b/src/freetextsearch-service/CMakeLists.txt new file mode 100644 index 0000000..028365f --- /dev/null +++ b/src/freetextsearch-service/CMakeLists.txt @@ -0,0 +1,104 @@ +########################################################################### +# @licence app begin@ +# SPDX-License-Identifier: MPL-2.0 +# +# Component Name: freetextsearch-server +# +# Author: Philippe Colliot +# +# Copyright (C) 2016, PCA Peugeot Citroën +# +# License: +# 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/. +# +# @licence end@ +########################################################################### +project(freetextsearch-server) +message(STATUS ${PROJECT_NAME}) + +cmake_minimum_required(VERSION 2.8) + +option(DBUS_LIB_PATH + "Path to the patched DBus library") + +set(CMAKE_VERBOSE_MAKEFILE on) +set(CMAKE_CXX_FLAGS "-Wall -std=c++0x") + +set(API_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../api") +set(FRANCA_DIR "${API_DIR}/franca") +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin) + +set(PARENT_API freetextsearchservice) +set(ROOT_API navigation) +set(API_VERSION_MAJOR 0) +set(API_VERSION "v${API_VERSION_MAJOR}") +set(COMMONAPI_GEN_DIR "${CMAKE_CURRENT_BINARY_DIR}/src-gen") +set(PRJ_SRC_GEN_PATH ${COMMONAPI_GEN_DIR}/${API_VERSION}/org/genivi/${ROOT_API}/${PARENT_API}) +set(PRJ_SRC_GEN_NAVIGATION_TYPES_PATH ${COMMONAPI_GEN_DIR}/org/genivi/${ROOT_API}) + +# DBus Path +if(DBUS_LIB_PATH) + message(STATUS "DBUS_LIB_PATH = " ${DBUS_LIB_PATH}) + set(DBUS_INCLUDE_DIRS ${DBUS_LIB_PATH}/include/dbus-1.0 ${DBUS_LIB_PATH}/lib/dbus-1.0/include) + set(DBUS_LIBDIR ${DBUS_LIB_PATH}/lib) + set(DBUS_LIBRARIES ${DBUS_LIB_PATH}/lib/libdbus-1.so) +else() + message(FATAL_ERROR "Please specify the path to your patched DBus library using -D DBUS_LIB_PATH=yourPath") +endif() + +# Packages +find_package(PkgConfig REQUIRED) +find_package(CommonAPI 3.1.5 REQUIRED) +find_package(CommonAPI-DBus 3.1.5 REQUIRED) + +#pkg_check_modules(DBUS "dbus-1 >= 1.8.4") // #to be fixed, it doesn't work so the paths are set manually (see above) +pkg_check_modules(COMMONAPI "CommonAPI >= 3.1.5") +pkg_check_modules(COMMONAPI_DBUS "CommonAPI-DBus >= 3.1.5") +pkg_check_modules(SQLITE3 REQUIRED sqlite3) +pkg_check_modules(GOBJECT gobject-2.0) +pkg_check_modules(GLIB REQUIRED glib-2.0) + +# Source Files +FILE(GLOB PRJ_LOCAL_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) + +add_subdirectory(${FRANCA_DIR}/navigation/freetextsearchservice "${CMAKE_CURRENT_BINARY_DIR}/franca") + +FILE(GLOB PRJ_STUB_GEN_SRCS ${PRJ_SRC_GEN_PATH}/*Stub*.cpp) +FILE(GLOB PRJ_STUB_GEN_TYPES ${PRJ_SRC_GEN_NAVIGATION_TYPES_PATH}/*Types*.cpp) +set(PRJ_SRCS ${PRJ_LOCAL_SRCS} ${PRJ_STUB_GEN_SRCS} ${PRJ_STUB_GEN_TYPES}) + +include_directories( + ${PRJ_SRC_GEN_PATH} + ${DBUS_INCLUDE_DIRS} + ${COMMONAPI_GEN_DIR} + ${COMMONAPI_INCLUDE_DIRS} + ${COMMONAPI_DBUS_INCLUDE_DIRS} + ${GOBJECT_INCLUDE_DIRS} + ${GLIB_INCLUDE_DIRS} + ${SQLITE3_INCLUDE_DIRS} +) + +link_directories( + ${DBUS_LIBDIR} + ${COMMONAPI_LIBDIR} + ${COMMONAPI_DBUS_LIBDIR} + ${GOBJECT_LIBRARY_DIRS} + ${GLIB_LIBRARY_DIRS} + ${SQLITE3_LIBRARY_DIRS} +) + +set(LIBRARIES + ${DBUS_LIBRARIES} + ${COMMONAPI_LIBRARIES} + ${COMMONAPI_DBUS_LIBRARIES} + ${GOBJECT_LIBRARIES} + ${GLIB_LIBRARIES} + ${SQLITE3_LIBRARIES} +) + +# Build service +add_executable(${PROJECT_NAME} ${PRJ_SRCS}) +target_link_libraries(${PROJECT_NAME} ${LIBRARIES}) +install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) diff --git a/src/freetextsearch-service/FreeTextSearchStubImpl.cpp b/src/freetextsearch-service/FreeTextSearchStubImpl.cpp new file mode 100644 index 0000000..79a5c96 --- /dev/null +++ b/src/freetextsearch-service/FreeTextSearchStubImpl.cpp @@ -0,0 +1,213 @@ +/** +* @licence app begin@ +* SPDX-License-Identifier: MPL-2.0 +* +* \copyright Copyright (C) 2015, 2016 TomTom International B.V. +* \copyright Copyright (C) 2016, PCA Peugeot Citroen +* \author Peter Goedegebure (Peter.Goedegebure@tomtom.com) +* \author Philippe Colliot <philippe.colliot@mpsa.com> +* 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 "FreeTextSearchStubImpl.hpp" + +NavigationTypes::Handle nextHandle = 1; + +FreeTextSearchStubImpl::FreeTextSearchStubImpl() { +} + +FreeTextSearchStubImpl::~FreeTextSearchStubImpl() { +} + +void FreeTextSearchStubImpl::getVersion(const std::shared_ptr<CommonAPI::ClientId> _client, + FreeTextSearch::RequestId _requestId, getVersionReply_t _reply) { + std::cout << "getVersion called." << std::endl; + + FreeTextSearch::RequestId responseId = _requestId; + CommonTypes::Version* version = new CommonTypes::Version(0, 1, 0, "today"); + _reply(responseId, *version); +} + +void FreeTextSearchStubImpl::ftsRequest(const std::shared_ptr<CommonAPI::ClientId> _client, FreeTextSearch::RequestId _requestId, + FreeTextSearch::FtsString _inputString, ::org::genivi::navigation::NavigationTypes::Coordinate2D _searchLocation, + FreeTextSearch::ShapeList _searchShapes, FreeTextSearch::PageSize _pageSize, + FreeTextSearch::SearchOptions _searchOptions, FreeTextSearch::FtsString _searchConditions, + FreeTextSearch::FuzzyLevel _fuzzyLevel, ftsRequestReply_t _reply) { + // TODO: introduce ftsRequestError value for OK. + FreeTextSearch::ftsRequestError error = FreeTextSearch::ftsRequestError::NoMoreFtsHandles; + + FreeTextSearch::RequestId responseId = _requestId; + + + // Note: No administration of freeTextSearchHandles, just increment a number. + NavigationTypes::Handle freeTextSearchHandle = nextHandle++; + _reply(error, responseId, freeTextSearchHandle); + + // Note: inputString is ignored, use fixed results. + // Note: searchLocation is ignored, use fixed results. + // TODO: introduce a value for 'not specified' for searchLocation (Coordinate2D). + // Note: searchShapes is ignored, use fixed results. + // Note: pageSize is ignored, use fixed size of 2. First page: 2 addresses (moreAvailable), 1 POI (no moreAvailable). + // Note: searchOptions is ignored, use fixed results. + // Note: searchConditions is ignored, use fixed results, + // Note: fuzzyLevel is ignored, used fixed results. + + FreeTextSearch::Addresses addresses; + FreeTextSearch::Address* addressPtr; + FreeTextSearch::FtsStringList* places; + FreeTextSearch::FtsStringList* postalCodes; + FreeTextSearch::StreetDetails* streetDetailsPtr; + + addressPtr = new FreeTextSearch::Address(); + NavigationTypes::LocationHandle locationHandle1 = 1234; + addressPtr->setLocationHandle(locationHandle1); + addressPtr->setCountryCode("NLD"); + addressPtr->setStateCode(""); + places = new FreeTextSearch::FtsStringList(); + places->push_back("Eindhoven"); + addressPtr->setPlaces(*places); + postalCodes = new FreeTextSearch::FtsStringList(); + postalCodes->push_back("5657 EB"); + addressPtr->setPostalCodes(*postalCodes); + streetDetailsPtr = new FreeTextSearch::StreetDetails(); + streetDetailsPtr->setStreetName("Luchthavenweg"); + streetDetailsPtr->setHouseNumber("48"); + streetDetailsPtr->setHouseNumberFromInput(""); + FreeTextSearch::AddressDetails addressDetails(*streetDetailsPtr); + addressPtr->setAddressDetails(addressDetails); + addressPtr->setMapCode("L2D.3Z"); + NavigationTypes::Coordinate2D* coordinate1 = new NavigationTypes::Coordinate2D(51.455664, 5.396336); + addressPtr->setCoordinate(*coordinate1); + addressPtr->setDistance(4566); + addressPtr->setScore(1000); + addressPtr->setFuzzyMatch(false); + addresses.push_back(*addressPtr); + + addressPtr = new FreeTextSearch::Address(); + NavigationTypes::LocationHandle locationHandle2 = 9876; + addressPtr->setLocationHandle(locationHandle2); + addressPtr->setCountryCode("NLD"); + addressPtr->setStateCode(""); + places = new FreeTextSearch::FtsStringList(); + places->push_back("'s Hertogenbosch"); + addressPtr->setPlaces(*places); + postalCodes = new FreeTextSearch::FtsStringList(); + postalCodes->push_back("<postal code>"); + addressPtr->setPostalCodes(*postalCodes); + streetDetailsPtr = new FreeTextSearch::StreetDetails(); + streetDetailsPtr->setStreetName("<street>"); + streetDetailsPtr->setHouseNumber("<housenumber>"); + streetDetailsPtr->setHouseNumberFromInput(""); + FreeTextSearch::AddressDetails addressDetails2(*streetDetailsPtr); + addressPtr->setAddressDetails(addressDetails2); + addressPtr->setMapCode("<map code>"); + NavigationTypes::Coordinate2D* coordinate2 = new NavigationTypes::Coordinate2D(52.434356, 17.555336); + addressPtr->setCoordinate(*coordinate2); + addressPtr->setDistance(196534); + addressPtr->setScore(578); + addressPtr->setFuzzyMatch(true); + addresses.push_back(*addressPtr); + + fireFtsResultAddressesSelective(responseId, addresses, true); + + FreeTextSearch::POIs pois; + FreeTextSearch::POI* poiPtr; + poiPtr = new FreeTextSearch::POI(); + NavigationTypes::LocationHandle locationHandle3 = 102934; + poiPtr->setLocationHandle(locationHandle3); + FreeTextSearch::POICategoryCode poiCategoryCode = 754; + poiPtr->setCategoryCode(poiCategoryCode); + FreeTextSearch::FtsStringList* brandNames; + brandNames = new FreeTextSearch::FtsStringList(); + brandNames->push_back("TomTom"); + brandNames->push_back("Bandit"); + poiPtr->setBrandNames(*brandNames); + poiPtr->setPoiName("TomTom Eindhoven"); + poiPtr->setAddress("Luchthavenweg 48, 5657 EB Eindhoven"); + places = new FreeTextSearch::FtsStringList(); + places->push_back("Eindhoven"); + poiPtr->setPlace(*places); + postalCodes = new FreeTextSearch::FtsStringList(); + postalCodes->push_back("5657 EB"); + poiPtr->setPostalCode(*postalCodes); + poiPtr->setMapCode("L2D.3Z"); + poiPtr->setCountryCode("NLD"); + poiPtr->setStateCode(""); + poiPtr->setTelephone("+31 40 84 44899"); + poiPtr->setCoordinate(*coordinate1); + pois.push_back(*poiPtr); + fireFtsResultPoisSelective(responseId, pois, false); + // TODO why is there no score for a POI? + + FreeTextSearch::FtsStatus ftsStatus = FreeTextSearch::FtsStatus::OK; + fireFtsDoneSelective(responseId, ftsStatus); +} + +void FreeTextSearchStubImpl::ftsNextPage(const std::shared_ptr<CommonAPI::ClientId> _client, FreeTextSearch::RequestId _requestId, + NavigationTypes::Handle _freeTextSearchHandle, FreeTextSearch::SearchOptions _searchOptions, + ftsNextPageReply_t _reply) { + // Note: No administration of freeTextSearchHandles, parameter is ignored. + // Note: searchOptions are ignored; always 1 address returned. + FreeTextSearch::RequestId responseId = _requestId; + + _reply(responseId); + + FreeTextSearch::FtsStatus ftsStatus = FreeTextSearch::FtsStatus::OK; + + FreeTextSearch::Addresses addresses; + FreeTextSearch::Address* addressPtr; + addressPtr = new FreeTextSearch::Address(); + NavigationTypes::LocationHandle locationHandle = 74658; + addressPtr->setLocationHandle(locationHandle); + addressPtr->setCountryCode("NLD"); + addressPtr->setStateCode(""); + FreeTextSearch::FtsStringList* places; + places = new FreeTextSearch::FtsStringList(); + places->push_back("Amsterdam"); + addressPtr->setPlaces(*places); + FreeTextSearch::FtsStringList* postalCodes; + postalCodes = new FreeTextSearch::FtsStringList(); + postalCodes->push_back("<postal code>"); + addressPtr->setPostalCodes(*postalCodes); + addressPtr->setMapCode("<map code>"); + FreeTextSearch::StreetDetails* streetDetailsPtr; + streetDetailsPtr = new FreeTextSearch::StreetDetails(); + streetDetailsPtr->setStreetName("<a street in Amsterdam>"); + streetDetailsPtr->setHouseNumber("<housenumber>"); + streetDetailsPtr->setHouseNumberFromInput(""); + FreeTextSearch::AddressDetails addressDetails(*streetDetailsPtr); + addressPtr->setAddressDetails(addressDetails); + NavigationTypes::Coordinate2D* coordinate = new NavigationTypes::Coordinate2D(50.123456, 9.838374); + addressPtr->setCoordinate(*coordinate); + addressPtr->setDistance(3009); + addressPtr->setScore(33); + addressPtr->setFuzzyMatch(false); + addresses.push_back(*addressPtr); + fireFtsResultAddressesSelective(responseId, addresses, false); + + fireFtsDoneSelective(responseId, ftsStatus); +} + +void FreeTextSearchStubImpl::ftsCancel(const std::shared_ptr<CommonAPI::ClientId> _client, FreeTextSearch::RequestId _requestId, + NavigationTypes::Handle _freeTextSearchHandle, ftsCancelReply_t _reply) { + FreeTextSearch::RequestId responseId = _requestId; + + _reply(responseId); +} + +void FreeTextSearchStubImpl::deleteLocationHandles(const std::shared_ptr<CommonAPI::ClientId> _client, FreeTextSearch::RequestId _requestId, + FreeTextSearch::LocationHandleList _locationHandleList, deleteLocationHandlesReply_t _reply) { + FreeTextSearch::RequestId responseId = _requestId; + + _reply(responseId); +} + diff --git a/src/freetextsearch-service/FreeTextSearchStubImpl.hpp b/src/freetextsearch-service/FreeTextSearchStubImpl.hpp new file mode 100644 index 0000000..2f793dd --- /dev/null +++ b/src/freetextsearch-service/FreeTextSearchStubImpl.hpp @@ -0,0 +1,55 @@ +/** +* @licence app begin@ +* SPDX-License-Identifier: MPL-2.0 +* +* \copyright Copyright (C) 2015, 2016 TomTom International B.V. +* \copyright Copyright (C) 2016, PCA Peugeot Citroen +* \author Peter Goedegebure (Peter.Goedegebure@tomtom.com) +* \author Philippe Colliot <philippe.colliot@mpsa.com> +* 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@ +*/ +#ifndef FREETEXTSEARCHSTUBIMPL_H_ +#define FREETEXTSEARCHSTUBIMPL_H_ + +#include <CommonAPI/CommonAPI.hpp> +#include <org/genivi/CommonTypes.hpp> +#include <org/genivi/navigation/NavigationTypes.hpp> +#include <v0/org/genivi/navigation/freetextsearchservice/FreeTextSearch.hpp> +#include <v0/org/genivi/navigation/freetextsearchservice/FreeTextSearchStubDefault.hpp> + +using namespace v0::org::genivi::navigation::freetextsearchservice; +using namespace org::genivi::navigation; +using namespace org::genivi; + +class FreeTextSearchStubImpl: public FreeTextSearchStubDefault { + +public: + FreeTextSearchStubImpl(); + ~FreeTextSearchStubImpl(); + void getVersion(const std::shared_ptr<CommonAPI::ClientId> _client, FreeTextSearch::RequestId _requestId, getVersionReply_t _reply); + void ftsRequest(const std::shared_ptr<CommonAPI::ClientId> _client, FreeTextSearch::RequestId _requestId, + FreeTextSearch::FtsString _inputString, ::org::genivi::navigation::NavigationTypes::Coordinate2D _searchLocation, + FreeTextSearch::ShapeList _searchShapes, FreeTextSearch::PageSize _pageSize, + FreeTextSearch::SearchOptions _searchOptions, FreeTextSearch::FtsString _searchConditions, + FreeTextSearch::FuzzyLevel _fuzzyLevel, ftsRequestReply_t _reply); + void ftsNextPage(const std::shared_ptr<CommonAPI::ClientId> _client, FreeTextSearch::RequestId _requestId, + NavigationTypes::Handle _freeTextSearchHandle, FreeTextSearch::SearchOptions _searchOptions, + ftsNextPageReply_t _reply); + void ftsCancel(const std::shared_ptr<CommonAPI::ClientId> _client, FreeTextSearch::RequestId _requestId, + NavigationTypes::Handle _freeTextSearchHandle, ftsCancelReply_t _reply); + void deleteLocationHandles(const std::shared_ptr<CommonAPI::ClientId> _client, FreeTextSearch::RequestId _requestId, + FreeTextSearch::LocationHandleList _locationHandleList, deleteLocationHandlesReply_t _reply); + +}; + +#endif /* FREETEXTSEARCHSTUBIMPL_H_ */ diff --git a/src/freetextsearch-service/main.cpp b/src/freetextsearch-service/main.cpp new file mode 100644 index 0000000..34aff3e --- /dev/null +++ b/src/freetextsearch-service/main.cpp @@ -0,0 +1,37 @@ +/* Copyright (C) 2015, 2016 TomTom International B.V. + * Author: Peter Goedegebure (Peter.Goedegebure@tomtom.com) + * 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 <thread> +#include <iostream> + +#include <CommonAPI/CommonAPI.hpp> +#include "FreeTextSearchStubImpl.hpp" + +int main() { + CommonAPI::Runtime::setProperty("LogContext", "FTSS"); + CommonAPI::Runtime::setProperty("LibraryBase", "FreeTextSearch"); + + std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::get(); + + std::string domain = "local"; + std::string instance = "org.genivi.navigation.freetextsearchservice"; + + std::shared_ptr<FreeTextSearchStubImpl> myService = std::make_shared<FreeTextSearchStubImpl>(); + while (!runtime->registerService(domain, instance, myService, "service-sample")) { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + + std::cout << "Successfully Registered Service!" << std::endl; + + while (true) { +// myService->incCounter(); // Change value of attribute, see stub implementation + std::cout << "Waiting for calls... (Abort with CTRL+C)" << std::endl; + std::this_thread::sleep_for(std::chrono::seconds(2)); + } + + return 0; +} 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 a81d690..137cf9b 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 @@ -1396,7 +1396,7 @@ void PoiManagerServerStub::removePOIs(const std::shared_ptr<CommonAPI::ClientId> } } -void PoiManagerServerStub::poiSearchStarted(const std::shared_ptr<CommonAPI::ClientId> _client, ::org::genivi::navigation::NavigationTypes::Handle _poiSearchHandle, uint16_t _maxSize, ::org::genivi::navigation::NavigationTypes::Coordinate3D _location, std::vector< ::v0_1::org::genivi::navigation::poiservice::POIServiceTypes::CategoryAndRadius> _poiCategories, std::vector< ::v0_1::org::genivi::navigation::poiservice::POIServiceTypes::AttributeDetails> _poiAttributes, std::string _inputString, uint16_t _sortOption, poiSearchStartedReply_t _reply) +void PoiManagerServerStub::poiSearchStarted(const std::shared_ptr<CommonAPI::ClientId> _client, ::org::genivi::navigation::NavigationTypes::Handle _poiSearchHandle, uint16_t _maxSize, ::org::genivi::navigation::NavigationTypes::Coordinate3D _location, std::vector< ::v0_1::org::genivi::navigation::poiservice::POIServiceTypes::CategoryAndRadius> _poiCategories, std::vector< ::v0_1::org::genivi::navigation::poiservice::POIServiceTypes::AttributeDetails> _poiAttributes, std::string _inputString, int32_t _sortOption, poiSearchStartedReply_t _reply) { POIServiceTypes::CategoryAndRadius categoryAndRadius; size_t index; 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 e9758c3..b835a40 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 @@ -203,7 +203,7 @@ public: void removeCategories(const std::shared_ptr<CommonAPI::ClientId> _client, std::vector< CommonTypes::CategoryID> _categories, removeCategoriesReply_t _reply); void addPOIs(const std::shared_ptr<CommonAPI::ClientId> _client, CommonTypes::CategoryID _unique_id, std::vector< POIServiceTypes::PoiAddedDetails> _poiList, addPOIsReply_t _reply); void removePOIs(const std::shared_ptr<CommonAPI::ClientId> _client, std::vector< POIServiceTypes::POI_ID> _ids, removePOIsReply_t _reply); - void poiSearchStarted(const std::shared_ptr<CommonAPI::ClientId> _client, ::org::genivi::navigation::NavigationTypes::Handle _poiSearchHandle, uint16_t _maxSize, ::org::genivi::navigation::NavigationTypes::Coordinate3D _location, std::vector< ::v0_1::org::genivi::navigation::poiservice::POIServiceTypes::CategoryAndRadius> _poiCategories, std::vector< ::v0_1::org::genivi::navigation::poiservice::POIServiceTypes::AttributeDetails> _poiAttributes, std::string _inputString, uint16_t _sortOption, poiSearchStartedReply_t _reply); + void poiSearchStarted(const std::shared_ptr<CommonAPI::ClientId> _client, ::org::genivi::navigation::NavigationTypes::Handle _poiSearchHandle, uint16_t _maxSize, ::org::genivi::navigation::NavigationTypes::Coordinate3D _location, std::vector< ::v0_1::org::genivi::navigation::poiservice::POIServiceTypes::CategoryAndRadius> _poiCategories, std::vector< ::v0_1::org::genivi::navigation::poiservice::POIServiceTypes::AttributeDetails> _poiAttributes, std::string _inputString, int32_t _sortOption, poiSearchStartedReply_t _reply); void poiSearchCanceled(const std::shared_ptr<CommonAPI::ClientId> _client, ::org::genivi::navigation::NavigationTypes::Handle _poiSearchHandle, poiSearchCanceledReply_t _reply); void resultListRequested(const std::shared_ptr<CommonAPI::ClientId> _client, POIServiceTypes::ContentAccessModuleID _camId, ::org::genivi::navigation::NavigationTypes::Handle _poiSearchHandle, std::vector< ::v0_1::org::genivi::navigation::poiservice::POIServiceTypes::AttributeID> _attributes, resultListRequestedReply_t _reply); void poiDetailsRequested(const std::shared_ptr<CommonAPI::ClientId> _client, std::vector< ::v0_1::org::genivi::navigation::poiservice::POIServiceTypes::POI_ID> _source_id, poiDetailsRequestedReply_t _reply); diff --git a/test/freetextsearch-service/CMakeLists.txt b/test/freetextsearch-service/CMakeLists.txt new file mode 100644 index 0000000..bee4781 --- /dev/null +++ b/test/freetextsearch-service/CMakeLists.txt @@ -0,0 +1,104 @@ +########################################################################### +# @licence app begin@ +# SPDX-License-Identifier: MPL-2.0 +# +# Component Name: freetextsearch-server +# +# Author: Philippe Colliot +# +# Copyright (C) 2016, PCA Peugeot Citroën +# +# License: +# 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/. +# +# @licence end@ +########################################################################### +project(freetextsearch-client) +message(STATUS ${PROJECT_NAME}) + +cmake_minimum_required(VERSION 2.8) + +option(DBUS_LIB_PATH + "Path to the patched DBus library") + +set(CMAKE_VERBOSE_MAKEFILE on) +set(CMAKE_CXX_FLAGS "-Wall -std=c++0x") + +set(API_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../api") +set(FRANCA_DIR "${API_DIR}/franca") +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin) + +set(PARENT_API freetextsearchservice) +set(ROOT_API navigation) +set(API_VERSION_MAJOR 0) +set(API_VERSION "v${API_VERSION_MAJOR}") +set(COMMONAPI_GEN_DIR "${CMAKE_CURRENT_BINARY_DIR}/src-gen") +set(PRJ_SRC_GEN_PATH ${COMMONAPI_GEN_DIR}/${API_VERSION}/org/genivi/${ROOT_API}/${PARENT_API}) +set(PRJ_SRC_GEN_NAVIGATION_TYPES_PATH ${COMMONAPI_GEN_DIR}/org/genivi/${ROOT_API}) + +# DBus Path +if(DBUS_LIB_PATH) + message(STATUS "DBUS_LIB_PATH = " ${DBUS_LIB_PATH}) + set(DBUS_INCLUDE_DIRS ${DBUS_LIB_PATH}/include/dbus-1.0 ${DBUS_LIB_PATH}/lib/dbus-1.0/include) + set(DBUS_LIBDIR ${DBUS_LIB_PATH}/lib) + set(DBUS_LIBRARIES ${DBUS_LIB_PATH}/lib/libdbus-1.so) +else() + message(FATAL_ERROR "Please specify the path to your patched DBus library using -D DBUS_LIB_PATH=yourPath") +endif() + +# Packages +find_package(PkgConfig REQUIRED) +find_package(CommonAPI 3.1.5 REQUIRED) +find_package(CommonAPI-DBus 3.1.5 REQUIRED) + +#pkg_check_modules(DBUS "dbus-1 >= 1.8.4") // #to be fixed, it doesn't work so the paths are set manually (see above) +pkg_check_modules(COMMONAPI "CommonAPI >= 3.1.5") +pkg_check_modules(COMMONAPI_DBUS "CommonAPI-DBus >= 3.1.5") +pkg_check_modules(SQLITE3 REQUIRED sqlite3) +pkg_check_modules(GOBJECT gobject-2.0) +pkg_check_modules(GLIB REQUIRED glib-2.0) + +# Source Files +FILE(GLOB PRJ_LOCAL_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) + +add_subdirectory(${FRANCA_DIR}/navigation/freetextsearchservice "${CMAKE_CURRENT_BINARY_DIR}/franca") + +FILE(GLOB PRJ_STUB_GEN_SRCS ${PRJ_SRC_GEN_PATH}/*Stub*.cpp) +FILE(GLOB PRJ_STUB_GEN_TYPES ${PRJ_SRC_GEN_NAVIGATION_TYPES_PATH}/*Types*.cpp) +set(PRJ_SRCS ${PRJ_LOCAL_SRCS} ${PRJ_STUB_GEN_SRCS} ${PRJ_STUB_GEN_TYPES}) + +include_directories( + ${PRJ_SRC_GEN_PATH} + ${DBUS_INCLUDE_DIRS} + ${COMMONAPI_GEN_DIR} + ${COMMONAPI_INCLUDE_DIRS} + ${COMMONAPI_DBUS_INCLUDE_DIRS} + ${GOBJECT_INCLUDE_DIRS} + ${GLIB_INCLUDE_DIRS} + ${SQLITE3_INCLUDE_DIRS} +) + +link_directories( + ${DBUS_LIBDIR} + ${COMMONAPI_LIBDIR} + ${COMMONAPI_DBUS_LIBDIR} + ${GOBJECT_LIBRARY_DIRS} + ${GLIB_LIBRARY_DIRS} + ${SQLITE3_LIBRARY_DIRS} +) + +set(LIBRARIES + ${DBUS_LIBRARIES} + ${COMMONAPI_LIBRARIES} + ${COMMONAPI_DBUS_LIBRARIES} + ${GOBJECT_LIBRARIES} + ${GLIB_LIBRARIES} + ${SQLITE3_LIBRARIES} +) + +# Build service +add_executable(${PROJECT_NAME} ${PRJ_SRCS}) +target_link_libraries(${PROJECT_NAME} ${LIBRARIES}) +install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) diff --git a/test/freetextsearch-service/main.cpp b/test/freetextsearch-service/main.cpp new file mode 100644 index 0000000..9240577 --- /dev/null +++ b/test/freetextsearch-service/main.cpp @@ -0,0 +1,326 @@ +/** +* @licence app begin@ +* SPDX-License-Identifier: MPL-2.0 +* +* \copyright Copyright (C) 2015, 2016 TomTom International B.V. +* \copyright Copyright (C) 2016, PCA Peugeot Citroen +* \author Peter Goedegebure (Peter.Goedegebure@tomtom.com) +* \author Philippe Colliot <philippe.colliot@mpsa.com> +* 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 <iostream> +#include <unistd.h> + +#include <CommonAPI/CommonAPI.hpp> +#include <org/genivi/CommonTypes.hpp> +#include <org/genivi/navigation/NavigationTypes.hpp> +#include <v0/org/genivi/navigation/freetextsearchservice/FreeTextSearchProxy.hpp> + +using namespace org::genivi; +using namespace org::genivi::navigation; +using namespace v0::org::genivi::navigation::freetextsearchservice; + +// Sequence: +// - get version info synchronous +// - start asynchronous request +// - when done is received (pageDone), request next page. +// - when done is received (pageDone), cancel the request and free the locationHandles. +// - when responses are received (cancelDone, freeHandleDone), we're done. +// +bool pageDone = false; +bool cancelDone = false; +bool freeHandlesDone = false; + +FreeTextSearch::Addresses resultAddresses; +FreeTextSearch::POIs resultPois; + +void printAddress(FreeTextSearch::Address address) { + std::cout << "Address: "; + std::cout << "score=" << address.getScore(); + std::cout << ", countryCode=" << address.getCountryCode(); + std::cout << ", stateCode=" << address.getStateCode(); + std::cout << ", mapCode=" << address.getMapCode(); + std::cout << ", places="; + FreeTextSearch::FtsStringList places = address.getPlaces(); + bool first = true; + for (unsigned int index = 0; index < places.size(); index++) { + if (first) { + first = false; + } else { + std::cout << ","; + } + std::cout << places.at(index); + } + FreeTextSearch::AddressDetails addressDetails = address.getAddressDetails(); + if (addressDetails.isType<FreeTextSearch::StreetDetails>()) { + FreeTextSearch::StreetDetails streetDetails = addressDetails.get<FreeTextSearch::StreetDetails>(); + std::cout << ", streetName=" << streetDetails.getStreetName(); + std::cout << ", houseNumber=" << streetDetails.getHouseNumber(); + std::cout << ", (fromInput=" << streetDetails.getHouseNumberFromInput() << ")"; + } + + std::cout << ", postalCodes="; + FreeTextSearch::FtsStringList postalCodes = address.getPostalCodes(); + first = true; + for (unsigned int index = 0; index < postalCodes.size(); index++) { + if (first) { + first = false; + } else { + std::cout << ","; + } + std::cout << postalCodes.at(index); + } + + NavigationTypes::Coordinate2D coordinate = address.getCoordinate(); + std::cout << ", coordinate=(" << coordinate.getLatitude() << "," << coordinate.getLongitude() << ")"; + std::cout << ", distance=" << address.getDistance(); + if (address.getFuzzyMatch()) { + std::cout << ", fuzzy"; + } + std::cout << ", locationHandle=" << address.getLocationHandle(); + std::cout << std::endl; +} + +void printPoi(FreeTextSearch::POI poi) { + std::cout << "POI: "; + std::cout << "poiName=" << poi.getPoiName(); + std::cout << ", brandNames="; + FreeTextSearch::FtsStringList brandNames = poi.getBrandNames(); + bool first = true; + for (unsigned int index = 0; index < brandNames.size(); index++) { + if (first) { + first = false; + } else { + std::cout << ","; + } + std::cout << brandNames.at(index); + } + std::cout << ", categoryCode=" << poi.getCategoryCode(); + std::cout << ", countryCode=" << poi.getCountryCode(); + std::cout << ", stateCode=" << poi.getStateCode(); + std::cout << ", mapCode=" << poi.getMapCode(); + std::cout << ", places="; + FreeTextSearch::FtsStringList places = poi.getPlace(); + first = true; + for (unsigned int index = 0; index < places.size(); index++) { + if (first) { + first = false; + } else { + std::cout << ","; + } + std::cout << places.at(index); + } + std::cout << ", postalCodes="; + FreeTextSearch::FtsStringList postalCodes = poi.getPostalCode(); + first = true; + for (unsigned int index = 0; index < postalCodes.size(); index++) { + if (first) { + first = false; + } else { + std::cout << ","; + } + std::cout << postalCodes.at(index); + } + std::cout << ", address=" << poi.getAddress(); + std::cout << ", telephone=" << poi.getTelephone(); + + NavigationTypes::Coordinate2D coordinate = poi.getCoordinate(); + std::cout << ", coordinate=(" << coordinate.getLatitude() << "," << coordinate.getLongitude() << ")"; + std::cout << ", locationHandle=" << poi.getLocationHandle(); + std::cout << std::endl; +} + +void printAllResults(std::string title) { + std::cout << std::endl; + std::cout << title << " - current results:" << std::endl; + + // TODO merge Addresses and POIs based on score. For first print all addresses and then all POIs. + for (unsigned int index=0; index < resultAddresses.size(); ++index) { + printAddress(resultAddresses.at(index)); + } + + for (unsigned int index=0; index < resultPois.size(); ++index) { + printPoi(resultPois.at(index)); + } + + std::cout << std::endl; +} + +void ftsRequestCallback(const CommonAPI::CallStatus& callStatus, + const FreeTextSearch::ftsRequestError& error, const FreeTextSearch::RequestId& responseId, + const NavigationTypes::Handle& freeTextSearchHandle) { + std::cout << " Result of ftsRequest (asynchronous)" << error << std::endl; + std::cout << " callStatus: " << ((callStatus == CommonAPI::CallStatus::SUCCESS) ? "SUCCESS" : "NO_SUCCESS") + << std::endl; + std::cout << " error = " << error << std::endl; + std::cout << " responseId = " << responseId << std::endl; + std::cout << " freeTextSearchHandle = " << freeTextSearchHandle << std::endl; +} + +void ftsNextPageCallback(const CommonAPI::CallStatus& callStatus, + const FreeTextSearch::RequestId& responseId) { + std::cout << " Result of ftsNextPage (asynchronous)" << std::endl; + std::cout << " callStatus: " << ((callStatus == CommonAPI::CallStatus::SUCCESS) ? "SUCCESS" : "NO_SUCCESS") + << std::endl; + std::cout << " responseId = " << responseId << std::endl; +} + +void ftsCancelCallback(const CommonAPI::CallStatus& callStatus, + const FreeTextSearch::RequestId& responseId) { + std::cout << " Result of ftsCancel (asynchronous)" << std::endl; + std::cout << " callStatus: " << ((callStatus == CommonAPI::CallStatus::SUCCESS) ? "SUCCESS" : "NO_SUCCESS") + << std::endl; + std::cout << " responseId = " << responseId << std::endl; + + cancelDone = true; +} + +void deleteLocationHandlesCallback(const CommonAPI::CallStatus& callStatus, + const FreeTextSearch::RequestId& responseId) { + std::cout << " Result of deleteLocationHandles (asynchronous)" << std::endl; + std::cout << " callStatus: " << ((callStatus == CommonAPI::CallStatus::SUCCESS) ? "SUCCESS" : "NO_SUCCESS") + << std::endl; + std::cout << " responseId = " << responseId << std::endl; + + freeHandlesDone = true; +} + +int main() { + std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::get(); + + std::string domain = "local"; + std::string instance = "org.genivi.navigation.freetextsearchservice"; + + std::shared_ptr<FreeTextSearchProxyDefault> myProxy = runtime->buildProxy < FreeTextSearchProxy > (domain, instance); + + while (!myProxy->isAvailable()) { + usleep(10); + } + + /* + * Subscribe to broadcasts + */ + myProxy->getFtsResultAddressesSelectiveEvent().subscribe([&](FreeTextSearch::RequestId responseId, FreeTextSearch::Addresses addresses, bool moreAvailable){ + std::cout << "Received ftsResultAddresses, responseId = " << responseId << std::endl; + std::cout << "moreAvailable = " << moreAvailable << std::endl; + + for (unsigned int index=0; index < addresses.size(); ++index) { + resultAddresses.push_back(addresses.at(index)); + } + + printAllResults("New addresses received"); + }); + + myProxy->getFtsResultPoisSelectiveEvent().subscribe([&](FreeTextSearch::RequestId responseId, FreeTextSearch::POIs pois, bool moreAvailable){ + std::cout << "Received ftsResultPois, responseId = " << responseId << std::endl; + std::cout << "moreAvailable = " << moreAvailable << std::endl; + + for (unsigned int index=0; index < pois.size(); ++index) { + resultPois.push_back(pois.at(index)); + } + + printAllResults("New POIs received"); + }); + + myProxy->getFtsDoneSelectiveEvent().subscribe([&](FreeTextSearch::RequestId responseId, FreeTextSearch::FtsStatus ftsStatus) { + std::cout << "Received ftsDone, responseId = " << responseId << std::endl; + std::cout << "ftsStatus = " << ftsStatus << std::endl; + + pageDone = true; + }); + + FreeTextSearch::RequestId requestId = 0; + FreeTextSearch::RequestId responseId; + CommonAPI::CallStatus callStatus; + + // Get the API version info. + CommonTypes::Version version; + std::cout << "Call getVersion (synchronous), requesId = " << requestId << std::endl; + myProxy->getVersion(requestId, callStatus, responseId, version); + std::cout << " callStatus: " << ((callStatus == CommonAPI::CallStatus::SUCCESS) ? "SUCCESS" : "NO_SUCCESS") + << std::endl; + std::cout << " responseId = " << responseId << std::endl; + std::cout << " version = " << version.getVersionMajor() << "." << version.getVersionMinor() + << "." << version.getVersionMicro() << " (" << version.getDate() << ")" << std::endl; + + requestId++; + + // Clear results + resultAddresses.clear(); + resultPois.clear(); + + // Search parameters + FreeTextSearch::FtsString inputString = "lucht"; + NavigationTypes::Coordinate2D* searchLocation = new NavigationTypes::Coordinate2D(48.053250, 8.324500); + FreeTextSearch::ShapeList searchShapes; + FreeTextSearch::PageSize pageSize = 20; + FreeTextSearch::SearchOptions searchOptions = FreeTextSearch::SearchOption::ADDRESS; + FreeTextSearch::FtsString searchConditions = ""; + FreeTextSearch::FuzzyLevel fuzzyLevel = 5; + // TODO At least the synchronous call always has the 'error' parameter. So there has to be a 'NO ERROR' value defined. + FreeTextSearch::ftsRequestError error; + NavigationTypes::Handle freeTextSearchHandle; + + pageDone = false; + std::cout << "Call ftsRequest (asynchronous), requesId = " << requestId << std::endl; + std::function<void(const CommonAPI::CallStatus&, + const FreeTextSearch::ftsRequestError&, const FreeTextSearch::RequestId&, + const NavigationTypes::Handle&)> ftsRequestCallbackFunction = ftsRequestCallback; + myProxy->ftsRequestAsync(requestId, inputString, *searchLocation, searchShapes, pageSize, searchOptions, searchConditions, fuzzyLevel, + ftsRequestCallbackFunction); + + while (!pageDone) { + std::cout << "Waiting for first page results." << std::endl; + usleep(50000); + } + + requestId++; + pageDone = false; + std::cout << "Call ftsNext (asynchronous), requesId = " << requestId << std::endl; + std::function<void(const CommonAPI::CallStatus&, + const FreeTextSearch::RequestId&)> ftsNextPageCallbackFunction = ftsNextPageCallback; + myProxy->ftsNextPageAsync(requestId, freeTextSearchHandle, searchOptions, ftsNextPageCallbackFunction); + + while (!pageDone) { + std::cout << "Waiting for second page results." << std::endl; + usleep(50000); + } + + requestId++; + cancelDone = false; + freeHandlesDone = false; + std::cout << "Call ftsCancel (asynchronous), requesId = " << requestId << std::endl; + std::function<void(const CommonAPI::CallStatus&, + const FreeTextSearch::RequestId&)> ftsCancelCallbackFunction = ftsCancelCallback; + myProxy->ftsCancelAsync(requestId, freeTextSearchHandle, ftsCancelCallbackFunction); + + requestId++; + std::cout << "Call deleteLocationHandles (asynchronous), requesId = " << requestId << std::endl; + std::function<void(const CommonAPI::CallStatus&, + const FreeTextSearch::RequestId&)> deleteLocationHandlesCallbackFunction = deleteLocationHandlesCallback; + FreeTextSearch::LocationHandleList locationHandleList; + myProxy->deleteLocationHandlesAsync(requestId, locationHandleList, deleteLocationHandlesCallbackFunction); + + + while (!(cancelDone && freeHandlesDone)) { + std::cout << "Waiting for cancel and deleteHandles to finish." << std::endl; + usleep(50000); + } + + +// while (true) { +// std::this_thread::sleep_for(std::chrono::seconds(5)); +// } + + return 0; +} diff --git a/test/poi-service/poi-manager-client/main.cpp b/test/poi-service/poi-manager-client/main.cpp index 5db73db..e64d4f5 100644 --- a/test/poi-service/poi-manager-client/main.cpp +++ b/test/poi-service/poi-manager-client/main.cpp @@ -40,6 +40,8 @@ #include <functional> #include <CommonAPI/CommonAPI.hpp> //Defined in the Common API Runtime library +#include <org/genivi/navigation/NavigationTypes.hpp> +#include <v0/org/genivi/navigation/poiservice/POIServiceTypes.hpp> #include <v0/org/genivi/navigation/poiservice/POIContentAccessModuleProxy.hpp> #include "poi-common-data-model.h" |