Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 1 | // Copyright (c) 2012 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_WIMAX_PROVIDER_H_ |
| 6 | #define SHILL_WIMAX_PROVIDER_H_ |
| 7 | |
Darin Petkov | 0fcd346 | 2012-05-17 11:25:11 +0200 | [diff] [blame] | 8 | #include <map> |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 9 | |
| 10 | #include <base/basictypes.h> |
| 11 | #include <base/memory/scoped_ptr.h> |
| 12 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 13 | |
| 14 | #include "shill/accessor_interface.h" |
Darin Petkov | b501ad2 | 2012-07-03 12:50:52 +0200 | [diff] [blame] | 15 | #include "shill/dbus_manager.h" |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 16 | #include "shill/refptr_types.h" |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 17 | #include "shill/wimax_network_proxy_interface.h" |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 18 | |
| 19 | namespace shill { |
| 20 | |
| 21 | class ControlInterface; |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 22 | class EventDispatcher; |
Darin Petkov | d1cd797 | 2012-05-22 15:26:15 +0200 | [diff] [blame] | 23 | class KeyValueStore; |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 24 | class Manager; |
| 25 | class Metrics; |
| 26 | class ProxyFactory; |
| 27 | class WiMaxManagerProxyInterface; |
| 28 | |
| 29 | class WiMaxProvider { |
| 30 | public: |
| 31 | WiMaxProvider(ControlInterface *control, |
| 32 | EventDispatcher *dispatcher, |
| 33 | Metrics *metrics, |
| 34 | Manager *manager); |
| 35 | virtual ~WiMaxProvider(); |
| 36 | |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 37 | void Start(); |
| 38 | void Stop(); |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 39 | |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 40 | // Signaled by DeviceInfo when a new WiMAX device becomes available. |
Darin Petkov | e4b2702 | 2012-05-16 13:28:50 +0200 | [diff] [blame] | 41 | virtual void OnDeviceInfoAvailable(const std::string &link_name); |
| 42 | |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 43 | // Signaled by a WiMAX device when its set of live networks changes. |
| 44 | virtual void OnNetworksChanged(); |
| 45 | |
Darin Petkov | c1e5273 | 2012-05-25 15:23:45 +0200 | [diff] [blame] | 46 | // Signaled by |service| when it's been unloaded by Manager. Returns true if |
| 47 | // this provider has released ownership of the service, and false otherwise. |
| 48 | virtual bool OnServiceUnloaded(const WiMaxServiceRefPtr &service); |
| 49 | |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 50 | // Creates if necessary and configures a WiMAX service with the given |
| 51 | // parameters. Used by Manager::GetService. |
Darin Petkov | d1cd797 | 2012-05-22 15:26:15 +0200 | [diff] [blame] | 52 | WiMaxServiceRefPtr GetService(const KeyValueStore &args, Error *error); |
| 53 | |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 54 | // Creates and registers all WiMAX services available in |profile|. Used by |
| 55 | // Manager::PushProfile. |
| 56 | void CreateServicesFromProfile(const ProfileRefPtr &profile); |
| 57 | |
| 58 | // Selects and returns a WiMAX device to connect |service| through. |
Darin Petkov | 6b9b2e1 | 2012-07-10 15:51:42 +0200 | [diff] [blame] | 59 | virtual WiMaxRefPtr SelectCarrier(const WiMaxServiceConstRefPtr &service); |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 60 | |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 61 | private: |
| 62 | friend class WiMaxProviderTest; |
Darin Petkov | b501ad2 | 2012-07-03 12:50:52 +0200 | [diff] [blame] | 63 | FRIEND_TEST(WiMaxProviderTest, ConnectDisconnectWiMaxManager); |
Darin Petkov | e4b2702 | 2012-05-16 13:28:50 +0200 | [diff] [blame] | 64 | FRIEND_TEST(WiMaxProviderTest, CreateDevice); |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 65 | FRIEND_TEST(WiMaxProviderTest, CreateServicesFromProfile); |
| 66 | FRIEND_TEST(WiMaxProviderTest, DestroyAllServices); |
Darin Petkov | e4b2702 | 2012-05-16 13:28:50 +0200 | [diff] [blame] | 67 | FRIEND_TEST(WiMaxProviderTest, DestroyDeadDevices); |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 68 | FRIEND_TEST(WiMaxProviderTest, FindService); |
Darin Petkov | e4b2702 | 2012-05-16 13:28:50 +0200 | [diff] [blame] | 69 | FRIEND_TEST(WiMaxProviderTest, GetLinkName); |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 70 | FRIEND_TEST(WiMaxProviderTest, GetUniqueService); |
Darin Petkov | e4b2702 | 2012-05-16 13:28:50 +0200 | [diff] [blame] | 71 | FRIEND_TEST(WiMaxProviderTest, OnDeviceInfoAvailable); |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 72 | FRIEND_TEST(WiMaxProviderTest, OnDevicesChanged); |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 73 | FRIEND_TEST(WiMaxProviderTest, OnNetworksChanged); |
Darin Petkov | c1e5273 | 2012-05-25 15:23:45 +0200 | [diff] [blame] | 74 | FRIEND_TEST(WiMaxProviderTest, OnServiceUnloaded); |
Darin Petkov | fc00fd4 | 2012-05-30 11:30:06 +0200 | [diff] [blame] | 75 | FRIEND_TEST(WiMaxProviderTest, RetrieveNetworkInfo); |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 76 | FRIEND_TEST(WiMaxProviderTest, SelectCarrier); |
Darin Petkov | fc00fd4 | 2012-05-30 11:30:06 +0200 | [diff] [blame] | 77 | FRIEND_TEST(WiMaxProviderTest, StartLiveServices); |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 78 | FRIEND_TEST(WiMaxProviderTest, StartStop); |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 79 | FRIEND_TEST(WiMaxProviderTest, StopDeadServices); |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 80 | |
Darin Petkov | fc00fd4 | 2012-05-30 11:30:06 +0200 | [diff] [blame] | 81 | struct NetworkInfo { |
| 82 | WiMaxNetworkId id; |
| 83 | std::string name; |
| 84 | }; |
| 85 | |
Darin Petkov | b501ad2 | 2012-07-03 12:50:52 +0200 | [diff] [blame] | 86 | void ConnectToWiMaxManager(); |
| 87 | void DisconnectFromWiMaxManager(); |
| 88 | void OnWiMaxManagerAppear(const std::string &owner); |
| 89 | |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 90 | void OnDevicesChanged(const RpcIdentifiers &devices); |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 91 | |
Darin Petkov | e4b2702 | 2012-05-16 13:28:50 +0200 | [diff] [blame] | 92 | void CreateDevice(const std::string &link_name, const RpcIdentifier &path); |
| 93 | void DestroyDeadDevices(const RpcIdentifiers &live_devices); |
| 94 | |
| 95 | std::string GetLinkName(const RpcIdentifier &path); |
| 96 | |
Darin Petkov | fc00fd4 | 2012-05-30 11:30:06 +0200 | [diff] [blame] | 97 | // Retrieves network info for a network at RPC |path| into |networks_| if it's |
| 98 | // not already available. |
| 99 | void RetrieveNetworkInfo(const RpcIdentifier &path); |
| 100 | |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 101 | // Finds and returns the service identified by |storage_id|. Returns NULL if |
| 102 | // the service is not found. |
| 103 | WiMaxServiceRefPtr FindService(const std::string &storage_id); |
| 104 | |
| 105 | // Finds or creates a service with the given parameters. The parameters |
| 106 | // uniquely identify a service so no duplicate services will be created. |
| 107 | WiMaxServiceRefPtr GetUniqueService(const WiMaxNetworkId &id, |
| 108 | const std::string &name); |
| 109 | |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 110 | // Starts all services with network ids in the current set of live |
| 111 | // networks. This method also creates, registers and starts the default |
| 112 | // service for each live network. |
| 113 | void StartLiveServices(); |
| 114 | |
Darin Petkov | c63dcf0 | 2012-05-24 11:51:43 +0200 | [diff] [blame] | 115 | // Stops all services with network ids that are not in the current set of live |
| 116 | // networks. |
| 117 | void StopDeadServices(); |
| 118 | |
| 119 | // Stops, deregisters and destroys all services. |
| 120 | void DestroyAllServices(); |
| 121 | |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 122 | ControlInterface *control_; |
| 123 | EventDispatcher *dispatcher_; |
| 124 | Metrics *metrics_; |
| 125 | Manager *manager_; |
| 126 | |
Darin Petkov | b501ad2 | 2012-07-03 12:50:52 +0200 | [diff] [blame] | 127 | // Monitor WiMaxManager DBus name ownership to detect daemon presence. |
| 128 | DBusManager::CancelableAppearedCallback on_wimax_manager_appear_; |
| 129 | DBusManager::CancelableVanishedCallback on_wimax_manager_vanish_; |
| 130 | |
| 131 | scoped_ptr<WiMaxManagerProxyInterface> wimax_manager_proxy_; |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 132 | |
Darin Petkov | c1e5273 | 2012-05-25 15:23:45 +0200 | [diff] [blame] | 133 | // Key is the interface link name. |
| 134 | std::map<std::string, RpcIdentifier> pending_devices_; |
Darin Petkov | 0fcd346 | 2012-05-17 11:25:11 +0200 | [diff] [blame] | 135 | std::map<std::string, WiMaxRefPtr> devices_; |
Darin Petkov | c1e5273 | 2012-05-25 15:23:45 +0200 | [diff] [blame] | 136 | // Key is service's storage identifier. |
| 137 | std::map<std::string, WiMaxServiceRefPtr> services_; |
Darin Petkov | fc00fd4 | 2012-05-30 11:30:06 +0200 | [diff] [blame] | 138 | std::map<RpcIdentifier, NetworkInfo> networks_; |
Darin Petkov | e4b2702 | 2012-05-16 13:28:50 +0200 | [diff] [blame] | 139 | |
Darin Petkov | b72b62e | 2012-05-15 16:55:36 +0200 | [diff] [blame] | 140 | ProxyFactory *proxy_factory_; |
| 141 | |
| 142 | DISALLOW_COPY_AND_ASSIGN(WiMaxProvider); |
| 143 | }; |
| 144 | |
| 145 | } // namespace shill |
| 146 | |
| 147 | #endif // SHILL_WIMAX_PROVIDER_H_ |