diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/here/here_api.cpp | 8 | ||||
-rw-r--r-- | src/here/here_base.cpp | 77 | ||||
-rw-r--r-- | src/here/here_base.h | 2 | ||||
-rwxr-xr-x | src/here/here_geocode.cpp | 11 | ||||
-rwxr-xr-x | src/here/here_geocode.h | 1 | ||||
-rwxr-xr-x | src/here/here_manager.cpp | 111 | ||||
-rwxr-xr-x | src/here/here_manager.h | 5 | ||||
-rwxr-xr-x | src/here/here_place.cpp | 198 | ||||
-rwxr-xr-x | src/here/here_place.h | 8 | ||||
-rwxr-xr-x | src/here/here_revgeocode.cpp | 11 | ||||
-rwxr-xr-x | src/here/here_revgeocode.h | 1 | ||||
-rwxr-xr-x | src/here/here_route.cpp | 10 | ||||
-rwxr-xr-x | src/here/here_route.h | 1 | ||||
-rwxr-xr-x | src/here/here_utils.cpp | 84 | ||||
-rwxr-xr-x | src/here/here_utils.h | 3 |
15 files changed, 433 insertions, 98 deletions
diff --git a/src/here/here_api.cpp b/src/here/here_api.cpp index 94de668..9de2ef9 100755 --- a/src/here/here_api.cpp +++ b/src/here/here_api.cpp @@ -22,7 +22,6 @@ #include "here_route.h" #include <common/HereConfig.h> - using namespace HERE_PLUGIN_NAMESPACE_PREFIX; int HerePluginInit(maps_plugin_h *hPlugin) @@ -30,6 +29,10 @@ int HerePluginInit(maps_plugin_h *hPlugin) if (!hPlugin) return HERE_ERROR_INVALID_PARAMETER; + here_error_e error = HereManager::CheckAgreement(); + if (error != HERE_ERROR_NONE) + return error; + HereManager::Create(); if (!HereManager::GetHandler()) @@ -46,10 +49,7 @@ int HerePluginShutdown(maps_plugin_h hPlugin) return HERE_ERROR_INVALID_PARAMETER; if (HereManager::GetHandler()) - { - HereManager::GetHandler()->TerminateAllServices(); HereManager::GetHandler()->Close(); - } return HERE_ERROR_NONE; } diff --git a/src/here/here_base.cpp b/src/here/here_base.cpp index bd8a87e..43a7fbe 100644 --- a/src/here/here_base.cpp +++ b/src/here/here_base.cpp @@ -16,6 +16,11 @@ #include "here_base.h" #include "here_manager.h" +#include <common/CommunicationError.h> +#include <common/ParserError.h> +#include <finder/FinderError.h> +#include <routes/RouterError.h> +#include <tilefetcher/TileFetcherError.h> HERE_PLUGIN_BEGIN_NAMESPACE @@ -25,6 +30,9 @@ HereBase::HereBase() m_nRestReqId = 0; m_bCanceled = 0; m_nReqId = 0; + + m_pCbFunc = NULL; + m_pUserData = NULL; } HereBase::~HereBase() @@ -53,4 +61,73 @@ gint HereBase::GetRestReqId(void) return m_nRestReqId; } +gint HereBase::GetErrorCode(const BaseReply& Reply) +{ + ErrorBase *pError = (ErrorBase*)Reply.GetError(); + maps_error_e error = MAPS_ERROR_UNKNOWN; + CommunicationError *commErr; + FinderError *finderErr; + String errMsg = ""; + + + if (pError) + { + ErrorBase::ErrorCategory category = pError->GetErrorCategory(); + + switch(category) + { + case ErrorBase::ErrorCategory::EC_CommunicationsError: + commErr = (CommunicationError*)pError; + errMsg = commErr->ToString(); + + if (commErr->GetErrorCode() == CommunicationError::ErrorCode::CE_NetworkError) + error = MAPS_ERROR_NETWORK_UNREACHABLE; + else if (commErr->GetErrorCode() == CommunicationError::ErrorCode::CE_RestEngineError) + error = MAPS_ERROR_INVALID_OPERATION; + else + error = HereUtils::ConvertHttpCodeToMapsError(commErr->GetHttpStatusCode()); + break; + + case ErrorBase::ErrorCategory::EC_ParserError: + errMsg = ((ParserError*)pError)->ToString(); + error = MAPS_ERROR_INVALID_OPERATION; + break; + + case ErrorBase::ErrorCategory::EC_RouterError: + errMsg = ((RouterError*)pError)->ToString(); + error = MAPS_ERROR_INVALID_OPERATION; + break; + + case ErrorBase::ErrorCategory::EC_TileMapError: + errMsg = ((TileFetcherError*)pError)->ToString(); + error = MAPS_ERROR_INVALID_OPERATION; + break; + + case ErrorBase::ErrorCategory::EC_FinderError: + finderErr = (FinderError*)pError; + //errMsg = finderErr->ToString(); + + if (finderErr->GetErrorType() == FinderError::ErrorType::ET_InvalidQueryArguments) + error = MAPS_ERROR_INVALID_PARAMETER; + else if (finderErr->GetErrorType() == FinderError::ErrorType::ET_InvalidCredentials) + error = MAPS_ERROR_KEY_NOT_AVAILABLE; + else + error = MAPS_ERROR_INVALID_OPERATION; + break; + default: + error = MAPS_ERROR_INVALID_OPERATION; + break; + } + } + + if (error != MAPS_ERROR_NONE) { + if (errMsg.size() > 0) errMsg += ". "; + MAPS_LOGE("ERROR: %s%s (%s, %ld)", errMsg.data(), + ConverHereErrorToString(ConvertToHereError(error)), + ConvertMapsErrorToChar(error), error); + } + + return error; +} + HERE_PLUGIN_END_NAMESPACE diff --git a/src/here/here_base.h b/src/here/here_base.h index 8d085e0..6d91848 100644 --- a/src/here/here_base.h +++ b/src/here/here_base.h @@ -19,6 +19,7 @@ //plug-in header #include "here_utils.h" +#include <common/BaseReply.h> HERE_PLUGIN_BEGIN_NAMESPACE @@ -41,6 +42,7 @@ public: gint GetReqId(void); gint GetRestReqId(void); + gint GetErrorCode(const BaseReply& Reply); protected: gint m_nReqId; diff --git a/src/here/here_geocode.cpp b/src/here/here_geocode.cpp index b00ef61..22f7c65 100755 --- a/src/here/here_geocode.cpp +++ b/src/here/here_geocode.cpp @@ -41,7 +41,7 @@ here_error_e HereGeocode::PrepareQuery() if (m_pQuery) return HERE_ERROR_PERMISSION_DENIED; - m_pQuery = new GeoCoderQuery(); + m_pQuery = new (std::nothrow) GeoCoderQuery(); if (!m_pQuery) return HERE_ERROR_OUT_OF_MEMORY; @@ -232,7 +232,7 @@ void HereGeocode::OnGeoCoderReply(const GeoCoderReply& Reply) if (nResults == 0) { ((maps_service_geocode_cb)m_pCbFunc)(MAPS_ERROR_NOT_FOUND, m_nReqId, - 0, 1, NULL, m_pUserData); + 0, 0, NULL, m_pUserData); delete this; return; } @@ -273,5 +273,12 @@ void HereGeocode::OnGeoCoderReply(const GeoCoderReply& Reply) delete this; } +void HereGeocode::OnGeoCoderFailure(const GeoCoderReply& Reply) +{ + if (!m_bCanceled) + ((maps_service_geocode_cb)m_pCbFunc)((maps_error_e)GetErrorCode(Reply), m_nReqId, 0, 0, NULL, m_pUserData); + delete this; +} + HERE_PLUGIN_END_NAMESPACE diff --git a/src/here/here_geocode.h b/src/here/here_geocode.h index 4f37176..33567de 100755 --- a/src/here/here_geocode.h +++ b/src/here/here_geocode.h @@ -63,6 +63,7 @@ public: here_error_e StartGeocodeByStructuredAddress(const maps_address_h hAddr); virtual void OnGeoCoderReply(const GeoCoderReply& Reply); + virtual void OnGeoCoderFailure(const GeoCoderReply& Reply); private: GeoCoderQuery* m_pQuery; diff --git a/src/here/here_manager.cpp b/src/here/here_manager.cpp index 31dcb1e..28178ce 100755 --- a/src/here/here_manager.cpp +++ b/src/here/here_manager.cpp @@ -14,8 +14,8 @@ * limitations under the License. */ -#include <sys/types.h> #include <unistd.h> +#include <libxml/xpath.h> #include "here_manager.h" #include "here_base.h" @@ -25,8 +25,13 @@ #include "here_route.h" #include "here_utils.h" #include <common/HereConfig.h> +#include <app.h> +#include <iostream> +#include <fstream> +#include <string> using namespace HERE_PLUGIN_NAMESPACE_PREFIX; +using namespace TIZEN_MAPS_NAMESPACE_PREFIX; HERE_PLUGIN_BEGIN_NAMESPACE @@ -38,7 +43,9 @@ HereManager::HereManager() : m_nNextReqId(1), m_hPref(NULL) { + xmlInitParser(); m_hConnection = NULL; + pthread_mutex_init(&m_mtxHereList, NULL); pthread_mutex_init(&g_mtxRef, NULL); } @@ -50,7 +57,10 @@ HereManager::~HereManager() connection_destroy(m_hConnection); m_hConnection = NULL; } + + pthread_mutex_destroy(&m_mtxHereList); pthread_mutex_destroy(&g_mtxRef); + xmlCleanupParser(); } bool HereManager::Create() @@ -58,9 +68,7 @@ bool HereManager::Create() bool result = false; if (!m_pHereManager) - { - m_pHereManager = new HereManager(); - } + m_pHereManager = new (std::nothrow) HereManager(); pthread_mutex_lock(&g_mtxRef); if (m_pHereManager) @@ -71,20 +79,26 @@ bool HereManager::Create() } pthread_mutex_unlock(&g_mtxRef); - m_pHereManager->SetCredentials(); + if (m_pHereManager) + m_pHereManager->SetCredentials(); return result; } void HereManager::Close() { pthread_mutex_lock(&g_mtxRef); - if (--m_nRefCnt == 0 && m_pHereManager) + bool terminate = (--m_nRefCnt == 0 && m_pHereManager); + pthread_mutex_unlock(&g_mtxRef); + + if (terminate) { + m_pHereManager->TerminateAllServices(); + HereConfig::Shutdown(); + delete m_pHereManager; m_pHereManager = NULL; } MAPS_LOGD("Closed a HereManager instance (%d).", m_nRefCnt); - pthread_mutex_unlock(&g_mtxRef); } HereManager* HereManager::GetHandler() @@ -102,26 +116,30 @@ void* HereManager::CreateInstance(HereSvcType nHereSvc, void* pCbFunc, switch(nHereSvc) { case HERE_SVC_GEOCODE: - pHere = (HereBase*)new HereGeocode(pCbFunc, pUserData, *nReqId); + pHere = (HereBase*)new (std::nothrow) HereGeocode(pCbFunc, pUserData, *nReqId); break; case HERE_SVC_REV_GEOCODE: - pHere = (HereBase*)new HereRevGeocode(pCbFunc, pUserData, *nReqId); + pHere = (HereBase*)new (std::nothrow) HereRevGeocode(pCbFunc, pUserData, *nReqId); break; case HERE_SVC_PLACE: - pHere = (HereBase*)new HerePlace(pCbFunc, pUserData, *nReqId); + pHere = (HereBase*)new (std::nothrow) HerePlace(pCbFunc, pUserData, *nReqId); break; case HERE_SVC_ROUTE: - pHere = (HereBase*)new HereRoute(pCbFunc, pUserData, *nReqId); + pHere = (HereBase*)new (std::nothrow) HereRoute(pCbFunc, pUserData, *nReqId); break; default: return NULL; } - m_HereList.push_back(pHere); + pthread_mutex_lock(&m_mtxHereList); + if (pHere) + m_HereList.push_back(pHere); + pthread_mutex_unlock(&m_mtxHereList); + return pHere; } @@ -129,6 +147,7 @@ here_error_e HereManager::CloseInstance(int nReqId) { HereSvcList::iterator it; + pthread_mutex_lock(&m_mtxHereList); for (it = m_HereList.begin(); it != m_HereList.end(); it++) { if ((*it)->GetReqId() == nReqId) @@ -137,6 +156,8 @@ here_error_e HereManager::CloseInstance(int nReqId) break; } } + pthread_mutex_unlock(&m_mtxHereList); + return HERE_ERROR_NONE; } @@ -144,6 +165,7 @@ here_error_e HereManager::CancelInstance(int nReqId) { HereSvcList::iterator it; + pthread_mutex_lock(&m_mtxHereList); for (it = m_HereList.begin(); it != m_HereList.end(); it++) { if ((*it)->GetReqId() == nReqId) @@ -151,9 +173,12 @@ here_error_e HereManager::CancelInstance(int nReqId) m_HereList.erase(it); RestItemHandle::Cancel((*it)->GetRestReqId()); (*it)->TerminateService(); + pthread_mutex_unlock(&m_mtxHereList); return HERE_ERROR_NONE; } } + pthread_mutex_unlock(&m_mtxHereList); + return HERE_ERROR_NOT_FOUND; } @@ -312,24 +337,25 @@ maps_preference_h HereManager::GetPreference() void HereManager::TerminateAllServices(void) { - if (m_nRefCnt > 0) return; - - HereSvcList::iterator it; while (1) { + pthread_mutex_lock(&m_mtxHereList); if (m_HereList.empty()) { + pthread_mutex_unlock(&m_mtxHereList); break; } it = m_HereList.begin(); + pthread_mutex_unlock(&m_mtxHereList); try { + if (*it) (*it)->TerminateService(); m_HereList.erase(it); - (*it)->TerminateService(); } catch (std::exception &e) { + MAPS_LOGD("Exception caught: %s", e.what()); } }; @@ -457,5 +483,58 @@ void HereManager::NetworkStateChangedIndCb(connection_type_e type, void *user_da pManager->SetProxyAddress(); } +here_error_e HereManager::CheckAgreement() +{ + const char UTC_TPK_APP[] = "org.tizen.capi-maps-service-native-utc"; + const char ITC_TPK_APP[] = "org.tizen.capi-maps-service-native-itc"; + const char UTC_APP[] = "core.capi-maps-service-tests"; + const char ITC_APP[] = "native.capi-maps-service-itc"; + + char *strAppId = NULL; + here_error_e error = HERE_ERROR_NONE; + + pid_t nProcessId = getpid(); + int nRet = app_manager_get_app_id(nProcessId, &strAppId); + if (nRet != APP_MANAGER_ERROR_NONE) + { + MAPS_LOGI("Get app_id [%ld]. nRet[%d]", nProcessId, nRet); + error = HERE_ERROR_SERVICE_NOT_AVAILABLE; + } + else if (strncmp(strAppId, UTC_APP, strlen(UTC_APP)) && + strncmp(strAppId, ITC_APP, strlen(ITC_APP)) && + strncmp(strAppId, UTC_TPK_APP, strlen(UTC_TPK_APP)) && + strncmp(strAppId, ITC_TPK_APP, strlen(ITC_TPK_APP)) && + !HereManager::GetAgreement()) + { + MAPS_LOGD("Not agreed yet"); + error = HERE_ERROR_SERVICE_NOT_AVAILABLE; + } + + g_free(strAppId); + return error; +} + +bool HereManager::GetAgreement(void) +{ + std::ifstream file (UC_FILE); + bool isAgree = false; + std::string line; + std::string value; + + if (file.is_open()) { + getline(file, line); + value = line.substr(6); + if (value.compare("Yes") == 0) + isAgree = true; + else + MAPS_LOGD("UC was set No"); + file.close(); + } else { + MAPS_LOGD("UC file open fail. %s (%d)", strerror(errno), errno); + } + + return isAgree; +} + HERE_PLUGIN_END_NAMESPACE diff --git a/src/here/here_manager.h b/src/here/here_manager.h index f68a5ea..c73cdfd 100755 --- a/src/here/here_manager.h +++ b/src/here/here_manager.h @@ -39,6 +39,8 @@ #include <common/ApplicationContext.h> #include <common/HereConfig.h> +#define UC_FILE "/opt/usr/apps/org.tizen.heremaps-uc/shared/data/heremaps_uc.xml" + HERE_PLUGIN_BEGIN_NAMESPACE class HereManager; @@ -82,6 +84,8 @@ public: static bool Create(); static HereManager* GetHandler(); static void Close(); + static here_error_e CheckAgreement(); + static bool GetAgreement(void); private: here_error_e SetCredentials(); @@ -96,6 +100,7 @@ protected: HereSvcList m_HereList; gint m_nNextReqId; maps_preference_h m_hPref; + pthread_mutex_t m_mtxHereList; }; HERE_PLUGIN_END_NAMESPACE diff --git a/src/here/here_place.cpp b/src/here/here_place.cpp index 53432c7..b42cb5f 100755 --- a/src/here/here_place.cpp +++ b/src/here/here_place.cpp @@ -29,7 +29,9 @@ HerePlace::HerePlace(void *pCbFunc, void *pUserData, int nReqId) m_nReplyCnt = 0; m_nReplyIdx = 0; + m_bReplyFlushed = false; m_szSortBy = NULL; + m_bPlaceDetailsInternal = false; } HerePlace::~HerePlace() @@ -58,7 +60,7 @@ here_error_e HerePlace::PrepareDiscoveryQuery() if (m_pDiscoveryQuery) return HERE_ERROR_PERMISSION_DENIED; - m_pDiscoveryQuery = new DiscoveryQuery(); + m_pDiscoveryQuery = new (std::nothrow) DiscoveryQuery(); if (!m_pDiscoveryQuery) return HERE_ERROR_OUT_OF_MEMORY; @@ -239,8 +241,11 @@ here_error_e HerePlace::StartDiscoveryPlaceByAddress(const char *szAddr, maps_ar m_pDiscoveryQuery->SetType(DiscoveryQuery::QT_SEARCH); String szSearchText = szAddr; - if (m_pDiscoveryQuery->GetSearchText().size()) + if (m_pDiscoveryQuery->GetSearchText().size() > 0 && + szSearchText != m_pDiscoveryQuery->GetSearchText()) + { szSearchText += " " + m_pDiscoveryQuery->GetSearchText(); + } m_pDiscoveryQuery->SetSearchText(szSearchText); maps_area_s *pArea = (maps_area_s*)hArea; @@ -275,7 +280,7 @@ here_error_e HerePlace::PreparePlaceDetailsQuery() if (m_pPlaceDetailsQuery) return HERE_ERROR_PERMISSION_DENIED; - m_pPlaceDetailsQuery = new PlaceDetailsQuery(); + m_pPlaceDetailsQuery = new (std::nothrow) PlaceDetailsQuery(); if (!m_pPlaceDetailsQuery) return HERE_ERROR_OUT_OF_MEMORY; @@ -326,7 +331,7 @@ here_error_e HerePlace::StartPlaceDetailsInternal(const char *szUrl) std::unique_ptr<PlaceDetailsQuery> pPlaceDetailsQuery (new (std::nothrow)PlaceDetailsQuery()); - + m_bPlaceDetailsInternal = true; bool bExcuted = (int)(pPlaceDetailsQuery->Execute(*this, NULL, szUrl) > 0); return (bExcuted ? HERE_ERROR_NONE : HERE_ERROR_INVALID_OPERATION); @@ -334,12 +339,6 @@ here_error_e HerePlace::StartPlaceDetailsInternal(const char *szUrl) void HerePlace::OnDiscoverReply (const DiscoveryReply &Reply) { - if (m_bCanceled) /* ignore call back if it was cancelled. */ - { - delete this; - return; - } - maps_place_h mapsPlace; PlaceItemList herePlaceList = Reply.GetPlaceItems(); PlaceItemList::iterator herePlaceIt; @@ -358,22 +357,14 @@ void HerePlace::OnDiscoverReply (const DiscoveryReply &Reply) m_nReplyIdx = 0; m_nReplyCnt = herePlaceList.size() + hereSearchList.size(); - if (m_nReplyCnt == 0) - { - ((maps_service_search_place_cb)m_pCbFunc)(MAPS_ERROR_NOT_FOUND, m_nReqId, - 0, 1, NULL, m_pUserData); - delete this; - return; - } - for (herePlaceIt = herePlaceList.begin(); - herePlaceIt != herePlaceList.end() && !m_bCanceled; + herePlaceIt != herePlaceList.end(); herePlaceIt++) { - isPending = false; - if ((error = maps_place_create(&mapsPlace)) == MAPS_ERROR_NONE) { + isPending = false; + /* title, uri, id */ hereLinkObj = herePlaceIt->GetLinkObject(); @@ -462,22 +453,28 @@ void HerePlace::OnDiscoverReply (const DiscoveryReply &Reply) hereLinkObj = herePlaceIt->GetLinkObject(); if (!hereLinkObj.GetHref().empty() && !hereLinkObj.GetId().empty()) { - m_PlaceList.push_back(mapsPlace); - isPending = true; - StartPlaceDetailsInternal(hereLinkObj.GetHref().c_str()); - MAPS_LOGD("Add maps_place_h to the pending list. id=%s", hereLinkObj.GetId().data()); + if (StartPlaceDetailsInternal(hereLinkObj.GetHref().c_str()) == HERE_ERROR_NONE) + { + m_PlaceList.push_back(mapsPlace); + isPending = true; + MAPS_LOGD("Add maps_place_h to the pending list. id=%s", hereLinkObj.GetId().data()); + } } } - } - if (!isPending) { - m_nReplyIdx++; - m_PlaceList.push_back(mapsPlace); + if (!isPending) { + m_nReplyIdx++; + m_PlaceList.push_back(mapsPlace); + } + } + else + { + m_nReplyCnt--; } } for (hereSearchIt = hereSearchList.begin(); - hereSearchIt != hereSearchList.end() && !m_bCanceled; + hereSearchIt != hereSearchList.end(); hereSearchIt++) { error = maps_place_create(&mapsPlace); @@ -513,43 +510,48 @@ void HerePlace::OnDiscoverReply (const DiscoveryReply &Reply) /* type */ if (!is_valid) + { + m_nReplyCnt--; error = MAPS_ERROR_NOT_FOUND; + maps_place_destroy(mapsPlace); + mapsPlace = NULL; + } + else + { + m_PlaceList.push_back(mapsPlace); + m_nReplyIdx++; + } + } + else + { + m_nReplyCnt--; } - - m_PlaceList.push_back(mapsPlace); - m_nReplyIdx++; } - if (m_nReplyIdx == m_nReplyCnt - 1) + if (!m_bReplyFlushed && (m_nReplyCnt == 0 || m_nReplyIdx == m_nReplyCnt)) { - __sortList(m_PlaceList); - - m_nReplyIdx = 0; - while (m_nReplyIdx < m_nReplyCnt && !m_bCanceled && !m_PlaceList.empty()) - { - mapsPlace = m_PlaceList.front(); - m_PlaceList.pop_front(); + if (m_nReplyCnt == 0) + error = MAPS_ERROR_NOT_FOUND; - /* callback function */ - if (((maps_service_search_place_cb)m_pCbFunc)((maps_error_e)error, m_nReqId, - m_nReplyIdx++, m_nReplyCnt, mapsPlace, m_pUserData) == FALSE) - { - break; - } - } + __flushReplies(error); delete this; } } -void HerePlace::OnPlaceDetailsReply (const PlaceDetailsReply &Reply) +void HerePlace::OnDiscoverFailure(const DiscoveryReply& Reply) { - if (m_bCanceled) /* ignore call back if it was cancelled. */ + if (!m_bReplyFlushed) { + m_nReplyIdx = 0; + m_nReplyCnt = 0; + __flushReplies((maps_error_e)GetErrorCode(Reply)); delete this; - return; } +} +void HerePlace::OnPlaceDetailsReply (const PlaceDetailsReply &Reply) +{ if (m_nReplyCnt == 0) m_nReplyCnt = 1; @@ -571,8 +573,8 @@ void HerePlace::OnPlaceDetailsReply (const PlaceDetailsReply &Reply) { mapsPlace = *it; isPending = true; + MAPS_LOGD("Found maps_place_h in the pending list. id=%s", placeId); g_free(placeId); - MAPS_LOGD("Found maps_place_h (%p) which is pending since DiscoveryReply", mapsPlace); break; } } @@ -632,37 +634,56 @@ void HerePlace::OnPlaceDetailsReply (const PlaceDetailsReply &Reply) ProcessPlaceRatings(herePlace, mapsPlace); ProcessPlaceRated(herePlace, mapsPlace); + + if (!isPending) + m_PlaceList.push_back(mapsPlace); + + m_nReplyIdx++; } else { + m_nReplyCnt--; error = MAPS_ERROR_NOT_FOUND; + maps_place_destroy(mapsPlace); + mapsPlace = NULL; } } + else + { + m_nReplyCnt--; + } - if (!isPending) - m_PlaceList.push_back(mapsPlace); - - m_nReplyIdx++; + if (!m_bReplyFlushed && (m_nReplyCnt == 0 || m_nReplyIdx == m_nReplyCnt)) + { + if (m_nReplyCnt == 0) + error = MAPS_ERROR_NOT_FOUND; + __flushReplies(error); + delete this; + } +} - if (m_nReplyIdx == m_nReplyCnt - 1) +void HerePlace::OnPlaceDetailsFailure(const PlaceDetailsReply& Reply) +{ + if (!m_bPlaceDetailsInternal) { - __sortList(m_PlaceList); - - m_nReplyIdx = 0; - while (m_nReplyIdx < m_nReplyCnt && !m_bCanceled && !m_PlaceList.empty()) + if (!m_bReplyFlushed) { - mapsPlace = m_PlaceList.front(); - m_PlaceList.pop_front(); - - /* callback function */ - if (((maps_service_search_place_cb)m_pCbFunc)((maps_error_e)error, m_nReqId, - m_nReplyIdx++, m_nReplyCnt, mapsPlace, m_pUserData) == FALSE) - { - break; - } + m_nReplyIdx = 0; + m_nReplyCnt = 0; + __flushReplies(GetErrorCode(Reply)); + delete this; + } + } + else + { + m_nReplyIdx++; + MAPS_LOGD("Internal error during updating detailed information for the place. (%d/%d)", m_nReplyIdx, m_nReplyCnt); + if (!m_bReplyFlushed && (m_nReplyIdx == m_nReplyCnt)) + { + __flushReplies(MAPS_ERROR_NONE); + delete this; } - delete this; } } @@ -1178,6 +1199,41 @@ void HerePlace::ProcessPlaceRated(PlaceDetails herePlace, maps_place_h mapsPlace maps_place_link_object_destroy(mapsRelated); } +void HerePlace::__flushReplies(int error) +{ + maps_place_h mapsPlace; + bool bCallbackCanceled = false; + int nReplyIdx = 0; + + if (m_bReplyFlushed) return; + m_bReplyFlushed = true; + + __sortList(m_PlaceList); + + while ((nReplyIdx < m_nReplyCnt) || + (error != MAPS_ERROR_NONE && nReplyIdx == 0 && m_nReplyCnt == 0) /* reply with only error */ + ) + { + mapsPlace = NULL; + if (!m_PlaceList.empty()) + { + mapsPlace = m_PlaceList.front(); + m_PlaceList.pop_front(); + } + + if (m_bCanceled || bCallbackCanceled) + { + maps_place_destroy(mapsPlace); + } + else if (((maps_service_search_place_cb)m_pCbFunc)((maps_error_e)error, m_nReqId, + nReplyIdx, m_nReplyCnt, mapsPlace, m_pUserData) == FALSE) + { + bCallbackCanceled = true; + } + nReplyIdx++; + } +} + bool HerePlace::__compareWithTitle(const maps_place_h &item1, const maps_place_h &item2) { bool result = false; diff --git a/src/here/here_place.h b/src/here/here_place.h index febdc24..0cc4338 100755 --- a/src/here/here_place.h +++ b/src/here/here_place.h @@ -84,7 +84,10 @@ public: here_error_e StartPlaceDetailsInternal(const char* szUrl); virtual void OnDiscoverReply(const DiscoveryReply &Reply); + virtual void OnDiscoverFailure(const DiscoveryReply& Reply); + virtual void OnPlaceDetailsReply(const PlaceDetailsReply &Reply); + virtual void OnPlaceDetailsFailure(const PlaceDetailsReply& Reply); private: void ProcessPlaceLocation(PlaceDetails herePlace, maps_place_h mapsPlace); @@ -97,6 +100,7 @@ private: void ProcessPlaceRated(PlaceDetails herePlace, maps_place_h mapsPlace); void __sortList(PlaceList &list); + void __flushReplies(int error); static bool __compareWithTitle(const maps_place_h &item1, const maps_place_h &item2); static bool __compareWithId(const maps_place_h &item1, const maps_place_h &item2); static bool __compareWithType(const maps_place_h &item1, const maps_place_h &item2); @@ -110,9 +114,11 @@ private: PlaceDetailsQuery* m_pPlaceDetailsQuery; int m_nReplyCnt; int m_nReplyIdx; + bool m_bReplyFlushed; char *m_szSortBy; + bool m_bPlaceDetailsInternal; - PlaceList m_PlaceList;; + PlaceList m_PlaceList; static const bool __sending_place_details_query_automatically = TRUE; }; diff --git a/src/here/here_revgeocode.cpp b/src/here/here_revgeocode.cpp index 1e7d273..e4f8bce 100755 --- a/src/here/here_revgeocode.cpp +++ b/src/here/here_revgeocode.cpp @@ -41,7 +41,7 @@ here_error_e HereRevGeocode::PrepareQuery() if (m_pQuery) return HERE_ERROR_PERMISSION_DENIED; - m_pQuery = new ReverseGeoCoderQuery(); + m_pQuery = new (std::nothrow) ReverseGeoCoderQuery(); if (!m_pQuery) return HERE_ERROR_OUT_OF_MEMORY; @@ -131,7 +131,7 @@ void HereRevGeocode::OnGeoCoderReply(const GeoCoderReply& Reply) if (nShortestIdx < 0) { ((maps_service_reverse_geocode_cb)m_pCbFunc)(MAPS_ERROR_NOT_FOUND, - m_nReqId, 0, 1, NULL, m_pUserData); + m_nReqId, 0, 0, NULL, m_pUserData); delete this; return; } @@ -191,5 +191,12 @@ void HereRevGeocode::OnGeoCoderReply(const GeoCoderReply& Reply) delete this; } +void HereRevGeocode::OnGeoCoderFailure(const GeoCoderReply& Reply) +{ + if (!m_bCanceled) + ((maps_service_reverse_geocode_cb)m_pCbFunc)((maps_error_e)GetErrorCode(Reply), m_nReqId, 0, 0, NULL, m_pUserData); + delete this; +} + HERE_PLUGIN_END_NAMESPACE diff --git a/src/here/here_revgeocode.h b/src/here/here_revgeocode.h index 30f827f..7a75b91 100755 --- a/src/here/here_revgeocode.h +++ b/src/here/here_revgeocode.h @@ -59,6 +59,7 @@ public: here_error_e StartRevGeocode(maps_item_hashtable_h hPref); virtual void OnGeoCoderReply(const GeoCoderReply& Reply); + virtual void OnGeoCoderFailure(const GeoCoderReply& Reply); private: ReverseGeoCoderQuery* m_pQuery; diff --git a/src/here/here_route.cpp b/src/here/here_route.cpp index 58cb5fe..aa1abfb 100755 --- a/src/here/here_route.cpp +++ b/src/here/here_route.cpp @@ -42,7 +42,7 @@ here_error_e HereRoute::PrepareQuery() return HERE_ERROR_PERMISSION_DENIED; GeoCoordinates origCoord, destCoord; - m_pQuery = new GeoRouteQuery(origCoord, destCoord); + m_pQuery = new (std::nothrow) GeoRouteQuery(origCoord, destCoord); if (!m_pQuery) return HERE_ERROR_OUT_OF_MEMORY; @@ -211,7 +211,7 @@ void HereRoute::OnRouteReply(const GeoRouteReply& Reply) if (nReplyNum == 0) { ((maps_service_search_route_cb)m_pCbFunc)(MAPS_ERROR_NOT_FOUND, m_nReqId, - 0, 1, NULL, m_pUserData); + 0, 0, NULL, m_pUserData); delete this; return; } @@ -305,6 +305,12 @@ void HereRoute::OnRouteReply(const GeoRouteReply& Reply) delete this; } +void HereRoute::OnRouteFailure(const GeoRouteReply& Reply) +{ + if (!m_bCanceled) + ((maps_service_search_route_cb)m_pCbFunc)((maps_error_e)GetErrorCode(Reply), m_nReqId, 0, 0, NULL, m_pUserData); + delete this; +} maps_error_e HereRoute::ProcessSegments(maps_route_h mapsRoute, const RouteSegmentList& hereSegmList) { diff --git a/src/here/here_route.h b/src/here/here_route.h index c1ecb96..0aab609 100755 --- a/src/here/here_route.h +++ b/src/here/here_route.h @@ -59,6 +59,7 @@ public: here_error_e StartRoute(void); virtual void OnRouteReply(const GeoRouteReply& Reply); + virtual void OnRouteFailure(const GeoRouteReply& Reply); private: maps_error_e ProcessSegments(maps_route_h mapsRoute, const RouteSegmentList& hereSegmList); diff --git a/src/here/here_utils.cpp b/src/here/here_utils.cpp index 9cc2c47..60f1fb9 100755 --- a/src/here/here_utils.cpp +++ b/src/here/here_utils.cpp @@ -15,6 +15,7 @@ */ #include "here_utils.h" +#include <common/CommunicationError.h> static const double LATITUDE_RANGE = 85.05113; @@ -66,6 +67,50 @@ int ConvertToHereError(int nErr) } return HERE_ERROR_UNKNOWN; } + +const char* ConverHereErrorToString(int nErr) +{ + switch (nErr) + { + case HERE_ERROR_NONE: return "No errors"; + case HERE_ERROR_PERMISSION_DENIED: return "Permission denied"; + case HERE_ERROR_OUT_OF_MEMORY: return "Out of memory"; + case HERE_ERROR_INVALID_PARAMETER: return "Invalid Parameter"; + case HERE_ERROR_NOT_SUPPORTED: return "Not suppoerted"; + case HERE_ERROR_CONNECTION_TIME_OUT: return "Connection time out"; + case HERE_ERROR_NETWORK_UNREACHABLE: return "Network unreachable"; + case HERE_ERROR_INVALID_OPERATION: return "Invalid operation"; + case HERE_ERROR_KEY_NOT_AVAILABLE: return "Key not available"; + case HERE_ERROR_RESOURCE_BUSY: return "Resource busy"; + case HERE_ERROR_CANCELED: return "Canceled"; + case HERE_ERROR_UNKNOWN: return "Unknown"; + case HERE_ERROR_SERVICE_NOT_AVAILABLE: return "Service not available"; + case HERE_ERROR_NOT_FOUND: return "Not found"; + } + return "Unknown"; +} + +const char* ConvertMapsErrorToChar(int nErr) +{ + switch (nErr) + { + case MAPS_ERROR_NONE: return "MAPS_ERROR_NONE"; + case MAPS_ERROR_PERMISSION_DENIED: return "MAPS_ERROR_PERMISSION_DENIED"; + case MAPS_ERROR_OUT_OF_MEMORY: return "MAPS_ERROR_OUT_OF_MEMORY"; + case MAPS_ERROR_INVALID_PARAMETER: return "MAPS_ERROR_INVALID_PARAMETER"; + case MAPS_ERROR_NOT_SUPPORTED: return "MAPS_ERROR_NOT_SUPPORTED"; + case MAPS_ERROR_CONNECTION_TIME_OUT: return "MAPS_ERROR_CONNECTION_TIME_OUT"; + case MAPS_ERROR_NETWORK_UNREACHABLE: return "MAPS_ERROR_NETWORK_UNREACHABLE"; + case MAPS_ERROR_INVALID_OPERATION: return "MAPS_ERROR_INVALID_OPERATION"; + case MAPS_ERROR_KEY_NOT_AVAILABLE: return "MAPS_ERROR_KEY_NOT_AVAILABLE"; + case MAPS_ERROR_RESOURCE_BUSY: return "MAPS_ERROR_RESOURCE_BUSY"; + case MAPS_ERROR_CANCELED: return "MAPS_ERROR_CANCELED"; + case MAPS_ERROR_UNKNOWN: return "MAPS_ERROR_UNKNOWN"; + case MAPS_ERROR_SERVICE_NOT_AVAILABLE: return "MAPS_ERROR_SERVICE_NOT_AVAILABLE"; + case MAPS_ERROR_NOT_FOUND: return "MAPS_ERROR_NOT_FOUND"; + } + return "MAPS_ERROR_UNKNOWN"; +} } @@ -179,6 +224,45 @@ Maneuver::InstructionDirection HereUtils::Convert(maps_route_turn_type_e nVal) return Maneuver::ID_NoDirection; } +maps_error_e HereUtils::ConvertHttpCodeToMapsError(int nVal) +{ + switch (nVal) + { + case 200:/*Ok*/ return MAPS_ERROR_NONE; + case 408:/*Request timeout*/ + case 504:/*Gateway timeout*/ + case 598:/*Network reading timeout*/ + case 599:/*Network connection timeout*/ return MAPS_ERROR_CONNECTION_TIME_OUT; + + case 404:/*Not found*/ + case 407:/*Proxy auth. required*/ + case 502:/*Bad gateway*/ return MAPS_ERROR_NETWORK_UNREACHABLE; + + case 401:/*Unauthorized*/ + case 402:/*Payment required*/ return MAPS_ERROR_KEY_NOT_AVAILABLE; + + case 405:/*Method not allowed*/ + case 413:/*Request entity too larget*/ + case 414:/*Request uri too large*/ return MAPS_ERROR_INVALID_OPERATION; + + case 403:/*Forbidden*/ + case 500:/*Server internal error*/ + case 501:/*Not implemented*/ + case 503:/*Service unavailable*/ return MAPS_ERROR_SERVICE_NOT_AVAILABLE; + } + + if (nVal > 0 && nVal < 100) // curl error code + return MAPS_ERROR_NETWORK_UNREACHABLE; + + if (nVal >= 400 && nVal < 500) // http code 4xx (client-side error) + return MAPS_ERROR_INVALID_OPERATION; + + if (nVal >= 500 && nVal < 600) // http code 5xx (server-side error) + return MAPS_ERROR_SERVICE_NOT_AVAILABLE; + + return MAPS_ERROR_UNKNOWN; +} + GeoBoundingBox& HereUtils::Convert(maps_area_h hArea, GeoBoundingBox& Box) { maps_area_s* area_s = (maps_area_s*)hArea; diff --git a/src/here/here_utils.h b/src/here/here_utils.h index bcd1abf..3a54031 100755 --- a/src/here/here_utils.h +++ b/src/here/here_utils.h @@ -97,6 +97,8 @@ extern "C" { int ConvertToMapsError(int nRet); int ConvertToHereError(int nRet); + const char* ConverHereErrorToString(int nErr); + const char* ConvertMapsErrorToChar(int nErr); } HERE_PLUGIN_BEGIN_NAMESPACE @@ -129,6 +131,7 @@ public: static void Convert(String strUtf8, WString& strUtf16); static void Convert(WString strUtf16, String& strUtf8); static GeoBoundingBox& Convert(const char *src, GeoBoundingBox &box); + static maps_error_e ConvertHttpCodeToMapsError(int nVal); static bool IsValid(GeoCoordinates geoCoord); static bool IsValid(maps_coordinates_s geoCoord); |