csharp: updating eldbus_connection docs.

Summary: ref T8361

Reviewers: lauromoura, felipealmeida, segfaultxavi, woohyun

Reviewed By: lauromoura

Subscribers: cedric, #reviewers, #committers

Tags: #efl

Maniphest Tasks: T8361

Differential Revision: https://phab.enlightenment.org/D10418
This commit is contained in:
Bruno da Silva Belo 2019-10-16 10:50:10 -03:00 committed by Lauro Moura
parent ee33f93743
commit e6bffe1e2b
1 changed files with 147 additions and 4 deletions

View File

@ -2,12 +2,14 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.ComponentModel;
using static eldbus.EldbusConnectionNativeFunctions; using static eldbus.EldbusConnectionNativeFunctions;
namespace eldbus namespace eldbus
{ {
[EditorBrowsable(EditorBrowsableState.Never)]
public static class EldbusConnectionNativeFunctions public static class EldbusConnectionNativeFunctions
{ {
[DllImport(efl.Libs.Eldbus)] public static extern IntPtr [DllImport(efl.Libs.Eldbus)] public static extern IntPtr
@ -89,22 +91,55 @@ public static class EldbusConnectionNativeFunctions
} }
/// <summary>Represents a DBus connection. /// <summary>Represents a DBus connection.
/// /// <para>Since EFL 1.23.</para>
/// Since EFL 1.23.
/// </summary> /// </summary>
public class Connection : IDisposable public class Connection : IDisposable
{ {
/// <summary>
/// The type of the Connection.
/// <para>Since EFL 1.23.</para>
/// </summary>
public enum Type public enum Type
{ {
/// <summary>
/// Unknown type.
/// <para>It's a sentinel.</para>
/// <para>Since EFL 1.23.</para>
/// </summary>
Unknown = 0, // sentinel, not a real type Unknown = 0, // sentinel, not a real type
/// <summary>
/// Session type.
/// <para>Since EFL 1.23.</para>
/// </summary>
Session, Session,
/// <summary>
/// System type.
/// <para>Since EFL 1.23.</para>
/// </summary>
System, System,
/// <summary>
/// Starter type.
/// <para>Since EFL 1.23.</para>
/// </summary>
Starter, Starter,
/// <summary>
/// Address type.
/// <para>Since EFL 1.23.</para>
/// </summary>
Address, Address,
/// <summary>
/// Last type.
/// <para>It's a sentinel.</para>
/// <para>Since EFL 1.23.</para>
/// </summary>
Last // sentinel, not a real type Last // sentinel, not a real type
}; };
[EditorBrowsable(EditorBrowsableState.Never)]
public IntPtr Handle {get;set;} = IntPtr.Zero; public IntPtr Handle {get;set;} = IntPtr.Zero;
/// <summary>Whether this wrapper owns the native handle.
/// <para>Since EFL 1.23.</para>
/// </summary>
public bool Own {get;set;} = true; public bool Own {get;set;} = true;
private void InitNew(IntPtr handle, bool own) private void InitNew(IntPtr handle, bool own)
@ -122,38 +157,67 @@ public class Connection : IDisposable
} }
} }
[EditorBrowsable(EditorBrowsableState.Never)]
public Connection(IntPtr handle, bool own) public Connection(IntPtr handle, bool own)
{ {
InitNew(handle, own); InitNew(handle, own);
} }
/// <summary>
/// Constructor.
/// <para>Since EFL 1.23.</para>
/// </summary>
/// <param name="type">The type of the connection.</param>
public Connection(eldbus.Connection.Type type) public Connection(eldbus.Connection.Type type)
{ {
InitNew(eldbus_connection_get(type), true); InitNew(eldbus_connection_get(type), true);
} }
/// <summary>
/// Constructor.
/// <para>Since EFL 1.23.</para>
/// </summary>
/// <param name="address">The address of the connection.</param>
public Connection(string address) public Connection(string address)
{ {
InitNew(eldbus_address_connection_get(address), true); InitNew(eldbus_address_connection_get(address), true);
} }
/// <summary>
/// Gets a Connection with a type.
/// <para>Since EFL 1.23.</para>
/// </summary>
/// <param name="type"></param>
/// <returns>A Connection with the type.</returns>
public static eldbus.Connection GetPrivate(eldbus.Connection.Type type) public static eldbus.Connection GetPrivate(eldbus.Connection.Type type)
{ {
return new eldbus.Connection(eldbus_private_connection_get(type), true); return new eldbus.Connection(eldbus_private_connection_get(type), true);
} }
/// <summary>
/// Gets a Connection with a address.
/// <para>Since EFL 1.23.</para>
/// </summary>
/// <param name="address">The address of the connection.</param>
public static eldbus.Connection GetPrivate(string address) public static eldbus.Connection GetPrivate(string address)
{ {
return new eldbus.Connection(eldbus_private_address_connection_get(address), true); return new eldbus.Connection(eldbus_private_address_connection_get(address), true);
} }
/// <summary>
/// Finalizer to be called from the Garbage Collector.
/// <para>Since EFL 1.23.</para>
/// </summary>
~Connection() ~Connection()
{ {
Dispose(false); Dispose(false);
} }
/// <summary>Disposes of this wrapper, releasing the native array if owned.
/// <para>Since EFL 1.23.</para>
/// </summary>
/// <param name="disposing">True if this was called from <see cref="Dispose()"/> public method. False if
/// called from the C# finalizer.</param>
protected virtual void Dispose(bool disposing) protected virtual void Dispose(bool disposing)
{ {
IntPtr h = Handle; IntPtr h = Handle;
@ -176,17 +240,28 @@ public class Connection : IDisposable
} }
} }
/// <summary>Releases the native resources held by this instance.
/// <para>Since EFL 1.23.</para>
/// </summary>
public void Dispose() public void Dispose()
{ {
Dispose(true); Dispose(true);
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
} }
/// <summary>Releases the native resources held by this instance.
/// <para>Since EFL 1.23.</para>
/// </summary>
public void Free() public void Free()
{ {
Dispose(); Dispose();
} }
/// <summary>
/// Releases the native handler.
/// <para>Since EFL 1.23.</para>
/// </summary>
/// <returns>The native handler.</returns>
public IntPtr Release() public IntPtr Release()
{ {
IntPtr h = Handle; IntPtr h = Handle;
@ -194,6 +269,14 @@ public class Connection : IDisposable
return h; return h;
} }
/// <summary>
/// Send a message.
/// <para>Since EFL 1.23.</para>
/// </summary>
/// <param name="msg">The message that will be sent.</param>
/// <param name="dlgt">The function that is executed when a response arrives..</param>
/// <param name="timeout">The timeout of the message.</param>
/// <returns>A <see cref="eldbus.Pending" /></returns>
public eldbus.Pending Send(eldbus.Message msg, eldbus.MessageDelegate dlgt = null, double timeout = -1) public eldbus.Pending Send(eldbus.Message msg, eldbus.MessageDelegate dlgt = null, double timeout = -1)
{ {
CheckHandle(); CheckHandle();
@ -218,6 +301,11 @@ public class Connection : IDisposable
return new eldbus.Pending(pending_hdl, false); return new eldbus.Pending(pending_hdl, false);
} }
/// <summary>
/// Gets a unique name assigned by the message bus.
/// <para>Since EFL 1.23.</para>
/// </summary>
/// <returns>The unique name string.</returns>
public string GetUniqueName() public string GetUniqueName()
{ {
CheckHandle(); CheckHandle();
@ -230,6 +318,14 @@ public class Connection : IDisposable
return Eina.StringConversion.NativeUtf8ToManagedString(ptr); return Eina.StringConversion.NativeUtf8ToManagedString(ptr);
} }
/// <summary>
/// Send a RequestName method.
/// <para>Since EFL 1.23.</para>
/// </summary>
/// <param name="bus">The name of the bus.</param>
/// <param name="flags">Parameter of the RequestName method.</param>
/// <param name="dlgt">The function to call when receiving answer.</param>
/// <returns>A <see cref="eldbus.Pending" /></returns>
public eldbus.Pending NameRequest(string bus, uint flags, eldbus.MessageDelegate dlgt = null) public eldbus.Pending NameRequest(string bus, uint flags, eldbus.MessageDelegate dlgt = null)
{ {
CheckHandle(); CheckHandle();
@ -252,6 +348,13 @@ public class Connection : IDisposable
return new eldbus.Pending(pending_hdl, false); return new eldbus.Pending(pending_hdl, false);
} }
/// <summary>
/// Send a ReleaseName method.
/// <para>Since EFL 1.23.</para>
/// </summary>
/// <param name="bus">The name of the bus.</param>
/// <param name="dlgt">The function to call when receiving answer.</param>
/// <returns>A <see cref="eldbus.Pending" /></returns>
public eldbus.Pending NameRelease(string bus, eldbus.MessageDelegate dlgt = null) public eldbus.Pending NameRelease(string bus, eldbus.MessageDelegate dlgt = null)
{ {
CheckHandle(); CheckHandle();
@ -274,6 +377,13 @@ public class Connection : IDisposable
return new eldbus.Pending(pending_hdl, false); return new eldbus.Pending(pending_hdl, false);
} }
/// <summary>
/// Send a GetNameOwner method.
/// <para>Since EFL 1.23.</para>
/// </summary>
/// <param name="bus">The name of the bus.</param>
/// <param name="dlgt">The function to call when receiving answer.</param>
/// <returns>A <see cref="eldbus.Pending" /></returns>
public eldbus.Pending GetNameOwner(string bus, eldbus.MessageDelegate dlgt = null) public eldbus.Pending GetNameOwner(string bus, eldbus.MessageDelegate dlgt = null)
{ {
CheckHandle(); CheckHandle();
@ -296,6 +406,13 @@ public class Connection : IDisposable
return new eldbus.Pending(pending_hdl, false); return new eldbus.Pending(pending_hdl, false);
} }
/// <summary>
/// Send NameHasOwner method.
/// <para>Since EFL 1.23.</para>
/// </summary>
/// <param name="bus">The name of the bus.</param>
/// <param name="dlgt">The function to call when receiving the answer.</param>
/// <returns>A <see cref="eldbus.Pending" /></returns>
public eldbus.Pending HasNameOwner(string bus, eldbus.MessageDelegate dlgt = null) public eldbus.Pending HasNameOwner(string bus, eldbus.MessageDelegate dlgt = null)
{ {
CheckHandle(); CheckHandle();
@ -318,6 +435,12 @@ public class Connection : IDisposable
return new eldbus.Pending(pending_hdl, false); return new eldbus.Pending(pending_hdl, false);
} }
/// <summary>
/// Send ListNames method.
/// <para>Since EFL 1.23.</para>
/// </summary>
/// <param name="dlgt">The function to call when receiving answer.</param>
/// <returns>A <see cref="eldbus.Pending" /></returns>
public eldbus.Pending NameList(eldbus.MessageDelegate dlgt = null) public eldbus.Pending NameList(eldbus.MessageDelegate dlgt = null)
{ {
CheckHandle(); CheckHandle();
@ -335,6 +458,12 @@ public class Connection : IDisposable
return new eldbus.Pending(pending_hdl, false); return new eldbus.Pending(pending_hdl, false);
} }
/// <summary>
/// Send ListActivatableNames method.
/// <para>Since EFL 1.23.</para>
/// </summary>
/// <param name="dlgt">The function to call when receiving a method.</param>
/// <returns>A <see cref="eldbus.Pending" /></returns>
public eldbus.Pending ActivatableList(eldbus.MessageDelegate dlgt = null) public eldbus.Pending ActivatableList(eldbus.MessageDelegate dlgt = null)
{ {
CheckHandle(); CheckHandle();
@ -352,6 +481,12 @@ public class Connection : IDisposable
return new eldbus.Pending(pending_hdl, false); return new eldbus.Pending(pending_hdl, false);
} }
/// <summary>
/// Send Hello method.
/// <para>Since EFL 1.23.</para>
/// </summary>
/// <param name="dlgt">The function to call when receiving answer.</param>
/// <returns>A <see cref="eldbus.Pending" /></returns>
public eldbus.Pending Hello(eldbus.MessageDelegate dlgt = null) public eldbus.Pending Hello(eldbus.MessageDelegate dlgt = null)
{ {
CheckHandle(); CheckHandle();
@ -369,6 +504,14 @@ public class Connection : IDisposable
return new eldbus.Pending(pending_hdl, false); return new eldbus.Pending(pending_hdl, false);
} }
/// <summary>
/// Send StartServiceByName method.
/// <para>Since EFL 1.23.</para>
/// </summary>
/// <param name="bus">The name of the bus.</param>
/// <param name="flags">Parameter of the StartServiceByName.</param>
/// <param name="dlgt">The function to call when receiving answer.</param>
/// <returns>A <see cref="eldbus.Pending" /></returns>
public eldbus.Pending NameStart(string bus, uint flags, eldbus.MessageDelegate dlgt = null) public eldbus.Pending NameStart(string bus, uint flags, eldbus.MessageDelegate dlgt = null)
{ {
CheckHandle(); CheckHandle();