d9e8b35e1a5d40eef36285da14e00e3a06d4a786
[platform/core/location/maps-plugin-here.git] / inc / here_utils.h
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef _LOCATION_HERE_UTILS_H_
18 #define _LOCATION_HERE_UTILS_H_
19
20 //common header
21 #include <glib.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <iostream>
25 #include <math.h>
26 #include <vector>
27
28 //maps-service header
29 #include <maps_area.h>
30 #include <maps_preference.h>
31 #include <maps_route_maneuver.h>
32 #include <maps_service.h>
33 #include <maps_view.h>
34
35 //plug-in header
36 #include "here_types.h"
37
38 //map engine header
39 #include <geocoder/GeoCoderQuery.h>
40 #include <finder/DiscoveryQuery.h>
41 #include <routes/GeoRouteQuery.h>
42 #include <routes/Maneuver.h>
43 #include <common/GeoCoordinates.h>
44 #include <common/GeoBoundingBox.h>
45 #include <common/GeoBoundingCircle.h>
46 #include <maps/GeoTiledMap.h>
47
48 #define HERE_PLUGIN_BEGIN_NAMESPACE  namespace Here { namespace PlugIn {
49 #define HERE_PLUGIN_END_NAMESPACE    }}
50 #define HERE_PLUGIN_NAMESPACE_PREFIX Here::PlugIn
51
52 #ifdef LOG_TAG
53 #undef LOG_TAG
54 #endif
55 #define LOG_TAG "HERE_PLUGIN"
56
57 /*
58 * Internal Macros
59 */
60 #define MAPS_LOGD(fmt,args...)  LOGD(fmt, ##args)
61 #define MAPS_LOGW(fmt,args...)  LOGW(fmt, ##args)
62 #define MAPS_LOGI(fmt,args...)  LOGI(fmt, ##args)
63 #define MAPS_LOGE(fmt,args...)  LOGE(fmt, ##args)
64 #define MAPS_SECLOG(fmt,args...)  SECURE_LOGD(fmt, ##args)
65
66 #define MAPS_CHECK_CONDITION(condition, error, msg)     \
67         do { \
68                 if (condition) { \
69                 } else { \
70                         MAPS_LOGE("%s(0x%08x)", msg, error); \
71                         return error; \
72                 } \
73         } while (0)
74
75 #define MAPS_NULL_ARG_CHECK_RETURN_FALSE(arg)\
76         do { \
77                 if(arg != NULL) { \
78                 } else  { \
79                         MAPS_LOGE("MAPS_ERROR_INVALID_PARAMETER");  \
80                         return false; };        \
81         } while (0)
82
83 #define MAPS_NULL_ARG_CHECK(arg)        \
84         MAPS_CHECK_CONDITION(arg != NULL,MAPS_ERROR_INVALID_PARAMETER,"MAPS_ERROR_INVALID_PARAMETER")
85
86 #define MAPS_PRINT_ERROR_CODE_RETURN(code) \
87         do{ \
88                 MAPS_LOGE("%s(0x%08x)", #code, code); \
89                 return code;    \
90         } while (0)
91
92 #ifndef TIZEN_MIGRATION
93 typedef std::string String;
94 typedef std::string Uri;
95 typedef std::wstring WString;
96 #endif
97
98 #define maps_item_list_items(item_list) g_list_length((GList*)(*(unsigned long*)item_list)  )
99
100 extern "C"
101 {
102         int ConvertToMapsError(int nRet);
103         int ConvertToHereError(int nRet);
104         const char* ConverHereErrorToString(int nErr);
105         const char* ConvertMapsErrorToChar(int nErr);
106 }
107
108 HERE_PLUGIN_BEGIN_NAMESPACE
109
110 using namespace HERE_MAPS_NAMESPACE_PREFIX;
111
112 class HereUtils
113 {
114 public:
115         /**
116          *This is the default constructor for Geocoder.
117          */
118
119         HereUtils();
120
121         /**
122          *This is the default destructor for Geocoder.
123          */
124
125         ~HereUtils();
126
127         static GeoRouteQuery::TravelMode Convert(maps_route_transport_mode_e nVal);
128         static maps_route_transport_mode_e Convert(GeoRouteQuery::TravelMode nVal);
129         static GeoRouteQuery::FeatureType Convert(maps_route_feature_e nVal);
130         static GeoRouteQuery::FeatureWeight Convert(maps_route_feature_weight_e nVal);
131         static Maneuver::InstructionDirection Convert(maps_route_turn_type_e nVal);
132         static GeoTiledMap::MapType Convert(maps_view_type_e nMapType, bool bBuildings, bool bTraffic, bool bPublicTransit);
133         static maps_route_turn_type_e Convert(Maneuver::InstructionDirection nVal);
134         static GeoBoundingBox& Convert(maps_area_h hArea, GeoBoundingBox& Box);
135         static maps_area_h& Convert(GeoBoundingBox Box, maps_area_h& hArea);
136         static GeoBoundingCircle& Convert(maps_area_h hArea, GeoBoundingCircle& circle);
137         static void Convert(String strUtf8, WString& strUtf16);
138         static void Convert(WString strUtf16, String& strUtf8);
139         static GeoBoundingBox& Convert(const char *src, GeoBoundingBox &box);
140         static maps_error_e ConvertHttpCodeToMapsError(int nVal);
141         static const double ConvertDistance(const double originValue, maps_distance_unit_e destUnit);
142         static const double ConvertDistance(const double originValue, maps_distance_unit_e originUnit, maps_distance_unit_e destUnit);
143
144         static bool IsValid(GeoCoordinates geoCoord);
145         static bool IsValid(maps_coordinates_s geoCoord);
146         static bool IsValidCoord(double dLat, double dLng);
147         static bool IsValid(maps_area_s hArea);
148 };
149
150 HERE_PLUGIN_END_NAMESPACE
151
152 #endif //_LOCATION_HERE_UTILS_H_