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 namespace Tizen.Multimedia
22 internal static partial class Interop
24 internal static class Radio
26 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
27 internal delegate void SeekCompletedCallback(int frequency, IntPtr userData);
29 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
30 internal delegate void ScanUpdatedCallback(int frequency, IntPtr userData);
32 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
33 internal delegate void ScanStoppedCallback(IntPtr userData);
35 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
36 internal delegate void ScanCompletedCallback(IntPtr userData);
38 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
39 internal delegate void InterruptedCallback(RadioInterruptedReason reason, IntPtr userData);
42 [DllImport(Libraries.Radio, EntryPoint = "radio_create")]
43 internal static extern RadioError Create(out RadioHandle radio);
45 [DllImport(Libraries.Radio, EntryPoint = "radio_destroy")]
46 internal static extern RadioError Destroy(IntPtr radio);
48 [DllImport(Libraries.Radio, EntryPoint = "radio_get_state")]
49 internal static extern RadioError GetState(RadioHandle radio, out RadioState state);
51 [DllImport(Libraries.Radio, EntryPoint = "radio_start")]
52 internal static extern RadioError Start(RadioHandle radio);
54 [DllImport(Libraries.Radio, EntryPoint = "radio_stop")]
55 internal static extern RadioError Stop(RadioHandle radio);
57 [DllImport(Libraries.Radio, EntryPoint = "radio_seek_up")]
58 internal static extern RadioError SeekUp(RadioHandle radio, SeekCompletedCallback callback,
59 IntPtr userData = default(IntPtr));
61 [DllImport(Libraries.Radio, EntryPoint = "radio_seek_down")]
62 internal static extern RadioError SeekDown(RadioHandle radio, SeekCompletedCallback callback,
63 IntPtr userData = default(IntPtr));
65 [DllImport(Libraries.Radio, EntryPoint = "radio_set_frequency")]
66 internal static extern RadioError SetFrequency(RadioHandle radio, int frequency);
68 [DllImport(Libraries.Radio, EntryPoint = "radio_get_frequency")]
69 internal static extern RadioError GetFrequency(RadioHandle radio, out int frequency);
71 [DllImport(Libraries.Radio, EntryPoint = "radio_get_signal_strength")]
72 internal static extern RadioError GetSignalStrength(RadioHandle radio, out int strength);
74 [DllImport(Libraries.Radio, EntryPoint = "radio_scan_start")]
75 internal static extern RadioError ScanStart(RadioHandle radio, ScanUpdatedCallback callback,
76 IntPtr userData = default(IntPtr));
78 [DllImport(Libraries.Radio, EntryPoint = "radio_scan_stop")]
79 internal static extern RadioError ScanStop(RadioHandle radio, ScanStoppedCallback callback,
80 IntPtr userData = default(IntPtr));
82 [DllImport(Libraries.Radio, EntryPoint = "radio_set_mute")]
83 internal static extern RadioError SetMute(RadioHandle radio, bool muted);
85 [DllImport(Libraries.Radio, EntryPoint = "radio_is_muted")]
86 internal static extern RadioError GetMuted(RadioHandle radio, out bool muted);
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));
92 [DllImport(Libraries.Radio, EntryPoint = "radio_unset_scan_completed_cb")]
93 internal static extern RadioError UnsetScanCompletedCb(RadioHandle radio);
95 [DllImport(Libraries.Radio, EntryPoint = "radio_set_interrupted_cb")]
96 internal static extern RadioError SetInterruptedCb(RadioHandle radio,
97 InterruptedCallback callback, IntPtr userData = default(IntPtr));
99 [DllImport(Libraries.Radio, EntryPoint = "radio_unset_interrupted_cb")]
100 internal static extern RadioError UnsetInterruptedCb(RadioHandle radio);
102 [DllImport(Libraries.Radio, EntryPoint = "radio_get_frequency_range")]
103 internal static extern RadioError GetFrequencyRange(RadioHandle radio, out int minFreq, out int maxFreq);
105 [DllImport(Libraries.Radio, EntryPoint = "radio_get_channel_spacing")]
106 internal static extern RadioError GetChannelSpacing(RadioHandle radio, out int channelSpacing);
108 [DllImport(Libraries.Radio, EntryPoint = "radio_set_volume")]
109 internal static extern RadioError SetVolume(RadioHandle radio, float volume);
111 [DllImport(Libraries.Radio, EntryPoint = "radio_get_volume")]
112 internal static extern RadioError GetVolume(RadioHandle radio, out float volume);
115 internal class RadioHandle : SafeHandle
117 protected RadioHandle() : base(IntPtr.Zero, true)
121 public override bool IsInvalid => handle == IntPtr.Zero;
123 protected override bool ReleaseHandle()
125 var ret = Radio.Destroy(handle);
126 if (ret != RadioError.None)
128 Log.Debug(GetType().FullName, $"Failed to release native handle.");