company logo

Creating an OSI interface

The ODABA Script Interface (OSI) provides a technology for interfacing C++ functions from within OSI functions. The example below shows the OSI interface for GlobalVariable class of the ODABA interface.

In order to call functions via the OSI interface, a library has to be provided exporting all functions to be interfaced.

Writing OSI interfaces is not really intuitive. Hence, a better way is creating OSI interfaces by means of ClassEditor. This requires the following steps:

  1. Implement a function by one or more implementations (at least return value and parameters have to be defined)
  2. Add a new implementation called _IF_ to the list of function implementations. This will automatically generate code for the OSI interface including distiction between different implementations by parameter count and type.
  3. Check the generated code (especially variable definitions) and do necessary corrections.
  4. Press the CI compile and link button in order to create an OSI interface library for the class. The OSI interface library for a class includes all functions defining an OSI inderface, i.e. having an implentation with name _IF_.

#include  <podaba.h>

#include  <h/if_mac.h>

#include  <_osi_GlobalVariable.hpp>

unsigned char _osi_CallConv _osi_GlobalVariable (PropertyHandle *co, PropertyHandle *retval, ParmList *parmlist, char *impname, ExecutionTypes exectype )

{

  OSIParmList    *pl   = reinterpret_cast<OSIParmList *>(parmlist);

  unsigned char         term = false;

  switch ( exectype )

  {

    case ET_Initialize :

         retval->CopyDescription(DBFieldDef::GetSystemFieldDef("GlobalVariable"));

         retval->GetDescription(false)->set_set_operation(AUTO);

         retval->GetDescription(false)->set_static(true);

         break;

    case ET_First      :

    {

         odaba::GlobalVariable   *CO               = INST_CAST(co->Get(0),odaba::GlobalVariable);

         int                       impnum          = AUTO;

         odaba::String             vString;

         odaba::Property           vProperty;

         retval->Close();

         CO->~GlobalVariable();

         switch ( pl->CheckParmCount(0,1) )

         {

           case 0 : impnum = 0;                     // impname == dummy

                    break;

           case 1 : if ( pl->IsText(1) )

                      impnum = 1;                   // impname == string

                    else

                      impnum = 2;                   // impname == property/value

                    break;

           default: ;

         }

         switch ( impnum )

         {

           case 0 : new(CO) odaba::GlobalVariable();             // impname == dummy

                    break;

           case 1 : pl->GetParms(vString);

                    new(CO) odaba::GlobalVariable(vString);      // impname == string

                    break;

           case 2 : pl->GetParms(vProperty);

                    new(CO) odaba::GlobalVariable(vProperty);    // impname == property/value

                    break;

           default: ;

         }

         retval->CopyHandle(co);

    }

         break;

    case ET_Next       :

    default            : term = true;

  }

  return ( term );

}

unsigned char _osi_CallConv _osi_create (PropertyHandle *co, PropertyHandle *retval, ParmList *parmlist, char *impname, ExecutionTypes exectype )

{

  OSIParmList    *pl   = reinterpret_cast<OSIParmList *>(parmlist);

  unsigned char         term = false;

  switch ( exectype )

  {

    case ET_Initialize :

         retval->Open();

         if ( co->GetDescription() ) {

           retval->CopyDescription(co->GetDescription());

           retval->GetDescription(false)->set_set_operation(true);

         }

         break;

    case ET_First      :

    {

         retval->Close();

         odaba::GlobalVariable   *CO      = INST_CAST(co->Get(0),odaba::GlobalVariable);

         int                      impnum  = AUTO;

         odaba::Property          vProperty;

         switch ( pl->CheckParmCount(1,1) )

         {

           case 1 : impnum = 0;                     // impname == property/value

                    break;

           default: ;

         }

         switch ( impnum )

         {

           case 0 : pl->GetParms(vProperty);

                    CO->create(vProperty);          // impname == property/value

                    break;

           default: ;

         }

         retval->CopyHandle(co);

    }

         break;

    case ET_Next       :

    default            : term = true;

  }

  return ( term );

}

unsigned char _osi_CallConv _osi_exist (PropertyHandle *co, PropertyHandle *retval, ParmList *parmlist, char *impname, ExecutionTypes exectype )

{

  OSIParmList    *pl   = reinterpret_cast<OSIParmList *>(parmlist);

  unsigned char         term = false;

  switch ( exectype )

  {

    case ET_Initialize :

         retval->CopyDescription(DBFieldDef::GetStaticFieldDef(T_LO));

         retval->GetDescription(false)->set_set_operation(AUTO);

         break;

    case ET_First      :

    {

         odaba::GlobalVariable *CO      = INST_CAST(co->Get(0),odaba::GlobalVariable);

         int                    impnum  = AUTO;

         bool                   bValue  = false;

         switch ( pl->CheckParmCount(0,0) )

         {

           case 0 : impnum = 0;                     // impname == get

                    break;

           default: ;

         }

         switch ( impnum )

         {

           case 0 : bValue = CO->exist();           // impname == get

                    *retval = (unsigned char)bValue;

                    break;

           default: ;

         }

    }

         break;

    case ET_Next       :

    default            : term = true;

  }

  return ( term );

}

unsigned char _osi_CallConv _osi_name (PropertyHandle *co, PropertyHandle *retval, ParmList *parmlist, char *impname, ExecutionTypes exectype )

{

  OSIParmList    *pl   = reinterpret_cast<OSIParmList *>(parmlist);

  unsigned char         term = false;

  switch ( exectype )

  {

    case ET_Initialize :

         retval->CopyDescription(DBFieldDef::GetStaticFieldDef(T_STRING));

         retval->GetDescription(false)->set_set_operation(AUTO);

         break;

    case ET_First      :

    {

         odaba::GlobalVariable *CO      = INST_CAST(co->Get(0),odaba::GlobalVariable);

         int                    impnum  = AUTO;

         odaba::String          vString;

         switch ( pl->CheckParmCount(0,0) )

         {

           case 0 : impnum = 0;                     // impname == get

                    break;

           default: ;

         }

         switch ( impnum )

         {

           case 0 : vString = CO->name();           // impname == get

                    *retval = vString._asNString();

                    break;

           default: ;

         }

    }

         break;

    case ET_Next       :

    default            : term = true;

  }

  return ( term );

}

unsigned char _osi_CallConv _osi_refresh (PropertyHandle *co, PropertyHandle *retval, ParmList *parmlist, char *impname, ExecutionTypes exectype )

{

  OSIParmList    *pl   = reinterpret_cast<OSIParmList *>(parmlist);

  unsigned char         term = false;

  switch ( exectype )

  {

    case ET_Initialize :

         retval->Open();

         if ( co->GetDescription() ) {

           retval->CopyDescription(co->GetDescription());

           retval->GetDescription(false)->set_set_operation(true);

         }

         break;

    case ET_First      :

    {

         retval->Close();

         odaba::GlobalVariable *CO      = INST_CAST(co->Get(0),odaba::GlobalVariable);

         int                    impnum  = AUTO;

         odaba::Property        vProperty;

         switch ( pl->CheckParmCount(0,0) )

         {

           case 0 : impnum = 0;                     // impname == default

                    break;

           default: ;

         }

         switch ( impnum )

         {

           case 0 : CO->refresh();                  // impname == default

                    break;

           default: ;

         }

         retval->CopyHandle(co);

    }

         break;

    case ET_Next       :

    default            : term = true;

  }

  return ( term );

}

unsigned char _osi_CallConv _osi_remove (PropertyHandle *co, PropertyHandle *retval, ParmList *parmlist, char *impname, ExecutionTypes exectype )

{

  OSIParmList    *pl   = reinterpret_cast<OSIParmList *>(parmlist);

  unsigned char   term = false;

  switch ( exectype )

  {

    case ET_Initialize :

         retval->CopyDescription(DBFieldDef::GetStaticFieldDef(T_VOID));

         retval->GetDescription(false)->set_set_operation(AUTO);

         break;

    case ET_First      :

    {

         retval->Close();

         odaba::GlobalVariable *CO      = INST_CAST(co->Get(0),odaba::GlobalVariable);

         int                    impnum  = AUTO;

         switch ( pl->CheckParmCount(0,0) )

         {

           case 0 : impnum = 0;                     // impname == default

                    break;

           default: ;

         }

         switch ( impnum )

         {

           case 0 : CO->remove();                   // impname == default

                    break;

           default: ;

         }

    }

         break;

    case ET_Next       :

    default            : term = true;

  }

  return ( term );

}