Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Maps / Interop / Interop.Area.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     internal class AreaHandle : SafeMapsHandle
23     {
24         [DllImport(Libraries.MapService, EntryPoint = "maps_area_create_rectangle")]
25         internal static extern ErrorCode CreateRectangle(IntPtr /* maps_coordinates_h */ topLeft, IntPtr /* maps_coordinates_h */ bottomRight, out IntPtr /* maps_area_h */ area);
26
27         [DllImport(Libraries.MapService, EntryPoint = "maps_area_create_circle")]
28         internal static extern ErrorCode CreateCircle(IntPtr /* maps_coordinates_h */ center, double radius, out IntPtr /* maps_area_h */ area);
29
30         [DllImport(Libraries.MapService, EntryPoint = "maps_area_destroy")]
31         internal static extern ErrorCode Destroy(IntPtr /* maps_area_h */ area);
32
33         [DllImport(Libraries.MapService, EntryPoint = "maps_area_clone")]
34         internal static extern ErrorCode Clone(IntPtr /* maps_area_h */ origin, out IntPtr /* maps_area_h */ cloned);
35
36         internal AreaHandle(IntPtr handle, bool needToRelease) : base(handle, needToRelease, Destroy)
37         {
38         }
39
40         internal AreaHandle(CoordinatesHandle topLeft, CoordinatesHandle bottomRight) : this(IntPtr.Zero, true)
41         {
42             IntPtr _topLeft = (topLeft != null ? topLeft : IntPtr.Zero);
43             IntPtr _bottomRight = (bottomRight != null ? bottomRight : IntPtr.Zero);
44             CreateRectangle(_topLeft, _bottomRight, out handle).ThrowIfFailed("Failed to create native handle");
45         }
46
47         internal AreaHandle(CoordinatesHandle center, double radius) : this(IntPtr.Zero, true)
48         {
49             IntPtr _center = (center != null ? center : IntPtr.Zero);
50             CreateCircle(_center, radius, out handle).ThrowIfFailed("Failed to create native handle");
51         }
52
53         internal static AreaHandle CloneFrom(IntPtr nativeHandle)
54         {
55             IntPtr handle;
56             Clone(nativeHandle, out handle).ThrowIfFailed("Failed to clone native handle");
57             return new AreaHandle(handle, true);
58         }
59
60         internal static AreaHandle Create(IntPtr nativeHandle)
61         {
62             return new AreaHandle(nativeHandle, true);
63         }
64     }
65 }