View on GitHub

stencil

Code Generator based on Model Template binding Transformations

Interfaces

TODO

Open questions

Data-stores part of interface?

Status : Under consideration (Needs prototyping for linking with DatabaseT)

Yes

No

If using virtual. The implementors can inherit markers to declare the data-stores they provide.

There should be a single data Store

Data-stores are optional

Overview

Practical Scenarios

Components

Events

interface Foo {
    // ...
    event Bar(int arg1, string arg2);
    // ...
}

Translates to

struct Foo : Stencil::InterfaceT<Foo> {
    void RaiseEvent_Bar(int arg1, std::string const& arg2);
}

The scenario based wrappers (WebService, PythonBinding etc) must use the InterfaceT<>::RegisterHandler(this) to register themselves as the event handlers for these callback and take the necessary action

Dev Notes on Handler mechanism

Functions

interface Foo {
    // ...
    static int DoSomething();
    int DoSomethingContextual(int arg1, int arg2);
    // ...
}

Translates to

struct Foo {
    static int DoSomething();
    virtual int AddNumbers(int arg1, int arg2) =0;
}

If an interface contain non static functions, the generated class must be implemented before it can be used.

Object Store

interface Foo {
    // ...
    objectstore DataObject dataobject1;
    objectstore Dataobject dataobject2;
    // ...
}

Adding object data Store to the interface doesn’t add value. Object Data Store can always be added to the services exposing the interface.

Handwritten (Implementation)

struct FooImpl : public Foo<DatabaseT>
{
  using DataStoreT = DatabaseT; // Used by Foo to 
  
  virtual int AddNumbers(int arg1, int arg2) override 
  {
     RaiseEvent_Bar(arg1, "test");
     return arg1 + arg2 + _offset; 
  }
  
  int offset_{-1};
};

// Static functions
int Foo::DoSomething() { return -1; }

// Activators/Creators 
static std::unique_ptr<Foo> Foo::Create()
{
return new FooImpl();
};
static std::shared_ptr<Foo> Foo::Activate()
{
return new FooImpl();
};


Code Generated Scenarios

Web-Service

The IDL

interface Server1 {
    event SomethingHappened(uint32 arg1, SimpleObject1 arg2);
    // readonly SimpleObject1 obj3;
    // writable SimpleObject1 obj4;

    objectstore SimpleObject1 obj1;
    objectstore NestedObject  obj2;
    dict<uint32, SimpleObject1> Function1(uint32 arg1, SimpleObject1 arg2);
}

results in the following apis

Language Bindings

foo1 = new IFoo()
foo1.AddNumbers(1,2)
IFoo.DoSomething()
foo1.Bar.subscribe(callback)
foo2 = new IFoo()

Might be useful to have objectstore so we can do

foo1.dataobjects.add(new DataObject(....))
foo1.dataobjects.get(id)
foo1.dataobjects.remove(...)

Typescript SSE sync

Design Notes

Virtual functions (vs Linked Functions)

Status : Approved. If you don’t like virtual functions, go full static and manage threadlocal context.

Interface activation

Programmer provided functions:.

Pros (Virtual)

Pros (Linked)