• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2015 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 #include <errno.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <time.h>
20 #include <unistd.h>
21 
22 #include <iostream>
23 
24 #include <base/command_line.h>
25 #include <base/logging.h>
26 #include <base/message_loop/message_loop.h>
27 
28 #include "proxy_dbus_shill_wifi_client.h"
29 #include "proxy_shill_wifi_client.h"
30 #include "proxy_rpc_server.h"
31 
32 namespace {
33 namespace switches {
34 static const char kHelp[] = "help";
35 static const char kPort[] = "port";
36 static const char kHelpMessage[] = "\n"
37     "Available Switches: \n"
38     "  --port=<port>\n"
39     "    Set the RPC server to listen on this TCP port(mandatory).\n";
40 }  // namespace switches
41 }  // namespace
42 
main(int argc,char * argv[])43 int main(int argc, char* argv[]) {
44   base::CommandLine::Init(argc, argv);
45   base::CommandLine* cl = base::CommandLine::ForCurrentProcess();
46 
47   if (cl->HasSwitch(switches::kHelp)) {
48     LOG(INFO) << switches::kHelpMessage;
49     return EXIT_SUCCESS;
50   }
51 
52   int xml_rpc_port;
53   if (!cl->HasSwitch(switches::kPort)) {
54     LOG(ERROR) << "port switch is mandatory.";
55     LOG(ERROR) << switches::kHelpMessage;
56     return EXIT_FAILURE;
57   }
58   xml_rpc_port = std::stoi(cl->GetSwitchValueASCII(switches::kPort));
59 
60   // Create and instantiate a message loop so that we can use it
61   // to block for asynchronous dbus signal callbacks. This needs
62   // to be instantiated before we connect to dbus.
63   base::MessageLoopForIO message_loop;
64 
65   // Connect to dbus's system bus.
66   dbus::Bus::Options options;
67   options.bus_type = dbus::Bus::SYSTEM;
68   scoped_refptr<dbus::Bus> dbus_bus = new dbus::Bus(options);
69   CHECK(dbus_bus->Connect());
70 
71   // We're creating the Dbus version of the Shill Wifi Client for now.
72   std::unique_ptr<ProxyShillWifiClient> shill_wifi_client(
73       new ProxyDbusShillWifiClient(dbus_bus));
74 
75   // Create the RPC server object
76   std::unique_ptr<ProxyRpcServer> rpc_server(
77       new ProxyRpcServer(xml_rpc_port, std::move(shill_wifi_client)));
78 
79   // Run indefinitely
80   rpc_server->Run();
81 
82   return 0;
83 }
84 
85