libmkkernel 9.0
Loading...
Searching...
No Matches
libmkkernel

The Programming-Language-Micro-Kernel Project.

SYNOPSIS

The libmkkernel package is the implementation of the Programming-Language-Micro-Kernel into the target-language C.

link: -Lpath -lmkkernel or automake: LDADD = libmkkernel.la

The libmkkernel package is a composition of multiple classes defining the Programming-Language-Micro-Kernel:

object description
Mk the namespace with all libmkkernel specific definitions
MkAttribute(…) the interface to access the package specific attribute
MkClassAttribute(…) the interface to access the class specific attribute
MkClassAttribute(Instance,…) the interface to access the instance specific attribute

To access all features without Mk prefix use:

#include "kernel_mk.h"

Using the libmkkernel package …
Using automake/libtool the MkKernel library have to be linked with the executable/library, this is done with:

‍LDADD = path/to/libmkkernel.la

or

‍mylib_la_LIBADD = path/to/libmkkernel.la

Example from acmds/Makefile.am using libmkkernel.la and libmqmsgque.la:
atool_SOURCES = atool.c ajoin.c acut.c asort.c asplit.c optionL.c optionL.h
atool_CFLAGS = -Wconversion -Werror -Wstrict-prototypes $(libmqmsgque_CPPFLAGS)
atool_LDFLAGS = $(UBSAN) -no-undefined
atool_LDADD = $(libmqmsgque_shared_LIBADD)

INDEX

BASICS
Philosophy , Package , ManagedObject , PrimitiveTypes , StorageManagement ,
CLASS
MkKernel PACKAGE , MkObjectC , MkBufferC , MkBufferStreamC , MkBufferListC , MkLogFileC , MkErrorC , MkRuntimeC
MISC
BinaryObject, Examples

INTRODUCTION

C-API: MK_C_API - Namespace for the LibMkKernel API …

The LibMkKernel API …

PHILOSOPHY

The MkKernel project is an infrastructure that link an library-item with a Target-Programming-Language using the Programming-Language-Micro-Kernel object-interface. The goal is a programming language independent interface between a C library and a target language.

Philosophy
Write Once → Run Everywhere

