2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Runtime.InteropServices;
20 internal static partial class Interop
22 [DllImport(Libraries.MapService, EntryPoint = "maps_place_get_id")]
23 internal static extern ErrorCode GetId(this PlaceHandle /* maps_place_h */ place, out string id);
25 [DllImport(Libraries.MapService, EntryPoint = "maps_place_get_name")]
26 internal static extern ErrorCode GetName(this PlaceHandle /* maps_place_h */ place, out string name);
28 [DllImport(Libraries.MapService, EntryPoint = "maps_place_get_uri")]
29 internal static extern ErrorCode GetUri(this PlaceHandle /* maps_place_h */ place, out string uri);
31 [DllImport(Libraries.MapService, EntryPoint = "maps_place_get_distance")]
32 internal static extern ErrorCode GetDistance(this PlaceHandle /* maps_place_h */ place, out int distance);
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);
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);
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);
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);
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);
49 internal class PlaceHandle : SafeMapsHandle
51 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
52 internal delegate bool PropertiesCallback(int index, int total, string key, string /* void */ value, IntPtr /* void */ userData);
54 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
55 internal delegate bool CategoriesCallback(int index, int total, IntPtr /* maps_place_category_h */ category, IntPtr /* void */ userData);
57 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
58 internal delegate bool AttributesCallback(int index, int total, IntPtr /* maps_place_attribute_h */ attribute, IntPtr /* void */ userData);
60 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
61 internal delegate bool ContactsCallback(int index, int total, IntPtr /* maps_place_contact_h */ contact, IntPtr /* void */ userData);
63 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
64 internal delegate bool EditorialsCallback(int index, int total, IntPtr /* maps_place_editorial_h */ editorial, IntPtr /* void */ userData);
66 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
67 internal delegate bool ImagesCallback(int index, int total, IntPtr /* maps_place_image_h */ image, IntPtr /* void */ userData);
69 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
70 internal delegate bool ReviewsCallback(int index, int total, IntPtr /* maps_place_review_h */ review, IntPtr /* void */ userData);
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);
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);
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);
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);
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);
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);
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);
93 [DllImport(Libraries.MapService, EntryPoint = "maps_place_destroy")]
94 internal static extern ErrorCode Destroy(IntPtr /* maps_place_h */ place);
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);
101 get { return NativeGet(this.GetId); }
106 get { return NativeGet(this.GetName); }
111 get { return NativeGet(this.GetUri); }
114 internal int Distance
116 get { return NativeGet<int>(this.GetDistance); }
119 internal CoordinatesHandle Coordinates
121 get { return NativeGet(this.GetLocation, CoordinatesHandle.Create); }
124 internal AddressHandle Address
126 get { return NativeGet(this.GetAddress, AddressHandle.Create); }
129 internal PlaceRatingHandle Rating
131 get { return NativeGet(this.GetRating, PlaceRatingHandle.Create); }
134 internal PlaceLinkObjectHandle Supplier
136 get { return NativeGet(this.GetSupplierLink, PlaceLinkObjectHandle.Create); }
139 internal PlaceLinkObjectHandle Related
141 get { return NativeGet(this.GetRelatedLink, PlaceLinkObjectHandle.Create); }
144 public PlaceHandle(IntPtr handle, bool needToRelease) : base(handle, needToRelease, Destroy)
148 internal static PlaceHandle CloneFrom(IntPtr nativeHandle)
151 Clone(nativeHandle, out handle).ThrowIfFailed("Failed to clone native handle");
152 return new PlaceHandle(handle, true);
156 internal void ForeachProperty(Action<string, string> action)
158 PropertiesCallback callback = (index, total, key, value, userData) =>
164 ForeachProperty(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get property list from native handle");
167 internal void ForeachCategory(Action<PlaceCategoryHandle> action)
169 // PlaceCategoryHandle is valid only in this callback and users should not keep its reference
170 CategoriesCallback callback = (index, total, handle, userData) =>
172 action(new PlaceCategoryHandle(handle, true));
176 ForeachCategory(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get category list from native handle");
179 internal void ForeachAttribute(Action<PlaceAttributeHandle> action)
181 // PlaceAttributeHandle is valid only in this callback and users should not keep its reference
182 AttributesCallback callback = (index, total, handle, userData) =>
184 action(new PlaceAttributeHandle(handle, true));
188 ForeachAttribute(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get attributes list from native handle");
191 internal void ForeachContact(Action<PlaceContactHandle> action)
193 // PlaceContactHandle is valid only in this callback and users should not keep its reference
194 ContactsCallback callback = (index, total, handle, userData) =>
196 action(new PlaceContactHandle(handle, true));
200 ForeachContact(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get contacts list from native handle");
203 internal void ForeachEditorial(Action<PlaceEditorialHandle> action)
205 // PlaceEditorialHandle is valid only in this callback and users should not keep its reference
206 EditorialsCallback callback = (index, total, handle, userData) =>
208 action(new PlaceEditorialHandle(handle, true));
212 ForeachEditorial(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get editorial list from native handle");
215 internal void ForeachImage(Action<PlaceImageHandle> action)
217 // PlaceImageHandle is valid only in this callback and users should not keep its reference
218 ImagesCallback callback = (index, total, handle, userData) =>
220 action(new PlaceImageHandle(handle, true));
224 ForeachImage(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get image list from native handle");
227 internal void ForeachReview(Action<PlaceReviewHandle> action)
229 // PlaceReviewHandle is valid only in this callback and users should not keep its reference
230 ReviewsCallback callback = (index, total, handle, userData) =>
232 action(new PlaceReviewHandle(handle, true));
236 ForeachReview(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get review list from native handle");