internal enum ErrorCode : int
{
None = Tizen.Internals.Errors.ErrorCode.None,
- InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter,
- OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory,
IoError = Tizen.Internals.Errors.ErrorCode.IoError,
+ OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory,
PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied,
+ InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter,
InvalidOperation = Tizen.Internals.Errors.ErrorCode.InvalidOperation,
+ AlreadyInProgress = Tizen.Internals.Errors.ErrorCode.AlreadyInProgress,
NotSupported = Tizen.Internals.Errors.ErrorCode.NotSupported,
+ TimedOut = Tizen.Internals.Errors.ErrorCode.TimedOut,
+ OperationFailed = -0x030C0000 | 0x01,
}
}
}
using System;
using System.Runtime.InteropServices;
-using Tizen.Applications;
+using Tizen.Applications.Cion;
using ErrorCode = Interop.Cion.ErrorCode;
internal static partial class CionClient
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void CionClientDiscoveredCb(string serviceName, IntPtr peerInfo, IntPtr userData);
+ internal delegate void CionClientServerDiscoveredCb(string serviceName, IntPtr peerInfo, IntPtr userData);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void CionClientConnectionResultCb(string serviceName, IntPtr peerInfo, IntPtr result, IntPtr userData);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void CionClientPayloadRecievedCb(string serviceName, IntPtr peerInfo, IntPtr payload, int status, IntPtr userData);
+ internal delegate void CionClientPayloadReceivedCb(string serviceName, IntPtr peerInfo, IntPtr payload, int status, IntPtr userData);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void CionClientDisconnectedCb(string serviceName, IntPtr peerInfo, IntPtr userData);
[DllImport(Libraries.Cion, EntryPoint = "cion_client_create")]
internal static extern ErrorCode CionClientCreate(out ClientSafeHandle client, string serviceName, IntPtr security);
- [DllImport(Libraries.Cion, EntryPoint = "cion_client_destory")]
+ [DllImport(Libraries.Cion, EntryPoint = "cion_client_destroy")]
internal static extern ErrorCode CionClientDestroy(IntPtr client);
[DllImport(Libraries.Cion, EntryPoint = "cion_client_try_discovery")]
- internal static extern ErrorCode CionClientTryDiscovery(ClientSafeHandle client, CionClientDiscoveredCb cb, IntPtr userData);
+ internal static extern ErrorCode CionClientTryDiscovery(ClientSafeHandle client, CionClientServerDiscoveredCb cb, IntPtr userData);
[DllImport(Libraries.Cion, EntryPoint = "cion_client_stop_discovery")]
internal static extern ErrorCode CionClientStopDiscovery(ClientSafeHandle client);
[DllImport(Libraries.Cion, EntryPoint = "cion_client_add_connection_result_cb")]
internal static extern ErrorCode CionClientAddConnectionResultCb(ClientSafeHandle client, CionClientConnectionResultCb cb, IntPtr userData);
- [DllImport(Libraries.Cion, EntryPoint = "cion_client_add_payload_recieved_cb")]
- internal static extern ErrorCode CionClientAddPayloadReceivedCb(ClientSafeHandle client, CionClientPayloadRecievedCb cb, IntPtr userData);
+ [DllImport(Libraries.Cion, EntryPoint = "cion_client_remove_connection_result_cb")]
+ internal static extern ErrorCode CionClientRemoveConnectionResultCb(ClientSafeHandle client, CionClientConnectionResultCb cb);
+
+ [DllImport(Libraries.Cion, EntryPoint = "cion_client_add_payload_received_cb")]
+ internal static extern ErrorCode CionClientAddPayloadReceivedCb(ClientSafeHandle client, CionClientPayloadReceivedCb cb, IntPtr userData);
+
+ [DllImport(Libraries.Cion, EntryPoint = "cion_client_remove_payload_received_cb")]
+ internal static extern ErrorCode CionClientRemovePayloadReceivedCb(ClientSafeHandle client, CionClientPayloadReceivedCb cb);
[DllImport(Libraries.Cion, EntryPoint = "cion_client_add_disconnected_cb")]
internal static extern ErrorCode CionClientAddDisconnectedCb(ClientSafeHandle client, CionClientDisconnectedCb cb, IntPtr userData);
+
+ [DllImport(Libraries.Cion, EntryPoint = "cion_client_remove_disconnected_cb")]
+ internal static extern ErrorCode CionClientRemoveDisconnectedCb(ClientSafeHandle client, CionClientDisconnectedCb cb);
}
}
using System;
using System.Runtime.InteropServices;
-using Tizen.Applications;
+using Tizen.Applications.Cion;
using ErrorCode = Interop.Cion.ErrorCode;
using System;
using System.Runtime.InteropServices;
-using Tizen.Applications;
+using Tizen.Applications.Cion;
using ErrorCode = Interop.Cion.ErrorCode;
[DllImport(Libraries.Cion, EntryPoint = "cion_group_add_payload_received_cb")]
internal static extern ErrorCode CionGroupAddPayloadReceivedCb(GroupSafeHandle group, CionGroupPayloadReceivedCb cb, IntPtr userData);
+ [DllImport(Libraries.Cion, EntryPoint = "cion_group_remove_payload_received_cb")]
+ internal static extern ErrorCode CionGroupRemovePayloadReceivedCb(GroupSafeHandle group, CionGroupPayloadReceivedCb cb);
+
[DllImport(Libraries.Cion, EntryPoint = "cion_group_add_joined_cb")]
internal static extern ErrorCode CionGroupAddJoinedCb(GroupSafeHandle group, CionGroupJoinedCb cb, IntPtr userData);
+ [DllImport(Libraries.Cion, EntryPoint = "cion_group_remove_joined_cb")]
+ internal static extern ErrorCode CionGroupRemoveJoinedCb(GroupSafeHandle group, CionGroupJoinedCb cb);
+
[DllImport(Libraries.Cion, EntryPoint = "cion_group_add_left_cb")]
internal static extern ErrorCode CionGroupAddLeftCb(GroupSafeHandle group, CionGroupLeftCb cb, IntPtr userData);
+
+ [DllImport(Libraries.Cion, EntryPoint = "cion_group_remove_left_cb")]
+ internal static extern ErrorCode CionGroupRemoveLeftCb(GroupSafeHandle group, CionGroupLeftCb cb);
}
}
using System;
using System.Runtime.InteropServices;
-using Tizen.Applications;
+using Tizen.Applications.Cion;
using ErrorCode = Interop.Cion.ErrorCode;
using System;
using System.Runtime.InteropServices;
-using Tizen.Applications;
+using Tizen.Applications.Cion;
using ErrorCode = Interop.Cion.ErrorCode;
using System;
using System.Runtime.InteropServices;
-using Tizen.Applications;
+using Tizen.Applications.Cion;
using ErrorCode = Interop.Cion.ErrorCode;
using System;
using System.Runtime.InteropServices;
-using Tizen.Applications;
+using Tizen.Applications.Cion;
using ErrorCode = Interop.Cion.ErrorCode;
internal static partial class CionServer
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void CionServerPeerInfoIterator(IntPtr peerInfo, IntPtr userData);
+ internal delegate bool CionServerPeerInfoIterator(IntPtr peerInfo, IntPtr userData);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void CionServerPayloadAsyncResultCb(IntPtr result, IntPtr userData);
internal delegate void CionServerDataReceivedCb(string serviceName, IntPtr peerInfo, byte[] data, int dataSize, out byte[] returnData, out int returnDataSize, IntPtr userData);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void CionServerPayloadRecievedCb(string serviceName, IntPtr peerInfo, IntPtr payload, int status, IntPtr userData);
+ internal delegate void CionServerPayloadReceivedCb(string serviceName, IntPtr peerInfo, IntPtr payload, int status, IntPtr userData);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void CionServerConnectionRequestCb(string serviceName, IntPtr peerInfo, IntPtr userData);
[DllImport(Libraries.Cion, EntryPoint = "cion_server_create")]
internal static extern ErrorCode CionServerCreate(out ServerSafeHandle server, string serviceName, string displayName, IntPtr security);
- [DllImport(Libraries.Cion, EntryPoint = "cion_server_destory")]
+ [DllImport(Libraries.Cion, EntryPoint = "cion_server_destroy")]
internal static extern ErrorCode CionServerDestroy(IntPtr server);
[DllImport(Libraries.Cion, EntryPoint = "cion_server_listen")]
internal static extern ErrorCode CionServerDisconnect(ServerSafeHandle server, PeerInfoSafeHandle peerInfo);
[DllImport(Libraries.Cion, EntryPoint = "cion_server_send_payload_async")]
- internal static extern ErrorCode CionServerSendPayloadAsync(ServerSafeHandle server, PeerInfoSafeHandle peerInfo, PayloadSafeHandle payload,
- CionServerPayloadAsyncResultCb cb, IntPtr userData);
+ internal static extern ErrorCode CionServerSendPayloadAsync(ServerSafeHandle server, PeerInfoSafeHandle peerInfo, PayloadSafeHandle payload, CionServerPayloadAsyncResultCb cb, IntPtr userData);
[DllImport(Libraries.Cion, EntryPoint = "cion_server_foreach_connected_peer_info")]
internal static extern ErrorCode CionServerForeachConnectedPeerInfo(ServerSafeHandle server, CionServerPeerInfoIterator cb, IntPtr userData);
[DllImport(Libraries.Cion, EntryPoint = "cion_server_add_connection_result_cb")]
internal static extern ErrorCode CionServerAddConnectionResultCb(ServerSafeHandle server, CionServerConnectionResultCb cb, IntPtr userData);
- [DllImport(Libraries.Cion, EntryPoint = "cion_server_add_payload_recieved_cb")]
- internal static extern ErrorCode CionServerAddPayloadReceivedCb(ServerSafeHandle server, CionServerPayloadRecievedCb cb, IntPtr userData);
+ [DllImport(Libraries.Cion, EntryPoint = "cion_server_remove_connection_result_cb")]
+ internal static extern ErrorCode CionServerRemoveConnectionResultCb(ServerSafeHandle server, CionServerConnectionResultCb cb);
- [DllImport(Libraries.Cion, EntryPoint = "cion_server_add_error_reported_cb")]
- internal static extern ErrorCode CionServerAddErrorReportedCb(ServerSafeHandle server, CionServerErrorReportedCb cb, IntPtr userData);
+ [DllImport(Libraries.Cion, EntryPoint = "cion_server_add_payload_received_cb")]
+ internal static extern ErrorCode CionServerAddPayloadReceivedCb(ServerSafeHandle server, CionServerPayloadReceivedCb cb, IntPtr userData);
- [DllImport(Libraries.Cion, EntryPoint = "cion_server_set_data_recieved_cb")]
+ [DllImport(Libraries.Cion, EntryPoint = "cion_server_remove_payload_received_cb")]
+ internal static extern ErrorCode CionServerRemovePayloadReceivedCb(ServerSafeHandle server, CionServerPayloadReceivedCb cb, IntPtr userData);
+
+ [DllImport(Libraries.Cion, EntryPoint = "cion_server_set_data_received_cb")]
internal static extern ErrorCode CionServerSetDataReceivedCb(ServerSafeHandle server, CionServerDataReceivedCb cb, IntPtr userData);
+ [DllImport(Libraries.Cion, EntryPoint = "cion_server_unset_data_received_cb")]
+ internal static extern ErrorCode CionServerUnsetDataReceivedCb(ServerSafeHandle server, CionServerDataReceivedCb cb);
+
[DllImport(Libraries.Cion, EntryPoint = "cion_server_add_disconnected_cb")]
internal static extern ErrorCode CionServerAddDisconnectedCb(ServerSafeHandle server, CionServerDisconnectedCb cb, IntPtr userData);
- [DllImport(Libraries.Cion, EntryPoint = "cion_server_set_ondemand_launch_enable")]
- internal static extern ErrorCode CionServerSetOndemandLaunchEnable(ServerSafeHandle server, bool enable);
+ [DllImport(Libraries.Cion, EntryPoint = "cion_server_remove_disconnected_cb")]
+ internal static extern ErrorCode CionServerRemoveDisconnectedCb(ServerSafeHandle server, CionServerDisconnectedCb cb);
+
+ [DllImport(Libraries.Cion, EntryPoint = "cion_server_set_on_demand_launch_enabled")]
+ internal static extern ErrorCode CionServerSetOnDemandLaunchEnabled(ServerSafeHandle server, bool enable);
+
+ [DllImport(Libraries.Cion, EntryPoint = "cion_server_set_display_name")]
+ internal static extern ErrorCode CionServerSetDisplayName(ServerSafeHandle server, string displayName);
}
}
using System;
-namespace Tizen.Applications
+namespace Tizen.Applications.Cion
{
internal static class CionErrorFactory
{
string errMessage = string.Format("{0} err = {1}", message, err);
switch (err)
{
- case Interop.Cion.ErrorCode.InvalidParameter:
- return new ArgumentException(errMessage);
+ case Interop.Cion.ErrorCode.IoError:
+ return new InvalidOperationException(errMessage);
case Interop.Cion.ErrorCode.OutOfMemory:
return new InvalidOperationException(errMessage);
- case Interop.Cion.ErrorCode.IoError:
- return new global::System.IO.IOException(errMessage);
case Interop.Cion.ErrorCode.PermissionDenied:
return new UnauthorizedAccessException(errMessage);
+ case Interop.Cion.ErrorCode.InvalidParameter:
+ return new ArgumentException(errMessage);
case Interop.Cion.ErrorCode.InvalidOperation:
return new InvalidOperationException(errMessage);
+ case Interop.Cion.ErrorCode.AlreadyInProgress:
+ return new InvalidOperationException(errMessage);
case Interop.Cion.ErrorCode.NotSupported:
return new NotSupportedException(errMessage);
+ case Interop.Cion.ErrorCode.TimedOut:
+ return new TimeoutException(errMessage);
+ case Interop.Cion.ErrorCode.OperationFailed:
+ return new InvalidOperationException(errMessage);
default:
return new InvalidOperationException(errMessage);
}
}
}
-}
+}
\ No newline at end of file
using System.Runtime.InteropServices;
using System.Threading.Tasks;
-namespace Tizen.Applications
+namespace Tizen.Applications.Cion
{
/// <summary>
/// An abstract class to represent cion client.
/// <since_tizen> 9 </since_tizen>
public abstract class ClientBase : IDisposable
{
- private readonly string LogTag = "Tizen.Cion";
+ private readonly string LogTag = "Tizen.Applications.Cion";
private readonly ClientSafeHandle _handle;
private PeerInfo _peer;
- private Interop.CionClient.CionClientDiscoveredCb _discoveredCb;
+ private Interop.CionClient.CionClientServerDiscoveredCb _discoveredCb;
private Interop.CionClient.CionClientConnectionResultCb _connectionResultCb;
- private Interop.CionClient.CionClientPayloadRecievedCb _payloadRecievedCb;
+ private Interop.CionClient.CionClientPayloadReceivedCb _payloadRecievedCb;
private Interop.CionClient.CionClientDisconnectedCb _disconnectedCb;
private Interop.CionClient.CionClientPayloadAsyncResultCb _payloadAsyncResultCb;
private Dictionary<string, TaskCompletionSource<PayloadAsyncResult>> _tcsDictionary = new Dictionary<string, TaskCompletionSource<PayloadAsyncResult>>();
+ private Dictionary<string, Interop.CionClient.CionClientPayloadAsyncResultCb> _payloadAsyncCbDictionary = new Dictionary<string, Interop.CionClient.CionClientPayloadAsyncResultCb>();
/// <summary>
/// Gets the service name of current cion client.
/// The constructor of ClientBase class.
/// </summary>
/// <param name="serviceName">The name of service.</param>
- /// <exception cref="OutOfMemoryException">Thrown when there is not enough memory to continue the execution of the method.</exception>
+ /// <remarks>The maximum length of service name is 512.</remarks>
+ /// <exception cref="ArgumentException">Thrown when the given service name is too long.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when there is not enough memory to continue the execution of the method.</exception>
/// <since_tizen> 9 </since_tizen>
public ClientBase(string serviceName) : this(serviceName, null) { }
/// </summary>
/// <param name="serviceName">The name of service.</param>
/// <param name="security">The security configuration.</param>
- /// <exception cref="OutOfMemoryException">Thrown when there is not enough memory to continue the execution of the method.</exception>
+ /// <remarks>The maximum length of service name is 512.</remarks>
+ /// <exception cref="ArgumentException">Thrown when the given service name is too long.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when there is not enough memory to continue the execution of the method.</exception>
/// <since_tizen> 9 </since_tizen>
public ClientBase(string serviceName, Cion.SecurityInfo security)
{
ServiceName = serviceName;
- Cion.SecuritySafeHandle handle = security?._handle;
+ SecuritySafeHandle handle = security?._handle;
Interop.Cion.ErrorCode ret = Interop.CionClient.CionClientCreate(out _handle, serviceName, handle?.DangerousGetHandle() ?? IntPtr.Zero);
if (ret != Interop.Cion.ErrorCode.None)
{
throw CionErrorFactory.GetException(ret, "Failed to add connection status changed callback.");
}
- _payloadRecievedCb = new Interop.CionClient.CionClientPayloadRecievedCb(
+ _payloadRecievedCb = new Interop.CionClient.CionClientPayloadReceivedCb(
(string service, IntPtr peerInfo, IntPtr payload, int status, IntPtr userData) =>
{
Payload receivedPayload;
/// <summary>
/// Starts discovering cion servers.
/// </summary>
+ /// <privilege>http://tizen.org/privilege/d2d.datasharing</privilege>
+ /// <privilege>http://tizen.org/privilege/internet</privilege>
+ /// <privlevel>public</privlevel>
/// <exception cref="InvalidOperationException">Thrown when the discovery operation is already in progress.</exception>
+ /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
/// <since_tizen> 9 </since_tizen>
public void TryDiscovery()
{
- Log.Error(LogTag, string.Format("Try discovery start"));
-
if (_discoveredCb == null)
{
- Interop.CionClient.CionClientDiscoveredCb cb = new Interop.CionClient.CionClientDiscoveredCb(
+ Interop.CionClient.CionClientServerDiscoveredCb cb = new Interop.CionClient.CionClientServerDiscoveredCb(
(string serviceName, IntPtr peerInfo, IntPtr userData) =>
{
- Log.Error(LogTag, string.Format("callback called !!"));
-
Interop.Cion.ErrorCode clone_ret = Interop.CionPeerInfo.CionPeerInfoClone(peerInfo, out PeerInfoSafeHandle clone);
if (clone_ret != Interop.Cion.ErrorCode.None)
{
/// </summary>
/// <param name="peer">The peer to connect.</param>
/// <privilege>http://tizen.org/privilege/d2d.datasharing</privilege>
+ /// <privilege>http://tizen.org/privilege/internet</privilege>
+ /// <privlevel>public</privlevel>
+ /// <exception cref="InvalidOperationException">Thrown when the client cannot connect to server.</exception>
+ /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
/// <since_tizen> 9 </since_tizen>
public void Connect(PeerInfo peer)
{
Interop.Cion.ErrorCode ret = Interop.CionClient.CionClientDisconnect(_handle);
if (ret != Interop.Cion.ErrorCode.None)
{
- throw CionErrorFactory.GetException(ret, "Failed to disconnect.");
+ Log.Error(LogTag, string.Format("Failed to disconnect: {0}", ret));
}
_peer = null;
}
/// <param name="data">The data to send.</param>
/// <param name="timeout">The timeout of sending operation.</param>
/// <exception cref="ArgumentException">Thrown when the given data is invalid.</exception>
- /// <exception cref="InvalidOperationException">Thrown when there is no connected cion server.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when there is no connected cion server or failed to receive reply.</exception>
+ /// <exception cref="TimeoutException">Thrown when a timeout occurred.</exception>
/// <since_tizen> 9 </since_tizen>
public byte[] SendData(byte[] data, int timeout)
{
/// </summary>
/// <param name="payload">The payload to send.</param>
/// <exception cref="ArgumentException">Thrown when the payload is not valid.</exception>
- /// <exception cref="InvalidOperationException">Thrown when there is no connected cion server.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when there is no connected cion server or failed to send payload.</exception>
/// <since_tizen> 9 </since_tizen>
public Task<PayloadAsyncResult> SendPayloadAsync(Payload payload)
{
throw new ArgumentException("Payload is invalid.");
}
+ if (_tcsDictionary.ContainsKey(payload.Id))
+ {
+ throw new InvalidOperationException("Payload is already sent.");
+ }
+
TaskCompletionSource<PayloadAsyncResult> tcs = new TaskCompletionSource<PayloadAsyncResult>();
_tcsDictionary[payload.Id] = tcs;
- if (_payloadAsyncResultCb == null)
- {
- Interop.CionClient.CionClientPayloadAsyncResultCb cb = new Interop.CionClient.CionClientPayloadAsyncResultCb(
- (IntPtr result, IntPtr userData) =>
+ Interop.CionClient.CionClientPayloadAsyncResultCb cb = new Interop.CionClient.CionClientPayloadAsyncResultCb(
+ (IntPtr result, IntPtr userData) =>
+ {
+ TaskCompletionSource<PayloadAsyncResult> tcsToReturn = _tcsDictionary[payload.Id];
+ PayloadAsyncResult resultPayload = null;
+ try
{
- TaskCompletionSource<PayloadAsyncResult> tcsToReturn = _tcsDictionary[payload.Id];
- PayloadAsyncResult resultPayload = null;
- try
- {
- resultPayload = PayloadAsyncResult.CreateFromHandle(result);
- }
- catch (Exception e)
- {
- Log.Error(LogTag, string.Format("Failed to create PayloadAsyncResult from result handle: {0}.", e.Message));
- tcsToReturn.SetException(e);
- return;
- }
- tcsToReturn.SetResult(resultPayload);
- _tcsDictionary.Remove(resultPayload.PayloadId);
- });
- _payloadAsyncResultCb = cb;
- }
+ resultPayload = PayloadAsyncResult.CreateFromHandle(result);
+ }
+ catch (Exception e)
+ {
+ Log.Error(LogTag, string.Format("Failed to create PayloadAsyncResult from result handle: {0}.", e.Message));
+ tcsToReturn.SetException(e);
+ return;
+ }
+ tcsToReturn.SetResult(resultPayload);
+ _payloadAsyncCbDictionary.Remove(resultPayload.PayloadId);
+ _tcsDictionary.Remove(resultPayload.PayloadId);
+ });
Interop.Cion.ErrorCode ret = Interop.CionClient.CionClientSendPayloadAsync(_handle, payload?._handle, _payloadAsyncResultCb, IntPtr.Zero);
if (ret != Interop.Cion.ErrorCode.None)
throw CionErrorFactory.GetException(ret, "Failed to send payload.");
}
+ _payloadAsyncCbDictionary[payload?.Id] = cb;
+
return tcs.Task;
}
using System.ComponentModel;
using System.Runtime.InteropServices;
-namespace Tizen.Applications
+namespace Tizen.Applications.Cion
{
internal sealed class ClientSafeHandle : SafeHandle
{
using System;
-namespace Tizen.Applications
+namespace Tizen.Applications.Cion
{
/// <summary>
/// A class to represent result of connection.
* limitations under the License.
*/
-namespace Tizen.Applications
+namespace Tizen.Applications.Cion
{
/// <summary>
/// Enumeration for connection status.
using System.Linq;
using System.Runtime.InteropServices;
-namespace Tizen.Applications
+namespace Tizen.Applications.Cion
{
/// <summary>
/// A class to represent data type payload.
using System;
-namespace Tizen.Applications
+namespace Tizen.Applications.Cion
{
/// <summary>
/// A class to represent file type payload.
/// <since_tizen> 9 </since_tizen>
public class FilePayload : Payload
{
- private readonly string LogTag = "Tizen.Cion";
+ private readonly string LogTag = "Tizen.Applications.Cion";
internal FilePayload(PayloadSafeHandle handle)
{
/// The constructor of FilePayload class.
/// </summary>
/// <param name="path">The path of file for the FilePayload.</param>
+ /// <remarks>
+ /// http://tizen.org/privilege/mediastorage is needed if the file path is relevant to media storage.
+ /// http://tizen.org/privilege/externalstorage is needed if the file path is relevant to external storage.
+ /// </remarks>
/// <exception cref="ArgumentException">Thrown when the input file path is invalid.</exception>
+ /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
/// <since_tizen> 9 </since_tizen>
public FilePayload(string path)
{
/// Saves file of payload to speicific path.
/// </summary>
/// <param name="path">The path of file to save.</param>
+ /// <remarks>
+ /// http://tizen.org/privilege/mediastorage is needed if the file path is relevant to media storage.
+ /// http://tizen.org/privilege/externalstorage is needed if the file path is relevant to external storage.
+ /// </remarks>
+ /// <exception cref="ArgumentException">Thrown when the input file path is invalid.</exception>
+ /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
/// <since_tizen> 9 </since_tizen>
public void SaveAsFile(string path)
{
using System;
-namespace Tizen.Applications
+namespace Tizen.Applications.Cion
{
/// <summary>
/// An abstract class to represent cion group.
/// <since_tizen> 9 </since_tizen>
public abstract class GroupBase : IDisposable
{
+ private readonly string LogTag = "Tizen.Applications.Cion";
private readonly GroupSafeHandle _handle;
private Interop.CionGroup.CionGroupPayloadReceivedCb _payloadReceivedCb;
/// The constructor of GroupBase class.
/// </summary>
/// <param name="topicName">The topic of group.</param>
+ /// <remarks>The maximum length of topic name is 512.</remarks>
+ /// <exception cref="ArgumentException">Thrown when the given topic name is too long.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when there is not enough memory to continue the execution of the method.</exception>
/// <since_tizen> 9 </since_tizen>
public GroupBase(string topicName) : this(topicName, null) { }
/// </summary>
/// <param name="topicName">The topic of group.</param>
/// <param name="security">The security configuration.</param>
- /// <exception cref="OutOfMemoryException">Thrown when there is not enough memory to continue the execution of the method.</exception>
+ /// <remarks>The maximum length of topic name is 512.</remarks>
+ /// <exception cref="ArgumentException">Thrown when the given topic name is too long.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when there is not enough memory to continue the execution of the method.</exception>
/// <since_tizen> 9 </since_tizen>
public GroupBase(string topicName, Cion.SecurityInfo security)
{
receivedPayload = new FilePayload(new PayloadSafeHandle(payload, false));
break;
default:
- throw new ArgumentException("Invalid payload type received.");
+ Log.Error(LogTag, "Invalid payload type received.");
+ return;
}
- OnPayloadReceived(receivedPayload, new PeerInfo(new PeerInfoSafeHandle(peerInfo, false)));
+ Interop.Cion.ErrorCode clone_ret = Interop.CionPeerInfo.CionPeerInfoClone(peerInfo, out PeerInfoSafeHandle clone);
+ if (clone_ret != Interop.Cion.ErrorCode.None)
+ {
+ Log.Error(LogTag, "Failed to clone peer info.");
+ return;
+ }
+ OnPayloadReceived(receivedPayload, new PeerInfo(clone));
});
ret = Interop.CionGroup.CionGroupAddPayloadReceivedCb(_handle, _payloadReceivedCb, IntPtr.Zero);
if (ret != Interop.Cion.ErrorCode.None)
/// Subscribes the topic.
/// </summary>
/// <privilege>http://tizen.org/privilege/d2d.datasharing</privilege>
+ /// <privilege>http://tizen.org/privilege/internet</privilege>
+ /// <privlevel>public</privlevel>
+ /// <exception cref="InvalidOperationException">Thrown when failed to subscribe.</exception>
+ /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
/// <since_tizen> 9 </since_tizen>
public void Subscribe()
{
Interop.Cion.ErrorCode ret = Interop.CionGroup.CionGroupUnsubscribe(_handle);
if (ret != Interop.Cion.ErrorCode.None)
{
- throw CionErrorFactory.GetException(ret, "Failed to unsubscribe.");
+ Log.Error(LogTag, string.Format("Failed to unsubscribe: {0}", ret));
}
}
/// </summary>
/// <param name="payload">The payload to publish.</param>
/// <exception cref="ArgumentException">Thrown when the payload is invalid.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when failed to publish.</exception>
/// <since_tizen> 9 </since_tizen>
public void Publish(Payload payload)
{
using System.ComponentModel;
using System.Runtime.InteropServices;
-namespace Tizen.Applications
+namespace Tizen.Applications.Cion
{
internal sealed class GroupSafeHandle : SafeHandle
{
* limitations under the License.
*/
-namespace Tizen.Applications
+namespace Tizen.Applications.Cion
{
/// <summary>
/// An abstract class to represent payload.
/// <since_tizen> 9 </since_tizen>
public abstract class Payload
{
- private readonly string LogTag = "Tizen.Cion";
+ private readonly string LogTag = "Tizen.Applications.Cion";
internal PayloadSafeHandle _handle;
/// <summary>
using System;
-namespace Tizen.Applications
+namespace Tizen.Applications.Cion
{
/// <summary>
/// A class to represent result of payload.
* limitations under the License.
*/
-namespace Tizen.Applications
+namespace Tizen.Applications.Cion
{
/// <summary>
/// Enumeration for payload result code.
using System.ComponentModel;
using System.Runtime.InteropServices;
-namespace Tizen.Applications
+namespace Tizen.Applications.Cion
{
internal sealed class PayloadSafeHandle : SafeHandle
{
* limitations under the License.
*/
-namespace Tizen.Applications
+namespace Tizen.Applications.Cion
{
/// <summary>
/// Enumeration for payload transfer status.
* limitations under the License.
*/
-namespace Tizen.Applications
+namespace Tizen.Applications.Cion
{
/// <summary>
/// Enumeration for payload type.
using System;
-namespace Tizen.Applications
+namespace Tizen.Applications.Cion
{
/// <summary>
/// A class to represent peer info.
/// <since_tizen> 9 </since_tizen>
public class PeerInfo : IDisposable
{
- private readonly string LogTag = "Tizen.Cion";
+ private readonly string LogTag = "Tizen.Applications.Cion";
internal PeerInfoSafeHandle _handle;
internal PeerInfo(PeerInfoSafeHandle handle)
using System.ComponentModel;
using System.Runtime.InteropServices;
-namespace Tizen.Applications
+namespace Tizen.Applications.Cion
{
internal sealed class PeerInfoSafeHandle : SafeHandle
{
/// <summary>
/// Gets the CA cert path.
/// </summary>
+ /// <remarks>
+ /// http://tizen.org/privilege/mediastorage is needed if the file path is relevant to media storage.
+ /// http://tizen.org/privilege/externalstorage is needed if the file path is relevant to external storage.
+ /// </remarks>
/// <exception cref="ArgumentException">Thrown when the CA path is invalid.</exception>
+ /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
/// <since_tizen> 9 </since_tizen>
public string CaPath
{
/// <summary>
/// Gets the cert path.
/// </summary>
+ /// <remarks>
+ /// http://tizen.org/privilege/mediastorage is needed if the file path is relevant to media storage.
+ /// http://tizen.org/privilege/externalstorage is needed if the file path is relevant to external storage.
+ /// </remarks>
/// <exception cref="ArgumentException">Thrown when the cert path is invalid.</exception>
+ /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
/// <since_tizen> 9 </since_tizen>
public string CertPath
{
/// <summary>
/// Gets the private key path.
/// </summary>
+ /// <remarks>
+ /// http://tizen.org/privilege/mediastorage is needed if the file path is relevant to media storage.
+ /// http://tizen.org/privilege/externalstorage is needed if the file path is relevant to external storage.
+ /// </remarks>
/// <exception cref="ArgumentException">Thrown when the private key path is invalid.</exception>
+ /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
/// <since_tizen> 9 </since_tizen>
public string PrivateKeyPath
{
using System.Collections.Generic;
using System.Threading.Tasks;
-namespace Tizen.Applications
+namespace Tizen.Applications.Cion
{
/// <summary>
/// An abstract class to represent cion server.
/// <since_tizen> 9 </since_tizen>
public abstract class ServerBase : IDisposable
{
- private const string LogTag = "Tizen.Cion";
+ private readonly string LogTag = "Tizen.Applications.Cion";
+ private string _displayName;
private readonly ServerSafeHandle _handle;
private Interop.CionServer.CionServerConnectionRequestCb _connectionRequestCb;
private Interop.CionServer.CionServerConnectionResultCb _connectionResultCb;
private Interop.CionServer.CionServerDataReceivedCb _dataReceivedCb;
- private Interop.CionServer.CionServerPayloadRecievedCb _payloadRecievedCb;
+ private Interop.CionServer.CionServerPayloadReceivedCb _payloadRecievedCb;
private Interop.CionServer.CionServerDisconnectedCb _disconnectedCb;
private Interop.CionServer.CionServerPayloadAsyncResultCb _payloadAsyncResultCb;
private Dictionary<Tuple<string, string>, TaskCompletionSource<PayloadAsyncResult>> _tcsDictionary = new Dictionary<Tuple<string, string>, TaskCompletionSource<PayloadAsyncResult>>();
public string ServiceName { get; }
/// <summary>
- /// Gets the display name of current cion server.
+ /// Gets or sets the display name of current cion server.
/// </summary>
/// <since_tizen> 9 </since_tizen>
- public string DisplayName { get; }
+ public string DisplayName
+ {
+ get
+ {
+ return _displayName;
+ }
+
+ set
+ {
+ Interop.Cion.ErrorCode ret = Interop.CionServer.CionServerSetDisplayName(_handle, value);
+ if (ret != Interop.Cion.ErrorCode.None)
+ {
+ Log.Error(LogTag, string.Format("Failed to set display name: {0}", ret));
+ }
+ else
+ {
+ _displayName = value;
+ }
+ }
+ }
/// <summary>
/// The constructor of ServerBase class.
/// </summary>
/// <param name="serviceName">The name of service.</param>
/// <param name="displayName">The display name of service.</param>
- /// <exception cref="OutOfMemoryException">Thrown when there is not enough memory to continue the execution of the method.</exception>
+ /// <remarks>The maximum length of service name is 512.</remarks>
+ /// <exception cref="ArgumentException">Thrown when the given service name is too long.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when there is not enough memory to continue the execution of the method.</exception>
/// <since_tizen> 9 </since_tizen>
public ServerBase(string serviceName, string displayName) : this(serviceName, displayName, null) { }
/// <param name="serviceName">The name of service.</param>
/// <param name="displayName">The display name of service.</param>
/// <param name="security">The security configuration.</param>
- /// <exception cref="OutOfMemoryException">Thrown when there is not enough memory to continue the execution of the method.</exception>
+ /// <remarks>The maximum length of service name is 512.</remarks>
+ /// <exception cref="ArgumentException">Thrown when the given service name is too long.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when there is not enough memory to continue the execution of the method.</exception>
/// <since_tizen> 9 </since_tizen>
public ServerBase(string serviceName, string displayName, Cion.SecurityInfo security)
{
ServiceName = serviceName;
- DisplayName = displayName;
+ _displayName = displayName;
Cion.SecuritySafeHandle handle = security?._handle;
Interop.Cion.ErrorCode ret = Interop.CionServer.CionServerCreate(out _handle, serviceName, displayName, handle?.DangerousGetHandle() ?? IntPtr.Zero);
_dataReceivedCb = new Interop.CionServer.CionServerDataReceivedCb(
(string service, IntPtr peerInfo, byte[] data, int dataSize, out byte[] returnData, out int returnDataSize, IntPtr userData) =>
{
- returnData = OnDataReceived(data, new PeerInfo(new PeerInfoSafeHandle(peerInfo, false)));
+ Interop.Cion.ErrorCode clone_ret = Interop.CionPeerInfo.CionPeerInfoClone(peerInfo, out PeerInfoSafeHandle clone);
+ if (clone_ret != Interop.Cion.ErrorCode.None)
+ {
+ Log.Error(LogTag, "Failed to clone peer info.");
+ returnData = null;
+ returnDataSize = -1;
+ }
+ returnData = OnDataReceived(data, new PeerInfo(clone));
returnDataSize = returnData.Length;
});
ret = Interop.CionServer.CionServerSetDataReceivedCb(_handle, _dataReceivedCb, IntPtr.Zero);
throw CionErrorFactory.GetException(ret, "Failed to set data received callback.");
}
- _payloadRecievedCb = new Interop.CionServer.CionServerPayloadRecievedCb(
+ _payloadRecievedCb = new Interop.CionServer.CionServerPayloadReceivedCb(
(string service, IntPtr peerInfo, IntPtr payload, int status, IntPtr userData) =>
{
Payload receivedPayload;
Log.Error(LogTag, "Invalid payload type received.");
return;
}
- OnPayloadReceived(receivedPayload, new PeerInfo(new PeerInfoSafeHandle(peerInfo, false)), (PayloadTransferStatus)status);
+ Interop.Cion.ErrorCode clone_ret = Interop.CionPeerInfo.CionPeerInfoClone(peerInfo, out PeerInfoSafeHandle clone);
+ if (clone_ret != Interop.Cion.ErrorCode.None)
+ {
+ Log.Error(LogTag, "Failed to clone peer info.");
+ return;
+ }
+ OnPayloadReceived(receivedPayload, new PeerInfo(clone), (PayloadTransferStatus)status);
});
ret = Interop.CionServer.CionServerAddPayloadReceivedCb(_handle, _payloadRecievedCb, IntPtr.Zero);
if (ret != Interop.Cion.ErrorCode.None)
/// <summary>
/// Starts server and listens for requests from cion clients.
/// </summary>
- /// <exception cref="InvalidOperationException">Thrown when the listen operation is already in progress.</exception>
/// <privilege>http://tizen.org/privilege/d2d.datasharing</privilege>
+ /// <privilege>http://tizen.org/privilege/internet</privilege>
+ /// <privlevel>public</privlevel>
+ /// <exception cref="InvalidOperationException">Thrown when the listen operation is already in progress.</exception>
+ /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
/// <since_tizen> 9 </since_tizen>
public void Listen()
{
Log.Error(LogTag, "Failed to clone peer info");
return;
}
- OnConnentionRequest(new PeerInfo(clone));
+ OnConnectionRequest(new PeerInfo(clone));
});
_connectionRequestCb = cb;
}
/// <param name="payload">The payload to send.</param>
/// <param name="peerInfo">The peer to send payload.</param>
/// <exception cref="ArgumentException">Thrown when the payload is not valid.</exception>
- /// <exception cref="InvalidOperationException">Thrown when there is no such connected cion client.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when there is no such connected cion client or failed to send payload.</exception>
/// <since_tizen> 9 </since_tizen>
public Task<PayloadAsyncResult> SendPayloadAsync(Payload payload, PeerInfo peerInfo)
{
/// Sends the payload to all of connected peer asynchronously.
/// </summary>
/// <param name="payload">The payload to send.</param>
+ /// <exception cref="ArgumentException">Thrown when the payload is not valid.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when failed to send payload.</exception>
/// <since_tizen> 9 </since_tizen>
public void SendPayloadAsync(Payload payload)
{
/// <summary>
/// Gets connected peers.
/// </summary>
- /// <exception cref="OutOfMemoryException">Thrown when there is not enough memory to continue the execution of the method.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when there is not enough memory to continue the execution of the method.</exception>
/// <since_tizen> 9 </since_tizen>
public IEnumerable<PeerInfo> GetConnectedPeerList()
{
Interop.Cion.ErrorCode clone_ret = Interop.CionPeerInfo.CionPeerInfoClone(peer, out PeerInfoSafeHandle clone);
if (clone_ret != Interop.Cion.ErrorCode.None)
{
- throw CionErrorFactory.GetException(clone_ret, "Failed to clone peer info.");
+ Log.Error(LogTag, "Failed to clone peer info.");
+ return false;
}
peerInfoList.Add(new PeerInfo(clone));
+ return true;
}, IntPtr.Zero);
return peerInfoList;
}
/// Sets ondemand launch enabled flag.
/// </summary>
/// <param name="enable">Whether ondemand launch is enabled or not.</param>
- /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
/// <privilege>http://tizen.org/privilege/d2d.remotelaunch</privilege>
+ /// <privlevel>public</privlevel>
+ /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
/// <since_tizen> 9 </since_tizen>
public void SetOndemandLaunchEnabled(bool enable)
{
- Interop.Cion.ErrorCode ret = Interop.CionServer.CionServerSetOndemandLaunchEnable(_handle, enable);
+ Interop.Cion.ErrorCode ret = Interop.CionServer.CionServerSetOnDemandLaunchEnabled(_handle, enable);
if (ret != Interop.Cion.ErrorCode.None)
{
throw CionErrorFactory.GetException(ret, "Failed to set ondemand launch enable");
/// </summary>
/// <param name="peerInfo">The peer info of the cion client.</param>
/// <since_tizen> 9 </since_tizen>
- protected abstract void OnConnentionRequest(PeerInfo peerInfo);
+ protected abstract void OnConnectionRequest(PeerInfo peerInfo);
/// <summary>
/// The callback invoked when disconnected with cion client.
using System.ComponentModel;
using System.Runtime.InteropServices;
-namespace Tizen.Applications
+namespace Tizen.Applications.Cion
{
internal sealed class ServerSafeHandle : SafeHandle
{