Commit 7d05b37c by amir

first working version with recursive fsm

parent d62aefc2
...@@ -2,17 +2,16 @@ ...@@ -2,17 +2,16 @@
<module type="CPP_MODULE" version="4"> <module type="CPP_MODULE" version="4">
<component name="NewModuleRootManager"> <component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/defs/enums.h" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/defs/retstat.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/defs/constants.h" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/defs/constants.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/defs/seh_types.cpp" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/defs/seh_types.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/defs/enums.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/defs/seh_types.h" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/defs/seh_types.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/defs/retstat.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/seh.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/seh/JsonCallFlowBuilder.h" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/seh/JsonCallFlowBuilder.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/seh/seh_engine.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/seh/seh_engine.h" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/seh/seh_engine.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/seh/JsonCallFlowBuilder.cpp" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/seh/JsonCallFlowBuilder.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/seh/XMLCallFlowBuilder.cpp" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/seh/XMLCallFlowBuilder.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/seh/seh_engine.cpp" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/seh/XMLCallFlowBuilder.h" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/seh/XMLCallFlowBuilder.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/CMakeLists.txt" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/CMakeLists.txt" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/test_seh.cpp" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/test/test_seh.cpp" isTestSource="false" />
......
cmake_minimum_required(VERSION 3.6) cmake_minimum_required(VERSION 2.8.12)
project(seh) project(seh)
# version stuff
set (seh_VERSION_MAJOR 0)
set (seh_VERSION_MINOR 1)
set (seh_VERSION_PATCH 0)
set(seh_VERSION_STRING ${seh_VERSION_MAJOR}.${seh_VERSION_MINOR}.${seh_VERSION_PATCH})
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
link_directories( ../3party/lib ) link_directories( ../3party/lib )
include_directories(SYSTEM ../3party/rapidjson-0.11/include/rapidjson) include_directories(SYSTEM ../3party/rapidjson-0.11/include/rapidjson)
set(SOURCE_FILES src/seh.h src/defs/constants.h src/defs/enums.h src/defs/retstat.h src/defs/seh_types.h src/defs/seh_types.cpp src/seh/seh_engine.cpp src/seh/seh_engine.h src/seh/JsonCallFlowBuilder.cpp src/seh/JsonCallFlowBuilder.h src/seh/XMLCallFlowBuilder.cpp src/seh/XMLCallFlowBuilder.h) set(SOURCE_FILES src/defs/constants.h src/defs/enums.h src/defs/retstat.h src/defs/seh_types.h src/defs/seh_types.cpp src/seh/seh_engine.cpp src/seh/seh_engine.h src/seh/JsonCallFlowBuilder.cpp src/seh/JsonCallFlowBuilder.h src/seh/XMLCallFlowBuilder.cpp src/seh/XMLCallFlowBuilder.h)
add_executable(seh ${SOURCE_FILES} test/test_seh.cpp) add_library(seh SHARED ${SOURCE_FILES})
\ No newline at end of file #target_link_libraries(seh ${PROJECT_LINK_LIBS} )
set_target_properties(seh PROPERTIES VERSION ${seh_VERSION_STRING}
SOVERSION ${seh_VERSION_MAJOR})
##add_executable(seh ${SOURCE_FILES} test/test_seh.cpp)
add_executable(test_seh test/test_seh.cpp)
target_link_libraries (test_seh seh)
# install part
set (CMAKE_INSTALL_PREFIX ../internals)
file (GLOB INSTALL_FILES "src/defs/*.h src/seh/seh_engine.h")
install(TARGETS seh DESTINATION lib)
install(FILES ${INSTALL_FILES} DESTINATION include/seh)
...@@ -29,7 +29,7 @@ RetStat ComplexEventAction::ActivateActions(EventData& eventData, ...@@ -29,7 +29,7 @@ RetStat ComplexEventAction::ActivateActions(EventData& eventData,
/****************************************** /******************************************
* check whether to move to the next state * check whether to move to the next state
******************************************/ ******************************************/
if (bMoveToNextState) if (bMoveToNextState && !activateActionData.boolWasStateChanged)
{ {
if (iNumOfActions > 0) { if (iNumOfActions > 0) {
if (eventData.NextStateValid()) { if (eventData.NextStateValid()) {
......
...@@ -712,9 +712,11 @@ RetStat JsonCallFlowBuilder::GetEventData(EventData &eventData, Document &eventN ...@@ -712,9 +712,11 @@ RetStat JsonCallFlowBuilder::GetEventData(EventData &eventData, Document &eventN
/******************************* /*******************************
* Resolving the action * Resolving the action
*******************************/ *******************************/
shared_ptr<EventAction> p_eventAction = make_shared<EventAction>();//new EventAction(); // shared_ptr<EventAction> p_eventAction = make_shared<EventAction>();//new EventAction();
p_eventAction->Reset(); // p_eventAction->Reset();
retStat = ResolveSimpleAction(p_eventAction.get(), (Document&)*actionNodeIterator); // retStat = ResolveSimpleAction(p_eventAction.get(), (Document&)*actionNodeIterator);
shared_ptr<EventAction> p_eventAction;
retStat = GetAction((Document&)*actionNodeIterator,&p_eventAction);
if (retStat.Fail()) if (retStat.Fail())
{ {
//p_eventAction = nullptr; //p_eventAction = nullptr;
......
...@@ -260,42 +260,62 @@ RetStat SehEngine::ResolveComplexActionNextState(EventAction* p_eventAction) { ...@@ -260,42 +260,62 @@ RetStat SehEngine::ResolveComplexActionNextState(EventAction* p_eventAction) {
/* /*
* checking the true actions * checking the true actions
*/ */
p_nextState = &p_eventIfAction->trueActions.nextState; retStat = ResolveRecursiveNextState(p_eventIfAction->trueActions);
if (p_nextState->IsValid()) if(retStat.Fail())
{
retStat = ResolveNextStateIndex(*p_nextState);
if (retStat.Fail())
{ {
retStat.SetFail(string(__PRETTY_FUNCTION__).append("-\tFailed to Resolve true actions NextState : ").append(p_nextState->stateName)); retStat.SetFail(string(__PRETTY_FUNCTION__).append("-\tFailed to Resolve true actions NextState : ").append(p_eventIfAction->trueActions.nextState.stateName));
return retStat; return retStat;
} }
} retStat = ResolveRecursiveNextState(p_eventIfAction->falseActions);
/* if(retStat.Fail())
* checking the false actions
*/
p_nextState = &p_eventIfAction->falseActions.nextState;
if (p_nextState->IsValid())
{
retStat = ResolveNextStateIndex(*p_nextState);
if (retStat.Fail())
{ {
retStat.SetFail(string(__PRETTY_FUNCTION__).append("-\tFailed to Resolve true actions NextState : ").append(p_nextState->stateName)); retStat.SetFail(string(__PRETTY_FUNCTION__).append("-\tFailed to Resolve true actions NextState : ").append(p_eventIfAction->falseActions.nextState.stateName));
return retStat; return retStat;
} }
}
// p_nextState = &p_eventIfAction->trueActions.nextState;
// if (p_nextState->IsValid())
// {
// retStat = ResolveNextStateIndex(*p_nextState);
// if (retStat.Fail())
// {
// retStat.SetFail(string(__PRETTY_FUNCTION__).append("-\tFailed to Resolve true actions NextState : ").append(p_nextState->stateName));
// return retStat;
// }
// }
// /*
// * checking the false actions
// */
// p_nextState = &p_eventIfAction->falseActions.nextState;
// if (p_nextState->IsValid())
// {
// retStat = ResolveNextStateIndex(*p_nextState);
// if (retStat.Fail())
// {
// retStat.SetFail(string(__PRETTY_FUNCTION__).append("-\tFailed to Resolve true actions NextState : ").append(p_nextState->stateName));
// return retStat;
// }
// }
break; break;
case nsEnums::eActionType_While: case nsEnums::eActionType_While:
p_eventWhileAction = (EventWhileAction*)p_eventAction; p_eventWhileAction = (EventWhileAction*)p_eventAction;
p_nextState = &p_eventWhileAction->whileActions.nextState; retStat = ResolveRecursiveNextState(p_eventWhileAction->whileActions);
if (p_nextState->IsValid()) if(retStat.Fail())
{
retStat = ResolveNextStateIndex(*p_nextState);
if (retStat.Fail())
{ {
retStat.SetFail(string(__PRETTY_FUNCTION__).append("-\tFailed to Resolve NextState in the While: ").append(p_nextState->stateName)); retStat.SetFail(string(__PRETTY_FUNCTION__).append("-\tFailed to Resolve NextState in the While: ").append(p_eventWhileAction->whileActions.nextState.stateName));
return retStat; return retStat;
} }
} // p_nextState = &p_eventWhileAction->whileActions.nextState;
// if (p_nextState->IsValid())
// {
// retStat = ResolveNextStateIndex(*p_nextState);
// if (retStat.Fail())
// {
// retStat.SetFail(string(__PRETTY_FUNCTION__).append("-\tFailed to Resolve NextState in the While: ").append(p_nextState->stateName));
// return retStat;
// }
// }
break; break;
case nsEnums::eActionType_Switch: case nsEnums::eActionType_Switch:
p_eventSwitchAction = (EventSwitchAction*)p_eventAction; p_eventSwitchAction = (EventSwitchAction*)p_eventAction;
...@@ -306,16 +326,22 @@ RetStat SehEngine::ResolveComplexActionNextState(EventAction* p_eventAction) { ...@@ -306,16 +326,22 @@ RetStat SehEngine::ResolveComplexActionNextState(EventAction* p_eventAction) {
iter != p_eventSwitchAction->switchActions.end(); ++iter) iter != p_eventSwitchAction->switchActions.end(); ++iter)
{ {
EventData& eventData = iter->second; EventData& eventData = iter->second;
p_nextState = &eventData.nextState; retStat = ResolveRecursiveNextState(eventData);
if (p_nextState->IsValid()) if(retStat.Fail())
{ {
retStat = ResolveNextStateIndex(*p_nextState); retStat.SetFail(string(__PRETTY_FUNCTION__).append("-\tFailed to Resolve NextState in the Switch: ").append(eventData.nextState.stateName));
if (retStat.Fail())
{
retStat.SetFail(string(__PRETTY_FUNCTION__).append("-\tFailed to Resolve NextState in the Switch: ").append(p_nextState->stateName));
return retStat; return retStat;
} }
} // p_nextState = &eventData.nextState;
// if (p_nextState->IsValid())
// {
// retStat = ResolveNextStateIndex(*p_nextState);
// if (retStat.Fail())
// {
// retStat.SetFail(string(__PRETTY_FUNCTION__).append("-\tFailed to Resolve NextState in the Switch: ").append(p_nextState->stateName));
// return retStat;
// }
// }
} }
break; break;
} }
...@@ -605,3 +631,50 @@ RetStat SehEngine::GetStateIndex(StateIndex &stateIndex, string &stateName) { ...@@ -605,3 +631,50 @@ RetStat SehEngine::GetStateIndex(StateIndex &stateIndex, string &stateName) {
return retStatus; return retStatus;
} }
/**
* checking recursively
* @param eventData
* @return
*/
RetStat SehEngine::ResolveRecursiveNextState(EventData &eventData) {
RetStat retStat;
NextState& nextState = eventData.nextState;
retStat = ResolveNextState(nextState);
if(retStat.Success())
{
/**
* going over the actions
*/
for (auto&& action: eventData.actions)
{
switch (action->actionType)
{
case eActionType_If:
case eActionType_While:
case eActionType_Switch:
retStat = ResolveComplexActionNextState(action.get());
break;
default:
break;
}
if(retStat.Fail())
break;
}
}
return RetStat();
}
RetStat SehEngine::ResolveNextState(NextState &nextState) {
RetStat retStat;
if (nextState.IsValid())
{
retStat = ResolveNextStateIndex(nextState);
if (retStat.Fail())
{
retStat.SetFail(string(__PRETTY_FUNCTION__).append("-\tFailed to Resolve true actions NextState : ").append(nextState.stateName));
return retStat;
}
}
return RetStat();
}
...@@ -148,6 +148,10 @@ public: ...@@ -148,6 +148,10 @@ public:
* @return * @return
*/ */
RetStat GetStateIndex(StateIndex& stateIndex, string& stateName); RetStat GetStateIndex(StateIndex& stateIndex, string& stateName);
RetStat ResolveRecursiveNextState(EventData &eventData);
RetStat ResolveNextState(NextState &nextState);
}; };
......
...@@ -36,9 +36,42 @@ ...@@ -36,9 +36,42 @@
"TO": "30000" "TO": "30000"
} }
}, { }, {
"Type": "If",
"Name": "IfElseAction",
"Then": {
"Actions": [{
"Type": "Action",
"Name": "SimpleAction"
}, {
"Type": "Action",
"Name": "ActionWithParamInt",
"Params": {
"TO": "300"
}
}, {
"Type": "Action",
"Name": "SimpleAction"
}],
"NextState": "Idle"
},
"Else": {
"Actions": [{
"Type": "Action",
"Name": "ActionWithParamInt",
"Params": {
"TO": "5000"
}
}, {
"Type": "Action",
"Name": "SimpleAction"
}, {
"Type": "Action", "Type": "Action",
"Name": "SimpleAction" "Name": "SimpleAction"
}], }],
"NextState": "Idle_IfElseState"
}
}],
"NextState": "Idle_IfThenState" "NextState": "Idle_IfThenState"
}, },
......
...@@ -95,7 +95,7 @@ public: ...@@ -95,7 +95,7 @@ public:
RetStat IfElseAction(ISEHParam* p_param) RetStat IfElseAction(ISEHParam* p_param)
{ {
retStat.SetFail(); retStat.Reset();//SetFail();
SEH_LOG("Action: \tIfElseAction"); SEH_LOG("Action: \tIfElseAction");
return retStat; return retStat;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment