Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Maps / Interop / Interop.Place.Filter.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_filter_get")]
23     internal static extern ErrorCode Get(this PlaceFilterHandle /* maps_place_filter_h */ filter, string key, out string value);
24
25     [DllImport(Libraries.MapService, EntryPoint = "maps_place_filter_set")]
26     internal static extern ErrorCode Set(this PlaceFilterHandle /* maps_place_filter_h */ filter, string key, string value);
27
28     [DllImport(Libraries.MapService, EntryPoint = "maps_place_filter_get_keyword")]
29     internal static extern ErrorCode GetKeyword(this PlaceFilterHandle /* maps_place_filter_h */ filter, out string keyword);
30
31     [DllImport(Libraries.MapService, EntryPoint = "maps_place_filter_set_keyword")]
32     internal static extern ErrorCode SetKeyword(this PlaceFilterHandle /* maps_place_filter_h */ filter, string keyword);
33
34     [DllImport(Libraries.MapService, EntryPoint = "maps_place_filter_get_place_name")]
35     internal static extern ErrorCode GetPlaceName(this PlaceFilterHandle /* maps_place_filter_h */ filter, out string placeName);
36
37     [DllImport(Libraries.MapService, EntryPoint = "maps_place_filter_set_place_name")]
38     internal static extern ErrorCode SetPlaceName(this PlaceFilterHandle /* maps_place_filter_h */ filter, string placeName);
39
40     [DllImport(Libraries.MapService, EntryPoint = "maps_place_filter_get_category")]
41     internal static extern ErrorCode GetCategory(this PlaceFilterHandle /* maps_place_filter_h */ filter, out IntPtr /* maps_place_category_h */ category);
42
43     [DllImport(Libraries.MapService, EntryPoint = "maps_place_filter_set_category")]
44     internal static extern ErrorCode SetCategory(this PlaceFilterHandle /* maps_place_filter_h */ filter, PlaceCategoryHandle /* maps_place_category_h */ category);
45
46     [DllImport(Libraries.MapService, EntryPoint = "maps_place_filter_get_place_address")]
47     internal static extern ErrorCode GetPlaceAddress(this PlaceFilterHandle /* maps_place_filter_h */ filter, out string placeAddress);
48
49     [DllImport(Libraries.MapService, EntryPoint = "maps_place_filter_set_place_address")]
50     internal static extern ErrorCode SetPlaceAddress(this PlaceFilterHandle /* maps_place_filter_h */ filter, string placeAddress);
51
52     internal class PlaceFilterHandle : SafeMapsHandle
53     {
54         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
55         internal delegate bool PlaceFilterPropertiesCallback(int index, int total, string key, IntPtr /* void */ value, IntPtr /* void */ userData);
56
57         [DllImport(Libraries.MapService, EntryPoint = "maps_place_filter_foreach_property")]
58         internal static extern ErrorCode ForeachProperty(IntPtr /* maps_place_filter_h */ filter, PlaceFilterPropertiesCallback callback, IntPtr /* void */ userData);
59
60
61         [DllImport(Libraries.MapService, EntryPoint = "maps_place_filter_create")]
62         internal static extern ErrorCode Create(out IntPtr /* maps_place_filter_h */ filter);
63
64         [DllImport(Libraries.MapService, EntryPoint = "maps_place_filter_destroy")]
65         internal static extern ErrorCode Destroy(IntPtr /* maps_place_filter_h */ filter);
66
67         internal string Keyword
68         {
69             get { return NativeGet(this.GetKeyword); }
70             set { NativeSet(this.SetKeyword, value); }
71         }
72
73         internal string PlaceName
74         {
75             get { return NativeGet(this.GetPlaceName); }
76             set { NativeSet(this.SetPlaceName, value); }
77         }
78
79         internal string PlaceAddress
80         {
81             get { return NativeGet(this.GetPlaceAddress); }
82             set { NativeSet(this.SetPlaceAddress, value); }
83         }
84
85         internal PlaceCategoryHandle Category
86         {
87             get { return NativeGet(this.GetCategory, PlaceCategoryHandle.Create); }
88             set { NativeSet(this.SetCategory, value); }
89         }
90
91         public PlaceFilterHandle(IntPtr handle, bool needToRelease) : base(handle, needToRelease, Destroy)
92         {
93         }
94
95         public PlaceFilterHandle() : this(IntPtr.Zero, true)
96         {
97             Create(out handle).ThrowIfFailed("Failed to create native handle");
98         }
99
100         internal void ForeachProperty(Action<string, string> action)
101         {
102             PlaceFilterPropertiesCallback callback = (index, total, key, value, userData) =>
103             {
104                 action(key, Marshal.PtrToStringUni(value));
105                 return true;
106             };
107
108             ForeachProperty(handle, callback, IntPtr.Zero).WarnIfFailed("Failed to get address list from native handle");
109         }
110     }
111 }