using Tizen.Internals.Errors;
using Tizen.Applications;
+using System.Reflection;
internal static partial class Interop
{
//int rpc_port_proxy_get_port(rpc_port_proxy_h h, rpc_port_port_type_e type, rpc_port_h* port);
[DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_get_port")]
internal static extern ErrorCode GetPort(IntPtr handle, PortType t, out IntPtr port);
+
+ //int rpc_port_proxy_connect_sync(rpc_port_proxy_h h, const char* appid, const char* port);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_connect_sync")]
+ internal static extern ErrorCode ConnectSync(IntPtr handle, string appId, string port);
}
internal static partial class Stub
[DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_get_port")]
internal static extern ErrorCode GetPort(IntPtr handle, PortType t, string instance, out IntPtr port);
}
+
+ internal static partial class Port
+ {
+ //int rpc_port_set_private_sharing_array(rpc_port_h port, const char* paths[], unsigned int size);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_set_private_sharing_array")]
+ internal static extern ErrorCode SetPrivateSharingArray(IntPtr handle, string[] paths, uint size);
+
+ //int rpc_port_set_private_sharing(rpc_port_h port, const char* path);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_set_private_sharing_array")]
+ internal static extern ErrorCode SetPrivateSharing(IntPtr handle, string path);
+
+ //int rpc_port_unset_private_sharing(rpc_port_h port);
+ [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_unset_private_sharing")]
+ internal static extern ErrorCode UnsetPrivateSharing(IntPtr handle);
+ }
}
}
*/
using System;
+using System.Collections.Generic;
+using System.Linq;
namespace Tizen.Applications.RPCPort
{
internal IntPtr Handle { get; set; }
internal Port() { }
+
+ /// <summary>
+ /// Shares private files with other applications.
+ /// </summary>
+ /// <remarks>
+ /// If all added paths are under the caller application's data path which can be obtained, those will be shared to the target application.
+ /// Platform will grant a temporary permission to the target application for those files and revoke it when the target application is terminated or UnshareFile() is called.
+ /// Paths should be regular files. The target application can just read them.
+ /// Note that the target application doesn't have read permission of the directory that is obtained by caller's data path. You should open the file path with read only mode directly.
+ /// </remarks>
+ /// <param name="paths">The file paths to be shared.</param>
+ /// <exception cref="InvalidIOException">Thrown when an internal IO error occurrs.</exception>
+ /// <since_tizen> 8 </since_tizen>
+ public void ShareFile(IEnumerable<string> paths)
+ {
+ if (paths == null)
+ throw new InvalidIOException();
+
+ string[] pathArray = paths.ToArray<string>();
+ Interop.LibRPCPort.ErrorCode err = Interop.LibRPCPort.Port.SetPrivateSharingArray(Handle, pathArray, (uint)pathArray.Length);
+ if (err != Interop.LibRPCPort.ErrorCode.None)
+ throw new InvalidIOException();
+ }
+
+ /// <summary>
+ /// Shares the private file with other applications.
+ /// </summary>
+ /// <seealso cref="ShareFile(IEnumerable{string})"/>
+ /// <param name="path">The file path to be shared.</param>
+ /// <exception cref="InvalidIOException">Thrown when an internal IO error occurrs.</exception>
+ /// <since_tizen> 8 </since_tizen>
+ public void ShareFile(string path)
+ {
+ if (path == null)
+ throw new InvalidIOException();
+
+ Interop.LibRPCPort.ErrorCode err = Interop.LibRPCPort.Port.SetPrivateSharing(Handle, path);
+ if (err != Interop.LibRPCPort.ErrorCode.None)
+ throw new InvalidIOException();
+ }
+
+ /// <summary>
+ /// Unshares the private file.
+ /// </summary>
+ /// <exception cref="InvalidIOException">Thrown when an internal IO error occurrs.</exception>
+ /// <since_tizen> 8 </since_tizen>
+ public void UnshareFile()
+ {
+ Interop.LibRPCPort.ErrorCode err = Interop.LibRPCPort.Port.UnsetPrivateSharing(Handle);
+ if (err != Interop.LibRPCPort.ErrorCode.None)
+ throw new InvalidIOException();
+ }
}
}
}
/// <summary>
+ /// Connects to port synchronously.
+ /// </summary>
+ /// <param name="appid">The target stub app ID.</param>
+ /// <param name="port">The name of the RPC port.</param>
+ /// <exception cref="InvalidIDException">Thrown when not available app ID is used.</exception>
+ /// <exception cref="InvalidIOException">Thrown when an internal IO error occurs.</exception>
+ /// <exception cref="PermissionDeniedException">Thrown when the permission is denied.</exception>
+ /// <privilege>http://tizen.org/privilege/datasharing</privilege>
+ /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
+ /// <since_tizen> 8 </since_tizen>
+ protected void ConnectSync(string appid, string port)
+ {
+ var err = Interop.LibRPCPort.Proxy.ConnectSync(_proxy, appid, port);
+ switch (err)
+ {
+ case Interop.LibRPCPort.ErrorCode.InvalidParameter:
+ throw new InvalidIDException();
+ case Interop.LibRPCPort.ErrorCode.PermissionDenied:
+ throw new PermissionDeniedException();
+ case Interop.LibRPCPort.ErrorCode.IoError:
+ throw new InvalidIOException();
+ }
+ }
+
+ /// <summary>
/// Gets a port.
/// </summary>
/// <param name="t">The type of port.</param>