The library-item is a c-api for a library available as c-header-file.
The library-item is mapped into a Target-Programming-Language using a language that is supported by the Programming-Language-Micro-Kernel.
Supported Languages are: (C,C++,C#,VB.NET,Java,Python,Ruby,Perl,PHP,Tcl or GO)

Strategy
It takes 4 years to write a programming-language, but it only takes 4 weeks to insert a micro-kernel.

The library-item is connected to the Target-Programming-Language using an api-layer generated by the token-stream-compiler of the Programming-Language-Micro-Kernel.

Conclusion
The MkKernel-Project is used to manage a collection of library-items using an API that is available in all major programming-languages.

PROGRAMMING

The MkKernel is responsible for:

  • providing the startup and cleanup API
  • providing the memory and caching API
  • providing the logging, debugging and error API
  • providing basic objects like buffer, list, stream, logging, runtime and error

The LibMsgque is separted into three programming-layers:

  1. The foundation-layer, used by the MkKernel library programmer
  2. The kernel-layer, used by the Programming-Language-Micro-Kernel programmer
  3. The implementation-layer, used by the target-language programmer
foundation-layer
The foundation-layer implement the libmkkernel library and is also responsible for the quality-target of the entire project.
  • establishing and managing the library-items
  • memory-management and garbage-collection
  • error-handling
  • logging and debugging
  • written in plain C
kernel-layer
The kernel-layer implement the Programming-Language-Micro-Kernel and is also responsible to generate and maintain the target-language-API source-code.
  • implementation of the managed-object technology
  • implementation of the token-stream-compiler technology
  • written in plain C, TCL and the target-language-API
implementation-layer
The implementation-layer is the API used by the target-language-programmer.
  • written in plain target-programming-language (C,C++,C#,VB.NET,Java,Python,Ruby,Perl,PHP,Tcl or GO)
Target
!! This documentation describe the implementation-layer and target the C programmer. !!

PACKAGE

C-API: MkKernel_C_API - The package is the toplevel structure of the Programming-Language-Micro-Kernel

The libmkkernel package is loaded with:

link: -Lpath -lmkkernel or automake: LDADD = libmkkernel.la

and is a composition of one or more class-item.

The libmkkernel package add the following public classes into MkObjectC_C_API :

Object C-Type Description
MkObjectC MK_OBJ The MkObjectC object known as obj or object is used as base-object type for a managed-object
MkBufferC MK_BUF The MkBufferC object known as buf or buffer is used to create and manage dynamic, generic, mixed typed data. …
MkBufferStreamC MK_BUS The MkBufferStreamC object known as bus or stream is a subclass of MkBufferC used for package-based-io
MkBufferListC MK_BFL The MkBufferListC object known as bfl or buffer-list is used to create and manage a list of MkBufferC
MkLogFileC MK_LFL The MkLogFileC object known as lfl or log-file is used to control … the target of the logging-output.
MkErrorC MK_ERR The MkErrorC object known as err or error is used to create … and manage an error message …
MkRuntimeC MK_RT The MkRuntimeC class known as mkrt or runtime is the main libmkkernel application environment …

The libmkkernel package add the following public types into MkObjectC_C_API :

    ABSTRACT: MkTypeSTT (TypeTypeType = type of a TypeType)
    |
    |- ABSTRACT: MkDefTypeSTT (TypeType = type of a Type)
       |
       |- MkObjectST, MkLogFileST, MkBufferListST,
       |- MkErrorPanicST, MkErrorIgnoreST, MkErrorPrintST, MkErrorDefaultST, MkErrorST
       |
       |- ABSTRACT: MkBufferST
          |- FINAL: MkBuffer64ST, MkBuffer256ST, MkBuffer1024ST
          |- ABSTRACT: MkBufferStreamST
             | FINAL: MkBufferStream64ST, MkBufferStream256ST, MkBufferStream1024ST, MkBufferStream16384ST

MANAGED OBJECT

C-API: MkObjectC_C_API - The MkObjectC object known as obj or object is used as base-object type for a managed-object

libmqmsgque is also called as Programming-Language-Micro-Kernel. libmqmsgque is like a programming-language without syntax but using the Target-Programming-Language (in our case C) of the Micro-Kernel as runtime environment.

Integration
To operate as a Micro-Kernel a maximum integration into the Target-Programming-Language is available.

This integration is done using the managed-object-technology.

Managed-Object
A managed-object is a piece of C-Code able to act as a native datatype in all Target-Programming-Languages supported.

The managed object supports low level integration features descripted in MkObjectS :

  • object identification based on signatures
  • reference counting
  • management of the self object pointer for the target-language
  • object-type specific features provided with MkTypeS

In the implementation-layer of libmkkernel only the public-features of the MkObjectC are visible to the programmer.

MANAGED OBJECT TYPES

In Programming-Language-Micro-Kernel everything is a struct, there are type-struct(s) and instance-struct(s):

  1. A type-struct is derived from MkTypeS and provide type-properties (static-properties) and type-methods (slots)
  2. A instance-struct is derived from MkObjectS and provide instance-properties and instance-methods

An instance is full defined by min 4 structs and optional base-structs :

  1. instance-struct -> base-struct(s) -> object-struct (MkObjectS)
  2. instance-type -> base-type(s) -> type-type (MkTypeS)

The following naming-convention exist for the C-API (example: MkBufferC)

name definition
MkBufferS instance-struct → This is the main-struct to define an instance
MkBufferST instance-type as specific-instance-type
MkBufferSTT instance-type as common-instance-type (cast from MkBufferST into MkTypeS) …
MkBufferC_T instance-type as specific-instance-type, useable in a class-macro as: class##_T
MkBufferC_TT instance-type as common-instance-type, useable in a class-macro as: class##_TT
MK_BUF class-shortcut for struct MkBufferS *, all shortcut using the XX_YYY syntax (only for public API) …
MK_BUFR reference-shortcut for struct MkBufferS, all shortcut using the XX_YYYR syntax (only for public API) …
MkBufferCR instance-struct-reference same as struct MkBufferS, useable in a class-macro as: class##R
MkBufferCT_X(instance) cast from an instance into the specific-instance-type
MkBufferCTT_X(instance) cast from an instance into the common-instance-type
MkBufferCT_TT(typ) cast from an common-instance-type into an specific-instance-type
MkBufferCTT instance-type as common-instance-type for MkBufferC in the target-programming-language (C,C++,C#,VB.NET,Java,Python,Ruby,Perl,PHP,Tcl or GO)
MkBufferCT instance-type as specific-instance-type for MkBufferC in the target-programming-language (C,C++,C#,VB.NET,Java,Python,Ruby,Perl,PHP,Tcl or GO)

the struct(s) are defined as:

  1. The instance-type is a type-struct able to create an instance.
  2. The type-type is a type-struct not able to create an instance but used as super-class for a instance-type and the base-type
  3. The base-type is a type-struct and used to initialize the type-properties and type-methods (called slots).
    An instance provide methods and slots. A slot is a method predefined in the type like constructor. A list of all slots are defined in MkTypeS.

    example MkBufferC : MkTypeS -> MkDefTypeS -> MkObjectST -> MkBufferST

  4. The instance is a link between the instance-struct, the base-struct the instance-type and the base-type.

    example MkBufferC : MkBufferST -> MkBufferS <- MkObjectS

  5. The base-struct is used to provide the base-instance-properties
    struct MyBaseStruct {
    union {
    struct MkObjectS obj
    } super;
    // MyBaseStruct-properties
    }
    struct MyInstanceStruct {
    union {
    struct MkObjectS obj
    struct MyBaseStruct bse
    } super;
    // MyInstanceStruct-properties
    }
    object header …
    Definition kernel_mk.h:4442

To use the specific-instance-type as argument to a function or as property in a struct the common-instance-type of type MkTypeS is used. To cast a specific-instance-type into a common-instance-type use:

  1. the path: type->super.typ
  2. the shortcut: MkTYP(type)->XYZ (pointer) or MkTYP_R(type).XYZ (reference)

To get the common-instance-type from the instance use:

  1. the path: instance->super.obj.type
  2. the shortcut: MkOBJ(instance)->type (pointer) or MkOBJ_R(instance).type (reference)

To get the base-type from the instance-type use:

  1. the path: instance->super.obj.type->base
  2. the shortcut: MkOBJ(instance)->type->base (pointer) or MkOBJ_R(instance).type->base (reference)

The predefined instance-type is an instance of the default-instance-type (MkDefTypeS) …

struct MkRuntimeS {
...
struct MkDefTypeS _MkBufferST;
...
}
BASE-TYPE all non specific types
Definition kernel_mk.h:4885
The MkRuntimeS provide a per-thread environment for LibMkKernel …

The properties and slots of the instance-type are predefined by the base-type and may be overwritten …

MkInstanceTypeInit ( MkBufferC, MkObjectC ) ;
#define MkBufferST
instance-type as specific-instance-type …
Definition kernel_mk.h:6255
MK_EXTERN void MkBufferLog_RT(MK_RT const mkrt, MK_BUFN const buf, MK_OBJN fmtobj, MK_DBG const debug, MK_STRN const callfunc, MK_INT const lvl)
log the MkBufferC …
MK_EXTERN void MkBufferReset_RT(MK_RT const mkrt, MK_BUF const buf) MK_RT_ATTR_HDL
reset a MkBufferC to the length zero …
MK_EXTERN MK_STRN MkBufferToString_RT(MK_RT const mkrt, MK_BUFN const buf) MK_RT_ATTR_HDL
get the string representation of the buf …
MK_EXTERN MK_BUF MkBufferCopy_RT(MK_RT const mkrt, MK_BUF const buf, MK_BUFN const srce) MK_RT_ATTR_HDL
copy the MkBufferC from srce to dest …
MK_EXTERN void MkBufferDelete_RT(MK_RT const mkrt, MK_BUF const buf) MK_RT_ATTR_HDL
Destructor - delete a MkBufferC instance …
MK_EXTERN MK_BUF MkBufferMerge_RT(MK_RT const mkrt, MK_BUF const buf) MK_RT_ATTR_HDL
Merge-Constructor - create a new MkBufferC as a merge from an existing object …
MK_EXTERN MK_BUF MkBufferDup_RT(MK_RT const mkrt, MK_BUFN const buf) MK_RT_ATTR_HDL
Dup-Constructor - create a new MkBufferC instance as copy from an existing MkBufferC instance
MK_OBJ(* MkMergeF)(MK_RT const mkrt, MK_OBJ const obj)
Definition kernel_mk.h:4603
MK_OBJ(* MkCopyF)(MK_RT const mkrt, MK_OBJ const obj, MK_OBJN const src)
Definition kernel_mk.h:4604
void(* MkLogF)(MK_RT const mkrt, MK_OBJN const obj, MK_OBJ fmt, MK_INT const debug, MK_STRN const prefix, MK_INT const lvl)
Definition kernel_mk.h:4612
MK_OBJ(* MkDupF)(MK_RT const mkrt, MK_OBJ const obj)
Definition kernel_mk.h:4601
void(* MkDestructorF)(MK_RT const mkrt, MK_OBJ const obj)
Definition kernel_mk.h:4600
MK_STRN(* MkToStringF)(MK_RT const mkrt, MK_OBJN const obj)
Definition kernel_mk.h:4614
#define MkTYP_R(x)
cast a known-managed-object into an MkTypeS reference
Definition kernel_mk.h:4879
void(* MkResetF)(MK_RT const mkrt, MK_OBJ const obj)
Definition kernel_mk.h:4605

The following relationship between the three different struct exists:

  1. The instance-type and the type-type have the super-class MkTypeS and the instance not.
  2. The type-type is a super-class of an instance-type.
  3. The instance-type has the 3 attributes MkTypeS::objsig, MkTypeS::objmask and MkTypeS::objsize defined, the type-type not.
  4. The instance has access to the instance-type using the cast (example MkBufferCT_X(instance))
  5. The instance-type has access to the base using MkTypeS::base and to the type using MkObjectS::type.

MANAGED OBJECT PROGRAMMING

The Programming-Language-Micro-Kernel using the manged-object technology to create a class-system with MkObjectS as the root-class.
The MkObjectS is the FIRST and REQUIRED attribute in the super-union.

  1. The instance-type is a composition of one or more super-classes and instance-attributes.
  2. All super-classes are grouped into a annonymous union called super.
  3. Only the super-class struct MkObjectS obj is required for object-management, all other super-classes are optional.
  4. The name of the super-class like obj or buf is fix and is required by tool-macros and functions.
// instance-type: MyFeatureS
struct MyStructS {
// instance super-class
union {
struct MkObjectS obj; // 'object' instance-type (required)
struct MkBufferS buf; // 'buffer' instance-type (optional,example)
} super;
// instance attribute
int myInt; …
}
The ABSTRACT-CLASS used to store a native-type-data-item defined by PRIMITIVE TYPE …
Definition kernel_mk.h:6194

A class is a link (MkObjectS::type) between:

instance-type(example: MkBufferS)
type-type(example: MkBufferSTTMkDefTypeSTTMkTypeSTT)

A class is identified by the signature (MkObjectS::signature) located at the FIRST int32 bits of the class-instance.

  • The managed-object supports one or more super-class using a union with struct MkObjectS obj as the first attribute in the union.
  • The union is required because the managed-object share the memory with the super-class.

There are two possible "cast" operations on a managed-object :

  1. A "cast" from a pointer of unknown origin (example: MK_MNG).
  2. A "cast" from an already known managed object pointer (example: MK_BUS).

In (1) the "cast" is checked using the "signature" and in (2) the "cast" is simply resolved within the "super-class".

Example: "cast" a pointer into a MkBufferS

  • "cast" from an unknown pointer: MK_BUF ret = MkBuf(ptr);
    • This "cast" is called an up-cast because you're upgrading the pointer (getting more information).
    • This "cast" checks the MkObjectS::signature to ensure that ptr is a valid object.
    • This "cast" is checked at runtime.
  • "cast" from a managed pointer: MK_BUF ret = MkBUF(ptr);
    • This "cast" is called a down-cast because you downgrading the pointer (lose some information).
    • This "cast" uses the super-union to just return a pointer that is already available.
    • This "cast" is checked at compile time.
  • To put it simply: MkBuf ≠ MkBUF

Example from kernel_mk.h A full class example from MkBufferS

struct MkBufferS {
// BEGIN-MkBufferS-super - created by 'cls_MqS.tcl -i NHI1_HOME/theKernel/libmkkernel/.libmkkernel.meta' - DO NOT change
union {
struct MkObjectS obj; // base CLASS \MkObjectS
} super;
// END-MkBufferS-super - created by 'cls_MqS.tcl -i NHI1_HOME/theKernel/libmkkernel/.libmkkernel.meta' - DO NOT change
// instance attributes
struct {
MK_NUM cursize;
enum MkTypeE type;
} var;
// instance storage
struct {
union MkBufferU first;
bool doBufferFree;
} storage;
struct ilsS {
} ils;
#define MkBufferS_ils_size 0
};
// BEGIN-MkBufferS-ClassDef - created by 'cls_MqS.tcl -i NHI1_HOME/theKernel/libmkkernel/.libmkkernel.meta' - DO NOT change
// Signature --------------------------------------------------------------
#define MkBufferC_SIGNATURE (MkObjectC_SIGNATURE ^ (1u<<10))
#define MkBufferC_MASK (((1u<<22)-1)<<10)
// Signature --------------------------------------------------------------
#define MkBufferC_X2buf(x) (x)
#define MkBufferC_X2obj(x) MkOBJ(x)
// TypeDef --------------------------------------------------------------
__parser__(ignore) typedef struct MkBufferS MkBufferCR;
__parser__(ignore) typedef const struct MkBufferS MkBufferCNR;
#define MkBufferC_T (&MK_RT_REF._MkBufferC_T)
#define MkBufferC_TT (MkTYP(MkBufferC_T))
#define MkBufferST MkBufferC_T
#define MkBufferSTT (MkTYP(MkBufferST))
#define MkBufferC_type MK_BUF
#define MkBufferCT_X(instance) ( (struct MkDefTypeS *) (MkOBJ_R(instance).type) )
#define MkBufferCTT_X(instance) (MkOBJ_R(instance).type)
#define MkBufferCT_TT(typ) ( (struct MkDefTypeS *) (typ) )
#define MkBufferC_NS MK
#define MkBufferCTT MkBufferCTT
#define MkBufferCT ( (struct MkDefTypeS *) MkBufferCTT )
// TypeCheck --------------------------------------------------------------
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wattributes"
__parser__(class=MkBufferC,static,hide)
return MkSanitizeCheck(MkBufferC,mng);
}
#pragma GCC diagnostic pop
#define MkBufferC_Check(mng) MkBufCheck(mng)
// ObjectCast --------------------------------------------------------------
__parser__push__(prefix=Cast);
__parser__(class=MkBufferC,hide,static)
META_ATTRIBUTE_SANITIZE
return (MkBufCheck(mng) ? (MK_BUF)mng : NULL);
}
__parser__(ignore)
META_ATTRIBUTE_SANITIZE
return (MkBufCheck(mng) ? (MK_BUFN)mng : NULL);
}
#define MkBufRaise(_buf) if (!_MkCheckX(MkBufferC,_buf)) { \
MkErrorSetC_1E("'MkBufferC' hdl is NULL"); \
goto error ; \
}
#define MkBUF_R(x) (*(x)).super.buf
#define MkBUF(x) (&MkBUF_R(x))
// END-MkBufferS-ClassDef - created by 'cls_MqS.tcl -i NHI1_HOME/theKernel/libmkkernel/.libmkkernel.meta' - DO NOT change
bool MkBufCheck(MK_MNGN mng)
check MkBufferS%->Mk{ObjectS::signature} …
Definition kernel_mk.h:6286
MK_BUF MkBuf(MK_MNG mng)
cast a unknown-object into an MkBufferS pointer or NULL if not possible
Definition kernel_mk.h:6305
MK_BUFN MkBufN(MK_MNGN mng)
(const) cast a unknown-object into an MkBufferS pointer or NULL if not possible
Definition kernel_mk.h:6312
#define mk_inline
Definition kernel_mk.h:2144
MkTypeE
basic data-types supported by Programming-Language-Micro-Kernel …
Definition kernel_mk.h:3299
const MK_PTRB * MK_MNGN
const - a managed object pointer, datatype will be checked on runtime
Definition kernel_mk.h:2731
int32_t MK_NUM
array size data-type ('num' items in array …
Definition kernel_mk.h:2679
MK_PTRB * MK_MNG
managed object pointer, datatype will be checked on runtime
Definition kernel_mk.h:2728
unsigned char MK_BINB
byte-array type data-type
Definition kernel_mk.h:2706
#define MkSanitizeCheck(_root, _m)
Definition kernel_mk.h:4412
#define MkBufferS_ils_size
ILS size
Definition kernel_mk.h:6217
#define __parser__pop__
Definition kernel_mk.h:318
#define __parser__push__(...)
Definition kernel_mk.h:317
#define __parser__(...)
Definition kernel_mk.h:314
MK_NUM offset
offset from start of MkBufferS to the start of MkBufferS::ils_data
Definition kernel_mk.h:6215
MK_NUM size
size of the MkBufferS::ils_data
Definition kernel_mk.h:6214
struct MkObjectS obj
Definition kernel_mk.h:6197
union MkBufferU first
POINTER to native data representation (ILS or malloc)
Definition kernel_mk.h:6208
struct MkBufferS::ilsS ils
ILS = predefined storage used for MkBufferS::storage->first.
struct MkBufferS::@4 storage
MK_BINB ils_data[MkBufferS_ils_size]
ILS storage
Definition kernel_mk.h:6218
struct MkBufferS::@3 var
variable part of the instance-data
union MkBufferS::@2 super
MK_NUM size
the size of the data-segment
Definition kernel_mk.h:6209
bool doBufferFree
should the data be freed? -> example: pBufferRefInit
Definition kernel_mk.h:6210
a union for all data items supported by MkBufferS …
Definition kernel_mk.h:3435

PRIMITIVE TYPE

C-API: MkKernel_PrimitiveType_C_API - a collection of all native-data-types supported by MkBufferC

The data send from one package-item to an other package-item is focused on speed and usability. By default the data is send as binary, only if the endian changes or a string representation is required an additional transformation is done.
The data send from one package-item to an other package-item is limited to a collection of specific types, based on native C data types.
An libmkkernel-API command with a focus on a specific type is using a type-postfix, for example MqReadC read a (C=string) data from the read-package.
In the documentation the type-item (TT) is a synonym for a (Y,O,S,I,W,F,D,B,C,L,U) type-item.

The following native-type identifier are available:

TT native comment
Y MK_BYT 1 byte signed character
O MK_BOL 1 byte boolean value using MK_YES or MK_NO
S MK_SRT 2 byte signed short
I MK_INT 4 byte signed integer
W MK_WID 8 byte signed long long integer
F MK_FLT 4 byte float
D MK_DBL 8 byte double
B MK_BINN unsigned char array used for binary data
C MK_STR string data using a \0 at the end

The following compose-type identifier's are available:

TT native comment
U MK_BUF buffer-item that can hold any single typed item from above
L MK_BFL buffer-list that can hold many buffer-item from above

Every native-data-type is encapsualted into a MkBufferC. A MkBufferC is type safe, this mean that every read to a MkBufferC have to match the data-type of the previous write. One exception is available, the cast from and to the MK_STR data-type (TYPE=C) is allowed.

Sending data mean sending one ore more MkBufferC from one package-item to an other package-item. The sender is using a MqSendTT command to put data as MkBufferC into an send-data-package and the reveiver is using a MqReadTT command to retrieve the data from the read-data-package.

CLASS TYPE

C-API: MkKernel_ClassType_C_API - a collection of types using the META class definition …

TODO

POINTER TYPE

C-API: MkKernel_PointerType_C_API - a collection of types allocates as array of data and supported by MkBufferC

For native type support read: MkKernel_PrimitiveType_C_API

The pointer-type is part of the native-type and usually support the size argument to propper allocate storage.

The following pointer-type identifier is available in MkBufferS:

TT type const type comment
B MK_BIN MK_BINN unsigned char array used for binary data (MK_BINN)
C MK_STR MK_STRN string data using a \0 at the end (MK_STR)

STORAGE MANAGEMENT

C-API: MkKernel_Storage_C_API - Storage Management …

Storage management is used in libmkkernel to provide temporary storage. It is a common design pattern that libmkkernel only returns a reference to the Internal-Temporary-Storage (ITS), so the Internal-Active-Storage (IAS) is not returned to the external end user. The ITS is a storage that is only used as a return value and nothing else. The temporary in ITS refers exclusively to the current state of the storage and not to the lifespan of the storage, the ITS is only allocated once at startup and then used again and again, similar to the static storage in C.

Internal libmkkernel distinguishes three different storage sources:

Context-Local-Storage (CLS)
CLS is tied to a specific MqContextC.
Example: the MqReadU returns a reference to an internal MkBufferC.
Funktion-Local-Storage (FLS)
FLS is used as the local temporary storage, usually as thread-local-storage, of a function-return-value.
Example: the MqReadL returns a MkBufferListC which is filled with multiple MkBufferC.
Runtime-Local-Storage (RLS)
RLS is used as global storage per RunTime instance.
Example: the MkErrorC only exists ONCE per runtime.

The CLS and FLS have the same visibility to the end user and are explained together as FLS.
The RLS is not mentioned in this documentation section because the RLS is more internal than CLS and FLS.

The end-user uses a FLS reference like a normal local C variable but with the following restriction:

  1. The value of the variable is a reference to the FLS storage belonging to the method that returned the reference.
  2. A FLS storage only ever exists once in a thread, which means that the FLS storage of a reference is overwritten if the FLS storage is used a second time in the same context.
  3. A context is, for example, a coherent block of code such as in a "service callback". A coherent context is broken if the same method that returned the original FLS as a result is called a second time or if a method is called that uses the "event loop".
  4. FLS storage must NOT be released by the end user, the Programming-Language-Micro-Kernel always ensures that the storage management of libmkkernel and the target-language is synchronized.
  5. If a FLS reference is added to another reference and this reference is also managed by the Programming-Language-Micro-Kernel, the Programming-Language-Micro-Kernel automatically ensures that the storage management is coherent, which means that the end user does not have to do anything.
  6. The FLS reference can be updated. This means that the FLS storage is being updated because the reference owner (usually a local variable) temporarily owns the FLS storage.

The "Dup" (duplicate) function is used to convert a temporary FLS variable into a global storage. The global storage is managed by the end user and may have to be released depending on the target programming language.

Example from server.c "ReadL" overwrite previous "ReadL"

static enum MkErrorE Ot_BFL2 ( MQ_CALLBACK_SERVICE_CALL_ARGS )
{
  MK_BFL tmp1 = MqReadL_e(mqctx);                           // "tmp1" is now a reference to the FLS storage of "ReadL"
  MK_BFL tmp2 = MqReadL_e(mqctx);                           // ERROR: the "tmp2" is using a SHARED reference with "tmp1"
  MqSend_E(mqctx, "R", "LL", tmp1, tmp2);                   // ERROR: "$tmp1" and "$tmp2" are the SAME values
  return MK_OK;
error:
  return MqSendRETURN (mqctx);
}

Example from server.c "ReadL" overwrite previous "ReadL" even in an "Event-Loop"

static enum MkErrorE pBFL3 ( MQ_CALLBACK_SERVICE_CALL_ARGS ) {
  __attribute__((unused))
  MK_BFL tmp2 = MqReadL_e(mqctx);                           // ERROR: the "tmp2" is using a SHARED reference with "tmp1"
  return MK_OK;
error:
  return MkErrorStack_1X(mqctx);
}
static enum MkErrorE Ot_BFL3 ( MQ_CALLBACK_SERVICE_CALL_ARGS )
{
  MK_BFL tmp1 = MqReadL_e(mqctx);                           // "tmp1" is now a reference to the FLS storage of "ReadL"
  MqSend_E(mqctx, "C", pBFL3, "ECOL:[III]", 4, 5, 6);       // ATTENTION: callback "pBFL3" using "ReadL"
  MqProcessEvent_E(mqctx,MQ_WAIT_OWN,MK_TIMEOUT_DEFAULT);   // ERROR: enter event-loop, callback "pBFL3" is called
  MqSend_E(mqctx, "R", "L", tmp1);                          // ERROR: "tmp1" has now the value from "tmp2"
  return MK_OK;
error:
  return MqSendRETURN (mqctx);
}

Example from server.c convert "ReadL" result into global storage using "Dup" and free later

static enum MkErrorE Ot_BFL4 ( MQ_CALLBACK_SERVICE_CALL_ARGS )
{
  MK_BFL tmp1 = MqReadL_e(mqctx);                           // "tmp1" is now a reference to the FLS storage of "ReadL"
  MK_BFL glb1 = MkBufferListDup(tmp1);                      // OK: "glb1" is now a UNSHARED reference to the global memory
  MK_BFL tmp2 = MqReadL_e(mqctx);                           // "tmp2" is now a reference to the FLS storage of "ReadL"
  MqSend_E(mqctx, "R", "LL", glb1, tmp2);                   // OK: "glb1" (alias tmp1) and "tmp2" are separate references
  MkBufferListDelete(glb1);                                 // ATTENTION: don't forget to free the global memory in C
  return MK_OK;
error:
  return MqSendRETURN (mqctx);
}

TLS storage used by the *CreateTLS style of functions

In the C language the TLS (Thread-Local-Storage) is unique per definition and the name is used to distinguish the storage.

‍The Problem is to create a TLS interface useable in all target-programming-language (C,C++,C#,VB.NET,Java,Python,Ruby,Perl,PHP,Tcl or GO) supported by the Programming-Language-Micro-Kernel.

The *CreateTLS style function return a TLS that is unique per runtime and not unique per definition. The tlsid (0,1,2,3...) is used to distinguish the storage.

Note
Every *CreateTLS style function with the same tlsid return the same memory in the same thread.

There is always a risk that the memory used by the *CreateTLS style of functions will also be used by another component of the software in the same thread.

Attention
Use the *CreateTLS style function with caution in a local (controlled) context.
It is a problem if the event-loop is called like for an event or an asynchronous-service-call and if an other component of the software uses the same *CreateTLS style function with the same tlsid .

Example from perfserver.c performance test with TLS storage in a local (controlled) context

static enum MkErrorE
Ot_BUST ( MQ_CALLBACK_SERVICE_CALL_ARGS )
{
  MK_BUS bus = MkBufferStreamCreateTLS(0);

  while (MqReadItemExists(mqctx)) {
    MkBufferStreamWriteU(bus,MqReadU_e(mqctx));
  }

  MkBufferStreamPosToStart(bus);

  MqSendSTART_E (mqctx);
  while (MkBufferStreamReadItemExists(bus)) {
    MqSendU_E (mqctx, MkBufferStreamReadU_e (bus));
  }

error:
  return MqSendRETURN (mqctx);
}

MkKernel PACKAGE

MkKernel ENUM

enum MkErrorEcollection for the different error-codes …
ErrorE_FromIntreturn the MkErrorE from integer …
ErrorE_ToIntreturn the MkErrorE as integer …
ErrorE_ToStringreturn the MkErrorE as string …
enum MkTimeoutEPredefined Timeout values …
TimeoutE_FromIntreturn the MkTimeoutE from integer …
TimeoutE_ToIntreturn the MkTimeoutE as integer …
TimeoutE_ToStringreturn the MkTimeoutE as string …
enum MkTypeEbasic data-types supported by Programming-Language-Micro-Kernel
TypeE_FromIntreturn the MkTypeE from integer …
TypeE_ToIntreturn the MkTypeE as integer …
TypeE_ToString

return the MkTypeE as string …

MkKernel SETUP

Cleanupcleanup libmkkernel internal memory …
Setup

setup libmkkernel internal memory …

MkKernel DETAIL

C-API: MkKernel_C_API - The package is the toplevel structure of the Programming-Language-Micro-Kernel

The libmkkernel package is loaded with:

link: -Lpath -lmkkernel or automake: LDADD = libmkkernel.la

and is a composition of one or more class-item.

The libmkkernel package add the following public classes into MkObjectC_C_API :

Object C-Type Description
MkObjectC MK_OBJ The MkObjectC object known as obj or object is used as base-object type for a managed-object
MkBufferC MK_BUF The MkBufferC object known as buf or buffer is used to create and manage dynamic, generic, mixed typed data. …
MkBufferStreamC MK_BUS The MkBufferStreamC object known as bus or stream is a subclass of MkBufferC used for package-based-io
MkBufferListC MK_BFL The MkBufferListC object known as bfl or buffer-list is used to create and manage a list of MkBufferC
MkLogFileC MK_LFL The MkLogFileC object known as lfl or log-file is used to control … the target of the logging-output.
MkErrorC MK_ERR The MkErrorC object known as err or error is used to create … and manage an error message …
MkRuntimeC MK_RT The MkRuntimeC class known as mkrt or runtime is the main libmkkernel application environment …

The libmkkernel package add the following public types into MkObjectC_C_API :

    ABSTRACT: MkTypeSTT (TypeTypeType = type of a TypeType)
    |
    |- ABSTRACT: MkDefTypeSTT (TypeType = type of a Type)
       |
       |- MkObjectST, MkLogFileST, MkBufferListST,
       |- MkErrorPanicST, MkErrorIgnoreST, MkErrorPrintST, MkErrorDefaultST, MkErrorST
       |
       |- ABSTRACT: MkBufferST
          |- FINAL: MkBuffer64ST, MkBuffer256ST, MkBuffer1024ST
          |- ABSTRACT: MkBufferStreamST
             | FINAL: MkBufferStream64ST, MkBufferStream256ST, MkBufferStream1024ST, MkBufferStream16384ST

MkKernel ENUM

C-API: MkKernel_Enum_C_API - C-API: Internal - Enum definition - libmkkernel enum definition …

MkKernel_C_API

A enum in the Programming-Language-Micro-Kernel is a enum-data-type and 3 enum-access-attributes

  1. ENUM_ToString → return the string-value from the enum-value
  2. ENUM_ToInt → return the integer-value from the enum-value
  3. ENUM_FromInt → create an enum-value from an integer-value.

The enum-data-type and the 3 enum-access-attributes are defined in all target-languages (C,C++,C#,VB.NET,Java,Python,Ruby,Perl,PHP,Tcl or GO).

enum MkErrorE

TOP

collection for the different error-codes … → API: MkErrorE

This is the default-error-indicator and return-value from near all Programming-Language-Micro-Kernel functions.

enum MkErrorE {
MK_OK = 0,
MK_ERROR = 2,
};
MkErrorE
collection for the different error-codes …
Definition kernel_mk.h:3111
@ MK_ERROR
exit upper code with an error (persistent)
Definition kernel_mk.h:3114
@ MK_CONTINUE
continue with upper code
Definition kernel_mk.h:3113
@ MK_OK
everything is OK, no error available (persistent)
Definition kernel_mk.h:3112

(static) enum MkErrorE MkErrorE_FromInt(MK_INT value, enum MkErrorE* value_out)

TOP

return the MkErrorE from integer … → API: MkErrorE_FromInt

(static) MK_INT MkErrorE_ToInt(enum MkErrorE value)

TOP

return the MkErrorE as integer … → API: MkErrorE_ToInt

(static) MK_STRN MkErrorE_ToString(enum MkErrorE value)

TOP

return the MkErrorE as string … → API: MkErrorE_ToString


enum MkTimeoutE

TOP

Predefined Timeout values … → API: MkTimeoutE

The MkTimeoutE is used wherever a "timeout" is required. As a special feature, in addition to the defined values in MkTimeoutE, freely defined values as integers as seconds are also accepted.

__parser__(enum-accept-integer=long)
enum MkTimeoutE {
};
MkTimeoutE
Predefined Timeout values …
Definition kernel_mk.h:3155
@ MK_TIMEOUT_LONG
long timeout in sec (180 sec) …
Definition kernel_mk.h:3159
@ MK_TIMEOUT_VERYSHORT
very short timeout in sec (5 sec) …
Definition kernel_mk.h:3168
@ MK_TIMEOUT_INIT
maximum timeout in sec (900 sec) …
Definition kernel_mk.h:3157
@ MK_TIMEOUT_MAX
request the maximum possible (infinite) timeout value …
Definition kernel_mk.h:3174
@ MK_TIMEOUT_NORMAL
normal timeout in sec (90 sec) …
Definition kernel_mk.h:3161
@ MK_TIMEOUT_USER
request the user defined timeout value from the MqTimeout configuration value …
Definition kernel_mk.h:3172
@ MK_TIMEOUT_SOCKET
shorter timeout in sec (10 sec) … This TIMEOUT is used for socket connection with 'connect'
Definition kernel_mk.h:3166
@ MK_TIMEOUT_SHORT
short timeout in sec (20 sec) …
Definition kernel_mk.h:3163
@ MK_TIMEOUT_DEFAULT
request the default timeout value …
Definition kernel_mk.h:3170
#define META_TIMEOUT_REF
Definition kernel_mk.h:194

(static) enum MkErrorE MkTimeoutE_FromInt(MK_INT value, enum MkTimeoutE* value_out)

TOP

return the MkTimeoutE from integer … → API: MkTimeoutE_FromInt

(static) MK_INT MkTimeoutE_ToInt(enum MkTimeoutE value)

TOP

return the MkTimeoutE as integer … → API: MkTimeoutE_ToInt

(static) MK_STRN MkTimeoutE_ToString(enum MkTimeoutE value)

TOP

return the MkTimeoutE as string … → API: MkTimeoutE_ToString


enum MkTypeE

TOP

basic data-types supported by Programming-Language-Micro-Kernel … → API: MkTypeE

enum MkTypeE {
MK_BINT = ((8 << MK_TYPE_SHIFT) ),
MK_STRT = ((9 << MK_TYPE_SHIFT) ),
MK_LSTT = ((10 << MK_TYPE_SHIFT) ),
};
#define MK_TYPE_IS_8_BYTE
the type is native and has a size of 8 bytes …
Definition kernel_mk.h:3282
#define MK_TYPE_IS_4_BYTE
the type is native and has a size of 4 bytes …
Definition kernel_mk.h:3279
#define MK_TYPE_IS_1_BYTE
the type is native and has a size of 1 byte …
Definition kernel_mk.h:3273
#define MK_TYPE_SHIFT
FIXED: type is only 8bit -> 4 bit=15 for type and 4 bit for flag …
Definition kernel_mk.h:3289
#define MK_TYPE_IS_2_BYTE
the type is native and has a size of 2 bytes …
Definition kernel_mk.h:3276
@ MK_BYTT
Y: 1 byte 'byte' type.
Definition kernel_mk.h:3300
@ MK_WIDT
W: 8 byte 'long long int' type.
Definition kernel_mk.h:3305
@ MK_INTT
I: 4 byte 'int' type.
Definition kernel_mk.h:3303
@ MK_FLTT
F: 4 byte 'float' type.
Definition kernel_mk.h:3304
@ MK_BINT
B: X byte 'byte-array' type.
Definition kernel_mk.h:3307
@ MK_BOLT
O: 1 byte 'boolean' type.
Definition kernel_mk.h:3301
@ MK_DBLT
D: 8 byte 'double' type.
Definition kernel_mk.h:3306
@ MK_STRT
C: X byte 'string' type (e.g. with a \0 at the end)
Definition kernel_mk.h:3308
@ MK_LSTT
L: X byte 'list' type.
Definition kernel_mk.h:3309
@ MK_SRTT
S: 2 byte 'short' type.
Definition kernel_mk.h:3302
See also
TypeE_ToString, TypeE_ToInt, TypeE_FromInt, BufferGetType2, BufferCastTo, BufferStreamReadGetNextType

(static) enum MkErrorE MkTypeE_FromInt(MK_INT value, enum MkTypeE* value_out)

TOP

return the MkTypeE from integer … → API: MkTypeE_FromInt

(static) MK_INT MkTypeE_ToInt(enum MkTypeE value)

TOP

return the MkTypeE as integer … → API: MkTypeE_ToInt

(static) MK_STRN MkTypeE_ToString(enum MkTypeE value)

TOP

return the MkTypeE as string … → API: MkTypeE_ToString

MkKernel SETUP

C-API: MkKernel_Setup_C_API - Setup und Cleanup the libmkkernel

Initializing a libmkkernel library depends on the target language and the specific nature of the Programming-Language-Micro-Kernel.

In general it is required to call a Setup style funtion as FIRST argument because of:

  • In a static build the shared library constructor/destructor is NOT called
  • In a shared build the order of library loading is target-language-specific
  • Every executable who uses a meta-library (MkKernel, MqMsgque, LcConfig, ...) which provide a language-specific-type (always assume this) and also support static-build (no constructor is called like C, C++, ...) require a call to the meta-library-setup-function for type-initialization at startup.

If more than one META library is called only the toplevel Setup is required:

  • example: The MkKernelSetup is not required if MqMsgqueSetup or LcConfigSetup is already used.

shared library detail

A new libmkkernel library is initialized with Setup and released again with Cleanup. Both functions are automatically called upon loading and unloading of the shared library.

Example: Definition (C) of the libmkkernel library startup functions

MK_EXTERN void MK_DECL MkSetup (void) __attribute__ ((constructor(200)));
MK_EXTERN void MK_DECL MkCleanup (void) __attribute__ ((destructor(200)));
#define MK_DECL
Definition kernel_mk.h:2159
#define MK_EXTERN
static library
Definition kernel_mk.h:2557
MK_EXTERN void MkCleanup(void)
cleanup libmkkernel internal memory …
MK_EXTERN void MkSetup(void)
setup libmkkernel internal memory …

In the Programming-Language-Micro-Kernel, a type is defined for each thread, which means that the new libmkkernel library must be known when the thread starts. This is not a problem as long as the external libmkkernel library is linked to the application. However, if dlopen is used to load the libmkkernel library, the current restriction is that the new data type from the libmkkernel library has not been defined in all existing threads.

The point in time when a library is loaded depends heavily on the programming language used.

  • A linked language such as C or C++ usually has all libraries initialised at startup.
  • A compiled language such as Java and C# only load a library when a function of the library is used and
    not when the library is declared.
  • A scripting language such as Tcl normally loads the library as soon as the declaration (package require myLib) is made, which happens fairly close to the start of the program but is not guaranteed.

‍To avoid all the problems call the Setup directly at the start of the main program.

Example: Start of the ConfigServer application from the example/csharp directory

  • The problem with the ConfigServer application is that the libmkkernel and libmqmsgque libraries are loaded very early, at startup, and the liblcconfig very late, only on request.
static void Main(string[] argv) {
LcConfig.Setup();
var srv = MqFactoryCT<ConfigServer>.Add().New();
try {
srv.LinkCreate(argv);
srv.ProcessEvent(MqWaitOnEventE.FOREVER);
} catch (Exception e) {
srv.ErrorCatch(e);
}
srv.Exit();
}

(static) void MkCleanup(void)

TOP

cleanup libmkkernel internal memory … → API: MkCleanup

MkCleanup will only be recognized once and will be ignored if not called in the same thread as MkSetup. After a call to MkSetup the call to MkCleanup is possible again.

‍The public MkCleanup is just a placeholder, the internal MkCleanup is always called even if the public MkCleanup is not called.

Attention
during cleanup objects will be deleted too -> the language interpreter have to be active

(static) void MkSetup(void)

TOP

setup libmkkernel internal memory … → API: MkSetup

MkSetup will only be recognized once, additional call's will be ignored until a MkCleanup is called.

‍A call to the public MkSetup is required if dlopen and thread is used.


MkObjectC

MkObjectC DBG

DbgMdebug: write a static-marker to the MkLogFileC (default: stderr) …
DbgDumpdebug: Dump a instance to stderr with LNG and MQ internal data…
DbgLdebug: write a instance-marker to the MkLogFileC (default: stderr) using the fmtobj as prefix …
DbgLogCdebug: write a short-obj-summary to MkLogFileC (default: stderr) …
DbgOidebug: write the object-details to MkLogFileC (default: stderr) …
DbgSTACK

debug: write the stack-trace to MkLogFileC (default: stderr) …

MkObjectC INTROSPECTION

Instancesget head-instance from linked-list of MkObjectS type …
Nextget next instance from linked-list of MkObjectS type
Prev

get previous instance from linked-list of MkObjectS type

MkObjectC LOG

LogCwrite a logging-message to MkLogFileC (default: stderr) using the internal format …
LogHEXlog binaray data as HEX into the MkLogFileC (default: stderr) …
LogVwrite a printf style logging-message to MkLogFileC (default: stderr) using the internal format …
LogVLwrite a vprintf style logging-message to MkLogFileC using the internal format …
LogLog-Slot - log the entire object to the MkLogFileC (default: stderr) target …
LogDetaillog the MkObjectS verbose into the MkLogFileC (default: stderr) …
LogSimple

log the MkObjectS into the MkLogFileC (default: stderr) …

MkObjectC MISC

FromHandleImport-Slot - returns a obj from a former exported handle
ErrorCatchconvert a programming-language-error into an libmkkernel error …
ToErrorError-Slot - return an error-object pre initialized with obj data.
ToHandleExport-Slot - returns a reference to the obj useable for external storage
ToNameInfo-Slot - returns brief information about the obj as a string
ToNameOfClassClass-Slot - returns the C-Class-Name of the obj as string
ToNameOfTypeType-Slot - returns the LibMkKernel-Type-Name of the obj as a string
ToString

String-Slot - returns the string representation of the obj

MkObjectC TOR

DeleteDelete-Slot - delete an instance.
Dispose

Dispose-Slot - untie the connection between the Native-C-Instance and the LibMsgque-Instance.

MkObjectC DETAIL

C-API: MkObjectC_C_API - The MkObjectC object known as obj or object is used as base-object type for a managed-object

libmqmsgque is also called as Programming-Language-Micro-Kernel. libmqmsgque is like a programming-language without syntax but using the Target-Programming-Language (in our case C) of the Micro-Kernel as runtime environment.

Integration
To operate as a Micro-Kernel a maximum integration into the Target-Programming-Language is available.

This integration is done using the managed-object-technology.

Managed-Object
A managed-object is a piece of C-Code able to act as a native datatype in all Target-Programming-Languages supported.

The managed object supports low level integration features descripted in MkObjectS :

  • object identification based on signatures
  • reference counting
  • management of the self object pointer for the target-language
  • object-type specific features provided with MkTypeS

In the implementation-layer of libmkkernel only the public-features of the MkObjectC are visible to the programmer.

MANAGED OBJECT TYPES

In Programming-Language-Micro-Kernel everything is a struct, there are type-struct(s) and instance-struct(s):

  1. A type-struct is derived from MkTypeS and provide type-properties (static-properties) and type-methods (slots)
  2. A instance-struct is derived from MkObjectS and provide instance-properties and instance-methods

An instance is full defined by min 4 structs and optional base-structs :

  1. instance-struct -> base-struct(s) -> object-struct (MkObjectS)
  2. instance-type -> base-type(s) -> type-type (MkTypeS)

The following naming-convention exist for the C-API (example: MkBufferC)

name definition
MkBufferS instance-struct → This is the main-struct to define an instance
MkBufferST instance-type as specific-instance-type
MkBufferSTT instance-type as common-instance-type (cast from MkBufferST into MkTypeS) …
MkBufferC_T instance-type as specific-instance-type, useable in a class-macro as: class##_T
MkBufferC_TT instance-type as common-instance-type, useable in a class-macro as: class##_TT
MK_BUF class-shortcut for struct MkBufferS *, all shortcut using the XX_YYY syntax (only for public API) …
MK_BUFR reference-shortcut for struct MkBufferS, all shortcut using the XX_YYYR syntax (only for public API) …
MkBufferCR instance-struct-reference same as struct MkBufferS, useable in a class-macro as: class##R
MkBufferCT_X(instance) cast from an instance into the specific-instance-type
MkBufferCTT_X(instance) cast from an instance into the common-instance-type
MkBufferCT_TT(typ) cast from an common-instance-type into an specific-instance-type
MkBufferCTT instance-type as common-instance-type for MkBufferC in the target-programming-language (C,C++,C#,VB.NET,Java,Python,Ruby,Perl,PHP,Tcl or GO)
MkBufferCT instance-type as specific-instance-type for MkBufferC in the target-programming-language (C,C++,C#,VB.NET,Java,Python,Ruby,Perl,PHP,Tcl or GO)

the struct(s) are defined as:

  1. The instance-type is a type-struct able to create an instance.
  2. The type-type is a type-struct not able to create an instance but used as super-class for a instance-type and the base-type
  3. The base-type is a type-struct and used to initialize the type-properties and type-methods (called slots).
    An instance provide methods and slots. A slot is a method predefined in the type like constructor. A list of all slots are defined in MkTypeS.

    example MkBufferC : MkTypeS -> MkDefTypeS -> MkObjectST -> MkBufferST

  4. The instance is a link between the instance-struct, the base-struct the instance-type and the base-type.

    example MkBufferC : MkBufferST -> MkBufferS <- MkObjectS

  5. The base-struct is used to provide the base-instance-properties
    struct MyBaseStruct {
    union {
    struct MkObjectS obj
    } super;
    // MyBaseStruct-properties
    }
    struct MyInstanceStruct {
    union {
    struct MkObjectS obj
    struct MyBaseStruct bse
    } super;
    // MyInstanceStruct-properties
    }

To use the specific-instance-type as argument to a function or as property in a struct the common-instance-type of type MkTypeS is used. To cast a specific-instance-type into a common-instance-type use:

  1. the path: type->super.typ
  2. the shortcut: MkTYP(type)->XYZ (pointer) or MkTYP_R(type).XYZ (reference)

To get the common-instance-type from the instance use:

  1. the path: instance->super.obj.type
  2. the shortcut: MkOBJ(instance)->type (pointer) or MkOBJ_R(instance).type (reference)

To get the base-type from the instance-type use:

  1. the path: instance->super.obj.type->base
  2. the shortcut: MkOBJ(instance)->type->base (pointer) or MkOBJ_R(instance).type->base (reference)

The predefined instance-type is an instance of the default-instance-type (MkDefTypeS) …

struct MkRuntimeS {
...
struct MkDefTypeS _MkBufferST;
...
}

The properties and slots of the instance-type are predefined by the base-type and may be overwritten …

The following relationship between the three different struct exists:

  1. The instance-type and the type-type have the super-class MkTypeS and the instance not.
  2. The type-type is a super-class of an instance-type.
  3. The instance-type has the 3 attributes MkTypeS::objsig, MkTypeS::objmask and MkTypeS::objsize defined, the type-type not.
  4. The instance has access to the instance-type using the cast (example MkBufferCT_X(instance))
  5. The instance-type has access to the base using MkTypeS::base and to the type using MkObjectS::type.

MANAGED OBJECT PROGRAMMING

The Programming-Language-Micro-Kernel using the manged-object technology to create a class-system with MkObjectS as the root-class.
The MkObjectS is the FIRST and REQUIRED attribute in the super-union.

  1. The instance-type is a composition of one or more super-classes and instance-attributes.
  2. All super-classes are grouped into a annonymous union called super.
  3. Only the super-class struct MkObjectS obj is required for object-management, all other super-classes are optional.
  4. The name of the super-class like obj or buf is fix and is required by tool-macros and functions.
// instance-type: MyFeatureS
struct MyStructS {
// instance super-class
union {
struct MkObjectS obj; // 'object' instance-type (required)
struct MkBufferS buf; // 'buffer' instance-type (optional,example)
} super;
// instance attribute
int myInt; …
}

A class is a link (MkObjectS::type) between:

instance-type(example: MkBufferS)
type-type(example: MkBufferSTTMkDefTypeSTTMkTypeSTT)

A class is identified by the signature (MkObjectS::signature) located at the FIRST int32 bits of the class-instance.

  • The managed-object supports one or more super-class using a union with struct MkObjectS obj as the first attribute in the union.
  • The union is required because the managed-object share the memory with the super-class.

There are two possible "cast" operations on a managed-object :

  1. A "cast" from a pointer of unknown origin (example: MK_MNG).
  2. A "cast" from an already known managed object pointer (example: MK_BUS).

In (1) the "cast" is checked using the "signature" and in (2) the "cast" is simply resolved within the "super-class".

Example: "cast" a pointer into a MkBufferS

  • "cast" from an unknown pointer: MK_BUF ret = MkBuf(ptr);
    • This "cast" is called an up-cast because you're upgrading the pointer (getting more information).
    • This "cast" checks the MkObjectS::signature to ensure that ptr is a valid object.
    • This "cast" is checked at runtime.
  • "cast" from a managed pointer: MK_BUF ret = MkBUF(ptr);
    • This "cast" is called a down-cast because you downgrading the pointer (lose some information).
    • This "cast" uses the super-union to just return a pointer that is already available.
    • This "cast" is checked at compile time.
  • To put it simply: MkBuf ≠ MkBUF

Example from kernel_mk.h A full class example from MkBufferS

struct MkBufferS {
// BEGIN-MkBufferS-super - created by 'cls_MqS.tcl -i NHI1_HOME/theKernel/libmkkernel/.libmkkernel.meta' - DO NOT change
union {
struct MkObjectS obj; // base CLASS \MkObjectS
} super;
// END-MkBufferS-super - created by 'cls_MqS.tcl -i NHI1_HOME/theKernel/libmkkernel/.libmkkernel.meta' - DO NOT change
// instance attributes
struct {
MK_NUM cursize;
enum MkTypeE type;
} var;
// instance storage
struct {
union MkBufferU first;
bool doBufferFree;
} storage;
struct ilsS {
} ils;
#define MkBufferS_ils_size 0
};
// BEGIN-MkBufferS-ClassDef - created by 'cls_MqS.tcl -i NHI1_HOME/theKernel/libmkkernel/.libmkkernel.meta' - DO NOT change
// Signature --------------------------------------------------------------
#define MkBufferC_SIGNATURE (MkObjectC_SIGNATURE ^ (1u<<10))
#define MkBufferC_MASK (((1u<<22)-1)<<10)
// Signature --------------------------------------------------------------
#define MkBufferC_X2buf(x) (x)
#define MkBufferC_X2obj(x) MkOBJ(x)
// TypeDef --------------------------------------------------------------
__parser__(ignore) typedef struct MkBufferS MkBufferCR;
__parser__(ignore) typedef const struct MkBufferS MkBufferCNR;
#define MkBufferC_T (&MK_RT_REF._MkBufferC_T)
#define MkBufferC_TT (MkTYP(MkBufferC_T))
#define MkBufferST MkBufferC_T
#define MkBufferSTT (MkTYP(MkBufferST))
#define MkBufferC_type MK_BUF
#define MkBufferCT_X(instance) ( (struct MkDefTypeS *) (MkOBJ_R(instance).type) )
#define MkBufferCTT_X(instance) (MkOBJ_R(instance).type)
#define MkBufferCT_TT(typ) ( (struct MkDefTypeS *) (typ) )
#define MkBufferC_NS MK
#define MkBufferCTT MkBufferCTT
#define MkBufferCT ( (struct MkDefTypeS *) MkBufferCTT )
// TypeCheck --------------------------------------------------------------
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wattributes"
__parser__(class=MkBufferC,static,hide)
return MkSanitizeCheck(MkBufferC,mng);
}
#pragma GCC diagnostic pop
#define MkBufferC_Check(mng) MkBufCheck(mng)
// ObjectCast --------------------------------------------------------------
__parser__push__(prefix=Cast);
__parser__(class=MkBufferC,hide,static)
META_ATTRIBUTE_SANITIZE
return (MkBufCheck(mng) ? (MK_BUF)mng : NULL);
}
__parser__(ignore)
META_ATTRIBUTE_SANITIZE
return (MkBufCheck(mng) ? (MK_BUFN)mng : NULL);
}
#define MkBufRaise(_buf) if (!_MkCheckX(MkBufferC,_buf)) { \
MkErrorSetC_1E("'MkBufferC' hdl is NULL"); \
goto error ; \
}
#define MkBUF_R(x) (*(x)).super.buf
#define MkBUF(x) (&MkBUF_R(x))
// END-MkBufferS-ClassDef - created by 'cls_MqS.tcl -i NHI1_HOME/theKernel/libmkkernel/.libmkkernel.meta' - DO NOT change

MkObjectC DBG

C-API: MkObjectC_Dbg_C_API - log a debugging-message to the MkLogFileC (default: stderr) …

This functions are "helpers" to support the programmer.

(static) void MkDbgM(MK_STRN message, MK_DBG debug, MK_STRN callfunc, MK_INT lvl)

TOP

debug: write a static-marker to the MkLogFileC (default: stderr) … → API: MkDbgM_RT

enum MkErrorE MkDbgDump(MK_OBJN obj, MK_STRN message, MK_STRN callfunc)

TOP

debug: Dump a instance to stderr with LNG and MQ internal data… → API: MkDbgDump_RT

Attention
this is only implemented by the Target-Programming-Language

void MkDbgL(MK_OBJN fmtobj, MK_STRN message, MK_DBG debug, MK_STRN callfunc, MK_INT lvl)

TOP

debug: write a instance-marker to the MkLogFileC (default: stderr) using the fmtobj as prefix … → API: MkDbgL_RT

The marker is prefixed with object data from th fmtobj.

void MkDbgLogC(MK_OBJN obj, MK_STRN callfunc)

TOP

debug: write a short-obj-summary to MkLogFileC (default: stderr) … → API: MkDbgLogC_RT

void MkDbgO(MK_OBJN obj, MK_STRN callfunc)

TOP

idebug: write the object-details to MkLogFileC (default: stderr) … → API: MkDbgO_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]objthe MkObjectS instance to work on - a MANAGED OBJECT after type-check and able to be supported by the MkObjectS API
[in]callfunca user-defined postfix to identify the calling function or the environment (default=name-of-function)

