Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Convergence / Tizen.Convergence / InternalAppCommunicationService.cs
1 /*
2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 using System;
18 using System.ComponentModel;
19 using Tizen.Internals.Errors;
20
21 namespace Tizen.Convergence
22 {
23     /// <summary>
24     /// The class provides APIs to support App to App communication service which relies on a remote server.
25     /// The initialization and execution of a server app (the app on the side with the Remote Server, e.g. TV) and a client app (e.g. the app on the mobile or wearable device) are slightly different.
26     /// On the server side an instance of the App Communication Service should be created and started by the app. Note, on the client side the service handle shouldn’t be created, but obtained during discovery.
27     /// For more information, refer Tizen D2D convergence specification
28     /// </summary>
29     [EditorBrowsable(EditorBrowsableState.Never)]
30     public class InternalAppCommunicationService : InternalService
31     {
32         /// <summary>
33         /// The constructor
34         /// </summary>
35         /// <feature>http://tizen.org/feature/convergence.d2d</feature>
36         /// <exception cref="NotSupportedException">Thrown if the required feature is not supported.</exception>
37         public InternalAppCommunicationService() :
38                 base(Interop.Internal.ServiceType.AppCommunication)
39         {
40
41         }
42
43         internal InternalAppCommunicationService(IntPtr serviceHandle) :
44                     base(serviceHandle)
45         {
46
47         }
48
49         /// <summary>
50         /// Starts and initiates the service
51         /// </summary>
52         /// <param name="channel">Channel to specify a logical session for the service</param>
53         /// <param name="payload">Contains additional data for start request. Refer D2D Convergence specification for more information</param>
54         /// <privilege>http://tizen.org/privilege/internet</privilege>
55         /// <privilege>http://tizen.org/privilege/bluetooth</privilege>
56         /// <privilege>http://tizen.org/privilege/d2d.datasharing</privilege>
57         /// <feature>http://tizen.org/feature/convergence.d2d</feature>
58         /// <exception cref="NotSupportedException">Thrown if the required feature is not supported.</exception>
59         /// <exception cref="InvalidOperationException">Thrown when the request is not supported as per Tizen D2D convergence specification </exception>
60         /// <exception cref="ArgumentNullException">Thrown when any of the arugments are null</exception>
61         /// <seealso cref="Service.ServiceEventOccurred"> The result of the request is delivered through this event</seealso>
62         public void Start(InternalChannel channel, InternalPayload payload)
63         {
64             if (channel == null)
65             {
66                 throw new ArgumentNullException();
67             }
68
69             Interop.Internal.ConvPayloadHandle handle = (payload == null) ? new Interop.Internal.ConvPayloadHandle() : payload._payloadHandle;
70             int ret = Interop.Internal.ConvService.Start(_serviceHandle, channel._channelHandle, handle);
71             if (ret != (int)ConvErrorCode.None)
72             {
73                 Log.Error(ErrorFactory.LogTag, "Interop: Failed to start app communication service:" + ErrorFacts.GetErrorMessage(ret));
74                 throw ErrorFactory.GetException(ret);
75             }
76         }
77
78         /// <summary>
79         /// Reads data from the channel opened on the service
80         /// </summary>
81         /// <param name="channel">Channel representing a logical session on the service</param>
82         /// <param name="payload">Contains additional data for start request. Refer D2D Convergence specification for more information</param>
83         /// <privilege>http://tizen.org/privilege/internet</privilege>
84         /// <privilege>http://tizen.org/privilege/bluetooth</privilege>
85         /// <feature>http://tizen.org/feature/convergence.d2d</feature>
86         /// <exception cref="NotSupportedException">Thrown if the required feature is not supported.</exception>
87         /// <exception cref="InvalidOperationException">Thrown when the request is not supported as per Tizen D2D convergence specification </exception>
88         /// <exception cref="ArgumentNullException">Thrown when any of the arugments are null</exception>
89         /// <seealso cref="Service.ServiceEventOccurred"> The result of the request is delivered through this event</seealso>
90         public void Read(InternalChannel channel, InternalPayload payload)
91         {
92             if (channel == null)
93             {
94                 throw new ArgumentNullException();
95             }
96
97             Interop.Internal.ConvPayloadHandle handle = (payload == null) ? new Interop.Internal.ConvPayloadHandle() : payload._payloadHandle;
98             int ret = Interop.Internal.ConvService.Read(_serviceHandle, channel._channelHandle, handle);
99             if (ret != (int)ConvErrorCode.None)
100             {
101                 Log.Error(ErrorFactory.LogTag, "Interop: Failed to read app communication service:" + ErrorFacts.GetErrorMessage(ret));
102                 throw ErrorFactory.GetException(ret);
103             }
104         }
105
106         /// <summary>
107         /// Publishes a message to the remote server application
108         /// </summary>
109         /// <param name="channel">Channel representing a logical session on the service</param>
110         /// <param name="payload">Contains additional data for start request. Refer D2D Convergence specification for more information</param>
111         /// <privilege>http://tizen.org/privilege/internet</privilege>
112         /// <privilege>http://tizen.org/privilege/bluetooth</privilege>
113         /// <privilege>http://tizen.org/privilege/d2d.datasharing</privilege>
114         /// <feature>http://tizen.org/feature/convergence.d2d</feature>
115         /// <exception cref="NotSupportedException">Thrown if the required feature is not supported.</exception>
116         /// <exception cref="InvalidOperationException">Thrown when the request is not supported as per Tizen D2D convergence specification </exception>
117         /// <exception cref="ArgumentNullException">Thrown when any of the arugments are null</exception>
118         /// <seealso cref="Service.ServiceEventOccurred"> The result of the request is delivered through this event</seealso>
119         public void Publish(InternalChannel channel, InternalPayload payload)
120         {
121             if (channel == null)
122             {
123                 throw new ArgumentNullException();
124             }
125
126             Interop.Internal.ConvPayloadHandle handle = (payload == null) ? new Interop.Internal.ConvPayloadHandle() : payload._payloadHandle;
127             int ret = Interop.Internal.ConvService.Publish(_serviceHandle, channel._channelHandle, handle);
128             if (ret != (int)ConvErrorCode.None)
129             {
130                 Log.Error(ErrorFactory.LogTag, "Interop: Failed to publish app communication service:" + ErrorFacts.GetErrorMessage(ret));
131                 throw ErrorFactory.GetException(ret);
132             }
133         }
134
135         /// <summary>
136         /// Stops the channel opened on the remote server application
137         /// </summary>
138         /// <param name="channel">Channel representing a logical session on the service</param>
139         /// <param name="payload">Contains additional data for start request. Refer D2D Convergence specification for more information</param>
140         /// <privilege>http://tizen.org/privilege/internet</privilege>
141         /// <privilege>http://tizen.org/privilege/bluetooth</privilege>
142         /// <feature>http://tizen.org/feature/convergence.d2d</feature>
143         /// <exception cref="NotSupportedException">Thrown if the required feature is not supported.</exception>
144         /// <exception cref="InvalidOperationException">Thrown when the request is not supported as per Tizen D2D convergence specification </exception>
145         /// <exception cref="ArgumentNullException">Thrown when any of the arugments are null</exception>
146         /// <seealso cref="Service.ServiceEventOccurred"> The result of the request is delivered through this event</seealso>
147         public void Stop(InternalChannel channel, InternalPayload payload)
148         {
149             if (channel == null)
150             {
151                 throw new ArgumentNullException();
152             }
153
154             Interop.Internal.ConvPayloadHandle handle = (payload == null) ? new Interop.Internal.ConvPayloadHandle() : payload._payloadHandle;
155             int ret = Interop.Internal.ConvService.Stop(_serviceHandle, channel._channelHandle, handle);
156             if (ret != (int)ConvErrorCode.None)
157             {
158                 Log.Error(ErrorFactory.LogTag, "Interop: Failed to start stop communication service:" + ErrorFacts.GetErrorMessage(ret));
159                 throw ErrorFactory.GetException(ret);
160             }
161         }
162     }
163 }