Skip to content

Commit

Permalink
Fix MATLAB
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier committed Oct 30, 2024
1 parent b5b60d2 commit a52d3e7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
6 changes: 3 additions & 3 deletions matlab/src/ImplicitContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extern "C"
{
try
{
return createResultValue(createStringMap(deref<Ice::ImplicitContext>(self)->getContext()));
return createResultValue(createContext(deref<Ice::ImplicitContext>(self)->getContext()));
}
catch (...)
{
Expand All @@ -33,8 +33,8 @@ extern "C"
{
try
{
map<string, string> ctx;
getStringMap(newContext, ctx);
Ice::Context ctx;
getContext(newContext, ctx);
deref<Ice::ImplicitContext>(self)->setContext(ctx);
}
catch (...)
Expand Down
8 changes: 4 additions & 4 deletions matlab/src/ObjectPrx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ extern "C"
try
{
Ice::Context ctx;
getStringMap(context, ctx);
getContext(context, ctx);
auto ok = restoreProxy(self)->ice_invoke(op, mode, params, v, ctx);
mxArray* results = 0;
if (!v.empty())
Expand Down Expand Up @@ -309,7 +309,7 @@ extern "C"
try
{
Ice::Context ctx;
getStringMap(context, ctx);
getContext(context, ctx);
function<void()> token = proxy->ice_invokeAsync(
op,
mode,
Expand Down Expand Up @@ -400,15 +400,15 @@ extern "C"

mxArray* Ice_ObjectPrx_ice_getContext(void* self)
{
return createResultValue(createStringMap(restoreProxy(self)->ice_getContext()));
return createResultValue(createContext(restoreProxy(self)->ice_getContext()));
}

mxArray* Ice_ObjectPrx_ice_context(void* self, void** r, mxArray* c)
{
try
{
Ice::Context ctx;
getStringMap(c, ctx);
getContext(c, ctx);
auto proxy = restoreProxy(self);
auto newProxy = proxy->ice_context(ctx);
*r = newProxy == proxy ? nullptr : new Ice::ObjectPrx(std::move(newProxy));
Expand Down
33 changes: 32 additions & 1 deletion matlab/src/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,39 @@ IceMatlab::createStringMap(const map<string, string>& m)
return r;
}

// TODO: reduce duplication with code above

mxArray*
IceMatlab::createContext(const Ice::Context& m)
{
mxArray* r;
if (m.empty())
{
mexCallMATLAB(1, &r, 0, 0, "containers.Map");
}
else
{
mwSize dims[2] = {1, 0};
dims[1] = static_cast<int>(m.size());
auto keys = mxCreateCellArray(2, dims);
auto values = mxCreateCellArray(2, dims);
int idx = 0;
for (auto p : m)
{
mxSetCell(keys, idx, createStringFromUTF8(p.first));
mxSetCell(values, idx, createStringFromUTF8(p.second));
idx++;
}
mxArray* params[2];
params[0] = keys;
params[1] = values;
mexCallMATLAB(1, &r, 2, params, "containers.Map");
}
return r;
}

void
IceMatlab::getStringMap(mxArray* p, map<string, string>& m)
IceMatlab::getContext(mxArray* p, Ice::Context& m)
{
if (mxIsEmpty(p))
{
Expand Down
2 changes: 2 additions & 0 deletions matlab/src/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace IceMatlab
void getIdentity(mxArray*, Ice::Identity&);
mxArray* createStringMap(const std::map<std::string, std::string>&);
void getStringMap(mxArray*, std::map<std::string, std::string>&);
mxArray* createContext(const Ice::Context&);
void getContext(mxArray*, Ice::Context&);
mxArray* createProtocolVersion(const Ice::ProtocolVersion&);
mxArray* createEncodingVersion(const Ice::EncodingVersion&);
void getEncodingVersion(mxArray*, Ice::EncodingVersion&);
Expand Down

0 comments on commit a52d3e7

Please sign in to comment.