This function can be overwritten in the target programming language.

void MkDbgSTACK(MK_OBJN fmtobj, MK_INT skip, MK_INT num, MK_STRN callfunc)

TOP

debug: write the stack-trace to MkLogFileC (default: stderr) … → API: MkDbgSTACK_RT

MkObjectC INTROSPECTION

C-API: MkObjectC_Introspection_C_API - Get information from the MkTypeS.

Get information about all instances created by class

The Introspection API is used to get information about the details of the instance and type implementation. Only the connection between type and instance is currently implemented.

Three methods are used to create an iteration over all avaialable instances of a type.

  • Every class has a Linked-List of all instances created starting from last to first.
  • The Introspection support always 3 Functions per class: Instance (static), Next and Prev
  • The Instance (example: (static) MK_BUF MkBufferInstances(void))
    • return the last-instance created or NULL if no instance was created.
  • The Next (example: MK_BUF MkBufferNext(MK_BUF buf))
    • return the next-instance for a given-instance or NULL if the given-instance is the last-instance.
  • The Prev (example: MK_BUF MkBufferPrev(MK_BUF buf))
    • return the previous-instance for a given-instance or NULL if the given-instance is the first-instance.

Example: a simple loop over all instances of class MkBufferC (language C++)

for (auto buf = MkBufferC::Instances(); buf != NULL; buf = buf->Next()) {
SendC(buf->ToString());
}

(static) MK_OBJ MkObjectInstances(void)

TOP

get head-instance from linked-list of MkObjectS type … → API: MkObjectInstances

The head-instance is the last instance created.

MK_OBJ MkObjectNext(MK_OBJ obj)

TOP

get next instance from linked-list of MkObjectS type → API: MkObjectNext

MK_OBJ MkObjectPrev(MK_OBJ obj)

TOP

get previous instance from linked-list of MkObjectS type → API: MkObjectPrev

MkObjectC LOG

C-API: MkObjectC_Log_C_API - log information to MkLogFileC (default: stderr) …

The logging-target is set direct by RuntimeSetLogfile or using the class MkLogFileC.

The target is stored at the MkRuntimeC using a FILE-stream and can be set individually for each thread. The default is stderr.

possible values are:

value decription OS man-page
stdout the standart output stdio(3)
stderr the standart error output stdio(3)
fileName an arbitary fileName fopen(3)

Many logging functions have common parameters:

Parameters
[in]fmtobjmanaged object used to format the log-message (default=NULL = use default format)
[in]callfunca user-defined postfix to identify the calling function or the environment (default=name-of-function)
[in]debugthe debug level from MkRuntimeS::debug, use 0 <= debug <= 9 (default=0)

void MkLogC(MK_OBJN fmtobj, MK_STRN message, MK_DBG debug, MK_STRN callfunc)

TOP

write a logging-message to MkLogFileC (default: stderr) using the internal format … → API: MkLogC_RT

The logging is only done if 'MqDebug >= level' and 'MqIsSilent == MK_NO' using the following format:

C> (NAME:PID:THREADID) [YYYY-MM-DD:HH-MM-SS] [String|Binary-DEBUGLEVEL-CONTEXTID-REFCOUNT-CONTEXTPTR-prefix]: message

The message is build with snprintf and finally send with fputsn without newline '\n' character at the end. To add the newline or an other special-caracter use the '\xxx' syntax.

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]fmtobjmanaged object used to format the log-message (default=NULL = use default format)
[in]callfunca user-defined postfix to identify the calling function or the environment (default=name-of-function)
[in]debugthe debug level from MkRuntimeS::debug, use 0 <= debug <= 9 (default=0)
[in]messagestring to log

void MkLogHEX(MK_OBJN fmtobj, MK_STRN callfunc, MkBinaryR data)

TOP

log binaray data as HEX into the MkLogFileC (default: stderr) … → API: MkLogHEX_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]fmtobjmanaged object used to format the log-message (default=NULL = use default format)
[in]callfunca user-defined postfix to identify the calling function or the environment (default=name-of-function)
[in]datathe binary data to log

void MkLogV(MK_OBJN fmtobj, MK_STRN callfunc, MK_DBG debug, MK_FST printfmt, ... args)

TOP

write a printf style logging-message to MkLogFileC (default: stderr) using the internal format … → API: MkLogV_RT

Use the format and the restrictions from LogC.

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]fmtobjmanaged object used to format the log-message (default=NULL = use default format)
[in]callfunca user-defined postfix to identify the calling function or the environment (default=name-of-function)
[in]debugthe debug level from MkRuntimeS::debug, use 0 <= debug <= 9 (default=0)
[in]printfmtis a c-string used as printf like format string

void MkLogVL(MK_OBJN fmtobj, MK_STRN callfunc, MK_DBG debug, MK_FST printfmt, va_list var_list)

TOP

write a vprintf style logging-message to MkLogFileC using the internal format … → API: MkLogVL_RT

Use the format and the restrictions from LogC.

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]fmtobjmanaged object used to format the log-message (default=NULL = use default format)
[in]callfunca user-defined postfix to identify the calling function or the environment (default=name-of-function)
[in]debugthe debug level from MkRuntimeS::debug, use 0 <= debug <= 9 (default=0)
[in]printfmtis a c-string used as printf like format string
[in]var_lista variable argument list object

void MkObjectLog(MK_OBJN obj, MK_OBJ fmtobj, MK_DBG debug, MK_STRN callfunc, MK_INT lvl)

TOP

Log-Slot - log the entire object to the MkLogFileC (default: stderr) target … → API: MkObjectLog_RT

Todo:

log_doku

slot_doku

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]objthe MkObjectS instance to work on - a MANAGED OBJECT after type-check and able to be supported by the MkObjectS API
[in]fmtobjmanaged object used to format the log-message (default=NULL = use default format)
[in]debugthe debug level from MkRuntimeS::debug, use 0 <= debug <= 9 (default=0)
[in]callfunca user-defined postfix to identify the calling function or the environment (default=name-of-function)
[in]lvla user-defined prefix starting with "" for lvl=0 and increase with " " for lvl+1 (default=0)
See also
BufferLog, BufferListLog, BufferStreamLog, ?MkLogFileLog?, ErrorLog, RuntimeDebug, ObjectLogSimple

void MkObjectLogDetail(MK_OBJN obj, MK_OBJN fmtobj, MK_DBG debug, MK_STRN callfunc, MK_INT lvl)

TOP

log the MkObjectS verbose into the MkLogFileC (default: stderr) … → API: MkObjectLogDetail_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]objthe MkObjectS instance to work on - a MANAGED OBJECT after type-check and able to be supported by the MkObjectS API
[in]fmtobjmanaged object used to format the log-message (default=NULL = use default format)
[in]debugthe debug level from MkRuntimeS::debug, use 0 <= debug <= 9 (default=0)
[in]callfunca user-defined postfix to identify the calling function or the environment (default=name-of-function)
[in]lvla user-defined prefix starting with "" for lvl=0 and increase with " " for lvl+1 (default=0)
See also
MkObjectC void MkObjectLog(MK_OBJN obj, MK_OBJ fmtobj, MK_DBG debug, MK_STRN callfunc, MK_INT lvl)

void MkObjectLogSimple(MK_OBJN obj, MK_OBJN fmtobj, MK_DBG debug, MK_STRN callfunc, MK_INT lvl)

TOP

log the MkObjectS into the MkLogFileC (default: stderr) … → API: MkObjectLogSimple_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]objthe MkObjectS instance to work on - a MANAGED OBJECT after type-check and able to be supported by the MkObjectS API
[in]fmtobjmanaged object used to format the log-message (default=NULL = use default format)
[in]debugthe debug level from MkRuntimeS::debug, use 0 <= debug <= 9 (default=0)
[in]callfunca user-defined postfix to identify the calling function or the environment (default=name-of-function)
[in]lvla user-defined prefix starting with "" for lvl=0 and increase with " " for lvl+1 (default=0)
See also
MkObjectC

MkObjectC MISC

C-API: MkObjectC_Misc_C_API - Various functions related to the MkObjectC

(static) MK_OBJ MkObjectFromHandle(MK_LONG exporthdl)

TOP

Import-Slot - returns a obj from a former exported handle → API: MkObjectFromHandle

Parameters
[in]exporthdlhandle former exported with ObjectToHandle
Returns
the required handle or NULL if handle is invalid

MK_ERR MkObjectErrorCatch(MK_OBJN obj, MK_EXP exception, MK_STRN callfunc)

TOP

convert a programming-language-error into an libmkkernel error … → API: MkObjectErrorCatch_RT

This function is a placeholder and have to be overloaded by the Target-Programming-Language. The goal is to handel an error-catch condition and convert an programming-language-error into an libmkkernel-error.

This is the same as (example form c++):

mngx->ErrorDEFAULT()->Catch(exception)

Example from server.c catch-send and reset an error

      MQ_CTX const clmqctx = srvctx->cl[clid];
      MqSendSTART_E (clmqctx);
      MqProxyItem_E (mqctx, clmqctx);
      if (MkErrorCheckI(MqSendEND_AND_WAIT(clmqctx, "ECOI", 5))) {
        MqContextErrorCopy (mqctx, clmqctx);
	MqSendI_E (mqctx, MkErrorGetNum_0E());
	MqSendC_E (mqctx, MkErrorGetText_0E());
	MkErrorReset_1X(mqctx);
      }
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]objthe MkObjectS instance to work on - a MANAGED OBJECT after type-check and able to be supported by the MkObjectS API
[in]exceptionthe exception object from C, if NULL the global exception object is used
[in]callfunca user-defined postfix to identify the calling function or the environment (default=name-of-function)
Returns
the ErrorDEFAULT initialized with exception value
See also
enum MkErrorE MkErrorRaise(MK_ERRN err) enum MkErrorE MkErrorReset(MK_ERR err, MK_STRN callfunc, MK_INT callline, MK_BOOL force)

MK_ERR MkObjectToError(MK_OBJ obj)

TOP

Error-Slot - return an error-object pre initialized with obj data. → API: MkObjectToError_RT

This slot is the same as ErrorDEFAULT with fmtobj set to this

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]objthe MkObjectS instance to work on - a MANAGED OBJECT after type-check and able to be supported by the MkObjectS API
Returns
the error-object
Attention
The memory of the out-value belongs to the called LibMkKernel function and therefore never becomes NULL. For details on the out-value, see: MkKernel_Storage_C_API.

MK_LONG MkObjectToHandle(MK_OBJ obj)

TOP

Export-Slot - returns a reference to the obj useable for external storage → API: MkObjectToHandle

A handle is a reference for an instance. A handle can be converted back into an instance using the ?Class?FromHandle syntax like (static) MK_BFL MkBufferListFromHandle(MK_LONG exporthdl)

Parameters
[in]objthe MkObjectS instance to work on - a MANAGED OBJECT after type-check and able to be supported by the MkObjectS API
Returns
the required handle

MK_STRN MkObjectToName(MK_OBJN obj)

TOP

Info-Slot - returns brief information about the obj as a string → API: MkObjectToName_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]objthe MkObjectS instance to work on - a MANAGED OBJECT after type-check and able to be supported by the MkObjectS API
Returns
the identification of the object as string
Attention
The memory of the out-value belongs to the called LibMkKernel function and therefore never becomes NULL. For details on the out-value, see: MkKernel_Storage_C_API.

MK_STRN MkObjectToNameOfClass(MK_OBJ obj)

TOP

Class-Slot - returns the C-Class-Name of the obj as string → API: MkObjectToNameOfClass_RT

The Programming-Language-Micro-Kernel connect the C language with the libmqmsgque runtime. Every class-object in C has an conterpart as libmqmsgque type-object in the Programming-Language-Micro-Kernel.

ObjectToNameOfType returns the name of the libmqmsgque type
ObjectToNameOfClass returns the name of the C class

MK_STRN MkObjectToNameOfType(MK_OBJN obj)

TOP

Type-Slot - returns the LibMkKernel-Type-Name of the obj as a string → API: MkObjectToNameOfType_RT

The Programming-Language-Micro-Kernel connect the C language with the LibMsgque runtime. Every class-object in C has an conterpart as LibMsgque type-object in the Programming-Language-Micro-Kernel.

ObjectToNameOfType returns the name of the libmsgque type
ObjectToNameOfClass returns the name of the C class
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]objthe MkObjectS instance to work on - a MANAGED OBJECT after type-check and able to be supported by the MkObjectS API
Returns
the name of the object-type as a string

MK_STRN MkObjectToString(MK_OBJN obj)

TOP

String-Slot - returns the string representation of the obj … → API: MkObjectToString_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]objthe MkObjectS instance to work on - a MANAGED OBJECT after type-check and able to be supported by the MkObjectS API
Returns
the required string
Attention
~ The memory of the out-value belongs to the called LibMkKernel function and therefore never becomes NULL. For details on the out-value, see: MkKernel_Storage_C_API.
~ On error an empty string is returned.

MkObjectC TOR

C-API: MkObjectC_TOR_C_API - Create and Destroy a managed-object.

void MkObjectDelete(MK_OBJ obj)

TOP

Delete-Slot - delete an instance. → API: MkObjectDelete_RT

There are two different ways to delete an instance:

ObjectDisposeto free the internal data but keep the outher shell alive - this is called a SOFT-DELETE
ObjectDelete to delete the outher shell including the internal data - this is called a HARD-DELETE
Attention
  1. The internal memory will be freed and the object-pointer will be set to NULL. If the object-pointer is already NULL nothing will be done.
  2. For a programming language without HARD-Delete support, the "Delete" method is assigned to a SOFT-Delete.
  3. For a programming language without garbage collection, a SOFT-delete without a HARD-delete causes a small memory loss (C++: ~32 bytes).
  4. After a SOFT-delete, the outher shell is still alive, but cannot be used. Any access to this shell generates an HDL-null-exception, but this exception can be caught. This is important for C++ as it prevents a core dump.
  5. On HARD-delete read more at SelfDeleteForce

