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_address_list_append")]
23 internal static extern ErrorCode ListAppend(this AddressListHandle /* maps_address_list_h */ addressList, AddressHandle /* maps_address_h */ address);
25 [DllImport(Libraries.MapService, EntryPoint = "maps_address_list_remove")]
26 internal static extern ErrorCode ListRemove(this AddressListHandle /* maps_address_list_h */ addressList, AddressHandle /* maps_address_h */ address);
28 [DllImport(Libraries.MapService, EntryPoint = "maps_address_list_get_length")]
29 internal static extern ErrorCode ListGetLength(this AddressListHandle /* maps_address_list_h */ addressList, out int length);
32 internal class AddressListHandle : SafeMapsHandle
34 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
35 internal delegate bool AddressCallback(int index, IntPtr /* maps_address_h */ addressHandle, IntPtr /* void */ userData);
37 [DllImport(Libraries.MapService, EntryPoint = "maps_address_list_create")]
38 internal static extern ErrorCode Create(out IntPtr /* maps_address_list_h */ addressList);
40 [DllImport(Libraries.MapService, EntryPoint = "maps_address_list_destroy")]
41 internal static extern ErrorCode Destroy(IntPtr /* maps_address_list_h */ addressList);
43 [DllImport(Libraries.MapService, EntryPoint = "maps_address_list_foreach")]
44 internal static extern ErrorCode Foreach(IntPtr /* maps_address_list_h */ addressList, AddressCallback callback, IntPtr /* void */ userData);
46 internal AddressListHandle() : base(IntPtr.Zero, true, Destroy)
48 Create(out handle).ThrowIfFailed("Failed to create native handle");
51 internal AddressListHandle(IntPtr handle, bool needToRelease) : base(handle, needToRelease, Destroy)
55 internal void Foreach(Action<AddressHandle> action)
57 AddressCallback callback = (index, handle, userData) =>
59 action(AddressHandle.CloneFrom(handle));
63 Foreach(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get address list from native handle");