blob: cca65d9f761b5b9ee6d2fe22d6f814c9484ea108 [file] [log] [blame]
Hao Chen5a97c382019-12-05 15:53:05 -08001#include <android-base/logging.h>
2#include <getopt.h>
3#include <unistd.h>
4
5#include "vhal_v2_0/virtualization/GrpcVehicleServer.h"
6#include "vhal_v2_0/virtualization/Utils.h"
7
8int main(int argc, char* argv[]) {
9 namespace vhal_impl = android::hardware::automotive::vehicle::V2_0::impl;
10
11 vhal_impl::VsockServerInfo serverInfo;
12
13 // unique values to identify the options
14 constexpr int OPT_VHAL_SERVER_CID = 1001;
15 constexpr int OPT_VHAL_SERVER_PORT_NUMBER = 1002;
16
17 struct option longOptions[] = {
18 {"server_cid", 1, 0, OPT_VHAL_SERVER_CID},
19 {"server_port", 1, 0, OPT_VHAL_SERVER_PORT_NUMBER},
20 {nullptr, 0, nullptr, 0},
21 };
22
23 int optValue;
24 while ((optValue = getopt_long_only(argc, argv, ":", longOptions, 0)) != -1) {
25 switch (optValue) {
26 case OPT_VHAL_SERVER_CID:
27 serverInfo.serverCid = std::atoi(optarg);
28 LOG(DEBUG) << "Vehicle HAL server CID: " << serverInfo.serverCid;
29 break;
30 case OPT_VHAL_SERVER_PORT_NUMBER:
31 serverInfo.serverPort = std::atoi(optarg);
32 LOG(DEBUG) << "Vehicle HAL server port: " << serverInfo.serverPort;
33 break;
34 default:
35 // ignore other options
36 break;
37 }
38 }
39
40 if (serverInfo.serverCid == 0 || serverInfo.serverPort == 0) {
41 LOG(FATAL) << "Invalid server information, CID: " << serverInfo.serverCid
42 << "; port: " << serverInfo.serverPort;
43 // Will abort after logging
44 }
45
46 auto server = vhal_impl::makeGrpcVehicleServer(vhal_impl::getVsockUri(serverInfo));
47 server->Start();
48 return 0;
49}