blob: d6e6c91a10e2d39797cdc427d08f70870114485a [file] [log] [blame]
anjana_sreekumar@infosys.com991c2062020-01-08 11:42:57 +05301/*
2 * Copyright (c) 2019, Infosys Ltd.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef SRC_MME_APP_MMETHREADS_H_
18#define SRC_MME_APP_MMETHREADS_H_
19
20#include <blockingCircularFifo.h>
21#include <ipcTypes.h>
22#include <msgBuffer.h>
23#include <interfaces/mmeIpcInterface.h>
24#include <mme_app.h>
25
26#define DATA_BUF_SIZE 255
27
28using namespace cmn::ipc;
29using namespace cmn::utils;
30
31extern MmeIpcInterface* mmeIpcIf_g;
32
33extern cmn::utils::BlockingCircularFifo<MsgBuffer, fifoQSize_c> mmeIpcIngressFifo_g;
34extern cmn::utils::BlockingCircularFifo<MsgBuffer, fifoQSize_c> mmeIpcEgressFifo_g;
35
36class MmeIngressIpcProducerThread
37{
38public:
39 void operator()()
40 {
41 uint16_t bytesRead = 0;
42 cmn::ipc::IpcAddress srcAddr;
43 unsigned char buf[DATA_BUF_SIZE] = {0};
44
45 while(1)
46 {
47 if ((bytesRead = mmeIpcIf_g->reader()->recvMsgFrom(buf, DATA_BUF_SIZE, srcAddr)) > 0 )
48 {
49 MsgBuffer *msgBuf = new MsgBuffer(bytesRead);
50 msgBuf->writeBytes(buf, bytesRead);
51 msgBuf->rewind();
52 if (!mmeIpcIngressFifo_g.push(msgBuf))
53 {
54 delete msgBuf;
55 }
56 }
57
58 memset(buf, 0 , 255);
59 }
60 }
61};
62
63class MmeIngressIpcConsumerThread
64{
65public:
66 void operator()()
67 {
68 while(1)
69 {
70 MsgBuffer* msgBuf = NULL;
71 while(mmeIpcIngressFifo_g.pop(msgBuf) == true)
72 {
73 mmeIpcIf_g->handleIpcMsg(msgBuf);
74 }
75 }
76 }
77};
78
79class MmeEgressIpcConsumerThread
80{
81public:
82 void operator()()
83 {
84 while(1)
85 {
86 MsgBuffer* msgBuf = NULL;
87 while(mmeIpcEgressFifo_g.pop(msgBuf) == true)
88 {
89 if (msgBuf != NULL)
90 {
91 cmn::ipc::IpcMsgHeader ipcHdr;
92 msgBuf->rewind();
93 msgBuf->readUint32(ipcHdr.destAddr.u32);
94 msgBuf->readUint32(ipcHdr.srcAddr.u32);
95 mmeIpcIf_g->sender()->sendMsgTo(msgBuf->getDataPointer(), msgBuf->getLength(), ipcHdr.destAddr);
96
97 delete msgBuf;
98 }
99 }
100 }
101 }
102};
103
104#endif /* SRC_MME_APP_MMETHREADS_H_ */