Skip to content

Provide functions in ModelicaUtilities.h to external objects implemented as shared libraries #4476

Open
@t-sommer

Description

@t-sommer

Currently it is not possible to access the functions in ModelicaUtilities.h from an ExternalObject that is implemented as a shared library in a generic way. Therefore I propose to introduce an ExternalObject

class ModelicaUtilityFunctions
  extends ExternalObject;

  function constructor
    output ModelicaUtilityFunctions functions;
  end constructor;

  function destructor
    input ModelicaUtilityFunctions functions;
  end destructor;

end ModelicaUtilityFunctions;

into the MSL that is implemented by the tools and returns a pointer to the following structure.

#include "ModelicaUtilities.h"

typedef struct {

	void  (*ModelicaMessage)(const char *string);
	void  (*ModelicaFormatMessage)(const char *string, ...);
	void  (*ModelicaVFormatMessage)(const char *string, va_list);
	void  (*ModelicaError)(const char *string);
	void  (*ModelicaFormatError)(const char *string, ...);
	void  (*ModelicaVFormatError)(const char *string, va_list);
	char* (*ModelicaAllocateString)(size_t len);
	char* (*ModelicaAllocateStringWithErrorReturn)(size_t len);
        // ...

} ModelicaUtilityFunctions_t;

This pointer can then be used by external objects to access these functions.

class MyExternalObject
  extends ExternalObject;

  function constructor
    input ModelicaUtilityFunctions callbacks;
    output MyExternalObject externalObject;
  external"C" externalObject =
        MyExternalObject_open(callbacks) annotation (
    Library="MyExternalObject");
  end constructor;

  function destructor
    input MyExternalObject externalObject;
  external"C" MyExternalObject_close(externalArduino) annotation (
    Library="MyExternalObject");
  end destructor;

end MyExternalObject;

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or enhancementspecificationIssue (also) addresses the Modelica language specification

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions