Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 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 SHILL_MANAGER_ |
| 6 | #define SHILL_MANAGER_ |
| 7 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 8 | #include <string> |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 9 | #include <vector> |
Chris Masone | 487b8bf | 2011-05-13 16:27:57 -0700 | [diff] [blame] | 10 | |
Paul Stewart | e613202 | 2011-08-16 09:11:02 -0700 | [diff] [blame] | 11 | #include <base/file_path.h> |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 12 | #include <base/memory/ref_counted.h> |
Chris Masone | 487b8bf | 2011-05-13 16:27:57 -0700 | [diff] [blame] | 13 | #include <base/memory/scoped_ptr.h> |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 14 | #include <chromeos/dbus/service_constants.h> |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 15 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 16 | #include "shill/device.h" |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 17 | #include "shill/device_info.h" |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 18 | #include "shill/modem_info.h" |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 19 | #include "shill/property_store.h" |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 20 | #include "shill/service.h" |
| 21 | #include "shill/shill_event.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 22 | |
| 23 | namespace shill { |
| 24 | |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 25 | class ControlInterface; |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 26 | class Error; |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 27 | class EventDispatcher; |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 28 | class ManagerAdaptorInterface; |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 29 | class GLib; |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 30 | |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 31 | class Manager { |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 32 | public: |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 33 | struct Properties { |
| 34 | public: |
| 35 | Properties() : offline_mode(false) {} |
| 36 | bool offline_mode; |
| 37 | std::string check_portal_list; |
| 38 | std::string country; |
| 39 | std::string portal_url; |
| 40 | }; |
| 41 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 42 | Manager(ControlInterface *control_interface, |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 43 | EventDispatcher *dispatcher, |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 44 | GLib *glib, |
| 45 | const std::string &run_directory, |
| 46 | const std::string &storage_directory, |
| 47 | const std::string &user_storage_format); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 48 | virtual ~Manager(); |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 49 | |
| 50 | void AddDeviceToBlackList(const std::string &device_name); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 51 | void Start(); |
| 52 | void Stop(); |
| 53 | |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 54 | const ProfileRefPtr &ActiveProfile(); |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 55 | bool MoveToActiveProfile(const ProfileRefPtr &from, |
| 56 | const ServiceRefPtr &to_move); |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 57 | |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 58 | void RegisterDevice(const DeviceRefPtr &to_manage); |
mukesh agrawal | 5029c6c | 2011-08-25 11:12:40 -0700 | [diff] [blame] | 59 | void DeregisterDevice(const DeviceRefPtr &to_forget); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 60 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame^] | 61 | virtual void RegisterService(const ServiceRefPtr &to_manage); |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 62 | void DeregisterService(const ServiceConstRefPtr &to_forget); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 63 | virtual void UpdateService(const ServiceConstRefPtr &to_update); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 64 | |
| 65 | void FilterByTechnology(Device::Technology tech, |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 66 | std::vector<DeviceRefPtr> *found); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 67 | |
Chris Masone | e0dea76 | 2011-06-09 09:06:03 -0700 | [diff] [blame] | 68 | ServiceRefPtr FindService(const std::string& name); |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 69 | std::vector<std::string> EnumerateAvailableServices(); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 70 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame^] | 71 | // called via RPC (e.g., from ManagerDBusAdaptor) |
| 72 | void RequestScan(const std::string &technology, Error *error); |
| 73 | |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 74 | virtual DeviceInfo *device_info() { return &device_info_; } |
| 75 | virtual PropertyStore *store() { return &store_; } |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 76 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 77 | private: |
Darin Petkov | 6f9eaa3 | 2011-08-09 15:26:44 -0700 | [diff] [blame] | 78 | friend class ManagerAdaptorInterface; |
| 79 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 80 | std::string CalculateState(); |
| 81 | std::vector<std::string> AvailableTechnologies(); |
| 82 | std::vector<std::string> ConnectedTechnologies(); |
| 83 | std::string DefaultTechnology(); |
| 84 | std::vector<std::string> EnabledTechnologies(); |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 85 | std::vector<std::string> EnumerateDevices(); |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 86 | // TODO(cmasone): This should be implemented by filtering |services_|. |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 87 | std::vector<std::string> EnumerateWatchedServices(); |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 88 | std::string GetActiveProfileName(); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 89 | |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 90 | void HelpRegisterDerivedString(const std::string &name, |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 91 | std::string(Manager::*get)(void), |
| 92 | bool(Manager::*set)(const std::string&)); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 93 | void HelpRegisterDerivedStrings(const std::string &name, |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 94 | Strings(Manager::*get)(void), |
| 95 | bool(Manager::*set)(const Strings&)); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 96 | |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 97 | const FilePath run_path_; |
| 98 | const FilePath storage_path_; |
| 99 | const std::string user_storage_format_; |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 100 | scoped_ptr<ManagerAdaptorInterface> adaptor_; |
| 101 | DeviceInfo device_info_; |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 102 | ModemInfo modem_info_; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 103 | bool running_; |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 104 | std::vector<DeviceRefPtr> devices_; |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 105 | // We store Services in a vector, because we want to keep them sorted. |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 106 | std::vector<ServiceRefPtr> services_; |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 107 | std::vector<ProfileRefPtr> profiles_; |
| 108 | ProfileRefPtr ephemeral_profile_; |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 109 | ControlInterface *control_interface_; |
| 110 | GLib *glib_; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 111 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 112 | // Properties to be get/set via PropertyStore calls. |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 113 | Properties props_; |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 114 | PropertyStore store_; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | } // namespace shill |
| 118 | |
| 119 | #endif // SHILL_MANAGER_ |