Beispiel #1
0
        /// <summary>
        /// Get the preferred plmn list asynchronously.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <returns>List of NetworkPreferredPlmnInfo.</returns>
        /// <privilege>http://tizen.org/privilege/telephony</privilege>
        /// <feature>http://tizen.org/feature/network.telephony</feature>
        /// <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 network instance is invalid or when method failed due to invalid operation.</exception>
        public Task <IEnumerable <NetworkPreferredPlmnInfo> > GetNetworkPreferredPlmn()
        {
            TaskCompletionSource <IEnumerable <NetworkPreferredPlmnInfo> > task = new TaskCompletionSource <IEnumerable <NetworkPreferredPlmnInfo> >();
            IntPtr id;

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

                    NetworkPreferredPlmnListStruct plmnStruct       = Marshal.PtrToStructure <NetworkPreferredPlmnListStruct>(dataResponse);
                    IEnumerable <NetworkPreferredPlmnInfo> plmnInfo = NetworkStructConversions.ConvertNetworkPreferredPlmnStruct(plmnStruct);
                    task.SetResult(plmnInfo);
                });

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

            int ret = Interop.Tapi.Network.GetNetworkPreferredPlmn(_handle, _response_map[id], id);

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

            return(task.Task);
        }
Beispiel #2
0
        internal static IEnumerable <NetworkPreferredPlmnInfo> ConvertNetworkPreferredPlmnStruct(NetworkPreferredPlmnListStruct plmnStruct)
        {
            List <NetworkPreferredPlmnInfo> plmnList = new List <NetworkPreferredPlmnInfo>();

            for (int i = 0; i <= plmnStruct.Count; i++)
            {
                NetworkPreferredPlmnInfo plmnInfo = new NetworkPreferredPlmnInfo();
                plmnInfo.idex        = plmnStruct.PlmnList[i].Index;
                plmnInfo.NwName      = plmnStruct.PlmnList[i].NetworkName;
                plmnInfo.NwPlmn      = plmnStruct.PlmnList[i].Plmn;
                plmnInfo.SvcProvName = plmnStruct.PlmnList[i].SnName;
                plmnInfo.SysType     = plmnStruct.PlmnList[i].Type;
                plmnList.Add(plmnInfo);
            }

            return(plmnList);
        }