(destructor) void MkObjectDispose(MK_OBJ obj)

TOP

Dispose-Slot - untie the connection between the Native-C-Instance and the LibMsgque-Instance. → API: MkObjectDispose_RT

There are two different ways to delete an instance:

ObjectDispose to free the internal data but keep the outher shell alive - this is called a SOFT-DELETE
ObjectDelete to delete the outher shell including the internal data - this is called a HARD-DELETE
Attention
1. For a programming language without HARD-Delete support, the "Delete" method is assigned to a SOFT-Delete.
2. For a programming language without garbage collection, a SOFT-delete without a HARD-delete causes a small memory loss (C++: ~32 bytes).
3. After a SOFT-delete, the outher shell is still active, but cannot be used. Any access to this shell generates an HDL-null-exception, but this exception can be caught. This is important for C++ as it prevents a core dump.

MkBufferC

MkBufferC ACCESS

AppendCappend a single string to a MkBufferC object …
AppendVappend a single string with format and ... arguments to a MkBuffer64S
AppendVLappend a single string with format and var_list arguments to a MkBuffer64S
Popdelete str from the MkBufferC
Pushadd str to the MkBufferC
ToObject

return the native language object from a MkBufferC

MkBufferC GET

GetTT

get a val_out from a MkBufferC

MkBufferC INFO

GetType1return the type from a MkBufferC as single character value …
GetType2return the MkTypeE from a MkBufferC
GetType3return the type from a MkBufferC as single character string …
IsLocalCheck if the MkBufferC is local (temporary), not local mean global
Loglog the MkBufferC
LogS

log the short MkBufferC object data to the MkLogFileC (default: stderr) …

MkBufferC INTROSPECTION

Instancesget head-instance from linked-list of MkBufferS type …
Nextget next instance from linked-list of MkBufferS type
Prev

get previous instance from linked-list of MkBufferS type

MkBufferC MISC

CastTochange the type of an MkBufferC to type
Cmpcompare TWO MkBufferC objects like strcmp do it for strings …
Copycopy the MkBufferC from srce to dest
Resetreset a MkBufferC to the length zero …
ResetFullreset a MkBufferC to the length zero and free allocated storage…
SizeAddadd size storage to the buf
SizeNewalloc min size storage to the buf
Tempcreate a temporary copy of the MkBufferC buf …
ToString

get the string representation of the buf

MkBufferC SET

SetVSet the MkBufferC to the val
SetVLSet the MkBufferC to the val
SetTT

Set the MkBufferC to the val

MkBufferC TOR

CreateConstructor - create a new MkBufferC with minimum size of internal storage …
Create1024call the BufferCreate with default type MkBuffer1024S (1024 byte) …
Create256call the BufferCreate with default type MkBuffer256S (256 byte) …
Create64call the BufferCreate with default type MkBuffer64S (64 byte) …
CreateTLSsame as BufferCreate but require no cleanup
CreateTTConstructor - create a new MkBufferC with an PRIMITIVE TYPE
FromHandleImport-Slot - returns a obj from a former exported handle
DeleteDestructor - delete a MkBufferC instance …
DupDup-Constructor - create a new MkBufferC instance as copy from an existing MkBufferC instance
Merge

Merge-Constructor - create a new MkBufferC as a merge from an existing object …

MkBufferC DETAIL

C-API: MkBufferC_C_API - The MkBufferC object known as buf or buffer is used to create and manage dynamic, generic, mixed typed data. …

The MkBufferC is used to store PRIMITIVE TYPE data. If libmkkernel is working on data… libmkkernel is working on an MkBufferC object or on a list of MkBufferC objects called MkBufferListC.

MkBufferS CLASS

The ABSTRACT-CLASS used to store a native-type-data-item defined by PRIMITIVE TYPE

C-Kernel-Details

The ABSTRACT-CLASS MkBufferS is used to store MkTypeE data in an MkBufferS::storage

A new MkBufferS is always preallocated with the predefined ILS-storage (MkBufferS::ils_data), but can switch to a MALLOC-storage if the storage requirements of the user exceed the predefined MkBufferS::ilsS::size.

‍A MkBufferS never run out of storage.

The basic goal of the ILS-storage technology is to minimize the usage of MALLOC, this mean that the MkBufferS::ilsS::size should be large enought to be sufficient for the user needs.

The following conditions must always be met for the ILS memory:

The ABSTRACT-CLASS MkBufferS is missing the ILS-storage, the FINAL-CLASSES are:

MkBuffer64C, MkBuffer256C and MkBuffer1024C

See also
MkBufferListC, MkBufferStreamC

MkBufferS CTOR / DTOR

command synonmym
(constructor) MK_BUF MkBufferCreate(MK_TYP type, MK_NUM size) no
void MkBufferDelete(MK_BUF buf) no

Example from server.c read a buffer-object and convert single-char-type-identifer to string.

static enum MkErrorE
Ot_BUF2 ( MQ_CALLBACK_SERVICE_CALL_ARGS )
{
  MK_BUF buf;
  int i;
  char str[2] = {'\0', '\0'};
  MqSendSTART_E (mqctx);
  for (i=0; i<3; i++) {
    MqReadU_E (mqctx, &buf);
    str[0] = MkBufferGetType1(buf);
    MqSendC_E (mqctx, str);
    MqSendU_E (mqctx, buf);
  }
  return MqSendRETURN(mqctx);
error:
  return MkErrorStack_1X(mqctx);
}
See also
BufferGetType1 BufferGetType2 BufferGetType3

MkBufferC ACCESS

C-API: MkBufferC_Access_C_API - various functions to access buffer-data

MK_BUF MkBufferAppendC(MK_BUF buf, MK_STRN val)

TOP

append a single string to a MkBufferC object … → API: MkBufferAppendC_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bufthe MkBufferS instance to work on
[in]valthe text to append to buf
Returns
the MkBufferC object with the new value

Example from server.c read and update a MkBufferC

      // START - ReadU - Example, read a buffer-object and append a string 
      MK_BUF buf;
      MqReadU_E (mqctx,&buf);
      MkBufferAppendC(buf,"- a really log text to overwrite the already allocated space");
      MqSendU_E (mqctx,buf);
      MqReadI_E (mqctx,&i);
      MqSendI_E (mqctx,i+1);
      // END - ReadU - Example

MK_INT MkBufferAppendV(MK_BUF buf, MK_FST printfmt, ... args)

TOP

append a single string with format and ... arguments to a MkBuffer64S … → API: MkBufferAppendV_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bufthe MkBufferS instance to work on
[in]printfmtis a c-string used as printf like format string
Returns
the size of the string appended to the MkBuffer64S object

MK_INT MkBufferAppendVL(MK_BUF buf, MK_FST printfmt, va_list var_list)

TOP

append a single string with format and var_list arguments to a MkBuffer64S … → API: MkBufferAppendVL_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bufthe MkBufferS instance to work on
[in]printfmtis a c-string used as printf like format string
[in]var_lista variable argument list object
Returns
the size of the string appended to the MkBuffer64S object

MK_NUM MkBufferPop(MK_BUF buf, MK_STRN val)

TOP

delete str from the MkBufferC … → API: MkBufferPop_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bufthe MkBufferS instance to work on
valthe text (string) to remove from buf
Returns
the size of the string removed from the MkBuffer64S object
Attention
MkBufferC have to be of type MK_STRT

MK_NUM MkBufferPush(MK_BUF buf, MK_STRN val)

TOP

add str to the MkBufferC … → API: MkBufferPush_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bufthe MkBufferS instance to work on
valthe text (string) to append to buf
Returns
the size of the string appended to the MkBuffer64S object
Attention
MkBufferC have to be of type MK_STRT

enum MkErrorE MkBufferToObject(MK_BUF buf, MK_NAT_OBJECT* obj_out)

TOP

return the native language object from a MkBufferC … → API: MkBufferToObject_RT

MkBufferC GET

C-API: MkBufferC_Get_C_API - various functions to get buffer-data

enum MkErrorE MkBufferGetTT(MK_BUFN buf, MK_BYT* val_out)

The BufferGetTT provide a single function for every PRIMITIVE TYPE

returncommand

C-API :

enum MkErrorE MkBufferGetB(MK_BUFN buf, MkBinaryR* val_out)MkBufferGetB_RT
enum MkErrorE MkBufferGetC(MK_BUFN buf, MK_STRN* val_out)MkBufferGetC_RT
enum MkErrorE MkBufferGetD(MK_BUFN buf, MK_DBL* val_out)MkBufferGetD_RT
enum MkErrorE MkBufferGetF(MK_BUFN buf, MK_FLT* val_out)MkBufferGetF_RT
enum MkErrorE MkBufferGetI(MK_BUFN buf, MK_INT* val_out)MkBufferGetI_RT
enum MkErrorE MkBufferGetL(MK_BUFN buf, MK_BFL* val_inout)MkBufferGetL_RT
enum MkErrorE MkBufferGetO(MK_BUFN buf, MK_BOL* val_out)MkBufferGetO_RT
enum MkErrorE MkBufferGetS(MK_BUFN buf, MK_SRT* val_out)MkBufferGetS_RT
enum MkErrorE MkBufferGetU(MK_BUF buf, MK_BUF* val_out)MkBufferGetU_RT
enum MkErrorE MkBufferGetW(MK_BUFN buf, MK_WID* val_out)MkBufferGetW_RT
enum MkErrorE MkBufferGetY(MK_BUFN buf, MK_BYT* val_out)

MkBufferGetY_RT

get a val_out from a MkBufferC

The MkBufferGetTT style of functions always return a val_out or a MkErrorC.

The val_out can be a PRIMITIVE TYPE, a class-type or a pointer-type (binary, string etc).

Returns
set the MkErrorC to the status MK_OK, MK_CONTINUE or MK_ERROR
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only) - (nonnull)
[in]bufthe MkBufferS instance to work on - (nonnull)
[out]val_outthe value to return - (nonnull)

MkBufferC INFO

C-API: MkBufferC_Info_C_API - various functions to get information out of buffer-data

MK_STRB MkBufferGetType1(MK_BUFN buf)

TOP

return the type from a MkBufferC as single character value … → API: MkBufferGetType1_RT

MK_BUFN const buf
)
{
switch (buf->var.type) {
case MK_STRT: return 'C';
case MK_INTT: return 'I';
case MK_DBLT: return 'D';
case MK_WIDT: return 'W';
case MK_BINT: return 'B';
case MK_BYTT: return 'Y';
case MK_BOLT: return 'O';
case MK_SRTT: return 'S';
case MK_FLTT: return 'F';
case MK_LSTT: return 'L';
}
return '*';
}
MK_EXTERN MK_STRB MkBufferGetType1_RT(MK_RT const mkrt, MK_BUFN const buf) MK_RT_ATTR_HDL
return the type from a MkBufferC as single character value …
char MK_STRB
string type data-type
Definition kernel_mk.h:2703
#define MK_RT_ATTR_HDL_CHECK(x)
Definition kernel_mk.h:2421
#define MK_RT_ATTR_RUNTIME_CHECK_XN(x)
Definition kernel_mk.h:2424
#define MK_RT_ARGS
Definition kernel_mk.h:2365

enum MkTypeE MkBufferGetType2(MK_BUFN buf)

TOP

return the MkTypeE from a MkBufferC … → API: MkBufferGetType2_RT

enum MkTypeE
MK_BUFN const buf
) {
return buf->var.type;
}
MK_EXTERN enum MkTypeE MkBufferGetType2_RT(MK_RT const mkrt, MK_BUFN const buf) MK_RT_ATTR_HDL
return the MkTypeE from a MkBufferC …

MK_STRN MkBufferGetType3(MK_BUFN buf)

TOP

return the type from a MkBufferC as single character string … → API: MkBufferGetType3_RT

MK_BUFN const buf
) {
switch (buf->var.type) {
case MK_STRT: return "C";
case MK_INTT: return "I";
case MK_DBLT: return "D";
case MK_WIDT: return "W";
case MK_BINT: return "B";
case MK_BYTT: return "Y";
case MK_BOLT: return "O";
case MK_SRTT: return "S";
case MK_FLTT: return "F";
case MK_LSTT: return "L";
}
return "*";
}
MK_EXTERN MK_STRN MkBufferGetType3_RT(MK_RT const mkrt, MK_BUFN const buf) MK_RT_ATTR_HDL
return the type from a MkBufferC as single character string …
const MK_STRB * MK_STRN
constant string pointer data-type
Definition kernel_mk.h:2745

MK_BOOL MkBufferIsLocal(MK_BUFN buf)

TOP

Check if the MkBufferC is local (temporary), not local mean global … → API: MkBufferIsLocal_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bufthe MkBufferS instance to work on
Returns
a boolean value… yes or no

void MkBufferLog(MK_BUFN buf, MK_OBJN fmtobj, MK_DBG debug, MK_STRN callfunc, MK_INT lvl)

TOP

log the MkBufferC … → API: MkBufferLog_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bufthe MkBufferS instance to work on
[in]fmtobjmanaged object used to format the log-message (default=NULL = use default format)
[in]debugthe debug level from MkRuntimeS::debug, use 0 <= debug <= 9 (default=0)
[in]callfunca user-defined postfix to identify the calling function or the environment (default=name-of-function)
[in]lvla user-defined prefix starting with "" for lvl=0 and increase with " " for lvl+1 (default=0)
See also
MkBufferC

void MkBufferLogS(MK_BUFN buf, MK_STRN varname, MK_OBJN fmtobj, MK_STRN callfunc)

TOP

log the short MkBufferC object data to the MkLogFileC (default: stderr) … → API: MkBufferLogS_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bufthe MkBufferS instance to work on
[in]varnameThe name of the argument to report
[in]fmtobjmanaged object used to format the log-message (default=NULL = use default format)
[in]callfunca user-defined postfix to identify the calling function or the environment (default=name-of-function)

MkBufferC INTROSPECTION

C-API: MkBufferC_Introspection_C_API - Get information from the MkTypeS.

Get information about all instances created by class

Get information about all instances created by class

The Introspection API is used to get information about the details of the instance and type implementation. Only the connection between type and instance is currently implemented.

Three methods are used to create an iteration over all avaialable instances of a type.

  • Every class has a Linked-List of all instances created starting from last to first.
  • The Introspection support always 3 Functions per class: Instance (static), Next and Prev
  • The Instance (example: (static) MK_BUF MkBufferInstances(void))
    • return the last-instance created or NULL if no instance was created.
  • The Next (example: MK_BUF MkBufferNext(MK_BUF buf))
    • return the next-instance for a given-instance or NULL if the given-instance is the last-instance.
  • The Prev (example: MK_BUF MkBufferPrev(MK_BUF buf))
    • return the previous-instance for a given-instance or NULL if the given-instance is the first-instance.

Example: a simple loop over all instances of class MkBufferC (language C++)

for (auto buf = MkBufferC::Instances(); buf != NULL; buf = buf->Next()) {
SendC(buf->ToString());
}

(static) MK_BUF MkBufferInstances(void)

TOP

get head-instance from linked-list of MkBufferS type … → API: MkBufferInstances

The head-instance is the last instance created.

MK_BUF MkBufferNext(MK_BUF buf)

TOP

get next instance from linked-list of MkBufferS type → API: MkBufferNext

MK_BUF MkBufferPrev(MK_BUF buf)

TOP

get previous instance from linked-list of MkBufferS type → API: MkBufferPrev

MkBufferC MISC

C-API: MkBufferC_Misc_C_API - various functions to work on buffer-data

enum MkErrorE MkBufferCastTo(MK_BUF buf, enum MkTypeE typ)

TOP

change the type of an MkBufferC to type … → API: MkBufferCastTo_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bufthe MkBufferS instance to work on
[in]typcast buf to typ
Returns
set the MkErrorC to the status MK_OK, MK_CONTINUE or MK_ERROR

MK_INT MkBufferCmp(MK_BUFN buf1, MK_BUFN buf2)

TOP

compare TWO MkBufferC objects like strcmp do it for strings … → API: MkBufferCmp_RT

-# if both types are equal than the native types are compared

  1. if both types are non-equal than the string representation of the types are compared
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]buf1the FIRST MkBufferC object to compare
[in]buf2the SECOND MkBufferC object to compare
Returns
Returns < 0 if buf1 is less than buf2; > 0 if buf1 is greater than buf2, and 0 if they are equal.

MK_BUF MkBufferCopy(MK_BUF buf, MK_BUFN srce)

TOP

copy the MkBufferC from srce to dest … → API: MkBufferCopy_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bufthe MkBufferS instance to work on
srcesource of the copy
Returns
the dest object

void MkBufferReset(MK_BUF buf)

TOP

reset a MkBufferC to the length zero … → API: MkBufferReset_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bufthe MkBufferS instance to work on
See also
void MkBufferResetFull(MK_BUF buf)

void MkBufferResetFull(MK_BUF buf)

TOP

reset a MkBufferC to the length zero and free allocated storage… → API: MkBufferResetFull_RT

In addition to void MkBufferReset(MK_BUF buf) the allocated storage is freed and reset to ILS

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bufthe MkBufferS instance to work on
See also
void MkBufferReset(MK_BUF buf)

MK_BUF MkBufferSizeAdd(MK_BUF buf, MK_NUM size)

TOP

add size storage to the buf … → API: MkBufferSizeAdd_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bufthe MkBufferS instance to work on
[in]sizeThe initial size of the instance-local-storage. The MkBufferC has dynamic-memory-management, the size value is just a hint to provide enought memory for future tasks. The real size created is the maximum of type-ILS-size and size . (default: 0 = use the type-ILS-size)
Returns
the input buf

MK_BUF MkBufferSizeNew(MK_BUF buf, MK_NUM size)

TOP

alloc min size storage to the buf … → API: MkBufferSizeNew_RT

Returns
the input buf
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bufthe MkBufferS instance to work on
[in]sizeThe initial size of the instance-local-storage. The MkBufferC has dynamic-memory-management, the size value is just a hint to provide enought memory for future tasks. The real size created is the maximum of type-ILS-size and size . (default: 0 = use the type-ILS-size)

MK_BUF MkBufferTemp(MK_BUFN buf)

TOP

create a temporary copy of the MkBufferC buf … → API: MkBufferTemp_RT

This function always return the same global memory from the per-thread-runtime-storage initialized with buf. This storage must not be freed and should only be used for temporary-short-time usage. In theory every function-call in the same thread could overwrite this memory.

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
buf- the source of the copy
Returns
the temporary buffer-object
Attention
The memory of the out-value belongs to the called LibMkKernel function and therefore never becomes NULL. For details on the out-value, see: MkKernel_Storage_C_API.

MK_STRN MkBufferToString(MK_BUFN buf)

TOP

get the string representation of the buf … → API: MkBufferToString_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bufthe MkBufferS instance to work on
Returns
the required string
Attention
~ The returned string is owned by self… do not free.
~ On error an empty string is returned.

MkBufferC SET

C-API: MkBufferC_Set_C_API - various functions to set buffer-data

MK_BUF MkBufferSetV(MK_BUF buf, MK_FST val, ... args)

TOP

Set the MkBufferC to the val … → API: MkBufferSetV_RT

The old value will be removed and the memory will be reset.

Returns
the MkBufferS object
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bufthe MkBufferS instance to work on
[in]valthe value to set the buf to
Precondition
val is from type c-string used as printf like format string

MK_BUF MkBufferSetVL(MK_BUF buf, MK_FST val, va_list var_list)

TOP

Set the MkBufferC to the val … → API: MkBufferSetVL_RT

The old value will be removed and the memory will be reset.

Returns
the MkBufferS object
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bufthe MkBufferS instance to work on
[in]valthe value to set the buf to
[in]var_lista variable argument list object
Precondition
val is a c-string used as printf like format string

MK_BUF MkBufferSetTT(MK_BUF buf, MK_BYT val)

The BufferSetTT provide a single function for every PRIMITIVE TYPE

returncommand

C-API :

MK_BUF MkBufferSetB(MK_BUF buf, MkBinaryR val)MkBufferSetB_RT
MK_BUF MkBufferSetC(MK_BUF buf, MK_STRN val)MkBufferSetC_RT
MK_BUF MkBufferSetD(MK_BUF buf, MK_DBL val)MkBufferSetD_RT
MK_BUF MkBufferSetF(MK_BUF buf, MK_FLT val)MkBufferSetF_RT
MK_BUF MkBufferSetI(MK_BUF buf, MK_INT val)MkBufferSetI_RT
MK_BUF MkBufferSetO(MK_BUF buf, MK_BOL val)MkBufferSetO_RT
MK_BUF MkBufferSetS(MK_BUF buf, MK_SRT val)MkBufferSetS_RT
MK_BUF MkBufferSetU(MK_BUF buf, MK_BUFN val)MkBufferSetU_RT
MK_BUF MkBufferSetW(MK_BUF buf, MK_WID val)MkBufferSetW_RT
MK_BUF MkBufferSetY(MK_BUF buf, MK_BYT val)

MkBufferSetY_RT

Set the MkBufferC to the val

The old value will be removed and the memory will be reset.

Returns
the MkBufferS object
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bufthe MkBufferS instance to work on
[in]valthe value to set the buf to

MkBufferC TOR

C-API: MkBufferC_TOR_C_API - various functions to create, initialize and destroy a MkBufferC

(constructor) MK_BUF MkBufferCreate(MK_TYP type, MK_NUM size)

TOP

Constructor - create a new MkBufferC with minimum size of internal storage … → API: MkBufferCreate_RT

The new instance belongs to the caller and may have to be released if necessary. A manual release using BufferDelete is always possible, but the instance can no longer be used afterwards.

There is a MkBufferCreateTT function for every PRIMITIVE TYPE.

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]typeA type defined as MkTypeS with a TT postfix (default: MkBuffer64S, possible: MkBuffer64S, MkBuffer256S and MkBuffer1024S)
[in]sizeThe initial size of the instance-local-storage. The MkBufferC has dynamic-memory-management, the size value is just a hint to provide enought memory for future tasks. The real size created is the maximum of type-ILS-size and size . (default: 0 = use the type-ILS-size)
Returns
The newly created MkBufferC instance, the instance is owned by the caller
See also
BufferDelete BufferDup MqReadU

(constructor) MK_BUF MkBufferCreate1024(MK_NUM size)

TOP

call the BufferCreate with default type MkBuffer1024S (1024 byte) … → API: MkBufferCreate1024_RT

(constructor) MK_BUF MkBufferCreate256(MK_NUM size)

TOP

call the BufferCreate with default type MkBuffer256S (256 byte) … → API: MkBufferCreate256_RT

(constructor) MK_BUF MkBufferCreate64(MK_NUM size)

TOP

call the BufferCreate with default type MkBuffer64S (64 byte) … → API: MkBufferCreate64_RT

(constructor) MK_BUF MkBufferCreateTLS(MK_INT tlsid)

TOP

same as BufferCreate but require no cleanup → API: MkBufferCreateTLS_RT

A TLS-instance only exists ONCE per thread and per TLS-function in memory. The memory will be reused and must not be freed.

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]tlsidAn per-thread unique name (integer > 0) to identify the reuse-able instance-storage. The tlsid have to be between: 0 <= tlsid < 32
Returns
the new MkBufferC instance, the instance belongs to the TLS-function and does not need to be deleted.
Note
This function is intended as a replacement for MkBufferCreateTLS_T for non-C programming languages.
Attention
for usage of the TLS-storage read more at StorageCreateTLS

(static) MK_BUF MkBufferFromHandle(MK_LONG exporthdl)

TOP

Import-Slot - returns a obj from a former exported handle → API: MkBufferFromHandle

Parameters
[in]exporthdlhandle former exported with ObjectToHandle
Returns
the required handle or NULL if handle is invalid

void MkBufferDelete(MK_BUF buf)

TOP

Destructor - delete a MkBufferC instance … → API: MkBufferDelete_RT

There are two different ways to delete an instance:

