Skip to content
This repository has been archived by the owner on May 25, 2020. It is now read-only.

Csharp fixes and API hiding stuff #11

Merged
merged 2 commits into from
Jul 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/bin/eolian_mono/eolian/mono/events.hh
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ struct event_definition_generator
scope_tab << "{\n"
<< scope_tab << scope_tab << "add\n"
<< scope_tab << scope_tab << "{\n"
<< scope_tab << scope_tab << scope_tab << "lock (eventLock)\n"
<< scope_tab << scope_tab << scope_tab << "lock (eflBindingEventLock)\n"
<< scope_tab << scope_tab << scope_tab << "{\n"
<< scope_tab << scope_tab << scope_tab << scope_tab << "Efl.EventCb callerCb = (IntPtr data, ref Efl.Event.NativeStruct evt) =>\n"
<< scope_tab << scope_tab << scope_tab << scope_tab << "{\n"
Expand All @@ -460,7 +460,7 @@ struct event_definition_generator
<< scope_tab << scope_tab << "}\n\n"
<< scope_tab << scope_tab << "remove\n"
<< scope_tab << scope_tab << "{\n"
<< scope_tab << scope_tab << scope_tab << "lock (eventLock)\n"
<< scope_tab << scope_tab << scope_tab << "lock (eflBindingEventLock)\n"
<< scope_tab << scope_tab << scope_tab << "{\n"
<< scope_tab << scope_tab << scope_tab << scope_tab << "string key = \"_" << upper_c_name << "\";\n"
<< scope_tab << scope_tab << scope_tab << scope_tab << "RemoveNativeEventHandler(" << library_name << ", key, value);\n"
Expand Down
5 changes: 3 additions & 2 deletions src/bin/eolian_mono/eolian/mono/function_definition.hh
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,10 @@ struct function_definition_generator

std::string self = "this.NativeHandle";

// inherited is set in the constructor, true if this instance is from a pure C# class (not generated).
// IsGeneratedBindingClass is set in the constructor, true if this
// instance is from a pure C# class (not generated).
if (do_super && !f.is_static)
self = "(inherited ? Efl.Eo.Globals.efl_super(" + self + ", this.NativeClass) : " + self + ")";
self = "(IsGeneratedBindingClass ? " + self + " : Efl.Eo.Globals.efl_super(" + self + ", this.NativeClass))";
else if (f.is_static)
self = "";

Expand Down
6 changes: 3 additions & 3 deletions src/bin/eolian_mono/eolian/mono/klass.hh
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ struct klass
<< scope_tab << scope_tab << name_helpers::klass_get_name(cls) << "();\n"
<< scope_tab << "/// <summary>Initializes a new instance of the <see cref=\"" << interface_name << "\"/> class.\n"
<< scope_tab << "/// Internal usage: This is used when interacting with C code and should not be used directly.</summary>\n"
<< scope_tab << "private " << concrete_name << "(System.IntPtr raw) : base(raw)\n"
<< scope_tab << "private " << concrete_name << "(Efl.Eo.Globals.WrappingHandle wh) : base(wh)\n"
<< scope_tab << "{\n"
<< scope_tab << "}\n\n"
)
Expand Down Expand Up @@ -511,7 +511,7 @@ struct klass
<< scope_tab << "/// <summary>Initializes a new instance of the <see cref=\"" << inherit_name << "\"/> class.\n"
<< scope_tab << "/// Internal usage: Constructs an instance from a native pointer. This is used when interacting with C code and should not be used directly.</summary>\n"
<< scope_tab << "/// <param name=\"raw\">The native pointer to be wrapped.</param>\n"
<< scope_tab << "protected " << inherit_name << "(System.IntPtr raw) : base(raw)\n"
<< scope_tab << "protected " << inherit_name << "(Efl.Eo.Globals.WrappingHandle wh) : base(wh)\n"
<< scope_tab << "{\n"
<< scope_tab << "}\n\n"
).generate(sink, std::make_tuple(constructors, constructors, constructors), context))
Expand All @@ -526,7 +526,7 @@ struct klass
scope_tab << "[Efl.Eo.PrivateNativeClass]\n"
<< scope_tab << "private class " << inherit_name << "Realized : " << inherit_name << "\n"
<< scope_tab << "{\n"
<< scope_tab << scope_tab << "private " << inherit_name << "Realized(IntPtr ptr) : base(ptr)\n"
<< scope_tab << scope_tab << "private " << inherit_name << "Realized(Efl.Eo.Globals.WrappingHandle wh) : base(wh)\n"
<< scope_tab << scope_tab << "{\n"
<< scope_tab << scope_tab << "}\n"
<< scope_tab << "}\n"
Expand Down
6 changes: 4 additions & 2 deletions src/bindings/mono/eina_mono/eina_promises.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,14 @@ public Future Then(ResolvedCb cb)
private static IntPtr ThenRaw(IntPtr previous, ResolvedCb cb)
{
FutureDesc desc = new FutureDesc();
desc.cb = NativeResolvedCb;
desc.cb = NativeResolvedCbDelegate;
GCHandle handle = GCHandle.Alloc(cb);
desc.data = GCHandle.ToIntPtr(handle);
return eina_future_then_from_desc(previous, desc);
}

