summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMorteza Damavandpeyma <morteza54dp@gmail.com>2017-01-19 15:43:12 +0100
committerMorteza Damavandpeyma <morteza54dp@gmail.com>2017-01-19 15:43:12 +0100
commit50e0a961b0fab17a25cda14d7d056ffc6aea4038 (patch)
treed8b6ef28ea9da659e6b8ced85c95e06973a87d99
parent6779d254cb4be8508ac4f4354d569b2096024cc6 (diff)
downloadpoi-service-50e0a961b0fab17a25cda14d7d056ffc6aea4038.tar.gz
Rewrite PoC and test applications for FreeTextSearchService
-rw-r--r--api/franca/navigation/freetextsearchservice/FreeTextSearch.fidl36
-rw-r--r--api/freetextsearch-service/genivi-freetextsearchservice-constants.xml7
-rw-r--r--src/freetextsearch-service/FreeTextSearchStubImpl.cpp418
-rw-r--r--src/freetextsearch-service/FreeTextSearchStubImpl.hpp94
-rw-r--r--src/freetextsearch-service/main.cpp61
-rw-r--r--test/freetextsearch-service/main.cpp401
6 files changed, 486 insertions, 531 deletions
diff --git a/api/franca/navigation/freetextsearchservice/FreeTextSearch.fidl b/api/franca/navigation/freetextsearchservice/FreeTextSearch.fidl
index ab8989f..f962e04 100644
--- a/api/franca/navigation/freetextsearchservice/FreeTextSearch.fidl
+++ b/api/franca/navigation/freetextsearchservice/FreeTextSearch.fidl
@@ -41,6 +41,18 @@ interface FreeTextSearch {
}
<**
+ @description: Contains constant values used in this interface
+ **>
+ enumeration FtsRangeConstants {
+ MAX_FUZZY_LEVEL = 5
+ MAX_SHAPES = 31
+ MAX_STRING_LIST_SIZE = 100
+ MAX_RESULTS = 500
+ MAX_STRING_LENGTH = 4095
+ MAX_LOCATION_HANDLES_LIST_SIZE = 4096
+ }
+
+ <**
@description: Search results are returned in some sequential pages. Each
page is identified with an ID called pageId. The pageId of the first
page is zero and pageIds are incremented by one for each subsequent page.
@@ -51,14 +63,14 @@ interface FreeTextSearch {
<**
@description: Type to represent most texts in this interface..
Character set = UNICODE
- Maximum length = 4095
+ Maximum length = MAX_STRING_LENGTH
**>
typedef FtsString is String
<**
@description: A list of strings
- maximum length = 100
+ maximum length = MAX_STRING_LIST_SIZE
**>
array FtsStringList of FtsString
@@ -104,14 +116,14 @@ interface FreeTextSearch {
<**
@description: A list of shapes.
- maximum length = 31
+ maximum length = MAX_SHAPES
**>
array ShapeList of Shape
<**
@description: A maximum number of results to be returned.
- Range[0:1000]
+ Range[0:MAX_RESULTS]
**>
typedef PageSize is UInt16
@@ -236,7 +248,7 @@ interface FreeTextSearch {
INVALID_PARAMETER_SEARCH_SHAPES = 11
<**
- @description: The fuzzy level is not in the allowed range: [0,5].
+ @description: The fuzzy level is not in the allowed range: [0,MAX_FUZZY_LEVEL].
**>
INVALID_PARAMETER_FUZZY_LEVEL = 12
@@ -255,7 +267,7 @@ interface FreeTextSearch {
<**
@description: A list of LocationHandles.
- maximum length = 4096
+ maximum length = MAX_LOCATION_HANDLES_LIST_SIZE
**>
array LocationHandleList of LocationHandle
@@ -419,7 +431,7 @@ interface FreeTextSearch {
<**
@description: A list of addresses.
- maximum length = 500
+ maximum length = MAX_RESULTS
**>
array Addresses of Address
@@ -491,7 +503,7 @@ interface FreeTextSearch {
<**
@description: A list of POIs.
- maximum length = 500
+ maximum length = MAX_RESULTS
**>
array POIs of POI
@@ -533,16 +545,16 @@ interface FreeTextSearch {
<**
@description: A list of POI categories.
- maximum length = 500
+ maximum length = MAX_RESULTS
**>
array POICategories of POICategory
<**
- @description: Indicates on a scale from 0 to 5 how fuzzy the search results can be.
+ @description: Indicates on a scale from 0 to MAX_FUZZY_LEVEL how fuzzy the search results can be.
0 means only an exact search is performed, 1 is the lowest level of fuzzy search
- and 5 means a very fuzzy search.
- Range[0:5]
+ and MAX_FUZZY_LEVEL means a very fuzzy search.
+ Range[0:MAX_FUZZY_LEVEL]
**>
typedef FuzzyLevel is Int8
diff --git a/api/freetextsearch-service/genivi-freetextsearchservice-constants.xml b/api/freetextsearch-service/genivi-freetextsearchservice-constants.xml
index 28178ca..906eb8a 100644
--- a/api/freetextsearch-service/genivi-freetextsearchservice-constants.xml
+++ b/api/freetextsearch-service/genivi-freetextsearchservice-constants.xml
@@ -8,6 +8,13 @@
-->
<constants name="FreeTextSearch">
+ <id name="FTSRANGECONSTANTS_MAX_FUZZY_LEVEL" value="5" />
+ <id name="FTSRANGECONSTANTS_MAX_SHAPES" value="31" />
+ <id name="FTSRANGECONSTANTS_MAX_STRING_LIST_SIZE" value="100" />
+ <id name="FTSRANGECONSTANTS_MAX_RESULTS" value="500" />
+ <id name="FTSRANGECONSTANTS_MAX_STRING_LENGTH" value="4095" />
+ <id name="FTSRANGECONSTANTS_MAX_LOCATION_HANDLES_LIST_SIZE" value="4096" />
+
<id name="SEARCHOPTION_ADDRESS" value="1" />
<id name="SEARCHOPTION_POI" value="2" />
<id name="SEARCHOPTION_POI_SUGGESTION" value="4" />
diff --git a/src/freetextsearch-service/FreeTextSearchStubImpl.cpp b/src/freetextsearch-service/FreeTextSearchStubImpl.cpp
index 79a5c96..556ff94 100644
--- a/src/freetextsearch-service/FreeTextSearchStubImpl.cpp
+++ b/src/freetextsearch-service/FreeTextSearchStubImpl.cpp
@@ -1,213 +1,237 @@
/**
-* @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@
-*/
+ * @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>
+ * \author Morteza Damavandpeyma <Morteza.Damavandpeyma@tomtom.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,
+ getVersionReply_t _reply)
+{
+ std::cout << "getVersion called." << std::endl;
-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);
+ CommonTypes::Version* version = new CommonTypes::Version(0, 1, 0, "today");
+ _reply(*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::ftsRequest(
+ const std::shared_ptr<CommonAPI::ClientId> _client,
+ FreeTextSearch::FtsString _inputString,
+ NavigationTypes::Coordinate2D _searchLocation,
+ FreeTextSearch::ShapeList _searchShapes, FreeTextSearch::PageSize _pageSize,
+ FreeTextSearch::SearchOptions _searchOptions,
+ FreeTextSearch::FtsString _searchConditions,
+ FreeTextSearch::FuzzyLevel _fuzzyLevel, ftsRequestReply_t _reply)
+{
+ std::cout << "ftsRequest called." << std::endl;
+ iSearchIsInProgress = true;
+
+ // Create new session handle.
+ iSessionHandle++;
+
+ // Start from first page
+ iPageId = 0;
+
+ _reply(FreeTextSearch::ftsRequestError::OK, iSessionHandle, iPageId);
+
+ // 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(iSessionHandle, iPageId, 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);
+ poiPtr->setDistance(1000);
+ poiPtr->setScore(1);
+ poiPtr->setFuzzyMatch(false);
+ poiPtr->setHasParents(false);
+ poiPtr->setHasChildren(false);
+ poiPtr->setDetourDistance(100);
+ poiPtr->setDetourTime(200);
+
+ pois.push_back(*poiPtr);
+ fireFtsResultPoisSelective(iSessionHandle, iPageId, pois, false);
+
+ FreeTextSearch::POICategories poiCategories;
+ fireFtsResultPoiSuggestionsSelective(iSessionHandle, iPageId, poiCategories);
+
+ fireFtsDoneSelective(iSessionHandle, iPageId, FreeTextSearch::FtsStatus::OK);
+ iSearchIsInProgress = false;
}
-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::ftsNextPage(
+ const std::shared_ptr<CommonAPI::ClientId> _client,
+ NavigationTypes::Handle _sessionHandle,
+ FreeTextSearch::SearchOptions _searchOptions, ftsNextPageReply_t _reply)
+{
+ std::cout << "ftsNextPage called." << std::endl;
+ if (iSearchIsInProgress)
+ {
+ std::cout << "There is a search in progress" << std::endl;
+ _reply(FreeTextSearch::ftsNextPageError::Literal::AlreadyInProgress, -1);
+ return;
+ }
+
+ iSearchIsInProgress = true;
+ // Note: searchOptions are ignored; always 1 address returned.
+
+ // Get the next page.
+ iPageId++;
+ _reply(FreeTextSearch::ftsNextPageError::Literal::OK, iPageId);
+
+ 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(iSessionHandle, iPageId, addresses, false);
+
+ fireFtsDoneSelective(iSessionHandle, iPageId, FreeTextSearch::FtsStatus::OK);
+ iSearchIsInProgress = false;
}
-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::ftsCancel(
+ const std::shared_ptr<CommonAPI::ClientId> _client,
+ NavigationTypes::Handle _sessionHandle, ftsCancelReply_t _reply)
+{
+ std::cout << "ftsCancel called." << std::endl;
+ _reply(FreeTextSearch::ftsCancelError::Literal::OK);
}
-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);
+void FreeTextSearchStubImpl::deleteLocationHandles(
+ const std::shared_ptr<CommonAPI::ClientId> _client,
+ FreeTextSearch::LocationHandleList _locationHandleList,
+ deleteLocationHandlesReply_t _reply)
+{
+ std::cout << "deleteLocationHandles called." << std::endl;
+ _reply();
}
diff --git a/src/freetextsearch-service/FreeTextSearchStubImpl.hpp b/src/freetextsearch-service/FreeTextSearchStubImpl.hpp
index 2f793dd..a6fbce3 100644
--- a/src/freetextsearch-service/FreeTextSearchStubImpl.hpp
+++ b/src/freetextsearch-service/FreeTextSearchStubImpl.hpp
@@ -1,54 +1,70 @@
/**
-* @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@
-*/
+ * @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>
+ * \author Morteza Damavandpeyma <Morteza.Damavandpeyma@tomtom.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 <v4/org/genivi/CommonTypes.hpp>
+#include <v4/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;
+using namespace v4::org::genivi::navigation;
+using namespace v4::org::genivi;
-class FreeTextSearchStubImpl: public FreeTextSearchStubDefault {
+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);
+ void getVersion(const std::shared_ptr<CommonAPI::ClientId> _client,
+ getVersionReply_t _reply) override;
+
+ void ftsRequest(const std::shared_ptr<CommonAPI::ClientId> _client,
+ FreeTextSearch::FtsString _inputString,
+ NavigationTypes::Coordinate2D _searchLocation,
+ FreeTextSearch::ShapeList _searchShapes,
+ FreeTextSearch::PageSize _pageSize,
+ FreeTextSearch::SearchOptions _searchOptions,
+ FreeTextSearch::FtsString _searchConditions,
+ FreeTextSearch::FuzzyLevel _fuzzyLevel, ftsRequestReply_t _reply)
+ override;
+
+ void ftsNextPage(const std::shared_ptr<CommonAPI::ClientId> _client,
+ NavigationTypes::Handle _sessionHandle,
+ FreeTextSearch::SearchOptions _searchOptions, ftsNextPageReply_t _reply)
+ override;
+
+ void ftsCancel(const std::shared_ptr<CommonAPI::ClientId> _client,
+ NavigationTypes::Handle _sessionHandle, ftsCancelReply_t _reply) override;
+
+ void deleteLocationHandles(const std::shared_ptr<CommonAPI::ClientId> _client,
+ FreeTextSearch::LocationHandleList _locationHandleList,
+ deleteLocationHandlesReply_t _reply) override;
+private:
+ NavigationTypes::Handle iSessionHandle = 0;
+ FreeTextSearch::PageId iPageId = 0;
+ bool iSearchIsInProgress = false;
};
diff --git a/src/freetextsearch-service/main.cpp b/src/freetextsearch-service/main.cpp
index 34aff3e..a5c7112 100644
--- a/src/freetextsearch-service/main.cpp
+++ b/src/freetextsearch-service/main.cpp
@@ -1,9 +1,24 @@
-/* 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/.
- */
+/**
+* @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>
+* \author Morteza Damavandpeyma <Morteza.Damavandpeyma@tomtom.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 <thread>
#include <iostream>
@@ -11,27 +26,19 @@
#include <CommonAPI/CommonAPI.hpp>
#include "FreeTextSearchStubImpl.hpp"
-int main() {
- CommonAPI::Runtime::setProperty("LogContext", "FTSS");
- CommonAPI::Runtime::setProperty("LibraryBase", "FreeTextSearch");
+int main()
+{
+ std::shared_ptr < CommonAPI::Runtime > runtime = CommonAPI::Runtime::get();
+ std::shared_ptr<FreeTextSearchStubImpl> myService = std::make_shared<FreeTextSearchStubImpl>();
+ runtime->registerService("local", "test", myService);
+ std::cout << "Successfully Registered FTS Service!" << std::endl;
- std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::get();
+ while (true)
+ {
+ std::cout << "Waiting for calls... (Abort with CTRL+C)" << std::endl;
+ std::this_thread::sleep_for(std::chrono::seconds(2));
+ }
- 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;
+ return 0;
}
+
diff --git a/test/freetextsearch-service/main.cpp b/test/freetextsearch-service/main.cpp
index 9240577..7ed6d53 100644
--- a/test/freetextsearch-service/main.cpp
+++ b/test/freetextsearch-service/main.cpp
@@ -6,6 +6,7 @@
* \copyright Copyright (C) 2016, PCA Peugeot Citroen
* \author Peter Goedegebure (Peter.Goedegebure@tomtom.com)
* \author Philippe Colliot <philippe.colliot@mpsa.com>
+* \author Morteza Damavandpeyma <Morteza.Damavandpeyma@tomtom.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,
@@ -18,309 +19,197 @@
*
* @licence end@
*/
+#include <thread>
#include <iostream>
+#include <sstream>
+#include <iterator>
+#include <algorithm>
#include <unistd.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/FreeTextSearchProxy.hpp>
-using namespace org::genivi;
-using namespace org::genivi::navigation;
using namespace v0::org::genivi::navigation::freetextsearchservice;
+using namespace v4::org::genivi::navigation;
+using namespace v4::org::genivi;
-// 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;
+bool ftsDoneIsReceived = false;
-FreeTextSearch::Addresses resultAddresses;
-FreeTextSearch::POIs resultPois;
+void printCommaSeperated(const std::vector<std::string>& strings)
+{
+ std::ostringstream ss;
+ std::copy(strings.begin(), strings.end() - 1, std::ostream_iterator<std::string>(ss, ", "));
+ ss << strings.back();
+ std::cout << ss.str();
+}
-void printAddress(FreeTextSearch::Address address) {
+void printAddress(const 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);
- }
+ printCommaSeperated(address.getPlaces());
+
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() << ")";
+ 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);
- }
-
+ printCommaSeperated(address.getPostalCodes());
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 << ", fuzzy=" << address.getFuzzyMatch();
std::cout << ", locationHandle=" << address.getLocationHandle();
std::cout << std::endl;
}
-void printPoi(FreeTextSearch::POI poi) {
+void printPoi(const 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);
- }
+ printCommaSeperated(poi.getBrandNames());
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);
- }
+ printCommaSeperated(poi.getPlace());
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);
- }
+ printCommaSeperated(poi.getPostalCode());
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 RegisterCallbacks(std::shared_ptr<FreeTextSearchProxy<> > fts)
+{
+ fts->getFtsResultAddressesSelectiveEvent().subscribe(
+ [&](NavigationTypes::Handle sessionHandle, FreeTextSearch::PageId pageId, FreeTextSearch::Addresses addresses, bool moreAvailable)
+ {
+ std::cout << std::endl << "FtsResultAddressesses"
+ << "\n\tsessionHandle = " << sessionHandle
+ << "\n\tpageId = " << pageId
+ << "\n\tmoreAvailable = " << moreAvailable
+ << std::endl;
+ std::for_each(addresses.begin(), addresses.end(), &printAddress);
+
+ });
+ fts->getFtsResultPoisSelectiveEvent().subscribe(
+ [&](NavigationTypes::Handle sessionHandle, FreeTextSearch::PageId pageId, FreeTextSearch::POIs pois, bool moreAvailable)
+ {
+ std::cout << std::endl << "FtsResultPOIs"
+ << "\n\tsessionHandle = " << sessionHandle
+ << "\n\tpageId = " << pageId
+ << "\n\tmoreAvailable = " << moreAvailable
+ << std::endl;
+ std::for_each(pois.begin(), pois.end(), &printPoi);
+ });
+ fts->getFtsResultPoiSuggestionsSelectiveEvent().subscribe(
+ [&](NavigationTypes::Handle sessionHandle, FreeTextSearch::PageId pageId, FreeTextSearch::POICategories poiCategories)
+ {
+ std::cout << std::endl << "PoiSuggestions"
+ << "\n\tsessionHandle = " << sessionHandle
+ << "\n\tpageId = " << pageId
+ << std::endl;
+ });
+ fts->getFtsDoneSelectiveEvent().subscribe(
+ [&](NavigationTypes::Handle sessionHandle, FreeTextSearch::PageId pageId, FreeTextSearch::FtsStatus status)
+ {
+ std::cout << std::endl << "FtsDone"
+ << "\n\tsessionHandle = " << sessionHandle
+ << "\n\tpageId = " << pageId
+ << "\n\tstatus = " << status
+ << std::endl;
+ ftsDoneIsReceived = true;
+ });
}
-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 WaitForFtsDoneSignal()
+{
+ std::cout << "Waiting for page results ...";
+ while (!ftsDoneIsReceived)
+ {
+ usleep(1000);
+ }
+ std::cout << 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::shared_ptr<FreeTextSearchProxy<>> fts = runtime->buildProxy<FreeTextSearchProxy>("local", "test");
+
+ while (!fts->isAvailable())
+ {
+ usleep(10);
+ }
+
+ RegisterCallbacks(fts);
+
+ CommonAPI::CallStatus callStatus;
+ CommonTypes::Version version;
+ FreeTextSearch::FtsString inputString = "TomTom Eindhoven";
+ NavigationTypes::Coordinate2D searchLocation(0, 0);
+ FreeTextSearch::ShapeList searchShapes;
+ FreeTextSearch::PageSize pageSize = 1;
+ FreeTextSearch::SearchOptions searchOptions = FreeTextSearch::SearchOption::ADDRESS || FreeTextSearch::SearchOption::POI;
+ FreeTextSearch::FtsString searchConditions = "";
+ FreeTextSearch::FuzzyLevel fuzzyLevel = 0;
+
+ FreeTextSearch::ftsRequestError errorFtsRequest;
+ FreeTextSearch::ftsNextPageError errorFtsNextPage;
+ FreeTextSearch::ftsCancelError errorFtsCancel;
+ FreeTextSearch::LocationHandleList locationHandleList;
+ NavigationTypes::Handle sessionHandle;
+ FreeTextSearch::PageId pageId;
+
+
+ std::cout << "Call getVersion (synchronous) *****************************************************"<< std::endl;
+ fts->getVersion(callStatus, version);
+ std::cout << "\tcallStatus = " << ((callStatus == CommonAPI::CallStatus::SUCCESS) ? "SUCCESS" : "NO_SUCCESS") << std::endl;
+ std::cout << "\tversion = " << version.getVersionMajor() << "." << version.getVersionMinor();
+ std::cout << "." << version.getVersionMicro() << " (" << version.getDate() << ")" << std::endl;
+
+
+ ftsDoneIsReceived = false;
+ fts->ftsRequest(inputString, searchLocation, searchShapes, pageSize, searchOptions, searchConditions, fuzzyLevel, callStatus, errorFtsRequest, sessionHandle, pageId);
+ std::cout << "Call ftsRequest (synchronous) *****************************************************" << std::endl;
+ std::cout << "\tcallStatus = " << ((callStatus == CommonAPI::CallStatus::SUCCESS) ? "SUCCESS" : "NO_SUCCESS") << std::endl;
+ std::cout << "\terror = " << errorFtsRequest << std::endl;
+ std::cout << "\tsessionHandle = " << sessionHandle << std::endl;
+ std::cout <<" \tpageId =" << pageId << std::endl;
+ WaitForFtsDoneSignal();
+
+
+ ftsDoneIsReceived = false;
+ fts->ftsNextPage(sessionHandle, searchOptions, callStatus, errorFtsNextPage, pageId);
+ std::cout << "Call ftsNextPage (synchronous) ****************************************************" <<std::endl;
+ std::cout << "\tcallStatus = " << ((callStatus == CommonAPI::CallStatus::SUCCESS) ? "SUCCESS" : "NO_SUCCESS") << std::endl;
+ std::cout << "\terror = " << errorFtsNextPage << std::endl;
+ std::cout << "\tpageId = " << pageId << std::endl;
+ WaitForFtsDoneSignal();
+
+
+ fts->ftsCancel(sessionHandle, callStatus, errorFtsCancel);
+ std::cout << "Call ftsCancel (synchronous) ******************************************************" <<std::endl;
+ std::cout << "\tcallStatus = " << ((callStatus == CommonAPI::CallStatus::SUCCESS) ? "SUCCESS" : "NO_SUCCESS") << std::endl;
+ std::cout << "\terror = " << errorFtsCancel << std::endl;
+
+
+ fts->deleteLocationHandles(locationHandleList, callStatus);
+ std::cout << "Call deleteLocationHandles (synchronous) ******************************************" <<std::endl;
+ std::cout << "\tcallStatus = " << ((callStatus == CommonAPI::CallStatus::SUCCESS) ? "SUCCESS" : "NO_SUCCESS") << std::endl;
+
+ return 0;
}
-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;
-}