Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 22 additions & 46 deletions src/plugins/udr_engine/UdrEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ class Engine : public StdPlugin<IExternalEngineImpl<Engine, ThrowStatusWrapper>
{
public:
explicit Engine(IPluginConfig* par)
: functions(getPool()),
procedures(getPool()),
triggers(getPool())
: functionsMap(getPool()),
proceduresMap(getPool()),
triggersMap(getPool())
{
LocalStatus ls;
CheckStatusWrapper s(&ls);
Expand Down Expand Up @@ -98,7 +98,7 @@ class Engine : public StdPlugin<IExternalEngineImpl<Engine, ThrowStatusWrapper>
ThrowStatusWrapper* status,
GenericMap<Pair<NonPooled<IExternalContext*, ObjType*> > >& children,
SharedObjType* sharedObj, IExternalContext* context,
SortedArray<SharedObjType*>& sharedObjs, const PathName& moduleName);
GenericMap<RightPooledPair<IAttachment*, SortedArray<SharedObjType*> > >& sharedObjs, const PathName& moduleName);

template <typename ObjType> void deleteChildren(
GenericMap<Pair<NonPooled<IExternalContext*, ObjType*> > >& children);
Expand All @@ -121,9 +121,9 @@ class Engine : public StdPlugin<IExternalEngineImpl<Engine, ThrowStatusWrapper>
Mutex childrenMutex;

public:
SortedArray<class SharedFunction*> functions;
SortedArray<class SharedProcedure*> procedures;
SortedArray<class SharedTrigger*> triggers;
GenericMap<RightPooledPair<IAttachment*, SortedArray<class SharedFunction*>>> functionsMap;
GenericMap<RightPooledPair<IAttachment*, SortedArray<class SharedProcedure*>>> proceduresMap;
GenericMap<RightPooledPair<IAttachment*, SortedArray<class SharedTrigger*>>> triggersMap;
};


Expand Down Expand Up @@ -293,9 +293,8 @@ class SharedFunction : public DisposeIface<IExternalFunctionImpl<SharedFunction,
char* name, unsigned nameSize)
{
strncpy(name, context->getClientCharSet(), nameSize);

IExternalFunction* function = engine->getChild<IUdrFunctionFactory, IExternalFunction>(
status, children, this, context, engine->functions, moduleName);
status, children, this, context, engine->functionsMap, moduleName);

if (function)
function->getCharSet(status, context, name, nameSize);
Expand All @@ -304,7 +303,7 @@ class SharedFunction : public DisposeIface<IExternalFunctionImpl<SharedFunction,
void execute(ThrowStatusWrapper* status, IExternalContext* context, void* inMsg, void* outMsg)
{
IExternalFunction* function = engine->getChild<IUdrFunctionFactory, IExternalFunction>(
status, children, this, context, engine->functions, moduleName);
status, children, this, context, engine->functionsMap, moduleName);

if (function)
function->execute(status, context, inMsg, outMsg);
Expand Down Expand Up @@ -357,7 +356,7 @@ class SharedProcedure : public DisposeIface<IExternalProcedureImpl<SharedProcedu
strncpy(name, context->getClientCharSet(), nameSize);

IExternalProcedure* procedure = engine->getChild<IUdrProcedureFactory, IExternalProcedure>(
status, children, this, context, engine->procedures, moduleName);
status, children, this, context, engine->proceduresMap, moduleName);

if (procedure)
procedure->getCharSet(status, context, name, nameSize);
Expand All @@ -367,7 +366,7 @@ class SharedProcedure : public DisposeIface<IExternalProcedureImpl<SharedProcedu
void* inMsg, void* outMsg)
{
IExternalProcedure* procedure = engine->getChild<IUdrProcedureFactory, IExternalProcedure>(
status, children, this, context, engine->procedures, moduleName);
status, children, this, context, engine->proceduresMap, moduleName);

return procedure ? procedure->open(status, context, inMsg, outMsg) : NULL;
}
Expand Down Expand Up @@ -418,7 +417,7 @@ class SharedTrigger : public DisposeIface<IExternalTriggerImpl<SharedTrigger, Th
strncpy(name, context->getClientCharSet(), nameSize);

IExternalTrigger* trigger = engine->getChild<IUdrTriggerFactory, IExternalTrigger>(
status, children, this, context, engine->triggers, moduleName);
status, children, this, context, engine->triggersMap, moduleName);

if (trigger)
trigger->getCharSet(status, context, name, nameSize);
Expand All @@ -428,7 +427,7 @@ class SharedTrigger : public DisposeIface<IExternalTriggerImpl<SharedTrigger, Th
unsigned action, void* oldMsg, void* newMsg)
{
IExternalTrigger* trigger = engine->getChild<IUdrTriggerFactory, IExternalTrigger>(
status, children, this, context, engine->triggers, moduleName);
status, children, this, context, engine->triggersMap, moduleName);

if (trigger)
trigger->execute(status, context, action, oldMsg, newMsg);
Expand Down Expand Up @@ -582,12 +581,13 @@ template <typename NodeType, typename ObjType, typename SharedObjType> ObjType*
ThrowStatusWrapper* status,
GenericMap<Pair<NonPooled<IExternalContext*, ObjType*> > >& children, SharedObjType* sharedObj,
IExternalContext* context,
SortedArray<SharedObjType*>& sharedObjs, const PathName& moduleName)
GenericMap<RightPooledPair<IAttachment*, SortedArray<SharedObjType*> > >& sharedObjsMap, const PathName& moduleName)
{
MutexLockGuard guard(childrenMutex, FB_FUNCTION);

if (!sharedObjs.exist(sharedObj))
sharedObjs.add(sharedObj);
auto sharedObjs = sharedObjsMap.getOrPut(context->getAttachment(status));
if (!sharedObjs->exist(sharedObj))
sharedObjs->add(sharedObj);

ObjType* obj;
if (!children.get(context, obj))
Expand Down Expand Up @@ -651,39 +651,15 @@ void Engine::openAttachment(ThrowStatusWrapper* /*status*/, IExternalContext* /*
}


void Engine::closeAttachment(ThrowStatusWrapper* /*status*/, IExternalContext* context)
void Engine::closeAttachment(ThrowStatusWrapper* status, IExternalContext* context)
{
MutexLockGuard guard(childrenMutex, FB_FUNCTION);

for (SortedArray<SharedFunction*>::iterator i = functions.begin(); i != functions.end(); ++i)
{
IExternalFunction* function;
if ((*i)->children.get(context, function))
{
function->dispose();
(*i)->children.remove(context);
}
}

for (SortedArray<SharedProcedure*>::iterator i = procedures.begin(); i != procedures.end(); ++i)
{
IExternalProcedure* procedure;
if ((*i)->children.get(context, procedure))
{
procedure->dispose();
(*i)->children.remove(context);
}
}
auto attachment = context->getAttachment(status);

for (SortedArray<SharedTrigger*>::iterator i = triggers.begin(); i != triggers.end(); ++i)
{
IExternalTrigger* trigger;
if ((*i)->children.get(context, trigger))
{
trigger->dispose();
(*i)->children.remove(context);
}
}
functionsMap.remove(attachment);
proceduresMap.remove(attachment);
triggersMap.remove(attachment);
}


Expand Down
Loading