Skip to content

Commit

Permalink
Corrected unclear specification of matlab mex call components to regi…
Browse files Browse the repository at this point in the history
…ster c functions
  • Loading branch information
hkhauke committed Feb 2, 2024
1 parent 2820223 commit cfc20d9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
26 changes: 19 additions & 7 deletions sources/jvxLibraries/jvxLexternalCall/include/CjvxMexCallsTpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ class CjvxMexCallsTpl : public CjvxMexCalls, public T
res = T::select(theOwner);
if (res == JVX_NO_ERROR)
{
// Run the class specific initialization
initExternalCall();

// Run mex call base classes function to init matlab call handles
res = CjvxMexCalls::select(_common_set_min.theHostRef, static_cast<CjvxProperties*>(this), "",
_theExtCallObjectName.c_str());
}
Expand All @@ -26,13 +29,22 @@ class CjvxMexCallsTpl : public CjvxMexCalls, public T
jvxErrorType unselect() override
{
jvxErrorType res = JVX_NO_ERROR;
res = T::unselect(); \
if (res == JVX_NO_ERROR)
{
res = CjvxMexCalls::unselect();
terminateExternalCall();
_theExtCallObjectName = "";
}
res = T::unselect();
if (res == JVX_NO_ERROR)
{
// Run the class specific implementation
terminateExternalCall();
res = CjvxMexCalls::unselect();

/*
* Should have been removed already in <CjvxMexCalls::unselect>
returnExternalCallHandle(_common_set_min.theHostRef, parent._theExtCallHandler);
parent._theExtCallHandler = NULL;
parent._theExtCallObjectName = "";
*/

_theExtCallObjectName = "";
}
return(res);
};

Expand Down
30 changes: 23 additions & 7 deletions sources/jvxLibraries/jvxLexternalCall/src/CjvxMexCalls_prv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,19 @@ CjvxMexCalls_prv::select(IjvxHiddenInterface* theHost, CjvxProperties* theProps,
{
#ifdef JVX_EXTERNAL_CALL_ENABLED

if (componentName)
parent._theExtCallObjectName = componentName;
if (parent._theExtCallObjectName.empty())
{
if (componentName)
parent._theExtCallObjectName = componentName;
}

parent._theExtCallHandler = NULL;
requestExternalCallHandle(theHost, &parent._theExtCallHandler);
if (parent._theExtCallHandler == nullptr)
{
requestExternalCallHandle(theHost, &parent._theExtCallHandler);
}

if (!parent._theExtCallHandler)
std::cerr << "[CjvxMexCalls_prv] WARNING: could not obtain mex call handler, disabling external call interface" << std::endl;
std::cerr << "[CjvxMexCalls_prv] WARNING: could not obtain mex call handler, disabling external call interface." << std::endl;
initExternalCallhandler(parent._theExtCallHandler, static_cast<IjvxExternalCallTarget*>(this), parent._theExtCallObjectName);
runtime.idThread = JVX_GET_CURRENT_THREAD_ID();

Expand All @@ -54,8 +60,18 @@ jvxErrorType
CjvxMexCalls_prv::unselect()
{
#ifdef JVX_EXTERNAL_CALL_ENABLED
terminateExternalCallhandler(parent._theExtCallHandler);
returnExternalCallHandle(theHostRef, parent._theExtCallHandler);

if (parent._theExtCallHandler)
{

terminateExternalCallhandler(parent._theExtCallHandler);
returnExternalCallHandle(theHostRef, parent._theExtCallHandler);
}
else
{
std::cerr << "[CjvxMexCalls_prv] WARNING: mex call handler removed to early, I am not able to de-regsiter the callbacks as required!" << std::endl;
}

parent._theExtCallHandler = NULL;
parent._theExtCallObjectName = "";

Expand Down

0 comments on commit cfc20d9

Please sign in to comment.