<GenerateDependencyFile>false</GenerateDependencyFile>
<DummyAssemblyVersion>$(VersionPrefix)</DummyAssemblyVersion>
<BaseIntermediateOutputPath>$(OutputBaseDir)obj\</BaseIntermediateOutputPath>
+ <OutDir>$(OutputDummyDir)</OutDir>
</PropertyGroup>
<!-- Properties for directories -->
<!-- Common Properties -->
<PropertyGroup>
<PublicModuleListFile>$(PackageSrcDir)PublicModuleList.txt</PublicModuleListFile>
+ <DummyBuildProject>$(MSBuildThisFileDirectory)build.dummy.csproj</DummyBuildProject>
</PropertyGroup>
<!-- Build Properties -->
<Target Name="Build" DependsOnTargets="Clean">
<MSBuild Projects="@(ProjectToBuild)"
- Properties="Configuration=$(Configuration);OutDir=$(OutputPlatformDir);RestoreSources=$(RestoreSources)"
+ Properties="Configuration=$(Configuration);RestoreSources=$(RestoreSources)"
+ Targets="Restore" />
+
+ <MSBuild Projects="@(ProjectToBuild)"
+ Properties="Configuration=$(Configuration);OutDir=$(OutputPlatformDir)"
BuildInParallel="true"
UseResultsCache="true"
- Targets="Restore;Rebuild" />
+ Targets="Build" />
<ReadLinesFromFile File="$(PublicModuleListFile)">
<Output TaskParameter="Lines" ItemName="PublicProject" />
-->
<Target Name="BuildDummy">
- <MSBuild Projects="$(MSBuildThisFileDirectory)build.dummy.csproj"
- Properties="Configuration=$(Configuration);OutDir=$(OutputBaseDir)\obj\bin;RestoreSources=$(RestoreSources)"
- BuildInParallel="true"
- UseResultsCache="true"
+ <MSBuild Projects="$(DummyBuildProject)"
+ Properties="Configuration=$(Configuration);RestoreSources=$(RestoreSources)"
Targets="Restore;Rebuild" />
</Target>
Name: csapi-tizenfx
Summary: Assemblies of Tizen .NET
-Version: 4.0.0.162
+Version: 4.0.0.165
Release: 1
Group: Development/Libraries
License: Apache-2.0
[DllImport(Libraries.MessagePort, EntryPoint = "message_port_send_trusted_message_with_local_port", CallingConvention = CallingConvention.Cdecl)]
internal static extern int SendTrustedMessageWithLocalPort(string remote_app_id, string remote_port, SafeBundleHandle message, int local_port_id);
+ [DllImport(Libraries.MessagePort, EntryPoint = "message_port_check_remote_port", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int CheckRemotePort(string remote_app_id, string remote_port, out bool exist);
+
+ [DllImport(Libraries.MessagePort, EntryPoint = "message_port_check_trusted_remote_port", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int CheckTrustedRemotePort(string remote_app_id, string remote_port, out bool exist);
+
+ [DllImport(Libraries.MessagePort, EntryPoint = "message_port_add_registered_cb", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int AddRegisteredCallback(string remote_app_id, string remote_port, bool trusted_remote_port, message_port_registration_event_cb callback, IntPtr userData, out int watcher_id);
+
+ [DllImport(Libraries.MessagePort, EntryPoint = "message_port_add_unregistered_cb", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int AddUnregisteredCallback(string remote_app_id, string remote_port, bool trusted_remote_port, message_port_registration_event_cb callback, IntPtr userData, out int watcher_id);
+
+ [DllImport(Libraries.MessagePort, EntryPoint = "message_port_remove_registration_event_cb", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int RemoveRegistrationCallback(int watcher_id);
+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void message_port_message_cb(int local_port_id, string remote_app_id, string remote_port, bool trusted_remote_port, IntPtr message, IntPtr userData);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate void message_port_registration_event_cb(string remote_app_id, string remote_port, bool trusted_remote_port, IntPtr userData);
}
}
/// </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;
/// message.AddItem("message", "a_string");
/// messagePort.Send(message, "ReceiverAppID", "ReceiverPort");
/// }
- /// messageProt.StopListening();
+ /// messagePort.StopListening();
/// </code>
public void StopListening()
{
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) :
}
/// <summary>
- /// Releases the unmanaged resource used by the MessagePort class specifying whether to perform a normal dispose operation.
+ /// Releases the unmanaged resources used by the MessagePort class specifying whether to perform a normal dispose operation.
/// </summary>
/// <param name="disposing">true for a normal dispose operation; false to finalize the handle.</param>
protected virtual void Dispose(bool disposing)
*/
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);
}
}
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.\
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Tizen.Applications.Messages
+{
+ using System;
+
+ /// <summary>
+ /// The RemotePort Class provides functions to get if the remote port is running and to get whether the remote port is registered or unregistered.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ public class RemotePort : IDisposable
+ {
+ private int _watcherIdForRegistered = -1;
+ private int _watcherIdForUnRegistered = -1;
+ private bool _disposed = false;
+
+ private Interop.MessagePort.message_port_registration_event_cb _registeredCallBack;
+ private Interop.MessagePort.message_port_registration_event_cb _unregisteredCallBack;
+
+ private EventHandler<RemotePortStateChangedEventArgs> _remotePortRegistered;
+ private EventHandler<RemotePortStateChangedEventArgs> _remotePortUnregistered;
+
+ private readonly string _portName = null;
+ private readonly string _appId = null;
+ private readonly bool _trusted = false;
+
+ private bool _isRunning = false;
+
+ /// <summary>
+ /// Constructor of the RemotePort class.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <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.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>
+ public RemotePort(String appId, string portName, bool trusted)
+ {
+ if (String.IsNullOrEmpty(appId) || String.IsNullOrEmpty(portName))
+ {
+ MessagePortErrorFactory.ThrowException((int)MessagePortError.InvalidParameter, "Remote Port", "AppId or PortName");
+ }
+
+ _appId = appId;
+ _portName = portName;
+ _trusted = trusted;
+
+ _registeredCallBack = (string remoteAppId, string remotePortName, bool remoteTrusted, IntPtr userData) =>
+ {
+ RemotePortStateChangedEventArgs args = new RemotePortStateChangedEventArgs()
+ {
+ Status = State.Registered
+ };
+
+ _remotePortRegistered?.Invoke(this, args);
+ };
+
+ _unregisteredCallBack = (string remoteAppId, string remotePortName, bool remoteTrusted, IntPtr userData) =>
+ {
+ RemotePortStateChangedEventArgs args = new RemotePortStateChangedEventArgs()
+ {
+ Status = State.Unregistered
+ };
+
+ _remotePortUnregistered?.Invoke(this, args);
+ };
+ }
+
+ /// <summary>
+ /// Destructor of the RemotePort class.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ ~RemotePort()
+ {
+ Dispose(false);
+ }
+
+ /// <summary>
+ /// The AppId of the remote port
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <returns> Return appid of RemotePort </returns>
+ public string AppId
+ {
+ get
+ {
+ return _appId;
+ }
+ }
+
+ /// <summary>
+ /// The name of the remote message port
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <returns> Return name of RemotePort </returns>
+ public string PortName
+ {
+ get
+ {
+ return _portName;
+ }
+ }
+
+ /// <summary>
+ /// If true the remote port is a trusted port, otherwise if false it is not
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <returns> Return true if RemotePort is trusted </returns>
+ public bool Trusted
+ {
+ get
+ {
+ return _trusted;
+ }
+ }
+
+ /// <summary>
+ /// Check if the remote message port is running.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <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();
+ /// </code>
+ /// <returns> Return true if Remote Port is running </returns>
+ public bool IsRunning()
+ {
+ int ret;
+
+ ret = _trusted ?
+ Interop.MessagePort.CheckTrustedRemotePort(_appId, _portName, out _isRunning) :
+ Interop.MessagePort.CheckRemotePort(_appId, _portName, out _isRunning);
+
+ if (ret != (int)MessagePortError.None)
+ {
+ MessagePortErrorFactory.ThrowException(ret);
+ }
+
+ return _isRunning;
+ }
+
+ /// <summary>
+ /// Called when the remote port is registered or unregistered.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <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;
+ /// static void RemotePortStateChangedCallback(object sender, MessageReceivedEventArgs e)
+ /// {
+ /// switch (e.Status)
+ /// {
+ /// case State.Registered :
+ /// Console.WriteLine("Remote Port Registered ");
+ /// break;
+ /// case State.Unregistered :
+ /// Console.WriteLine("Remote Port Unregistered ");
+ /// break;
+ /// default :
+ /// break;
+ /// }
+ /// }
+ /// </code>
+ public event EventHandler<RemotePortStateChangedEventArgs> RemotePortStateChanged
+ {
+ add
+ {
+ if (_remotePortRegistered == null)
+ {
+ int ret = AddRegistrationCallback();
+
+ if (ret != (int)MessagePortError.None)
+ {
+ MessagePortErrorFactory.ThrowException(ret);
+ }
+ }
+
+ _remotePortRegistered += value;
+ _remotePortUnregistered += value;
+ }
+
+ remove
+ {
+ if (_remotePortRegistered?.GetInvocationList()?.Length > 0)
+ {
+ _remotePortRegistered -= value;
+ _remotePortUnregistered -= value;
+
+ if (_remotePortRegistered == null)
+ {
+ RemoveRegistrationCallback();
+ }
+ }
+ }
+ }
+
+ private int AddRegistrationCallback()
+ {
+ if (_watcherIdForRegistered != -1)
+ {
+ Interop.MessagePort.RemoveRegistrationCallback(_watcherIdForRegistered);
+ _watcherIdForRegistered = -1;
+ }
+
+ int ret = Interop.MessagePort.AddRegisteredCallback(_appId, _portName, _trusted, _registeredCallBack, IntPtr.Zero, out _watcherIdForRegistered);
+
+ if (ret != (int)MessagePortError.None)
+ {
+ return ret;
+ }
+
+ if (_watcherIdForUnRegistered != -1)
+ {
+ Interop.MessagePort.RemoveRegistrationCallback(_watcherIdForUnRegistered);
+ _watcherIdForUnRegistered = -1;
+ }
+
+ ret = Interop.MessagePort.AddUnregisteredCallback(_appId, _portName, _trusted, _unregisteredCallBack, IntPtr.Zero, out _watcherIdForUnRegistered);
+
+ if (ret != (int)MessagePortError.None)
+ {
+ return ret;
+ }
+
+ return ret;
+ }
+
+ private void RemoveRegistrationCallback()
+ {
+ if (_watcherIdForRegistered != -1 && _watcherIdForUnRegistered != -1)
+ {
+ int ret = Interop.MessagePort.RemoveRegistrationCallback(_watcherIdForRegistered);
+
+ if (ret != (int)MessagePortError.None)
+ {
+ MessagePortErrorFactory.ThrowException(ret);
+ }
+
+ _watcherIdForRegistered = -1;
+
+ ret = Interop.MessagePort.RemoveRegistrationCallback(_watcherIdForUnRegistered);
+
+ if (ret != (int)MessagePortError.None)
+ {
+ MessagePortErrorFactory.ThrowException(ret);
+ }
+
+ _watcherIdForUnRegistered = -1;
+ }
+ }
+
+ /// <summary>
+ /// Releases the unmanaged resources used by the RemotePort class specifying whether to perform a normal dispose operation.
+ /// </summary>
+ /// <param name="disposing">true for a normal dispose operation; false to finalize the handle.</param>
+ protected virtual void Dispose(bool disposing)
+ {
+ if (_disposed)
+ {
+ return;
+ }
+
+ RemoveRegistrationCallback();
+
+ _disposed = true;
+ }
+
+ /// <summary>
+ /// Releases all resources used by the RemotePort class.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+ }
+
+ /// <summary>
+ /// Enumeration for Remote Message Port state type
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ public enum State : Byte
+ {
+ /// <summary>
+ /// Value representing Remote Port state is unregistered
+ /// </summary>
+ Unregistered = 0,
+ /// <summary>
+ /// Value representing Remote Port state is registered
+ /// </summary>
+ Registered = 1
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.\
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Tizen.Applications.Messages
+{
+ using System;
+
+ /// <summary>
+ /// An extended EventArgs class which contains state of remote message port
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ public class RemotePortStateChangedEventArgs : EventArgs
+ {
+ /// <summary>
+ /// The State of remote port
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ public State Status { get; internal set; }
+ }
+}