xpfCppPluginInvoke



FUNCTION xpfCppPluginInvoke (DllPath                                                      : STRING;
                             DllName                                                      : STRING; 
                             FunctionName         									      : STRING;
                             Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9, Arg10  : GENERIC;
                             Arg11,Arg12,Arg13,Arg14,Arg15,Arg16,Arg17,Arg18,Arg19,Arg20  : GENERIC;
                             Arg21,Arg22,Arg23,Arg24,Arg25,Arg26,Arg27,Arg28,Arg29,Arg30  : GENERIC)
                             Result                                                       : GENERIC; 
                

This function invokes a C++ method implemented in a .dll/.so file. The C++ plugin MUST contain the four methods:

  1. extern "C" EDMLONG DLL_EXPORT dll_main(char *methodName, tSdaiSelect *inputParameters, EDMINT nOfParameters, tSdaiSelect *returnValue)
  2. extern "C" EDMLONG DLL_EXPORT dll_version()
  3. extern "C" void  DLL_EXPORT *dll_malloc(void *threadObject, EDMLONG bufSize)
  4. extern "C" EDMLONG  DLL_EXPORT dll_freeAll(void *threadObject)



Arguments


TypeNameComment
STRINGDllPathSpecifies the file path for the .dll/.so file relative to the default folder of the EDM application server.
STRINGDllNameSpecifies the name of the .dll/.so file.
STRINGFunctionNameThe name of the function in the dll
GENERICArg1 - Arg30Optional, input parameters to the C++ method.

Return Value


 

TypeNameComment
GENERICactivatedModelIdreturned value from the C++ method



