Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Maps / Interop / Interop.AddressList.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_address_list_append")]
23     internal static extern ErrorCode ListAppend(this AddressListHandle /* maps_address_list_h */ addressList, AddressHandle /* maps_address_h */ address);
24
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);
27
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);
30
31
32     internal class AddressListHandle : SafeMapsHandle
33     {
34         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
35         internal delegate bool AddressCallback(int index, IntPtr /* maps_address_h */ addressHandle, IntPtr /* void */ userData);
36
37         [DllImport(Libraries.MapService, EntryPoint = "maps_address_list_create")]
38         internal static extern ErrorCode Create(out IntPtr /* maps_address_list_h */ addressList);
39
40         [DllImport(Libraries.MapService, EntryPoint = "maps_address_list_destroy")]
41         internal static extern ErrorCode Destroy(IntPtr /* maps_address_list_h */ addressList);
42
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);
45
46         internal AddressListHandle() : base(IntPtr.Zero, true, Destroy)
47         {
48             Create(out handle).ThrowIfFailed("Failed to create native handle");
49         }
50
51         internal AddressListHandle(IntPtr handle, bool needToRelease) : base(handle, needToRelease, Destroy)
52         {
53         }
54
55         internal void Foreach(Action<AddressHandle> action)
56         {
57             AddressCallback callback = (index, handle, userData) =>
58             {
59                 action(AddressHandle.CloneFrom(handle));
60                 return true;
61             };
62
63             Foreach(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get address list from native handle");
64         }
65     }
66 }