From: Dinesh Dwivedi Date: Wed, 18 May 2016 11:14:19 +0000 (+0530) Subject: [SystemInfo] Added base implementation X-Git-Tag: submit/tizen/20161214.063015~41^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6724a045f19ee7d79bb2d0f1d9467ad54ccd16a4;p=platform%2Fcore%2Fcsapi%2Fsystem.git [SystemInfo] Added base implementation Change-Id: Ibaea7b825eb7ae1eb1061e81c6882ac7435a8c2f Signed-off-by: Dinesh Dwivedi --- diff --git a/Tizen.System/Interop/Interop.Libraries.cs b/Tizen.System/Interop/Interop.Libraries.cs index f4ceadc..93a287c 100644 --- a/Tizen.System/Interop/Interop.Libraries.cs +++ b/Tizen.System/Interop/Interop.Libraries.cs @@ -1,22 +1,16 @@ -/// Copyright 2016 by Samsung Electronics, Inc., -/// -/// This software is the confidential and proprietary information -/// of Samsung Electronics, Inc. ("Confidential Information"). You -/// shall not disclose such Confidential Information and shall use -/// it only in accordance with the terms of the license agreement -/// you entered into with Samsung. - - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. internal static partial class Interop { internal static partial class Libraries { - public const string RuntimeInfo = "libcapi-system-runtime-info.so.0"; + internal const string RuntimeInfo = "libcapi-system-runtime-info.so.0"; + internal const string SystemInfo = "libcapi-system-info.so.0"; } } diff --git a/Tizen.System/Interop/Interop.SystemInfo.cs b/Tizen.System/Interop/Interop.SystemInfo.cs new file mode 100644 index 0000000..8b2bb4b --- /dev/null +++ b/Tizen.System/Interop/Interop.SystemInfo.cs @@ -0,0 +1,71 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; +using System.Runtime.InteropServices; + +internal static partial class Interop +{ + internal static partial class SystemInfo + { + internal enum ErrorCode + { + None = Tizen.Internals.Errors.ErrorCode.None, + InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter, + OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory, + IoError = Tizen.Internals.Errors.ErrorCode.IoError, + PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied, + NotSupported = Tizen.Internals.Errors.ErrorCode.NoSuchDevice, + } + + internal enum SystemInfoValueType + { + Bool = 0, + Int = 1, + Double = 2, + String = 3, + } + + internal enum SystemInfoType + { + platform, + Custom, + None, + } + + [DllImport(Libraries.SystemInfo, EntryPoint = "system_info_get_platform_type")] + internal static extern ErrorCode SystemInfoGetPlatformType(string key, out SystemInfoValueType type); + + [DllImport(Libraries.SystemInfo, EntryPoint = "system_info_get_custom_type")] + internal static extern ErrorCode SystemInfoGetCustomType(string key, out SystemInfoValueType type); + + [DllImport(Libraries.SystemInfo, EntryPoint = "system_info_get_platform_bool")] + internal static extern ErrorCode SystemInfoGetPlatformBool(string key, out bool value); + + [DllImport(Libraries.SystemInfo, EntryPoint = "system_info_get_platform_int")] + internal static extern ErrorCode SystemInfoGetPlatformInt(string key, out int value); + + [DllImport(Libraries.SystemInfo, EntryPoint = "system_info_get_platform_double")] + internal static extern ErrorCode SystemInfoGetPlatformDouble(string key, out double value); + + [DllImport(Libraries.SystemInfo, EntryPoint = "system_info_get_platform_string")] + internal static extern ErrorCode SystemInfoGetPlatformString(string key, out string value); + + [DllImport(Libraries.SystemInfo, EntryPoint = "system_info_get_custom_bool")] + internal static extern ErrorCode SystemInfoGetCustomBool(string key, out bool value); + + [DllImport(Libraries.SystemInfo, EntryPoint = "system_info_get_custom_int")] + internal static extern ErrorCode SystemInfoGetCustomInt(string key, out int value); + + [DllImport(Libraries.SystemInfo, EntryPoint = "system_info_get_custom_double")] + internal static extern ErrorCode SystemInfoGetCustomDouble(string key, out double value); + + [DllImport(Libraries.SystemInfo, EntryPoint = "system_info_get_custom_string")] + internal static extern ErrorCode SystemInfoGetCustomString(string key, out string value); + } +} diff --git a/Tizen.System/SystemInfo/SystemInfo.cs b/Tizen.System/SystemInfo/SystemInfo.cs new file mode 100644 index 0000000..d167a8c --- /dev/null +++ b/Tizen.System/SystemInfo/SystemInfo.cs @@ -0,0 +1,255 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; + +namespace Tizen.System.SystemInfo +{ + /// + /// System Information class. This class has methods which can be used to obtain device information + /// + public static class SystemInfo + { + private const string LogTag = "Tizen.System"; + + private static Interop.SystemInfo.SystemInfoType GetValueType(string key, out Interop.SystemInfo.SystemInfoValueType valueType) + { + Interop.SystemInfo.ErrorCode err = Interop.SystemInfo.SystemInfoGetPlatformType(key, out valueType); + if (err == Interop.SystemInfo.ErrorCode.None) + { + return Interop.SystemInfo.SystemInfoType.platform; + } + + Log.Debug(LogTag, string.Format("Key {0} not in platform system info", key)); + err = Interop.SystemInfo.SystemInfoGetCustomType(key, out valueType); + if (err == Interop.SystemInfo.ErrorCode.None) + { + return Interop.SystemInfo.SystemInfoType.Custom; + } + + Log.Debug(LogTag, string.Format("Key {0} not in custom system info", key)); + return Interop.SystemInfo.SystemInfoType.None; + } + + /// + /// Checks if type of value for given feature is T + /// + /// Type of value for feature key + /// The name of the feature + /// true if type of value for given feature is T, false otherwise + public static bool Is(string key) + { + Interop.SystemInfo.SystemInfoValueType valueType; + Interop.SystemInfo.SystemInfoType keyType = GetValueType(key, out valueType); + if (keyType == Interop.SystemInfo.SystemInfoType.None) + { + return false; + } + + switch (valueType) + { + case Interop.SystemInfo.SystemInfoValueType.Bool: + return typeof(T) == typeof(bool); + case Interop.SystemInfo.SystemInfoValueType.Double: + return typeof(T) == typeof(double); + case Interop.SystemInfo.SystemInfoValueType.Int: + return typeof(T) == typeof(int); + case Interop.SystemInfo.SystemInfoValueType.String: + return typeof(T) == typeof(string); + } + return false; + } + + /// + /// Checks if given key is valid feature + /// + /// The name of the feature + /// true of key is valid, false otherwise + public static bool IsValidKey(string key) + { + Interop.SystemInfo.SystemInfoValueType valueType; + return GetValueType(key, out valueType) != Interop.SystemInfo.SystemInfoType.None; + } + + /// + /// Gets the value of the feature. + /// + /// Type of key value + /// The name of the feature + /// The value of the given feature + /// return true on success otherwise false + public static bool TryGetValue(string key, out T value) + { + bool res = false; + if (typeof(T) == typeof(bool)) + { + bool val; + res = TryGetValue(key, out val); + value = (T)(object)val; + } + else if (typeof(T) == typeof(int)) + { + int val; + res = TryGetValue(key, out val); + value = (T)(object)val; + } + else if (typeof(T) == typeof(double)) + { + double val; + res = TryGetValue(key, out val); + value = (T)(object)val; + } + else if (typeof(T) == typeof(string)) + { + string val; + res = TryGetValue(key, out val); + value = (T)(object)val; + } + else + { + value = default(T); + } + return res; + } + + /// + /// Gets the bool value of the feature. + /// + /// The name of the feature + /// The value of the given feature + /// return true on success otherwise false + public static bool TryGetValue(string key, out bool value) + { + Interop.SystemInfo.SystemInfoValueType valueType; + Interop.SystemInfo.SystemInfoType keyType = GetValueType(key, out valueType); + + Interop.SystemInfo.ErrorCode err = Interop.SystemInfo.ErrorCode.InvalidParameter; + if (keyType == Interop.SystemInfo.SystemInfoType.platform) + { + err = Interop.SystemInfo.SystemInfoGetPlatformBool(key, out value); + } + else if (keyType == Interop.SystemInfo.SystemInfoType.Custom) + { + err = Interop.SystemInfo.SystemInfoGetCustomBool(key, out value); + } else + { + value = false; + } + + if (err != Interop.SystemInfo.ErrorCode.None) + { + Log.Warn(LogTag, string.Format("Failed to get value for key: {0}. err = {1}", key, err)); + return false; + } + + return true; + } + + /// + /// Gets the int value of the feature. + /// + /// The name of the feature + /// The value of the given feature + /// return true on success otherwise false + public static bool TryGetValue(string key, out int value) + { + Interop.SystemInfo.SystemInfoValueType valueType; + Interop.SystemInfo.SystemInfoType keyType = GetValueType(key, out valueType); + + Interop.SystemInfo.ErrorCode err = Interop.SystemInfo.ErrorCode.InvalidParameter; + if (keyType == Interop.SystemInfo.SystemInfoType.platform) + { + err = Interop.SystemInfo.SystemInfoGetPlatformInt(key, out value); + } + else if (keyType == Interop.SystemInfo.SystemInfoType.Custom) + { + err = Interop.SystemInfo.SystemInfoGetCustomInt(key, out value); + } + else + { + value = 0; + } + + if (err != Interop.SystemInfo.ErrorCode.None) + { + Log.Warn(LogTag, string.Format("Failed to get value for key: {0}. err = {1}", key, err)); + return false; + } + + return true; + } + + /// + /// Gets the double value of the feature. + /// + /// The name of the feature + /// The value of the given feature + /// return true on success otherwise false + public static bool TryGetValue(string key, out double value) + { + Interop.SystemInfo.SystemInfoValueType valueType; + Interop.SystemInfo.SystemInfoType keyType = GetValueType(key, out valueType); + + Interop.SystemInfo.ErrorCode err = Interop.SystemInfo.ErrorCode.InvalidParameter; + if (keyType == Interop.SystemInfo.SystemInfoType.platform) + { + err = Interop.SystemInfo.SystemInfoGetPlatformDouble(key, out value); + } + else if (keyType == Interop.SystemInfo.SystemInfoType.Custom) + { + err = Interop.SystemInfo.SystemInfoGetCustomDouble(key, out value); + } + else + { + value = 0; + } + + if (err != Interop.SystemInfo.ErrorCode.None) + { + Log.Warn(LogTag, string.Format("Failed to get value for key: {0}. err = {1}", key, err)); + return false; + } + + return true; + } + + /// + /// Gets the string value of the feature. + /// + /// The name of the feature + /// The value of the given feature + /// return true on success otherwise false + public static bool TryGetValue(string key, out string value) + { + Interop.SystemInfo.SystemInfoValueType valueType; + Interop.SystemInfo.SystemInfoType keyType = GetValueType(key, out valueType); + + Interop.SystemInfo.ErrorCode err = Interop.SystemInfo.ErrorCode.InvalidParameter; + if (keyType == Interop.SystemInfo.SystemInfoType.platform) + { + err = Interop.SystemInfo.SystemInfoGetPlatformString(key, out value); + } + else if (keyType == Interop.SystemInfo.SystemInfoType.Custom) + { + err = Interop.SystemInfo.SystemInfoGetCustomString(key, out value); + } + else + { + value = string.Empty; + } + + if (err != Interop.SystemInfo.ErrorCode.None) + { + Log.Warn(LogTag, string.Format("Failed to get value for key: {0}. err = {1}", key, err)); + return false; + } + + return true; + } + } +} diff --git a/Tizen.System/Tizen.System.csproj b/Tizen.System/Tizen.System.csproj index 2e6a0d7..194e3dc 100644 --- a/Tizen.System/Tizen.System.csproj +++ b/Tizen.System/Tizen.System.csproj @@ -9,7 +9,7 @@ Properties Tizen.System Tizen.System - v4.0 + v4.5 512 8.0.30703 @@ -66,6 +66,7 @@ + @@ -73,6 +74,7 @@ + diff --git a/packaging/csapi-tizen.system.spec b/packaging/csapi-tizen.system.spec index 4b05ac1..987d2ff 100755 --- a/packaging/csapi-tizen.system.spec +++ b/packaging/csapi-tizen.system.spec @@ -1,5 +1,4 @@ -%define dllpath %{_libdir}/mono/tizen -%define dllname Tizen.System.dll +%define BUILDCONF Debug Name: csapi-tizen.system Summary: Tizen System API for C# @@ -15,20 +14,19 @@ Source2: %{name}.pc.in # TODO: replace mono-compiler, mono-devel to mcs, mono-shlib-cop BuildRequires: mono-compiler BuildRequires: mono-devel -# TODO: replace mono-core to gacutil. -# mono-core should provide the symbol 'gacutil' -Requires(post): mono-core -Requires(postun): mono-core # P/Invoke Dependencies +BuildRequires: pkgconfig(csapi-tizen) BuildRequires: pkgconfig(capi-system-device) BuildRequires: pkgconfig(capi-system-runtime-info) +BuildRequires: pkgconfig(capi-system-info) # P/Invoke Runtime Dependencies # TODO: It should be removed after fix tizen-rpm-config +# DLL Dependencies Requires: capi-system-device Requires: capi-system-runtime-info -# DLL Dependencies +Requires: capi-system-info #BuildRequires: ... %description @@ -48,50 +46,21 @@ Development package for %{name} cp %{SOURCE1} . %build -# build dll -mcs -target:library -out:%{dllname} -keyfile:Tizen.System/Tizen.System.snk \ - Tizen.System/Properties/AssemblyInfo.cs \ - Tizen.System/System.cs \ - Tizen.System/Device/EventArgs.cs \ - Tizen.System/Device/Battery.cs \ - Tizen.System/Device/Display.cs \ - Tizen.System/Device/Haptic.cs \ - Tizen.System/Device/Led.cs \ - Tizen.System/Device/Power.cs \ - Tizen.System/Interop/Interop.Device.cs \ - Tizen.System/Interop/Interop.Libraries.cs \ - Tizen.System/Interop/Interop.RuntimeInfo.cs \ - Tizen.System/RuntimeInfo/CpuUsage.cs \ - Tizen.System/RuntimeInfo/Enumerations.cs \ - Tizen.System/RuntimeInfo/MemoryInformation.cs \ - Tizen.System/RuntimeInfo/RuntimeInfoErrorFactory.cs \ - Tizen.System/RuntimeInfo/RuntimeInformation.cs \ - Tizen.System/RuntimeInfo/RuntimeKeyStatusChangedEventArgs.cs - -# check p/invoke -if [ -x %{dllname} ]; then - RET=`mono-shlib-cop %{dllname}`; \ - CNT=`echo $RET | grep -E "^error:" | wc -l`; \ - if [ $CNT -gt 0 ]; then exit 1; fi -fi +xbuild Tizen.System/Tizen.System.csproj /p:Configuration=%{BUILDCONF} %install -# copy dll -mkdir -p %{buildroot}%{dllpath} -install -p -m 644 %{dllname} %{buildroot}%{dllpath} +gacutil -i Tizen.System/bin/%{BUILDCONF}/*.dll -root "%{buildroot}%{_libdir}" -package tizen # generate pkgconfig mkdir -p %{buildroot}%{_libdir}/pkgconfig -sed -e "s#@version@#%{version}#g" \ - -e "s#@dllpath@#%{dllpath}#g" \ - -e "s#@dllname@#%{dllname}#g" \ +sed -e "s#@name@#%{name}#g" \ + -e "s#@version@#%{version}#g" \ + -e "s#@libs@#%{pc_libs}#g" \ %{SOURCE2} > %{buildroot}%{_libdir}/pkgconfig/%{name}.pc -%post -gacutil -i %{dllpath}/%{dllname} %files -%{dllpath}/%{dllname} +%{_libdir}/mono %files devel %{_libdir}/pkgconfig/%{name}.pc