2 * Copyright (c) 2016 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.
20 namespace Tizen.Network.IoTConnectivity
23 /// This class represents response from a resource.
24 /// It provides APIs to manage response.
26 /// <since_tizen> 3 </since_tizen>
27 public class Response : IDisposable
29 private bool _disposed = false;
32 /// Constructor of Response.
34 /// <since_tizen> 3 </since_tizen>
36 /// Response response = new Response();
41 /// Destructor of the Response class.
49 /// Gets or sets the result from/into the response.
51 /// <since_tizen> 3 </since_tizen>
52 /// <value>The result from/into the response.</value>
53 public ResponseCode Result { get; set; }
56 /// Gets or sets the representation from/into the response.
58 /// <since_tizen> 3 </since_tizen>
59 /// <value>The representation from/into the response.</value>
60 public Representation Representation { get; set; }
63 /// Gets or sets the options from/into the response.
65 /// <since_tizen> 3 </since_tizen>
66 /// <value>The options from/into the response.</value>
67 public ResourceOptions Options { get; set; }
70 /// Releases any unmanaged resources used by this object.
72 /// <since_tizen> 3 </since_tizen>
76 GC.SuppressFinalize(this);
79 internal bool Send(IntPtr requestHandle)
81 IntPtr responseHandle = IntPtr.Zero;
82 int ret = Interop.IoTConnectivity.Server.Response.Create(requestHandle, out responseHandle);
83 if (ret != (int)IoTConnectivityError.None)
85 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to send response");
89 ret = Interop.IoTConnectivity.Server.Response.SetResult(responseHandle, (int)Result);
90 if (ret != (int)IoTConnectivityError.None)
92 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to send response");
93 Interop.IoTConnectivity.Server.Response.Destroy(responseHandle);
97 if (Representation != null)
99 ret = Interop.IoTConnectivity.Server.Response.SetRepresentation(responseHandle, Representation._representationHandle);
100 if (ret != (int)IoTConnectivityError.None)
102 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to send response");
103 Interop.IoTConnectivity.Server.Response.Destroy(responseHandle);
110 ret = Interop.IoTConnectivity.Server.Response.SetOptions(responseHandle, Options._resourceOptionsHandle);
111 if (ret != (int)IoTConnectivityError.None)
113 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to send response");
114 Interop.IoTConnectivity.Server.Response.Destroy(responseHandle);
119 ret = Interop.IoTConnectivity.Server.Response.Send(responseHandle);
120 if (ret != (int)IoTConnectivityError.None)
122 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to send response");
123 Interop.IoTConnectivity.Server.Response.Destroy(responseHandle);
127 Interop.IoTConnectivity.Server.Response.Destroy(responseHandle);
132 /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
134 /// <since_tizen> 3 </since_tizen>
135 /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
136 protected virtual void Dispose(bool disposing)