private static FutureCb NativeResolvedCbDelegate = new FutureCb(NativeResolvedCb);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the definition of NativeResolvedCbDelegate is missing.

It is here. Just a FutureCb using NativeResolvedCb.


private static Eina.ValueNative NativeResolvedCb(IntPtr data, Eina.ValueNative value, IntPtr dead_future)
{
GCHandle handle = GCHandle.FromIntPtr(data);
Expand Down Expand Up @@ -340,7 +342,7 @@ public Future Chain(IEnumerable<ResolvedCb> cbs)
for (; i < cbsList.Count(); i++)
{
ResolvedCb cb = cbsList[i];
descs[i].cb = NativeResolvedCb;
descs[i].cb = NativeResolvedCbDelegate;
GCHandle handle = GCHandle.Alloc(cb);
descs[i].data = GCHandle.ToIntPtr(handle);
}
Expand Down
28 changes: 17 additions & 11 deletions src/bindings/mono/eo_mono/EoWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace Eo

public abstract class EoWrapper : IWrapper, IDisposable
{
protected readonly object eventLock = new object();
protected bool inherited = false;
protected System.IntPtr handle = IntPtr.Zero;
protected readonly object eflBindingEventLock = new object();
private bool generated = true;
private System.IntPtr handle = IntPtr.Zero;

private static Efl.EventCb ownershipUniqueDelegate = new Efl.EventCb(OwnershipUniqueCallback);
private static Efl.EventCb ownershipSharedDelegate = new Efl.EventCb(OwnershipSharedCallback);
Expand All @@ -32,7 +32,7 @@ public abstract class EoWrapper : IWrapper, IDisposable
/// <param name="ch">Tag struct storing the native handle of the object being constructed.</param>
protected EoWrapper(ConstructingHandle ch)
{
inherited = true;
generated = false;
handle = Efl.Eo.Globals.efl_constructor(Efl.Eo.Globals.efl_super(ch.NativeHandle, Efl.Eo.Globals.efl_class_get(ch.NativeHandle)));
if (handle == IntPtr.Zero)
{
Expand All @@ -47,11 +47,12 @@ protected EoWrapper(ConstructingHandle ch)
}

/// <summary>Initializes a new instance of the <see cref="Object"/> class.
/// Internal usage: Constructs an instance from a native pointer. This is used when interacting with C code and should not be used directly.</summary>
/// Internal usage: Constructs an instance from a native pointer. This is used when interacting with C code and should not be used directly.
/// Do not implement this constructor.</summary>
/// <param name="raw">The native pointer to be wrapped.</param>
protected EoWrapper(System.IntPtr raw)
protected EoWrapper(Efl.Eo.Globals.WrappingHandle wh)
{
handle = raw;
handle = wh.NativeHandle;
AddWrapperSupervisor();
}

Expand All @@ -67,9 +68,9 @@ protected EoWrapper(IntPtr baseKlass, System.Type managedType, Efl.Object parent
[CallerFilePath] string file = null,
[CallerLineNumber] int line = 0)
{
inherited = ((object)this).GetType() != managedType;
generated = ((object)this).GetType() == managedType;
IntPtr actual_klass = baseKlass;
if (inherited)
if (!generated)
{
actual_klass = Efl.Eo.ClassRegister.GetInheritKlassOrRegister(baseKlass, ((object)this).GetType());
}
Expand All @@ -82,7 +83,7 @@ protected EoWrapper(IntPtr baseKlass, System.Type managedType, Efl.Object parent
parent_ptr = parent.NativeHandle;
}

if (!inherited)
if (generated)
{
handle = Efl.Eo.Globals._efl_add_internal_start(file, line, actual_klass, parent_ptr, 1, 0);
}
Expand Down Expand Up @@ -123,6 +124,11 @@ public abstract System.IntPtr NativeClass
get;
}

protected bool IsGeneratedBindingClass
{
get { return generated; }
}

/// <summary>Releases the underlying native instance.</summary>
protected virtual void Dispose(bool disposing)
{
Expand Down Expand Up @@ -292,7 +298,7 @@ public ConstructingHandle(IntPtr h)
NativeHandle = h;
}

public IntPtr NativeHandle { get; set; }
public IntPtr NativeHandle { get; private set; }
}

public abstract class NativeMethods : Efl.Eo.NativeClass
Expand Down
20 changes: 18 additions & 2 deletions src/bindings/mono/eo_mono/iwrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -624,14 +624,15 @@ public static Efl.Eo.IWrapper CreateWrapperFor(System.IntPtr handle, bool should
try
{
var flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
constructor = managedType.GetConstructor(flags, null, new Type[1] { typeof(System.IntPtr) }, null);
constructor = managedType.GetConstructor(flags, null, new Type[1] { typeof(WrappingHandle) }, null);
}
catch (InvalidOperationException)
{
throw new InvalidOperationException($"Can't get constructor for type {managedType}");
}

var ret = (Efl.Eo.IWrapper) constructor.Invoke(new object[1] { handle });
WrappingHandle wh = new WrappingHandle(handle);
var ret = (Efl.Eo.IWrapper) constructor.Invoke(new object[1] { wh });

if (ret == null)
{
Expand Down Expand Up @@ -715,6 +716,21 @@ public static void ThreadSafeFreeCbExec(EinaFreeCb cbFreeCb, IntPtr cbData)
Monitor.Exit(Efl.All.InitLock);
}

/// <sumary>
/// Internal struct used by the binding to pass the native handle pointer
/// to the managed object wrapping constructor.
/// Internal usage only: do not use this class in inherited classes.
/// </sumary>
public struct WrappingHandle
{
public WrappingHandle(IntPtr h)
{
NativeHandle = h;
}

public IntPtr NativeHandle { get; private set; }
}

} // Globals

public static class Config
Expand Down
9 changes: 5 additions & 4 deletions src/tests/efl_mono/EoConstruction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ private InheritedConstructibleObject(ConstructingHandle ch) : base(ch)
public int DefaultConstrutorCallCount { get; set; } = 0;
public int SpecialConstrutorCallCount { get; set; } = 0;

public bool InheritedFlag
/// <summary>Pointer to the native class description.</summary>
public bool IsInheritedClass
{
get { return inherited; }
get { return !this.IsGeneratedBindingClass; }
}

public override int MultiplyIntegerValue(int v)
Expand All @@ -56,7 +57,7 @@ public static void TestGeneratedEoDirectConstruction()
public static void TestInheritedEoDirectConstruction()
{
var obj = new InheritedConstructibleObject();
Test.AssertEquals(obj.InheritedFlag, true);
Test.AssertEquals(obj.IsInheritedClass, true);
Test.AssertEquals(obj.NativeConstructionCount, 1);
Test.AssertEquals(obj.DefaultConstructionCount, 1);
Test.AssertEquals(obj.SpecialConstructionCount, 0);
Expand All @@ -75,7 +76,7 @@ public static void TestInheritedEoIndirectConstruction()
Test.AssertEquals(obj.MultiplyIntegerValue(21), 42);

var obj2 = (InheritedConstructibleObject) obj.ConstructTypeAndStore(typeof(InheritedConstructibleObject));
Test.AssertEquals(obj2.InheritedFlag, true);
Test.AssertEquals(obj2.IsInheritedClass, true);
Test.AssertEquals(obj2.NativeConstructionCount, 1);
Test.AssertEquals(obj2.DefaultConstructionCount, 0);
Test.AssertEquals(obj2.SpecialConstructionCount, 1);
Expand Down