2 * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 namespace Tizen.Applications
22 /// A class to represent result of payload.
24 /// <since_tizen> 9 </since_tizen>
25 public class PayloadAsyncResult : IDisposable
27 private PayloadAsyncResult(PayloadAsyncResultCode result, PeerInfo peer, string payloadId)
31 PayloadId = payloadId;
34 internal static PayloadAsyncResult CreateFromHandle(IntPtr handle)
36 Interop.Cion.ErrorCode ret = Interop.CionPayloadAsyncResult.CionPayloadAsyncResultGetResult(handle, out int code);
37 if (ret != Interop.Cion.ErrorCode.None)
39 throw CionErrorFactory.GetException(ret, "Fail to get result code from the AsyncResult");
42 ret = Interop.CionPayloadAsyncResult.CionPayloadAsyncResultGetPayloadID(handle, out string payloadId);
43 if (ret != Interop.Cion.ErrorCode.None)
45 throw CionErrorFactory.GetException(ret, "Fail to get payload id from the AsyncResult");
48 ret = Interop.CionPayloadAsyncResult.CionPayloadAsyncResultGetPeerInfo(handle, out IntPtr peer);
49 if (ret != Interop.Cion.ErrorCode.None)
51 throw CionErrorFactory.GetException(ret, "Fail to get peerinfo from the AsyncResult");
53 ret = Interop.CionPeerInfo.CionPeerInfoClone(peer, out PeerInfoSafeHandle clone);
54 if (ret != Interop.Cion.ErrorCode.None)
56 throw CionErrorFactory.GetException(ret, "Failed to clone peer info.");
59 return new PayloadAsyncResult((PayloadAsyncResultCode)code, new PeerInfo(clone), payloadId);
63 /// Gets the result of payload.
65 /// <since_tizen> 9 </since_tizen>
66 public PayloadAsyncResultCode Result { get; }
69 /// Gets the peer info of payload.
71 /// <since_tizen> 9 </since_tizen>
72 public PeerInfo PeerInfo { get; }
75 /// Gets the payload id.
77 /// <since_tizen> 9 </since_tizen>
78 public string PayloadId { get; }
80 #region IDisposable Support
81 private bool disposedValue = false;
84 /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
86 /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
87 /// <since_tizen> 9 </since_tizen>
88 protected virtual void Dispose(bool disposing)
101 /// Releases all resources used by the PayloadAsyncResult class.
103 /// <since_tizen> 9 </since_tizen>
104 public void Dispose()
107 GC.SuppressFinalize(this);