ObjectDisposeto free the internal data but keep the outher shell alive - this is called a SOFT-DELETE
ObjectDelete to delete the outher shell including the internal data - this is called a HARD-DELETE
Attention
  1. The internal memory will be freed and the object-pointer will be set to NULL. If the object-pointer is already NULL nothing will be done.
  2. For a programming language without HARD-Delete support, the "Delete" method is assigned to a SOFT-Delete.
  3. For a programming language without garbage collection, a SOFT-delete without a HARD-delete causes a small memory loss (C++: ~32 bytes).
  4. After a SOFT-delete, the outher shell is still alive, but cannot be used. Any access to this shell generates an HDL-null-exception, but this exception can be caught. This is important for C++ as it prevents a core dump.
  5. On HARD-delete read more at SelfDeleteForce
See also
BufferCreate BufferDup MqReadU

(constructor) MK_BUF MkBufferDup(MK_BUFN buf)

TOP

Dup-Constructor - create a new MkBufferC instance as copy from an existing MkBufferC instance → API: MkBufferDup_RT

The new instance belongs to the caller and may have to be released if necessary. A manual release using BufferDelete is always possible, but the instance can no longer be used afterwards.

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bufthe MkBufferS instance to work on
Returns
The newly created MkBufferC instance, the instance is owned by the caller
See also
ObjDup BufferDelete

(constructor) MK_BUF MkBufferMerge(MK_BUF buf)

TOP

Merge-Constructor - create a new MkBufferC as a merge from an existing object … → API: MkBufferMerge_RT

The Merge-Constructor create a new instance and merge all internal data from the src into the new instance. After the Merge-Constructor the BufferResetFull is called for the merge-source bus.

One usage of the Merge-Constructor is to get a lightweight-copy of a Thread-Local-Storage object for external usage.

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bufthe MkBufferS instance to work on
Returns
The new instance or NULL on error or if no Merge-Constructor is available
Attention
The new instance have to be deleted with BufferDelete
See also
BufferDup BufferResetFull BufferDelete

(constructor) MK_BUF MkBufferCreateTT(MK_BYT val)

The BufferCreateTT provide a single function for every PRIMITIVE TYPE

returncommand

C-API :

(constructor) MK_BUF MkBufferCreateB(MkBinaryR val)MkBufferCreateB_RT
(constructor) MK_BUF MkBufferCreateC(MK_STRN val)MkBufferCreateC_RT
(constructor) MK_BUF MkBufferCreateD(MK_DBL val)MkBufferCreateD_RT
(constructor) MK_BUF MkBufferCreateF(MK_FLT val)MkBufferCreateF_RT
(constructor) MK_BUF MkBufferCreateI(MK_INT val)MkBufferCreateI_RT
(constructor) MK_BUF MkBufferCreateO(MK_BOL val)MkBufferCreateO_RT
(constructor) MK_BUF MkBufferCreateS(MK_SRT val)MkBufferCreateS_RT
(constructor) MK_BUF MkBufferCreateU(MK_BUFN val)MkBufferCreateU_RT
(constructor) MK_BUF MkBufferCreateW(MK_WID val)MkBufferCreateW_RT
(constructor) MK_BUF MkBufferCreateY(MK_BYT val)

MkBufferCreateY_RT

Constructor - create a new MkBufferC with an PRIMITIVE TYPE

The new instance belongs to the caller and may have to be released if necessary. A manual release using BufferDelete is always possible, but the instance can no longer be used afterwards.

Returns
The newly created MkBufferC instance, the instance is owned by the caller
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]valthe PRIMITIVE TYPE object as data-source

MkBufferStreamC

MkBufferStreamC INTROSPECTION

Instancesget head-instance from linked-list of MkBufferStreamS type …
Nextget next instance from linked-list of MkBufferStreamS type
Prev

get previous instance from linked-list of MkBufferStreamS type

MkBufferStreamC MISC

Copycopy the MkBufferStreamC from src to bus
Loglog the MkBufferStreamC
PosToStartset the current-access-position to the start of MkBufferStreamC
Resetreset a MkBufferStreamC to the length zero …
ResetFull

reset a MkBufferStreamC to the length zero and free allocated storage…

MkBufferStreamC READ

ReadALLget a temporary MkBufferListC from all data in the MkBufferStreamC
ReadGetNextTypeget the type (MkTypeE) of the next Item in the MkBufferStreamC or "0" if not available
ReadGetNumItemsget the number of items left in the MkBufferStreamC
ReadItemExistscheck if an item exists in the read-data-package
ReadLONGread the long native object from the MkBufferStreamC
ReadL_ENDEND read a list-item-type from the MkBufferStreamC
ReadL_STARTSTART read a list-item-type from the MkBufferStreamC
ReadUndoundo the last MkBufferStreamC READ function call …
ReadTT

read a val_out from the MkBufferStreamC

MkBufferStreamC TOR

Createcreate and initialize an MkBufferStreamC instance …
Create1024call the BufferStreamCreate with default type MkBufferStream1024S (1024 byte) …
Create16384call the BufferStreamCreate with default type MkBufferStream16384S (16384 byte) …
Create256call the BufferStreamCreate with default type MkBufferStream256S (256 byte) …
Create64call the BufferStreamCreate with default type MkBufferStream64S (64 byte) …
CreateTLSsame as BufferStreamCreate but require no cleanup …
FromHandleImport-Slot - returns a obj from a former exported handle
DeleteDestructor - delete a MkBufferStreamC instance …
DupDup-Constructor - create a new MkBufferStreamC instance as copy from an existing MkBufferStreamC instance …
Merge

Merge-Constructor - create a new MkBufferStreamC as a merge from an existing object …

MkBufferStreamC WRITE

WriteLONGwrite the long native object into the MkBufferStreamC
WriteL_ENDEND write a list-item-type into the MkBufferStreamC
WriteL_FLATwrite a MkBufferListC FLAT into the MkBufferStreamC
WriteL_STARTSTART write a list-item-type into the MkBufferStreamC
WriteVwrite format-string into the MkBufferStreamC
WriteVLwrite format-string into the MkBufferStreamC
WriteTT

write a PRIMITIVE TYPE into the MkBufferStreamC

MkBufferStreamC DETAIL

C-API: MkBufferStreamC_C_API - The MkBufferStreamC object known as bus or stream is a subclass of MkBufferC used for package-based-io

The MkBufferStreamC is required to send data via a socket (pipe,tcp,uds,...). The data is organized as a continuous binary-array. Each item is preceded by type and, if applicable, size information.

‍See also: MkBufferC, MkBufferListC

C-Kernel-Details

The ABSTRACT-CLASS MkBufferStreamS has the private-parent-class MkBufferS and is used to store typed-data in a continuous binary-array at MkBufferS::storage.

private-parent-class mean:
MkBufferStreamS use the features of MkBufferS but does not expose the API

In addition to the binary-array the MkBufferStreamS also include features like:

  1. the encoding: MkBufferStreamS::endian_is_wrong
  2. the total number of items: MkBufferStreamS::numItems
  3. current position pointer: MkBufferStreamS::cur
  4. support for recursion: embedding a MkBufferStreamS into a MkBufferStreamS

The MkBufferStreamS inherits the following features from MkBufferS:

  1. the storage: MkBufferS::storage
  2. the type: MkBufferS::type
  3. the ILS: MkBufferS::ils

The ABSTRACT-CLASS MkBufferStreamS is missing the ILS-storage, the FINAL-CLASSES are:

MkBufferStream16384S, MkBufferStream256S, MkBufferStream64S and MkBufferStream1024S

See also
MkBufferC, MkBufferListC

MkBufferStreamC INTROSPECTION

C-API: MkBufferStreamC_Introspection_C_API - Get information from the MkTypeS.

Get information about all instances created by class

Get information about all instances created by class

The Introspection API is used to get information about the details of the instance and type implementation. Only the connection between type and instance is currently implemented.

Three methods are used to create an iteration over all avaialable instances of a type.

  • Every class has a Linked-List of all instances created starting from last to first.
  • The Introspection support always 3 Functions per class: Instance (static), Next and Prev
  • The Instance (example: (static) MK_BUF MkBufferInstances(void))
    • return the last-instance created or NULL if no instance was created.
  • The Next (example: MK_BUF MkBufferNext(MK_BUF buf))
    • return the next-instance for a given-instance or NULL if the given-instance is the last-instance.
  • The Prev (example: MK_BUF MkBufferPrev(MK_BUF buf))
    • return the previous-instance for a given-instance or NULL if the given-instance is the first-instance.

Example: a simple loop over all instances of class MkBufferC (language C++)

for (auto buf = MkBufferC::Instances(); buf != NULL; buf = buf->Next()) {
SendC(buf->ToString());
}

(static) MK_BUS MkBufferStreamInstances(void)

TOP

get head-instance from linked-list of MkBufferStreamS type … → API: MkBufferStreamInstances

The head-instance is the last instance created.

MK_BUS MkBufferStreamNext(MK_BUS bus)

TOP

get next instance from linked-list of MkBufferStreamS type → API: MkBufferStreamNext

MK_BUS MkBufferStreamPrev(MK_BUS bus)

TOP

get previous instance from linked-list of MkBufferStreamS type → API: MkBufferStreamPrev

MkBufferStreamC MISC

C-API: MkBufferStreamC_Misc_C_API - various functions to create and destroy a MkBufferStreamC

MK_BUS MkBufferStreamCopy(MK_BUS bus, MK_BUSN src)

TOP

copy the MkBufferStreamC from src to bus … → API: MkBufferStreamCopy_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]busthe MkBufferStreamS instance to work on
srcsource of the copy
Returns
the bus instance

void MkBufferStreamLog(MK_BUS bus, MK_OBJN fmtobj, MK_DBG debug, MK_STRN callfunc, MK_INT lvl)

TOP

log the MkBufferStreamC … → API: MkBufferStreamLog_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]busthe MkBufferStreamS instance to work on
[in]fmtobjmanaged object used to format the log-message (default=NULL = use default format)
[in]debugthe debug level from MkRuntimeS::debug, use 0 <= debug <= 9 (default=0)
[in]callfunca user-defined postfix to identify the calling function or the environment (default=name-of-function)
[in]lvla user-defined prefix starting with "" for lvl=0 and increase with " " for lvl+1 (default=0)

void MkBufferStreamPosToStart(MK_BUS bus)

TOP

set the current-access-position to the start of MkBufferStreamC … → API: MkBufferStreamPosToStart_RT

void MkBufferStreamReset(MK_BUS bus)

TOP

reset a MkBufferStreamC to the length zero … → API: MkBufferStreamReset_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]busthe MkBufferStreamS instance to work on
See also
void MkBufferStreamResetFull(MK_BUS bus)

void MkBufferStreamResetFull(MK_BUS bus)

TOP

reset a MkBufferStreamC to the length zero and free allocated storage… → API: MkBufferStreamResetFull_RT

In addition to void MkBufferStreamReset(MK_BUS bus) the allocated storage is freed and reset to ILS. This is usefull if the internal storage was filled once with a huge amount of data.

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]busthe MkBufferStreamS instance to work on
See also
void MkBufferStreamReset(MK_BUS bus)

MkBufferStreamC READ

C-API: MkBufferStreamC_Read_C_API - various functions to 'read' data from a MkBufferStreamC

Read is done at the position of MkBufferStreamS::storage->cur. After read the cur is incemented with read-sizeof characters.

enum MkErrorE MkBufferStreamReadALL(MK_BUS bus, MK_BFL* val_inout)

TOP

get a temporary MkBufferListC from all data in the MkBufferStreamC … → API: MkBufferStreamReadALL_RT

If the val_inout is NULL than a temporary MkBufferListC is returned. If the val_inout is not NULL than the memory of the val_inout is reused.

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]busthe MkBufferStreamS instance to work on
[in,out]val_inoutthe MkBufferListC - the storage of the input is reused
Returns
set the MkErrorC to the status MK_OK, MK_CONTINUE or MK_ERROR
See also
BufferStreamReadL
Attention
The memory of the out-value belongs to the called LibMkKernel function and therefore never becomes NULL. For details on the out-value, see: MkKernel_Storage_C_API.

enum MkTypeE MkBufferStreamReadGetNextType(MK_BUSN bus)

TOP

get the type (MkTypeE) of the next Item in the MkBufferStreamC or "0" if not available → API: MkBufferStreamReadGetNextType_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]busthe MkBufferStreamS instance to work on
Returns
the type

MK_NUM MkBufferStreamReadGetNumItems(MK_BUSN bus)

TOP

get the number of items left in the MkBufferStreamC … → API: MkBufferStreamReadGetNumItems_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]busthe MkBufferStreamS instance to work on
Returns
the number of items as integer

MK_BOOL MkBufferStreamReadItemExists(MK_BUSN bus)

TOP

check if an item exists in the read-data-package … → API: MkBufferStreamReadItemExists_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]busthe MkBufferStreamS instance to work on
Returns
boolean, MK_YES or MK_NO

enum MkErrorE MkBufferStreamReadLONG(MK_BUS bus, MK_LONG* val_out)

TOP

read the long native object from the MkBufferStreamC … → API: MkBufferStreamReadLONG_RT

on 64bit use a BufferStreamReadI and on 32bit use a BufferStreamReadW

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]busthe MkBufferStreamS instance to work on
[out]val_outthe native long object to read
Returns
set the MkErrorC to the status MK_OK, MK_CONTINUE or MK_ERROR
Attention
this api-function is NOT portable
See also
enum MkErrorE MkBufferStreamWriteLONG(MK_BUS bus, MK_LONG val)

enum MkErrorE MkBufferStreamReadL_END(MK_BUS bus)

TOP

END read a list-item-type from the MkBufferStreamC … → API: MkBufferStreamReadL_END_RT

enum MkErrorE MkBufferStreamReadL_START(MK_BUS bus, MK_BUF buf)

TOP

START read a list-item-type from the MkBufferStreamC … → API: MkBufferStreamReadL_START_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]busthe MkBufferStreamS instance to work on
[in]bufNULL or a MkBufferC with a list-item-type or an error is raised.
Returns
set the MkErrorC to the status MK_OK, MK_CONTINUE or MK_ERROR

enum MkErrorE MkBufferStreamReadUndo(MK_BUS bus)

TOP

undo the last MkBufferStreamC READ function call … → API: MkBufferStreamReadUndo_RT

Decrement the current-access-position by one, to the start of the last read body-item. The next read function call will extract the same item again. Only one undo level is supported.

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]busthe MkBufferStreamS instance to work on
Returns
set the MkErrorC to the status MK_OK, MK_CONTINUE or MK_ERROR

enum MkErrorE MkBufferStreamReadTT(MK_BUS bus, MK_BYT* val_out)

The BufferStreamReadTT provide a single function for every PRIMITIVE TYPE

returncommand

C-API :

enum MkErrorE MkBufferStreamReadB(MK_BUS bus, MkBinaryR* val_out)MkBufferStreamReadB_RT
enum MkErrorE MkBufferStreamReadC(MK_BUS bus, MK_STRN* val_out)MkBufferStreamReadC_RT
enum MkErrorE MkBufferStreamReadD(MK_BUS bus, MK_DBL* val_out)MkBufferStreamReadD_RT
enum MkErrorE MkBufferStreamReadF(MK_BUS bus, MK_FLT* val_out)MkBufferStreamReadF_RT
enum MkErrorE MkBufferStreamReadI(MK_BUS bus, MK_INT* val_out)MkBufferStreamReadI_RT
enum MkErrorE MkBufferStreamReadL(MK_BUS bus, MK_BFL* val_out)MkBufferStreamReadL_RT
enum MkErrorE MkBufferStreamReadO(MK_BUS bus, MK_BOL* val_out)MkBufferStreamReadO_RT
enum MkErrorE MkBufferStreamReadU(MK_BUS bus, MK_BUF* val_out)MkBufferStreamReadU_RT
enum MkErrorE MkBufferStreamReadW(MK_BUS bus, MK_WID* val_out)MkBufferStreamReadW_RT
enum MkErrorE MkBufferStreamReadY(MK_BUS bus, MK_BYT* val_out)

MkBufferStreamReadY_RT

read a val_out from the MkBufferStreamC

The MkBufferStreamReadTT style of functions always return a val_out or a MkErrorC.

Precondition
The val_out can be a PRIMITIVE TYPE, a class-type or a pointer-type (binary, string etc).
After every read the current-access-position is incremented by one to get the next item for the next read.
To reset the current-access-position to the start use void MkBufferStreamPosToStart(MK_BUS bus).
Returns
set the MkErrorC to the status MK_OK, MK_CONTINUE or MK_ERROR
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]busthe MkBufferStreamS instance to work on
[out]val_outthe new value

MkBufferStreamC TOR

C-API: MkBufferStreamC_TOR_C_API - various functions to create and destroy a MkBufferStreamC

(constructor) MK_BUS MkBufferStreamCreate(MK_TYP type, MK_NUM size)

TOP

create and initialize an MkBufferStreamC instance … → API: MkBufferStreamCreate_RT

The new instance belongs to the caller and may have to be released if necessary. A manual release using BufferStreamDelete is always possible, but the instance can no longer be used afterwards.

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]typeA type defined as MkTypeS with a TT postfix (default: MkBufferStream1024S, possible: MkBufferStream16384S, MkBufferStream256S, MkBufferStream64S and MkBufferStream1024S)
[in]sizeThe initial size of the instance-local-storage. The MkBufferStreamC has dynamic-memory-management, the size value is just a hint to provide enought memory for future tasks. The real size created is the maximum of type-ILS-size and size . (default: 0 = use the type-ILS-size)
Returns
The newly created MkBufferStreamC instance, the instance is owned by the caller

(constructor) MK_BUS MkBufferStreamCreate1024(MK_NUM size)

TOP

call the BufferStreamCreate with default type MkBufferStream1024S (1024 byte) … → API: MkBufferStreamCreate1024_RT

(constructor) MK_BUS MkBufferStreamCreate16384(MK_NUM size)

TOP

call the BufferStreamCreate with default type MkBufferStream16384S (16384 byte) … → API: MkBufferStreamCreate16384_RT

(constructor) MK_BUS MkBufferStreamCreate256(MK_NUM size)

TOP

call the BufferStreamCreate with default type MkBufferStream256S (256 byte) … → API: MkBufferStreamCreate256_RT

(constructor) MK_BUS MkBufferStreamCreate64(MK_NUM size)

TOP

call the BufferStreamCreate with default type MkBufferStream64S (64 byte) … → API: MkBufferStreamCreate64_RT

(constructor) MK_BUS MkBufferStreamCreateTLS(MK_NUM tlsid)

TOP

same as BufferStreamCreate but require no cleanup … → API: MkBufferStreamCreateTLS_RT

A TLS-instance only exists ONCE per thread and per TLS-function in memory. The memory will be reused and must not be freed.

The new BufferStreamCreateTLS instance is ready to use and does NOT require a BufferStreamReset first and a BufferStreamDelete last.

By default the MkBufferStream64S type is used as an array of references (struct MkBufferStream64S and not struct MkBufferStream64S *). If the memory requirement exceed the predefined-storage of the MkBufferStream64S the memory is allocated on the heap.

Example from perfserver.c performance test with TLS storage

static enum MkErrorE
Ot_BUST ( MQ_CALLBACK_SERVICE_CALL_ARGS )
{
  MK_BUS bus = MkBufferStreamCreateTLS(0);

  while (MqReadItemExists(mqctx)) {
    MkBufferStreamWriteU(bus,MqReadU_e(mqctx));
  }

  MkBufferStreamPosToStart(bus);

  MqSendSTART_E (mqctx);
  while (MkBufferStreamReadItemExists(bus)) {
    MqSendU_E (mqctx, MkBufferStreamReadU_e (bus));
  }

error:
  return MqSendRETURN (mqctx);
}
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]tlsidAn per-thread unique name (integer > 0) to identify the reuse-able instance-storage. The tlsid have to be between: 0 <= tlsid < 32
Returns
the new MkBufferStreamC instance, the instance belongs to the TLS-function and does not need to be deleted.
Attention
for usage of the TLS-storage read more at StorageCreateTLS

(static) MK_BUS MkBufferStreamFromHandle(MK_LONG exporthdl)

TOP

Import-Slot - returns a obj from a former exported handle → API: MkBufferStreamFromHandle

Parameters
[in]exporthdlhandle former exported with ObjectToHandle
Returns
the required handle or NULL if handle is invalid

void MkBufferStreamDelete(MK_BUS bus)

TOP

Destructor - delete a MkBufferStreamC instance … → API: MkBufferStreamDelete_RT

There are two different ways to delete an instance:

ObjectDisposeto free the internal data but keep the outher shell alive - this is called a SOFT-DELETE
ObjectDelete to delete the outher shell including the internal data - this is called a HARD-DELETE
Attention
  1. The internal memory will be freed and the object-pointer will be set to NULL. If the object-pointer is already NULL nothing will be done.
  2. For a programming language without HARD-Delete support, the "Delete" method is assigned to a SOFT-Delete.
  3. For a programming language without garbage collection, a SOFT-delete without a HARD-delete causes a small memory loss (C++: ~32 bytes).
  4. After a SOFT-delete, the outher shell is still alive, but cannot be used. Any access to this shell generates an HDL-null-exception, but this exception can be caught. This is important for C++ as it prevents a core dump.
  5. On HARD-delete read more at SelfDeleteForce
See also
BufferStreamCreate BufferStreamDup

(constructor) MK_BUS MkBufferStreamDup(MK_BUSN src)

TOP

Dup-Constructor - create a new MkBufferStreamC instance as copy from an existing MkBufferStreamC instance … → API: MkBufferStreamDup_RT

The new instance belongs to the caller and may have to be released if necessary. A manual release using BufferStreamDelete is always possible, but the instance can no longer be used afterwards.

Returns
The newly created MkBufferStreamC instance, the instance is owned by the caller
See also
ObjDup BufferStreamDelete

(constructor) MK_BUS MkBufferStreamMerge(MK_BUS bus)

TOP

Merge-Constructor - create a new MkBufferStreamC as a merge from an existing object … → API: MkBufferStreamMerge_RT

The Merge-Constructor create a new instance and merge all internal data from the src into the new instance. After the Merge-Constructor the BufferStreamResetFull is called for the merge-source bus.

One usage of the Merge-Constructor is to get a lightweight-copy of a Thread-Local-Storage object for external usage.

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]busthe MkBufferStreamS instance to work on - (nonnull)
Returns
The new instance or NULL on error or if no Merge-Constructor is available
Attention
The new instance have to be deleted with BufferStreamDelete
See also
BufferStreamDup BufferStreamResetFull BufferStreamDelete

MkBufferStreamC WRITE

C-API: MkBufferStreamC_Write_C_API - various functions to write into a MkBufferStreamC

Write is done at the position of MkBufferStreamS::storage->cur. After write the cur is incemented with write-sizeof characters.

enum MkErrorE MkBufferStreamWriteLONG(MK_BUS bus, MK_LONG val)

TOP

write the long native object into the MkBufferStreamC … → API: MkBufferStreamWriteLONG_RT

on 64bit use a BufferStreamWriteW and on 32bit use a BufferStreamWriteI

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]busthe MkBufferStreamS instance to work on
[in]valthe native long object to write
Returns
set the MkErrorC to the status MK_OK, MK_CONTINUE or MK_ERROR
Attention
this api-function is NOT portable
See also
enum MkErrorE MkBufferStreamReadLONG(MK_BUS bus, MK_LONG* val_out)

enum MkErrorE MkBufferStreamWriteL_END(MK_BUS bus)

TOP

END write a list-item-type into the MkBufferStreamC … → API: MkBufferStreamWriteL_END_RT

enum MkErrorE MkBufferStreamWriteL_FLAT(MK_BUS bus, MK_BFL bfl)

TOP

write a MkBufferListC FLAT into the MkBufferStreamC … → API: MkBufferStreamWriteL_FLAT_RT

A MkBufferListC can be written into a MkBufferStreamC using:

command description example
BufferStreamWriteL one item as list-item-type … [ itm1 itm2 itm3 itm4 ] …
BufferStreamWriteL_FLAT a sequence of single items … itm1 itm2 itm3 itm4 …

