Zen API
 All Classes Files Functions Variables Typedefs Macros Groups Pages
Overview

The Zen API is an open-source library that provides a foundation for software developed by LMI Technologies. Zen includes portable definitions for data types, support for concurrency and I/O, and a variety of utility functions. Most native libraries and applications developed by LMI Technologies depend on Zen.

Zen is an object-oriented library, implemented in C. A small Zen program is shown below:

#include <kApi/kApi.h> //include all zen headers
int main()
{
kAssembly assembly = kNULL; //assembly handle
kImage image = kNULL; //image handle
kSize width = 32;
kSize height = 64;
kSize i, j;
//get an initialized reference to zen's core assembly (kApiLib)
kCheck(kApiLib_Construct(&assembly));
//construct a new image object
kCheck(kImage_Construct(&image, kTypeOf(k8u), width, height, kNULL));
//set the image pixels to a test pattern
for (i = 0; i < height; ++i)
{
//get a pointer to the first element in the current row
k8u* row = kImage_RowAt(image, i);
for (j = 0; j < width; ++j)
{
row[j] = (k8u) (i + j);
}
}
//save the image using bmp format
kCheck(kImage_Export(image, "test.bmp"));
//destroy the image object
//release the kApiLib assembly
kCheck(kObject_Destroy(assembly));
return kOK;
}

This short program illustrates several points:

  • A Zen assembly is a collection of types. Typically, each library or application defines a single assembly that contains all of the types defined in that component. In the example above, the kApiLib_Construct function is used to construct an instance of Zen's core assembly (kApiLib). A program must construct an assembly instance before using the services provided by that assembly, and should destroy the assembly instance before the program exits.
  • Zen recognizes two fundamental kinds of data: value types (e.g. kSize) and reference types (e.g. kImage). Value types (structs, enums, primitives) are simple structures with public fields; reference types (classes, interfaces) are opaque structures that are represented with handles and accessed using functions.
  • Zen implements a single-inheritance, multiple-interface class model. All Zen classes descend from kObject. In the example above, this fact enables the kObject_Destroy method to be used on both the image object and the assembly object.
  • Zen supports type reflection in a variety of ways. In the example above, the kTypeOf macro is used to obtain type information (kType) corresponding to the k8u value type (8-bit unsigned integer).
  • All Zen names are prefixed with k (or K). In function names, underscores are used to separate type names from method names. For example, in the kImage_Construct function, kImage is the class name, and Construct is the method name.
  • A variety of helper macros are defined as syntactic aids. In the example above, the kCheck macro is used to test the return value from Zen functions; if any function returns an error code, the kCheck macro will immediately return the error code (kStatus value) to the caller.

Zen implements an extensible type system. That is, multiple assemblies can be defined and the types defined in one assembly can extend the types defined in another assembly. Among other things, this enables classes defined in other libraries to extend kObject.

Zen is provided under the MIT license. Visual Studio project files are included for Windows and GNU makefiles are included for Linux. Zen has been tested on the following operating system editions:

  • Windows 7 32-bit
  • Windows 7 64-bit
  • Ubuntu 13.10 32-bit
  • Ubuntu 13.10 64-bit
  • DSP/BIOS 5.32.01
See also
FAQ, kObject, kType, kAssembly