Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
ipgallery.common.cpp
/
seh
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Registry
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
18669a33
authored
Sep 18, 2016
by
amir
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
first working version with pointer allocations
parent
1537b4b9
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
768 additions
and
160 deletions
src/defs/enums.h
src/defs/retstat.h
src/defs/seh_types.cpp
src/defs/seh_types.h
src/seh/JsonCallFlowBuilder.cpp
src/seh/JsonCallFlowBuilder.h
src/seh/XMLCallFlowBuilder.cpp
src/seh/XMLCallFlowBuilder.h
src/seh/seh_engine.cpp
src/seh/seh_engine.h
test/resources/TestSEH.json
test/resources/TestSEH.xml
test/test_seh.cpp
src/defs/enums.h
View file @
18669a33
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
#define SEH_ENUMS_H
#define SEH_ENUMS_H
#include <map>
#include <map>
#include <string.h>
namespace
nsEnums
namespace
nsEnums
{
{
enum
eRetStat
enum
eRetStat
...
@@ -31,11 +32,13 @@ namespace nsEnums
...
@@ -31,11 +32,13 @@ namespace nsEnums
{
"Switch"
,
eActionType_Switch
}
{
"Switch"
,
eActionType_Switch
}
};
};
static
eEventActionType
ResolveEventActionType
(
const
char
*
eventActionType
)
static
eEventActionType
ResolveEventActionType
(
const
char
*
p_
eventActionType
)
{
{
auto
iterator
=
eventActionTypeMap
.
find
(
eventActionType
);
for
(
auto
entry
:
eventActionTypeMap
)
if
(
iterator
!=
eventActionTypeMap
.
end
())
{
return
iterator
->
second
;
if
(
strcasecmp
(
entry
.
first
,
p_eventActionType
)
==
0
)
return
entry
.
second
;
}
return
eActionType_Max
;
return
eActionType_Max
;
}
}
}
}
...
...
src/defs/retstat.h
View file @
18669a33
...
@@ -13,19 +13,19 @@ class RetStat
...
@@ -13,19 +13,19 @@ class RetStat
{
{
private
:
private
:
eRetStat
retstat_
;
eRetStat
retstat_
;
int
ret_code_
;
//
int ret_code_;
std
::
string
error_text_
;
std
::
string
error_text_
;
public
:
public
:
RetStat
()
:
retstat_
(
eSuccess
)
,
ret_code_
(
0
)
{}
RetStat
()
:
retstat_
(
eSuccess
)
/*, ret_code_(0)*/
{}
RetStat
(
bool
success_
,
int
ret_code_
,
const
std
::
string
&
error_text_
)
:
retstat_
(
eSuccess
),
RetStat
(
bool
success_
,
int
ret_code_
,
const
std
::
string
&
error_text_
)
:
retstat_
(
eSuccess
),
ret_code_
(
ret_code_
),
//
ret_code_(ret_code_),
error_text_
(
error_text_
)
{}
error_text_
(
error_text_
)
{}
void
Reset
()
void
Reset
()
{
{
retstat_
=
eSuccess
;
retstat_
=
eSuccess
;
ret_code_
=
0
;
//
ret_code_ = 0;
error_text_
.
clear
();
error_text_
.
clear
();
}
}
void
SetSuccess
()
{
retstat_
=
eSuccess
;
}
void
SetSuccess
()
{
retstat_
=
eSuccess
;
}
...
@@ -46,9 +46,23 @@ public:
...
@@ -46,9 +46,23 @@ public:
bool
Fail
()
{
return
(
retstat_
==
eFail
);
}
bool
Fail
()
{
return
(
retstat_
==
eFail
);
}
std
::
string
&
GetError
()
{
return
error_text_
;
}
std
::
string
&
GetError
()
{
return
error_text_
;
}
int
GetRetCode
()
const
{
/**
return
ret_code_
;
* using the error text assuming status will
* only be valid on success
* @return
*/
std
::
string
&
GetStatusText
()
{
return
error_text_
;
}
}
void
SetStatusText
(
std
::
string
&
status
)
{
error_text_
.
assign
(
status
);
}
void
SetStatusText
(
const
char
*
status
)
{
error_text_
.
assign
(
status
);
}
};
};
#endif //SEH_RETSTAT_H
#endif //SEH_RETSTAT_H
src/defs/seh_types.cpp
View file @
18669a33
...
@@ -12,12 +12,12 @@ RetStat ComplexEventAction::ActivateActions(EventData& eventData,
...
@@ -12,12 +12,12 @@ RetStat ComplexEventAction::ActivateActions(EventData& eventData,
{
{
int
iNumOfActions
=
eventData
.
getNumOfActions
();
int
iNumOfActions
=
eventData
.
getNumOfActions
();
for
(
EventAction
eventAction
:
eventData
.
actions
)
for
(
EventAction
*
p_
eventAction
:
eventData
.
actions
)
{
{
/*
/*
* activating the action
* activating the action
*/
*/
retStat
=
(
RetStat
)
eventAction
.
ActivateAction
(
activateActionData
);
//action.invoke(activateActionData.object,
eventAction.param);
retStat
=
p_eventAction
->
ActivateAction
(
activateActionData
);
//action.invoke(activateActionData.object, p_
eventAction.param);
if
(
retStat
.
Fail
())
if
(
retStat
.
Fail
())
{
{
//logger.severe("ComplexEventAction::ActivateActions-\tFailed in Action");
//logger.severe("ComplexEventAction::ActivateActions-\tFailed in Action");
...
@@ -34,9 +34,9 @@ RetStat ComplexEventAction::ActivateActions(EventData& eventData,
...
@@ -34,9 +34,9 @@ RetStat ComplexEventAction::ActivateActions(EventData& eventData,
if
(
iNumOfActions
>
0
)
{
if
(
iNumOfActions
>
0
)
{
if
(
eventData
.
NextStateValid
())
{
if
(
eventData
.
NextStateValid
())
{
activateActionData
.
boolWasStateChanged
=
true
;
activateActionData
.
boolWasStateChanged
=
true
;
activateActionData
.
nextStateIndex
.
uiStateFlowIndex
=
eventData
.
nextState
.
stateIndex
.
uiStateFlowIndex
;
activateActionData
.
p_nextStateIndex
->
Set
(
eventData
.
nextState
.
stateIndex
)
;
activateActionData
.
nextStateIndex
.
uiStateIndex
=
eventData
.
nextState
.
stateIndex
.
uiStateIndex
;
//logger.info("SEHEngine-\tChanging to State: " + eventData.nextState.stateName);
//logger.info("SEHEngine-\tChanging to State: " + eventData.nextState.stateName);
SEH_LOG
(
"ComplexEventAction::ActivateActions
\t
Changing to State: "
,
eventData
.
nextState
.
stateName
);
SEH_LOG
(
"ComplexEventAction::ActivateActions
\t
Changing to State: "
,
eventData
.
nextState
.
stateName
);
}
else
{
}
else
{
activateActionData
.
boolWasStateChanged
=
false
;
activateActionData
.
boolWasStateChanged
=
false
;
...
@@ -53,8 +53,8 @@ RetStat ComplexEventAction::ActivateActions(EventData& eventData,
...
@@ -53,8 +53,8 @@ RetStat ComplexEventAction::ActivateActions(EventData& eventData,
void
EventIfAction
::
Reset
()
void
EventIfAction
::
Reset
()
{
{
EventAction
::
Reset
();
EventAction
::
Reset
();
trueActions
.
Reset
();
//
trueActions.Reset();
falseActions
.
Reset
();
//
falseActions.Reset();
}
}
RetStat
EventIfAction
::
ActivateAction
(
ActivateActionData
&
activateActionData
)
RetStat
EventIfAction
::
ActivateAction
(
ActivateActionData
&
activateActionData
)
...
@@ -73,7 +73,7 @@ RetStat EventIfAction::ActivateAction(ActivateActionData& activateActionData)
...
@@ -73,7 +73,7 @@ RetStat EventIfAction::ActivateAction(ActivateActionData& activateActionData)
void
EventWhileAction
::
Reset
()
void
EventWhileAction
::
Reset
()
{
{
EventAction
::
Reset
();
EventAction
::
Reset
();
whileActions
.
Reset
();
//
whileActions.Reset();
}
}
RetStat
EventWhileAction
::
ActivateAction
(
ActivateActionData
&
activateActionData
)
RetStat
EventWhileAction
::
ActivateAction
(
ActivateActionData
&
activateActionData
)
...
@@ -90,7 +90,7 @@ RetStat EventWhileAction::ActivateAction(ActivateActionData &activateActionData)
...
@@ -90,7 +90,7 @@ RetStat EventWhileAction::ActivateAction(ActivateActionData &activateActionData)
if
(
whileActions
.
NextStateValid
()
)
if
(
whileActions
.
NextStateValid
()
)
{
{
activateActionData
.
boolWasStateChanged
=
true
;
activateActionData
.
boolWasStateChanged
=
true
;
activateActionData
.
nextStateIndex
=
whileActions
.
nextState
.
stateIndex
;
activateActionData
.
p_nextStateIndex
->
Set
(
whileActions
.
nextState
.
stateIndex
)
;
SEH_LOG
(
"EventWhileAction-
\t
Changing to State: "
,
whileActions
.
nextState
.
stateName
);
SEH_LOG
(
"EventWhileAction-
\t
Changing to State: "
,
whileActions
.
nextState
.
stateName
);
}
}
else
else
...
@@ -113,22 +113,22 @@ RetStat EventSwitchAction::ActivateAction(ActivateActionData &activateActionData
...
@@ -113,22 +113,22 @@ RetStat EventSwitchAction::ActivateAction(ActivateActionData &activateActionData
return
retStat
;
return
retStat
;
/************************************************************
/************************************************************
* Activating the appropriate case according to the ret
_code
* Activating the appropriate case according to the ret
status
***********************************************************/
***********************************************************/
if
(
retStat
.
GetRetCode
()
<
switchActions
.
size
())
EventData
*
p_eventData
=
Get
(
retStat
.
GetStatusText
());
if
(
p_eventData
!=
nullptr
)
{
{
EventData
eventData
=
switchActions
[
retStat
.
GetRetCode
()];
retStat
=
ActivateActions
(
*
p_eventData
,
activateActionData
,
true
);
retStat
=
ActivateActions
(
eventData
,
activateActionData
,
true
);
if
(
retStat
.
Success
())
if
(
retStat
.
Success
())
{
{
/******************************************
/******************************************
* check whether to move to the next state
* check whether to move to the next state
******************************************/
******************************************/
if
(
eventData
.
NextStateValid
()
)
if
(
p_eventData
->
NextStateValid
()
)
{
{
activateActionData
.
boolWasStateChanged
=
true
;
activateActionData
.
boolWasStateChanged
=
true
;
activateActionData
.
nextStateIndex
=
eventData
.
nextState
.
stateIndex
;
activateActionData
.
p_nextStateIndex
->
Set
(
p_eventData
->
nextState
.
stateIndex
)
;
SEH_LOG
(
"EventSwitchAction-
\t
Changing to State: "
,
eventData
.
nextState
.
stateName
);
SEH_LOG
(
"EventSwitchAction-
\t
Changing to State: "
,
p_eventData
->
nextState
.
stateName
);
}
}
else
else
{
{
...
@@ -139,7 +139,7 @@ RetStat EventSwitchAction::ActivateAction(ActivateActionData &activateActionData
...
@@ -139,7 +139,7 @@ RetStat EventSwitchAction::ActivateAction(ActivateActionData &activateActionData
}
}
else
else
{
{
retStat
.
SetFail
(
"EventSwitchAction::ActivateAction-
\t
Return value is bigger the num of switch cases"
);
retStat
.
SetFail
(
string
(
"EventSwitchAction::ActivateAction-
\t
switch case doesn't exists: "
).
append
(
retStat
.
GetStatusText
())
);
SEH_LOG_ERROR
(
retStat
.
GetError
());
SEH_LOG_ERROR
(
retStat
.
GetError
());
return
retStat
;
return
retStat
;
}
}
...
@@ -149,5 +149,5 @@ RetStat EventSwitchAction::ActivateAction(ActivateActionData &activateActionData
...
@@ -149,5 +149,5 @@ RetStat EventSwitchAction::ActivateAction(ActivateActionData &activateActionData
void
ActivateActionData
::
Reset
()
{
void
ActivateActionData
::
Reset
()
{
this
->
boolWasStateChanged
=
false
;
this
->
boolWasStateChanged
=
false
;
this
->
nextStateIndex
.
Reset
()
;
this
->
p_nextStateIndex
=
nullptr
;
}
}
src/defs/seh_types.h
View file @
18669a33
...
@@ -9,6 +9,8 @@
...
@@ -9,6 +9,8 @@
#include <vector>
#include <vector>
#include <iostream>
#include <iostream>
#include <map>
#include <map>
#include <bits/unique_ptr.h>
#include <list>
#include "constants.h"
#include "constants.h"
#include "retstat.h"
#include "retstat.h"
...
@@ -17,7 +19,8 @@ void seh_log(std::ostream& out, Arg&& arg, Args&&... args)
...
@@ -17,7 +19,8 @@ void seh_log(std::ostream& out, Arg&& arg, Args&&... args)
{
{
out
<<
std
::
forward
<
Arg
>
(
arg
);
out
<<
std
::
forward
<
Arg
>
(
arg
);
using
expander
=
int
[];
using
expander
=
int
[];
(
void
)
expander
{
0
,
(
void
(
out
<<
','
<<
std
::
forward
<
Args
>
(
args
)),
0
)...};
(
void
)
expander
{
0
,
(
void
(
out
<<
' '
<<
std
::
forward
<
Args
>
(
args
)),
0
)...};
out
<<
std
::
endl
;
}
}
#define SEH_LOG(...) seh_log(std::cout,__VA_ARGS__)
#define SEH_LOG(...) seh_log(std::cout,__VA_ARGS__)
...
@@ -53,6 +56,61 @@ struct StateIndex
...
@@ -53,6 +56,61 @@ struct StateIndex
return
(
uiStateIndex
!=
nsConstants
::
C_NO_ENTRY
&&
return
(
uiStateIndex
!=
nsConstants
::
C_NO_ENTRY
&&
uiStateFlowIndex
!=
nsConstants
::
C_NO_ENTRY
);
uiStateFlowIndex
!=
nsConstants
::
C_NO_ENTRY
);
}
}
void
Set
(
StateIndex
&
stateIndex
)
{
uiStateFlowIndex
=
stateIndex
.
uiStateFlowIndex
;
uiStateIndex
=
stateIndex
.
uiStateIndex
;
}
};
struct
_StateIndex
{
string
stateName
;
string
fsmId
;
_StateIndex
()
{
}
_StateIndex
(
_StateIndex
&
stateIndex
)
{
SEH_METHOD_LOG
(
"CopyConstructor"
);
this
->
fsmId
=
stateIndex
.
fsmId
;
this
->
stateName
=
stateIndex
.
stateName
;
}
_StateIndex
(
string
fsmId
,
string
stateName
)
{
this
->
fsmId
=
fsmId
;
this
->
stateName
=
stateName
;
}
void
Reset
()
{
stateName
.
clear
();
fsmId
.
clear
();
}
bool
isValid
()
{
return
(
!
fsmId
.
empty
()
&&
!
stateName
.
empty
());
}
_StateIndex
&
operator
=
(
_StateIndex
&&
stateIndex
){
SEH_METHOD_LOG
(
"move"
);
fsmId
=
move
(
stateIndex
.
fsmId
);
stateName
=
move
(
stateIndex
.
stateName
);
return
*
this
;
}
_StateIndex
&
operator
=
(
const
_StateIndex
&
stateIndex
){
SEH_METHOD_LOG
(
"copy"
);
fsmId
=
stateIndex
.
fsmId
;
stateName
=
stateIndex
.
stateName
;
return
*
this
;
}
};
};
...
@@ -74,10 +132,10 @@ typedef std::function<RetStat (ISEHParam* )> AFP;
...
@@ -74,10 +132,10 @@ typedef std::function<RetStat (ISEHParam* )> AFP;
struct
IBaseSEH
struct
IBaseSEH
{
{
virtual
AFP
resolveAction
(
const
char
*
actionName
)
=
0
;
virtual
AFP
resolveAction
(
const
char
*
actionName
)
=
0
;
virtual
int
resolveEvent
(
const
char
*
eventName
);
//
virtual int resolveEvent(const char* eventName);
virtual
const
char
*
resolveEventName
(
int
event
);
//
virtual const char* resolveEventName(int event);
virtual
ISEHParam
*
getNewSEHParam
();
virtual
ISEHParam
*
getNewSEHParam
()
=
0
;
virtual
void
setAppData
(
void
*
p_appData
);
virtual
void
setAppData
(
void
*
p_appData
)
=
0
;
//public RetStatSupplier invokeFunc(CallSite callSite, SEHParam sehParam) throws Throwable;
//public RetStatSupplier invokeFunc(CallSite callSite, SEHParam sehParam) throws Throwable;
};
};
...
@@ -88,7 +146,7 @@ struct IBaseSEH
...
@@ -88,7 +146,7 @@ struct IBaseSEH
struct
ActivateActionData
struct
ActivateActionData
{
{
//IBaseSEH* p_object;
//IBaseSEH* p_object;
StateIndex
nextStateIndex
;
StateIndex
*
p_
nextStateIndex
;
bool
boolWasStateChanged
;
// if true means that the called object
bool
boolWasStateChanged
;
// if true means that the called object
// change the state - moved to the next
// change the state - moved to the next
// state
// state
...
@@ -136,6 +194,7 @@ struct EventAction
...
@@ -136,6 +194,7 @@ struct EventAction
EventAction
&
operator
=
(
const
EventAction
&
eventAction
)
EventAction
&
operator
=
(
const
EventAction
&
eventAction
)
{
{
SEH_METHOD_LOG
(
"copy"
);
this
->
name
.
assign
(
eventAction
.
name
);
this
->
name
.
assign
(
eventAction
.
name
);
this
->
action
=
eventAction
.
action
;
this
->
action
=
eventAction
.
action
;
if
(
eventAction
.
p_param_
!=
nullptr
)
if
(
eventAction
.
p_param_
!=
nullptr
)
...
@@ -185,6 +244,12 @@ struct NextState
...
@@ -185,6 +244,12 @@ struct NextState
StateIndex
stateIndex
;
StateIndex
stateIndex
;
string
stateName
;
string
stateName
;
// NextState(NextState& nextState) {
// SEH_METHOD_LOG("CoptConstructor");
// stateIndex = nextState.stateIndex;
// stateName = nextState.stateName;
// }
void
Reset
()
void
Reset
()
{
{
stateIndex
.
Reset
();
stateIndex
.
Reset
();
...
@@ -193,6 +258,7 @@ struct NextState
...
@@ -193,6 +258,7 @@ struct NextState
NextState
&
operator
=
(
const
NextState
&
nextState
)
NextState
&
operator
=
(
const
NextState
&
nextState
)
{
{
SEH_METHOD_LOG
(
"copy"
);
this
->
stateIndex
=
nextState
.
stateIndex
;
this
->
stateIndex
=
nextState
.
stateIndex
;
this
->
stateName
.
assign
(
nextState
.
stateName
);
this
->
stateName
.
assign
(
nextState
.
stateName
);
return
*
this
;
return
*
this
;
...
@@ -223,10 +289,17 @@ struct EventData
...
@@ -223,10 +289,17 @@ struct EventData
{
{
// vector < tEventAction*> ta_Actions;
// vector < tEventAction*> ta_Actions;
// test - amir
// test - amir
vector
<
EventAction
>
actions
;
list
<
EventAction
*
>
actions
;
NextState
nextState
;
NextState
nextState
;
string
eventName
;
string
eventName
;
virtual
~
EventData
()
{
// for(auto p_eventAction : actions)
// delete(p_eventAction);
Reset
();
}
void
Reset
()
void
Reset
()
{
{
actions
.
clear
();
actions
.
clear
();
...
@@ -241,6 +314,7 @@ struct EventData
...
@@ -241,6 +314,7 @@ struct EventData
EventData
&
operator
=
(
const
EventData
&
eventData
)
EventData
&
operator
=
(
const
EventData
&
eventData
)
{
{
SEH_METHOD_LOG
(
"copy"
);
if
(
!
eventData
.
actions
.
empty
())
if
(
!
eventData
.
actions
.
empty
())
this
->
actions
=
eventData
.
actions
;
this
->
actions
=
eventData
.
actions
;
this
->
nextState
=
eventData
.
nextState
;
this
->
nextState
=
eventData
.
nextState
;
...
@@ -248,9 +322,22 @@ struct EventData
...
@@ -248,9 +322,22 @@ struct EventData
return
*
this
;
return
*
this
;
}
}
void
AddAction
(
EventAction
&
action
)
// EventData& operator = (EventData&& eventData)
// {
// SEH_METHOD_LOG("move");
// if (!eventData.actions.empty())
// this->actions = eventData.actions;
// this->nextState = eventData.nextState;
// this->eventName = move(eventData.eventName);
// return *this;
// }
void
AddAction
(
EventAction
*
p_action
)
{
{
actions
.
push_back
(
action
);
actions
.
push_back
(
p_action
);
}
const
NextState
&
GetNextState
()
const
{
return
nextState
;
}
}
bool
Empty
()
{
return
actions
.
empty
();
}
bool
Empty
()
{
return
actions
.
empty
();
}
...
@@ -281,11 +368,16 @@ struct EventIfAction: public ComplexEventAction
...
@@ -281,11 +368,16 @@ struct EventIfAction: public ComplexEventAction
EventData
trueActions
;
EventData
trueActions
;
EventData
falseActions
;
EventData
falseActions
;
EventIfAction
()
{
this
->
actionType
=
eActionType_If
;
}
EventIfAction
()
{
this
->
actionType
=
eActionType_If
;
// trueActions = unique_ptr<EventData>(new EventData());
// falseActions = unique_ptr<EventData>(new EventData());
}
void
Reset
();
void
Reset
();
RetStat
ActivateAction
(
ActivateActionData
&
activateActionData
);
RetStat
ActivateAction
(
ActivateActionData
&
activateActionData
);
EventIfAction
&
operator
=
(
const
EventIfAction
&
eventIfAction
)
EventIfAction
&
operator
=
(
const
EventIfAction
&
eventIfAction
)
{
{
SEH_METHOD_LOG
(
"EventIfAction copy"
);
this
->
operator
=
(
eventIfAction
);
this
->
operator
=
(
eventIfAction
);
trueActions
=
eventIfAction
.
trueActions
;
trueActions
=
eventIfAction
.
trueActions
;
falseActions
=
eventIfAction
.
falseActions
;
falseActions
=
eventIfAction
.
falseActions
;
...
@@ -297,11 +389,15 @@ struct EventWhileAction: public ComplexEventAction
...
@@ -297,11 +389,15 @@ struct EventWhileAction: public ComplexEventAction
{
{
EventData
whileActions
;
EventData
whileActions
;
EventWhileAction
()
{
this
->
actionType
=
eActionType_While
;
}
EventWhileAction
()
{
this
->
actionType
=
eActionType_While
;
//whileActions = unique_ptr<EventData>(new EventData());
}
void
Reset
();
void
Reset
();
RetStat
ActivateAction
(
ActivateActionData
&
activateActionData
);
RetStat
ActivateAction
(
ActivateActionData
&
activateActionData
);
EventWhileAction
&
operator
=
(
const
EventWhileAction
&
eventAction
)
EventWhileAction
&
operator
=
(
const
EventWhileAction
&
eventAction
)
{
{
SEH_METHOD_LOG
(
"EventWhileAction copy"
);
this
->
operator
=
(
eventAction
);
this
->
operator
=
(
eventAction
);
whileActions
=
eventAction
.
whileActions
;
whileActions
=
eventAction
.
whileActions
;
return
*
this
;
return
*
this
;
...
@@ -310,7 +406,7 @@ struct EventWhileAction: public ComplexEventAction
...
@@ -310,7 +406,7 @@ struct EventWhileAction: public ComplexEventAction
struct
EventSwitchAction
:
public
ComplexEventAction
struct
EventSwitchAction
:
public
ComplexEventAction
{
{
vector
<
EventData
>
switchActions
;
map
<
string
,
EventData
>
switchActions
;
//short numOfCases;
//short numOfCases;
EventSwitchAction
()
{
this
->
actionType
=
eActionType_Switch
;
}
EventSwitchAction
()
{
this
->
actionType
=
eActionType_Switch
;
}
...
@@ -319,11 +415,28 @@ struct EventSwitchAction: public ComplexEventAction
...
@@ -319,11 +415,28 @@ struct EventSwitchAction: public ComplexEventAction
RetStat
ActivateAction
(
ActivateActionData
&
activateActionData
);
RetStat
ActivateAction
(
ActivateActionData
&
activateActionData
);
EventSwitchAction
&
operator
=
(
const
EventSwitchAction
&
eventSwitchAction
)
EventSwitchAction
&
operator
=
(
const
EventSwitchAction
&
eventSwitchAction
)
{
{
SEH_METHOD_LOG
(
"EventSwitchAction copy"
);
this
->
operator
=
(
eventSwitchAction
);
this
->
operator
=
(
eventSwitchAction
);
// numOfCases = eventSwitchAction.numOfCases;
// numOfCases = eventSwitchAction.numOfCases;
switchActions
=
eventSwitchAction
.
switchActions
;
switchActions
=
eventSwitchAction
.
switchActions
;
return
*
this
;
return
*
this
;
}
}
void
Add
(
string
&
switchCase
,
EventData
&
eventData
)
{
switchActions
[
switchCase
]
=
eventData
;
}
void
Add
(
const
char
*
p_switchCase
,
EventData
&
eventData
)
{
switchActions
[
string
(
p_switchCase
)]
=
eventData
;
}
EventData
*
Get
(
string
&
switchCase
)
{
auto
iter
=
switchActions
.
find
(
switchCase
);
if
(
iter
!=
switchActions
.
end
())
return
&
iter
->
second
;
return
nullptr
;
}
};
};
struct
State
struct
State
...
@@ -343,16 +456,32 @@ struct State
...
@@ -343,16 +456,32 @@ struct State
stateName
.
clear
();
stateName
.
clear
();
baseState
.
Reset
();
baseState
.
Reset
();
}
}
State
&
operator
=
(
const
State
&
state
){
SEH_METHOD_LOG
(
"State copy"
);
eventsMap
=
state
.
eventsMap
;
stateName
=
state
.
stateName
;
baseState
=
state
.
baseState
;
return
*
this
;
}
};
};
struct
CallFlow
struct
CallFlow
{
{
int
flowIndex
=
0
;
int
flowIndex
=
0
;
vector
<
State
>
stateArray
;
vector
<
State
*
>
stateArray
;
int
iNumOfStates
;
int
iNumOfStates
;
string
flowFileName
;
string
flowFileName
;
IBaseSEH
*
p_baseSEHObject
;
IBaseSEH
*
p_baseSEHObject
;
virtual
~
CallFlow
()
{
for
(
State
*
p_state
:
stateArray
)
delete
(
p_state
);
Reset
();
}
void
Reset
()
void
Reset
()
{
{
flowIndex
=
0
;
flowIndex
=
0
;
...
@@ -364,6 +493,8 @@ struct CallFlow
...
@@ -364,6 +493,8 @@ struct CallFlow
string
&
GetFlowFileNameStr
()
string
&
GetFlowFileNameStr
()
{
{
SEH_METHOD_LOG
(
"copy"
);
return
flowFileName
;
return
flowFileName
;
}
}
...
@@ -371,6 +502,15 @@ struct CallFlow
...
@@ -371,6 +502,15 @@ struct CallFlow
{
{
return
flowFileName
.
c_str
();
return
flowFileName
.
c_str
();
}
}
CallFlow
&
operator
=
(
const
CallFlow
&
callFlow
){
SEH_METHOD_LOG
(
"copy"
);
flowIndex
=
callFlow
.
flowIndex
;
stateArray
=
callFlow
.
stateArray
;
flowFileName
=
callFlow
.
flowFileName
;
iNumOfStates
=
callFlow
.
iNumOfStates
;
p_baseSEHObject
=
callFlow
.
p_baseSEHObject
;
}
};
};
...
@@ -378,7 +518,7 @@ struct ICallFlowBuilder {
...
@@ -378,7 +518,7 @@ struct ICallFlowBuilder {
virtual
void
Clear
()
=
0
;
virtual
void
Clear
()
=
0
;
virtual
RetStat
BuildFlowTableFromFile
(
string
&
flowFileName
,
CallFlow
*
p_callFlow
,
IBaseSEH
*
p_baseSEHObject
)
=
0
;
virtual
RetStat
BuildFlowTableFromFile
(
string
&
flowFileName
,
CallFlow
*
p_callFlow
,
IBaseSEH
*
p_baseSEHObject
)
=
0
;
virtual
RetStat
BuildFlowTableFromString
(
string
&
flowFSM
,
CallFlow
*
p_callFlow
,
IBaseSEH
*
baseSEHObject
)
=
0
;
virtual
RetStat
BuildFlowTableFromString
(
const
char
*
p_
flowFSM
,
CallFlow
*
p_callFlow
,
IBaseSEH
*
baseSEHObject
)
=
0
;
};
};
#endif //SEH_SEH_TYPES_H
#endif //SEH_SEH_TYPES_H
src/seh/JsonCallFlowBuilder.cpp
View file @
18669a33
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
//
//
#include "JsonCallFlowBuilder.h"
#include "JsonCallFlowBuilder.h"
#include "../defs/seh_types.h"
#include <document.h>
#include <document.h>
#include <fstream>
#include <fstream>
#include <sstream>
#include <sstream>
...
@@ -33,15 +34,7 @@ RetStat JsonCallFlowBuilder::BuildFlowTableFromFile(string& flowFileName, CallFl
...
@@ -33,15 +34,7 @@ RetStat JsonCallFlowBuilder::BuildFlowTableFromFile(string& flowFileName, CallFl
{
{
std
::
stringstream
buffer
;
std
::
stringstream
buffer
;
buffer
<<
jsonFile
.
rdbuf
();
buffer
<<
jsonFile
.
rdbuf
();
p_flowDoc_
=
new
Document
();
return
BuildFlowTableFromString
(
buffer
.
str
().
c_str
(),
p_callFlow
,
p_baseSEHObject
);
if
(
!
p_flowDoc_
->
Parse
<
0
>
(
buffer
.
str
().
c_str
()).
HasParseError
())
{
retStat
=
CreateCallFlow
(
flowFileName
,
iCurrentState
);
}
else
{
retStat
.
SetFail
(
string
(
"Failed to parse File: "
).
append
(
flowFileName
));
}
}
}
else
else
{
{
...
@@ -51,7 +44,7 @@ RetStat JsonCallFlowBuilder::BuildFlowTableFromFile(string& flowFileName, CallFl
...
@@ -51,7 +44,7 @@ RetStat JsonCallFlowBuilder::BuildFlowTableFromFile(string& flowFileName, CallFl
return
retStat
;
return
retStat
;
}
}
RetStat
JsonCallFlowBuilder
::
BuildFlowTableFromString
(
string
&
flowFSM
,
CallFlow
*
p_callFlow
,
IBaseSEH
*
p_baseSEHObject
)
{
RetStat
JsonCallFlowBuilder
::
BuildFlowTableFromString
(
const
char
*
p_
flowFSM
,
CallFlow
*
p_callFlow
,
IBaseSEH
*
p_baseSEHObject
)
{
RetStat
retStat
;
RetStat
retStat
;
int
iCurrentState
=
0
;
int
iCurrentState
=
0
;
this
->
p_callFlow_
=
p_callFlow
;
this
->
p_callFlow_
=
p_callFlow
;
...
@@ -65,7 +58,7 @@ RetStat JsonCallFlowBuilder::BuildFlowTableFromString(string& flowFSM, CallFlow*
...
@@ -65,7 +58,7 @@ RetStat JsonCallFlowBuilder::BuildFlowTableFromString(string& flowFSM, CallFlow*
//this->p_callFlow_->flowFileName.assign(flowFileName);
//this->p_callFlow_->flowFileName.assign(flowFileName);
p_flowDoc_
=
new
Document
();
p_flowDoc_
=
new
Document
();
if
(
!
p_flowDoc_
->
Parse
<
0
>
(
flowFSM
.
c_str
()
).
HasParseError
())
if
(
!
p_flowDoc_
->
Parse
<
0
>
(
p_flowFSM
).
HasParseError
())
{
{
retStat
=
CreateCallFlow
(
this
->
flowFileName_
,
iCurrentState
);
retStat
=
CreateCallFlow
(
this
->
flowFileName_
,
iCurrentState
);
}
else
}
else
...
@@ -78,7 +71,6 @@ RetStat JsonCallFlowBuilder::BuildFlowTableFromString(string& flowFSM, CallFlow*
...
@@ -78,7 +71,6 @@ RetStat JsonCallFlowBuilder::BuildFlowTableFromString(string& flowFSM, CallFlow*
JsonCallFlowBuilder
::
JsonCallFlowBuilder
()
{
JsonCallFlowBuilder
::
JsonCallFlowBuilder
()
{
this
->
p_callFlow_
=
nullptr
;
this
->
p_callFlow_
=
nullptr
;
this
->
eventAction_
.
Reset
();
this
->
eventData_
.
Reset
();
this
->
eventData_
.
Reset
();
this
->
flowFileName_
.
clear
();
this
->
flowFileName_
.
clear
();
...
@@ -118,8 +110,8 @@ RetStat JsonCallFlowBuilder::CreateCallFlow(string& flowFileName, int iCurrentSt
...
@@ -118,8 +110,8 @@ RetStat JsonCallFlowBuilder::CreateCallFlow(string& flowFileName, int iCurrentSt
for
(
Value
::
ConstValueIterator
itr
=
statesArrayNode
.
Begin
();
itr
!=
statesArrayNode
.
End
();
++
itr
)
for
(
Value
::
ConstValueIterator
itr
=
statesArrayNode
.
Begin
();
itr
!=
statesArrayNode
.
End
();
++
itr
)
{
{
Document
*
p_currentStateNode
=
(
Document
*
)
itr
;
//stateNode;
Document
*
p_currentStateNode
=
(
Document
*
)
itr
;
//stateNode;
State
state
;
//
State state;
p_state
=
&
state
;
//p_callFlow_->stateArray[iCurrentState];
p_state
=
new
State
();
//
&state;//p_callFlow_->stateArray[iCurrentState];
//p_currentStateNode = stateNode;
//p_currentStateNode = stateNode;
/*
/*
* Getting the <Name> tag - first child
* Getting the <Name> tag - first child
...
@@ -145,7 +137,7 @@ RetStat JsonCallFlowBuilder::CreateCallFlow(string& flowFileName, int iCurrentSt
...
@@ -145,7 +137,7 @@ RetStat JsonCallFlowBuilder::CreateCallFlow(string& flowFileName, int iCurrentSt
/*********************
/*********************
* pushing the state
* pushing the state
*******************/
*******************/
p_callFlow_
->
stateArray
.
push_back
(
state
);
p_callFlow_
->
stateArray
.
push_back
(
p_
state
);
}
}
}
}
else
else
...
@@ -191,8 +183,7 @@ RetStat JsonCallFlowBuilder::GetState(Document &stateNode, State *p_State) {
...
@@ -191,8 +183,7 @@ RetStat JsonCallFlowBuilder::GetState(Document &stateNode, State *p_State) {
/*
/*
* adding the event to map
* adding the event to map
*/
*/
EventData
eventData
=
this
->
eventData_
;
p_State
->
eventsMap
[
this
->
eventData_
.
eventName
]
=
this
->
eventData_
;
p_State
->
eventsMap
[
this
->
eventData_
.
eventName
]
=
eventData
;
}
}
}
}
else
else
...
@@ -231,8 +222,9 @@ RetStat JsonCallFlowBuilder::GetEvent(Document &eventNode) {
...
@@ -231,8 +222,9 @@ RetStat JsonCallFlowBuilder::GetEvent(Document &eventNode) {
auto
&
eventNextStateNode
=
eventNode
[
nsConstants
::
C_NEXT_STATE
.
c_str
()];
auto
&
eventNextStateNode
=
eventNode
[
nsConstants
::
C_NEXT_STATE
.
c_str
()];
if
(
eventNextStateNode
.
IsString
())
if
(
eventNextStateNode
.
IsString
())
{
{
// checking for NULL state
string
nextStateStr
=
eventNextStateNode
.
GetString
();
string
nextStateStr
=
eventNextStateNode
.
GetString
();
if
(
nextStateStr
.
compare
(
nsConstants
::
C_N
EXT
_STATE
)
==
0
)
if
(
nextStateStr
.
compare
(
nsConstants
::
C_N
ULL
_STATE
)
==
0
)
{
{
this
->
eventData_
.
nextState
.
Reset
();
this
->
eventData_
.
nextState
.
Reset
();
}
}
...
@@ -271,17 +263,20 @@ RetStat JsonCallFlowBuilder::GetEventActions(Document &eventActionsNode) {
...
@@ -271,17 +263,20 @@ RetStat JsonCallFlowBuilder::GetEventActions(Document &eventActionsNode) {
for
(
auto
actionNodePtr
=
eventActionsNode
.
Begin
();
actionNodePtr
!=
eventActionsNode
.
End
();
++
actionNodePtr
)
for
(
auto
actionNodePtr
=
eventActionsNode
.
Begin
();
actionNodePtr
!=
eventActionsNode
.
End
();
++
actionNodePtr
)
{
{
Document
&
actionNode
=
*
(
Document
*
)
actionNodePtr
;
Document
&
actionNode
=
*
(
Document
*
)
actionNodePtr
;
EventAction
*
p_eventAction
=
nullptr
;
/*******************************
/*******************************
* Resolving the action
* Resolving the action
*******************************/
*******************************/
retStat
=
GetAction
(
actionNode
);
retStat
=
GetAction
(
actionNode
,
&
p_eventAction
);
if
(
retStat
.
Fail
()
)
if
(
retStat
.
Success
()
&&
p_eventAction
!=
nullptr
)
return
retStat
;
{
/*****************************
/*****************************
* Storing the action
* Storing the action
****************************/
****************************/
this
->
eventData_
.
AddAction
(
*
this
->
p_eventAction_
);
this
->
eventData_
.
AddAction
(
p_eventAction
);
delete
(
this
->
p_eventAction_
);
}
else
break
;
}
}
return
retStat
;
return
retStat
;
}
}
...
@@ -303,9 +298,9 @@ RetStat JsonCallFlowBuilder::GetEventActions(Document &eventActionsNode) {
...
@@ -303,9 +298,9 @@ RetStat JsonCallFlowBuilder::GetEventActions(Document &eventActionsNode) {
* @param actionNode
* @param actionNode
* @return
* @return
*/
*/
RetStat
JsonCallFlowBuilder
::
GetAction
(
Document
&
actionNode
)
{
RetStat
JsonCallFlowBuilder
::
GetAction
(
Document
&
actionNode
,
EventAction
**
pp_eventAction
)
{
RetStat
retStat
;
RetStat
retStat
;
this
->
eventAction_
.
Reset
();
/*
/*
* getting the type
* getting the type
*/
*/
...
@@ -318,33 +313,33 @@ RetStat JsonCallFlowBuilder::GetAction(Document &actionNode) {
...
@@ -318,33 +313,33 @@ RetStat JsonCallFlowBuilder::GetAction(Document &actionNode) {
switch
(
eventActonType
)
{
switch
(
eventActonType
)
{
case
eActionType_Regular
:
case
eActionType_Regular
:
// Handle action
// Handle action
this
->
p_eventAction_
=
new
EventAction
();
*
pp_eventAction
=
new
EventAction
();
this
->
p_eventAction_
->
Reset
();
(
*
pp_eventAction
)
->
Reset
();
retStat
=
ResolveSimpleAction
(
this
->
p_eventAction_
,
actionNode
);
retStat
=
ResolveSimpleAction
(
*
pp_eventAction
,
actionNode
);
break
;
break
;
case
eActionType_If
:
case
eActionType_If
:
this
->
p_eventAction_
=
new
EventIfAction
();
*
pp_eventAction
=
new
EventIfAction
();
this
->
p_eventAction_
->
Reset
();
(
*
pp_eventAction
)
->
Reset
();
/*******************************
/*******************************
* Getting the condition action
* Getting the condition action
********************************/
********************************/
retStat
=
HandleEventIfAction
((
EventIfAction
*
)
this
->
p_eventAction_
,
actionNode
);
retStat
=
HandleEventIfAction
((
EventIfAction
*
)
*
pp_eventAction
,
actionNode
);
break
;
break
;
case
eActionType_Switch
:
case
eActionType_Switch
:
this
->
p_eventAction_
=
new
EventSwitchAction
();
*
pp_eventAction
=
new
EventSwitchAction
();
this
->
p_eventAction_
->
Reset
();
(
*
pp_eventAction
)
->
Reset
();
/*******************************
/*******************************
* Getting the condition action
* Getting the condition action
********************************/
********************************/
retStat
=
HandleEventSwitchAction
((
EventSwitchAction
*
)
this
->
p_eventAction_
,
actionNode
);
retStat
=
HandleEventSwitchAction
((
EventSwitchAction
*
)
*
pp_eventAction
,
actionNode
);
break
;
break
;
case
eActionType_While
:
case
eActionType_While
:
this
->
p_eventAction_
=
new
EventWhileAction
();
*
pp_eventAction
=
new
EventWhileAction
();
this
->
p_eventAction_
->
Reset
();
(
*
pp_eventAction
)
->
Reset
();
/*******************************
/*******************************
* Getting the condition action
* Getting the condition action
********************************/
********************************/
retStat
=
HandleEventWhileAction
((
EventWhileAction
*
)
this
->
p_eventAction_
,
actionNode
);
retStat
=
HandleEventWhileAction
((
EventWhileAction
*
)
*
pp_eventAction
,
actionNode
);
break
;
break
;
default
:
default
:
break
;
break
;
...
@@ -562,7 +557,7 @@ RetStat JsonCallFlowBuilder::HandleEventSwitchAction(EventSwitchAction *p_eventS
...
@@ -562,7 +557,7 @@ RetStat JsonCallFlowBuilder::HandleEventSwitchAction(EventSwitchAction *p_eventS
{
{
for
(
auto
caseIterator
=
caseNodeIterator
->
MemberBegin
();
caseIterator
!=
caseNodeIterator
->
MemberEnd
();
++
caseIterator
)
for
(
auto
caseIterator
=
caseNodeIterator
->
MemberBegin
();
caseIterator
!=
caseNodeIterator
->
MemberEnd
();
++
caseIterator
)
{
{
if
(
caseIterator
->
value
.
IsObject
())
{
if
(
caseIterator
->
name
.
IsString
()
&&
caseIterator
->
value
.
IsObject
())
{
unique_ptr
<
EventData
>
p_eventData
(
new
EventData
());
unique_ptr
<
EventData
>
p_eventData
(
new
EventData
());
retStat
=
GetEventData
(
*
p_eventData
,
(
Document
&
)
caseIterator
->
value
);
retStat
=
GetEventData
(
*
p_eventData
,
(
Document
&
)
caseIterator
->
value
);
if
(
retStat
.
Fail
())
if
(
retStat
.
Fail
())
...
@@ -570,7 +565,7 @@ RetStat JsonCallFlowBuilder::HandleEventSwitchAction(EventSwitchAction *p_eventS
...
@@ -570,7 +565,7 @@ RetStat JsonCallFlowBuilder::HandleEventSwitchAction(EventSwitchAction *p_eventS
/*
/*
* add the event data
* add the event data
*/
*/
p_eventSwitchAction
->
switchActions
.
push_back
(
*
p_eventData
);
p_eventSwitchAction
->
Add
(
caseIterator
->
name
.
GetString
(),
*
p_eventData
);
}
else
{
}
else
{
retStat
.
SetFail
(
string
(
"JsonCallFlowBuilder.HandleEventSwitchAction-
\t
no case object: "
).
append
(
p_eventSwitchAction
->
name
));
retStat
.
SetFail
(
string
(
"JsonCallFlowBuilder.HandleEventSwitchAction-
\t
no case object: "
).
append
(
p_eventSwitchAction
->
name
));
}
}
...
@@ -680,6 +675,7 @@ void JsonCallFlowBuilder::GetActionParams(EventAction *p_eventAction, Document &
...
@@ -680,6 +675,7 @@ void JsonCallFlowBuilder::GetActionParams(EventAction *p_eventAction, Document &
*/
*/
RetStat
JsonCallFlowBuilder
::
ResolveActionFunc
(
EventAction
*
p_eventAction
,
const
char
*
p_actionFuncName
)
{
RetStat
JsonCallFlowBuilder
::
ResolveActionFunc
(
EventAction
*
p_eventAction
,
const
char
*
p_actionFuncName
)
{
RetStat
retStat
;
RetStat
retStat
;
p_eventAction
->
name
.
assign
(
p_actionFuncName
);
/*********************************
/*********************************
* Resolve action
* Resolve action
********************************/
********************************/
...
@@ -716,9 +712,9 @@ RetStat JsonCallFlowBuilder::GetEventData(EventData &eventData, Document &eventN
...
@@ -716,9 +712,9 @@ RetStat JsonCallFlowBuilder::GetEventData(EventData &eventData, Document &eventN
/*******************************
/*******************************
* Resolving the action
* Resolving the action
*******************************/
*******************************/
unique_ptr
<
EventAction
>
p_eventAction
(
new
EventAction
()
);
EventAction
*
p_eventAction
=
new
EventAction
(
);
p_eventAction
->
Reset
();
p_eventAction
->
Reset
();
retStat
=
ResolveSimpleAction
(
p_eventAction
.
get
()
,
(
Document
&
)
*
actionNodeIterator
);
retStat
=
ResolveSimpleAction
(
p_eventAction
,
(
Document
&
)
*
actionNodeIterator
);
if
(
retStat
.
Fail
())
if
(
retStat
.
Fail
())
{
{
//p_eventAction = nullptr;
//p_eventAction = nullptr;
...
@@ -728,7 +724,7 @@ RetStat JsonCallFlowBuilder::GetEventData(EventData &eventData, Document &eventN
...
@@ -728,7 +724,7 @@ RetStat JsonCallFlowBuilder::GetEventData(EventData &eventData, Document &eventN
/*****************************
/*****************************
* Storing the action
* Storing the action
****************************/
****************************/
eventData
.
AddAction
(
*
p_eventAction
);
eventData
.
AddAction
(
p_eventAction
);
}
}
}
else
}
else
{
{
...
@@ -743,6 +739,7 @@ RetStat JsonCallFlowBuilder::GetEventData(EventData &eventData, Document &eventN
...
@@ -743,6 +739,7 @@ RetStat JsonCallFlowBuilder::GetEventData(EventData &eventData, Document &eventN
const
char
*
p_nextState
=
getParamString
(
eventNode
,
nsConstants
::
C_NEXT_STATE
.
c_str
());
const
char
*
p_nextState
=
getParamString
(
eventNode
,
nsConstants
::
C_NEXT_STATE
.
c_str
());
if
(
p_nextState
)
if
(
p_nextState
)
{
{
//
if
(
strcasecmp
(
p_nextState
,
nsConstants
::
C_NULL_STATE
.
c_str
())
!=
0
)
if
(
strcasecmp
(
p_nextState
,
nsConstants
::
C_NULL_STATE
.
c_str
())
!=
0
)
eventData
.
nextState
.
setStateName
(
p_nextState
);
eventData
.
nextState
.
setStateName
(
p_nextState
);
else
else
...
...
src/seh/JsonCallFlowBuilder.h
View file @
18669a33
...
@@ -15,8 +15,6 @@ using namespace rapidjson;
...
@@ -15,8 +15,6 @@ using namespace rapidjson;
class
JsonCallFlowBuilder
:
public
ICallFlowBuilder
{
class
JsonCallFlowBuilder
:
public
ICallFlowBuilder
{
private
:
private
:
EventData
eventData_
;
EventData
eventData_
;
EventAction
eventAction_
;
EventAction
*
p_eventAction_
;
CallFlow
*
p_callFlow_
;
CallFlow
*
p_callFlow_
;
IBaseSEH
*
p_baseSEHObject_
;
IBaseSEH
*
p_baseSEHObject_
;
string
flowFileName_
;
string
flowFileName_
;
...
@@ -27,7 +25,7 @@ public:
...
@@ -27,7 +25,7 @@ public:
virtual
RetStat
BuildFlowTableFromFile
(
string
&
flowFileName
,
CallFlow
*
p_callFlow
,
IBaseSEH
*
p_baseSEHObject
)
override
;
virtual
RetStat
BuildFlowTableFromFile
(
string
&
flowFileName
,
CallFlow
*
p_callFlow
,
IBaseSEH
*
p_baseSEHObject
)
override
;
virtual
RetStat
BuildFlowTableFromString
(
string
&
flowFSM
,
CallFlow
*
p_callFlow
,
IBaseSEH
*
baseSEHObject
)
override
;
virtual
RetStat
BuildFlowTableFromString
(
const
char
*
p_
flowFSM
,
CallFlow
*
p_callFlow
,
IBaseSEH
*
baseSEHObject
)
override
;
RetStat
CreateCallFlow
(
string
&
basic_string
,
int
iCurrentState
);
RetStat
CreateCallFlow
(
string
&
basic_string
,
int
iCurrentState
);
...
@@ -37,7 +35,7 @@ public:
...
@@ -37,7 +35,7 @@ public:
RetStat
GetEventActions
(
Document
&
eventActionsNode
);
RetStat
GetEventActions
(
Document
&
eventActionsNode
);
RetStat
GetAction
(
Document
&
actionNode
);
RetStat
GetAction
(
Document
&
actionNode
,
EventAction
**
pp_eventAction
);
RetStat
ResolveSimpleAction
(
EventAction
*
p_eventAction
,
Document
&
actionNode
);
RetStat
ResolveSimpleAction
(
EventAction
*
p_eventAction
,
Document
&
actionNode
);
...
...
src/seh/XMLCallFlowBuilder.cpp
View file @
18669a33
...
@@ -12,6 +12,6 @@ RetStat XMLCallFlowBuilder::BuildFlowTableFromFile(string& flowFileName, CallFlo
...
@@ -12,6 +12,6 @@ RetStat XMLCallFlowBuilder::BuildFlowTableFromFile(string& flowFileName, CallFlo
return
RetStat
();
return
RetStat
();
}
}
RetStat
XMLCallFlowBuilder
::
BuildFlowTableFromString
(
string
&
flowFSM
,
CallFlow
*
p_callFlow
,
IBaseSEH
*
baseSEHObject
)
{
RetStat
XMLCallFlowBuilder
::
BuildFlowTableFromString
(
const
char
*
p_
flowFSM
,
CallFlow
*
p_callFlow
,
IBaseSEH
*
baseSEHObject
)
{
return
RetStat
();
return
RetStat
();
}
}
src/seh/XMLCallFlowBuilder.h
View file @
18669a33
...
@@ -13,7 +13,7 @@ class XMLCallFlowBuilder : public ICallFlowBuilder{
...
@@ -13,7 +13,7 @@ class XMLCallFlowBuilder : public ICallFlowBuilder{
public
:
public
:
virtual
RetStat
BuildFlowTableFromFile
(
string
&
flowFileName
,
CallFlow
*
p_callFlow
,
IBaseSEH
*
p_baseSEHObject
)
override
;
virtual
RetStat
BuildFlowTableFromFile
(
string
&
flowFileName
,
CallFlow
*
p_callFlow
,
IBaseSEH
*
p_baseSEHObject
)
override
;
virtual
RetStat
BuildFlowTableFromString
(
string
&
flowFSM
,
CallFlow
*
p_callFlow
,
IBaseSEH
*
baseSEHObject
)
override
;
virtual
RetStat
BuildFlowTableFromString
(
const
char
*
p_
flowFSM
,
CallFlow
*
p_callFlow
,
IBaseSEH
*
baseSEHObject
)
override
;
virtual
void
Clear
()
override
;
virtual
void
Clear
()
override
;
};
};
...
...
src/seh/seh_engine.cpp
View file @
18669a33
...
@@ -49,7 +49,7 @@ RetStat SehEngine::BuildMultiCallFlowTables(map<string, string> &flowFilesMap) {
...
@@ -49,7 +49,7 @@ RetStat SehEngine::BuildMultiCallFlowTables(map<string, string> &flowFilesMap) {
retStat
=
BuildSingleFlowTable
(
entry
.
first
,
entry
.
second
);
retStat
=
BuildSingleFlowTable
(
entry
.
first
,
entry
.
second
);
if
(
retStat
.
Fail
())
if
(
retStat
.
Fail
())
{
{
if
(
!
retStat
.
GetError
().
empty
())
if
(
retStat
.
GetError
().
empty
())
SEH_LOG_ERROR
(
"BuildMultiCallFlowTables-
\t
Failed to parse flow"
);
SEH_LOG_ERROR
(
"BuildMultiCallFlowTables-
\t
Failed to parse flow"
);
else
else
SEH_LOG_ERROR
(
retStat
.
GetError
());
SEH_LOG_ERROR
(
retStat
.
GetError
());
...
@@ -93,7 +93,7 @@ ICallFlowBuilder *SehEngine::createCallFlowBuilder(string flowFile) {
...
@@ -93,7 +93,7 @@ ICallFlowBuilder *SehEngine::createCallFlowBuilder(string flowFile) {
string
fileExt
=
flowFile
.
substr
(
lastIndexOf
+
1
);
string
fileExt
=
flowFile
.
substr
(
lastIndexOf
+
1
);
if
(
fileExt
.
compare
(
"xml"
)
==
0
)
if
(
fileExt
.
compare
(
"xml"
)
==
0
)
return
new
XMLCallFlowBuilder
();
return
new
XMLCallFlowBuilder
();
else
if
(
fileExt
.
compare
(
"json"
))
else
if
(
fileExt
.
compare
(
"json"
)
==
0
)
return
new
JsonCallFlowBuilder
();
return
new
JsonCallFlowBuilder
();
}
}
return
nullptr
;
return
nullptr
;
...
@@ -149,9 +149,9 @@ RetStat SehEngine::ResolveNextStateIndex(NextState& nextState) {
...
@@ -149,9 +149,9 @@ RetStat SehEngine::ResolveNextStateIndex(NextState& nextState) {
if
(
p_callFlow
->
iNumOfStates
>
0
&&
!
p_callFlow
->
stateArray
.
empty
())
if
(
p_callFlow
->
iNumOfStates
>
0
&&
!
p_callFlow
->
stateArray
.
empty
())
{
{
int
iStateIndex
=
0
;
int
iStateIndex
=
0
;
for
(
State
state
:
p_callFlow
->
stateArray
)
for
(
State
*
p_
state
:
p_callFlow
->
stateArray
)
{
{
if
(
state
.
stateName
.
compare
(
nextState
.
stateName
)
==
0
)
if
(
p_state
->
stateName
.
compare
(
nextState
.
stateName
)
==
0
)
{
{
nextState
.
stateIndex
.
uiStateFlowIndex
=
iFlowIndex
;
nextState
.
stateIndex
.
uiStateFlowIndex
=
iFlowIndex
;
nextState
.
stateIndex
.
uiStateIndex
=
iStateIndex
;
nextState
.
stateIndex
.
uiStateIndex
=
iStateIndex
;
...
@@ -180,12 +180,12 @@ RetStat SehEngine::ResolveNextStateIndexes() {
...
@@ -180,12 +180,12 @@ RetStat SehEngine::ResolveNextStateIndexes() {
/*****************************
/*****************************
* going over the flow states
* going over the flow states
*****************************/
*****************************/
for
(
State
statePtr
:
p_callFlow
->
stateArray
)
for
(
State
*
p_state
:
p_callFlow
->
stateArray
)
{
{
/**************************
/**************************
* Scanning the map events
* Scanning the map events
*************************/
*************************/
for
(
auto
eventMapItr
:
statePtr
.
eventsMap
)
for
(
auto
&
eventMapItr
:
p_state
->
eventsMap
)
{
{
EventData
*
p_eventData
=
&
eventMapItr
.
second
;
EventData
*
p_eventData
=
&
eventMapItr
.
second
;
/*****************************
/*****************************
...
@@ -196,9 +196,9 @@ RetStat SehEngine::ResolveNextStateIndexes() {
...
@@ -196,9 +196,9 @@ RetStat SehEngine::ResolveNextStateIndexes() {
/********************************************
/********************************************
* Resolve complex actions next state if any
* Resolve complex actions next state if any
*******************************************/
*******************************************/
for
(
EventAction
action
:
p_eventData
->
actions
)
for
(
EventAction
*
p_
action
:
p_eventData
->
actions
)
{
{
retStat
=
ResolveComplexActionNextState
(
action
);
retStat
=
ResolveComplexActionNextState
(
p_
action
);
if
(
retStat
.
Fail
())
if
(
retStat
.
Fail
())
return
retStat
;
return
retStat
;
}
}
...
@@ -207,6 +207,7 @@ RetStat SehEngine::ResolveNextStateIndexes() {
...
@@ -207,6 +207,7 @@ RetStat SehEngine::ResolveNextStateIndexes() {
* state is empty then it means that we want to stay in
* state is empty then it means that we want to stay in
* the same state
* the same state
****************************************/
****************************************/
p_nextState
=
&
p_eventData
->
nextState
;
if
(
p_nextState
->
IsValid
())
if
(
p_nextState
->
IsValid
())
{
{
retStat
=
ResolveNextStateIndex
(
p_eventData
->
nextState
);
retStat
=
ResolveNextStateIndex
(
p_eventData
->
nextState
);
...
@@ -222,15 +223,15 @@ RetStat SehEngine::ResolveNextStateIndexes() {
...
@@ -222,15 +223,15 @@ RetStat SehEngine::ResolveNextStateIndexes() {
/******************************
/******************************
* Resolve Base State if exists
* Resolve Base State if exists
*****************************/
*****************************/
if
(
statePtr
.
baseState
.
IsValid
())
if
(
p_state
->
baseState
.
IsValid
())
{
{
retStat
=
ResolveNextStateIndex
(
statePtr
.
baseState
);
retStat
=
ResolveNextStateIndex
(
p_state
->
baseState
);
if
(
retStat
.
Fail
())
if
(
retStat
.
Fail
())
{
{
if
(
retStat
.
GetError
().
empty
())
if
(
retStat
.
GetError
().
empty
())
retStat
.
SetFail
(
string
(
__PRETTY_FUNCTION__
)
retStat
.
SetFail
(
string
(
__PRETTY_FUNCTION__
)
.
append
(
"-
\t
Failed to Resolve BaseState : "
)
.
append
(
"-
\t
Failed to Resolve BaseState : "
)
.
append
(
statePtr
.
baseState
.
stateName
));
.
append
(
p_state
->
baseState
.
stateName
));
return
retStat
;
return
retStat
;
}
}
}
}
...
@@ -243,73 +244,75 @@ RetStat SehEngine::ResolveNextStateIndexes() {
...
@@ -243,73 +244,75 @@ RetStat SehEngine::ResolveNextStateIndexes() {
return
retStat
;
return
retStat
;
}
}
RetStat
SehEngine
::
ResolveComplexActionNextState
(
EventAction
&
actionRef
)
{
RetStat
SehEngine
::
ResolveComplexActionNextState
(
EventAction
*
p_eventAction
)
{
RetStat
retStat
;
RetStat
retStat
;
EventIfAction
*
p_eventIfAction
;
EventIfAction
*
p_eventIfAction
;
EventWhileAction
*
p_eventWhileAction
;
EventWhileAction
*
p_eventWhileAction
;
EventSwitchAction
*
p_eventSwitchAction
;
EventSwitchAction
*
p_eventSwitchAction
;
NextState
nextState
;
NextState
*
p_
nextState
;
switch
(
actionRef
.
actionType
)
switch
(
p_eventAction
->
actionType
)
{
{
case
nsEnums
:
:
eActionType_Regular
:
case
nsEnums
:
:
eActionType_Regular
:
break
;
break
;
case
nsEnums
:
:
eActionType_If
:
case
nsEnums
:
:
eActionType_If
:
p_eventIfAction
=
(
EventIfAction
*
)
&
actionRef
;
p_eventIfAction
=
(
EventIfAction
*
)
p_eventAction
;
/*
/*
* checking the true actions
* checking the true actions
*/
*/
nextState
=
p_eventIfAction
->
trueActions
.
nextState
;
p_nextState
=
&
p_eventIfAction
->
trueActions
.
nextState
;
if
(
nextState
.
IsValid
())
if
(
p_nextState
->
IsValid
())
{
{
retStat
=
ResolveNextStateIndex
(
nextState
);
retStat
=
ResolveNextStateIndex
(
*
p_
nextState
);
if
(
retStat
.
Fail
())
if
(
retStat
.
Fail
())
{
{
retStat
.
SetFail
(
string
(
__PRETTY_FUNCTION__
).
append
(
"-
\t
Failed to Resolve true actions NextState : "
).
append
(
nextState
.
stateName
));
retStat
.
SetFail
(
string
(
__PRETTY_FUNCTION__
).
append
(
"-
\t
Failed to Resolve true actions NextState : "
).
append
(
p_nextState
->
stateName
));
return
retStat
;
return
retStat
;
}
}
}
}
/*
/*
* checking the false actions
* checking the false actions
*/
*/
nextState
=
p_eventIfAction
->
falseActions
.
nextState
;
p_nextState
=
&
p_eventIfAction
->
falseActions
.
nextState
;
if
(
nextState
.
IsValid
())
if
(
p_nextState
->
IsValid
())
{
{
retStat
=
ResolveNextStateIndex
(
nextState
);
retStat
=
ResolveNextStateIndex
(
*
p_
nextState
);
if
(
retStat
.
Fail
())
if
(
retStat
.
Fail
())
{
{
retStat
.
SetFail
(
string
(
__PRETTY_FUNCTION__
).
append
(
"-
\t
Failed to Resolve true actions NextState : "
).
append
(
nextState
.
stateName
));
retStat
.
SetFail
(
string
(
__PRETTY_FUNCTION__
).
append
(
"-
\t
Failed to Resolve true actions NextState : "
).
append
(
p_nextState
->
stateName
));
return
retStat
;
return
retStat
;
}
}
}
}
break
;
break
;
case
nsEnums
:
:
eActionType_While
:
case
nsEnums
:
:
eActionType_While
:
p_eventWhileAction
=
(
EventWhileAction
*
)
&
actionRef
;
p_eventWhileAction
=
(
EventWhileAction
*
)
p_eventAction
;
nextState
=
p_eventWhileAction
->
whileActions
.
nextState
;
p_nextState
=
&
p_eventWhileAction
->
whileActions
.
nextState
;
if
(
nextState
.
IsValid
())
if
(
p_nextState
->
IsValid
())
{
{
retStat
=
ResolveNextStateIndex
(
nextState
);
retStat
=
ResolveNextStateIndex
(
*
p_
nextState
);
if
(
retStat
.
Fail
())
if
(
retStat
.
Fail
())
{
{
retStat
.
SetFail
(
string
(
__PRETTY_FUNCTION__
).
append
(
"-
\t
Failed to Resolve NextState in the While: "
).
append
(
nextState
.
stateName
));
retStat
.
SetFail
(
string
(
__PRETTY_FUNCTION__
).
append
(
"-
\t
Failed to Resolve NextState in the While: "
).
append
(
p_nextState
->
stateName
));
return
retStat
;
return
retStat
;
}
}
}
}
break
;
break
;
case
nsEnums
:
:
eActionType_Switch
:
case
nsEnums
:
:
eActionType_Switch
:
p_eventSwitchAction
=
(
EventSwitchAction
*
)
&
actionRef
;
p_eventSwitchAction
=
(
EventSwitchAction
*
)
p_eventAction
;
/*
/*
* going over the cases
* going over the cases
*/
*/
for
(
EventData
eventData
:
p_eventSwitchAction
->
switchActions
)
for
(
auto
iter
=
p_eventSwitchAction
->
switchActions
.
begin
();
iter
!=
p_eventSwitchAction
->
switchActions
.
end
();
++
iter
)
{
{
nextState
=
eventData
.
nextState
;
EventData
&
eventData
=
iter
->
second
;
if
(
nextState
.
IsValid
())
p_nextState
=
&
eventData
.
nextState
;
if
(
p_nextState
->
IsValid
())
{
{
retStat
=
ResolveNextStateIndex
(
nextState
);
retStat
=
ResolveNextStateIndex
(
*
p_
nextState
);
if
(
retStat
.
Fail
())
if
(
retStat
.
Fail
())
{
{
retStat
.
SetFail
(
string
(
__PRETTY_FUNCTION__
).
append
(
"-
\t
Failed to Resolve NextState in the Switch: "
).
append
(
nextState
.
stateName
));
retStat
.
SetFail
(
string
(
__PRETTY_FUNCTION__
).
append
(
"-
\t
Failed to Resolve NextState in the Switch: "
).
append
(
p_nextState
->
stateName
));
return
retStat
;
return
retStat
;
}
}
}
}
...
@@ -325,12 +328,12 @@ RetStat SehEngine::ActivateActions(StateIndex& nextStateIndex) {
...
@@ -325,12 +328,12 @@ RetStat SehEngine::ActivateActions(StateIndex& nextStateIndex) {
bool
b_DidLastActionFailed
=
false
;
bool
b_DidLastActionFailed
=
false
;
int
iNumOfActions
=
this
->
p_eventData_
->
getNumOfActions
();
int
iNumOfActions
=
this
->
p_eventData_
->
getNumOfActions
();
this
->
activateActionData_
.
nextStateIndex
=
nextStateIndex
;
this
->
activateActionData_
.
p_nextStateIndex
=
&
nextStateIndex
;
this
->
activateActionData_
.
boolWasStateChanged
=
false
;
this
->
activateActionData_
.
boolWasStateChanged
=
false
;
for
(
EventAction
eventAction
:
this
->
p_eventData_
->
actions
)
for
(
EventAction
*
p_
eventAction
:
this
->
p_eventData_
->
actions
)
{
{
this
->
p_eventAction_
=
&
eventAction
;
this
->
p_eventAction_
=
p_
eventAction
;
/************************************************************
/************************************************************
* activating the action. checking if the last action failed, if so
* activating the action. checking if the last action failed, if so
* then activating only mandatory actions
* then activating only mandatory actions
...
@@ -382,9 +385,7 @@ RetStat SehEngine::ActivateActions(StateIndex& nextStateIndex) {
...
@@ -382,9 +385,7 @@ RetStat SehEngine::ActivateActions(StateIndex& nextStateIndex) {
/*
/*
* Setting next state
* Setting next state
*/
*/
nextStateIndex
.
uiStateFlowIndex
=
p_eventData_
->
nextState
.
stateIndex
.
uiStateFlowIndex
;
nextStateIndex
.
Set
(
p_eventData_
->
nextState
.
stateIndex
);
nextStateIndex
.
uiStateIndex
=
p_eventData_
->
nextState
.
stateIndex
.
uiStateIndex
;
}
else
}
else
{
{
SEH_LOG
(
"SehEngine-
\t
Staying in the same State: "
,
p_state_
->
stateName
);
SEH_LOG
(
"SehEngine-
\t
Staying in the same State: "
,
p_state_
->
stateName
);
...
@@ -465,7 +466,8 @@ RetStat SehEngine::InitMultiFlows(map<string, string> &flowFilesMap, map<string,
...
@@ -465,7 +466,8 @@ RetStat SehEngine::InitMultiFlows(map<string, string> &flowFilesMap, map<string,
auto
baseSEHObjectMapIterator
=
baseSEHObjectMap_
.
find
(
entry
.
first
);
auto
baseSEHObjectMapIterator
=
baseSEHObjectMap_
.
find
(
entry
.
first
);
if
(
baseSEHObjectMapIterator
!=
baseSEHObjectMap_
.
end
())
if
(
baseSEHObjectMapIterator
!=
baseSEHObjectMap_
.
end
())
p_cf
->
p_baseSEHObject
=
baseSEHObjectMapIterator
->
second
;
p_cf
->
p_baseSEHObject
=
baseSEHObjectMapIterator
->
second
;
callFlowArray_
[
index
++
]
=
p_cf
;
callFlowArray_
.
push_back
(
p_cf
);
index
++
;
}
}
return
BuildMultiCallFlowTables
(
flowFilesMap
);
return
BuildMultiCallFlowTables
(
flowFilesMap
);
}
}
...
@@ -476,6 +478,13 @@ RetStat SehEngine::HandleEvent(StateIndex& stateIndex, string& eventStr) {
...
@@ -476,6 +478,13 @@ RetStat SehEngine::HandleEvent(StateIndex& stateIndex, string& eventStr) {
/********************
/********************
* Validating
* Validating
********************/
********************/
if
(
!
stateIndex
.
isValid
())
{
SEH_METHOD_ERROR
(
"-
\t
Invalid State index"
);
retStatus
.
SetFail
();
return
retStatus
;
}
/******************************
/******************************
* Reseting the working params Getting the Session State
* Reseting the working params Getting the Session State
*****************************/
*****************************/
...
@@ -493,7 +502,7 @@ RetStat SehEngine::HandleEvent(StateIndex& stateIndex, string& eventStr) {
...
@@ -493,7 +502,7 @@ RetStat SehEngine::HandleEvent(StateIndex& stateIndex, string& eventStr) {
* Getting the EventData from State/Event/Party
* Getting the EventData from State/Event/Party
* and setting the BaseSEH object
* and setting the BaseSEH object
***********************************************/
***********************************************/
this
->
p_state_
=
&
p_callFlow
->
stateArray
[
this
->
p_stateIndex_
->
uiStateIndex
];
this
->
p_state_
=
p_callFlow
->
stateArray
[
this
->
p_stateIndex_
->
uiStateIndex
];
p_eventData_
=
(
EventData
*
)
GetFromMap
(
this
->
p_state_
->
eventsMap
,
eventStr
);
p_eventData_
=
(
EventData
*
)
GetFromMap
(
this
->
p_state_
->
eventsMap
,
eventStr
);
this
->
p_baseSEHObject_
=
p_callFlow
->
p_baseSEHObject
;
this
->
p_baseSEHObject_
=
p_callFlow
->
p_baseSEHObject
;
//this->activateActionData_.object = p_callFlow->baseSEHObject;;
//this->activateActionData_.object = p_callFlow->baseSEHObject;;
...
@@ -510,7 +519,7 @@ RetStat SehEngine::HandleEvent(StateIndex& stateIndex, string& eventStr) {
...
@@ -510,7 +519,7 @@ RetStat SehEngine::HandleEvent(StateIndex& stateIndex, string& eventStr) {
&&
(
this
->
p_state_
->
baseState
.
IsValid
()))
&&
(
this
->
p_state_
->
baseState
.
IsValid
()))
{
{
this
->
p_stateIndex_
=
&
this
->
p_state_
->
baseState
.
stateIndex
;
this
->
p_stateIndex_
=
&
this
->
p_state_
->
baseState
.
stateIndex
;
this
->
p_state_
=
&
p_callFlow
->
stateArray
[
this
->
p_stateIndex_
->
uiStateIndex
];
this
->
p_state_
=
p_callFlow
->
stateArray
[
this
->
p_stateIndex_
->
uiStateIndex
];
this
->
p_eventData_
=
(
EventData
*
)
GetFromMap
(
this
->
p_state_
->
eventsMap
,
eventStr
);
// eventCellsArray[iEvent];
this
->
p_eventData_
=
(
EventData
*
)
GetFromMap
(
this
->
p_state_
->
eventsMap
,
eventStr
);
// eventCellsArray[iEvent];
}
}
...
@@ -553,7 +562,7 @@ const string &SehEngine::GetStateName(StateIndex &stateIndex) {
...
@@ -553,7 +562,7 @@ const string &SehEngine::GetStateName(StateIndex &stateIndex) {
if
(
stateIndex
.
uiStateFlowIndex
<
maxNumberOfCallFlows_
)
if
(
stateIndex
.
uiStateFlowIndex
<
maxNumberOfCallFlows_
)
{
{
if
(
stateIndex
.
uiStateIndex
<
callFlowArray_
[
stateIndex
.
uiStateFlowIndex
]
->
iNumOfStates
)
if
(
stateIndex
.
uiStateIndex
<
callFlowArray_
[
stateIndex
.
uiStateFlowIndex
]
->
iNumOfStates
)
return
callFlowArray_
[
stateIndex
.
uiStateFlowIndex
]
->
stateArray
[
stateIndex
.
uiStateIndex
]
.
stateName
;
return
callFlowArray_
[
stateIndex
.
uiStateFlowIndex
]
->
stateArray
[
stateIndex
.
uiStateIndex
]
->
stateName
;
else
else
return
nsConstants
::
C_WRONG_SEH_STATE
;
return
nsConstants
::
C_WRONG_SEH_STATE
;
}
}
...
@@ -573,9 +582,9 @@ RetStat SehEngine::GetStateIndex(StateIndex &stateIndex, string &stateName) {
...
@@ -573,9 +582,9 @@ RetStat SehEngine::GetStateIndex(StateIndex &stateIndex, string &stateName) {
/**************************
/**************************
* finding the state
* finding the state
*************************/
*************************/
for
(
State
&
state
:
callFlowEntry
.
second
->
stateArray
)
for
(
State
*
p_
state
:
callFlowEntry
.
second
->
stateArray
)
{
{
if
(
state
.
stateName
.
compare
(
stateName
)
==
0
)
if
(
p_state
->
stateName
.
compare
(
stateName
)
==
0
)
{
{
stateIndex
.
uiStateFlowIndex
=
callFlowEntry
.
second
->
flowIndex
;
stateIndex
.
uiStateFlowIndex
=
callFlowEntry
.
second
->
flowIndex
;
stateIndex
.
uiStateIndex
=
iStateIndex
;
stateIndex
.
uiStateIndex
=
iStateIndex
;
...
...
src/seh/seh_engine.h
View file @
18669a33
...
@@ -77,7 +77,7 @@ private:
...
@@ -77,7 +77,7 @@ private:
* @param actionPtr
* @param actionPtr
* @return
* @return
*/
*/
RetStat
ResolveComplexActionNextState
(
EventAction
&
actionRef
);
RetStat
ResolveComplexActionNextState
(
EventAction
*
p_eventAction
);
/**
/**
* activating the actions and moving to the next state
* activating the actions and moving to the next state
*
*
...
...
test/resources/TestSEH.json
0 → 100644
View file @
18669a33
{
"States"
:
[{
"Name"
:
"Idle"
,
"Events"
:
[{
"Name"
:
"Event1"
,
"Actions"
:
[{
"Type"
:
"Action"
,
"Name"
:
"SimpleAction"
},
{
"Type"
:
"Action"
,
"Name"
:
"ActionWithParamInt"
,
"Params"
:
{
"TO"
:
"20"
}
},
{
"Type"
:
"Action"
,
"Name"
:
"ActionWithParamString"
,
"Params"
:
{
"CallType"
:
"IncOut"
}
}],
"NextState"
:
"Idle_NestState1"
},
{
"Name"
:
"Event2"
,
"Actions"
:
[{
"Type"
:
"If"
,
"Name"
:
"IfElseAction"
,
"Then"
:
{
"Actions"
:
[{
"Type"
:
"Action"
,
"Name"
:
"SimpleAction"
},
{
"Type"
:
"Action"
,
"Name"
:
"ActionWithParamInt"
,
"Params"
:
{
"TO"
:
"30000"
}
},
{
"Type"
:
"Action"
,
"Name"
:
"SimpleAction"
}],
"NextState"
:
"Idle_IfThenState"
},
"Else"
:
{
"Actions"
:
[{
"Type"
:
"Action"
,
"Name"
:
"ActionWithParamInt"
,
"Params"
:
{
"TO"
:
"5000"
}
},
{
"Type"
:
"Action"
,
"Name"
:
"SimpleAction"
},
{
"Type"
:
"Action"
,
"Name"
:
"SimpleAction"
}],
"NextState"
:
"Idle_IfElseState"
}
}],
"NextState"
:
"Idle_IfElseDefaultState"
}]
},
{
"Name"
:
"Idle_NestState1"
,
"Events"
:
[{
"Name"
:
"Event3"
,
"Actions"
:
[{
"Type"
:
"Action"
,
"Name"
:
"SimpleAction"
},
{
"Type"
:
"Action"
,
"Name"
:
"SimpleAction"
},
{
"Type"
:
"Switch"
,
"Name"
:
"SwitchAction"
,
"Cases"
:
[{
"Val1"
:
{
"Actions"
:
[{
"Type"
:
"Action"
,
"Name"
:
"SimpleAction"
},
{
"Type"
:
"Action"
,
"Name"
:
"ActionWithParamInt"
,
"Params"
:
{
"TDCause"
:
"8"
}
},
{
"Type"
:
"Action"
,
"Name"
:
"ActionWithParamString"
,
"Params"
:
{
"Party"
:
"ICP"
}
}],
"NextState"
:
"Idle"
}
},
{
"Val2"
:
{
"Actions"
:
[{
"Type"
:
"Action"
,
"Name"
:
"ActionWithParamInt"
,
"Params"
:
{
"TDCause"
:
"8"
}
},
{
"Type"
:
"Action"
,
"Name"
:
"ActionWithParamString"
,
"Params"
:
{
"Party"
:
"ICP"
}
}],
"NextState"
:
"Idle_NestState1"
}
}]
}],
"NextState"
:
"Idle_SwitchDefaultState"
}]
},
{
"Name"
:
"Idle_IfThenState"
,
"Events"
:
[{
"Name"
:
"Event4"
,
"Actions"
:
[
{
"Type"
:
"Action"
,
"Name"
:
"SimpleAction"
}
],
"NextState"
:
"Idle"
}]
},
{
"Name"
:
"Idle_IfElseState"
,
"Events"
:
[{
"Name"
:
"Event4"
,
"Actions"
:
[
{
"Type"
:
"Action"
,
"Name"
:
"SimpleAction"
}
],
"NextState"
:
"Idle"
}]
},
{
"Name"
:
"Idle_IfElseDefaultState"
,
"Events"
:
[{
"Name"
:
"Event4"
,
"Actions"
:
[
{
"Type"
:
"Action"
,
"Name"
:
"SimpleAction"
}
],
"NextState"
:
"Idle"
}]
},
{
"Name"
:
"Idle_SwitchDefaultState"
,
"Events"
:
[{
"Name"
:
"Event4"
,
"Actions"
:
[
{
"Type"
:
"Action"
,
"Name"
:
"SimpleAction"
}
],
"NextState"
:
"Idle"
}]
}]
}
\ No newline at end of file
test/resources/TestSEH.xml
0 → 100644
View file @
18669a33
<?xml version="1.0" encoding="UTF-8"?>
<xml>
<State>
<Name>
Idle
</Name>
<Event>
<Name>
Event1
</Name>
<Actions>
<Action>
SimpleAction
</Action>
<Action>
<Name>
ActionWithParamInt
</Name>
<Params>
<TO>
20
</TO>
</Params>
</Action>
<Action>
<Name>
ActionWithParamString
</Name>
<Params>
<CallType>
IncOut
</CallType>
</Params>
</Action>
</Actions>
<NextState>
Idle_NestState1
</NextState>
</Event>
<Event>
<Name>
Event2
</Name>
<Actions>
<If>
<Action>
IfElseAction
</Action>
<Then>
<Actions>
<Action>
SimpleAction
</Action>
<Action>
<Name>
ActionWithParamInt
</Name>
<Params>
<TO>
30000
</TO>
</Params>
</Action>
<Action>
SimpleAction
</Action>
</Actions>
<NextState>
Idle_IfThenState
</NextState>
</Then>
<Else>
<Actions>
<Action>
<Name>
ActionWithParamInt
</Name>
<Params>
<TO>
5000
</TO>
</Params>
</Action>
<Action>
SimpleAction
</Action>
<Action>
SimpleAction
</Action>
</Actions>
<NextState>
Idle_IfElseState
</NextState>
</Else>
</If>
</Actions>
<NextState>
Idle_IfElseDefaultState
</NextState>
</Event>
</State>
<State>
<Name>
Idle_NestState1
</Name>
<Event>
<Name>
Event3
</Name>
<Actions>
<Action>
SimpleAction
</Action>
<Action>
SimpleAction
</Action>
<Switch>
<Action>
SwitchAction
</Action>
<Case>
<Value>
Val1
</Value>
<Actions>
<Action>
SimpleAction
</Action>
<Action>
<Name>
ActionWithParamInt
</Name>
<Params>
<TDCause>
8
</TDCause>
<!-- SetUp TO -->
</Params>
</Action>
<Action>
<Name>
ActionWithParamString
</Name>
<Params>
<Party>
ICP
</Party>
</Params>
</Action>
</Actions>
<NextState>
Idle
</NextState>
</Case>
<Case>
<Value>
Val2
</Value>
<Actions>
<Action>
<Name>
ActionWithParamInt
</Name>
<Params>
<TDCause>
8
</TDCause>
<!-- SetUp TO -->
</Params>
</Action>
<Action>
<Name>
ActionWithParamString
</Name>
<Params>
<Party>
ICP
</Party>
</Params>
</Action>
</Actions>
<NextState>
Idle_NestState1
</NextState>
</Case>
<Case>
<Value>
Val3
</Value>
<Actions>
<Action>
SimpleAction
</Action>
</Actions>
<NextState>
Idle_SwitchDefaultState
</NextState>
</Case>
</Switch>
</Actions>
<NextState>
Idle_SwitchDefaultState
</NextState>
</Event>
</State>
<State>
<Name>
Idle_IfThenState
</Name>
<Event>
<Name>
Event4
</Name>
<Actions>
<Action>
SimpleAction
</Action>
</Actions>
<NextState>
Idle
</NextState>
</Event>
</State>
<State>
<Name>
Idle_IfElseState
</Name>
<Event>
<Name>
Event4
</Name>
<Actions>
<Action>
SimpleAction
</Action>
</Actions>
<NextState>
Idle
</NextState>
</Event>
</State>
<State>
<Name>
Idle_IfElseDefaultState
</Name>
<Event>
<Name>
Event4
</Name>
<Actions>
<Action>
SimpleAction
</Action>
</Actions>
<NextState>
Idle
</NextState>
</Event>
</State>
<State>
<Name>
Idle_SwitchDefaultState
</Name>
<Event>
<Name>
Event4
</Name>
<Actions>
<Action>
SimpleAction
</Action>
</Actions>
<NextState>
Idle
</NextState>
</Event>
</State>
</xml>
\ No newline at end of file
test/test_seh.cpp
View file @
18669a33
...
@@ -5,9 +5,112 @@
...
@@ -5,9 +5,112 @@
#include <iostream>
#include <iostream>
#include <functional>
#include <functional>
#include <vector>
#include <vector>
#include <cstring>
#include <limits.h>
#include <mhash.h>
#include "../src/defs/seh_types.h"
#include "../src/seh/seh_engine.h"
typedef
std
::
function
<
int
(
int
,
int
)
>
INTINT_FUNC
;
typedef
std
::
function
<
int
(
int
,
int
)
>
INTINT_FUNC
;
using
namespace
std
::
placeholders
;
using
namespace
std
::
placeholders
;
using
namespace
std
;
class
TestISEHParam
:
public
ISEHParam
{
private
:
int
intValue
=
0
;
string
strVal
;
public
:
virtual
void
SetParam
(
const
char
*
name
,
const
char
*
value
)
override
{
if
((
strcasecmp
(
name
,
"TO"
)
==
0
)
||
(
strcasecmp
(
name
,
"TDCause"
)
==
0
))
intValue
=
atoi
(
value
);
else
if
((
strcasecmp
(
name
,
"Party"
)
==
0
)
||
(
strcasecmp
(
name
,
"CallType"
)
==
0
))
strVal
.
assign
(
value
);
}
int
getIntValue
()
const
{
return
intValue
;
}
const
string
&
getStrVal
()
const
{
return
strVal
;
}
};
class
TestSEH
:
public
IBaseSEH
{
RetStat
retStat
;
public
:
virtual
AFP
resolveAction
(
const
char
*
p_actionName
)
override
{
if
(
strcasecmp
(
p_actionName
,
"SimpleAction"
)
==
0
)
return
std
::
bind
(
&
TestSEH
::
SimpleAction
,
this
,
_1
);
else
if
(
strcasecmp
(
p_actionName
,
"ActionWithParamInt"
)
==
0
)
return
std
::
bind
(
&
TestSEH
::
ActionWithParamInt
,
this
,
_1
);
else
if
(
strcasecmp
(
p_actionName
,
"ActionWithParamString"
)
==
0
)
return
std
::
bind
(
&
TestSEH
::
ActionWithParamString
,
this
,
_1
);
else
if
(
strcasecmp
(
p_actionName
,
"IfElseAction"
)
==
0
)
return
std
::
bind
(
&
TestSEH
::
IfElseAction
,
this
,
_1
);
else
if
(
strcasecmp
(
p_actionName
,
"SwitchAction"
)
==
0
)
return
std
::
bind
(
&
TestSEH
::
SwitchAction
,
this
,
_1
);
return
nullptr
;
}
virtual
ISEHParam
*
getNewSEHParam
()
override
{
return
new
TestISEHParam
();
}
virtual
void
setAppData
(
void
*
p_appData
)
override
{
}
/*
* ACTIONS
*/
RetStat
SimpleAction
(
ISEHParam
*
p_param
)
{
retStat
.
SetSuccess
();
SEH_LOG
(
"Action:
\t
SimpleAction"
);
return
retStat
;
}
RetStat
ActionWithParamInt
(
ISEHParam
*
p_param
)
{
retStat
.
SetSuccess
();
TestISEHParam
*
p_sehParam
=
(
TestISEHParam
*
)
p_param
;
SEH_LOG
(
"Action:
\t
ActionWithParamInt: "
,
p_sehParam
->
getIntValue
());
return
retStat
;
}
RetStat
ActionWithParamString
(
ISEHParam
*
p_param
)
{
retStat
.
SetSuccess
();
TestISEHParam
*
p_sehParam
=
(
TestISEHParam
*
)
p_param
;
SEH_LOG
(
"Action:
\t
ActionWithParamString: "
,
p_sehParam
->
getStrVal
());
return
retStat
;
}
RetStat
IfElseAction
(
ISEHParam
*
p_param
)
{
retStat
.
SetFail
();
SEH_LOG
(
"Action:
\t
IfElseAction"
);
return
retStat
;
}
RetStat
SwitchAction
(
ISEHParam
*
p_param
)
{
retStat
.
SetSuccess
();
SEH_LOG
(
"Action:
\t
SwitchAction"
);
retStat
.
SetStatusText
(
"Val1"
);
//retStat.retCode = EnumSwitchValues.Val1.ordinal();
return
retStat
;
}
};
class
TestAdd
class
TestAdd
{
{
...
@@ -26,32 +129,10 @@ public:
...
@@ -26,32 +129,10 @@ public:
INTINT_FUNC
resolveFunc
()
{
return
std
::
bind
(
&
TestSub
::
subbing
,
this
,
_1
,
_2
);
}
INTINT_FUNC
resolveFunc
()
{
return
std
::
bind
(
&
TestSub
::
subbing
,
this
,
_1
,
_2
);
}
};
};
void
testArrays
()
void
simple_test
()
{
{
struct
IntPtr
{
int
a
;
void
*
p
;
IntPtr
(
int
a
)
:
a
(
a
)
{}
IntPtr
()
{}
};
std
::
vector
<
IntPtr
>
intPtrArray
;
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
IntPtr
ip
;
ip
.
a
=
i
;
intPtrArray
.
push_back
(
ip
);
}
for
(
auto
itr
:
intPtrArray
)
std
::
cout
<<
itr
.
a
<<
std
::
endl
;
}
int
main
()
{
INTINT_FUNC
func
;
INTINT_FUNC
func
;
testArrays
();
return
0
;
std
::
cout
<<
"Hello, World!"
<<
std
::
endl
;
std
::
cout
<<
"Hello, World!"
<<
std
::
endl
;
TestAdd
testAdd
;
TestAdd
testAdd
;
TestSub
testSub
;
TestSub
testSub
;
...
@@ -59,6 +140,45 @@ int main() {
...
@@ -59,6 +140,45 @@ int main() {
std
::
cout
<<
"result is: "
<<
func
(
20
,
10
)
<<
std
::
endl
;
std
::
cout
<<
"result is: "
<<
func
(
20
,
10
)
<<
std
::
endl
;
func
=
testSub
.
resolveFunc
();
func
=
testSub
.
resolveFunc
();
std
::
cout
<<
"result is: "
<<
func
(
20
,
10
)
<<
std
::
endl
;
std
::
cout
<<
"result is: "
<<
func
(
20
,
10
)
<<
std
::
endl
;
}
std
::
string
getexepath
()
{
char
result
[
PATH_MAX
];
ssize_t
count
=
readlink
(
"/proc/self/exe"
,
result
,
PATH_MAX
);
return
std
::
string
(
result
,
(
count
>
0
)
?
count
:
0
);
}
int
main
()
{
RetStat
stat
;
SehEngine
*
fsmEngine
=
new
SehEngine
();
TestSEH
testSEH
;
StateIndex
state
;
// = new StateIndex();
string
event
;
cout
<<
"current dir is: "
<<
getexepath
()
<<
endl
;
SEH_LOG
(
"Hello"
);
map
<
string
,
string
>
flowFilesMap
;
map
<
string
,
IBaseSEH
*>
flowsSEHMap
;
//flowFilesMap.put("Test", "src/test/resources/seh/TestSEH.xml");
flowFilesMap
[
"Test"
]
=
"/home/amir/git/ipgallery/common/cpp/seh/test/resources/TestSEH.json"
;
flowsSEHMap
[
"Test"
]
=
&
testSEH
;
stat
=
fsmEngine
->
InitMultiFlows
(
flowFilesMap
,
flowsSEHMap
);
if
(
stat
.
Success
())
{
state
.
uiStateFlowIndex
=
0
;
state
.
uiStateIndex
=
0
;
// idle
event
=
"Event1"
;
fsmEngine
->
HandleEvent
(
state
,
event
);
event
=
"Event3"
;
fsmEngine
->
HandleEvent
(
state
,
event
);
event
=
"Event2"
;
fsmEngine
->
HandleEvent
(
state
,
event
);
event
=
"Event2"
;
fsmEngine
->
HandleEvent
(
state
,
event
);
event
=
"Event4"
;
fsmEngine
->
HandleEvent
(
state
,
event
);
}
return
0
;
return
0
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment