|
| 1 | +/* |
| 2 | + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The OpenAirInterface Software Alliance licenses this file to You under |
| 6 | + * the terms found in the LICENSE file in the root of this source tree. |
| 7 | + * |
| 8 | + * Unless required by applicable law or agreed to in writing, software |
| 9 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | + * See the License for the specific language governing permissions and |
| 12 | + * limitations under the License. |
| 13 | + *------------------------------------------------------------------------------- |
| 14 | + * For more information about the OpenAirInterface (OAI) Software Alliance: |
| 15 | + |
| 16 | + */ |
| 17 | + |
| 18 | +/*! \file sgw_s8_task.c |
| 19 | + \brief |
| 20 | + \author |
| 21 | + \company |
| 22 | + \email: |
| 23 | +*/ |
| 24 | +#define SGW_S8 |
| 25 | +#define SGW_S8_TASK_C |
| 26 | + |
| 27 | +#include <stdio.h> |
| 28 | +#include "log.h" |
| 29 | +#include "assertions.h" |
| 30 | +#include "common_defs.h" |
| 31 | +#include "itti_free_defined_msg.h" |
| 32 | +#include "sgw_s8_defs.h" |
| 33 | + |
| 34 | +static int handle_message(zloop_t* loop, zsock_t* reader, void* arg); |
| 35 | +static void sgw_s8_exit(void); |
| 36 | +task_zmq_ctx_t sgw_s8_task_zmq_ctx; |
| 37 | + |
| 38 | +static void* sgw_s8_thread(void* args) { |
| 39 | + itti_mark_task_ready(TASK_SGW_S8); |
| 40 | + init_task_context( |
| 41 | + TASK_SGW_S8, (task_id_t[]){TASK_MME_APP}, 1, handle_message, |
| 42 | + &sgw_s8_task_zmq_ctx); |
| 43 | + |
| 44 | + zloop_start(sgw_s8_task_zmq_ctx.event_loop); |
| 45 | + sgw_s8_exit(); |
| 46 | + return NULL; |
| 47 | +} |
| 48 | + |
| 49 | +int sgw_s8_init(void) { |
| 50 | + OAILOG_DEBUG(LOG_SGW_S8, "Initializing SGW-S8 interface\n"); |
| 51 | + |
| 52 | + if (itti_create_task(TASK_SGW_S8, &sgw_s8_thread, NULL) < 0) { |
| 53 | + OAILOG_ERROR(LOG_SGW_S8, "Failed to create sgw_s8 task\n"); |
| 54 | + return RETURNerror; |
| 55 | + } |
| 56 | + OAILOG_DEBUG(LOG_SGW_S8, "Done initialization of SGW_S8 interface\n"); |
| 57 | + return RETURNok; |
| 58 | +} |
| 59 | + |
| 60 | +static int handle_message(zloop_t* loop, zsock_t* reader, void* arg) { |
| 61 | + zframe_t* msg_frame = zframe_recv(reader); |
| 62 | + assert(msg_frame); |
| 63 | + MessageDef* received_message_p = (MessageDef*) zframe_data(msg_frame); |
| 64 | + |
| 65 | + switch (ITTI_MSG_ID(received_message_p)) { |
| 66 | + case TERMINATE_MESSAGE: { |
| 67 | + itti_free_msg_content(received_message_p); |
| 68 | + zframe_destroy(&msg_frame); |
| 69 | + sgw_s8_exit(); |
| 70 | + } break; |
| 71 | + |
| 72 | + default: { |
| 73 | + OAILOG_DEBUG( |
| 74 | + LOG_SGW_S8, "Unkwnon message ID %d: %s\n", |
| 75 | + ITTI_MSG_ID(received_message_p), ITTI_MSG_NAME(received_message_p)); |
| 76 | + } break; |
| 77 | + } |
| 78 | + |
| 79 | + itti_free_msg_content(received_message_p); |
| 80 | + zframe_destroy(&msg_frame); |
| 81 | + return 0; |
| 82 | +} |
| 83 | + |
| 84 | +//------------------------------------------------------------------------------ |
| 85 | +static void sgw_s8_exit(void) { |
| 86 | + destroy_task_context(&sgw_s8_task_zmq_ctx); |
| 87 | + OAILOG_DEBUG(LOG_SGW_S8, "Finished cleaning up SGW_S8 task \n"); |
| 88 | + OAI_FPRINTF_INFO("TASK_SGW_S8 terminated\n"); |
| 89 | + pthread_exit(NULL); |
| 90 | +} |
0 commit comments