9d8a898bcf24495db3e654ab3094c2f2d30293b9
[platform/core/csapi/maps.git] / Tizen.Maps / Interop / Interop.Place.cs
1 /*
2  * Copyright (c) 2016 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 using System;
18 using System.Runtime.InteropServices;
19
20 internal static partial class Interop
21 {
22     [DllImport(Libraries.MapService, EntryPoint = "maps_place_get_id")]
23     internal static extern ErrorCode GetId(this PlaceHandle /* maps_place_h */ place, out string id);
24
25     [DllImport(Libraries.MapService, EntryPoint = "maps_place_get_name")]
26     internal static extern ErrorCode GetName(this PlaceHandle /* maps_place_h */ place, out string name);
27
28     [DllImport(Libraries.MapService, EntryPoint = "maps_place_get_uri")]
29     internal static extern ErrorCode GetUri(this PlaceHandle /* maps_place_h */ place, out string uri);
30
31     [DllImport(Libraries.MapService, EntryPoint = "maps_place_get_distance")]
32     internal static extern ErrorCode GetDistance(this PlaceHandle /* maps_place_h */ place, out int distance);
33
34     [DllImport(Libraries.MapService, EntryPoint = "maps_place_get_location")]
35     internal static extern ErrorCode GetLocation(this PlaceHandle /* maps_place_h */ place, out IntPtr /* maps_coordinates_h */ location);
36
37     [DllImport(Libraries.MapService, EntryPoint = "maps_place_get_address")]
38     internal static extern ErrorCode GetAddress(this PlaceHandle /* maps_place_h */ place, out IntPtr /* maps_address_h */ address);
39
40     [DllImport(Libraries.MapService, EntryPoint = "maps_place_get_rating")]
41     internal static extern ErrorCode GetRating(this PlaceHandle /* maps_place_h */ place, out IntPtr /* maps_place_rating_h */ rating);
42
43     [DllImport(Libraries.MapService, EntryPoint = "maps_place_get_supplier_link")]
44     internal static extern ErrorCode GetSupplierLink(this PlaceHandle /* maps_place_h */ place, out IntPtr /* maps_place_link_object_h */ supplier);
45
46     [DllImport(Libraries.MapService, EntryPoint = "maps_place_get_related_link")]
47     internal static extern ErrorCode GetRelatedLink(this PlaceHandle /* maps_place_h */ place, out IntPtr /* maps_place_link_object_h */ related);
48
49     internal class PlaceHandle : SafeMapsHandle
50     {
51         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
52         internal delegate bool PropertiesCallback(int index, int total, string key, string /* void */ value, IntPtr /* void */ userData);
53
54         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
55         internal delegate bool CategoriesCallback(int index, int total, IntPtr /* maps_place_category_h */ category, IntPtr /* void */ userData);
56
57         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
58         internal delegate bool AttributesCallback(int index, int total, IntPtr /* maps_place_attribute_h */ attribute, IntPtr /* void */ userData);
59
60         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
61         internal delegate bool ContactsCallback(int index, int total, IntPtr /* maps_place_contact_h */ contact, IntPtr /* void */ userData);
62
63         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
64         internal delegate bool EditorialsCallback(int index, int total, IntPtr /* maps_place_editorial_h */ editorial, IntPtr /* void */ userData);
65
66         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
67         internal delegate bool ImagesCallback(int index, int total, IntPtr /* maps_place_image_h */ image, IntPtr /* void */ userData);
68
69         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
70         internal delegate bool ReviewsCallback(int index, int total, IntPtr /* maps_place_review_h */ review, IntPtr /* void */ userData);
71
72         [DllImport(Libraries.MapService, EntryPoint = "maps_place_foreach_property")]
73         internal static extern ErrorCode ForeachProperty(IntPtr /* maps_place_h */ place, PropertiesCallback callback, IntPtr /* void */ userData);
74
75         [DllImport(Libraries.MapService, EntryPoint = "maps_place_foreach_category")]
76         internal static extern ErrorCode ForeachCategory(IntPtr /* maps_place_h */ place, CategoriesCallback callback, IntPtr /* void */ userData);
77
78         [DllImport(Libraries.MapService, EntryPoint = "maps_place_foreach_attribute")]
79         internal static extern ErrorCode ForeachAttribute(IntPtr /* maps_place_h */ place, AttributesCallback callback, IntPtr /* void */ userData);
80
81         [DllImport(Libraries.MapService, EntryPoint = "maps_place_foreach_contact")]
82         internal static extern ErrorCode ForeachContact(IntPtr /* maps_place_h */ place, ContactsCallback callback, IntPtr /* void */ userData);
83
84         [DllImport(Libraries.MapService, EntryPoint = "maps_place_foreach_editorial")]
85         internal static extern ErrorCode ForeachEditorial(IntPtr /* maps_place_h */ place, EditorialsCallback callback, IntPtr /* void */ userData);
86
87         [DllImport(Libraries.MapService, EntryPoint = "maps_place_foreach_image")]
88         internal static extern ErrorCode ForeachImage(IntPtr /* maps_place_h */ place, ImagesCallback callback, IntPtr /* void */ userData);
89
90         [DllImport(Libraries.MapService, EntryPoint = "maps_place_foreach_review")]
91         internal static extern ErrorCode ForeachReview(IntPtr /* maps_place_h */ place, ReviewsCallback callback, IntPtr /* void */ userData);
92
93         [DllImport(Libraries.MapService, EntryPoint = "maps_place_destroy")]
94         internal static extern ErrorCode Destroy(IntPtr /* maps_place_h */ place);
95
96         [DllImport(Libraries.MapService, EntryPoint = "maps_place_clone")]
97         internal static extern ErrorCode Clone(IntPtr /* maps_place_h */ origin, out IntPtr /* maps_place_h */ cloned);
98
99         internal string Id
100         {
101             get { return NativeGet(this.GetId); }
102         }
103
104         internal string Name
105         {
106             get { return NativeGet(this.GetName); }
107         }
108
109         internal string Uri
110         {
111             get { return NativeGet(this.GetUri); }
112         }
113
114         internal int Distance
115         {
116             get { return NativeGet<int>(this.GetDistance); }
117         }
118
119         internal CoordinatesHandle Coordinates
120         {
121             get { return NativeGet(this.GetLocation, CoordinatesHandle.Create); }
122         }
123
124         internal AddressHandle Address
125         {
126             get { return NativeGet(this.GetAddress, AddressHandle.Create); }
127         }
128
129         internal PlaceRatingHandle Rating
130         {
131             get { return NativeGet(this.GetRating, PlaceRatingHandle.Create); }
132         }
133
134         internal PlaceLinkObjectHandle Supplier
135         {
136             get { return NativeGet(this.GetSupplierLink, PlaceLinkObjectHandle.Create); }
137         }
138
139         internal PlaceLinkObjectHandle Related
140         {
141             get { return NativeGet(this.GetRelatedLink, PlaceLinkObjectHandle.Create); }
142         }
143
144         public PlaceHandle(IntPtr handle, bool needToRelease) : base(handle, needToRelease, Destroy)
145         {
146         }
147
148         internal static PlaceHandle CloneFrom(IntPtr nativeHandle)
149         {
150             IntPtr handle;
151             Clone(nativeHandle, out handle).ThrowIfFailed("Failed to clone native handle");
152             return new PlaceHandle(handle, true);
153         }
154
155
156         internal void ForeachProperty(Action<string, string> action)
157         {
158             PropertiesCallback callback = (index, total, key, value, userData) =>
159             {
160                 action(key, value);
161                 return true;
162             };
163
164             ForeachProperty(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get property list from native handle");
165         }
166
167         internal void ForeachCategory(Action<PlaceCategoryHandle> action)
168         {
169             // PlaceCategoryHandle is valid only in this callback and users should not keep its reference
170             CategoriesCallback callback = (index, total, handle, userData) =>
171             {
172                 action(new PlaceCategoryHandle(handle, true));
173                 return true;
174             };
175
176             ForeachCategory(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get category list from native handle");
177         }
178
179         internal void ForeachAttribute(Action<PlaceAttributeHandle> action)
180         {
181             // PlaceAttributeHandle is valid only in this callback and users should not keep its reference
182             AttributesCallback callback = (index, total, handle, userData) =>
183             {
184                 action(new PlaceAttributeHandle(handle, true));
185                 return true;
186             };
187
188             ForeachAttribute(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get attributes list from native handle");
189         }
190
191         internal void ForeachContact(Action<PlaceContactHandle> action)
192         {
193             // PlaceContactHandle is valid only in this callback and users should not keep its reference
194             ContactsCallback callback = (index, total, handle, userData) =>
195             {
196                 action(new PlaceContactHandle(handle, true));
197                 return true;
198             };
199
200             ForeachContact(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get contacts list from native handle");
201         }
202
203         internal void ForeachEditorial(Action<PlaceEditorialHandle> action)
204         {
205             // PlaceEditorialHandle is valid only in this callback and users should not keep its reference
206             EditorialsCallback callback = (index, total, handle, userData) =>
207             {
208                 action(new PlaceEditorialHandle(handle, true));
209                 return true;
210             };
211
212             ForeachEditorial(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get editorial list from native handle");
213         }
214
215         internal void ForeachImage(Action<PlaceImageHandle> action)
216         {
217             // PlaceImageHandle is valid only in this callback and users should not keep its reference
218             ImagesCallback callback = (index, total, handle, userData) =>
219             {
220                 action(new PlaceImageHandle(handle, true));
221                 return true;
222             };
223
224             ForeachImage(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get image list from native handle");
225         }
226
227         internal void ForeachReview(Action<PlaceReviewHandle> action)
228         {
229             // PlaceReviewHandle is valid only in this callback and users should not keep its reference
230             ReviewsCallback callback = (index, total, handle, userData) =>
231             {
232                 action(new PlaceReviewHandle(handle, true));
233                 return true;
234             };
235
236             ForeachReview(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get review list from native handle");
237         }
238     }
239 }