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