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.Runtime.InteropServices;
19 using System.ComponentModel;
21 namespace Tizen.Convergence
24 /// The Channel class provies a logical session for communicating with AppCommunicationService.
26 [EditorBrowsable(EditorBrowsableState.Never)]
27 public class InternalChannel : IDisposable
29 internal Interop.Internal.ConvChannelHandle _channelHandle;
30 internal const string ChannelUriKey = "uri";
31 internal const string ChannelIdKey = "channel_id";
36 /// <param name="uri">Uri of the server side app</param>
37 /// <param name="id">Unique identifier</param>
38 /// <feature>http://tizen.org/feature/convergence.d2d</feature>
39 /// <exception cref="NotSupportedException">Thrown if the required feature is not supported.</exception>
40 /// <exception cref="ArgumentNullException">Throws when the arguments passed are null</exception>
41 public InternalChannel(string uri, string id)
43 if (uri == null || id == null)
45 throw new ArgumentNullException();
48 int ret = Interop.Internal.ConvChannel.Create(out _channelHandle);
49 if (ret != (int)ConvErrorCode.None)
51 Log.Error(ErrorFactory.LogTag, "Failed to create channel");
52 throw ErrorFactory.GetException(ret);
55 ret = Interop.Internal.ConvChannel.SetString(_channelHandle, ChannelUriKey, uri);
56 if (ret != (int)ConvErrorCode.None)
58 Log.Error(ErrorFactory.LogTag, "Failed to create channel");
59 throw ErrorFactory.GetException(ret);
62 ret = Interop.Internal.ConvChannel.SetString(_channelHandle, ChannelIdKey, id);
63 if (ret != (int)ConvErrorCode.None)
65 Log.Error(ErrorFactory.LogTag, "Failed to create channel");
66 throw ErrorFactory.GetException(ret);
73 internal InternalChannel(IntPtr channelHandle)
75 _channelHandle = new Interop.Internal.ConvChannelHandle(channelHandle, false);
77 IntPtr stringPtr = IntPtr.Zero;
78 int ret = Interop.Internal.ConvChannel.GetString(_channelHandle, ChannelUriKey, out stringPtr);
79 if (ret != (int)ConvErrorCode.None)
81 Log.Error(ErrorFactory.LogTag, "Failed to create channel");
82 throw ErrorFactory.GetException(ret);
84 Uri = Marshal.PtrToStringAnsi(stringPtr);
85 Interop.Libc.Free(stringPtr);
87 ret = Interop.Internal.ConvChannel.GetString(_channelHandle, ChannelIdKey, out stringPtr);
88 if (ret != (int)ConvErrorCode.None)
90 Log.Error(ErrorFactory.LogTag, "Failed to create channel");
91 throw ErrorFactory.GetException(ret);
94 Id = Marshal.PtrToStringAnsi(stringPtr);
95 Interop.Libc.Free(stringPtr);
99 /// Uri of the server side app
101 public string Uri { get; }
104 /// Unique identifier
106 public string Id { get; }
109 /// The dispose method
111 public void Dispose()
113 _channelHandle.Dispose();