Example


  1. Calling the QEX methods

    -- ------------------------------------------------------------------------ 
    --  Author      : Olav Liestøl, EPM Technology A/S
    --  Description : Test 
    -- ------------------------------------------------------------------------
    QUERY_SCHEMA test_cpp_plugin FOR ap209_multidisciplinary_analysis_and_design_mim_lf;
        GLOBAL
            DECLARE src INSTANCE OF ap209_multidisciplinary_analysis_and_design_mim_lf;
        END_GLOBAL;
    
        VIEW_ENTITY result_value;
            elementId:                STRING;
            varableName:              STRING;
            fieldVarId:               INTEGER;
        END_VIEW_ENTITY;
    
        VIEW_ENTITY query_results;
            status:                   STRING;
            variable_values :         LIST OF result_value;
        END_VIEW_ENTITY;
    
        VIEW_ENTITY variable_def;
            selectName:               STRING;
            variableName:             STRING;
        END_VIEW_ENTITY;
    
        VIEW_ENTITY variable_definitions;
            status:                   STRING;
            definitions :             LIST OF variable_def;
        END_VIEW_ENTITY;
    
    
        QUERY_FUNCTION GetFemResults (repositoryName, modelName, loadCase : STRING; variables : LIST OF STRING) : STRING; 
           LOCAL
                vars                 : LIST OF INTEGER;
                rk                   : STRING;
                result               : query_results;
           END_LOCAL;
    
            vars ++ 29;
            vars ++ 30;
            vars ++ 31;
            vars ++ 32;
    
            result := xpfCppPluginInvoke('AP209queriesBin', 'AP209qexQueries.dll', 'getFemResults',
                                                  'InitialRepository', 'AP209_2', vars, vars, '*', 0, 10);
           Return (result.status);
       END_QUERY_FUNCTION;
    
       QUERY_FUNCTION GetVariableDefinitions : LIST OF STRING; 
           LOCAL
                result            : variable_definitions;
                output            : LIST OF STRING;
                o                 : STRING;
           END_LOCAL;
    
           result := xpfCppPluginInvoke('AP209queriesBin', 'AP209qexQueries.dll', 'getVariableDefinitions');
           REPEAT i:=1 TO xpfSizeOf(result.definitions);
             o := result.definitions[i].variableName;
             output ++ o;
          END_REPEAT;
          Return (output);
       END_QUERY_FUNCTION;
    END_QUERY_SCHEMA;
  2. Calling the C++ plugins

    #include "stdafx.h"
    
    #include "AP209queries.h"
    #include "AP209qexQueries.h"
    
    /*===================================================================================================================*/
    AP209qexQueries::AP209qexQueries(Database *_db, Repository *_rep, AP209model *_m)
    /*===================================================================================================================*/
    {
       dllMa = new CMemoryAllocator(0x100000); resultMa = NULL; db = _db; rep = _rep; m = _m;
    }
    /*===================================================================================================================*/
    AP209qexQueries::~AP209qexQueries()
    /*===================================================================================================================*/
    {
       if (resultMa) delete resultMa;
       delete dllMa;
    }
    /*===================================================================================================================*/
    void AP209qexQueries::openModel(char *repName, char *modelName)
    /*===================================================================================================================*/
    {
       rep->init(db, repName);
       m->open(modelName, sdaiRO);
    }
    
    /*===================================================================================================================*/
    EDMLONG AP209qexQueries::getFemResults(char *rep, char *model, char *parameterString, SdaiAggr variableIds, tSdaiSelect *returnValue,
       int maxNoOfResultsReturned, int firstResultReturned)
    /*===================================================================================================================*/
    {
       EdmiError rstat = OK;
       Container<EDMULONG> varTypes(m->getMemoryAllocator());
       InstanceId  resId, qresId;
       SdaiAggr    vvAggrId;
       ADB myADB;
       
       openModel(rep, model);
       AP209queries query(m);
    
       Iterator<EDMULONG, ap209::entityType> varTypeIter(variableIds, m);
       for (EDMULONG var=varTypeIter.first(); varTypeIter.moreElems(); var=varTypeIter.next()) {
          varTypes.add(var);
       }
       Container<femResult> *results = query.getResults(parameterString, &varTypes, maxNoOfResultsReturned, firstResultReturned) ;
    
       CHECK(vmCreateInstanceBN ("ap209_multidisciplinary_analysis_and_design_mim_lf", "test_cpp_plugin", "query_results", &qresId));
       myADB.type = sdaiSTRING; myADB.value.stringVal = "OK"; myADB.value_set = true;
       CHECK(vmPutAttrBN(qresId, "status", &myADB));
       returnValue->type = sdaiINSTANCE; returnValue->value.instVal = qresId; returnValue->nTypes = 0;
       CHECK(vmCreateAggrBN (qresId, "variable_values", &vvAggrId));
    
       for (femResult *res = results->firstp(); res; res = results->nextp()) {
          CHECK(vmCreateInstanceBN ("ap209_multidisciplinary_analysis_and_design_mim_lf", "test_cpp_plugin", "result_value", &resId));
          myADB.type = sdaiINSTANCE; myADB.value.instVal = resId; myADB.value_set = true;
          CHECK(vmAddToAggr(vvAggrId, &myADB));
       }
       return rstat;
    }
    /*===================================================================================================================*/
    EDMLONG AP209qexQueries::getVariableDefinitions(tSdaiSelect *returnValue)
    /*===================================================================================================================*/
    {
       EdmiError rstat = OK;
       int nOfVars;
       AP209queries query(m);
       InstanceId  vardefId, defsId;
       SdaiAggr    defsAggrId;
       ADB myADB;
    
       FieldVariableDescriptor  *fvDescriptors = query.getTheFieldVariableDescriptors(&nOfVars);
          
       CHECK(vmCreateInstanceBN ("ap209_multidisciplinary_analysis_and_design_mim_lf", "test_cpp_plugin", "variable_definitions", &defsId));
       myADB.type = sdaiSTRING; myADB.value.stringVal = "OK"; myADB.value_set = true;
       CHECK(vmPutAttrBN(defsId, "status", &myADB));
       returnValue->type = sdaiINSTANCE; returnValue->value.instVal = defsId; returnValue->nTypes = 0;
       CHECK(vmCreateAggrBN (defsId, "definitions", &defsAggrId));
       for (int i=0; i < nOfVars; i++) {
          CHECK(vmCreateInstanceBN ("ap209_multidisciplinary_analysis_and_design_mim_lf", "test_cpp_plugin", "variable_def", &vardefId));
          myADB.type = sdaiINSTANCE; myADB.value.instVal = vardefId; myADB.value_set = true;
          CHECK(vmAddToAggr(defsAggrId, &myADB));
          myADB.type = sdaiSTRING; 
          myADB.value.stringVal = fvDescriptors[i].selectName; CHECK(vmPutAttrBN(vardefId, "selectName", &myADB));
          myADB.value.stringVal = fvDescriptors[i].variableName; CHECK(vmPutAttrBN(vardefId, "variableName", &myADB));
       }
       return rstat;
    }
    /*================================================================================================*/
    void myExceptionHandler(EDMLONG errcode, char *message, char *file, int lineNo)
    /*================================================================================================*/
    {
       throw new CedmError(errcode,message,file, lineNo);
    }
    /*===================================================================================================================*/
    extern "C" EDMLONG DLL_EXPORT dll_main(char *methodName, tSdaiSelect *inputParameters, EDMINT nOfParameters,
       tSdaiSelect *returnValue)
    /*===================================================================================================================*/
    {
       EdmiError rstat = OK;
    
       try {
             defineExceptionHandler(&myExceptionHandler);
          
          CMemoryAllocator  the_ma(0x100000);
          Database          the_db("", "", "");
          Repository        the_rep(&the_db, "");
          AP209model        the_model(&the_ma, &the_rep);elementelement
             
          AP209qexQueries queryEngine(&the_db, &the_rep, &the_model);
    
    
          if (strEQL(methodName, "getFemResults")) {
             rstat = queryEngine.getFemResults(inputParameters[0].value.stringVal, inputParameters[1].value.stringVal, inputParameters[4].value.stringVal,
                inputParameters[2].value.aggrVal, returnValue, inputParameters[4].value.intVal, inputParameters[5].value.intVal);
          } else if (strEQL(methodName, "getVariableDefinitions")) {
             rstat = queryEngine.getVariableDefinitions(returnValue);
          }
       } catch (CedmError *e) {
          rstat = e->rstat; delete e;
       } catch (...) {
          rstat = sdaiESYSTEM;
       }
       return rstat;
    }
    
    extern "C" EDMLONG DLL_EXPORT dll_version()
    {
       return 1;
    }
    
    extern "C" void  DLL_EXPORT *dll_malloc(void *threadObject, EDMLONG bufSize)
    {
       AP209qexQueries *plugin = (AP209qexQueries*)threadObject;
       if (plugin) {
          return plugin->alloc(bufSize);
       } else {
          return NULL;
       }
    }
    
    extern "C" EDMLONG  DLL_EXPORT dll_freeAll(void *threadObject)
    {
       AP209qexQueries *plugin = (AP209qexQueries*)threadObject;
       delete plugin;
       return OK;
    }
    
    
    


See also

Filter by label

There are no items with the selected labels at this time.

   
Â