Fixing svace issue
[apps/native/boot-animation.git] / src / boot.c
1 /*
2  * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
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
18 #include <vconf.h>
19 #include <getopt.h>
20 #include <stdlib.h>
21 #include <fcntl.h>
22
23 #include "animation.h"
24 #include "boot.h"
25 #include "app_log.h"
26 #include "boot_sound.h"
27
28 #include "test.h"
29
30 extern char *optarg;
31 extern int optind;
32
33 void(*boot_exit)(void);
34
35 static int __check_on_off_type(void *user_data)
36 {
37         int c;
38         int i;
39         int argc;
40         char **argv;
41         int type = TYPE_UNKNOWN;
42         struct args *args = user_data;
43         static struct option long_options[] = {
44                 {"start",       no_argument,            0,      's'     },
45                 {"off",         no_argument,            0,      'o'     },
46                 {"stop",        no_argument,            0,      'p'     },
47                 {"clear",       no_argument,            0,      'c'     },
48                 {0,             0,                      0,      0       },
49         };
50         argc = args->argc;
51         argv = args->argv;
52
53         if(argc < 0 || argc > 2)
54         {
55                 __E("Invalid argument count for boot animation: [argc: %d]", argc);
56                 return TYPE_UNKNOWN;
57         }
58
59         for (i = 0; i < argc; i++)
60                 __D("argc %d [%s]", i, argv[i]);
61
62         while ((c = getopt_long(argc, argv, "sopc", long_options, NULL)) >= 0) {
63
64                 switch (c) {
65                 case 's':
66                         type = TYPE_ON;
67                         break;
68                 case 'p':
69                         type = TYPE_OFF_NOEXIT;
70                         break;
71                 case 'o':
72                         type = TYPE_OFF;
73                         break;
74                 case 'c':
75                         type = TYPE_OFF_NOEXIT;
76                         break;
77                 default:
78                         type = TYPE_UNKNOWN;
79                         __D("[Boot-ani] unknown arg [%s]", optarg);
80                         return EXIT_FAILURE;
81                 }
82         }
83         optind = 0;
84
85         return type;
86 }
87
88 #if (!TEST_MODE)
89 int main(int argc, char *argv[])
90 {
91         int fd = 0;
92         struct args args;
93         setenv("HOME", "/home/root", 1);
94
95         if (argc < 2) {
96                 printf("Usage) %s {--start|--stop}\n", argv[0]);
97                 printf("  Ex:");
98                 printf("    # %s --start\n", argv[0]);
99                 printf("    # %s --stop\n", argv[0]);
100                 printf("    # %s --off\n", argv[0]);
101
102                 return EXIT_FAILURE;
103         }
104
105         args.argc = argc;
106         args.argv = argv;
107
108         static int invoked_flag = 0;
109         if (invoked_flag == 1)
110                 return -1;
111
112         invoked_flag = 1;
113
114         close(1);
115         fd = open("/tmp/myfile.txt", O_CREAT|O_RDWR, S_IRWXU|S_IRGRP);
116         __D("Result of log file open: %d", fd);
117
118         elm_init(argc, argv);
119         boot_exit = elm_exit;
120
121         int boot_type = -1;
122         boot_type = __check_on_off_type(&args);
123         if (boot_type < 0) {
124                 __E("Failed to get on off type or UNKNOWN_TYPE: %d", boot_type);
125                 return 1;
126         }
127
128         if (animation_init(boot_type) != EXIT_SUCCESS) {
129                 __E("Exit boot-animation");
130                 return 1;
131         }
132
133         if (vconf_set_int(VCONFKEY_BOOT_ANIMATION_FINISHED, 0) != 0)
134                 __D("Failed to set finished value to 0\n");
135
136         play_boot_sound(boot_type);
137
138         elm_run();
139
140         animation_fini();
141
142         return 0;
143 }
144
145 #endif
146
147 #include "test.h"
148 #if TEST_MODE
149 int __t__check_on_off_type(void *user_data)
150 {
151         return __check_on_off_type(user_data);
152 }
153 #endif