Skip to content

Commit

Permalink
[Tizen.Applications.RPCPort] Add internal APIs (#6495)
Browse files Browse the repository at this point in the history
* [Tizen.Applications.RPCPort] Add internal APIS

Signed-off-by: pjh9216 <[email protected]>

* Add comments for exceptions

Signed-off-by: pjh9216 <[email protected]>

---------

Signed-off-by: pjh9216 <[email protected]>
  • Loading branch information
pjh9216 authored Dec 5, 2024
1 parent c8d0a63 commit 7343586
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Tizen.Applications.Common/Interop/Interop.RPCPort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,34 @@ internal static partial class Parcel
//int rpc_port_parcel_create_without_header(rpc_port_parcel_h *h);
[DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_create_without_header")]
internal static extern ErrorCode CreateWithoutHeader(out IntPtr parcelHandle);

//int rpc_port_parcel_reserve(rpc_port_parcel_h h, unsigned int size);
[DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_reserve")]
internal static extern ErrorCode Reserve(IntPtr parcelHandle, uint size);

//int rpc_port_parcel_set_data_size(rpc_port_parcel_h h, unsigned int size);
[DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_set_data_size")]
internal static extern ErrorCode SetDataSize(IntPtr parcelHandle, uint size);

//int rpc_port_parcel_get_data_size(rpc_port_parcel_h h, unsigned int* size);
[DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_get_data_size")]
internal static extern ErrorCode GetDataSize(IntPtr parcelHandle, out uint size);

//int rpc_port_parcel_pin(rpc_port_parcel_h h);
[DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_pin")]
internal static extern ErrorCode Pin(IntPtr parcelHandle);

//int rpc_port_parcel_get_reader(rpc_port_parcel_h h, unsigned int* reader_pos);
[DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_get_reader")]
internal static extern ErrorCode GetReader(IntPtr parcelHandle, out uint readerPos);

//int rpc_port_parcel_set_reader(rpc_port_parcel_h h, unsigned int reader_pos);
[DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_set_reader")]
internal static extern ErrorCode SetReader(IntPtr parcelHandle, uint readerPos);

//int rpc_port_parcel_create_from_parcel(rpc_port_parcel_h* h, rpc_port_parcel_h origin_parcel, unsigned int start_pos, unsigned int size);
[DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_parcel_create_from_parcel")]
internal static extern ErrorCode CreateFromParcel(out IntPtr parcelHandle, IntPtr originParcel, uint startPos, uint size);
}

internal static partial class Proxy
Expand Down
116 changes: 116 additions & 0 deletions src/Tizen.Applications.Common/Tizen.Applications.RPCPort/Parcel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/

using System;
using System.ComponentModel;
using System.Reflection.Metadata;
using System.Runtime.InteropServices;

namespace Tizen.Applications.RPCPort
Expand Down Expand Up @@ -155,6 +157,28 @@ public class Parcel : IDisposable
private IntPtr _handle;
private ParcelHeader _header;

/// <summary>
/// Constructs a sub parcel from origin parcel.
/// </summary>
/// <param name="origin">The origin parcel.</param>
/// <param name="startPos">The start position from origin parcel.</param>
/// <param name="size">The size of the new parcel.</param>
/// <exception cref="InvalidIOException">Thrown when an internal IO error occurs.</exception>
/// <exception cref="ArgumentException">Thrown when arguments are invalid.</exception>
/// <since_tizen> 10 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
public Parcel(Parcel origin, uint startPos, uint size)
{
if (origin == null)
throw new ArgumentException();

Interop.LibRPCPort.ErrorCode error;

error = Interop.LibRPCPort.Parcel.CreateFromParcel(out _handle, origin._handle, startPos, size);
if (error != Interop.LibRPCPort.ErrorCode.None)
throw new InvalidIOException();
}

/// <summary>
/// Constructs a new instance of the Parcel class.
/// </summary>
Expand Down Expand Up @@ -529,6 +553,98 @@ public ParcelHeader GetHeader()
return _header;
}

/// <summary>
/// Reserves bytes to write later.
/// <param name="size">The bytes to reserve.</param>
/// </summary>
/// <exception cref="InvalidIOException">Thrown when an internal IO error occurs.</exception>
/// <since_tizen> 10 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
public void Reserve(uint size)
{
Interop.LibRPCPort.ErrorCode error;
error = Interop.LibRPCPort.Parcel.Reserve(_handle, size);
if (error != Interop.LibRPCPort.ErrorCode.None)
throw new InvalidIOException();
}

/// <summary>
/// Pin the memory. Once it is called, the capacity would not be changed.
/// </summary>
/// <exception cref="InvalidIOException">Thrown when an internal IO error occurs.</exception>
/// <since_tizen> 10 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
public void Pin()
{
Interop.LibRPCPort.ErrorCode error;
error = Interop.LibRPCPort.Parcel.Pin(_handle);
if (error != Interop.LibRPCPort.ErrorCode.None)
throw new InvalidIOException();
}

/// <summary>
/// Gets the reader pointer of the parcel to the start.
/// </summary>
/// <returns>The position of the reader</returns>
/// <exception cref="InvalidIOException">Thrown when an internal IO error occurs.</exception>
/// <since_tizen> 10 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
public uint GetReader()
{
Interop.LibRPCPort.ErrorCode error;
error = Interop.LibRPCPort.Parcel.GetReader(_handle, out uint reader);
if (error != Interop.LibRPCPort.ErrorCode.None)
throw new InvalidIOException();
return reader;
}

/// <summary>
/// Sets the reader pointer of the parcel to the start.
/// </summary>
/// <param name="pos">The position to read.</param>
/// <exception cref="InvalidIOException">Thrown when an internal IO error occurs.</exception>
/// <since_tizen> 10 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
public void SetReader(uint pos)
{
Interop.LibRPCPort.ErrorCode error;
error = Interop.LibRPCPort.Parcel.SetReader(_handle, pos);
if (error != Interop.LibRPCPort.ErrorCode.None)
throw new InvalidIOException();
}

/// <summary>
/// Gets the size of the raw data of the parcel.
/// </summary>
/// <returns>The size of data</returns>
/// <exception cref="InvalidIOException">Thrown when an internal IO error occurs.</exception>
/// <since_tizen> 10 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
public uint GetDataSize()
{
Interop.LibRPCPort.ErrorCode error;
error = Interop.LibRPCPort.Parcel.GetDataSize(_handle, out uint size);
if (error != Interop.LibRPCPort.ErrorCode.None)
throw new InvalidIOException();

return size;
}

/// <summary>
/// Sets the size of the raw data of the parcel.
/// </summary>
/// <param name="size">The size of data.</param>
/// <exception cref="InvalidIOException">Thrown when an internal IO error occurs.</exception>
/// <since_tizen> 10 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
public void SetDataSize(uint size)
{
Interop.LibRPCPort.ErrorCode error;
error = Interop.LibRPCPort.Parcel.SetDataSize(_handle, size);
if (error != Interop.LibRPCPort.ErrorCode.None)
throw new InvalidIOException();
}

#region IDisposable Support
private bool disposedValue = false;

Expand Down

0 comments on commit 7343586

Please sign in to comment.