Peter Qiu | 376e404 | 2014-11-13 09:40:28 -0800 | [diff] [blame] | 1 | // Copyright 2014 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef APMANAGER_SERVICE_H_ |
| 6 | #define APMANAGER_SERVICE_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include <base/macros.h> |
| 11 | #include <chromeos/process.h> |
| 12 | |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 13 | #include "apmanager/config.h" |
Peter Qiu | 376e404 | 2014-11-13 09:40:28 -0800 | [diff] [blame] | 14 | #include "apmanager/dbus_adaptors/org.chromium.apmanager.Service.h" |
Peter Qiu | bf8e36c | 2014-12-03 22:59:45 -0800 | [diff] [blame] | 15 | #include "apmanager/dhcp_server_factory.h" |
Peter Qiu | 7751730 | 2015-01-08 16:22:16 -0800 | [diff] [blame] | 16 | #include "apmanager/file_writer.h" |
Peter Qiu | 1dbf9fd | 2015-01-09 13:36:55 -0800 | [diff] [blame^] | 17 | #include "apmanager/process_factory.h" |
Peter Qiu | 376e404 | 2014-11-13 09:40:28 -0800 | [diff] [blame] | 18 | |
| 19 | namespace apmanager { |
| 20 | |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 21 | class Manager; |
Peter Qiu | 376e404 | 2014-11-13 09:40:28 -0800 | [diff] [blame] | 22 | |
| 23 | class Service : public org::chromium::apmanager::ServiceAdaptor, |
| 24 | public org::chromium::apmanager::ServiceInterface { |
| 25 | public: |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 26 | Service(Manager* manager, int service_identifier); |
Peter Qiu | 376e404 | 2014-11-13 09:40:28 -0800 | [diff] [blame] | 27 | virtual ~Service(); |
| 28 | |
| 29 | // Implementation of ServiceInterface. |
| 30 | virtual bool Start(chromeos::ErrorPtr* error); |
| 31 | virtual bool Stop(chromeos::ErrorPtr* error); |
| 32 | |
| 33 | // Register Service DBus object. |
| 34 | void RegisterAsync( |
| 35 | chromeos::dbus_utils::ExportedObjectManager* object_manager, |
Peter Qiu | c9ce1f1 | 2014-12-05 11:14:29 -0800 | [diff] [blame] | 36 | const scoped_refptr<dbus::Bus>& bus, |
Peter Qiu | 376e404 | 2014-11-13 09:40:28 -0800 | [diff] [blame] | 37 | chromeos::dbus_utils::AsyncEventSequencer* sequencer); |
| 38 | |
| 39 | const dbus::ObjectPath& dbus_path() const { return dbus_path_; } |
| 40 | |
| 41 | private: |
| 42 | friend class ServiceTest; |
| 43 | |
| 44 | static const char kHostapdPath[]; |
| 45 | static const char kHostapdConfigPathFormat[]; |
Peter Qiu | 1dbf9fd | 2015-01-09 13:36:55 -0800 | [diff] [blame^] | 46 | static const char kHostapdControlInterfacePath[]; |
Peter Qiu | 376e404 | 2014-11-13 09:40:28 -0800 | [diff] [blame] | 47 | static const int kTerminationTimeoutSeconds; |
| 48 | |
| 49 | // Return true if hostapd process is currently running. |
| 50 | bool IsHostapdRunning(); |
| 51 | |
| 52 | // Start hostapd process. Return true if process is created/started |
| 53 | // successfully, false otherwise. |
| 54 | bool StartHostapdProcess(const std::string& config_file_path); |
| 55 | |
| 56 | // Stop the running hostapd process. Sending it a SIGTERM signal first, then |
| 57 | // a SIGKILL if failed to terminated with SIGTERM. |
| 58 | void StopHostapdProcess(); |
| 59 | |
Peter Qiu | bf8e36c | 2014-12-03 22:59:45 -0800 | [diff] [blame] | 60 | // Release resources allocated to this service. |
| 61 | void ReleaseResources(); |
| 62 | |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 63 | Manager* manager_; |
Peter Qiu | 376e404 | 2014-11-13 09:40:28 -0800 | [diff] [blame] | 64 | int service_identifier_; |
| 65 | std::string service_path_; |
| 66 | dbus::ObjectPath dbus_path_; |
| 67 | std::unique_ptr<Config> config_; |
| 68 | std::unique_ptr<chromeos::dbus_utils::DBusObject> dbus_object_; |
| 69 | std::unique_ptr<chromeos::Process> hostapd_process_; |
Peter Qiu | bf8e36c | 2014-12-03 22:59:45 -0800 | [diff] [blame] | 70 | std::unique_ptr<DHCPServer> dhcp_server_; |
| 71 | DHCPServerFactory* dhcp_server_factory_; |
Peter Qiu | 7751730 | 2015-01-08 16:22:16 -0800 | [diff] [blame] | 72 | FileWriter* file_writer_; |
Peter Qiu | 1dbf9fd | 2015-01-09 13:36:55 -0800 | [diff] [blame^] | 73 | ProcessFactory* process_factory_; |
Peter Qiu | 376e404 | 2014-11-13 09:40:28 -0800 | [diff] [blame] | 74 | |
| 75 | DISALLOW_COPY_AND_ASSIGN(Service); |
| 76 | }; |
| 77 | |
| 78 | } // namespace apmanager |
| 79 | |
| 80 | #endif // APMANAGER_SERVICE_H_ |