tizen 2.4 release
[framework/location/maps-plugin-here.git] / src / here / 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
34 //plug-in header
35 #include "here_types.h"
36
37 //map engine header
38 #include <geocoder/GeoCoderQuery.h>
39 #include <finder/DiscoveryQuery.h>
40 #include <routes/GeoRouteQuery.h>
41 #include <routes/Maneuver.h>
42 #include <common/GeoCoordinates.h>
43
44 #define HERE_PLUGIN_BEGIN_NAMESPACE  namespace Here { namespace PlugIn {
45 #define HERE_PLUGIN_END_NAMESPACE    }}
46 #define HERE_PLUGIN_NAMESPACE_PREFIX Here::PlugIn
47
48 #ifdef LOG_TAG
49 #undef LOG_TAG
50 #endif
51 #define LOG_TAG "HERE_PLUGIN"
52
53 /*
54 * Internal Macros
55 */
56 #define MAPS_LOGD(fmt,args...)  LOGD(fmt, ##args)
57 #define MAPS_LOGW(fmt,args...)  LOGW(fmt, ##args)
58 #define MAPS_LOGI(fmt,args...)  LOGI(fmt, ##args)
59 #define MAPS_LOGE(fmt,args...)  LOGE(fmt, ##args)
60 #define MAPS_SECLOG(fmt,args...)  SECURE_LOGD(fmt, ##args)
61
62 #define MAPS_CHECK_CONDITION(condition, error, msg)     \
63         do { \
64                 if (condition) { \
65                 } else { \
66                         MAPS_LOGE("%s(0x%08x)", msg, error); \
67                         return error; \
68                 } \
69         } while (0)
70
71 #define MAPS_NULL_ARG_CHECK_RETURN_FALSE(arg)\
72         do { \
73                 if(arg != NULL) { \
74                 } else  { \
75                         MAPS_LOGE("MAPS_ERROR_INVALID_PARAMETER");  \
76                         return false; };        \
77         } while (0)
78
79 #define MAPS_NULL_ARG_CHECK(arg)        \
80         MAPS_CHECK_CONDITION(arg != NULL,MAPS_ERROR_INVALID_PARAMETER,"MAPS_ERROR_INVALID_PARAMETER")
81
82 #define MAPS_PRINT_ERROR_CODE_RETURN(code) \
83         do{ \
84                 MAPS_LOGE("%s(0x%08x)", #code, code); \
85                 return code;    \
86         } while (0)
87
88 #ifndef TIZEN_MIGRATION
89 typedef std::string String;
90 typedef std::string Uri;
91 typedef std::wstring WString;
92 #endif
93
94 #define maps_item_list_items(item_list) g_list_length((GList*)(*(unsigned long*)item_list)  )
95
96 extern "C"
97 {
98         int ConvertToMapsError(int nRet);
99         int ConvertToHereError(int nRet);
100 }
101
102 HERE_PLUGIN_BEGIN_NAMESPACE
103
104 using namespace HERE_MAPS_NAMESPACE_PREFIX;
105
106 class HereUtils
107 {
108 public:
109         /**
110          *This is the default constructor for Geocoder.
111          */
112
113         HereUtils();
114
115         /**
116          *This is the default destructor for Geocoder.
117          */
118
119         ~HereUtils();
120
121         static GeoRouteQuery::TravelMode Convert(maps_route_transport_mode_e nVal);
122         static maps_route_transport_mode_e Convert(GeoRouteQuery::TravelMode nVal);
123         static GeoRouteQuery::FeatureType Convert(maps_route_feature_e nVal);
124         static GeoRouteQuery::FeatureWeight Convert(maps_route_feature_weight_e nVal);
125         static Maneuver::InstructionDirection Convert(maps_route_turn_type_e nVal);
126         static maps_route_turn_type_e Convert(Maneuver::InstructionDirection nVal);
127         static GeoBoundingBox& Convert(maps_area_h hArea, GeoBoundingBox& Box);
128         static maps_area_h& Convert(GeoBoundingBox Box, maps_area_h& hArea);
129         static void Convert(String strUtf8, WString& strUtf16);
130         static void Convert(WString strUtf16, String& strUtf8);
131         static GeoBoundingBox& Convert(const char *src, GeoBoundingBox &box);
132
133         static bool IsValid(GeoCoordinates geoCoord);
134         static bool IsValid(maps_coordinates_s geoCoord);
135         static bool IsValidCoord(double dLat, double dLng);
136         static bool IsValid(maps_area_s hArea);
137
138 private:
139 };
140
141 HERE_PLUGIN_END_NAMESPACE
142
143 #endif //_LOCATION_HERE_UTILS_H_