Module DkSDKFFIOCaml_StdSource

Introduction

Usage

This module is designed to be opened, like so:

open DkSDKFFIOCaml_Std

All modules introduced by the open statement will start with Com, like Com, ComMessage, etc.

The Com* modules are explained in sections below.

DkSDK COM objects

First Things

Roughly speaking, COM objects are traditional objects (ex. Java, C++ and Swift objects) that have no class hierarchies but have "interfaces" similar to Java interfaces, pure C++ abstract classes and Swift protocols.

DkSDK COM objects live in an area of memory within a process that is separate from your programming language's objects. The key benefit of using COM objects is that they can be accessed by many programming languages.

Take for example Java and OCaml. If you need to have Java and OCaml interact in the same process, you could define:

You now have a bidirectional channel between Java and OCaml.

This may sound more involved than a traditional FFI (Java JNA, OCaml ctypes, etc). It is! But you gain portability of your code between languages; the same OCaml code can work in an Android (Java) application, and the same OCaml code can work in an iOS (Swift) application, and the same OCaml code can run natively in a desktop application.

And what you write is simpler than you may initially think:

Formal Ideas

The most primitive concepts you will need to understand are COM interfaces and COM objects:

In DkSDK FFI, you primarily interact with two COM interfaces.

The COM generic class object is a value that:

The COM generic instance object is a value that:

The COM generic interface is a type which is a specialization of the COM interface. A generic interface is the set of all future and existing COM generic objects that both:

The module Com is where you can get pre-existing COM generic class objects and call methods on COM objects.

module Com : sig ... end

Messages

Each host platform has a different Cap n' Proto message signature. These differences encapsulate the different ways the host platforms manage memory. Some host platforms use manual memory management, some use the type system, some use referencing counting and others use full garbage collection. Regardless, the Cap n' Proto message signature hides all of the host language memory management details.

Sourcemodule ComMessage : sig ... end

Schemas

Any Cap n' Proto schema can be used for sending and receiving messages through DkSDK FFI.

A set of single-element structures is available for convenience when you don't want to generate your own Cap n' Proto schema. All of the basic scalar Cap n' Proto types are available as single-element structures.

In addition, the ComStandardSchema.S.Reader.ComObject and ComStandardSchema.S.Builder.ComObject types are used to pass back and forth references to DkSDK COM objects. Its schema is the ComObject schema.

module ComStandardSchema : sig ... end

Persistence and Transmission

module ComCodecs : sig ... end

Serialization and deserialization protocols.