16using System.Reflection;
17using System.Runtime.InteropServices;
18using System.Runtime.CompilerServices;
19using System.Collections.Generic;
20using System.Threading;
28 public partial class MkObjectC
30 public partial class MkObjectC : MkObjectC
33 private readonly
static ConstructorInfo ctor =
getCtor(typeof(MkObjectC));
34 private readonly
static ThreadLocal<MkObjectC> MK_NULL =
new ThreadLocal<MkObjectC>(() => {
42 private static MkObjectC MkObjectC_ObjCreate (IntPtr
hdl) {
46 private static IntPtr MkObjectC_SelfCreate (IntPtr
mkrt, IntPtr obj, IntPtr env) {
50 private static void MkObjectC_SelfUnlink (IntPtr
mkrt, IntPtr
self, IntPtr env) {
54 internal static void SetupThreadOBJ (IntPtr
mkrt) {
55 Mk.MkCsTypeUpdate(
mkrt, MkCsTypeLookupE.OBJ, MkObjectC_SelfCreate, MkObjectC_SelfUnlink);
58 #if !META_STATIC_OVERWRITE
63 SetupThreadOBJ(IntPtr.Zero);
69 private IntPtr phdl = IntPtr.Zero;
70 protected IntPtr
pmkrt = IntPtr.Zero;
78 if (phdl == IntPtr.Zero)
throw new NullReferenceException($
"'{this.GetType().Name}' hdl is NULL");
110 if (obj ==
null || obj.phdl == IntPtr.Zero) {
111 throw new NullReferenceException($
"'{obj != null ? obj.GetType().Name : cls}' hdl is NULL");
117 if (obj ==
null)
return IntPtr.Zero;
127 internal void atomCreate (IntPtr obj) {
128 if (obj == IntPtr.Zero) {
131 }
else if (
Mk.MkObjCheck(obj)) {
133 mkrt =
Mk.MkRuntimeGetFromObj(obj);
135 Mk.MkRefIncrSelf(obj, (IntPtr) GCHandle.Alloc(
this), IntPtr.Zero);
137 Mk.MkRefIncrSelf(obj, (IntPtr) GCHandle.Alloc(
this,GCHandleType.Weak), IntPtr.Zero);
140 throw new MkSignatureExceptionC(
"MkObjectC");
145 internal void atomDeleteSoft () {
148 IntPtr
self =
Mk.CsGetSelfPtr(
Mk.MkObj(phdl));
149 if (
self != IntPtr.Zero) {
150 var gch = GCHandle.FromIntPtr(
self);
151 Mk.MkRefDecrWithoutSelf(
mkrt,phdl);
163 GC.SuppressFinalize(
this);
167 internal void atomDeleteHard () {
170 IntPtr
self =
Mk.CsGetSelfPtr(
Mk.MkObj(phdl));
171 if (
self != IntPtr.Zero) {
172 var gch = GCHandle.FromIntPtr(
self);
173 Mk.MkRefDecrWithUnlinkSelf(
mkrt,phdl);
185 GC.SuppressFinalize(
this);
189 protected static object atomObjNew (Type type, ConstructorInfo ctor, IntPtr obj) {
191 if (
self != IntPtr.Zero) {
193 return GCHandle.FromIntPtr(
self).Target;
195 object ret = GCHandle.FromIntPtr(
self).Target;
196 if (ret !=
null)
return ret;
199 return ctor.Invoke(
new Object[] {obj});
202 protected static object atomObjCreate (Type type, ConstructorInfo ctor, IntPtr obj) {
204 return ctor.Invoke(
new Object[] {obj});
207 protected static IntPtr
atomSelfCreate (ConstructorInfo ctor, IntPtr obj, IntPtr env) {
209 if (obj == IntPtr.Zero) {
212 ctor.Invoke(
new Object[] {obj});
219 return ctor.Invoke(
new Object[] {IntPtr.Zero});
223 var obj = (
MkObjectC) GCHandle.FromIntPtr(
self).Target;
225 obj.hdl = IntPtr.Zero;
227 if (obj !=
null) obj.hdl = IntPtr.Zero;
244 protected static ConstructorInfo
getCtor (Type type) {
245 Type[] types =
new Type[1];
246 types[0] = typeof(IntPtr);
247 ConstructorInfo constr = type.GetConstructor(
248 BindingFlags.Instance | BindingFlags.NonPublic,
null, CallingConventions.HasThis, types,
null
250 if (constr ==
null) {
251 throw new Exception(
"internal constructor '" + type.Name +
" (IntPtr)' not found.");
257 protected static string Name (IntPtr
mkrt, IntPtr obj) {
258 return Marshal.PtrToStringAnsi(
Mk.MkObjectToName(
mkrt,obj));
271 protected virtual void Dispose(
bool disposing)
276 if(phdl != IntPtr.Zero)
300 return phdl != IntPtr.Zero;
304 private static IntPtr MkObjectErrorCatchTmpl (IntPtr
mkrt, IntPtr
hdl, Exception exception, IntPtr callfunc) {
309 private string MkObjectToNameOfClassTmpl (IntPtr dummy) {
310 return this.GetType().Name;
313 private MkErrorE MkDbgDumpTmpl (IntPtr
mkrt, IntPtr
hdl, IntPtr message, IntPtr callfunc) {
314 return Mk.MkDbgDump(
mkrt,
hdl,message,callfunc);
319 return GetType().Name;
326 public partial class MkObjectC {
336 IntPtr __retVal__L =
Mk.MkObjectHandleResolve(IntPtr.Zero, netHdl);
361 Int32 __retVal__L =
Mk.MkObjectHandleGetOfType(
hdl);
375 Mk.MkObjectHandleDeleteByNetHdl(IntPtr.Zero, netHdl);
382 public partial class MkObjectC {
392 IntPtr __retVal__L =
Mk.MkObjectNext(
hdl);
398 IntPtr __retVal__L =
Mk.MkObjectPrev(
hdl);
406 IntPtr __retVal__L =
Mk.MkObjectInstances(IntPtr.Zero);
414 public partial class MkObjectC {
424 IntPtr __retVal__L =
Mk.MkObjectGetNull();
432 public partial class MkObjectC {
441 public void DbgDump (
string message =
"var", [CallerMemberName]
string callfunc =
null) {
442 IntPtr message_cstr = Marshal.StringToHGlobalAnsi(message);
443 IntPtr callfunc_cstr = Marshal.StringToHGlobalAnsi(callfunc);
444 MkErrorE errVal = MkDbgDumpTmpl(
mkrt,
hdl, message_cstr, callfunc_cstr);
445 Marshal.FreeHGlobal(message_cstr);
446 Marshal.FreeHGlobal(callfunc_cstr);
451 public void DbgL (
string message,
int debug = 0, [CallerMemberName]
string callfunc =
null,
int lvl = 0) {
453 IntPtr message_cstr = Marshal.StringToHGlobalAnsi(message);
454 IntPtr callfunc_cstr = Marshal.StringToHGlobalAnsi(callfunc);
456 Marshal.FreeHGlobal(message_cstr);
457 Marshal.FreeHGlobal(callfunc_cstr);
461 public void DbgLogC ([CallerMemberName]
string callfunc =
null) {
462 IntPtr callfunc_cstr = Marshal.StringToHGlobalAnsi(callfunc);
464 Marshal.FreeHGlobal(callfunc_cstr);
468 public void DbgO ([CallerMemberName]
string callfunc =
null) {
469 IntPtr callfunc_cstr = Marshal.StringToHGlobalAnsi(callfunc);
471 Marshal.FreeHGlobal(callfunc_cstr);
475 public void DbgSTACK (
int skip = 0,
int num = -1, [CallerMemberName]
string callfunc =
null) {
476 IntPtr callfunc_cstr = Marshal.StringToHGlobalAnsi(callfunc);
478 Marshal.FreeHGlobal(callfunc_cstr);
484 public static void DbgM (
string message,
int debug = 0, [CallerMemberName]
string callfunc =
null,
int lvl = 0) {
486 IntPtr message_cstr = Marshal.StringToHGlobalAnsi(message);
487 IntPtr callfunc_cstr = Marshal.StringToHGlobalAnsi(callfunc);
488 Mk.MkDbgM(IntPtr.Zero, message_cstr, debug, callfunc_cstr, lvl);
489 Marshal.FreeHGlobal(message_cstr);
490 Marshal.FreeHGlobal(callfunc_cstr);
497 public partial class MkObjectC {
506 public void LogC (
string message,
int debug = 0, [CallerMemberName]
string callfunc =
null) {
508 IntPtr message_cstr = Marshal.StringToHGlobalAnsi(message);
509 IntPtr callfunc_cstr = Marshal.StringToHGlobalAnsi(callfunc);
511 Marshal.FreeHGlobal(message_cstr);
512 Marshal.FreeHGlobal(callfunc_cstr);
516 public void LogHEX (
string callfunc,
byte[] data) {
517 IntPtr callfunc_cstr = Marshal.StringToHGlobalAnsi(callfunc);
518 var data_size = Marshal.SizeOf(data[0]) * data.Length;
519 var data_data = Marshal.AllocHGlobal(data_size);
520 Marshal.Copy(data,0,data_data,data_size);
523 Marshal.FreeHGlobal(callfunc_cstr);
527 public void Log (
MkObjectC fmtobj =
null,
int debug = 0, [CallerMemberName]
string callfunc =
null,
int lvl = 0) {
530 IntPtr callfunc_cstr = Marshal.StringToHGlobalAnsi(callfunc);
531 Mk.MkObjectLog(
mkrt,
hdl, fmtobj_hdl, debug, callfunc_cstr, lvl);
532 Marshal.FreeHGlobal(callfunc_cstr);
536 public void LogLong (
MkObjectC fmtobj =
null,
int debug = 0, [CallerMemberName]
string callfunc =
null,
int lvl = 0) {
539 IntPtr callfunc_cstr = Marshal.StringToHGlobalAnsi(callfunc);
540 Mk.MkObjectLogLong(
mkrt,
hdl, fmtobj_hdl, debug, callfunc_cstr, lvl);
541 Marshal.FreeHGlobal(callfunc_cstr);
545 public void LogShort (
MkObjectC fmtobj =
null,
int debug = 0, [CallerMemberName]
string callfunc =
null,
int lvl = 0) {
548 IntPtr callfunc_cstr = Marshal.StringToHGlobalAnsi(callfunc);
549 Mk.MkObjectLogShort(
mkrt,
hdl, fmtobj_hdl, debug, callfunc_cstr, lvl);
550 Marshal.FreeHGlobal(callfunc_cstr);
554 public void LogType (
MkObjectC fmtobj =
null,
int debug = 0, [CallerMemberName]
string callfunc =
null,
int lvl = 0) {
557 IntPtr callfunc_cstr = Marshal.StringToHGlobalAnsi(callfunc);
558 Mk.MkObjectLogType(
mkrt,
hdl, fmtobj_hdl, debug, callfunc_cstr, lvl);
559 Marshal.FreeHGlobal(callfunc_cstr);
566 public partial class MkObjectC {
576 IntPtr callfunc_cstr = Marshal.StringToHGlobalAnsi(callfunc);
577 IntPtr __retVal__L = MkObjectErrorCatchTmpl(
mkrt,
hdl, exception, callfunc_cstr);
578 Marshal.FreeHGlobal(callfunc_cstr);
584 IntPtr __retVal__L =
Mk.MkObjectToError(
mkrt,
hdl);
599 return Marshal.PtrToStringAnsi(__retVal__L);
607 IntPtr __retVal__L =
Mk.MkObjectToNameOfType(
mkrt,
hdl);
608 return Marshal.PtrToStringAnsi(__retVal__L);
614 return Marshal.PtrToStringAnsi(__retVal__L);
621 public partial class MkObjectC {
631 Int32 __retVal__L =
Mk.MkRefGet(
hdl);
639 public partial class MkObjectC {
667 IntPtr key_cstr = Marshal.StringToHGlobalAnsi(key);
668 Int32 __retVal__L =
Mk.MkSysHashI32(key_cstr, length);
669 Marshal.FreeHGlobal(key_cstr);
674 public static string SysHashSTR (
string key,
int length = -1) {
675 IntPtr key_cstr = Marshal.StringToHGlobalAnsi(key);
676 IntPtr __retVal__L =
Mk.MkSysHashSTR(key_cstr, length);
677 Marshal.FreeHGlobal(key_cstr);
678 return Marshal.PtrToStringAnsi(__retVal__L);
685 public partial class MkObjectC {
704 GC.SuppressFinalize(
this);
720 GC.SuppressFinalize(
this);
727 IntPtr ident_cstr = Marshal.StringToHGlobalAnsi(ident);
728 Mk.MkObjectDeleteCallbackCleanup(IntPtr.Zero, ident_cstr);
729 Marshal.FreeHGlobal(ident_cstr);
735 IntPtr ident_cstr = Marshal.StringToHGlobalAnsi(ident);
736 IntPtr callback_ptr = callback ==
null ? IntPtr.Zero : (IntPtr)GCHandle.Alloc(
new MkCall(callback));
737 if (callback_ptr == IntPtr.Zero) fCall =
null;
738 IntPtr filter_cstr = Marshal.StringToHGlobalAnsi(filter);
739 MkErrorE errVal =
Mk.MkObjectDeleteCallbackSetup(IntPtr.Zero, ident_cstr, fCall, callback_ptr, ObjectDeleteFree, filter_cstr);
740 Marshal.FreeHGlobal(ident_cstr);
741 Marshal.FreeHGlobal(filter_cstr);
MkErrorC - the class known as err or error is used to create and manage an error message …
static void Check(IntPtr ctx, MkErrorE err)
static MkErrorC MkErrorC_ObjNew(IntPtr hdl)
C-API: MkExceptionC_C_API - MkExceptionC - The default-exception of the Programming-Language-Micro-...
static IntPtr Catch(IntPtr mkrt, IntPtr expobj, Exception exception, IntPtr callfunc)
convert an Target-Programming-Language (TPL) exception into an MkErrorC …
MkObjectC - class known as obj or object is used as base-class type for a Programming-Language-Micro-...
static object atomObjNew(Type type, ConstructorInfo ctor, IntPtr obj)
static IntPtr getOBJ_null_allow(MkObjectC obj)
static object atomObjCreate(Type type, ConstructorInfo ctor, IntPtr obj)
static void atomSelfUnlink(IntPtr self, IntPtr env)
static string Name(IntPtr mkrt, IntPtr obj)
C#: string obj.ToName() → C-API Info-Slot - returns brief information about the obj as a string
delegate void MkObjectDeleteSCB(string typeName, int typeHdl, int objHdl)
implements the csmkkernel API object: public version from MkObjectDeleteSCB as method
virtual void Dispose(bool disposing)
Support IDisposable.
static object atomSelfNull(ConstructorInfo ctor)
static IntPtr getOBJ(string cls, MkObjectC obj)
static MkObjectC MkObjectC_ObjNew(IntPtr hdl)
static ConstructorInfo getCtor(Type type)
static IntPtr atomSelfCreate(ConstructorInfo ctor, IntPtr obj, IntPtr env)
MkRuntimeC - The class known as mkrt or runtime is the main csmkkernel application environment …
static Mk.MkBinaryR MkBinaryCreate(long size, IntPtr data)
static IntPtr MkRuntimeGet()
static Int32 MkObjectHandleGet(IntPtr mkrt, IntPtr obj)
static unsafe IntPtr CsGetSelfPtr(IntPtr hdl)
#define MK_NULL
The Programming-Language-Micro-Kernel (PLMK) NULL value as null in C# …
MkErrorE
collection for the different error-codes …
MkObjectC Prev()
C#: MkObjectC obj.Prev() → C-API get previous instance from linked-list of MkObjectS type
static void HandleDeleteByNetHdl(Int32 netHdl)
C#: [static] MkObjectC.HandleDeleteByNetHdl(Int32 netHdl) → C-API Handle-Delete-Slot - delete a ...
static MkObjectC GetNull()
C#: [static] MkObjectC MkObjectC.GetNull() → C-API Null-Slot - return a MkObjectC typed NULL ins...
static MkObjectC Instances()
C#: [static] MkObjectC MkObjectC.Instances() → C-API get head-instance from linked-list of MkObj...
MkObjectC Next()
C#: MkObjectC obj.Next() → C-API get next instance from linked-list of MkObjectS type
static MkObjectC HandleResolve(Int32 netHdl)
C#: [static] MkObjectC MkObjectC.HandleResolve(Int32 netHdl) → C-API Handle-Resolve-Slot - retur...
void HandleDelete()
C#: netObj.HandleDelete() → C-API Handle-Delete-Slot - delete a netObj from handle-storage …
Int32 HandleGet()
C#: Int32 obj.HandleGet() → C-API Handle-Get-Slot - returns a export-hdl to the MkObjectC useab...
bool HandleExists()
C#: bool obj.HandleExists() → C-API check if obj has already a handle defined…
Int32 HandleGetOfType()
C#: Int32 obj.HandleGetOfType() → C-API Export-Slot - returns typeHdl of the obj .
Int32 HandleGetOr0()
C#: Int32 obj.HandleGetOr0() → C-API return export-hdl or 0 in not created…
void DbgL(string message, int debug=0, [CallerMemberName]string callfunc=null, int lvl=0)
C#: fmtobj.DbgL(string message, int debug = 0, [CallerMemberName]string callfunc = null,...
void DbgSTACK(int skip=0, int num=-1, [CallerMemberName]string callfunc=null)
C#: fmtobj.DbgSTACK(int skip = 0, int num = -1, [CallerMemberName]string callfunc = null) → C-API ...
void DbgDump(string message="var", [CallerMemberName]string callfunc=null)
C#: obj.DbgDump(string message = "var", [CallerMemberName]string callfunc = null) → C-API debug...
static void DbgM(string message, int debug=0, [CallerMemberName]string callfunc=null, int lvl=0)
C#: [static] MkObjectC.DbgM(string message, int debug = 0, [CallerMemberName]string callfunc = null,...
void DbgO([CallerMemberName]string callfunc=null)
C#: obj.DbgO([CallerMemberName]string callfunc = null) → C-API debug: write the object-details ...
void DbgLogC([CallerMemberName]string callfunc=null)
C#: obj.DbgLogC([CallerMemberName]string callfunc = null) → C-API debug: write a short-obj-summ...
void LogLong(MkObjectC fmtobj=null, int debug=0, [CallerMemberName]string callfunc=null, int lvl=0)
C#: obj.LogLong(MkObjectC fmtobj = null, int debug = 0, [CallerMemberName]string callfunc = null,...
void LogC(string message, int debug=0, [CallerMemberName]string callfunc=null)
C#: fmtobj.LogC(string message, int debug = 0, [CallerMemberName]string callfunc = null) → C-API ...
void LogHEX(string callfunc, byte[] data)
C#: fmtobj.LogHEX(string callfunc, byte[] data) → C-API log binaray data as HEX into the MkLogF...
void LogType(MkObjectC fmtobj=null, int debug=0, [CallerMemberName]string callfunc=null, int lvl=0)
C#: obj.LogType(MkObjectC fmtobj = null, int debug = 0, [CallerMemberName]string callfunc = null,...
void LogShort(MkObjectC fmtobj=null, int debug=0, [CallerMemberName]string callfunc=null, int lvl=0)
C#: obj.LogShort(MkObjectC fmtobj = null, int debug = 0, [CallerMemberName]string callfunc = null,...
void Log(MkObjectC fmtobj=null, int debug=0, [CallerMemberName]string callfunc=null, int lvl=0)
C#: obj.Log(MkObjectC fmtobj = null, int debug = 0, [CallerMemberName]string callfunc = null,...
MkErrorC ErrorCatch(Exception exception=null, [CallerMemberName]string callfunc=null)
C#: MkErrorC obj.ErrorCatch(Exception exception = null, [CallerMemberName]string callfunc = null) →...
bool IsNull()
C#: bool obj.IsNull() → C-API ckeck if the object is null
MkErrorC ToError()
C#: MkErrorC obj.ToError() → C-API Error-Slot - return an error-object pre initialized with obj...
string ToNameOfType()
C#: string obj.ToNameOfType() → C-API Type-Slot - returns the LibMkKernel-Type-Name of the obj ...
string ToName()
C#: string obj.ToName() → C-API Info-Slot - returns brief information about the obj as a string
override string ToString()
C#: string inst.ToString() → C-API String-Slot - returns the string representation of the inst ...
string ToNameOfClass()
C#: string obj.ToNameOfClass() → C-API Class-Slot - returns the C#-Class-Name of the obj as str...
static int SysHashI32(string key, int length=-1)
MkSysHashI32
int SysGetPid()
MkSysGetPid
static string SysHashSTR(string key, int length=-1)
MkSysHashSTR
void SysKill(int pid, int signal)
MkSysKill
static void DeleteCallbackCleanup(string ident)
C#: [static] MkObjectC.DeleteCallbackCleanup(string ident) → C-API cleanup the DeleteCallback in...
void Delete()
C#: [destructor] obj.Delete() → C-API Delete-Slot - delete an instance.
void Dispose()
C#: [destructor] obj.Dispose() → C-API Dispose-Slot - untie the connection between the Native-C#...
static void DeleteCallbackSetup(string ident, MkObjectDeleteSCB callback=null, string filter=null)
C#: [static] MkObjectC.DeleteCallbackSetup(string ident, MkObjectDeleteSCB callback = null,...
enum MkErrorE(* MkObjectDeleteCallF)(MK_RT mkrt, MK_OBJN const obj, MK_STRN const typeName, MK_HDL const typeHdl, MK_HDL const objHdl, MK_CBP const __data__)
static callback to delete an obj …
static int DebugGet()
C#: [static] int MkRuntimeC.DebugGet() → C-API get the MkRuntimeS::debug value …
MkErrorE
→ C-API: MkErrorE → C-API: MkErrorE