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_coordinates_list_append")]
23 internal static extern ErrorCode Append(this CoordinatesListHandle /* maps_coordinates_list_h */ coordinatesList, IntPtr /* maps_coordinates_h */ coordinates);
25 [DllImport(Libraries.MapService, EntryPoint = "maps_coordinates_list_remove")]
26 internal static extern ErrorCode Remove(this CoordinatesListHandle /* maps_coordinates_list_h */ coordinatesList, CoordinatesHandle /* maps_coordinates_h */ coordinates);
29 internal class CoordinatesListHandle : SafeMapsHandle
31 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
32 internal delegate bool CoordinatesCallback(int index, IntPtr /* maps_coordinates_h */ coordinates, IntPtr /* void */ userData);
34 [DllImport(Libraries.MapService, EntryPoint = "maps_coordinates_list_create")]
35 internal static extern ErrorCode Create(out IntPtr /* maps_coordinates_list_h */ coordinatesList);
37 [DllImport(Libraries.MapService, EntryPoint = "maps_coordinates_list_destroy")]
38 internal static extern ErrorCode Destroy(IntPtr /* maps_coordinates_list_h */ coordinatesList);
40 [DllImport(Libraries.MapService, EntryPoint = "maps_coordinates_list_foreach")]
41 internal static extern ErrorCode Foreach(IntPtr /* maps_coordinates_list_h */ coordinatesList, CoordinatesCallback callback, IntPtr /* void */ userData);
43 internal CoordinatesListHandle(IntPtr handle, bool needToRelease) : base(handle, needToRelease, Destroy) { }
45 internal CoordinatesListHandle(bool needToRelease = true) : this(IntPtr.Zero, needToRelease)
47 Create(out handle).ThrowIfFailed("Failed to create native handle");
50 internal void Add(CoordinatesHandle handleToAdd)
52 using (var clonedHandle = CoordinatesHandle.CloneFrom(handleToAdd))
54 if (this.Append(clonedHandle).WarnIfFailed("Failed to add coordinates to the list"))
56 clonedHandle.HasOwnership = false;
61 internal void ForEach(Action<CoordinatesHandle> action)
63 CoordinatesCallback callback = (index, handle, userData) =>
65 action(CoordinatesHandle.CloneFrom(handle));
69 Foreach(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get coordinates list from native handle");