/// </summary>
/// <param name="portName">The name of the local message port.</param>
/// <param name="trusted">If true, it is the trusted message port of application, otherwise false.</param>
- /// <exception cref="System.InvalidOperationException">Thrown when portName is null or empty.</exception>
+ /// <exception cref="System.ArgumentException">Thrown when portName is null or empty.</exception>
/// <code>
/// MessagePort messagePort = new MessagePort("SenderPort", true);
/// </code>
/// <summary>
/// Register the local message port.
/// </summary>
- /// <exception cref="System.InvalidOperationException">Thrown when portName is already used, when there is an invalid parameter, when out of memory, when there is an I/O error.</exception>
+ /// <exception cref="System.InvalidOperationException">Thrown when portName is already used, when there is an I/O error.</exception>
+ /// <exception cref="System.ArgumentException">Thrown when there is an invalid parameter.</exception>
+ /// <exception cref="System.OutOfMemoryException">Thrown when out of memory.</exception>
/// <code>
/// MessagePort messagePort = new MessagePort("SenderPort", true);
/// messagePort.MessageReceived += MessageReceivedCallback;
{
if (s_portMap.Contains(_portName))
{
- throw new InvalidOperationException(_portName + " is already used");
+ MessagePortErrorFactory.ThrowException((int)MessagePortError.InvalidOperation, _portName + "is already used");
}
_messageCallBack = (int localPortId, string remoteAppId, string remotePortName, bool trusted, IntPtr message, IntPtr userData) =>
{
Interop.MessagePort.RegisterPort(_portName, _messageCallBack, IntPtr.Zero);
if (_portId <= 0)
- throw new InvalidOperationException("Can't Listening with " + _portName);
+ MessagePortErrorFactory.ThrowException(_portId, "RegisterPort", _portName);
s_portMap.Add(_portName);
_listening = true;
/// <summary>
/// Unregisters the local message port.
/// </summary>
- /// <exception cref="System.InvalidOperationException">Thrown when messageport is already stopped, when there is an invalid parameter, when the port is not found, when out of memory, when there is an I/O error.</exception>
+ /// <exception cref="System.InvalidOperationException">Thrown when messageport is already stopped, when there is an I/O error, when the port is not found.</exception>
+ /// <exception cref="System.ArgumentException">Thrown when there is an invalid parameter.</exception>
+ /// <exception cref="System.OutOfMemoryException">Thrown when out of memory.</exception>
/// <code>
/// MessagePort messagePort = new MessagePort("SenderPort", true);
/// messagePort.MessageReceived += MessageReceivedCallback;
{
if (!_listening)
{
- throw new InvalidOperationException("Already stopped");
+ MessagePortErrorFactory.ThrowException((int)MessagePortError.InvalidOperation, "Already stopped");
}
int ret = _trusted ?
if (ret != (int)MessagePortError.None)
{
- MessagePortErrorFactory.ThrowException(ret);
+ MessagePortErrorFactory.ThrowException(ret, "Error Unregister port");
}
lock (s_lock)
/// <param name="message">The message to be passed to the remote application, the recommended message size is under 4KB.</param>
/// <param name="remoteAppId">The ID of the remote application.</param>
/// <param name="remotePortName">The name of the remote message port.</param>
- /// <exception cref="System.InvalidOperationException">Thrown when there is an invalid parameter, when the port is not found, when out of memory, when there is an I/O error.</exception>
+ /// <exception cref="System.InvalidOperationException">Thrown when there is an I/O error, when the port is not found.</exception>
+ /// <exception cref="System.ArgumentException">Thrown when there is an invalid parameter.</exception>
+ /// <exception cref="System.OutOfMemoryException">Thrown when out of memory.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">Thrown when message has exceeded the maximum limit(4KB).</exception>
/// <code>
/// MessagePort messagePort = new MessagePort("SenderPort", true);
/// <param name="remoteAppId">The ID of the remote application.</param>
/// <param name="remotePortName">The name of the remote message port.</param>
/// <param name="trusted">If true, it is the trusted message port of remote application, otherwise false.</param>
- /// <exception cref="System.InvalidOperationException">Thrown when there is an invalid parameter, when the port is not found, when out of memory, when there is an I/O error.</exception>
+ /// <exception cref="System.InvalidOperationException">Thrown when there is an I/O error, when the port is not found.</exception>
+ /// <exception cref="System.ArgumentException">Thrown when there is an invalid parameter.</exception>
+ /// <exception cref="System.OutOfMemoryException">Thrown when out of memory.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">Thrown when message has exceeded the maximum limit(4KB).</exception>
+ /// <exception cref="System.UnauthorizedAccessException">Thrown when the remote application is not signed with the same certificate.</exception>
/// <code>
/// MessagePort messagePort = new MessagePort("SenderPort", true);
/// messagePort.MessageReceived += MessageReceivedCallback;
{
if (!_listening)
{
- throw new InvalidOperationException("Should start listen before send");
+ MessagePortErrorFactory.ThrowException((int)MessagePortError.InvalidOperation, "Should start listen before send");
}
if (message == null)
{
- throw new ArgumentNullException("message");
+ MessagePortErrorFactory.ThrowException((int)MessagePortError.InvalidParameter, "message is null", "Message");
}
int ret = trusted ?
Interop.MessagePort.SendTrustedMessageWithLocalPort(remoteAppId, remotePortName, message.SafeBundleHandle, _portId) :
*/
using System;
+using System.Runtime.CompilerServices;
using Tizen.Internals.Errors;
namespace Tizen.Applications.Messages
internal static class MessagePortErrorFactory
{
- internal static void ThrowException(int errorCode, string errorMessage = null, string paramName = null)
+ private const string LogTag = "Tizen.Applications.MessagePort";
+ internal static void ThrowException(int errorCode, string errorMessage = null, string paramName = null,
+ [CallerMemberName] string memberName = "", [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0)
{
MessagePortError err = (MessagePortError)errorCode;
if (String.IsNullOrEmpty(errorMessage))
{
errorMessage = err.ToString();
}
+
+ Log.Error(LogTag, $"{memberName}({lineNumber.ToString()}) : {filePath}");
+ Log.Error(LogTag, "Error : " + errorMessage);
+
switch ((MessagePortError)errorCode)
{
case MessagePortError.IOError:
- case MessagePortError.OutOfMemory:
case MessagePortError.InvalidOperation:
case MessagePortError.PortNotFound:
case MessagePortError.ResourceUnavailable: throw new InvalidOperationException(errorMessage);
- case MessagePortError.InvalidParameter:
- case MessagePortError.CertificateNotMatch: throw new ArgumentException(errorMessage, paramName);
+ case MessagePortError.InvalidParameter: throw new ArgumentException(errorMessage, paramName);
+ case MessagePortError.CertificateNotMatch: throw new UnauthorizedAccessException(errorMessage);
+ case MessagePortError.OutOfMemory: throw new OutOfMemoryException(errorMessage);
case MessagePortError.MaxExceeded: throw new ArgumentOutOfRangeException(paramName, errorMessage);
}
}
/// <param name="appId">The Id of the remote application</param>
/// <param name="portName">The name of the remote message port</param>
/// <param name="trusted">If true is the trusted message port of application, otherwise false</param>
- /// <exception cref="System.InvalidOperationException">Thrown when appId is null or empty, when portName is null or empty</exception>
+ /// <exception cref="System.ArgumentException">Thrown when appId is null or empty, when portName is null or empty</exception>
/// <code>
/// RemotePort remotePort = new RemotePort("org.tizen.example.messageport", "SenderPort", false);
/// </code>
/// Check if the remote message port is running.
/// </summary>
/// <since_tizen> 4 </since_tizen>
- /// <exception cref="System.InvalidOperationException">Thrown when out of memory, when there is an I/O error</exception>
+ /// <exception cref="System.InvalidOperationException">Thrown when there is an I/O error</exception>
+ /// <exception cref="System.OutOfMemoryException">Thrown when out of memory.</exception>
/// <code>
/// Remote remotePort = new RemotePort("org.tizen.example", "SenderPort", true);
/// bool isRunning = remotePort.isRunning();
/// Called when the remote port is registered or unregistered.
/// </summary>
/// <since_tizen> 4 </since_tizen>
- /// <exception cref="System.InvalidOperationException">Thrown when out of memory, when there is an I/O error</exception>
+ /// <exception cref="System.InvalidOperationException">Thrown when there is an I/O error</exception>
+ /// <exception cref="System.OutOfMemoryException">Thrown when out of memory.</exception>
/// <code>
/// Remote remotePort = new RemotePort("org.tizen.example", "SenderPort", true);
/// remotePort.RemotePortStateChanged += RemotePortStateChangedCallback;