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 | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 15 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 16 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 17 | #include "shill/device.h" |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 18 | #include "shill/device_info.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 19 | #include "shill/event_dispatcher.h" |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 20 | #include "shill/modem_info.h" |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 21 | #include "shill/property_store.h" |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 22 | #include "shill/service.h" |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 23 | #include "shill/wifi.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 24 | |
| 25 | namespace shill { |
| 26 | |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 27 | class ControlInterface; |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 28 | class Error; |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 29 | class EventDispatcher; |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 30 | class ManagerAdaptorInterface; |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 31 | class GLib; |
Chris Masone | d0ceb8c | 2011-06-02 10:05:39 -0700 | [diff] [blame] | 32 | |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 33 | class Manager { |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 34 | public: |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 35 | struct Properties { |
| 36 | public: |
| 37 | Properties() : offline_mode(false) {} |
| 38 | bool offline_mode; |
| 39 | std::string check_portal_list; |
| 40 | std::string country; |
| 41 | std::string portal_url; |
| 42 | }; |
| 43 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 44 | Manager(ControlInterface *control_interface, |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 45 | EventDispatcher *dispatcher, |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 46 | GLib *glib, |
| 47 | const std::string &run_directory, |
| 48 | const std::string &storage_directory, |
| 49 | const std::string &user_storage_format); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 50 | virtual ~Manager(); |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 51 | |
| 52 | void AddDeviceToBlackList(const std::string &device_name); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 53 | void Start(); |
| 54 | void Stop(); |
| 55 | |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 56 | const ProfileRefPtr &ActiveProfile(); |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 57 | bool MoveServiceToProfile(const ServiceRefPtr &to_move, |
| 58 | const ProfileRefPtr &destination); |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 59 | |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 60 | void RegisterDevice(const DeviceRefPtr &to_manage); |
mukesh agrawal | 5029c6c | 2011-08-25 11:12:40 -0700 | [diff] [blame] | 61 | void DeregisterDevice(const DeviceRefPtr &to_forget); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 62 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 63 | virtual void RegisterService(const ServiceRefPtr &to_manage); |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 64 | virtual void DeregisterService(const ServiceRefPtr &to_forget); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 65 | virtual void UpdateService(const ServiceConstRefPtr &to_update); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 66 | |
Paul Stewart | fdd1607 | 2011-09-16 12:41:35 -0700 | [diff] [blame] | 67 | void FilterByTechnology(Technology::Identifier tech, |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 68 | std::vector<DeviceRefPtr> *found); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 69 | |
Chris Masone | e0dea76 | 2011-06-09 09:06:03 -0700 | [diff] [blame] | 70 | ServiceRefPtr FindService(const std::string& name); |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 71 | std::vector<std::string> EnumerateAvailableServices(); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 72 | |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 73 | // called via RPC (e.g., from ManagerDBusAdaptor) |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 74 | WiFiServiceRefPtr GetWifiService(const KeyValueStore &args, Error *error); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 75 | void RequestScan(const std::string &technology, Error *error); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 76 | std::string GetTechnologyOrder(); |
| 77 | void SetTechnologyOrder(const std::string &order, Error *error); |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 78 | // Create a profile. This does not affect the profile stack. |
| 79 | void CreateProfile(const std::string &name, Error *error); |
| 80 | // Pushes existing profile with name |name| onto stack of managed profiles. |
| 81 | void PushProfile(const std::string &name, Error *error); |
| 82 | // Pops profile named |name| off the top of the stack of managed profiles. |
| 83 | void PopProfile(const std::string &name, Error *error); |
| 84 | // Remove the active profile. |
| 85 | void PopAnyProfile(Error *error); |
mukesh agrawal | 3239932 | 2011-09-01 10:53:43 -0700 | [diff] [blame] | 86 | |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 87 | virtual DeviceInfo *device_info() { return &device_info_; } |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 88 | PropertyStore *mutable_store() { return &store_; } |
| 89 | virtual const PropertyStore &store() const { return store_; } |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 90 | |
Chris Masone | 877ff98 | 2011-09-21 16:18:24 -0700 | [diff] [blame] | 91 | std::vector<DeviceRefPtr>::iterator devices_begin() { |
| 92 | return devices_.begin(); |
| 93 | } |
| 94 | std::vector<DeviceRefPtr>::iterator devices_end() { return devices_.end(); } |
| 95 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 96 | private: |
Darin Petkov | 6f9eaa3 | 2011-08-09 15:26:44 -0700 | [diff] [blame] | 97 | friend class ManagerAdaptorInterface; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 98 | friend class ManagerTest; |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 99 | FRIEND_TEST(ManagerTest, PushPopProfile); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 100 | FRIEND_TEST(ManagerTest, SortServices); |
Darin Petkov | 6f9eaa3 | 2011-08-09 15:26:44 -0700 | [diff] [blame] | 101 | |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 102 | static const char kManagerErrorNoDevice[]; |
| 103 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 104 | std::string CalculateState(); |
| 105 | std::vector<std::string> AvailableTechnologies(); |
| 106 | std::vector<std::string> ConnectedTechnologies(); |
| 107 | std::string DefaultTechnology(); |
| 108 | std::vector<std::string> EnabledTechnologies(); |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 109 | std::vector<std::string> EnumerateDevices(); |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 110 | // TODO(cmasone): This should be implemented by filtering |services_|. |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 111 | std::vector<std::string> EnumerateWatchedServices(); |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 112 | std::string GetActiveProfileName(); |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 113 | |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 114 | void HelpRegisterDerivedString( |
| 115 | const std::string &name, |
| 116 | std::string(Manager::*get)(void), |
| 117 | void(Manager::*set)(const std::string&, Error *)); |
| 118 | void HelpRegisterDerivedStrings( |
| 119 | const std::string &name, |
| 120 | Strings(Manager::*get)(void), |
| 121 | void(Manager::*set)(const Strings&, Error *)); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 122 | |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 123 | void PopProfileInternal(); |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 124 | bool OrderServices(ServiceRefPtr a, ServiceRefPtr b); |
| 125 | void SortServices(); |
| 126 | |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 127 | const FilePath run_path_; |
| 128 | const FilePath storage_path_; |
| 129 | const std::string user_storage_format_; |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 130 | scoped_ptr<ManagerAdaptorInterface> adaptor_; |
| 131 | DeviceInfo device_info_; |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 132 | ModemInfo modem_info_; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 133 | bool running_; |
Paul Stewart | 5dc40aa | 2011-10-28 19:43:43 -0700 | [diff] [blame] | 134 | // Used to facilitate unit tests which can't use RPC. |
| 135 | bool connect_profiles_to_rpc_; |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 136 | std::vector<DeviceRefPtr> devices_; |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 137 | // 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] | 138 | std::vector<ServiceRefPtr> services_; |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 139 | std::vector<ProfileRefPtr> profiles_; |
| 140 | ProfileRefPtr ephemeral_profile_; |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 141 | ControlInterface *control_interface_; |
| 142 | GLib *glib_; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 143 | |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 144 | // The priority order of technologies |
| 145 | std::vector<Technology::Identifier> technology_order_; |
| 146 | |
Chris Masone | b925cc8 | 2011-06-22 15:39:57 -0700 | [diff] [blame] | 147 | // Properties to be get/set via PropertyStore calls. |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 148 | Properties props_; |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 149 | PropertyStore store_; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 150 | }; |
| 151 | |
| 152 | } // namespace shill |
| 153 | |
| 154 | #endif // SHILL_MANAGER_ |