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 public class Response : IDisposable
28 private bool _disposed = false;
31 /// Constructor of Response
34 /// Response response = new Response();
39 /// Destructor of the Response class.
47 /// Gets or sets the result from/into the reponse
49 public ResponseCode Result { get; set; }
52 /// Gets or sets the representation from/into the reponse
54 public Representation Representation { get; set; }
57 /// Gets or sets the options from/into the reponse
59 public ResourceOptions Options { get; set; }
62 /// Releases any unmanaged resources used by this object.
67 GC.SuppressFinalize(this);
70 internal bool Send(IntPtr requestHandle)
72 IntPtr responseHandle = IntPtr.Zero;
73 int ret = Interop.IoTConnectivity.Server.Response.Create(requestHandle, out responseHandle);
74 if (ret != (int)IoTConnectivityError.None)
76 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to send response");
80 ret = Interop.IoTConnectivity.Server.Response.SetResult(responseHandle, (int)Result);
81 if (ret != (int)IoTConnectivityError.None)
83 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to send response");
84 Interop.IoTConnectivity.Server.Response.Destroy(responseHandle);
88 if (Representation != null)
90 ret = Interop.IoTConnectivity.Server.Response.SetRepresentation(responseHandle, Representation._representationHandle);
91 if (ret != (int)IoTConnectivityError.None)
93 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to send response");
94 Interop.IoTConnectivity.Server.Response.Destroy(responseHandle);
101 ret = Interop.IoTConnectivity.Server.Response.SetOptions(responseHandle, Options._resourceOptionsHandle);
102 if (ret != (int)IoTConnectivityError.None)
104 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to send response");
105 Interop.IoTConnectivity.Server.Response.Destroy(responseHandle);
110 ret = Interop.IoTConnectivity.Server.Response.Send(responseHandle);
111 if (ret != (int)IoTConnectivityError.None)
113 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to send response");
114 Interop.IoTConnectivity.Server.Response.Destroy(responseHandle);
118 Interop.IoTConnectivity.Server.Response.Destroy(responseHandle);
123 /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
125 /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
126 protected virtual void Dispose(bool disposing)