The second is called FLAT because the shell of the list-item-type is missing .

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]busthe MkBufferStreamS instance to work on
[in]bflthe MkBufferListC to insert
Returns
set the MkErrorC to the status MK_OK, MK_CONTINUE or MK_ERROR
See also
BufferStreamReadL BufferStreamReadL

enum MkErrorE MkBufferStreamWriteL_START(MK_BUS bus)

TOP

START write a list-item-type into the MkBufferStreamC … → API: MkBufferStreamWriteL_START_RT

enum MkErrorE MkBufferStreamWriteV(MK_BUS bus, MK_STRN fmt, ... args)

TOP

write format-string into the MkBufferStreamC … → API: MkBufferStreamWriteV_RT

enum MkErrorE MkBufferStreamWriteVL(MK_BUS bus, MK_STRN fmt, va_list ap)

TOP

write format-string into the MkBufferStreamC … → API: MkBufferStreamWriteVL_RT

enum MkErrorE MkBufferStreamWriteTT(MK_BUS bus, MK_BYT val)

The BufferStreamWriteTT provide a single function for every PRIMITIVE TYPE

returncommand

C-API :

enum MkErrorE MkBufferStreamWriteB(MK_BUS bus, MkBinaryR val)MkBufferStreamWriteB_RT
enum MkErrorE MkBufferStreamWriteC(MK_BUS bus, MK_STRN val)MkBufferStreamWriteC_RT
enum MkErrorE MkBufferStreamWriteD(MK_BUS bus, MK_DBL val)MkBufferStreamWriteD_RT
enum MkErrorE MkBufferStreamWriteF(MK_BUS bus, MK_FLT val)MkBufferStreamWriteF_RT
enum MkErrorE MkBufferStreamWriteI(MK_BUS bus, MK_INT val)MkBufferStreamWriteI_RT
enum MkErrorE MkBufferStreamWriteL(MK_BUS bus, MK_BFL bfl)MkBufferStreamWriteL_RT
enum MkErrorE MkBufferStreamWriteO(MK_BUS bus, MK_BOL val)MkBufferStreamWriteO_RT
enum MkErrorE MkBufferStreamWriteU(MK_BUS bus, MK_BUF val)MkBufferStreamWriteU_RT
enum MkErrorE MkBufferStreamWriteW(MK_BUS bus, MK_WID val)MkBufferStreamWriteW_RT
enum MkErrorE MkBufferStreamWriteY(MK_BUS bus, MK_BYT val)

MkBufferStreamWriteY_RT

write a PRIMITIVE TYPE into the MkBufferStreamC

After every write the current-access-position is incremented by one, use void MkBufferStreamReset(MK_BUS bus) to reset.

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]busthe MkBufferStreamS instance to work on
[in]valthe new PRIMITIVE TYPE
Returns
set the MkErrorC to the status MK_OK, MK_CONTINUE or MK_ERROR

MkBufferListC

MkBufferListC APPEND

AppendGappend a native PRIMITIVE TYPE object to a MkBufferListC
AppendLAappend a variable number of MkBufferC object's to an MkBufferListC object using an other MkBufferListC OR a list of arguments (only in NON MK_STR)
AppendLPcopy a MkBufferListS list into an MkBufferListS object on position
AppendUPappend a MkBufferC item into an MkBufferListC object on position
AppendVappend an printf like format object to the end of an MkBufferListS object …
AppendVAappend a variable number of strings to an MkBufferListS object …
AppendVALappend a variable number of strings to an MkBufferListS object …
AppendVCappend a argc/argv list of strings to an MkBufferListS object …
AppendVLappend an printf like format object to the end of an MkBufferListS object …
AppendTTappend a native PRIMITIVE TYPE object to a MkBufferListC
PositionMerge

merge a MkBufferListS list into an MkBufferListS object on position

MkBufferListC CHECK

CheckOptionsearch for boolean option in MkBufferListS list and return MK_BOL value …
CheckOptionTT

search for opt in MkBufferListS list and fill var with opt_argument or the defval value …

MkBufferListC INDEX

IndexDeletedelete the index'th list item from the MkBufferListS object …
IndexExtractextract (read & delete) the index object from bfl
IndexGetget (read only) the index object from bfl
IndexGetCget the index element from MkBufferListC ... as string. …
IndexGetUget the index element from MkBufferListC ... if not available… create it. …
IndexSetset the index object from bfl
IndexSetCset the index element from MkBufferListC ... to string… if not available… create space …
IndexSetUset the index element from MkBufferListC ... if not available… createspace …
Reservereserve num items in a MkBufferListC object …
Size

get the number-of-items in the bfl

MkBufferListC INTROSPECTION

Instancesget head-instance from linked-list of MkBufferListS type …
Nextget next instance from linked-list of MkBufferListS type
Prev

get previous instance from linked-list of MkBufferListS type

MkBufferListC LOG

Logwrite the detail-summary of the MkBufferListC to MkLogFileC (default: stderr) …
LogSwrite the short-summary of the MkBufferListC to MkLogFileC (default: stderr) …
LogSSwrite the very-short-summary of the MkBufferListC to MkLogFileC (default: stderr) …
LogSSS

write the very-very-short-summary of the MkBufferListC to MkLogFileC (default: stderr) …

MkBufferListC MISC

Cmpcompare two buffer-list
Copycopy all internal data from src to tgt
Movemove all internal data from from to the end of to
Resetreset a MkBufferListC object …
SearchCsearch MK_STR item from a MkBufferListS object starting at startindex
Sortsort a MkBufferListC
ToBufferExport a bfl into an MkBufferC using an MkBufferStreamC
ToList

get a target-language list representation of the bfl

MkBufferListC TOR

CreateConstructs a MkBufferC instance with size storage…
CreateLAConstructs a MkBufferListC instance with an other MkBufferListC OR a list of arguments (only in NON MK_STR)
CreateTLSsame as BufferListCreate but require no cleanup …
CreateVAConstructs a MkBufferListC instance with a varargs argument that ends with NULL
CreateVALConstructs a MkBufferListC instance with a va_list argument …
CreateVCConstructs a MkBufferListC instance with a argc/argv data from a list of strings …
FileGlobcreate a new MkBufferListC using the result from a filesystem glob operation …
FromHandleImport-Slot - returns a obj from a former exported handle
DeleteDestructor - delete a MkBufferListC instance …
DupDup-Constructor - create a new MkBufferListC instance as copy from an existing MkBufferListC instance …
Merge

Merge-Constructor - constructs a MkBufferListC instance as a merge from an existing MkBufferListC instance …

MkBufferListC DETAIL

C-API: MkBufferListC_C_API - The MkBufferListC object known as bfl or buffer-list is used to create and manage a list of MkBufferC

The MkBufferListC is used to store a list of MkBufferC data into an array. In contrast to the MkBufferStreamC, each individual item can be accessed directly with the MkBufferListC.

MkBufferListS CLASS

The CLASS used to store a list of MkBufferS items into a flat array…

C-Kernel-Details

The CLASS MkBufferListS is used to store a list of MkBufferS into an MkBufferListS::data array. To access an MkBufferS item use:

‍0 <= index < MkBufferListS::cursize

A new MkBufferListS is always preallocated with the predefined ILS-storage (MkBufferListS::bls), but can switch to a MALLOC-storage if the storage requirements of the user exceed the predefined ILS-storage-size (MkBufferListS_bls_size).

‍A MkBufferListS never run out of storage.

See also
MkBufferC, MkBufferStreamC

MkBufferListS CTOR / DTOR

command alias
(constructor) MK_BFL MkBufferListCreate(MK_NUM size) no
void MkBufferListDelete(MK_BFL bfl) no

MkBufferListC APPEND

C-API: MkBufferListC_Append_C_API - various functions to 'append' on a MkBufferListC

void MkBufferListAppendG(MK_BFL bfl, MK_LONG val)

TOP

append a native PRIMITIVE TYPE object to a MkBufferListC … → API: MkBufferListAppendG_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
[in]valthe PRIMITIVE TYPE object data to append

MK_BFL MkBufferListAppendLA(MK_BFL bfl, MK_BAC args)

TOP

append a variable number of MkBufferC object's to an MkBufferListC object using an other MkBufferListC OR a list of arguments (only in NON MK_STR) → API: MkBufferListAppendLA_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
[in]argsthe MkBufferListC object

MK_BFL MkBufferListAppendLP(MK_BFL bfl, MK_BFL addBufL, MK_NUM position)

TOP

copy a MkBufferListS list into an MkBufferListS object on position … → API: MkBufferListAppendLP_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
[in]addBufLthe MkBufferListS object to append
[in]positioninsert in at position, shift all following arguments one up
Attention
Set position to 0 to append to the beginning or set position to -1 to append to the end

void MkBufferListAppendUP(MK_BFL bfl, MK_BUF addBuf, MK_NUM position)

TOP

append a MkBufferC item into an MkBufferListC object on position … → API: MkBufferListAppendUP_RT

- set position to 0 to append to the beginning

  • set position to -1 to append to the end
  • after append the addBuf belongs to bfl
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
[in]addBufthe MkBufferC object to append
[in]positioninsert in at position, shift all following arguments one up
Attention
After append the object addBuf will be owned by bfl.

void MkBufferListAppendV(MK_BFL bfl, MK_FST printfmt, ... args)

TOP

append an printf like format object to the end of an MkBufferListS object … → API: MkBufferListAppendV_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
[in]printfmtis a c-string used as printf like format string

MK_BFL MkBufferListAppendVA(MK_BFL bfl, MK_STRN arg0, ... args)

TOP

append a variable number of strings to an MkBufferListS object … → API: MkBufferListAppendVA_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
[in]arg0anchor element for ...
Attention
The C-Api requires a NULL item on end to signal… end-of-list.

MK_BFL MkBufferListAppendVAL(MK_BFL bfl, MK_STRN arg0, va_list var_list)

TOP

append a variable number of strings to an MkBufferListS object … → API: MkBufferListAppendVAL_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
[in]arg0anchor element for ...
[in]var_lista variable argument list object
Attention
The C-Api requires a NULL item on end to signal… end-of-list.

MK_BFL MkBufferListAppendVC(MK_BFL bfl, ME_VCV argv)

TOP

append a argc/argv list of strings to an MkBufferListS object … → API: MkBufferListAppendVC_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
[in]argcthe length of the argv array
[in]argvthe strings to append

void MkBufferListAppendVL(MK_BFL bfl, MK_FST printfmt, va_list var_list)

TOP

append an printf like format object to the end of an MkBufferListS object … → API: MkBufferListAppendVL_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
[in]printfmtis a c-string used as printf like format string
[in]var_lista variable argument list object

MK_BFL MkBufferListPositionMerge(MK_BFL bfl, MK_BFL source, MK_NUM position)

TOP

merge a MkBufferListS list into an MkBufferListS object on position … → API: MkBufferListPositionMerge_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
[in]sourcethe object to be merged into bfl, afterwords the source is empty and can be deleted
[in]positioninsert in at position, shift all following arguments one up. Set position to 0 to append to the beginning or set position to -1 to append to the end

void MkBufferListAppendTT(MK_BFL bfl, MK_BYT val)

The BufferListAppendTT provide a single function for every PRIMITIVE TYPE

returncommand

C-API :

void MkBufferListAppendC(MK_BFL bfl, MK_STRN val)MkBufferListAppendC_RT
void MkBufferListAppendD(MK_BFL bfl, MK_DBL val)MkBufferListAppendD_RT
void MkBufferListAppendF(MK_BFL bfl, MK_FLT val)MkBufferListAppendF_RT
void MkBufferListAppendI(MK_BFL bfl, MK_INT val)MkBufferListAppendI_RT
void MkBufferListAppendO(MK_BFL bfl, MK_BOL val)MkBufferListAppendO_RT
void MkBufferListAppendS(MK_BFL bfl, MK_SRT val)MkBufferListAppendS_RT
void MkBufferListAppendU(MK_BFL bfl, MK_BUF val)MkBufferListAppendU_RT
void MkBufferListAppendW(MK_BFL bfl, MK_WID val)MkBufferListAppendW_RT
void MkBufferListAppendY(MK_BFL bfl, MK_BYT val)

MkBufferListAppendY_RT

append a native PRIMITIVE TYPE object to a MkBufferListC

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
[in]valthe PRIMITIVE TYPE object data to append

MkBufferListC CHECK

C-API: MkBufferListC_Check_C_API - various functions to 'check' a MkBufferListC

This functions are used for parsing command-line-arguments.

MK_BOOL MkBufferListCheckOption(MK_BFL bfl, MK_STRN opt, MK_BOOL onlyFirst)

TOP

search for boolean option in MkBufferListS list and return MK_BOL value … → API: MkBufferListCheckOption_RT

-# If opt is found, the opt is deleted from the MkBufferListC.

  1. If opt starting with a - or a -- the opt is treated as true
  2. If opt starting with a + or a ++ the opt is treated as false
  3. If opt does not start with a - or a + than the opt is treated as true
  4. It multiple opt are available all opt are checked and deleted.
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on or NULL
[in]optFind opt string in the MkBufferListC
[in]onlyFirstStop after first item was found

enum MkErrorE MkBufferListCheckOptionTT(MK_BFL bfl, MK_STRN opt, MK_BYT defval, MK_BOOL onlyFirst, MK_BYT* val_out)

The BufferListCheckOptionTT provide a single function for every PRIMITIVE TYPE

returncommand

C-API :

enum MkErrorE MkBufferListCheckOptionC(MK_BFL bfl, MK_STRN opt, MK_STRN defval, MK_BOOL onlyFirst, MK_STRN* val_out)MkBufferListCheckOptionC_RT
enum MkErrorE MkBufferListCheckOptionD(MK_BFL bfl, MK_STRN opt, MK_DBL defval, MK_BOOL onlyFirst, MK_DBL* val_out)MkBufferListCheckOptionD_RT
enum MkErrorE MkBufferListCheckOptionF(MK_BFL bfl, MK_STRN opt, MK_FLT defval, MK_BOOL onlyFirst, MK_FLT* val_out)MkBufferListCheckOptionF_RT
enum MkErrorE MkBufferListCheckOptionI(MK_BFL bfl, MK_STRN opt, MK_INT defval, MK_BOOL onlyFirst, MK_INT* val_out)MkBufferListCheckOptionI_RT
enum MkErrorE MkBufferListCheckOptionO(MK_BFL bfl, MK_STRN opt, MK_BOOL defval, MK_BOOL onlyFirst, MK_BOOL* val_out)MkBufferListCheckOptionO_RT
enum MkErrorE MkBufferListCheckOptionS(MK_BFL bfl, MK_STRN opt, MK_SRT defval, MK_BOOL onlyFirst, MK_SRT* val_out)MkBufferListCheckOptionS_RT
enum MkErrorE MkBufferListCheckOptionU(MK_BFL bfl, MK_STRN opt, MK_BUF defval, MK_BOOL onlyFirst, MK_BUF* val_out)MkBufferListCheckOptionU_RT
enum MkErrorE MkBufferListCheckOptionW(MK_BFL bfl, MK_STRN opt, MK_WID defval, MK_BOOL onlyFirst, MK_WID* val_out)MkBufferListCheckOptionW_RT
enum MkErrorE MkBufferListCheckOptionY(MK_BFL bfl, MK_STRN opt, MK_BYT defval, MK_BOOL onlyFirst, MK_BYT* val_out)

MkBufferListCheckOptionY_RT

search for opt in MkBufferListS list and fill var with opt_argument or the defval value …

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on or NULL
[in]optFind opt string in the MkBufferListC
[in]defvalThe value used if opt was not found
[in]onlyFirstIf more than one opt is available, return only the first (true [DEFAULT]) or the last (false)
[out]val_outIf opt is found, return the argument from opt otherwise defval
Returns
set the MkErrorC to the status MK_OK, MK_CONTINUE or MK_ERROR
Attention
  • If val_out is NULL an error is returned.
  • If the opt is found but no opt_argument than a error is returned.
  • If the opt is found, the opt and the opt_argument are deleted from the MkBufferListC.
  • If the defval is returned only a copy of the defval is returned and not the original defval.

MkBufferListC INDEX

C-API: MkBufferListC_Index_C_API - various functions to access a MkBufferListC by 'index' …

enum MkErrorE MkBufferListIndexDelete(MK_BFL bfl, MK_NUM index, MK_NUM numitems, MK_BOOL doDelete)

TOP

delete the index'th list item from the MkBufferListS object … → API: MkBufferListIndexDelete_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
[in]indexan integer index to access an object in an array by position, start=0, end=-1
numitemsdelete number of items
doDeleteif doDelete == true delete the MkBufferC object, associated with the index, too
Returns
set the MkErrorC to the status MK_OK, MK_CONTINUE or MK_ERROR

enum MkErrorE MkBufferListIndexExtract(MK_BFL bfl, MK_NUM index, MK_BUF* val_out)

TOP

extract (read & delete) the index object from bfl … → API: MkBufferListIndexExtract_RT

If the index is not available, this is an error

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
[in]indexan integer index to access an object in an array by position, start=0, end=-1
[out]val_outthe MkBuffer64S object to return
Returns
set the MkErrorC to the status MK_OK, MK_CONTINUE or MK_ERROR
Attention
1. val_out is owned by the caller and have to be freed.
2. val_out will allways be set to NULL first.
See also
BufferListDelete

enum MkErrorE MkBufferListIndexGet(MK_BFLN bfl, MK_NUM index, MK_BUF* val_out)

TOP

get (read only) the index object from bfl … → API: MkBufferListIndexGet_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
[in]indexan integer index to access an object in an array by position, start=0, end=-1
[out]val_outthe MkBufferC to return
Returns
set the MkErrorC to the status MK_OK, MK_CONTINUE or MK_ERROR
Attention
1. val_out is owned by the MkBufferListC and must NOT be freed.
2. val_out will allways be set to NULL first.
3. it is an error if index is not available.
See also
BufferListIndexGetU

MK_STRN MkBufferListIndexGetC(MK_BFL bfl, MK_NUM index)

TOP

get the index element from MkBufferListC ... as string. … → API: MkBufferListIndexGetC_RT

for details please refer to BufferListIndexGetU.

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
[in]indexan integer index to access an object in an array by position, start=0, end=-1
Returns
the string requested or an EMPTY-STRING on error

MK_BUF MkBufferListIndexGetU(MK_BFL bfl, MK_NUM index)

TOP

get the index element from MkBufferListC ... if not available… create it. … → API: MkBufferListIndexGetU_RT

The buffer returned is still owned by bfl.

index starting first next... mode
+0 < idx < (+)~ begin 0 1, 2, 3 ... access idx from begin
-1 < idx < (-)~ end -1 -2, -3, -4 ... append idx to the end
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
[in]indexan integer index to access an object in an array by position, start=0, end=-1
Returns
the MkBufferC requested
See also
BufferListIndexGet

enum MkErrorE MkBufferListIndexSet(MK_BFL bfl, MK_NUM index, MK_BUF buf)

TOP

set the index object from bfl … → API: MkBufferListIndexSet_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
[in]indexan integer index to access an object in an array by position, start=0, end=-1
[in]bufthe MkBufferS instance to work on
Returns
set the MkErrorC to the status MK_OK, MK_CONTINUE or MK_ERROR
Attention
It is an error if index is not available.
See also
BufferListIndexSetU

void MkBufferListIndexSetC(MK_BFL bfl, MK_NUM index, MK_STRN str)

TOP

set the index element from MkBufferListC ... to string… if not available… create space … → API: MkBufferListIndexSetC_RT

for details please refer to BufferListIndexGetU

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
[in]indexan integer index to access an object in an array by position, start=0, end=-1
[in]strthe string to set

void MkBufferListIndexSetU(MK_BFL bfl, MK_NUM index, MK_BUF buf)

TOP

set the index element from MkBufferListC ... if not available… createspace … → API: MkBufferListIndexSetU_RT

-# cursize will be >= index+1

  1. size will be >= index+1
  2. cursize <= X < index+1 -> the missing buffer will be created
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
[in]indexan integer index to access an object in an array by position, start=0, end=-1
[in]bufthe MkBufferS instance to work on

void MkBufferListReserve(MK_BFL bfl, MK_NUM num)

TOP

reserve num items in a MkBufferListC object … → API: MkBufferListReserve_RT

-# cursize will be num

  1. size will b >= num
  2. free: num <= X < cursize
  3. init: cursize <= X < num
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
bflthe MkBufferListC object to reserve memory
numreserve the number of items for later use.

MK_NUM MkBufferListSize(MK_BFLN bfl)

TOP

get the number-of-items in the bfl … → API: MkBufferListSize_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
Returns
the number-of-items in the bfl

MkBufferListC INTROSPECTION

C-API: MkBufferListC_Introspection_C_API - Get information from the MkTypeS.

Get information about all instances created by class

Get information about all instances created by class

The Introspection API is used to get information about the details of the instance and type implementation. Only the connection between type and instance is currently implemented.

Three methods are used to create an iteration over all avaialable instances of a type.

  • Every class has a Linked-List of all instances created starting from last to first.
  • The Introspection support always 3 Functions per class: Instance (static), Next and Prev
  • The Instance (example: (static) MK_BUF MkBufferInstances(void))
    • return the last-instance created or NULL if no instance was created.
  • The Next (example: MK_BUF MkBufferNext(MK_BUF buf))
    • return the next-instance for a given-instance or NULL if the given-instance is the last-instance.
  • The Prev (example: MK_BUF MkBufferPrev(MK_BUF buf))
    • return the previous-instance for a given-instance or NULL if the given-instance is the first-instance.

Example: a simple loop over all instances of class MkBufferC (language C++)

for (auto buf = MkBufferC::Instances(); buf != NULL; buf = buf->Next()) {
SendC(buf->ToString());
}

(static) MK_BFL MkBufferListInstances(void)

TOP

get head-instance from linked-list of MkBufferListS type … → API: MkBufferListInstances

The head-instance is the last instance created.

MK_BFL MkBufferListNext(MK_BFL bfl)

TOP

get next instance from linked-list of MkBufferListS type → API: MkBufferListNext

MK_BFL MkBufferListPrev(MK_BFL bfl)

TOP

get previous instance from linked-list of MkBufferListS type → API: MkBufferListPrev

MkBufferListC LOG

C-API: MkBufferListC_Log_C_API - various functions to 'log' a MkBufferListC

void MkBufferListLog(MK_BFLN bfl, MK_OBJN fmtobj, MK_DBG debug, MK_STRN callfunc, MK_INT lvl)

TOP

write the detail-summary of the MkBufferListC to MkLogFileC (default: stderr) … → API: MkBufferListLog_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
[in]fmtobjmanaged object used to format the log-message (default=NULL = use default format)
[in]debugthe debug level from MkRuntimeS::debug, use 0 <= debug <= 9 (default=0)
[in]callfunca user-defined postfix to identify the calling function or the environment (default=name-of-function)
[in]lvla user-defined prefix starting with "" for lvl=0 and increase with " " for lvl+1 (default=0)
See also
MkBufferListC

void MkBufferListLogS(MK_BFLN bfl, MK_STRN varname, MK_OBJN fmtobj, MK_STRN callfunc)

TOP

write the short-summary of the MkBufferListC to MkLogFileC (default: stderr) … → API: MkBufferListLogS_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
varnameprefix to identify the variable name
[in]fmtobjmanaged object used to format the log-message (default=NULL = use default format)
[in]callfunca user-defined postfix to identify the calling function or the environment (default=name-of-function)

void MkBufferListLogSS(MK_BFLN bfl, MK_STRN varname, MK_OBJN fmtobj, MK_STRN callfunc)

TOP

write the very-short-summary of the MkBufferListC to MkLogFileC (default: stderr) … → API: MkBufferListLogSS_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
varnameprefix to identify the variable name
[in]fmtobjmanaged object used to format the log-message (default=NULL = use default format)
[in]callfunca user-defined postfix to identify the calling function or the environment (default=name-of-function)

