1 /// Copyright 2016 by Samsung Electronics, Inc.,
3 /// This software is the confidential and proprietary information
4 /// of Samsung Electronics, Inc. ("Confidential Information"). You
5 /// shall not disclose such Confidential Information and shall use
6 /// it only in accordance with the terms of the license agreement
7 /// you entered into with Samsung.
11 namespace Tizen.Network.IoTConnectivity
14 /// This class represents response from a resource.
15 /// It provides APIs to manage response.
17 public class Response : IDisposable
19 private bool _disposed = false;
22 /// Constructor of Response
25 /// Response response = new Response();
30 /// Destructor of the Response class.
38 /// Gets or sets the result from/into the reponse
40 public ResponseCode Result { get; set; }
43 /// Gets or sets the representation from/into the reponse
45 public Representation Representation { get; set; }
48 /// Gets or sets the options from/into the reponse
50 public ResourceOptions Options { get; set; }
53 /// Releases any unmanaged resources used by this object.
58 GC.SuppressFinalize(this);
61 internal bool Send(IntPtr requestHandle)
63 IntPtr responseHandle = IntPtr.Zero;
64 int ret = Interop.IoTConnectivity.Server.Response.Create(requestHandle, out responseHandle);
65 if (ret != (int)IoTConnectivityError.None)
67 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to send response");
71 ret = Interop.IoTConnectivity.Server.Response.SetResult(responseHandle, (int)Result);
72 if (ret != (int)IoTConnectivityError.None)
74 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to send response");
75 Interop.IoTConnectivity.Server.Response.Destroy(responseHandle);
79 if (Representation != null)
81 ret = Interop.IoTConnectivity.Server.Response.SetRepresentation(responseHandle, Representation._representationHandle);
82 if (ret != (int)IoTConnectivityError.None)
84 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to send response");
85 Interop.IoTConnectivity.Server.Response.Destroy(responseHandle);
92 ret = Interop.IoTConnectivity.Server.Response.SetOptions(responseHandle, Options._resourceOptionsHandle);
93 if (ret != (int)IoTConnectivityError.None)
95 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to send response");
96 Interop.IoTConnectivity.Server.Response.Destroy(responseHandle);
101 ret = Interop.IoTConnectivity.Server.Response.Send(responseHandle);
102 if (ret != (int)IoTConnectivityError.None)
104 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to send response");
105 Interop.IoTConnectivity.Server.Response.Destroy(responseHandle);
109 Interop.IoTConnectivity.Server.Response.Destroy(responseHandle);
114 /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
116 /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
117 protected virtual void Dispose(bool disposing)