Пример #1
0
        internal static SsUssdMsgInfo ConvertSsMsgStruct(SsUssdMsgInfoStruct msgStruct)
        {
            SsUssdMsgInfo info = new SsUssdMsgInfo();

            info.Length     = msgStruct.Length;
            info.Dcs        = msgStruct.Dcs;
            info.UssdString = msgStruct.UssdString;
            info.Type       = msgStruct.Type;
            return(info);
        }
Пример #2
0
        internal static SsUssdMsgInfoStruct ConvertSsUssdMsgInfo(SsUssdMsgInfo info)
        {
            SsUssdMsgInfoStruct msgStruct = new SsUssdMsgInfoStruct();

            msgStruct.Type       = info.Type;
            msgStruct.Dcs        = info.Dcs;
            msgStruct.Length     = info.Length;
            msgStruct.UssdString = info.UssdString;
            return(msgStruct);
        }
Пример #3
0
        /// <summary>
        /// Sends a USSD string or User response to the Network.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <param name="info">The data coding scheme used</param>
        /// <returns>A task containing SS USSD response information.</returns>
        /// <feature>http://tizen.org/feature/network.telephony</feature>
        /// <privlevel>platform</privlevel>
        /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
        /// <exception cref="NotSupportedException">Thrown when telephony feature is not supported.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
        /// <exception cref="ArgumentNullException">Thrown when Ussd message info is passed as null.</exception>
        /// <exception cref="ArgumentException">Thrown when it is failed due to invalid parameter.</exception>
        /// <exception cref="InvalidOperationException">Thrown when it is failed due to invalid operation.</exception>
        public Task <SsUssdResponse> SsSendUssdRequest(SsUssdMsgInfo info)
        {
            TaskCompletionSource <SsUssdResponse> task = new TaskCompletionSource <SsUssdResponse>();
            IntPtr id = (IntPtr)_requestId++;

            _callbackMap[id] = (handle, result, data, key) =>
            {
                Task taskResult = new Task(() =>
                {
                    if (result != (int)SsCause.Success)
                    {
                        Log.Error(TapiUtility.LogTag, "Error occurs in sending USSD request: " + (SsCause)result);
                        task.SetException(new InvalidOperationException("Error occurs in sending USSD request, " + (SsCause)result));
                        return;
                    }

                    SsUssdResponseStruct response = Marshal.PtrToStructure <SsUssdResponseStruct>(data);
                    task.SetResult(SsStructConversions.ConvertSsUssdResponseStruct(response));
                });
                taskResult.Start();
                taskResult.Wait();
                _callbackMap.Remove(key);
            };

            if (info == null)
            {
                throw new ArgumentNullException("Ussd message info is null");
            }

            SsUssdMsgInfoStruct msgStruct = SsClassConversions.ConvertSsUssdMsgInfo(info);
            int ret = Interop.Tapi.Ss.SsSendUssdRequest(_handle, ref msgStruct, _callbackMap[id], id);

            if (ret != (int)TapiError.Success)
            {
                Log.Error(TapiUtility.LogTag, "Failed to send USSD request, Error: " + (TapiError)ret);
                TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
            }

            return(task.Task);
        }