void MkBufferListLogSSS(MK_BFLN bfl, MK_STRN varname, MK_OBJN fmtobj, MK_STRN callfunc)

TOP

write the very-very-short-summary of the MkBufferListC to MkLogFileC (default: stderr) … → API: MkBufferListLogSSS_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
[in]varnameThe name of the argument to report
[in]fmtobjmanaged object used to format the log-message (default=NULL = use default format)
[in]callfunca user-defined postfix to identify the calling function or the environment (default=name-of-function)

MkBufferListC MISC

C-API: MkBufferListC_Misc_C_API - various functions to work on a MkBufferListC

MK_INT MkBufferListCmp(MK_BFLN bfl, MK_BFLN bfl2)

TOP

compare two buffer-list … → API: MkBufferListCmp_RT

First the size is compared and if the size is equal every argument starting from 0 is compared with BufferCmp. The first BufferCmp with a result != 0 finish the comparison and this result is returned.

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
[in]bfl2buffer-list to compare
Returns
Returns < 0 if bfl is less than bfl2; > 0 if bfl is greater than bfl2, and 0 if they are equal

void MkBufferListCopy(MK_BFL bfl, MK_BFLN src)

TOP

copy all internal data from src to tgt … → API: MkBufferListCopy_RT

-# existing data will be overwritten

  1. the cursize of src will be the cursize of tgt
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
[in]srcthe source of the copy

void MkBufferListMove(MK_BFL to, MK_BFL from)

TOP

move all internal data from from to the end of to … → API: MkBufferListMove_RT

after the move… the from ist empty and only the shell exists

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]tothe target of the move
[in]fromthe source of the move

void MkBufferListReset(MK_BFL bfl)

TOP

reset a MkBufferListC object … → API: MkBufferListReset_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
Attention
all MkBufferC objects will be freed

MK_NUM MkBufferListSearchC(MK_BFLN bfl, MK_STRN str, MK_NUM len, MK_NUM startindex)

TOP

search MK_STR item from a MkBufferListS object starting at startindex … → API: MkBufferListSearchC_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
strthe string to search for
lenthe length of str or -1 to calulate the length with strlen
startindexstart searching in buf from index startindex
Returns
The index of the str found or -1 if not found. The return value can be used as startindex of following calls to BufferListSearchC

a typical usage for this code is parsing an MkBufferListS object for multiple occurrences of a string

while ((startindex = MkBufferListSearchC (buf, str, strlen(str), startindex)) != -1) {
...
}
#define MkBufferListSearchC(...)
Attention
The size of str have to be at least 4 bytes

MK_BFL MkBufferListSort(MK_BFL bfl)

TOP

sort a MkBufferListC … → API: MkBufferListSort_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
Returns
Return the input bfl as sorted list

MK_BUF MkBufferListToBuffer(MK_BFLN bfl)

TOP

Export a bfl into an MkBufferC using an MkBufferStreamC … → API: MkBufferListToBuffer_RT

An buffer is able to hold all primitive types and LIST of primitive types. An buffer-list is an Indexed-LIST representation of a LIST of buffer.

To add a buffer-list into an buffer the buffer-list have to be converted into a buffer-stream and the buffer-stream have to be exported as buffer. The buffer is finally apended to the buffer-list.

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
Returns
the required buffer or a NULL on error
Attention
The memory of the out-value belongs to the called LibMkKernel function and therefore never becomes NULL. For details on the out-value, see: MkKernel_Storage_C_API.

MK_NAT_LIST MkBufferListToList(MK_BFLN bfl)

TOP

get a target-language list representation of the bfl … → API: MkBufferListToList_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
Returns
the required list
Attention
this is only implemented by the Target-Programming-Language

MkBufferListC TOR

C-API: MkBufferListC_TOR_C_API - various functions to create and destroy a MkBufferListC

(constructor) MK_BFL MkBufferListCreate(MK_NUM size)

TOP

Constructs a MkBufferC instance with size storage… → API: MkBufferListCreate_RT

The new instance belongs to the caller and may have to be released if necessary. A manual release using BufferListDelete is always possible, but the instance can no longer be used afterwards.

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]sizeThe initial size of the instance-local-storage. The MkBufferListC has dynamic-memory-management, the size value is just a hint to provide enought memory for future tasks. The real size created is the maximum of type-ILS-size and size . (default: 0 = use the type-ILS-size)
Returns
The newly created MkBufferListC instance, the instance is owned by the caller

(constructor) MK_BFL MkBufferListCreateLA(MK_BAC args)

TOP

Constructs a MkBufferListC instance with an other MkBufferListC OR a list of arguments (only in NON MK_STR) → API: MkBufferListCreateLA_RT

The new instance belongs to the caller and may have to be released if necessary. A manual release using BufferListDelete is always possible, but the instance can no longer be used afterwards.

Returns
The newly created MkBufferListC instance, the instance is owned by the caller
See also
BufferListDup

(constructor) MK_BFL MkBufferListCreateTLS(MK_NUM tlsid)

TOP

same as BufferListCreate but require no cleanup … → API: MkBufferListCreateTLS_RT

A TLS-instance only exists ONCE per thread and per TLS-function in memory. The memory will be reused and must not be freed.

The new BufferListCreateTLS instance is ready to use and does NOT require a BufferListReset first and a BufferListDelete last.

By default a MkBufferListS type is created because internal an array of references is used and no "malloc" etc is done. ONLY if the required size extend the MkBufferListS prealloc size the storage-manager switch internal to dynamic storage management.

Example from perfserver.c performance test with TLS storage

static enum MkErrorE
Ot_BFLT ( MQ_CALLBACK_SERVICE_CALL_ARGS )
{
while (MqReadItemExists(mqctx)) {
MkBufferListAppendU(bfl,MqReadU_e(mqctx));
}
MqSendSTART_E (mqctx);
for (int i=0; i<bfl->cursize; i++) {
MqSendU_E (mqctx, MkBufferListIndexGet_e (bfl,i));
}
error:
return MqSendRETURN (mqctx);
}
#define MkBufferListAppendU(...)
#define MkBufferListIndexGet_e(...)
#define MkBufferListCreateTLS(...)
The CLASS used to store a list of MkBufferS items into a flat array…
Definition kernel_mk.h:9037
MK_NUM cursize
the currently used number of allocated MkBufferC objects (e.g. 0 <= cursize <= size)
Definition kernel_mk.h:9046
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]tlsidAn per-thread unique name (integer > 0) to identify the reuse-able instance-storage. The tlsid have to be between: 0 <= tlsid < 32
Returns
the new MkBufferListC instance, the instance belongs to the TLS-function and does not need to be deleted.
Attention
for usage of the TLS-storage read more at StorageCreateTLS

(constructor) MK_BFL MkBufferListCreateVA(MK_STRN arg0, ... args)

TOP

Constructs a MkBufferListC instance with a varargs argument that ends with NULL … → API: MkBufferListCreateVA_RT

The new instance belongs to the caller and may have to be released if necessary. A manual release using BufferListDelete is always possible, but the instance can no longer be used afterwards.

Returns
The newly created MkBufferListC instance, the instance is owned by the caller

(constructor) MK_BFL MkBufferListCreateVAL(MK_STRN arg0, va_list var_list)

TOP

Constructs a MkBufferListC instance with a va_list argument … → API: MkBufferListCreateVAL_RT

The new instance belongs to the caller and may have to be released if necessary. A manual release using BufferListDelete is always possible, but the instance can no longer be used afterwards.

Returns
The newly created MkBufferListC instance, the instance is owned by the caller
See also
va_start(3), va_arg(3), va_copy(3), and va_end(3)

(constructor) MK_BFL MkBufferListCreateVC(ME_VCV argv)

TOP

Constructs a MkBufferListC instance with a argc/argv data from a list of strings … → API: MkBufferListCreateVC_RT

The new instance belongs to the caller and may have to be released if necessary. A manual release using BufferListDelete is always possible, but the instance can no longer be used afterwards.

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
argcthe argc from the initial main function
argvthe arguments from the initial main function
Returns
The newly created MkBufferListC instance, the instance is owned by the caller
Attention
a MkBufferListC instance is always created… even if argc = 0
See also
MqCtxTypeS::argvFix
int main (int argc, char *argv[])
{
MK_BFL largs = MkBufferListCreateVC(argc, argv);
....
}
#define MkBufferListCreateVC(...)

(constructor) MK_BFL MkBufferListFileGlob(MK_STRN pattern_match)

TOP

create a new MkBufferListC using the result from a filesystem glob operation … → API: MkBufferListFileGlob_RT

(static) MK_BFL MkBufferListFromHandle(MK_LONG exporthdl)

TOP

Import-Slot - returns a obj from a former exported handle → API: MkBufferListFromHandle

Parameters
[in]exporthdlhandle former exported with ObjectToHandle
Returns
the required handle or NULL if handle is invalid

void MkBufferListDelete(MK_BFL bfl)

TOP

Destructor - delete a MkBufferListC instance … → API: MkBufferListDelete_RT

There are two different ways to delete an instance:

ObjectDisposeto free the internal data but keep the outher shell alive - this is called a SOFT-DELETE
ObjectDelete to delete the outher shell including the internal data - this is called a HARD-DELETE
Attention
  1. The internal memory will be freed and the object-pointer will be set to NULL. If the object-pointer is already NULL nothing will be done.
  2. For a programming language without HARD-Delete support, the "Delete" method is assigned to a SOFT-Delete.
  3. For a programming language without garbage collection, a SOFT-delete without a HARD-delete causes a small memory loss (C++: ~32 bytes).
  4. After a SOFT-delete, the outher shell is still alive, but cannot be used. Any access to this shell generates an HDL-null-exception, but this exception can be caught. This is important for C++ as it prevents a core dump.
  5. On HARD-delete read more at SelfDeleteForce
See also
BufferListCreate BufferListDup MqReadL

(constructor) MK_BFL MkBufferListDup(MK_BFLN bfl)

TOP

Dup-Constructor - create a new MkBufferListC instance as copy from an existing MkBufferListC instance … → API: MkBufferListDup_RT

The new instance belongs to the caller and may have to be released if necessary. A manual release using BufferListDelete is always possible, but the instance can no longer be used afterwards.

Returns
The newly created MkBufferListC instance, the instance is owned by the caller
See also
ObjDup

(constructor) MK_BFL MkBufferListMerge(MK_BFL bfl)

TOP

Merge-Constructor - constructs a MkBufferListC instance as a merge from an existing MkBufferListC instance … → API: MkBufferListMerge_RT

The Merge-Constructor create a new object-shell, and take-over all the internal data from the source-object. After the Merge-Constructor the source-object is empty as if a BufferListReset was called.

One usage of the Merge-Constructor is to get a lightweight-copy of a Thread-Local-Storage object for external usage.

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]bflthe MkBufferListS instance to work on
Returns
The new instance or NULL on error or if no Merge-Constructor is available
Attention
The new instance have to be deleted with BufferListDelete
See also
BufferListDup

MkErrorC

MkErrorC GET

GetCodeget the value of MkErrorS::code
GetNumget the MkErrorS::num. The number can be used as exit-code …
GetSizeget the error-message-size from the exception-object
GetText

get the MkErrorS::text

MkErrorC INTROSPECTION

Instancesget head-instance from linked-list of MkErrorS type …
Nextget next instance from linked-list of MkErrorS type
Prev

get previous instance from linked-list of MkErrorS type

MkErrorC MISC

Catchconvert a programming-language-error into an libmkkernel error …
Loglog the error to MkLogFileC (default: stderr) …
Printlnprint the default-error to the MkLogFileC (default: stderr) and clear the error afterwards …
ResetThis function clears the err and resets to MK_OK
Stackcheck on error and if yes append an ErrorStackFormat to the error-message
StackFormat

append an ensemble of func, file and line to the error-message

MkErrorC RAISE

PanicCdo a panic with string as argument …
PanicVdo a panic with a vararg as argument …
PanicVLdo a panic with a vararg-list as argument …
AppendCappend the message to the MkErrorS::text
AppendVappend a vararg string to the MkErrorC
AppendVLappend a va_list string to the MkErrorC
NoRaiseignore the next return of MK_ERROR and do not raise an target-language-exception
Raiseconvert an libmkkernel error into an programming-language-error and raise afterwards. …
SetC'set' and 'raise' the MkErrorC using a string-message and a errnum-number
SetVset the MkErrorS object using a format string argument list and raise an error …
SetVL

'set' and 'raise' the MkErrorC using a vararg-list message …

MkErrorC SIGNAL

IsEXITcheck on APPLICATION-EXIT error …
IsSOCKETcheck on SOCKET-DOWN error …
SetCONTINUEsignal end of processing in an MqIEvent callback …
SetCodeset the MkErrorS::code value …
SetEXITfinish the current callback, return to toplevel and MqExit the application …
SetSOCKET

create SOCKET-DOWN error …

MkErrorC SYSTEM

DEFAULTsystem-error - this is always the error in duty …
IGNOREsystem-error - do not store the error in an MkErrorC and ignore the error …
PRINT

system-error - print the error to the MkLogFileC

MkErrorC TOR

FromHandleImport-Slot - returns a obj from a former exported handle
DeleteDestructor - delete a MkErrorS object …
Dup

Dup-Constructor - create a new MkErrorC instance as copy from an existing MkErrorC instance …

MkErrorC DETAIL

C-API: MkErrorC_C_API - The MkErrorC object known as err or error is used to create … and manage an error message …

An error is a singleton object per thread created at startup and is located at MkRuntimeRLS using the datatype MkErrorC.

‍As error-indicator the enum MkErrorE is used.

The MkErrorC is used to collect all data needed to handle an error and provide global ressources required to process and report the error.

The MkErrorC is also used to integrate the error-handling from libmkkernel into the error-handling-code of the target C.

Example from Filter6.c use MqContextErrorCatch to convert a C error into a libmkkernel error

int
main (
  const int argc,
  MK_STRN argv[]
)
{
  MqRtSetup_NULL;

  // define the new type
  Filter6TT = MkTypeDup2(MqContextC_TT,"Filter6");
  Filter6TT->objsize = sizeof(struct FilterCtxS);
  Filter6T->fHelp = FilterHelp;

  // create the factory
  MQ_FCT mqfct = MqFactoryAdd(MK_ERROR_PANIC, Filter6Factory, NULL,NULL,NULL,NULL,NULL,NULL,NULL,"Filter6");
  MQ_CTX mqctx = NULL;

#ifdef BUG1
  // for BUG testing in 'trans2-2-T1aE-...'
  MqFactoryInitial(mqfct);
#endif

  // parse the command-line
  MK_BFL args = MkBufferListCreateVC (argc, argv);

  // search for option "--retryCnt"
  MkBufferListCheckOptionI_E (args, "--retryCnt", 3, true, &retryCnt);

  // create the filter
  MqFactoryNew_E (mqfct, NULL, &mqctx);

  // create the link
  MqLinkCreate_E (mqctx, args);

  // start event-loop and wait forever
  MqProcessEvent_E (mqctx, MQ_WAIT_FOREVER, MK_TIMEOUT_USER);

  // finish and exit
error:
  MkBufferListDelete(args);
  MqExit_1 (mqctx);
}

MkExceptionC

Object used to connect the LibMsgqueError with the target-programming-language (C,C++,C#,VB.NET,Java,Python,Ruby,Perl,PHP,Tcl or GO) error …

The LibMsgque provide with MkErrorC a complete error-handling with focus to support the "C" Programming-Language. The support include catch, raise, signal and attributes. In addition every target-programming-language (C,C++,C#,VB.NET,Java,Python,Ruby,Perl,PHP,Tcl or GO) add their own error-handling and the purpose of MkExceptionC is to integrate the MkErrorC into the target-programming-language (C,C++,C#,VB.NET,Java,Python,Ruby,Perl,PHP,Tcl or GO).

The implementation of an exception depends heavily on the target-programming-language (C,C++,C#,VB.NET,Java,Python,Ruby,Perl,PHP,Tcl or GO), starting with no exception at all, for example. C, an exception as a class object, or as an exception as a global attribute.

Attention
  • All MkExceptionC code is implemented at the target-programming-language (C,C++,C#,VB.NET,Java,Python,Ruby,Perl,PHP,Tcl or GO) without support by the Programming-Language-Micro-Kernel compiler.
  • By default, MkExceptionC is only used internally, hidden by the class MkErrorC.

ExceptionCheck

Checks if Exception is of type MkExceptionC and returns MK_YES or MK_NO

Attention
This is just a placeholder and have to be implemented in the target-programming-language (C,C++,C#,VB.NET,Java,Python,Ruby,Perl,PHP,Tcl or GO).

Example: test case to check KILL and RECOVER feature, check on MkExceptionC

    MK_BUF VAL = MqReadU_e(mqctx);
    clmqctx = MqContextCreate (ClientTT, NULL);
    MqConfigSetPrefix(clmqctx,"cl");
    MqConfigSetPostfix(clmqctx,"-1");
    MkErrorCheck (ClientCreateParent2( MK_RT_CALL mqctx, clmqctx));
    MK_INT PID=0;
    MqSend_E(clmqctx, "W", "GPID@I", &PID);
    MkSysKill_E(MkOBJ(mqctx),PID,9);
    MK_INT RET=0;
    for (int i=1; i<=3; i++) {
      if (MkErrorCheckI(MqSend(clmqctx, "W", "ECOI:U@I", VAL, &RET))) {
        if (MkErrorIsSOCKET_0E()) {
          MkErrorReset_1X(clmqctx);
          MqLinkConnect(clmqctx);
          continue;
        } else {
          goto error;
        }
      }
      break;
    }
    MqSendSTART_E(mqctx);
    MqSendI_E (mqctx, RET);
Returns
the result of the check, MK_YES or MK_NO
Parameters
[in]exceptionthe exception object from C, if NULL the global exception object is used

MkErrorC GET

C-API: MkErrorC_Get_C_API - various functions to 'get' data out of MkErrorC

enum MkErrorE MkErrorGetCode(MK_ERRN err)

TOP

get the value of MkErrorS::code … → API: MkErrorGetCode

MK_INT MkErrorGetNum(MK_ERRN err)

TOP

get the MkErrorS::num. The number can be used as exit-code … → API: MkErrorGetNum

MK_SIZE MkErrorGetSize(MK_ERRN err)

TOP

get the error-message-size from the exception-object … → API: MkErrorGetSize

MK_STRN MkErrorGetText(MK_ERRN err)

TOP

get the MkErrorS::text … → API: MkErrorGetText

MkErrorC INTROSPECTION

C-API: MkErrorC_Introspection_C_API - Get information from the MkTypeS.

Get information about all instances created by class

Get information about all instances created by class

The Introspection API is used to get information about the details of the instance and type implementation. Only the connection between type and instance is currently implemented.

Three methods are used to create an iteration over all avaialable instances of a type.

  • Every class has a Linked-List of all instances created starting from last to first.
  • The Introspection support always 3 Functions per class: Instance (static), Next and Prev
  • The Instance (example: (static) MK_BUF MkBufferInstances(void))
    • return the last-instance created or NULL if no instance was created.
  • The Next (example: MK_BUF MkBufferNext(MK_BUF buf))
    • return the next-instance for a given-instance or NULL if the given-instance is the last-instance.
  • The Prev (example: MK_BUF MkBufferPrev(MK_BUF buf))
    • return the previous-instance for a given-instance or NULL if the given-instance is the first-instance.

Example: a simple loop over all instances of class MkBufferC (language C++)

for (auto buf = MkBufferC::Instances(); buf != NULL; buf = buf->Next()) {
SendC(buf->ToString());
}

(static) MK_ERR MkErrorInstances(void)

TOP

get head-instance from linked-list of MkErrorS type … → API: MkErrorInstances

The head-instance is the last instance created.

MK_ERR MkErrorNext(MK_ERR err)

TOP

get next instance from linked-list of MkErrorS type → API: MkErrorNext

MK_ERR MkErrorPrev(MK_ERR err)

TOP

get previous instance from linked-list of MkErrorS type → API: MkErrorPrev

MkErrorC MISC

C-API: MkErrorC_Misc_C_API - various functions to 'work' on a MkErrorC

MK_ERR MkErrorCatch(MK_ERR err, MK_EXP exception, MK_STRN callfunc)

TOP

convert a programming-language-error into an libmkkernel error … → API: MkErrorCatch_RT

Same as MK_ERR MkObjectErrorCatch(MK_OBJN obj, MK_EXP exception, MK_STRN callfunc) but skip the Error-Prefix in final target-programming-language (C,C++,C#,VB.NET,Java,Python,Ruby,Perl,PHP,Tcl or GO).

Example from Bug3.c catch an error using (static) MK_ERR MkErrorDEFAULT(MK_OBJN fmtobj)

  // \b "C" does not suppot the \b "Catch" function because there is ONLY the \LibMqMsgque error and nothing else.
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]errthe MkErrorS instance to work on - the default-error is automatically created on startup. (NULL allowed)
[in]exceptionthe exception object from C, if NULL the global exception object is used
[in]callfunca user-defined postfix to identify the calling function or the environment (default=name-of-function)
Returns
the ErrorDEFAULT initialized with exception value
See also
enum MkErrorE MkErrorRaise(MK_ERRN err) enum MkErrorE MkErrorReset(MK_ERR err, MK_STRN callfunc, MK_INT callline, MK_BOOL force)

void MkErrorLog(MK_ERRN err, MK_OBJN fmtobj, MK_DBG debug, MK_STRN callfunc, MK_INT lvl)

TOP

log the error to MkLogFileC (default: stderr) … → API: MkErrorLog_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]errthe MkErrorS instance to work on - the default-error is automatically created on startup. (NULL allowed)
[in]fmtobjmanaged object used to format the log-message (default=NULL = use default format)
[in]debugthe debug level from MkRuntimeS::debug, use 0 <= debug <= 9 (default=0)
[in]callfunca user-defined postfix to identify the calling function or the environment (default=name-of-function)
[in]lvla user-defined prefix starting with "" for lvl=0 and increase with " " for lvl+1 (default=0)
See also
MkErrorC void MkErrorLog(MK_ERRN err, MK_OBJN fmtobj, MK_DBG debug, MK_STRN callfunc, MK_INT lvl)

void MkErrorPrintln(MK_ERR err)

TOP

print the default-error to the MkLogFileC (default: stderr) and clear the error afterwards … → API: MkErrorPrintln_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]errthe MkErrorS instance to work on - the default-error is automatically created on startup. (NULL allowed)

enum MkErrorE MkErrorReset(MK_ERR err, MK_STRN callfunc, MK_INT callline, MK_BOOL force)

TOP

This function clears the err and resets to MK_OK … → API: MkErrorReset_RT

Attention
Use this function carfully, as misuse will result in the loss of the error-message.

It is recommended that you use this feature only after the error has been processed.

  • processed = The error was send to another server or printed to the user or to a file.
See also
ErrorRaise ErrorCatch

enum MkErrorE MkErrorStack(MK_ERR err, MK_STRN callfunc, MK_STRN callfile, MK_INT callline)

TOP

check on error and if yes append an ErrorStackFormat to the error-message … → API: MkErrorStack_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]errthe MkErrorS instance to work on - the default-error is automatically created on startup. (NULL allowed) → NULL allowed
[in]callfunca user-defined postfix to identify the calling function or the environment (default=name-of-function)
[in]callfilethe name of the file the call take place (e.g. FILE)
[in]calllinethe number of the line the call take place (e.g. LINE)
Returns
set the MkErrorC to the status MK_OK, MK_CONTINUE or MK_ERROR

void MkErrorStackFormat(MK_ERR err, MK_STRN callfunc, MK_STRN callfile, MK_INT callline)

TOP

append an ensemble of func, file and line to the error-message … → API: MkErrorStackFormat_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]errthe MkErrorS instance to work on - the default-error is automatically created on startup. (NULL allowed)
[in]callfunca user-defined postfix to identify the calling function or the environment (default=name-of-function)
[in]callfilethe name of the file the call take place (e.g. FILE)
[in]calllinethe number of the line the call take place (e.g. LINE)

MkErrorC RAISE

C-API: MkErrorC_Raise_C_API - various functions to 'raise' a MkErrorC

An error is "raised" by naming the MkErrorS::text and changing the MkErrorS::code to MK_ERROR.

(static) void MkPanicC(MK_OBJN errobj, MK_STRN callfunc, MK_INT errnum, MK_STRN message)

TOP

do a panic with string as argument … → API: MkPanicC_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]errobja managed object used to identify and format the error-message
[in]callfunca user-defined postfix to identify the calling function or the environment (default=name-of-function)
[in]errnumthe error number used as exit-code as well
messagethe string to be displayed
Attention
this function will never return

