anjana_sreekumar@infosys.com | 991c206 | 2020-01-08 11:42:57 +0530 | [diff] [blame^] | 1 | /* |
| 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 | #include <iostream> |
| 18 | #include <pthread.h> |
| 19 | #include <thread> |
| 20 | #include <string.h> |
| 21 | #include <sys/stat.h> |
| 22 | |
| 23 | #include <blockingCircularFifo.h> |
| 24 | #include <msgBuffer.h> |
| 25 | #include "err_codes.h" |
| 26 | #include <interfaces/mmeIpcInterface.h> |
| 27 | #include <mmeStates/stateFactory.h> |
| 28 | #include "message_queues.h" |
| 29 | #include "mme_app.h" |
| 30 | #include "msgType.h" |
| 31 | #include "stateMachineEngine.h" |
| 32 | #include <sys/types.h> |
| 33 | #include "mmeThreads.h" |
| 34 | |
| 35 | extern "C" |
| 36 | { |
| 37 | #include "log.h" |
| 38 | #include "json_data.h" |
| 39 | } |
| 40 | |
| 41 | extern void* RunServer(void * data); |
| 42 | using namespace std; |
| 43 | using namespace mme; |
| 44 | |
| 45 | /********************************************************* |
| 46 | * |
| 47 | * Circular FIFOs for sender IPC and Reader IPC threads |
| 48 | * |
| 49 | **********************************************************/ |
| 50 | cmn::utils::BlockingCircularFifo<cmn::utils::MsgBuffer, fifoQSize_c> mmeIpcIngressFifo_g; |
| 51 | cmn::utils::BlockingCircularFifo<cmn::utils::MsgBuffer, fifoQSize_c> mmeIpcEgressFifo_g; |
| 52 | |
| 53 | /********************************************************* |
| 54 | * |
| 55 | * Externs |
| 56 | * |
| 57 | **********************************************************/ |
| 58 | extern char processName[255]; |
| 59 | extern int pid; |
| 60 | |
| 61 | mme_config g_mme_cfg; |
| 62 | pthread_t stage_tid[5]; |
| 63 | |
| 64 | MmeIpcInterface* mmeIpcIf_g = NULL; |
| 65 | void |
| 66 | init_parser(char *path) |
| 67 | { |
| 68 | load_json(path); |
| 69 | } |
| 70 | |
| 71 | int |
| 72 | parse_mme_conf() |
| 73 | { |
| 74 | /*mme own information*/ |
| 75 | g_mme_cfg.mme_name = get_string_scalar("mme.name"); |
| 76 | if(NULL == g_mme_cfg.mme_name) return E_PARSING_FAILED; |
| 77 | |
| 78 | g_mme_cfg.mme_ip_addr = get_ip_scalar("mme.ip_addr"); |
| 79 | if(E_PARSING_FAILED == g_mme_cfg.mme_ip_addr) return E_PARSING_FAILED; |
| 80 | |
| 81 | g_mme_cfg.mcc_dig1 = get_int_scalar("mme.mcc.dig1"); |
| 82 | if(E_PARSING_FAILED == g_mme_cfg.mcc_dig1) return E_PARSING_FAILED; |
| 83 | g_mme_cfg.mcc_dig2 = get_int_scalar("mme.mcc.dig2"); |
| 84 | if(E_PARSING_FAILED == g_mme_cfg.mcc_dig1) return E_PARSING_FAILED; |
| 85 | g_mme_cfg.mcc_dig3 = get_int_scalar("mme.mcc.dig3"); |
| 86 | if(E_PARSING_FAILED == g_mme_cfg.mcc_dig1) return E_PARSING_FAILED; |
| 87 | g_mme_cfg.mcc_dig1 = get_int_scalar("mme.mnc.dig1"); |
| 88 | if(E_PARSING_FAILED == g_mme_cfg.mcc_dig1) return E_PARSING_FAILED; |
| 89 | g_mme_cfg.mnc_dig2 = get_int_scalar("mme.mnc.dig2"); |
| 90 | if(E_PARSING_FAILED == g_mme_cfg.mcc_dig1) return E_PARSING_FAILED; |
| 91 | g_mme_cfg.mnc_dig3 = get_int_scalar("mme.mnc.dig3"); |
| 92 | if(E_PARSING_FAILED == g_mme_cfg.mcc_dig1) return E_PARSING_FAILED; |
| 93 | |
| 94 | return SUCCESS; |
| 95 | } |
| 96 | |
| 97 | void setThreadName(std::thread* thread, const char* threadName) |
| 98 | { |
| 99 | auto handle = thread->native_handle(); |
| 100 | pthread_setname_np(handle,threadName); |
| 101 | } |
| 102 | |
| 103 | int main(int argc, char *argv[]) |
| 104 | { |
| 105 | memcpy (processName, argv[0], strlen(argv[0])); |
| 106 | pid = getpid(); |
| 107 | |
| 108 | StateFactory::Instance()->initialize(); |
| 109 | |
| 110 | mmeIpcIf_g = new MmeIpcInterface(); |
| 111 | mmeIpcIf_g->setup(); |
| 112 | |
| 113 | init_parser("conf/mme.json"); |
| 114 | parse_mme_conf(); |
| 115 | |
| 116 | MmeIngressIpcProducerThread ipcReader; |
| 117 | std::thread t1(ipcReader); |
| 118 | setThreadName(&t1, "IpcReader"); |
| 119 | t1.detach(); |
| 120 | |
| 121 | MmeIngressIpcConsumerThread msgHandlerThread; |
| 122 | std::thread t2(msgHandlerThread); |
| 123 | setThreadName(&t2, "MMEMsgHandlerThread"); |
| 124 | t2.detach(); |
| 125 | |
| 126 | MmeEgressIpcConsumerThread ipcWriter; |
| 127 | std::thread t3(ipcWriter); |
| 128 | setThreadName(&t3, "IpcWriter"); |
| 129 | t3.detach(); |
| 130 | |
| 131 | // start gRPC server |
| 132 | pthread_attr_t attr; |
| 133 | pthread_attr_init(&attr); |
| 134 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); |
| 135 | pthread_create(&stage_tid[0], &attr, &RunServer, NULL); |
| 136 | pthread_attr_destroy(&attr); |
| 137 | |
| 138 | while(1) |
| 139 | { |
| 140 | SM::StateMachineEngine::Instance()->run(); |
| 141 | } |
| 142 | |
| 143 | return 0; |
| 144 | } |