Commit 18669a33 by amir

first working version with pointer allocations

parent 1537b4b9
......@@ -6,6 +6,7 @@
#define SEH_ENUMS_H
#include <map>
#include <string.h>
namespace nsEnums
{
enum eRetStat
......@@ -31,11 +32,13 @@ namespace nsEnums
{"Switch",eActionType_Switch}
};
static eEventActionType ResolveEventActionType(const char* eventActionType)
static eEventActionType ResolveEventActionType(const char* p_eventActionType)
{
auto iterator = eventActionTypeMap.find(eventActionType);
if (iterator != eventActionTypeMap.end())
return iterator->second;
for (auto entry : eventActionTypeMap)
{
if(strcasecmp(entry.first,p_eventActionType) == 0)
return entry.second;
}
return eActionType_Max;
}
}
......
......@@ -13,19 +13,19 @@ class RetStat
{
private:
eRetStat retstat_;
int ret_code_;
//int ret_code_;
std::string error_text_;
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),
ret_code_(ret_code_),
// ret_code_(ret_code_),
error_text_(error_text_) {}
void Reset()
{
retstat_ = eSuccess;
ret_code_ = 0;
//ret_code_ = 0;
error_text_.clear();
}
void SetSuccess() { retstat_ = eSuccess; }
......@@ -46,9 +46,23 @@ public:
bool Fail() { return (retstat_ == eFail); }
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
......@@ -12,12 +12,12 @@ RetStat ComplexEventAction::ActivateActions(EventData& eventData,
{
int iNumOfActions = eventData.getNumOfActions();
for (EventAction eventAction : eventData.actions)
for (EventAction* p_eventAction : eventData.actions)
{
/*
* 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())
{
//logger.severe("ComplexEventAction::ActivateActions-\tFailed in Action");
......@@ -34,9 +34,9 @@ RetStat ComplexEventAction::ActivateActions(EventData& eventData,
if (iNumOfActions > 0) {
if (eventData.NextStateValid()) {
activateActionData.boolWasStateChanged = true;
activateActionData.nextStateIndex.uiStateFlowIndex = eventData.nextState.stateIndex.uiStateFlowIndex;
activateActionData.nextStateIndex.uiStateIndex = eventData.nextState.stateIndex.uiStateIndex;
//logger.info("SEHEngine-\tChanging to State: " + eventData.nextState.stateName);
activateActionData.p_nextStateIndex->Set(eventData.nextState.stateIndex);
//logger.info("SEHEngine-\tChanging to State: " + eventData.nextState.stateName);
SEH_LOG("ComplexEventAction::ActivateActions\tChanging to State: ",eventData.nextState.stateName);
} else {
activateActionData.boolWasStateChanged = false;
......@@ -53,8 +53,8 @@ RetStat ComplexEventAction::ActivateActions(EventData& eventData,
void EventIfAction::Reset()
{
EventAction::Reset();
trueActions.Reset();
falseActions.Reset();
// trueActions.Reset();
// falseActions.Reset();
}
RetStat EventIfAction::ActivateAction(ActivateActionData& activateActionData)
......@@ -73,7 +73,7 @@ RetStat EventIfAction::ActivateAction(ActivateActionData& activateActionData)
void EventWhileAction::Reset()
{
EventAction::Reset();
whileActions.Reset();
//whileActions.Reset();
}
RetStat EventWhileAction::ActivateAction(ActivateActionData &activateActionData)
......@@ -90,7 +90,7 @@ RetStat EventWhileAction::ActivateAction(ActivateActionData &activateActionData)
if (whileActions.NextStateValid() )
{
activateActionData.boolWasStateChanged = true;
activateActionData.nextStateIndex = whileActions.nextState.stateIndex;
activateActionData.p_nextStateIndex->Set(whileActions.nextState.stateIndex);
SEH_LOG("EventWhileAction-\tChanging to State: ",whileActions.nextState.stateName);
}
else
......@@ -113,22 +113,22 @@ RetStat EventSwitchAction::ActivateAction(ActivateActionData &activateActionData
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(eventData,activateActionData,true);
retStat = ActivateActions(*p_eventData,activateActionData,true);
if(retStat.Success())
{
/******************************************
* check whether to move to the next state
******************************************/
if (eventData.NextStateValid() )
if (p_eventData->NextStateValid() )
{
activateActionData.boolWasStateChanged = true;
activateActionData.nextStateIndex = eventData.nextState.stateIndex;
SEH_LOG("EventSwitchAction-\tChanging to State: ",eventData.nextState.stateName);
activateActionData.p_nextStateIndex->Set(p_eventData->nextState.stateIndex);
SEH_LOG("EventSwitchAction-\tChanging to State: ",p_eventData->nextState.stateName);
}
else
{
......@@ -139,7 +139,7 @@ RetStat EventSwitchAction::ActivateAction(ActivateActionData &activateActionData
}
else
{
retStat.SetFail("EventSwitchAction::ActivateAction-\tReturn value is bigger the num of switch cases");
retStat.SetFail(string("EventSwitchAction::ActivateAction-\tswitch case doesn't exists: ").append(retStat.GetStatusText()));
SEH_LOG_ERROR(retStat.GetError());
return retStat;
}
......@@ -149,5 +149,5 @@ RetStat EventSwitchAction::ActivateAction(ActivateActionData &activateActionData
void ActivateActionData::Reset() {
this->boolWasStateChanged = false;
this->nextStateIndex.Reset();
this->p_nextStateIndex = nullptr;
}
......@@ -9,6 +9,8 @@
#include <vector>
#include <iostream>
#include <map>
#include <bits/unique_ptr.h>
#include <list>
#include "constants.h"
#include "retstat.h"
......@@ -17,7 +19,8 @@ void seh_log(std::ostream& out, Arg&& arg, Args&&... args)
{
out << std::forward<Arg>(arg);
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__)
......@@ -53,6 +56,61 @@ struct StateIndex
return (uiStateIndex != 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;
struct IBaseSEH
{
virtual AFP resolveAction(const char* actionName) = 0;
virtual int resolveEvent(const char* eventName);
virtual const char* resolveEventName(int event);
virtual ISEHParam* getNewSEHParam();
virtual void setAppData(void* p_appData);
// virtual int resolveEvent(const char* eventName);
// virtual const char* resolveEventName(int event);
virtual ISEHParam* getNewSEHParam() = 0;
virtual void setAppData(void* p_appData) = 0;
//public RetStatSupplier invokeFunc(CallSite callSite, SEHParam sehParam) throws Throwable;
};
......@@ -88,7 +146,7 @@ struct IBaseSEH
struct ActivateActionData
{
//IBaseSEH* p_object;
StateIndex nextStateIndex;
StateIndex* p_nextStateIndex;
bool boolWasStateChanged; // if true means that the called object
// change the state - moved to the next
// state
......@@ -136,6 +194,7 @@ struct EventAction
EventAction& operator = (const EventAction& eventAction)
{
SEH_METHOD_LOG("copy");
this->name.assign(eventAction.name);
this->action = eventAction.action;
if (eventAction.p_param_ != nullptr)
......@@ -185,6 +244,12 @@ struct NextState
StateIndex stateIndex;
string stateName;
// NextState(NextState& nextState) {
// SEH_METHOD_LOG("CoptConstructor");
// stateIndex = nextState.stateIndex;
// stateName = nextState.stateName;
// }
void Reset()
{
stateIndex.Reset();
......@@ -193,6 +258,7 @@ struct NextState
NextState& operator = (const NextState& nextState)
{
SEH_METHOD_LOG("copy");
this->stateIndex = nextState.stateIndex;
this->stateName.assign(nextState.stateName);
return *this;
......@@ -223,10 +289,17 @@ struct EventData
{
// vector < tEventAction*> ta_Actions;
// test - amir
vector<EventAction> actions;
list<EventAction*> actions;
NextState nextState;
string eventName;
virtual ~EventData() {
// for(auto p_eventAction : actions)
// delete(p_eventAction);
Reset();
}
void Reset()
{
actions.clear();
......@@ -241,6 +314,7 @@ struct EventData
EventData& operator = (const EventData& eventData)
{
SEH_METHOD_LOG("copy");
if (!eventData.actions.empty())
this->actions = eventData.actions;
this->nextState = eventData.nextState;
......@@ -248,9 +322,22 @@ struct EventData
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(); }
......@@ -281,11 +368,16 @@ struct EventIfAction: public ComplexEventAction
EventData trueActions;
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();
RetStat ActivateAction(ActivateActionData& activateActionData);
EventIfAction& operator = (const EventIfAction& eventIfAction)
{
SEH_METHOD_LOG("EventIfAction copy");
this->operator=(eventIfAction);
trueActions = eventIfAction.trueActions;
falseActions = eventIfAction.falseActions;
......@@ -297,11 +389,15 @@ struct EventWhileAction: public ComplexEventAction
{
EventData whileActions;
EventWhileAction() { this->actionType = eActionType_While; }
EventWhileAction() {
this->actionType = eActionType_While;
//whileActions = unique_ptr<EventData>(new EventData());
}
void Reset();
RetStat ActivateAction(ActivateActionData& activateActionData);
EventWhileAction& operator = (const EventWhileAction& eventAction)
{
SEH_METHOD_LOG("EventWhileAction copy");
this->operator=(eventAction);
whileActions = eventAction.whileActions;
return *this;
......@@ -310,7 +406,7 @@ struct EventWhileAction: public ComplexEventAction
struct EventSwitchAction: public ComplexEventAction
{
vector<EventData> switchActions;
map<string,EventData> switchActions;
//short numOfCases;
EventSwitchAction() { this->actionType = eActionType_Switch; }
......@@ -319,11 +415,28 @@ struct EventSwitchAction: public ComplexEventAction
RetStat ActivateAction(ActivateActionData& activateActionData);
EventSwitchAction& operator = (const EventSwitchAction& eventSwitchAction)
{
SEH_METHOD_LOG("EventSwitchAction copy");
this->operator=(eventSwitchAction);
// numOfCases = eventSwitchAction.numOfCases;
switchActions = eventSwitchAction.switchActions;
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
......@@ -343,16 +456,32 @@ struct State
stateName.clear();
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
{
int flowIndex = 0;
vector<State> stateArray;
vector<State*> stateArray;
int iNumOfStates;
string flowFileName;
IBaseSEH* p_baseSEHObject;
virtual ~CallFlow() {
for(State* p_state: stateArray)
delete(p_state);
Reset();
}
void Reset()
{
flowIndex = 0;
......@@ -364,6 +493,8 @@ struct CallFlow
string& GetFlowFileNameStr()
{
SEH_METHOD_LOG("copy");
return flowFileName;
}
......@@ -371,6 +502,15 @@ struct CallFlow
{
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 {
virtual void Clear() = 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
......@@ -15,8 +15,6 @@ using namespace rapidjson;
class JsonCallFlowBuilder : public ICallFlowBuilder {
private:
EventData eventData_;
EventAction eventAction_;
EventAction* p_eventAction_;
CallFlow* p_callFlow_;
IBaseSEH* p_baseSEHObject_;
string flowFileName_;
......@@ -27,7 +25,7 @@ public:
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);
......@@ -37,7 +35,7 @@ public:
RetStat GetEventActions(Document &eventActionsNode);
RetStat GetAction(Document &actionNode);
RetStat GetAction(Document &actionNode, EventAction **pp_eventAction);
RetStat ResolveSimpleAction(EventAction *p_eventAction, Document &actionNode);
......
......@@ -12,6 +12,6 @@ RetStat XMLCallFlowBuilder::BuildFlowTableFromFile(string& flowFileName, CallFlo
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();
}
......@@ -13,7 +13,7 @@ class XMLCallFlowBuilder : public ICallFlowBuilder{
public:
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;
};
......
......@@ -77,7 +77,7 @@ private:
* @param actionPtr
* @return
*/
RetStat ResolveComplexActionNextState(EventAction& actionRef);
RetStat ResolveComplexActionNextState(EventAction* p_eventAction);
/**
* activating the actions and moving to the next state
*
......
{
"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
<?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
......@@ -5,9 +5,112 @@
#include <iostream>
#include <functional>
#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;
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: \tSimpleAction");
return retStat;
}
RetStat ActionWithParamInt(ISEHParam* p_param)
{
retStat.SetSuccess();
TestISEHParam* p_sehParam = (TestISEHParam*)p_param;
SEH_LOG("Action: \tActionWithParamInt: ",p_sehParam->getIntValue());
return retStat;
}
RetStat ActionWithParamString(ISEHParam* p_param)
{
retStat.SetSuccess();
TestISEHParam* p_sehParam = (TestISEHParam*)p_param;
SEH_LOG("Action: \tActionWithParamString: ",p_sehParam->getStrVal());
return retStat;
}
RetStat IfElseAction(ISEHParam* p_param)
{
retStat.SetFail();
SEH_LOG("Action: \tIfElseAction");
return retStat;
}
RetStat SwitchAction(ISEHParam* p_param)
{
retStat.SetSuccess();
SEH_LOG("Action: \tSwitchAction");
retStat.SetStatusText("Val1");
//retStat.retCode = EnumSwitchValues.Val1.ordinal();
return retStat;
}
};
class TestAdd
{
......@@ -26,32 +129,10 @@ public:
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;
testArrays();
return 0;
std::cout << "Hello, World!" << std::endl;
TestAdd testAdd;
TestSub testSub;
......@@ -59,6 +140,45 @@ int main() {
std::cout << "result is: " << func(20,10) << std::endl;
func = testSub.resolveFunc();
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;
}
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