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.
18 using System.ComponentModel;
19 using Tizen.Internals.Errors;
21 namespace Tizen.Convergence
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
29 [EditorBrowsable(EditorBrowsableState.Never)]
30 public class InternalAppCommunicationService : InternalService
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)
43 internal InternalAppCommunicationService(IntPtr serviceHandle) :
50 /// Starts and initiates the service
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)
66 throw new ArgumentNullException();
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)
73 Log.Error(ErrorFactory.LogTag, "Interop: Failed to start app communication service:" + ErrorFacts.GetErrorMessage(ret));
74 throw ErrorFactory.GetException(ret);
79 /// Reads data from the channel opened on the service
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)
94 throw new ArgumentNullException();
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)
101 Log.Error(ErrorFactory.LogTag, "Interop: Failed to read app communication service:" + ErrorFacts.GetErrorMessage(ret));
102 throw ErrorFactory.GetException(ret);
107 /// Publishes a message to the remote server application
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)
123 throw new ArgumentNullException();
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)
130 Log.Error(ErrorFactory.LogTag, "Interop: Failed to publish app communication service:" + ErrorFacts.GetErrorMessage(ret));
131 throw ErrorFactory.GetException(ret);
136 /// Stops the channel opened on the remote server application
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)
151 throw new ArgumentNullException();
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)
158 Log.Error(ErrorFactory.LogTag, "Interop: Failed to start stop communication service:" + ErrorFacts.GetErrorMessage(ret));
159 throw ErrorFactory.GetException(ret);