Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.Radio / Interop / Interop.Radio.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 namespace Tizen.Multimedia
21 {
22     internal static partial class Interop
23     {
24         internal static class Radio
25         {
26             [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
27             internal delegate void SeekCompletedCallback(int frequency, IntPtr userData);
28
29             [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
30             internal delegate void ScanUpdatedCallback(int frequency, IntPtr userData);
31
32             [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
33             internal delegate void ScanStoppedCallback(IntPtr userData);
34
35             [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
36             internal delegate void ScanCompletedCallback(IntPtr userData);
37
38             [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
39             internal delegate void InterruptedCallback(RadioInterruptedReason reason, IntPtr userData);
40
41
42             [DllImport(Libraries.Radio, EntryPoint = "radio_create")]
43             internal static extern RadioError Create(out RadioHandle radio);
44
45             [DllImport(Libraries.Radio, EntryPoint = "radio_destroy")]
46             internal static extern RadioError Destroy(IntPtr radio);
47
48             [DllImport(Libraries.Radio, EntryPoint = "radio_get_state")]
49             internal static extern RadioError GetState(RadioHandle radio, out RadioState state);
50
51             [DllImport(Libraries.Radio, EntryPoint = "radio_start")]
52             internal static extern RadioError Start(RadioHandle radio);
53
54             [DllImport(Libraries.Radio, EntryPoint = "radio_stop")]
55             internal static extern RadioError Stop(RadioHandle radio);
56
57             [DllImport(Libraries.Radio, EntryPoint = "radio_seek_up")]
58             internal static extern RadioError SeekUp(RadioHandle radio, SeekCompletedCallback callback,
59                 IntPtr userData = default(IntPtr));
60
61             [DllImport(Libraries.Radio, EntryPoint = "radio_seek_down")]
62             internal static extern RadioError SeekDown(RadioHandle radio, SeekCompletedCallback callback,
63                 IntPtr userData = default(IntPtr));
64
65             [DllImport(Libraries.Radio, EntryPoint = "radio_set_frequency")]
66             internal static extern RadioError SetFrequency(RadioHandle radio, int frequency);
67
68             [DllImport(Libraries.Radio, EntryPoint = "radio_get_frequency")]
69             internal static extern RadioError GetFrequency(RadioHandle radio, out int frequency);
70
71             [DllImport(Libraries.Radio, EntryPoint = "radio_get_signal_strength")]
72             internal static extern RadioError GetSignalStrength(RadioHandle radio, out int strength);
73
74             [DllImport(Libraries.Radio, EntryPoint = "radio_scan_start")]
75             internal static extern RadioError ScanStart(RadioHandle radio, ScanUpdatedCallback callback,
76                 IntPtr userData = default(IntPtr));
77
78             [DllImport(Libraries.Radio, EntryPoint = "radio_scan_stop")]
79             internal static extern RadioError ScanStop(RadioHandle radio, ScanStoppedCallback callback,
80                 IntPtr userData = default(IntPtr));
81
82             [DllImport(Libraries.Radio, EntryPoint = "radio_set_mute")]
83             internal static extern RadioError SetMute(RadioHandle radio, bool muted);
84
85             [DllImport(Libraries.Radio, EntryPoint = "radio_is_muted")]
86             internal static extern RadioError GetMuted(RadioHandle radio, out bool muted);
87
88             [DllImport(Libraries.Radio, EntryPoint = "radio_set_scan_completed_cb")]
89             internal static extern RadioError SetScanCompletedCb(RadioHandle radio,
90                 ScanCompletedCallback callback, IntPtr userData = default(IntPtr));
91
92             [DllImport(Libraries.Radio, EntryPoint = "radio_unset_scan_completed_cb")]
93             internal static extern RadioError UnsetScanCompletedCb(RadioHandle radio);
94
95             [DllImport(Libraries.Radio, EntryPoint = "radio_set_interrupted_cb")]
96             internal static extern RadioError SetInterruptedCb(RadioHandle radio,
97                 InterruptedCallback callback, IntPtr userData = default(IntPtr));
98
99             [DllImport(Libraries.Radio, EntryPoint = "radio_unset_interrupted_cb")]
100             internal static extern RadioError UnsetInterruptedCb(RadioHandle radio);
101
102             [DllImport(Libraries.Radio, EntryPoint = "radio_get_frequency_range")]
103             internal static extern RadioError GetFrequencyRange(RadioHandle radio, out int minFreq, out int maxFreq);
104
105             [DllImport(Libraries.Radio, EntryPoint = "radio_get_channel_spacing")]
106             internal static extern RadioError GetChannelSpacing(RadioHandle radio, out int channelSpacing);
107
108             [DllImport(Libraries.Radio, EntryPoint = "radio_set_volume")]
109             internal static extern RadioError SetVolume(RadioHandle radio, float volume);
110
111             [DllImport(Libraries.Radio, EntryPoint = "radio_get_volume")]
112             internal static extern RadioError GetVolume(RadioHandle radio, out float volume);
113         }
114
115         internal class RadioHandle : SafeHandle
116         {
117             protected RadioHandle() : base(IntPtr.Zero, true)
118             {
119             }
120
121             public override bool IsInvalid => handle == IntPtr.Zero;
122
123             protected override bool ReleaseHandle()
124             {
125                 var ret = Radio.Destroy(handle);
126                 if (ret != RadioError.None)
127                 {
128                     Log.Debug(GetType().FullName, $"Failed to release native handle.");
129                     return false;
130                 }
131
132                 return true;
133             }
134         }
135     }
136 }