blob: ca18448e23609698adb16494fae2c3d4c0e4d0da [file] [log] [blame]
Darin Petkovb72b62e2012-05-15 16:55:36 +02001// 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 Petkov0fcd3462012-05-17 11:25:11 +02008#include <map>
Darin Petkovb72b62e2012-05-15 16:55:36 +02009
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 Petkovb501ad22012-07-03 12:50:52 +020015#include "shill/dbus_manager.h"
Darin Petkovb72b62e2012-05-15 16:55:36 +020016#include "shill/refptr_types.h"
Darin Petkovc63dcf02012-05-24 11:51:43 +020017#include "shill/wimax_network_proxy_interface.h"
Darin Petkovb72b62e2012-05-15 16:55:36 +020018
19namespace shill {
20
21class ControlInterface;
Darin Petkovb72b62e2012-05-15 16:55:36 +020022class EventDispatcher;
Darin Petkovd1cd7972012-05-22 15:26:15 +020023class KeyValueStore;
Darin Petkovb72b62e2012-05-15 16:55:36 +020024class Manager;
25class Metrics;
26class ProxyFactory;
27class WiMaxManagerProxyInterface;
28
29class WiMaxProvider {
30 public:
31 WiMaxProvider(ControlInterface *control,
32 EventDispatcher *dispatcher,
33 Metrics *metrics,
34 Manager *manager);
35 virtual ~WiMaxProvider();
36
Darin Petkovc63dcf02012-05-24 11:51:43 +020037 void Start();
38 void Stop();
Darin Petkovb72b62e2012-05-15 16:55:36 +020039
Darin Petkovc63dcf02012-05-24 11:51:43 +020040 // Signaled by DeviceInfo when a new WiMAX device becomes available.
Darin Petkove4b27022012-05-16 13:28:50 +020041 virtual void OnDeviceInfoAvailable(const std::string &link_name);
42
Darin Petkovc63dcf02012-05-24 11:51:43 +020043 // Signaled by a WiMAX device when its set of live networks changes.
44 virtual void OnNetworksChanged();
45
Darin Petkovc1e52732012-05-25 15:23:45 +020046 // 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 Petkovc63dcf02012-05-24 11:51:43 +020050 // Creates if necessary and configures a WiMAX service with the given
51 // parameters. Used by Manager::GetService.
Darin Petkovd1cd7972012-05-22 15:26:15 +020052 WiMaxServiceRefPtr GetService(const KeyValueStore &args, Error *error);
53
Darin Petkovc63dcf02012-05-24 11:51:43 +020054 // 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 Petkov6b9b2e12012-07-10 15:51:42 +020059 virtual WiMaxRefPtr SelectCarrier(const WiMaxServiceConstRefPtr &service);
Darin Petkovc63dcf02012-05-24 11:51:43 +020060
Darin Petkovb72b62e2012-05-15 16:55:36 +020061 private:
62 friend class WiMaxProviderTest;
Darin Petkovb501ad22012-07-03 12:50:52 +020063 FRIEND_TEST(WiMaxProviderTest, ConnectDisconnectWiMaxManager);
Darin Petkove4b27022012-05-16 13:28:50 +020064 FRIEND_TEST(WiMaxProviderTest, CreateDevice);
Darin Petkovc63dcf02012-05-24 11:51:43 +020065 FRIEND_TEST(WiMaxProviderTest, CreateServicesFromProfile);
66 FRIEND_TEST(WiMaxProviderTest, DestroyAllServices);
Darin Petkove4b27022012-05-16 13:28:50 +020067 FRIEND_TEST(WiMaxProviderTest, DestroyDeadDevices);
Darin Petkovc63dcf02012-05-24 11:51:43 +020068 FRIEND_TEST(WiMaxProviderTest, FindService);
Darin Petkove4b27022012-05-16 13:28:50 +020069 FRIEND_TEST(WiMaxProviderTest, GetLinkName);
Darin Petkovc63dcf02012-05-24 11:51:43 +020070 FRIEND_TEST(WiMaxProviderTest, GetUniqueService);
Darin Petkove4b27022012-05-16 13:28:50 +020071 FRIEND_TEST(WiMaxProviderTest, OnDeviceInfoAvailable);
Darin Petkov9893d9c2012-05-17 15:27:31 -070072 FRIEND_TEST(WiMaxProviderTest, OnDevicesChanged);
Darin Petkovc63dcf02012-05-24 11:51:43 +020073 FRIEND_TEST(WiMaxProviderTest, OnNetworksChanged);
Darin Petkovc1e52732012-05-25 15:23:45 +020074 FRIEND_TEST(WiMaxProviderTest, OnServiceUnloaded);
Darin Petkovfc00fd42012-05-30 11:30:06 +020075 FRIEND_TEST(WiMaxProviderTest, RetrieveNetworkInfo);
Darin Petkovc63dcf02012-05-24 11:51:43 +020076 FRIEND_TEST(WiMaxProviderTest, SelectCarrier);
Darin Petkovfc00fd42012-05-30 11:30:06 +020077 FRIEND_TEST(WiMaxProviderTest, StartLiveServices);
Darin Petkovb72b62e2012-05-15 16:55:36 +020078 FRIEND_TEST(WiMaxProviderTest, StartStop);
Darin Petkovc63dcf02012-05-24 11:51:43 +020079 FRIEND_TEST(WiMaxProviderTest, StopDeadServices);
Darin Petkovb72b62e2012-05-15 16:55:36 +020080
Darin Petkovfc00fd42012-05-30 11:30:06 +020081 struct NetworkInfo {
82 WiMaxNetworkId id;
83 std::string name;
84 };
85
Darin Petkovb501ad22012-07-03 12:50:52 +020086 void ConnectToWiMaxManager();
87 void DisconnectFromWiMaxManager();
88 void OnWiMaxManagerAppear(const std::string &owner);
89
Darin Petkov9893d9c2012-05-17 15:27:31 -070090 void OnDevicesChanged(const RpcIdentifiers &devices);
Darin Petkovb72b62e2012-05-15 16:55:36 +020091
Darin Petkove4b27022012-05-16 13:28:50 +020092 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 Petkovfc00fd42012-05-30 11:30:06 +020097 // 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 Petkovc63dcf02012-05-24 11:51:43 +0200101 // 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 Petkovc63dcf02012-05-24 11:51:43 +0200110 // 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 Petkovc63dcf02012-05-24 11:51:43 +0200115 // 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 Petkovb72b62e2012-05-15 16:55:36 +0200122 ControlInterface *control_;
123 EventDispatcher *dispatcher_;
124 Metrics *metrics_;
125 Manager *manager_;
126
Darin Petkovb501ad22012-07-03 12:50:52 +0200127 // 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 Petkovb72b62e2012-05-15 16:55:36 +0200132
Darin Petkovc1e52732012-05-25 15:23:45 +0200133 // Key is the interface link name.
134 std::map<std::string, RpcIdentifier> pending_devices_;
Darin Petkov0fcd3462012-05-17 11:25:11 +0200135 std::map<std::string, WiMaxRefPtr> devices_;
Darin Petkovc1e52732012-05-25 15:23:45 +0200136 // Key is service's storage identifier.
137 std::map<std::string, WiMaxServiceRefPtr> services_;
Darin Petkovfc00fd42012-05-30 11:30:06 +0200138 std::map<RpcIdentifier, NetworkInfo> networks_;
Darin Petkove4b27022012-05-16 13:28:50 +0200139
Darin Petkovb72b62e2012-05-15 16:55:36 +0200140 ProxyFactory *proxy_factory_;
141
142 DISALLOW_COPY_AND_ASSIGN(WiMaxProvider);
143};
144
145} // namespace shill
146
147#endif // SHILL_WIMAX_PROVIDER_H_