O-CU-UP
[scp/ocu/5gnr.git] / Cu / CuUpApp / Src / main.c
1 /******************************************************************************
2 ###############################################################################
3 #   Copyright (c) [2017-2020] [ICT/CAS]                                        #
4 #   Licensed under the ORAN Software License v1.0 (License)             #
5 ###############################################################################
6 ******************************************************************************/
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <fcntl.h>
10 #include <unistd.h>
11 #include <signal.h>
12 #include <getopt.h>
13 #include "vos_common.h"
14 #include "vos_time.h"
15 #include "vos_cli.h"
16 #include "plat_alarm.h"
17 #include "plat_db.h"
18 #include "gnbCommon.h"
19 #include "cuCommon.h"
20 #include "omCuupApi.h"
21 extern UCHAR cuupUnSocketPath[];
22 INT32 cuupGetSetUpPara(INT32 argc, INT8 **argv)
23 {
24         UCHAR *pInt = NULL;
25         
26         struct option long_options[] =
27         {
28                 {"startup-item",        required_argument,      0,      'i' },
29                 {"version",             no_argument,            0,      'v' },
30                 {"help",                        no_argument,            0,      'h' },
31                 {0,                             0,                                      0,      0 }
32         };
33         
34         while (1)
35         {
36                 int option_index = 0;
37                 int c = getopt_long(argc, argv, "i:vh", long_options, &option_index);
38                 if (c == -1)
39                 {
40                         break;
41                 }
42                 
43                 switch (c)
44                 {
45                         case 'i':
46                                 pInt = (UCHAR *)cuupUnSocketPath;
47                                 break;
48                         case 'v': 
49                                 exit(0);
50                                 break;
51                         case 'h':
52                                 exit(0);
53             default:
54                 return VOS_OK;
55                 }
56         
57                 if (pInt && optarg)
58                 {
59                         sscanf(optarg, "%s", pInt);
60                         VOS_Printf("unSocketPath: %s\n", cuupUnSocketPath);
61                 }
62         }
63         
64         return VOS_OK;
65 }
66
67 void cuupAppSigHandler(int sig)
68 {            
69     VOS_Printf("\r\nReceive signal:%d\r\n",sig);
70     
71     if(SIGSEGV == sig)
72     {
73         if(shm_unlink(CUUP_SHM_FILE) < 0)
74         {
75             VOS_Printf("Du_shm Delete CUUP_SHM_FILE shared memory failed !\n ");
76             return;
77         }
78        signal(sig, SIG_DFL);
79        kill(getpid(), sig);
80     }
81     else if(SIGINT == sig)
82     {
83     }
84     else if(SIGABRT == sig)
85     {
86         if(shm_unlink(CUUP_SHM_FILE) < 0)
87         {
88             VOS_Printf("Du_shm Delete CUUP_SHM_FILE shared memory failed !\n ");
89             return;
90         }    
91     }
92     return;
93 }
94
95 INT32 cuupAppregisterSignal()
96 {
97
98     /*9:SIGSEGV signal*/
99     if ( Product_Signal( SIGSEGV, 0,cuupAppSigHandler ) == VOS_ERROR )
100     {
101         /*commomctrl_om_init_fail_rsp(0);*/
102         return VOS_ERROR;
103     }
104
105     if ( Product_Signal( SIGINT, 0,cuupAppSigHandler ) == VOS_ERROR )
106     {
107
108         return VOS_ERROR;
109     }
110
111     /*2:capture signal*/
112     if ( Product_Signal( SIGABRT,0,cuupAppSigHandler ) == VOS_ERROR )
113     {
114         /*commomctrl_om_init_fail_rsp(0);*/
115         return VOS_ERROR;
116     }
117     return VOS_OK;
118 }
119
120 /*
121     function name: main
122     function:      协议栈入口函数
123     para:          无
124     return value:  VOS_OK,VOS_ERROR
125 */
126 INT32 main(int argc,INT8 **argv)
127 {
128     /*check para*/
129     
130     CHECK_FUNCTION_RET(cuupGetSetUpPara(argc,argv));
131
132     /*init cucp global var*/
133     CHECK_FUNCTION_RET(cuupAppGlobalVarInit());
134     
135     /*platform init*/
136     CHECK_FUNCTION_RET(cuupAppPlatformInit(argv));
137         
138     /*register signal*/
139     CHECK_FUNCTION_RET(cuupAppregisterSignal());
140     /*VOS_TaskInfoAttach 必须在main函数里调用*/
141     
142     /*omadp vos task create*/
143     CHECK_FUNCTION_RET(cuupAppOmadpModuleInit());
144     
145     while(1)
146     {
147         sleep(5000);
148
149     }   
150     return 0;
151 }
152
153
154
155
156
157