(static) void MkPanicV(MK_OBJN errobj, MK_STRN callfunc, MK_INT errnum, MK_FST printfmt, ... args)

TOP

do a panic with a vararg as argument … → API: MkPanicV_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]errobja managed object used to identify and format the error-message
[in]callfunca user-defined postfix to identify the calling function or the environment (default=name-of-function)
[in]errnumthe error number used as exit-code as well
[in]printfmtis a c-string used as printf like format string
Attention
this function will never return

(static) void MkPanicVL(MK_OBJN errobj, MK_STRN callfunc, MK_INT errnum, MK_FST printfmt, va_list var_list)

TOP

do a panic with a vararg-list as argument … → API: MkPanicVL_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]errobja managed object used to identify and format the error-message
[in]callfunca user-defined postfix to identify the calling function or the environment (default=name-of-function)
[in]errnumthe error number used as exit-code as well
[in]printfmtis a c-string used as printf like format string
[in]var_lista variable argument list object
Attention
this function will never return

void MkErrorAppendC(MK_ERR err, MK_STRN message)

TOP

append the message to the MkErrorS::text … → API: MkErrorAppendC_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]errthe MkErrorS instance to work on - the default-error is automatically created on startup. (NULL allowed)
[in]messagethe string to be displayed as message (append)

void MkErrorAppendV(MK_ERR err, MK_FST printfmt, ... args)

TOP

append a vararg string to the MkErrorC … → API: MkErrorAppendV_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]errthe MkErrorS instance to work on - the default-error is automatically created on startup. (NULL allowed)
[in]printfmtis a c-string used as printf like format string

void MkErrorAppendVL(MK_ERR err, MK_FST printfmt, va_list var_list)

TOP

append a va_list string to the MkErrorC … → API: MkErrorAppendVL_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]errthe MkErrorS instance to work on - the default-error is automatically created on startup. (NULL allowed)
[in]printfmtis a c-string used as printf like format string
[in]var_lista variable argument list object

MK_ERR MkErrorNoRaise(MK_ERR err)

TOP

ignore the next return of MK_ERROR and do not raise an target-language-exception … → API: MkErrorNoRaise_RT

Many functions from the MkErrorXXX return an MkErrorE to signal that an MK_ERROR is set. The target-language react on this signal and raise an target-language-exception.
If this behaviour is not desired the ErrorNoRaise is used to suppress the next MK_ERROR return.

This feature is used to avoid the target-language-exception after ErrorSetC etc.

This is usefull if:

  1. an error should be send by MqSendERROR later
  2. an error will be extended by using multiple ErrorAppendC etc later and than raised with ErrorRaise

Example from server.c create and send an background-error message

static enum MkErrorE
BgError ( MQ_CALLBACK_SERVICE_CALL_ARGS )
{
  MQ_CTX master = MqSlaveGetMaster(mqctx);
  if (master) {
    MK_ERR err = MkErrorNoRaise(MkErrorDEFAULT_1M(master));
    // MkErrorGetTextI and MkErrorSetC using the !! SAME !! memory
    // → need a temporary buffer "ctxbuf.buf"
    MkBufferSetC(MkBUF(&master->ctxbuf), MkErrorGetText(err));
    MkErrorSetC(err, MkBUF_R(&master->ctxbuf).storage.first.C, "BGERROR", MkErrorGetNum(err));
    MqSendERROR (master);
  }
  return MkErrorStack_E(mqctx);
}
Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]errthe MkErrorS instance to work on - the default-error is automatically created on startup. (NULL allowed)
Returns
the input err with MkErrorS::noRaise flag set

enum MkErrorE MkErrorRaise(MK_ERRN err)

TOP

convert an libmkkernel error into an programming-language-error and raise afterwards. … → API: MkErrorRaise_RT

If ther is no libmkkernel-error (MkErrorS::code "= #MK_ERROR) than nothing happen. @param [in] err the #MkErrorS instance to work on - the \e default-error is automatically created on startup. (NULL allowed) \sa \ref doc_mk_c_ErrorCatch "ErrorCatch" \ref doc_mk_c_ErrorReset "ErrorReset"

enum MkErrorE MkErrorSetC(MK_ERR err, MK_STRN message, MK_STRN callfunc, MK_INT errnum)

TOP

'set' and 'raise' the MkErrorC using a string-message and a errnum-number … → API: MkErrorSetC_RT

The message will be formatted into a libmkkernel error-message.

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]errthe MkErrorS instance to work on - the default-error is automatically created on startup. (NULL allowed) - err==NULL allowed
[in]messagethe string to be displayed as message
[in]callfunca user-defined postfix to identify the calling function or the environment (default=name-of-function)
[in]errnumthe error number used as exit-code as well
Attention
Use ErrorNoRaise to avoid raise an error.

enum MkErrorE MkErrorSetV(MK_ERR err, MK_STRN callfunc, MK_INT errnum, MK_FST printfmt, ... args)

TOP

set the MkErrorS object using a format string argument list and raise an error … → API: MkErrorSetV_RT

The string argument list will be formatted into a libmkkernel error-message.

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]errthe MkErrorS instance to work on - the default-error is automatically created on startup. (NULL allowed)
[in]callfunca user-defined postfix to identify the calling function or the environment (default=name-of-function)
[in]errnumthe error number used as exit-code as well
[in]printfmtis a c-string used as printf like format string
Returns
set the MkErrorC to the status MK_OK, MK_CONTINUE or MK_ERROR
Attention
Use ErrorNoRaise to avoid raise an error.

enum MkErrorE MkErrorSetVL(MK_ERR err, MK_STRN callfunc, MK_INT errnum, MK_FST printfmt, va_list var_list)

TOP

'set' and 'raise' the MkErrorC using a vararg-list message … → API: MkErrorSetVL_RT

The var_list will be formatted into a libmkkernel error-message.

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]errthe MkErrorS instance to work on - the default-error is automatically created on startup. (NULL allowed)
[in]callfunca user-defined postfix to identify the calling function or the environment (default=name-of-function)
[in]errnumthe error number used as exit-code as well
[in]printfmtis a c-string used as printf like format string
[in]var_lista variable argument list object
Returns
set the MkErrorC to the status MK_OK, MK_CONTINUE or MK_ERROR
Attention
Use ErrorNoRaise to avoid raise an error.

MkErrorC SIGNAL

C-API: MkErrorC_Signal_C_API - various functions to set and check a 'signal' on a MkErrorC

MK_BOOL MkErrorIsEXIT(MK_ERR err)

TOP

check on APPLICATION-EXIT error … → API: MkErrorIsEXIT

The exit-error-object is made for two resons:

  1. The error is set by ErrorSetEXIT to signal end-of-application.
  2. The error is raised by a function to signal a fatal-error which require an application-exit.
    The only source of this kind of fatal-error is a link-target-abnormal-exit caused by a server/network crash.

The link-target-abnormal-exit can only occur for functions that perform a network-request, such as:

  • MqLinkCreate, MqLinkCreateChild, MqLinkConnect, MqSendEND, MqSendEND_AND_WAIT or MqProcessEvent

The aim of this function is to react to an exit-error-object and is used to ignore the error with an ErrorReset and then later to re-establish a connection with a MqLinkConnect.

  • Read more from the: example/c/Filter4.c example

Example "C": catch and ignore an EXIT return-code

if (MkErrorCheckI (MqSendEND_AND_WAIT (ctx, "TOKS", MK_TIMEOUT_USER))) {
}
#define MkErrorIsEXIT_0E()
#define MkErrorReset_1X(x)
#define MkErrorCheckI(err)

MK_BOOL MkErrorIsSOCKET(MK_ERRN err)

TOP

check on SOCKET-DOWN error … → API: MkErrorIsSOCKET

void MkErrorSetCONTINUE(MK_ERR err)

TOP

signal end of processing in an MqIEvent callback … → API: MkErrorSetCONTINUE_RT

void MkErrorSetCode(MK_ERR err, enum MkErrorE code)

TOP

set the MkErrorS::code value … → API: MkErrorSetCode_RT

enum MkErrorE MkErrorSetEXIT(MK_ERR err, MK_STRN callfunc)

TOP

finish the current callback, return to toplevel and MqExit the application … → API: MkErrorSetEXIT_RT

To exit a application in a callback is a difficult task because the code is in-duty. To achieve this goal a special exit-error-object is created and reported to the toplevel. If a transaction is ongoing the MqSendRETURN is not called and thus the transaction is not finished. The calling application is informed later by a socket-down event. This only works for a parent-context. An exit in a child-context is ignored.

Example: raise an EXIT-exception in an ruby-service:

def EXIT
MkErrorC.DEFAULT().SetEXIT()
end

enum MkErrorE MkErrorSetSOCKET(MK_ERR err, MK_STRN detail, MK_STRN callfunc)

TOP

create SOCKET-DOWN error … → API: MkErrorSetSOCKET_RT

MkErrorC SYSTEM

C-API: MkErrorC_System_C_API - various functions to reaise 'System' messagen on MkErrorC

(static) MK_ERR MkErrorDEFAULT(MK_OBJN fmtobj)

TOP

system-error - this is always the error in duty … → API: MkErrorDEFAULT

Set the MkErrorS::format_of_error attribute to fmtobj or NULL. The next error-massage will be formated as usual and than be raised as error. The default-error will be modified.

The next error-message created with ErrorSetC etc is formatted with MkRuntimeS->cid ("context-in-duty") or simply as "DEFAULT" if cid == NULL.

Parameters
[in]fmtobjmanaged object used to format the log-message (default=NULL = use default format)
Returns
the default-error with MkErrorS::format_of_error attribute set
See also
ErrorDEFAULT, ErrorPRINT, ErrorIGNORE, ErrorPANIC

(static) MK_ERR MkErrorIGNORE(void)

TOP

system-error - do not store the error in an MkErrorC and ignore the error … → API: MkErrorIGNORE_RT

There are two functions to suppress an error: (static) MK_ERR MkErrorIGNORE(void) and MK_ERR MkErrorNoRaise(MK_ERR err).

The (static) MK_ERR MkErrorIGNORE(void) set the MkErrorS::format_of_error attribute to IGNORE. The next error will be ignored, no formatting will be performed and the the default-error will not be modified.

The MK_ERR MkErrorNoRaise(MK_ERR err) set the MkErrorS::noRaise attribute to TRUE. The next error will be set as usual but not raised. This is usefull to set an error and later append additional information to the error. Final the error have to be raised with enum MkErrorE MkErrorRaise(MK_ERRN err).

Returns
the default-error with MkErrorS::format_of_error attribute set
See also
ErrorDEFAULT, ErrorPRINT, ErrorIGNORE, ErrorPANIC

(static) MK_ERR MkErrorPRINT(void)

TOP

system-error - print the error to the MkLogFileC … → API: MkErrorPRINT_RT

Set the MkErrorS::format_of_error attribute to PRINT. The next error-massage will be formated as usual and than be reported using LogVL. The default-error will not be modified.

Returns
the default-error with MkErrorS::format_of_error attribute set
See also
ErrorDEFAULT, ErrorPRINT, ErrorIGNORE, ErrorPANIC

MkErrorC TOR

C-API: MkErrorC_TOR_C_API - various functions to 'create' and 'delete' a MkErrorC

(static) MK_ERR MkErrorFromHandle(MK_LONG exporthdl)

TOP

Import-Slot - returns a obj from a former exported handle → API: MkErrorFromHandle

Parameters
[in]exporthdlhandle former exported with ObjectToHandle
Returns
the required handle or NULL if handle is invalid

void MkErrorDelete(MK_ERR err)

TOP

Destructor - delete a MkErrorS object … → API: MkErrorDelete_RT

There are two different ways to delete an instance:

ObjectDisposeto free the internal data but keep the outher shell alive - this is called a SOFT-DELETE
ObjectDelete to delete the outher shell including the internal data - this is called a HARD-DELETE
Attention
  1. The internal memory will be freed and the object-pointer will be set to NULL. If the object-pointer is already NULL nothing will be done.
  2. For a programming language without HARD-Delete support, the "Delete" method is assigned to a SOFT-Delete.
  3. For a programming language without garbage collection, a SOFT-delete without a HARD-delete causes a small memory loss (C++: ~32 bytes).
  4. After a SOFT-delete, the outher shell is still alive, but cannot be used. Any access to this shell generates an HDL-null-exception, but this exception can be caught. This is important for C++ as it prevents a core dump.
  5. On HARD-delete read more at SelfDeleteForce
See also
BufferDup ObjectDelete

(constructor) MK_ERR MkErrorDup(MK_ERRN srce)

TOP

Dup-Constructor - create a new MkErrorC instance as copy from an existing MkErrorC instance … → API: MkErrorDup_RT

The new instance belongs to the caller and may have to be released if necessary. A manual release using ErrorDelete is always possible, but the instance can no longer be used afterwards.

Returns
The newly created MkErrorC instance, the instance is owned by the caller
See also
ObjDup ErrorDelete

MkLogFileC

MkLogFileC INTROSPECTION

Instancesget head-instance from linked-list of MkLogFileS type …
Nextget next instance from linked-list of MkLogFileS type
Prev

get previous instance from linked-list of MkLogFileS type

MkLogFileC TOR

FromHandleImport-Slot - returns a obj from a former exported handle
Openopen the log-file in append mode …
Close

Destructor - delete a MkLogFileC instance …

MkLogFileC WRITE

GetFileget the log-file
WriteCwrite to log-file
WriteVwrite to log-file
WriteVL

write to log-file

MkLogFileC DETAIL

C-API: MkLogFileC_C_API - The MkLogFileC object known as lfl or log-file is used to control … the target of the logging-output.

The logging-target is set direct by RuntimeSetLogfile or using the class MkLogFileC.

The target is stored at the MkRuntimeC using a FILE-stream and can be set individually for each thread. The default is stderr.

possible values are:

value decription OS man-page
stdout the standart output stdio(3)
stderr the standart error output stdio(3)
fileName an arbitary fileName fopen(3)

MkLogFileC INTROSPECTION

C-API: MkLogFileC_Introspection_C_API - Get information from the MkTypeS.

Get information about all instances created by class

Get information about all instances created by class

The Introspection API is used to get information about the details of the instance and type implementation. Only the connection between type and instance is currently implemented.

Three methods are used to create an iteration over all avaialable instances of a type.

  • Every class has a Linked-List of all instances created starting from last to first.
  • The Introspection support always 3 Functions per class: Instance (static), Next and Prev
  • The Instance (example: (static) MK_BUF MkBufferInstances(void))
    • return the last-instance created or NULL if no instance was created.
  • The Next (example: MK_BUF MkBufferNext(MK_BUF buf))
    • return the next-instance for a given-instance or NULL if the given-instance is the last-instance.
  • The Prev (example: MK_BUF MkBufferPrev(MK_BUF buf))
    • return the previous-instance for a given-instance or NULL if the given-instance is the first-instance.

Example: a simple loop over all instances of class MkBufferC (language C++)

for (auto buf = MkBufferC::Instances(); buf != NULL; buf = buf->Next()) {
SendC(buf->ToString());
}

(static) MK_LFL MkLogFileInstances(void)

TOP

get head-instance from linked-list of MkLogFileS type … → API: MkLogFileInstances

The head-instance is the last instance created.

MK_LFL MkLogFileNext(MK_LFL lfl)

TOP

get next instance from linked-list of MkLogFileS type → API: MkLogFileNext

MK_LFL MkLogFilePrev(MK_LFL lfl)

TOP

get previous instance from linked-list of MkLogFileS type → API: MkLogFilePrev

MkLogFileC TOR

C-API: MkLogFileC_TOR_C_API - various functions to 'create and delete' a MkLogFileC

(static) MK_LFL MkLogFileFromHandle(MK_LONG exporthdl)

TOP

Import-Slot - returns a obj from a former exported handle → API: MkLogFileFromHandle

Parameters
[in]exporthdlhandle former exported with ObjectToHandle
Returns
the required handle or NULL if handle is invalid

(constructor) enum MkErrorE MkLogFileOpen(MK_OBJ errobj, MK_STRN file, MK_LFL* lfh_out)

TOP

open the log-file in append mode … → API: MkLogFileOpen_RT

The new instance belongs to the caller and may have to be released if necessary. A manual release using LogFileClose is always possible, but the instance can no longer be used afterwards.

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]errobja managed object used to identify and format the error-message
[in]filethe filename to open
[out]lfh_outreturns
Returns
The newly created MkLogFileC instance, the instance is owned by the caller
set the MkErrorC to the status MK_OK, MK_CONTINUE or MK_ERROR
Attention
on error the lfh_out is set to NULL

void MkLogFileClose(MK_LFL lfh)

TOP

Destructor - delete a MkLogFileC instance … → API: MkLogFileClose_RT

There are two different ways to delete an instance:

ObjectDisposeto free the internal data but keep the outher shell alive - this is called a SOFT-DELETE
ObjectDelete to delete the outher shell including the internal data - this is called a HARD-DELETE
Attention
  1. The internal memory will be freed and the object-pointer will be set to NULL. If the object-pointer is already NULL nothing will be done.
  2. For a programming language without HARD-Delete support, the "Delete" method is assigned to a SOFT-Delete.
  3. For a programming language without garbage collection, a SOFT-delete without a HARD-delete causes a small memory loss (C++: ~32 bytes).
  4. After a SOFT-delete, the outher shell is still alive, but cannot be used. Any access to this shell generates an HDL-null-exception, but this exception can be caught. This is important for C++ as it prevents a core dump.
  5. On HARD-delete read more at SelfDeleteForce
See also
LogFileOpen

MkLogFileC WRITE

C-API: MkLogFileC_Write_C_API - various functions to 'write' into a MkLogFileC

enum MkErrorE MkLogFileGetFile(MK_LFLN lfl, MK_STRN* file_out)

TOP

get the log-file … → API: MkLogFileGetFile_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]lflthe MkLogFileS instance to work on
[out]file_outthe log-file to return
Returns
set the MkErrorC to the status MK_OK, MK_CONTINUE or MK_ERROR

enum MkErrorE MkLogFileWriteC(MK_LFLN lfl, MK_STRN text)

TOP

write to log-file … → API: MkLogFileWriteC_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]lflthe MkLogFileS instance to work on
[in]textthe text to write
Returns
set the MkErrorC to the status MK_OK, MK_CONTINUE or MK_ERROR

enum MkErrorE MkLogFileWriteV(MK_LFLN lfl, MK_FST printfmt, ... args)

TOP

write to log-file … → API: MkLogFileWriteV_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]lflthe MkLogFileS instance to work on
[in]printfmtis a c-string used as printf like format string
Returns
set the MkErrorC to the status MK_OK, MK_CONTINUE or MK_ERROR

enum MkErrorE MkLogFileWriteVL(MK_LFLN lfl, MK_FST printfmt, va_list var_list)

TOP

write to log-file … → API: MkLogFileWriteVL_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]lflthe MkLogFileS instance to work on
[in]printfmtis a c-string used as printf like format string
[in]var_lista variable argument list object
Returns
set the MkErrorC to the status MK_OK, MK_CONTINUE or MK_ERROR

MkRuntimeC

MkRuntimeC CONFIG

Debuglog the MkRuntimeC
GetDebugget the MkRuntimeS::debug value …
GetIsSilentget the MkRuntimeS::isSilent value …
GetLogfileget the MkRuntimeS::logfile value …
SetDebugset the MkRuntimeS::debug value …
SetIsSilentset the MkRuntimeS::isSilent value …
SetLogfile

set the MkRuntimeS::logfile value and cleanup old value …

MkRuntimeC DETAIL

C-API: MkRuntimeC_C_API - The MkRuntimeC class known as mkrt or runtime is the main libmkkernel application environment …

The runtime is automatically created as thread-local-storage at startup, so that each new thread receives a thread-specific runtime. Each instance on this thread has a link to the runtime it was created in:

The runtime provide the following features:

  • the default-error -> MkErrorC
  • the runtime local storage (RLS) for various internal features
  • application wide configuration data like debug logfile or silent

To access the MkRuntimeRLS in C or C++ the MkRuntimeC_Interface_C_API is used.

MkRuntimeC CONFIG

C-API: MkRuntimeC_Config_C_API - only C - various functions to configure the MkRuntimeC

The MkRuntimeRLS-configuration belongs to a single MkRuntimeRLS. In a threadable application, each thread has its own MkRuntimeRLS and therefore its own configuration.

A function ending in 'I' is the inline variant of the function without the 'I' and is preferred in C.

(static) void MkRuntimeDebug(MK_RT mkrt, MK_OBJN fmtobj, MK_DBG debug, MK_STRN callfunc, MK_INT lvl)

TOP

log the MkRuntimeC … → API: MkRuntimeDebug

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]fmtobjmanaged object used to format the log-message (default=NULL = use default format)
[in]debugthe debug level from MkRuntimeS::debug, use 0 <= debug <= 9 (default=0)
[in]callfunca user-defined postfix to identify the calling function or the environment (default=name-of-function)
[in]lvla user-defined prefix starting with "" for lvl=0 and increase with " " for lvl+1 (default=0)
See also
MkRuntimeC

(static) MK_INT MkRuntimeGetDebug(void)

TOP

get the MkRuntimeS::debug value … → API: MkRuntimeGetDebug

(static) MK_BOOL MkRuntimeGetIsSilent(void)

TOP

get the MkRuntimeS::isSilent value … → API: MkRuntimeGetIsSilent

(static) MK_STRN MkRuntimeGetLogfile(void)

TOP

get the MkRuntimeS::logfile value … → API: MkRuntimeGetLogfile

Attention
the string is owned by libmkkernel -> do not free !!

(static) void MkRuntimeSetDebug(MK_INT dbg)

TOP

set the MkRuntimeS::debug value … → API: MkRuntimeSetDebug

(static) void MkRuntimeSetIsSilent(MK_BOOL silent)

TOP

set the MkRuntimeS::isSilent value … → API: MkRuntimeSetIsSilent

(static) enum MkErrorE MkRuntimeSetLogfile(MK_STRN logfile)

TOP

set the MkRuntimeS::logfile value and cleanup old value … → API: MkRuntimeSetLogfile_RT

Parameters
[in]mkrtthe MkRuntimeS instance to work on - the runtime argument, used by MK_RT_CALL (C-only)
[in]logfilefilename, "stdout" or "stderr", default = "stderr" for NULL or ""

BINARY OBJECT

No special binary-object is used. All binary-data is available as C MK_BINN.


EXAMPLES

Example from server.c read a buffer-object and convert single-char-type-identifer to string.

static enum MkErrorE
Ot_BUF2 ( MQ_CALLBACK_SERVICE_CALL_ARGS )
{
  MK_BUF buf;
  int i;
  char str[2] = {'\0', '\0'};
  MqSendSTART_E (mqctx);
  for (i=0; i<3; i++) {
    MqReadU_E (mqctx, &buf);
    str[0] = MkBufferGetType1(buf);
    MqSendC_E (mqctx, str);
    MqSendU_E (mqctx, buf);
  }
  return MqSendRETURN(mqctx);
error:
  return MkErrorStack_1X(mqctx);
}

SEE ALSO

libmkkernel, ccmkkernel, csmkkernel, javamkkernel, gomkkernel, pymkkernel, rbmkkernel, tclmkkernel, perlmkkernel, phpmkkernel

KEYWORDS

C, unix, socket, message, msgque