blob: 66f5fcaec858f452f1b6ef7f58382fe915d51670 [file] [log] [blame]
Colin Crossa3d386e2013-02-06 21:03:34 -08001/*
2 * Copyright (C) 2013 The Android Open Source Project
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 <stdio.h>
18#include <unistd.h>
Colin Crossa3d386e2013-02-06 21:03:34 -080019#include <cutils/klog.h>
Szymon Starzycki2a656c32013-09-05 14:26:28 -070020#include <getopt.h>
21#include <stdlib.h>
Colin Crossa3d386e2013-02-06 21:03:34 -080022
23#include "debug.h"
Szymon Starzyckib6c5f282013-07-24 17:08:04 -070024#include "trigger.h"
Szymon Starzycki2a656c32013-09-05 14:26:28 -070025#include "socket_client.h"
Colin Crossa3d386e2013-02-06 21:03:34 -080026
27unsigned int debug_level = DEBUG;
28
29void commands_init();
30void usb_init();
31void config_init();
Szymon Starzycki2a656c32013-09-05 14:26:28 -070032int transport_socket_init();
Szymon Starzyckibc849f12013-09-13 15:37:08 -070033int network_discovery_init();
Colin Crossa3d386e2013-02-06 21:03:34 -080034
35int main(int argc, char **argv)
36{
Szymon Starzycki2a656c32013-09-05 14:26:28 -070037 int socket_client = 0;
38 int c;
39
40 klog_init();
41 klog_set_level(6);
42
43 const struct option longopts[] = {
44 {"socket", no_argument, 0, 'S'},
45 {0, 0, 0, 0}
46 };
47
48 while (1) {
49 c = getopt_long(argc, argv, "S", longopts, NULL);
50 /* Alphabetical cases */
51 if (c < 0)
52 break;
53 switch (c) {
54 case 'S':
55 socket_client = 1;
56 break;
57 case '?':
58 return 1;
59 default:
60 return 0;
61 }
62 }
63
Colin Crossa3d386e2013-02-06 21:03:34 -080064 (void)argc;
65 (void)argv;
66
67 klog_init();
68 klog_set_level(6);
69
Szymon Starzycki2a656c32013-09-05 14:26:28 -070070 if (socket_client) {
71 run_socket_client();
72 }
73 else {
74 config_init();
75 load_trigger();
76 commands_init();
77 usb_init();
78 if (!transport_socket_init())
79 exit(1);
Szymon Starzyckibc849f12013-09-13 15:37:08 -070080 network_discovery_init();
Szymon Starzycki2a656c32013-09-05 14:26:28 -070081 while (1) {
82 sleep(1);
83 }
Colin Crossa3d386e2013-02-06 21:03:34 -080084 }
85 return 0;
86}