/*
* Copyright 2019 by its authors. See AUTHORS.
*
* 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.
*/
#pragma warning disable 1591
using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
///Eo class description, passed to efl_class_new.
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
internal struct ClassDescription : IEquatable
{
///Current Eo version.
internal uint version;
///Name of the class.
[MarshalAs(UnmanagedType.LPStr)] internal String name;
///Class type.
internal int class_type;
///Size of data (private + protected + public) per instance.
internal UIntPtr data_size;
///Initializer for the class.
internal IntPtr class_initializer;
///Constructor of the class.
internal IntPtr class_constructor;
///Destructor of the class.
internal IntPtr class_destructor;
///
/// Gets a hash for .
/// Since EFL 1.24.
///
/// A hash code.
public override int GetHashCode()
=> version.GetHashCode() ^ name.GetHashCode(StringComparison.Ordinal)
^ class_type ^ data_size.GetHashCode();
/// Returns whether this
/// is equal to the given .
/// Since EFL 1.24.
///
/// The to be compared to.
/// true if is equal to other.
public override bool Equals(object other)
=> (!(other is ClassDescription)) ? false
: Equals((ClassDescription)other);
/// Returns whether this is equal
/// to the given .
/// Since EFL 1.24.
///
/// The to be compared to.
/// true if is equal to other.
public bool Equals(ClassDescription other)
=> (name == other.name) && (class_type == other.class_type);
/// Returns whether lhs is equal to rhs.
/// Since EFL 1.24.
///
/// The left hand side of the operator.
/// The right hand side of the operator.
/// true if lhs is equal
/// to rhs.
public static bool operator==(ClassDescription lhs, ClassDescription rhs)
=> lhs.Equals(rhs);
/// Returns whether lhs is not equal to rhs.
/// Since EFL 1.24.
///
/// The left hand side of the operator.
/// The right hand side of the operator.
/// true if lhs is not equal
/// to rhs.
public static bool operator!=(ClassDescription lhs, ClassDescription rhs)
=> !(lhs == rhs);
}
///Description of an Eo API operation.
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
internal struct EflOpDescription
{
///The EAPI function offering this op. (String with the name of the function on Windows)
internal IntPtr api_func;
///The static function to be called for this op
internal IntPtr func;
}
///List of operations on a given Object.
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
internal struct EflObjectOps
{
///The op descriptions array of size count.
internal IntPtr descs;
///Number of op descriptions.
internal UIntPtr count;
};
namespace Efl
{
///
/// This struct holds the description of a specific event.
/// Since EFL 1.22.
///
[StructLayout(LayoutKind.Sequential)]
internal struct EventDescription
{
///Name of the event.
public IntPtr Name;
///true if the event cannot be frozen.
[MarshalAs(UnmanagedType.U1)] public bool Unfreezable;
///Internal use: true if this is a legacy event.
[MarshalAs(UnmanagedType.U1)] public bool Legacy_is;
///true if when the even is triggered again from a callback it
///will start from where it was.
[MarshalAs(UnmanagedType.U1)] public bool Restart;
private static Dictionary descriptions = new Dictionary();
///Constructor for EventDescription
///The name of the module containing the event.
///The name of the event.
public EventDescription(string moduleName, string name)
{
this.Name = GetNative(moduleName, name);
this.Unfreezable = false;
this.Legacy_is = false;
this.Restart = false;
}
///Get the native structure.
///The name of the module containing the event.
///The name of the event.
///Pointer to the native structure.
public static IntPtr GetNative(string moduleName, string name)
{
if (!descriptions.ContainsKey(name))
{
IntPtr data = Efl.Eo.FunctionInterop.LoadFunctionPointer(moduleName, name);
if (data == IntPtr.Zero)
{
string error = Eina.StringConversion.NativeUtf8ToManagedString(Efl.Eo.Globals.dlerror());
throw new Exception(error);
}
descriptions.Add(name, data);
}
return descriptions[name];
}
};
///
/// A parameter passed in event callbacks holding extra event parameters.
/// This is the full event information passed to callbacks in C.
/// Since EFL 1.22.
///
[StructLayout(LayoutKind.Sequential)]
[Efl.Eo.BindingEntity]
internal struct Event
{
/// Internal wrapper for field Object
private System.IntPtr obj;
/// Internal wrapper for field Desc
private System.IntPtr desc;
/// Internal wrapper for field Info
private System.IntPtr info;
///
/// The object the callback was called on.
/// Since EFL 1.22.
///
public Efl.Object Object { get => (Efl.Object) Efl.Eo.Globals.CreateWrapperFor(obj); }
///
/// The event description.
/// Since EFL 1.22.
///
public Efl.EventDescription Desc { get => Eina.PrimitiveConversion.PointerToManaged(desc); }
///
/// Extra event information passed by the event caller.
/// Must be cast to the event type declared in the EO file. Keep in mind that:
/// 1) Objects are passed as a normal Eo*. Event subscribers can call functions on these objects.
/// 2) Structs, built-in types and containers are passed as const pointers, with one level of indirection.
/// Since EFL 1.22.
///
public System.IntPtr Info { get => info; }
/// Constructor for Event.
public Event(
Efl.Object obj = default(Efl.Object),
Efl.EventDescription desc = default(Efl.EventDescription),
System.IntPtr info = default(System.IntPtr))
{
this.obj = obj?.NativeHandle ?? System.IntPtr.Zero;
this.desc = Eina.PrimitiveConversion.ManagedToPointerAlloc(desc);
this.info = info;
}
/// Implicit conversion to the managed representation from a native pointer.
/// Native pointer to be converted.
public static implicit operator Event(IntPtr ptr)
{
var tmp = (Event) Marshal.PtrToStructure(ptr, typeof(Event));
return tmp;
}
}
internal delegate void EventCb(System.IntPtr data, ref Event evt);
internal delegate void FreeWrapperSupervisorCb(System.IntPtr obj);
namespace Access
{
public struct ActionData : IEquatable
{
public IntPtr name;
public IntPtr action;
public IntPtr param;
public IntPtr func;
///
/// Gets a hash for .
/// Since EFL 1.24.
///
/// A hash code.
public override int GetHashCode()
=> name.GetHashCode() ^ action.GetHashCode()
^ param.GetHashCode() ^ func.GetHashCode();
/// Returns whether this
/// is equal to the given .
/// Since EFL 1.24.
///
/// The to be compared to.
/// true if is equal to other.
public override bool Equals(object other)
=> (!(other is ActionData)) ? false
: Equals((ActionData)other);
/// Returns whether this is equal
/// to the given .
/// Since EFL 1.24.
///
/// The to be compared to.
/// true if is equal to other.
public bool Equals(ActionData other)
=> (name == other.name) && (action == other.action)
&& (param == other.param) && (func == other.func);
/// Returns whether lhs is equal to rhs.
/// Since EFL 1.24.
///
/// The left hand side of the operator.
/// The right hand side of the operator.
/// true if lhs is equal
/// to rhs.
public static bool operator==(ActionData lhs, ActionData rhs)
=> lhs.Equals(rhs);
/// Returns whether lhs is not equal to rhs.
/// Since EFL 1.24.
///
/// The left hand side of the operator.
/// The right hand side of the operator.
/// true if lhs is not equal
/// to rhs.
public static bool operator!=(ActionData lhs, ActionData rhs)
=> !(lhs == rhs);
}
} // namespace Access
} // namespace Efl