Example #1
0
        internal static MiscDeviceInfo ConvertMiscInfoStruct(MiscDeviceInfoStruct infoStruct)
        {
            MiscDeviceInfo deviceInfo = new MiscDeviceInfo();

            deviceInfo.Vendor = infoStruct.Vendor;
            deviceInfo.Device = infoStruct.Device;
            return(deviceInfo);
        }
Example #2
0
        /// <summary>
        /// Get device vendor name and device name of cellular dongle.
        /// </summary>
        /// <returns>Instance of MiscDeviceInfo.</returns>
        /// <privilege>http://tizen.org/privilege/telephony</privilege>
        /// <feature>http://tizen.org/feature/network.telephony</feature>
        /// <remarks>
        /// Result can be delivered with only cellular dongle insertion.
        /// </remarks>
        /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
        /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
        /// <exception cref="System.InvalidOperationException">Thrown when modem instance is invalid or when method failed due to invalid operation.</exception>
        public Task <MiscDeviceInfo> GetDeviceInfo()
        {
            TaskCompletionSource <MiscDeviceInfo> task = new TaskCompletionSource <MiscDeviceInfo>();
            IntPtr id;

            id = (IntPtr)_requestId++;
            _response_map[id] = (IntPtr handle, int result, IntPtr data, IntPtr key) =>
            {
                Task resultTask = new Task(() =>
                {
                    if (result != (int)TapiError.Success)
                    {
                        Log.Error(TapiUtility.LogTag, "Error occurs during getting the device name and vendor name, " + (TapiError)result);
                        task.SetException(new InvalidOperationException("Error occurs during getting the device name and vendor name, " + (TapiError)result));
                        return;
                    }

                    MiscDeviceInfoStruct infoStruct = Marshal.PtrToStructure <MiscDeviceInfoStruct>(data);
                    MiscDeviceInfo deviceInfo       = ModemStructConversions.ConvertMiscInfoStruct(infoStruct);
                    task.SetResult(deviceInfo);
                });

                resultTask.Start();
                resultTask.Wait();
                _response_map.Remove(key);
            };

            int ret = Interop.Tapi.Modem.GetDeviceInfo(_handle, _response_map[id], id);

            if (ret != (int)TapiError.Success)
            {
                Log.Error(TapiUtility.LogTag, "Failed to get the device vendor name and device name, Error: " + (TapiError)ret);
                TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
            }

            return(task.Task);
        }