Exemplo n.º 1
0
        private static void NativeDeleteResultCallbackHandler(IntPtr resource, int err, int requestType, IntPtr responseHandle, IntPtr userData)
        {
            IntPtr responseCompletionId = userData;
            TaskCompletionSource <RemoteResponse> responseCompletionSource = _taskCompletionMap[responseCompletionId];

            _taskCompletionMap.Remove(responseCompletionId);

            if (err == (int)(IoTConnectivityError.Iotivity))
            {
                RemoteResponse response = new RemoteResponse();
                response.Result         = ResponseCode.Forbidden;
                response.Representation = null;
                responseCompletionSource.TrySetResult(response);
            }
            else if (responseHandle != IntPtr.Zero)
            {
                try
                {
                    responseCompletionSource.TrySetResult(GetRemoteResponse(responseHandle));
                }
                catch (Exception exp)
                {
                    Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get RemoteResponse: ", exp.Message);
                    responseCompletionSource.TrySetException(exp);
                }
            }
            else
            {
                responseCompletionSource.TrySetException(IoTConnectivityErrorFactory.GetException((int)IoTConnectivityError.System));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Deletes the resource asynchronously.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <privilege>http://tizen.org/privilege/internet</privilege>
        /// <privlevel>public</privlevel>
        /// <returns>Remote response with result and representation.</returns>
        /// <feature>http://tizen.org/feature/iot.ocf</feature>
        public async Task <RemoteResponse> DeleteAsync()
        {
            TaskCompletionSource <RemoteResponse> tcsRemoteResponse = new TaskCompletionSource <RemoteResponse>();

            IntPtr id = IntPtr.Zero;

            lock (_responseCallbacksMap)
            {
                id = (IntPtr)_responseCallbackId++;
            }
            _responseCallbacksMap[id] = (IntPtr resource, int err, int requestType, IntPtr responseHandle, IntPtr userData) =>
            {
                IntPtr responseCallbackId = userData;
                lock (_responseCallbacksMap)
                {
                    _responseCallbacksMap.Remove(responseCallbackId);
                }
                if (err == (int)(IoTConnectivityError.Iotivity))
                {
                    RemoteResponse response = new RemoteResponse();
                    response.Result         = ResponseCode.Forbidden;
                    response.Representation = null;
                    tcsRemoteResponse.TrySetResult(response);
                }
                else if (responseHandle != IntPtr.Zero)
                {
                    try
                    {
                        tcsRemoteResponse.TrySetResult(GetRemoteResponse(responseHandle));
                    }
                    catch (Exception exp)
                    {
                        Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get RemoteResponse: ", exp.Message);
                        tcsRemoteResponse.TrySetException(exp);
                    }
                }
                else
                {
                    tcsRemoteResponse.TrySetException(IoTConnectivityErrorFactory.GetException((int)IoTConnectivityError.System));
                }
            };

            int errCode = Interop.IoTConnectivity.Client.RemoteResource.Delete(_remoteResourceHandle, _responseCallbacksMap[id], id);

            if (errCode != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to delete");
                tcsRemoteResponse.TrySetException(IoTConnectivityErrorFactory.GetException(errCode));
            }
            return(await tcsRemoteResponse.Task);
        }