MME2 changes - Propped commits from openmme/paging branch. Added scripts
for code gen

Change-Id: Ie55032217232214ac8544ca76ea34335205329e4
diff --git a/include/cmn/basicTypes.h b/include/cmn/basicTypes.h
new file mode 100644
index 0000000..7ea0e44
--- /dev/null
+++ b/include/cmn/basicTypes.h
@@ -0,0 +1,7 @@
+#include <stdint.h>
+
+typedef uint8_t Uint8;
+typedef uint16_t Uint16;
+typedef uint32_t Uint32;
+typedef uint64_t Uint64;
+
diff --git a/include/cmn/blockingCircularFifo.h b/include/cmn/blockingCircularFifo.h
new file mode 100644
index 0000000..41069d7
--- /dev/null
+++ b/include/cmn/blockingCircularFifo.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2019, Infosys Ltd.
+ *
+ * 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 INCLUDE_CMN_BLOCKINGCIRCULARFIFO_H_
+#define INCLUDE_CMN_BLOCKINGCIRCULARFIFO_H_
+
+#include <cstddef>
+#include <semaphore.h>
+#include "circularFifo.h"
+
+namespace cmn {
+	namespace utils {
+
+		template<typename Element, size_t size>
+		class BlockingCircularFifo
+		{
+		public:
+			BlockingCircularFifo():circularQueue()
+			{
+				sem_init(&pop_semaphore, 0, 0);
+				sem_init(&push_semaphore, 0, size);
+			}
+
+			~BlockingCircularFifo()
+			{
+				sem_destroy(&pop_semaphore);
+				sem_destroy(&push_semaphore);
+			}
+
+			bool push(Element* item)
+			{
+				sem_wait(&push_semaphore);
+				bool ret = circularQueue.push(item);
+				if (ret)
+					sem_post(&pop_semaphore);
+				else
+					sem_post(&push_semaphore);
+				return ret;
+			}
+
+			bool pop(Element*& item)
+			{
+				sem_wait(&pop_semaphore);
+				bool ret = circularQueue.pop(item);
+				if (ret)
+					sem_post(&push_semaphore);
+				else
+					sem_post(&pop_semaphore);
+				return ret;
+			}
+
+		private:
+			CircularFifo<Element, size> circularQueue;
+			sem_t pop_semaphore;
+			sem_t push_semaphore;
+		};
+	}
+}
+#endif /* INCLUDE_CMN_BLOCKINGCIRCULARFIFO_H_ */
diff --git a/include/cmn/circularFifo.h b/include/cmn/circularFifo.h
new file mode 100644
index 0000000..30e629b
--- /dev/null
+++ b/include/cmn/circularFifo.h
@@ -0,0 +1,94 @@
+/*
+ * This code is in public domain.
+ * Implementation and its platform dependent issues discussed in
+ * https://kjellkod.wordpress.com/2012/11/28/c-debt-paid-in-full-wait-free-lock-free-queue/
+ */
+
+#ifndef INCLUDE_CMN_CIRCULARFIFO_H_
+#define INCLUDE_CMN_CIRCULARFIFO_H_
+
+#include <atomic>
+#include <cstddef>
+
+namespace cmn {
+	namespace utils {
+		template<typename Element, size_t Size>
+		class CircularFifo
+		{
+			public:
+				enum { Capacity = Size + 1 };
+
+				CircularFifo() : _tail(0), _head(0){}
+				virtual ~CircularFifo() {}
+
+				bool push(Element* item);
+				bool pop(Element*& item);
+
+				bool wasEmpty() const;
+				bool wasFull() const;
+				bool isLockFree() const;
+
+			private:
+				size_t increment(size_t idx) const;
+
+				std::atomic <size_t>  _tail;
+				Element*    _array[Capacity];
+				std::atomic<size_t>   _head;
+		};
+
+		template<typename Element, size_t Size>
+		bool CircularFifo<Element, Size>::push(Element* item)
+		{
+			const auto current_tail = _tail.load(std::memory_order_relaxed);
+			const auto next_tail = increment(current_tail);
+			if(next_tail != _head.load(std::memory_order_acquire))
+			{
+				_array[current_tail] = item;
+				_tail.store(next_tail, std::memory_order_release);
+				return true;
+			}
+
+			return false;
+		}
+
+		template<typename Element, size_t Size>
+		bool CircularFifo<Element, Size>::pop(Element*& item)
+		{
+			const auto current_head = _head.load(std::memory_order_relaxed);
+			if(current_head == _tail.load(std::memory_order_acquire))
+				return false;
+
+			item = _array[current_head];
+			_head.store(increment(current_head), std::memory_order_release);
+			return true;
+		}
+
+		template<typename Element, size_t Size>
+		bool CircularFifo<Element, Size>::wasEmpty() const
+		{
+			return (_head.load() == _tail.load());
+		}
+
+		template<typename Element, size_t Size>
+		bool CircularFifo<Element, Size>::wasFull() const
+		{
+			const auto next_tail = increment(_tail.load());
+			return (next_tail == _head.load());
+		}
+
+		template<typename Element, size_t Size>
+		bool CircularFifo<Element, Size>::isLockFree() const
+		{
+			return (_tail.is_lock_free() && _head.is_lock_free());
+		}
+
+		template<typename Element, size_t Size>
+		size_t CircularFifo<Element, Size>::increment(size_t idx) const
+		{
+			return (idx + 1) % Capacity;
+		}
+	}
+}
+
+
+#endif /* INCLUDE_CMN_CIRCULARFIFO_H_ */
diff --git a/include/cmn/dataGroupManager.h b/include/cmn/dataGroupManager.h
new file mode 100644
index 0000000..b1dc16e
--- /dev/null
+++ b/include/cmn/dataGroupManager.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2019, Infosys Ltd.
+ *
+ * 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 DATA_GROUP_MANAGER_H
+#define DATA_GROUP_MANAGER_H
+
+#include <deque>
+#include "controlBlock.h"
+#include <mutex>
+
+using namespace SM;
+
+namespace cmn {
+namespace DGM
+{
+	class DataGroupManager
+	{
+		public:
+		
+			DataGroupManager();
+			virtual ~DataGroupManager();
+			
+			void initializeCBStore( int DataCount );
+			virtual ControlBlock* allocateCB();
+			virtual void deAllocateCB( uint32_t cbIndex );
+			SM::ControlBlock* findControlBlock( uint32_t index );
+
+		protected:
+			ControlBlock* cbstore_m;		// Indexed Store
+
+		private:
+			std::deque<ControlBlock*> freeQ_m;	// free Q
+			std::mutex mutex_m;
+
+	};
+};
+};
+#endif
diff --git a/include/cmn/debug.h b/include/cmn/debug.h
new file mode 100644
index 0000000..8a7a393
--- /dev/null
+++ b/include/cmn/debug.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2019, Infosys Ltd.
+ *
+ * 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 DEBUG_H_
+#define DEBUG_H_
+
+#include <iostream>
+#include <sstream>
+#include <stdint.h>
+
+using namespace std;
+
+namespace cmn
+{
+namespace utils
+{
+typedef enum{
+              LEVEL_1,
+              LEVEL_2,
+              LEVEL_3,
+              LEVEL_4
+            }DebugLevel;
+
+
+class Debug{
+public:
+  Debug();
+  ~Debug();
+
+  void printDebugStream();
+  void printDebugStreamToFile();
+
+  void add(char* data);
+  void add(uint8_t data);
+  void add(uint16_t data);
+  void add(uint32_t data);
+  void add(uint64_t data);
+  
+  void endOfLine();
+  void startNewLine();
+  void incrIndent();
+  void decrIndent();
+
+  void clearStream();
+ 
+  void setHexOutput();
+  void unsetHexOutput();
+
+private:
+
+  ostringstream stream;
+  uint8_t indent;
+  bool newLine;
+};
+};
+};
+
+#endif /* DEBUGUTILS_H_ */
+
diff --git a/include/cmn/ipcChannel.h b/include/cmn/ipcChannel.h
new file mode 100644
index 0000000..eb0dd31
--- /dev/null
+++ b/include/cmn/ipcChannel.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2019, Infosys Ltd.
+ *
+ * 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 INCLUDE_CMN_IPCCHANNEL_H_
+#define INCLUDE_CMN_IPCCHANNEL_H_
+
+#include "ipcTypes.h"
+
+namespace cmn {
+namespace ipc {
+
+class IpcChannel {
+public:
+	IpcChannel(IpcChannelType ipcType);
+	virtual ~IpcChannel();
+
+	IpcChannelType getIpcChannelType() const;
+	void setIpcChannelType(const IpcChannelType ipcType);
+
+	IpcChannelHdl getIpcChannelHdl() const;
+	void setIpcChannelHdl(const IpcChannelHdl ipcHdl, const IpcChannelType ipcType);
+
+	virtual void sendMsgTo(void * buffer, uint32_t len, IpcAddress destAddress) = 0;
+	virtual uint32_t recvMsgFrom(void * buffer, uint32_t bufLen, IpcAddress& srcAddress) = 0;
+
+protected:
+	IpcChannelType ipcType_m;
+	IpcChannelHdl ipcHdl_m;
+};
+
+} /* namespace ipc */
+} /* namespace cmn */
+
+#endif /* INCLUDE_CMN_IPCCHANNEL_H_ */
diff --git a/include/cmn/ipcTypes.h b/include/cmn/ipcTypes.h
new file mode 100644
index 0000000..d8855ed
--- /dev/null
+++ b/include/cmn/ipcTypes.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2019, Infosys Ltd.
+ *
+ * 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 INCLUDE_CMN_IPCTYPES_H_
+#define INCLUDE_CMN_IPCTYPES_H_
+
+#include <stdint.h>
+
+namespace cmn {
+namespace ipc {
+
+enum class IpcChannelType
+{
+	tipc_c,
+	maxIpcType_c
+};
+
+union IpcChannelHdl
+{
+	uint32_t u32;
+};
+
+union IpcAddress
+{
+	uint32_t u32;
+};
+
+typedef struct IpcMsgHeader
+{
+	IpcAddress destAddr;
+	IpcAddress srcAddr;
+
+} IpcMsgHeader;
+
+} /* namespace ipc */
+} /* namespace cmn */
+
+
+
+
+#endif /* INCLUDE_CMN_IPCTYPES_H_ */
diff --git a/include/cmn/memPoolManager.h b/include/cmn/memPoolManager.h
new file mode 100644
index 0000000..61d614a
--- /dev/null
+++ b/include/cmn/memPoolManager.h
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2019, Infosys Ltd.
+ *
+ * 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 INCLUDE_CMN_MEMPOOLMANAGER_H_
+#define INCLUDE_CMN_MEMPOOLMANAGER_H_
+
+#include <cstdint>
+#include <memory>
+#include <cstring>
+
+namespace cmn {
+	namespace memPool {
+		template <typename T>
+		class MemBlock
+		{
+		public:
+                        union Data {
+                                MemBlock<T>* next_mp;
+                                alignas(alignof(T)) uint8_t dataBlock_m[sizeof(T)];
+                        };
+
+			MemBlock() { memset(data_m.dataBlock_m, 0, sizeof(T)); }
+
+			void reset() { memset(data_m.dataBlock_m, 0, sizeof(T)); }
+
+			MemBlock<T>* getNextMemBlock() { return data_m.next_mp; }
+			void setNextMemBlock(MemBlock<T>* nxtBlk_p) { data_m.next_mp = nxtBlk_p; }
+
+			T* getDataBlock() { return (reinterpret_cast<T*> (data_m.dataBlock_m)); }
+
+		private:
+			Data data_m;
+		};
+
+		template <typename T>
+		class MemChunk
+		{
+		public:
+
+			MemChunk(uint32_t numOfBlocks)
+			{
+				std::unique_ptr<MemBlock<T>[]> blkArray_p(new MemBlock<T>[numOfBlocks]);
+				blockArray_mpa.reset(blkArray_p.release());
+
+				uint32_t  i = 1;
+				for (; i < numOfBlocks; i++)
+				{
+					blockArray_mpa[i-1].setNextMemBlock(&blockArray_mpa[i]);
+				}
+				blockArray_mpa[i].setNextMemBlock(NULL);
+			}
+
+			MemBlock<T>* getMemBlockArray() { return blockArray_mpa.get(); }
+
+			void setNextMemChunk(std::unique_ptr<MemChunk> &&nxtChunk_p) { nextMemChunk_mp.reset(nxtChunk_p.release()); }
+
+		private:
+			std::unique_ptr<MemChunk<T>> nextMemChunk_mp;
+			std::unique_ptr<MemBlock<T>[]> blockArray_mpa;
+		};
+
+		template <typename T>
+		class MemPoolManager
+		{
+		public:
+			MemPoolManager(size_t chunkSize):chunkSize_m(chunkSize),
+					currentChunk_mp(new MemChunk<T>(chunkSize)),
+					freeList_mp(currentChunk_mp->getMemBlockArray())
+			{
+
+			}
+
+			template <typename... Args> T* allocate(Args &&... args)
+			{
+				if (freeList_mp == NULL)
+				{
+					std::unique_ptr<MemChunk<T>> newChunk_p (new MemChunk<T>(chunkSize_m));
+					newChunk_p->setNextMemChunk(std::move(currentChunk_mp));
+					currentChunk_mp.reset(newChunk_p.release());
+
+					freeList_mp = currentChunk_mp->getMemBlockArray();
+				}
+				MemBlock<T>* currentBlock_p = freeList_mp;
+				freeList_mp = freeList_mp->getNextMemBlock();
+
+				T* dataBlock_p = currentBlock_p->getDataBlock();
+
+				new (dataBlock_p) T(std::forward<Args>(args)...);
+				return dataBlock_p;
+			}
+
+			void free(T* data_p)
+			{
+			    data_p->T::~T();
+			    MemBlock<T>* currentBlock_p = reinterpret_cast<MemBlock<T>*>(data_p);
+			    
+			    currentBlock_p->reset();
+
+			    currentBlock_p->setNextMemBlock(freeList_mp);
+			    freeList_mp = currentBlock_p;
+			}
+		private:
+			size_t chunkSize_m;
+			std::unique_ptr<MemChunk<T>> currentChunk_mp;
+			MemBlock<T>* freeList_mp;
+		};
+	}
+}
+
+
+#endif /* INCLUDE_CMN_MEMPOOLMANAGER_H_ */
diff --git a/include/cmn/msgBuffer.h b/include/cmn/msgBuffer.h
new file mode 100644
index 0000000..fcf799b
--- /dev/null
+++ b/include/cmn/msgBuffer.h
@@ -0,0 +1,88 @@
+/*
+ * MsgBuffer.h
+ *
+ *  Created on: Feb 13, 2011
+ *      Author: hariharanb
+ */
+
+#ifndef MSGBUFFER_H_
+#define MSGBUFFER_H_
+
+#include <sstream>
+#include <debug.h>
+
+#include <stdint.h>
+
+#define DEFAULT_BUFF_SIZE 1024
+
+using namespace std;
+extern cmn::utils::Debug errorStream;
+namespace cmn
+{
+namespace utils
+{
+class MsgBuffer
+{
+public:
+
+	MsgBuffer();
+	MsgBuffer(uint16_t size);
+
+	~MsgBuffer();
+
+
+	bool writeBits(uint8_t data, uint8_t size, bool append = true);
+	bool writeBytes(uint8_t* data, uint16_t size, bool append = true);
+	bool writeUint8(uint8_t data,  bool append = true);
+	bool writeUint16(uint16_t data, bool append = true);
+	bool writeUint32(uint32_t data, bool append = true);
+	bool writeUint64(uint64_t data, bool append = true);
+
+	void display (Debug &stream);
+
+	uint8_t readBits(uint16_t size);
+	bool readBytes(uint8_t* data, uint16_t size);
+
+	bool readBit();
+	void readUint8(uint8_t &data);
+	bool readUint16(uint16_t &data);
+	bool readUint32(uint32_t &data);
+	bool readUint64(uint64_t &data);
+	void reset();
+	void rewind();
+	void goToEnd();
+	void skipBits(uint8_t size);
+	void skipBytes(uint16_t size);
+    	uint16_t getLength();
+	uint16_t getBufferSize();
+    	uint16_t getCurrentIndex();
+    	void goToIndex(uint16_t idx);
+
+    	uint8_t charToHex(uint8_t x);
+    	uint16_t lengthLeft();
+    	uint16_t sizeLeft();
+
+    	void* getDataPointer();
+    	void setLength(uint16_t bufLen);
+
+private:
+
+	uint8_t* data_mp;
+	uint16_t bufSize;
+	uint16_t length;
+	uint16_t bitLength;
+	uint16_t byteIndex;
+	uint16_t bitIndex;
+
+	void initialize(uint16_t size);
+	bool incrBitIndex(uint8_t size);
+	bool incrByteIndex(uint16_t size);
+	void nextByte();
+};
+};
+};
+
+using namespace cmn::utils;
+
+#endif /* MSGBUFFER_H_ */
+
diff --git a/include/cmn/tipcSocket.h b/include/cmn/tipcSocket.h
new file mode 100644
index 0000000..da069db
--- /dev/null
+++ b/include/cmn/tipcSocket.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2019, Infosys Ltd.
+ *
+ * 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 INCLUDE_CMN_TIPCSOCKET_H_
+#define INCLUDE_CMN_TIPCSOCKET_H_
+
+#include "ipcChannel.h"
+
+namespace cmn {
+namespace ipc {
+
+class TipcSocket: public IpcChannel {
+public:
+	TipcSocket();
+	virtual ~TipcSocket();
+
+	bool bindTipcSocket(IpcAddress myAddress);
+
+    virtual void sendMsgTo(void * buffer, uint32_t len, IpcAddress destAddr);
+    virtual uint32_t recvMsgFrom(void * buffer, uint32_t len, IpcAddress& srcAddr);
+
+private:
+    void initialize();
+
+};
+
+} /* namespace ipc */
+} /* namespace cmn */
+
+#endif /* INCLUDE_CMN_TIPCSOCKET_H_ */
diff --git a/include/cmn/tipcTypes.h b/include/cmn/tipcTypes.h
new file mode 100644
index 0000000..6083170
--- /dev/null
+++ b/include/cmn/tipcTypes.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2019, Infosys Ltd.
+ *
+ * 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 INCLUDE_COMMONFWK_TIPCTYPES_H_
+#define INCLUDE_COMMONFWK_TIPCTYPES_H_
+
+#include <stdint.h>
+
+static const uint32_t tipcServiceAddressType_c = 18888;
+static const uint32_t tipcDomain_c = 0x0;
+
+typedef enum TipcServiceInstance
+{
+	mmeAppInstanceNum_c = 1,
+	s1apAppInstanceNum_c,
+	s6AppInstanceNum_c,
+	s11AppInstanceNum_c,
+
+	maxInstanceNum_c
+
+} TipcInstanceTypes;
+
+#endif /* INCLUDE_COMMONFWK_TIPCTYPES_H_ */