From: Kichan Kwon Date: Tue, 22 Aug 2017 10:42:54 +0000 (+0900) Subject: [Information] Make a common class for integrating key-value functions X-Git-Tag: preview1-00199~2^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F74%2F145474%2F15;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [Information] Make a common class for integrating key-value functions - You can get the runtime feature with using string key - http://tizen.org/runtimefeature/FEATURE_NAME - Information class just checks whether this key is runtime feature or not and pass to the appropriate class - For convenience, key and type check functions are embedded in the get function - Before run get function, these are automatically run Change-Id: I0f1f6137afbb1f0409d16b433376b2d3de46b2c5 Signed-off-by: Kichan Kwon --- diff --git a/src/Tizen.System.Information/Common/Information.cs b/src/Tizen.System.Information/Common/Information.cs new file mode 100755 index 000000000..5ec9dc01c --- /dev/null +++ b/src/Tizen.System.Information/Common/Information.cs @@ -0,0 +1,197 @@ +/* +* Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the License); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an AS IS BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; + +namespace Tizen.System +{ + /// + /// The Information class provides functions to obtain various system information. + /// + public static class Information + { + internal const string HttpPrefix = "http://"; + internal const string RuntimeInfoStringKeyPrefix = "tizen.org/runtimefeature/"; + + internal const string RuntimeInfoStringKeyBluetooth = "bluetooth"; + internal const string RuntimeInfoStringKeyTetheringWiFi = "tethering.wifi"; + internal const string RuntimeInfoStringKeyTetheringBluetooth = "tethering.bluetooth"; + internal const string RuntimeInfoStringKeyTetheringUsb = "tethering.usb"; + internal const string RuntimeInfoStringKeyPacketData = "packetdata"; + internal const string RuntimeInfoStringKeyDataRoaming = "dataroaming"; + internal const string RuntimeInfoStringKeyVibration = "vibration"; + internal const string RuntimeInfoStringKeyAudioJackConnected = "audiojack.connected"; + internal const string RuntimeInfoStringKeyBatteryCharging = "battery.charging"; + internal const string RuntimeInfoStringKeyTvOut = "tvout"; + internal const string RuntimeInfoStringKeyCharger = "charger"; + internal const string RuntimeInfoStringKeyAutoRotation = "autorotation"; + internal const string RuntimeInfoStringKeyGps = "gps"; + internal const string RuntimeInfoStringKeyAudioJackType = "audiojack.type"; + + + private static readonly Dictionary StringEnumMapping = new Dictionary + { + [RuntimeInfoStringKeyPrefix + RuntimeInfoStringKeyBluetooth] = RuntimeInfoKey.Bluetooth, + [RuntimeInfoStringKeyPrefix + RuntimeInfoStringKeyTetheringWiFi] = RuntimeInfoKey.WifiHotspot, + [RuntimeInfoStringKeyPrefix + RuntimeInfoStringKeyTetheringBluetooth] = RuntimeInfoKey.BluetoothTethering, + [RuntimeInfoStringKeyPrefix + RuntimeInfoStringKeyTetheringUsb] = RuntimeInfoKey.UsbTethering, + [RuntimeInfoStringKeyPrefix + RuntimeInfoStringKeyPacketData] = RuntimeInfoKey.PacketData, + [RuntimeInfoStringKeyPrefix + RuntimeInfoStringKeyDataRoaming] = RuntimeInfoKey.DataRoaming, + [RuntimeInfoStringKeyPrefix + RuntimeInfoStringKeyVibration] = RuntimeInfoKey.Vibration, + [RuntimeInfoStringKeyPrefix + RuntimeInfoStringKeyAudioJackConnected] = RuntimeInfoKey.AudioJack, + [RuntimeInfoStringKeyPrefix + RuntimeInfoStringKeyBatteryCharging] = RuntimeInfoKey.BatteryIsCharging, + [RuntimeInfoStringKeyPrefix + RuntimeInfoStringKeyTvOut] = RuntimeInfoKey.TvOut, + [RuntimeInfoStringKeyPrefix + RuntimeInfoStringKeyCharger] = RuntimeInfoKey.Charger, + [RuntimeInfoStringKeyPrefix + RuntimeInfoStringKeyAutoRotation] = RuntimeInfoKey.AutoRotation, + [RuntimeInfoStringKeyPrefix + RuntimeInfoStringKeyGps] = RuntimeInfoKey.Gps, + [RuntimeInfoStringKeyPrefix + RuntimeInfoStringKeyAudioJackType] = RuntimeInfoKey.AudioJackConnector + }; + + internal static readonly Dictionary EnumStringMapping = new Dictionary + { + [RuntimeInfoKey.Bluetooth] = RuntimeInfoStringKeyBluetooth, + [RuntimeInfoKey.WifiHotspot] = RuntimeInfoStringKeyTetheringWiFi, + [RuntimeInfoKey.BluetoothTethering] = RuntimeInfoStringKeyTetheringBluetooth, + [RuntimeInfoKey.UsbTethering] = RuntimeInfoStringKeyTetheringUsb, + [RuntimeInfoKey.PacketData] = RuntimeInfoStringKeyPacketData, + [RuntimeInfoKey.DataRoaming] = RuntimeInfoStringKeyDataRoaming, + [RuntimeInfoKey.Vibration] = RuntimeInfoStringKeyVibration, + [RuntimeInfoKey.AudioJack] = RuntimeInfoStringKeyAudioJackConnected, + [RuntimeInfoKey.BatteryIsCharging] = RuntimeInfoStringKeyBatteryCharging, + [RuntimeInfoKey.TvOut] = RuntimeInfoStringKeyTvOut, + [RuntimeInfoKey.Charger] = RuntimeInfoStringKeyCharger, + [RuntimeInfoKey.AutoRotation] = RuntimeInfoStringKeyAutoRotation, + [RuntimeInfoKey.Gps] = RuntimeInfoStringKeyGps, + [RuntimeInfoKey.AudioJackConnector] = RuntimeInfoStringKeyAudioJackType + }; + + [EditorBrowsable(EditorBrowsableState.Never)] + private static bool ConvertStringToRuntimeInfoKey(string key, out RuntimeInfoKey feature) + { + string filteredKey = key.StartsWith(HttpPrefix) ? key.Substring(HttpPrefix.Length) : key; + feature = default(RuntimeInfoKey); + + return StringEnumMapping.TryGetValue(filteredKey, out feature); + } + + [EditorBrowsable(EditorBrowsableState.Never)] + private static bool TryGetRuntimeInfoValue(RuntimeInfoKey key, out T value) + { + value = default(T); + + if (!RuntimeInfo.Is(key)) + { + Log.Error(InformationErrorFactory.LogTag, "Invalid return type"); + return false; + } + + return RuntimeInfo.TryGetValue(key, out value); + } + + [EditorBrowsable(EditorBrowsableState.Never)] + private static bool TryGetSystemInfoValue(string key, out T value) + { + value = default(T); + + if (!SystemInfo.IsValidKey(key)) + { + Log.Error(InformationErrorFactory.LogTag, "Invalid key"); + return false; + } + + if (!SystemInfo.Is(key)) + { + Log.Error(InformationErrorFactory.LogTag, "Invalid return type"); + return false; + } + + return SystemInfo.TryGetValue(key, out value); + } + + /// + /// Gets the value of the feature. + /// + /// 4 + /// The type of . + /// The name of the feature. + /// The value of the given feature. + /// Returns true on success, otherwise false. + public static bool TryGetValue(string key, out T value) + { + RuntimeInfoKey runtimeFeature; + + if (ConvertStringToRuntimeInfoKey(key, out runtimeFeature)) + { + return TryGetRuntimeInfoValue(runtimeFeature, out value); + } + else + { + return TryGetSystemInfoValue(key, out value); + } + } + + /// + /// Registers a change event callback for given runtime feature key. + /// + /// + /// This function is only for runtime feature. + /// + /// 4 + /// The name of runtime feature which wants to register callback. + /// The callback function to subscribe. + /// Thrown when the is invalid. + /// Thrown when the feature related is not supported. + public static void SetCallback(string key, EventHandler callback) + { + RuntimeInfoKey runtimeFeature; + + if (!ConvertStringToRuntimeInfoKey(key, out runtimeFeature)) + { + Log.Error(InformationErrorFactory.LogTag, "Invalid key"); + InformationErrorFactory.ThrowException(InformationError.InvalidParameter); + } + + RuntimeInfo.SetCallback(runtimeFeature, callback); + } + + /// + /// Unregisters a change event callback for given runtime feature key. + /// + /// + /// This function is only for runtime feature. + /// + /// 4 + /// The name of runtime feature which wants to unregister callback. + /// The callback function to unsubscribe. + /// Thrown when the is invalid. + /// Thrown when the feature related is not supported. + public static void UnsetCallback(string key, EventHandler callback) + { + RuntimeInfoKey runtimeFeature; + + if (!ConvertStringToRuntimeInfoKey(key, out runtimeFeature)) + { + Log.Error(InformationErrorFactory.LogTag, "Invalid key"); + InformationErrorFactory.ThrowException(InformationError.InvalidParameter); + } + + RuntimeInfo.UnsetCallback(runtimeFeature, callback); + } + } +} diff --git a/src/Tizen.System.Information/Interop/Interop.RuntimeInfo.cs b/src/Tizen.System.Information/Interop/Interop.RuntimeInfo.cs index 8c177a1da..d34d53aee 100755 --- a/src/Tizen.System.Information/Interop/Interop.RuntimeInfo.cs +++ b/src/Tizen.System.Information/Interop/Interop.RuntimeInfo.cs @@ -22,7 +22,7 @@ internal static partial class Interop { internal static partial class RuntimeInfo { - public delegate void RuntimeInformationChangedCallback(RuntimeInformationKey key, IntPtr userData); + public delegate void RuntimeInformationChangedCallback(RuntimeInfoKey key, IntPtr userData); [StructLayout(LayoutKind.Sequential)] public struct MemoryInfo @@ -63,16 +63,16 @@ internal static partial class Interop } [DllImport(Libraries.RuntimeInfo, EntryPoint = "runtime_info_get_value_int")] - public static extern InformationError GetValue(RuntimeInformationKey key, out int status); + public static extern InformationError GetValue(RuntimeInfoKey key, out int status); [DllImport(Libraries.RuntimeInfo, EntryPoint = "runtime_info_get_value_bool")] - public static extern InformationError GetValue(RuntimeInformationKey key, out bool status); + public static extern InformationError GetValue(RuntimeInfoKey key, out bool status); [DllImport(Libraries.RuntimeInfo, EntryPoint = "runtime_info_get_value_double")] - public static extern InformationError GetValue(RuntimeInformationKey key, out double status); + public static extern InformationError GetValue(RuntimeInfoKey key, out double status); [DllImport(Libraries.RuntimeInfo, EntryPoint = "runtime_info_get_value_string")] - public static extern InformationError GetValue(RuntimeInformationKey key, out string status); + public static extern InformationError GetValue(RuntimeInfoKey key, out string status); [DllImport(Libraries.RuntimeInfo, EntryPoint = "runtime_info_get_system_memory_info")] public static extern InformationError GetSystemMemoryInfo(out MemoryInfo memoryInfo); @@ -96,9 +96,9 @@ internal static partial class Interop public static extern InformationError GetProcessorMaxFrequency(int coreId, out int cpuFreq); [DllImport(Libraries.RuntimeInfo, EntryPoint = "runtime_info_set_changed_cb")] - public static extern InformationError SetRuntimeInfoChangedCallback(RuntimeInformationKey runtimeInfoKey, RuntimeInformationChangedCallback cb, IntPtr userData); + public static extern InformationError SetRuntimeInfoChangedCallback(RuntimeInfoKey runtimeInfoKey, RuntimeInformationChangedCallback cb, IntPtr userData); [DllImport(Libraries.RuntimeInfo, EntryPoint = "runtime_info_unset_changed_cb")] - public static extern InformationError UnsetRuntimeInfoChangedCallback(RuntimeInformationKey runtimeInfoKey); + public static extern InformationError UnsetRuntimeInfoChangedCallback(RuntimeInfoKey runtimeInfoKey); } } diff --git a/src/Tizen.System.Information/RuntimeInfo/Enumerations.cs b/src/Tizen.System.Information/RuntimeInfo/Enumerations.cs index 8b2fcf024..da3b370f6 100755 --- a/src/Tizen.System.Information/RuntimeInfo/Enumerations.cs +++ b/src/Tizen.System.Information/RuntimeInfo/Enumerations.cs @@ -14,14 +14,15 @@ * limitations under the License. */ -using System; +using System.ComponentModel; namespace Tizen.System { + [EditorBrowsable(EditorBrowsableState.Never)] /// /// Enumeration for the runtime information key. /// - public enum RuntimeInformationKey + internal enum RuntimeInfoKey { /// /// Indicates whether Bluetooth is enabled. diff --git a/src/Tizen.System.Information/RuntimeInfo/RuntimeFeatureStatusChangedEventArgs.cs b/src/Tizen.System.Information/RuntimeInfo/RuntimeFeatureStatusChangedEventArgs.cs new file mode 100755 index 000000000..dbfacd85f --- /dev/null +++ b/src/Tizen.System.Information/RuntimeInfo/RuntimeFeatureStatusChangedEventArgs.cs @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the License); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an AS IS BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +using System; + +namespace Tizen.System +{ + /// + /// RuntimeFeatureStatusChangedEventArgs is an extended EventArgs class. This class contains event arguments for runtime event listeners. + /// + public class RuntimeFeatureStatusChangedEventArgs : EventArgs + { + /// + /// The key indicating the runtime system preference which was changed. + /// It includes the prefix "http://" though you don't use for registering callback. + /// + public String Key { get; internal set; } + } +} diff --git a/src/Tizen.System.Information/RuntimeInfo/RuntimeInfo.cs b/src/Tizen.System.Information/RuntimeInfo/RuntimeInfo.cs new file mode 100755 index 000000000..9ce011a5e --- /dev/null +++ b/src/Tizen.System.Information/RuntimeInfo/RuntimeInfo.cs @@ -0,0 +1,219 @@ +/* +* Copyright (c) 2016 - 2017 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the License); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an AS IS BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +using System; +using System.Collections.Generic; +using System.IO; +using System.ComponentModel; + +namespace Tizen.System +{ + [EditorBrowsable(EditorBrowsableState.Never)] + internal static class RuntimeInfo + { + private static RuntimeInfoEventHandler BluetoothEnabled = new RuntimeInfoEventHandler(RuntimeInfoKey.Bluetooth); + private static RuntimeInfoEventHandler WifiHotspotEnabled = new RuntimeInfoEventHandler(RuntimeInfoKey.WifiHotspot); + private static RuntimeInfoEventHandler BluetoothTetheringEnabled = new RuntimeInfoEventHandler(RuntimeInfoKey.BluetoothTethering); + private static RuntimeInfoEventHandler UsbTetheringEnabled = new RuntimeInfoEventHandler(RuntimeInfoKey.UsbTethering); + private static RuntimeInfoEventHandler PacketDataEnabled = new RuntimeInfoEventHandler(RuntimeInfoKey.PacketData); + private static RuntimeInfoEventHandler DataRoamingEnabled = new RuntimeInfoEventHandler(RuntimeInfoKey.DataRoaming); + private static RuntimeInfoEventHandler VibrationEnabled = new RuntimeInfoEventHandler(RuntimeInfoKey.Vibration); + private static RuntimeInfoEventHandler AudioJackConnected = new RuntimeInfoEventHandler(RuntimeInfoKey.AudioJack); + private static RuntimeInfoEventHandler GpsStatusChanged = new RuntimeInfoEventHandler(RuntimeInfoKey.Gps); + private static RuntimeInfoEventHandler BatteryIsCharging = new RuntimeInfoEventHandler(RuntimeInfoKey.BatteryIsCharging); + private static RuntimeInfoEventHandler TvOutConnected = new RuntimeInfoEventHandler(RuntimeInfoKey.TvOut); + private static RuntimeInfoEventHandler AudioJackConnectorChanged = new RuntimeInfoEventHandler(RuntimeInfoKey.AudioJackConnector); + private static RuntimeInfoEventHandler ChargerConnected = new RuntimeInfoEventHandler(RuntimeInfoKey.Charger); + private static RuntimeInfoEventHandler AutoRotationEnabled = new RuntimeInfoEventHandler(RuntimeInfoKey.AutoRotation); + + internal static readonly Dictionary s_keyDataTypeMapping = new Dictionary + { + [RuntimeInfoKey.Bluetooth] = typeof(bool), + [RuntimeInfoKey.WifiHotspot] = typeof(bool), + [RuntimeInfoKey.BluetoothTethering] = typeof(bool), + [RuntimeInfoKey.UsbTethering] = typeof(bool), + [RuntimeInfoKey.PacketData] = typeof(bool), + [RuntimeInfoKey.DataRoaming] = typeof(bool), + [RuntimeInfoKey.Vibration] = typeof(bool), + [RuntimeInfoKey.AudioJack] = typeof(bool), + [RuntimeInfoKey.BatteryIsCharging] = typeof(bool), + [RuntimeInfoKey.TvOut] = typeof(bool), + [RuntimeInfoKey.Charger] = typeof(bool), + [RuntimeInfoKey.AutoRotation] = typeof(bool), + [RuntimeInfoKey.Gps] = typeof(int), + [RuntimeInfoKey.AudioJackConnector] = typeof(int) + }; + + /// + /// Validates the data type of the status represented by the runtime key. + /// Note that this is a generic method. + /// + /// The generic type to validate. + /// The runtime information key for which the status type is validated. + /// True if the data type matches. + /// Thrown when the is invalid. + internal static bool Is(RuntimeInfoKey key) + { + if (!s_keyDataTypeMapping.ContainsKey(key)) + { + Log.Error(InformationErrorFactory.LogTag, "Invalid data type"); + throw new ArgumentException("Invalid parameter"); + } + + return s_keyDataTypeMapping[key] == typeof(T); + } + + /// + /// Gets the status of runtime key. + /// Note that this is a generic method. + /// + /// The generic type to return. + /// The runtime information key for which the current should be read. + /// The value of the given feature. + /// Returns true on success, otherwise false. + internal static bool TryGetValue(RuntimeInfoKey key, out T value) + { + Type type; + value = default(T); + + if (!s_keyDataTypeMapping.TryGetValue(key, out type)) + { + Log.Error(InformationErrorFactory.LogTag, "Invalid key"); + return false; + } + + if (type == typeof(bool)) + { + InformationError ret = Interop.RuntimeInfo.GetValue(TvProductHelper.ConvertKeyIfTvProduct(key), out bool val); + + if (ret != InformationError.None) + { + Log.Error(InformationErrorFactory.LogTag, "Interop failed to get value for key {0}", key.ToString()); + return false; + } + + value = (T)(object)val; + } + else if(type == typeof(int)) + { + InformationError ret = Interop.RuntimeInfo.GetValue(TvProductHelper.ConvertKeyIfTvProduct(key), out int val); + + if (ret != InformationError.None) + { + Log.Error(InformationErrorFactory.LogTag, "Interop failed to get value for key {0}", key.ToString()); + return false; + } + + value = (T)(object)val; + } + + return true; + } + + private static void FindEventHandler(RuntimeInfoKey key, ref RuntimeInfoEventHandler handler) + { + switch (key) + { + case RuntimeInfoKey.Bluetooth: + handler = BluetoothEnabled; + break; + case RuntimeInfoKey.WifiHotspot: + handler = WifiHotspotEnabled; + break; + case RuntimeInfoKey.BluetoothTethering: + handler = BluetoothTetheringEnabled; + break; + case RuntimeInfoKey.UsbTethering: + handler = UsbTetheringEnabled; + break; + case RuntimeInfoKey.PacketData: + handler = PacketDataEnabled; + break; + case RuntimeInfoKey.DataRoaming: + handler = DataRoamingEnabled; + break; + case RuntimeInfoKey.Vibration: + handler = VibrationEnabled; + break; + case RuntimeInfoKey.AudioJack: + handler = AudioJackConnected; + break; + case RuntimeInfoKey.Gps: + handler = GpsStatusChanged; + break; + case RuntimeInfoKey.BatteryIsCharging: + handler = BatteryIsCharging; + break; + case RuntimeInfoKey.TvOut: + handler = TvOutConnected; + break; + case RuntimeInfoKey.AudioJackConnector: + handler = AudioJackConnectorChanged; + break; + case RuntimeInfoKey.Charger: + handler = ChargerConnected; + break; + case RuntimeInfoKey.AutoRotation: + handler = AutoRotationEnabled; + break; + default: + handler = null; + break; + } + } + + /// + /// Registers a change event callback for given key. + /// + /// The runtime information key which wants to register callback. + /// The callback function to subscribe. + /// Thrown when the is invalid. + /// Thrown when the feature related is not supported. + internal static void SetCallback(RuntimeInfoKey key, EventHandler callback) + { + RuntimeInfoEventHandler handler = null; + + FindEventHandler(key, ref handler); + if (handler == null) + { + Log.Error(InformationErrorFactory.LogTag, "Invalid key"); + InformationErrorFactory.ThrowException(InformationError.InvalidParameter); + } + + handler.EventHandler += callback; + } + + /// + /// Unregisters a change event callback for given key. + /// + /// The runtime information key which wants to unregister callback. + /// The callback function to unsubscribe. + /// Thrown when the is invalid. + internal static void UnsetCallback(RuntimeInfoKey key, EventHandler callback) + { + RuntimeInfoEventHandler handler = null; + + FindEventHandler(key, ref handler); + if (handler == null) + { + Log.Error(InformationErrorFactory.LogTag, "Invalid key"); + InformationErrorFactory.ThrowException(InformationError.InvalidParameter); + } + + handler.EventHandler -= callback; + } + } +} diff --git a/src/Tizen.System.Information/RuntimeInfo/RuntimeInfoEventHandler.cs b/src/Tizen.System.Information/RuntimeInfo/RuntimeInfoEventHandler.cs index 445ceca8e..733e0f1c4 100755 --- a/src/Tizen.System.Information/RuntimeInfo/RuntimeInfoEventHandler.cs +++ b/src/Tizen.System.Information/RuntimeInfo/RuntimeInfoEventHandler.cs @@ -22,16 +22,16 @@ namespace Tizen.System [EditorBrowsable(EditorBrowsableState.Never)] internal class RuntimeInfoEventHandler { - private RuntimeInformationKey Key; - private event EventHandler Handler; + private RuntimeInfoKey Key; + private event EventHandler Handler; - internal RuntimeInfoEventHandler(RuntimeInformationKey key) + internal RuntimeInfoEventHandler(RuntimeInfoKey key) { Key = key; Handler = null; } - internal event EventHandler EventHandler + internal event EventHandler EventHandler { add { @@ -61,11 +61,11 @@ namespace Tizen.System } } - private void RuntimeInformationChangedCallback(RuntimeInformationKey key, IntPtr userData) + private void RuntimeInformationChangedCallback(RuntimeInfoKey key, IntPtr userData) { - RuntimeKeyStatusChangedEventArgs eventArgs = new RuntimeKeyStatusChangedEventArgs() + RuntimeFeatureStatusChangedEventArgs eventArgs = new RuntimeFeatureStatusChangedEventArgs() { - Key = key + Key = Information.HttpPrefix + Information.RuntimeInfoStringKeyPrefix + (Information.EnumStringMapping.ContainsKey(key) ? Information.EnumStringMapping[key] : "Invalid") }; Handler?.Invoke(null, eventArgs); diff --git a/src/Tizen.System.Information/RuntimeInfo/RuntimeInformation.cs b/src/Tizen.System.Information/RuntimeInfo/RuntimeInformation.cs deleted file mode 100755 index c4ef6c635..000000000 --- a/src/Tizen.System.Information/RuntimeInfo/RuntimeInformation.cs +++ /dev/null @@ -1,230 +0,0 @@ -/* -* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved -* -* Licensed under the Apache License, Version 2.0 (the License); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an AS IS BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.ComponentModel; -using System.Runtime.InteropServices; - -namespace Tizen.System -{ - /// - /// The RuntimeInformation provides functions to obtain the runtime information of various system preferences. - /// - public static class RuntimeInformation - { - private static RuntimeInfoEventHandler BluetoothEnabled = new RuntimeInfoEventHandler(RuntimeInformationKey.Bluetooth); - private static RuntimeInfoEventHandler WifiHotspotEnabled = new RuntimeInfoEventHandler(RuntimeInformationKey.WifiHotspot); - private static RuntimeInfoEventHandler BluetoothTetheringEnabled = new RuntimeInfoEventHandler(RuntimeInformationKey.BluetoothTethering); - private static RuntimeInfoEventHandler UsbTetheringEnabled = new RuntimeInfoEventHandler(RuntimeInformationKey.UsbTethering); - private static RuntimeInfoEventHandler PacketDataEnabled = new RuntimeInfoEventHandler(RuntimeInformationKey.PacketData); - private static RuntimeInfoEventHandler DataRoamingEnabled = new RuntimeInfoEventHandler(RuntimeInformationKey.DataRoaming); - private static RuntimeInfoEventHandler VibrationEnabled = new RuntimeInfoEventHandler(RuntimeInformationKey.Vibration); - private static RuntimeInfoEventHandler AudioJackConnected = new RuntimeInfoEventHandler(RuntimeInformationKey.AudioJack); - private static RuntimeInfoEventHandler GpsStatusChanged = new RuntimeInfoEventHandler(RuntimeInformationKey.Gps); - private static RuntimeInfoEventHandler BatteryIsCharging = new RuntimeInfoEventHandler(RuntimeInformationKey.BatteryIsCharging); - private static RuntimeInfoEventHandler TvOutConnected = new RuntimeInfoEventHandler(RuntimeInformationKey.TvOut); - private static RuntimeInfoEventHandler AudioJackConnectorChanged = new RuntimeInfoEventHandler(RuntimeInformationKey.AudioJackConnector); - private static RuntimeInfoEventHandler ChargerConnected = new RuntimeInfoEventHandler(RuntimeInformationKey.Charger); - private static RuntimeInfoEventHandler AutoRotationEnabled = new RuntimeInfoEventHandler(RuntimeInformationKey.AutoRotation); - - internal static readonly Dictionary s_keyDataTypeMapping = new Dictionary - { - [RuntimeInformationKey.Bluetooth] = typeof(bool), - [RuntimeInformationKey.WifiHotspot] = typeof(bool), - [RuntimeInformationKey.BluetoothTethering] = typeof(bool), - [RuntimeInformationKey.UsbTethering] = typeof(bool), - [RuntimeInformationKey.PacketData] = typeof(bool), - [RuntimeInformationKey.DataRoaming] = typeof(bool), - [RuntimeInformationKey.Vibration] = typeof(bool), - [RuntimeInformationKey.AudioJack] = typeof(bool), - [RuntimeInformationKey.BatteryIsCharging] = typeof(bool), - [RuntimeInformationKey.TvOut] = typeof(bool), - [RuntimeInformationKey.Charger] = typeof(bool), - [RuntimeInformationKey.AutoRotation] = typeof(bool), - [RuntimeInformationKey.Gps] = typeof(int), - [RuntimeInformationKey.AudioJackConnector] = typeof(int) - }; - - /// - /// Validates the data type of the status represented by the runtime key. - /// Note that this is a generic method. - /// - /// 3 - /// The generic type to validate. - /// The runtime information key for which the status type is validated. - /// True if the data type matches. - /// Thrown when the is invalid. - public static bool Is(RuntimeInformationKey key) - { - if (!s_keyDataTypeMapping.ContainsKey(key)) - { - Log.Error(InformationErrorFactory.LogTag, "Invalid data type"); - throw new ArgumentException("Invalid parameter"); - } - - return s_keyDataTypeMapping[key] == typeof(T); - } - - /// - /// Gets the status of runtime key. - /// Note that this is a generic method. - /// - /// 4 - /// The generic type to return. - /// The runtime information key for which the current should be read. - /// The value of the given feature. - /// Returns true on success, otherwise false. - public static bool TryGetValue(RuntimeInformationKey key, out T value) - { - Type type; - value = default(T); - - if (!s_keyDataTypeMapping.TryGetValue(key, out type)) - { - Log.Error(InformationErrorFactory.LogTag, "Invalid key"); - return false; - } - - if (type == typeof(bool)) - { - InformationError ret = Interop.RuntimeInfo.GetValue(TvProductHelper.ConvertKeyIfTvProduct(key), out bool val); - - if (ret != InformationError.None) - { - Log.Error(InformationErrorFactory.LogTag, "Interop failed to get value for key {0}", key.ToString()); - return false; - } - - value = (T)(object)val; - } - else if(type == typeof(int)) - { - InformationError ret = Interop.RuntimeInfo.GetValue(TvProductHelper.ConvertKeyIfTvProduct(key), out int val); - - if (ret != InformationError.None) - { - Log.Error(InformationErrorFactory.LogTag, "Interop failed to get value for key {0}", key.ToString()); - return false; - } - - value = (T)(object)val; - } - - return true; - } - - [EditorBrowsable(EditorBrowsableState.Never)] - private static void FindEventHandler(RuntimeInformationKey key, ref RuntimeInfoEventHandler handler) - { - switch (key) - { - case RuntimeInformationKey.Bluetooth: - handler = BluetoothEnabled; - break; - case RuntimeInformationKey.WifiHotspot: - handler = WifiHotspotEnabled; - break; - case RuntimeInformationKey.BluetoothTethering: - handler = BluetoothTetheringEnabled; - break; - case RuntimeInformationKey.UsbTethering: - handler = UsbTetheringEnabled; - break; - case RuntimeInformationKey.PacketData: - handler = PacketDataEnabled; - break; - case RuntimeInformationKey.DataRoaming: - handler = DataRoamingEnabled; - break; - case RuntimeInformationKey.Vibration: - handler = VibrationEnabled; - break; - case RuntimeInformationKey.AudioJack: - handler = AudioJackConnected; - break; - case RuntimeInformationKey.Gps: - handler = GpsStatusChanged; - break; - case RuntimeInformationKey.BatteryIsCharging: - handler = BatteryIsCharging; - break; - case RuntimeInformationKey.TvOut: - handler = TvOutConnected; - break; - case RuntimeInformationKey.AudioJackConnector: - handler = AudioJackConnectorChanged; - break; - case RuntimeInformationKey.Charger: - handler = ChargerConnected; - break; - case RuntimeInformationKey.AutoRotation: - handler = AutoRotationEnabled; - break; - default: - handler = null; - break; - } - } - - /// - /// Registers a change event callback for given key. - /// - /// 4 - /// The runtime information key which wants to register callback. - /// The callback function to subscribe. - /// Thrown when the is invalid. - /// Thrown when the feature related is not supported. - public static void SetCallback(RuntimeInformationKey key, EventHandler callback) - { - RuntimeInfoEventHandler handler = null; - - FindEventHandler(key, ref handler); - if (handler == null) - { - Log.Error(InformationErrorFactory.LogTag, "Invalid key"); - InformationErrorFactory.ThrowException(InformationError.InvalidParameter); - } - - handler.EventHandler += callback; - } - - /// - /// Unregisters a change event callback for given key. - /// - /// 4 - /// The runtime information key which wants to unregister callback. - /// The callback function to unsubscribe. - /// Thrown when the is invalid. - public static void UnsetCallback(RuntimeInformationKey key, EventHandler callback) - { - RuntimeInfoEventHandler handler = null; - - FindEventHandler(key, ref handler); - if (handler == null) - { - Log.Error(InformationErrorFactory.LogTag, "Invalid key"); - InformationErrorFactory.ThrowException(InformationError.InvalidParameter); - } - - handler.EventHandler -= callback; - } - } -} diff --git a/src/Tizen.System.Information/RuntimeInfo/RuntimeKeyStatusChangedEventArgs.cs b/src/Tizen.System.Information/RuntimeInfo/RuntimeKeyStatusChangedEventArgs.cs deleted file mode 100755 index c145c930d..000000000 --- a/src/Tizen.System.Information/RuntimeInfo/RuntimeKeyStatusChangedEventArgs.cs +++ /dev/null @@ -1,35 +0,0 @@ -/* -* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved -* -* Licensed under the Apache License, Version 2.0 (the License); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an AS IS BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Tizen.System -{ - /// - /// RuntimeInfoChangedEventArgs is an extended EventArgs class. This class contains event arguments for runtime event listeners. - /// - public class RuntimeKeyStatusChangedEventArgs : EventArgs - { - /// - /// The key indicating the runtime system preference which was changed. - /// - public RuntimeInformationKey Key { get; internal set; } - } -} diff --git a/src/Tizen.System.Information/RuntimeInfo/TvProductHelper.cs b/src/Tizen.System.Information/RuntimeInfo/TvProductHelper.cs index 73b45f9d3..df9e3a249 100755 --- a/src/Tizen.System.Information/RuntimeInfo/TvProductHelper.cs +++ b/src/Tizen.System.Information/RuntimeInfo/TvProductHelper.cs @@ -25,26 +25,26 @@ namespace Tizen.System { private static int is_TV_product = -1; - private static readonly Dictionary s_keyTVkeyMapping = new Dictionary + private static readonly Dictionary s_keyTVkeyMapping = new Dictionary { - [RuntimeInformationKey.Bluetooth] = 5, - [RuntimeInformationKey.WifiHotspot] = 6, - [RuntimeInformationKey.BluetoothTethering] = 7, - [RuntimeInformationKey.UsbTethering] = 8, - [RuntimeInformationKey.PacketData] = 13, - [RuntimeInformationKey.DataRoaming] = 14, - [RuntimeInformationKey.Vibration] = 16, - [RuntimeInformationKey.AudioJack] = 20, - [RuntimeInformationKey.BatteryIsCharging] = 22, - [RuntimeInformationKey.TvOut] = 18, - [RuntimeInformationKey.Charger] = 26, - [RuntimeInformationKey.AutoRotation] = 28, - [RuntimeInformationKey.Gps] = 21, - [RuntimeInformationKey.AudioJackConnector] = 20 + [RuntimeInfoKey.Bluetooth] = 5, + [RuntimeInfoKey.WifiHotspot] = 6, + [RuntimeInfoKey.BluetoothTethering] = 7, + [RuntimeInfoKey.UsbTethering] = 8, + [RuntimeInfoKey.PacketData] = 13, + [RuntimeInfoKey.DataRoaming] = 14, + [RuntimeInfoKey.Vibration] = 16, + [RuntimeInfoKey.AudioJack] = 20, + [RuntimeInfoKey.BatteryIsCharging] = 22, + [RuntimeInfoKey.TvOut] = 18, + [RuntimeInfoKey.Charger] = 26, + [RuntimeInfoKey.AutoRotation] = 28, + [RuntimeInfoKey.Gps] = 21, + [RuntimeInfoKey.AudioJackConnector] = 20 }; /// This function is for a TV product. It will be removed. - internal static RuntimeInformationKey ConvertKeyIfTvProduct(RuntimeInformationKey key) + internal static RuntimeInfoKey ConvertKeyIfTvProduct(RuntimeInfoKey key) { bool is_key_existed = false; string profile; @@ -73,7 +73,7 @@ namespace Tizen.System { InformationErrorFactory.ThrowException(InformationError.InvalidParameter); } - return (RuntimeInformationKey)key_TV; + return (RuntimeInfoKey)key_TV; } } } diff --git a/src/Tizen.System.Information/SystemInfo/SystemInfo.cs b/src/Tizen.System.Information/SystemInfo/SystemInfo.cs index 5f410e78d..ba7afd5a4 100755 --- a/src/Tizen.System.Information/SystemInfo/SystemInfo.cs +++ b/src/Tizen.System.Information/SystemInfo/SystemInfo.cs @@ -19,9 +19,7 @@ using System.ComponentModel; namespace Tizen.System { - /// - /// System Information class. This class has methods which can be used to obtain device information. - /// + [EditorBrowsable(EditorBrowsableState.Never)] public static class SystemInfo { [EditorBrowsable(EditorBrowsableState.Never)] @@ -47,11 +45,10 @@ namespace Tizen.System /// /// Checks if the type of value for the given feature is T. /// - /// 3 /// Type of value for the feature key. /// The name of the feature. /// True if type of value for the given feature is T, otherwise false. - public static bool Is(string key) + internal static bool Is(string key) { Interop.SystemInfo.SystemInfoValueType valueType; Interop.SystemInfo.SystemInfoType keyType = GetValueType(key, out valueType); @@ -77,10 +74,9 @@ namespace Tizen.System /// /// Checks if the given key is a valid feature. /// - /// 3 /// The name of the feature. /// True if the key is valid, otherwise false. - public static bool IsValidKey(string key) + internal static bool IsValidKey(string key) { Interop.SystemInfo.SystemInfoValueType valueType; return GetValueType(key, out valueType) != Interop.SystemInfo.SystemInfoType.None; @@ -89,12 +85,11 @@ namespace Tizen.System /// /// Gets the value of the feature. /// - /// 3 /// Type of key value. /// The name of the feature. /// The value of the given feature. /// Returns true on success, otherwise false. - public static bool TryGetValue(string key, out T value) + internal static bool TryGetValue(string key, out T value) { bool res = false; if (typeof(T) == typeof(bool)) @@ -131,7 +126,6 @@ namespace Tizen.System /// /// Gets the bool value of the feature. /// - /// 3 /// The name of the feature. /// The value of the given feature. /// Returns true on success, otherwise false. @@ -165,7 +159,6 @@ namespace Tizen.System /// /// Gets the int value of the feature. /// - /// 3 /// The name of the feature. /// The value of the given feature. /// Returns true on success, otherwise false. @@ -200,11 +193,10 @@ namespace Tizen.System /// /// Gets the double value of the feature. /// - /// 3 /// The name of the feature. /// The value of the given feature. /// Returns true on success, otherwise false. - public static bool TryGetValue(string key, out double value) + internal static bool TryGetValue(string key, out double value) { Interop.SystemInfo.SystemInfoValueType valueType; Interop.SystemInfo.SystemInfoType keyType = GetValueType(key, out valueType); @@ -235,7 +227,6 @@ namespace Tizen.System /// /// Gets the string value of the feature. /// - /// 3 /// The name of the feature. /// The value of the given feature. /// Returns true on success, otherwise false. diff --git a/src/Tizen.System.Information/Usage/SystemCpuUsage.cs b/src/Tizen.System.Information/Usage/SystemCpuUsage.cs index 5573e0e26..d72b4628e 100755 --- a/src/Tizen.System.Information/Usage/SystemCpuUsage.cs +++ b/src/Tizen.System.Information/Usage/SystemCpuUsage.cs @@ -24,9 +24,9 @@ namespace Tizen.System /// public class SystemCpuUsage { - internal Interop.RuntimeInfo.CpuUsage Usage; - internal int[] CurrentFrequencies; - internal int[] MaxFrequencies; + private Interop.RuntimeInfo.CpuUsage Usage; + private int[] CurrentFrequencies; + private int[] MaxFrequencies; /// /// The constructor of SystemCpuUsage class. diff --git a/src/Tizen.System.Information/Usage/SystemMemoryUsage.cs b/src/Tizen.System.Information/Usage/SystemMemoryUsage.cs index f7508aee7..41ec78f54 100755 --- a/src/Tizen.System.Information/Usage/SystemMemoryUsage.cs +++ b/src/Tizen.System.Information/Usage/SystemMemoryUsage.cs @@ -23,7 +23,7 @@ namespace Tizen.System /// public class SystemMemoryUsage { - internal Interop.RuntimeInfo.MemoryInfo Info; + private Interop.RuntimeInfo.MemoryInfo Info; /// /// The constructor of MemoryInformation class.