MME2 changes - Propped commits from openmme/paging branch. Added scripts
for code gen
Change-Id: Ie55032217232214ac8544ca76ea34335205329e4
diff --git a/scripts/SMCodeGen/templates/stateMachineTmpls/actionHandlers.cpp.tt b/scripts/SMCodeGen/templates/stateMachineTmpls/actionHandlers.cpp.tt
new file mode 100644
index 0000000..e4a98e2
--- /dev/null
+++ b/scripts/SMCodeGen/templates/stateMachineTmpls/actionHandlers.cpp.tt
@@ -0,0 +1,48 @@
+[%- BLOCK %]
+[%- actionList = [] %]
+[%- PYTHON %]
+procedure = [% TemplateInputVar %]
+actionNames = []
+import utils
+for state in procedure['States']:
+ for event in state['Events']:
+ for action in event['Actions']:
+ rc = utils.searchWordInDir(utils.outputDir, action.lower())
+ if rc is False:
+ actionNames.append(action.lower())
+flag = utils.isFileEmpty(utils.outputDir, utils.outputFileName)
+stash.set('actionList', actionNames)
+stash.set('includeHeader', flag)
+[%- END %]
+[%- END %]
+[%- IF includeHeader == 1 -%]
+/*
+ * Copyright 2019-present Infosys Limited
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+/******************************************************************************
+ *
+ * This is an auto generated file.
+ * Please do not edit this file.
+ * All edits to be made through template source file
+ * <TOP-DIR/scripts/SMCodeGen/templates/stateMachineTmpls/actionHandlers.cpp.tt>
+ ******************************************************************************/
+#include "actionHandlers/actionHandlers.h"
+#include "controlBlock.h"
+
+using namespace mme;
+using namespace SM;
+
+[% END %]
+[%- FOREACH action = actionList -%]
+/***************************************
+* Action handler : [% action %]
+***************************************/
+ActStatus ActionHandlers::[% action %](ControlBlock& cb)
+{
+ return ActStatus::PROCEED;
+}
+
+[% END -%]
diff --git a/scripts/SMCodeGen/templates/stateMachineTmpls/actionHandlers.h.tt b/scripts/SMCodeGen/templates/stateMachineTmpls/actionHandlers.h.tt
new file mode 100644
index 0000000..66fc613
--- /dev/null
+++ b/scripts/SMCodeGen/templates/stateMachineTmpls/actionHandlers.h.tt
@@ -0,0 +1,66 @@
+[%- actions = [] %]
+[%- FOREACH actionList = TemplateInputVar%]
+ [%- FOREACH actionObj = actionList%]
+ [%- actions.push(actionObj) %]
+ [%- END %]
+[%- END %]
+[%- actions = actions.unique.sort %]
+[%- USE String %]
+/*
+ * Copyright 2019-present, Infosys Limited.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**************************************
+ *
+ * This is an auto generated file.
+ * Please do not edit this file.
+ * All edits to be made through template source file
+ * <TOP-DIR/scripts/SMCodeGen/templates/stateMachineTmpls/actionHandlers.h.tt>
+ **************************************/
+#ifndef ACTIONHANDLERS_H_
+#define ACTIONHANDLERS_H_
+
+#include "smTypes.h"
+
+namespace mme
+{
+ class ActionHandlers
+ {
+
+ /***************************************
+ * Constructor
+ ****************************************/
+ ActionHandlers()
+ {
+ }
+
+ /***************************************
+ * Destructor
+ ****************************************/
+ ~ActionHandlers()
+ {
+ }
+
+ public:
+ [%- FOREACH action = actions %]
+
+ /**********************************************
+ * Action handler : [%String.new(action).lower%]
+ ***********************************************/
+ static SM::ActStatus [%String.new(action).lower%](SM::ControlBlock& cb);
+ [%-END%]
+ };//ActionHandlers
+};//mme
+
+#endif /* ACTIONHANDLERS_H_ */
\ No newline at end of file
diff --git a/scripts/SMCodeGen/templates/stateMachineTmpls/enum.tt b/scripts/SMCodeGen/templates/stateMachineTmpls/enum.tt
new file mode 100644
index 0000000..dd6c455
--- /dev/null
+++ b/scripts/SMCodeGen/templates/stateMachineTmpls/enum.tt
@@ -0,0 +1,85 @@
+[%- stateList = [] %]
+[%- eventList = [] %]
+[%- actionList = [] %]
+[%- FOREACH ProcedureList = TemplateInputVar %]
+ [%- FOREACH Procedure = ProcedureList %]
+ [%- FOREACH State = Procedure.States %]
+ [%- stateList.push(State.Name) %]
+ [%- FOREACH Event = State.Events %]
+ [%- eventList.push(Event.Name) %]
+ [%- actionList = actionList.merge(Event.Actions) %]
+ [%- END %]
+ [%- END %]
+ [%- END %]
+[%- END %]
+[%- stateList = stateList.unique.sort %]
+[%- eventList = eventList.unique.sort %]
+[%- actionList = actionList.unique.sort -%]
+/*
+ * Copyright 2019-present, Infosys Limited.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef SM_ENUMS_H
+#define SM_ENUMS_H
+/**************************************
+ *
+ * This is an auto generated file.
+ * Please do not edit this file.
+ * All edits to be made through template source file
+ * <TOP-DIR/scripts/SMCodeGen/templates/stateMachineTmpls/enum.tt>
+ **************************************/
+
+enum State_e
+{
+ [%- FOREACH state = stateList%]
+ [% state %],[% END %]
+ END_STATE
+};
+
+static constexpr const char* States[] =
+{
+ [%- FOREACH state = stateList%]
+ "[% state %]",[%END%]
+ "END_STATE"
+};
+
+enum Event_e
+{
+ [%- FOREACH event = eventList%]
+ [% event %],[%END%]
+ END_EVENT
+};
+
+static constexpr const char* Events[] =
+{
+ [%- FOREACH event = eventList%]
+ "[% event %]",[%END%]
+ "END_EVENT"
+};
+
+enum Action_e
+{
+ [%- FOREACH actions = actionList%]
+ [% actions %],[% END %]
+ END_ACTION
+};
+
+static constexpr const char* Actions[] =
+{
+ [%- FOREACH action = actionList%]
+ "[% action %]",[%END%]
+ "END_ACTION"
+};
+
+#endif
\ No newline at end of file
diff --git a/scripts/SMCodeGen/templates/stateMachineTmpls/state.cpp.tt b/scripts/SMCodeGen/templates/stateMachineTmpls/state.cpp.tt
new file mode 100644
index 0000000..94e0425
--- /dev/null
+++ b/scripts/SMCodeGen/templates/stateMachineTmpls/state.cpp.tt
@@ -0,0 +1,87 @@
+ [%- State = TemplateInputVar %]
+ [%- USE String %]
+ [%- MACRO CLASSNAME(str) BLOCK %]
+ [%- className = String.new %]
+ [%- strList = String.new(str).lower.split("_") %]
+ [%- FOREACH str = strList %]
+ [%- token = className.append(String.new(str).capital.text()) %]
+ [%- END %]
+ [%- className %]
+ [%- END %]
+ [%- MACRO FILENAME(str) BLOCK %]
+ [%- fileName = String.new %]
+ [%- str = CLASSNAME(str) %]
+ [%- fileName = fileName.append(str.substr(0,1)).lower %]
+ [%- fileName = fileName.append(str.substr(1)) %]
+ [%- fileName %]
+ [%- END %]
+ [%- stateClassName = CLASSNAME(State.Name) %]
+/*
+ * Copyright 2019-present Infosys Limited
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+/**************************************
+ * [% FILENAME(State.Name) %].cpp
+ * This is an auto generated file.
+ * Please do not edit this file.
+ * All edits to be made through template source file
+ * <TOP-DIR/scripts/SMCodeGen/templates/stateMachineTmpls/state.cpp.tt>
+ **************************************/
+
+#include "smEnumTypes.h"
+#include "actionTable.h"
+#include "actionHandlers/actionHandlers.h"
+
+#include "mmeStates/[% FILENAME(State.Name) %].h"
+[%- FOREACH Event = State.Events %]
+[%- IF Event.NextState != "end_state" %]
+#include "mmeStates/[% FILENAME(Event.NextState) %].h"
+[%- END %]
+[%- END %]
+
+using namespace mme;
+using namespace SM;
+
+/******************************************************************************
+* Constructor
+******************************************************************************/
+[% stateClassName %]::[% stateClassName %]():State(State_e::[% State.Name %])
+{
+}
+
+/******************************************************************************
+* Destructor
+******************************************************************************/
+[% stateClassName %]::~[% stateClassName %]()
+{
+}
+
+/******************************************************************************
+* creates and returns static instance
+******************************************************************************/
+[% stateClassName %]* [% stateClassName %]::Instance()
+{
+ static [% stateClassName %] state;
+ return &state;
+}
+
+/******************************************************************************
+* initializes eventToActionsMap
+******************************************************************************/
+void [% stateClassName %]::initialize()
+{
+ [%- FOREACH Event = State.Events %]
+ {
+ ActionTable actionTable;
+ [%- FOREACH Action = Event.Actions %]
+ actionTable.addAction(&ActionHandlers::[% String.new(Action).lower %]);
+ [%- END %]
+ [%- IF Event.NextState != "end_state" %]
+ actionTable.setNextState([% CLASSNAME(Event.NextState) %]::Instance());
+ [%- END %]
+ eventToActionsMap.insert(pair<Event_e, ActionTable>(Event_e::[% Event.Name %], actionTable));
+ }
+ [%- END %]
+}
diff --git a/scripts/SMCodeGen/templates/stateMachineTmpls/state.h.tt b/scripts/SMCodeGen/templates/stateMachineTmpls/state.h.tt
new file mode 100644
index 0000000..36feeec
--- /dev/null
+++ b/scripts/SMCodeGen/templates/stateMachineTmpls/state.h.tt
@@ -0,0 +1,79 @@
+ [%- State = TemplateInputVar %]
+ [%- USE String %]
+ [%- MACRO CLASSNAME(str) BLOCK %]
+ [%- className = String.new %]
+ [%- strList = String.new(str).lower.split("_") %]
+ [%- FOREACH str = strList %]
+ [%- token = className.append(String.new(str).capital.text()) %]
+ [%- END %]
+ [%- className %]
+ [%- END %]
+ [%- MACRO FILENAME(str) BLOCK %]
+ [%- fileName = String.new %]
+ [%- str = CLASSNAME(str) %]
+ [%- fileName = fileName.append(str.substr(0,1)).lower %]
+ [%- fileName = fileName.append(str.substr(1)) %]
+ [%- fileName %]
+ [%- END %]
+ [%- stateClassName = CLASSNAME(State.Name) -%]
+/*
+ * Copyright 2019-present, Infosys Limited.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ /******************************************************
+ * [% FILENAME(State.Name) %].h
+ * This is an auto generated file.
+ * Please do not edit this file.
+ * All edits to be made through template source file
+ * <TOP-DIR/scripts/SMCodeGen/templates/stateMachineTmpls/state.h.tt>
+ ******************************************************/
+
+#ifndef __[% stateClassName %]__
+#define __[% stateClassName %]__
+
+#include "state.h"
+
+namespace mme {
+
+ class [% stateClassName %] : public SM::State
+ {
+ public:
+ /******************************************
+ * Instance
+ * Creates static instance for the state
+ *******************************************/
+ static [% stateClassName %]* Instance();
+
+ /****************************************
+ * [% stateClassName %]
+ * Destructor
+ ****************************************/
+ ~[% stateClassName %]();
+
+ /******************************************
+ * initialize
+ * Initializes action handlers for the state
+ * and next state
+ ******************************************/
+ void initialize();
+
+ private:
+ /****************************************
+ * [% stateClassName %]
+ * Private constructor
+ ****************************************/
+ [% stateClassName %]();
+ };
+};
+#endif // __[% stateClassName %]__
diff --git a/scripts/SMCodeGen/templates/stateMachineTmpls/stateFactory.cpp.tt b/scripts/SMCodeGen/templates/stateMachineTmpls/stateFactory.cpp.tt
new file mode 100644
index 0000000..74cb717
--- /dev/null
+++ b/scripts/SMCodeGen/templates/stateMachineTmpls/stateFactory.cpp.tt
@@ -0,0 +1,78 @@
+ [%- USE String %]
+ [%- MACRO CLASSNAME(str) BLOCK %]
+ [%- className = String.new %]
+ [%- strList = String.new(str).lower.split("_") %]
+ [%- FOREACH str = strList %]
+ [%- token = className.append(String.new(str).capital.text()) %]
+ [%- END %]
+ [%- className %]
+ [%- END %]
+ [%- MACRO FILENAME(str) BLOCK %]
+ [%- fileName = String.new %]
+ [%- str = CLASSNAME(str) %]
+ [%- fileName = fileName.append(str.substr(0,1)).lower %]
+ [%- fileName = fileName.append(str.substr(1)) %]
+ [%- fileName %]
+ [%- END %]
+ [%- stateList = [] %]
+ [%- FOREACH StatesArray = TemplateInputVar %]
+ [%- FOREACH State = StatesArray %]
+ [%- stateList.push(State.Name) %]
+ [%- END %]
+ [%- END %]
+ [%- stateList = stateList.unique.sort %]
+/*
+ * Copyright 2019-present Infosys Limited
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+/**************************************
+ * [% FILENAME(State.Name) %].cpp
+ * This is an auto generated file.
+ * Please do not edit this file.
+ * All edits to be made through template source file
+ * <TOP-DIR/scripts/SMCodeGen/templates/stateMachineTmpls/stateFactory.cpp.tt>
+ **************************************/
+
+#include "mmeStates/stateFactory.h"
+[%- FOREACH state = stateList%]
+[%- IF state != "end_state" %]
+#include "mmeStates/[% FILENAME(state) %].h"
+[%- END %]
+[%- END %]
+
+using namespace mme;
+
+/**********************************************
+* Constructor
+***********************************************/
+StateFactory::StateFactory()
+{
+}
+
+/**********************************************
+* Destructor
+***********************************************/
+StateFactory::~StateFactory()
+{
+}
+
+/**********************************************
+* creates and returns static instance
+***********************************************/
+
+StateFactory* StateFactory::Instance()
+{
+ static StateFactory instance;
+ return &instance;
+}
+
+void StateFactory::initialize()
+{
+ [%- FOREACH state = stateList%]
+ [%- IF state != "end_state" %]
+ [% CLASSNAME(state) %]::Instance()->initialize();
+ [%- END %]
+ [%- END %]
+}
diff --git a/scripts/SMCodeGen/templates/stateMachineTmpls/stateFactory.h.tt b/scripts/SMCodeGen/templates/stateMachineTmpls/stateFactory.h.tt
new file mode 100644
index 0000000..5367e85
--- /dev/null
+++ b/scripts/SMCodeGen/templates/stateMachineTmpls/stateFactory.h.tt
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2019-present, Infosys Limited.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**************************************
+ *
+ * This is an auto generated file.
+ * Please do not edit this file.
+ * All edits to be made through template source file
+ * <TOP-DIR/scripts/SMCodeGen/templates/stateMachineTmpls/stateFactory.h.tt>
+ **************************************/
+
+#ifndef __StateFactory__
+#define __StateFactory__
+
+namespace mme {
+ class StateFactory {
+ public:
+ /******************************************
+ * Instance
+ * Creates static instance for the state
+ *******************************************/
+ static StateFactory* Instance();
+
+ /*****************************************
+ * StateFactory
+ * Destructor
+ *****************************************/
+ ~StateFactory();
+
+ /******************************************
+ * initialize
+ * Initializes action handlers for the state
+ * and next state
+ ******************************************/
+ void initialize();
+
+ private:
+ /****************************************
+ * StateFactory
+ * Private constructor
+ ****************************************/
+ StateFactory();
+
+ };
+};
+#endif // __StateFactory__