blob: 6bddeb5bd57023b569e94562cad0a94ecff7ff27 [file] [log] [blame]
Paul Stewart75897df2011-04-27 09:05:53 -07001// 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 Masone9be4a9d2011-05-16 15:44:09 -07008#include <string>
Paul Stewart75897df2011-04-27 09:05:53 -07009#include <vector>
Chris Masone487b8bf2011-05-13 16:27:57 -070010
Paul Stewarte6132022011-08-16 09:11:02 -070011#include <base/file_path.h>
Chris Masone9be4a9d2011-05-16 15:44:09 -070012#include <base/memory/ref_counted.h>
Chris Masone487b8bf2011-05-13 16:27:57 -070013#include <base/memory/scoped_ptr.h>
Chris Masone88cbd5f2011-07-03 14:30:04 -070014#include <chromeos/dbus/service_constants.h>
Paul Stewart75897df2011-04-27 09:05:53 -070015
Paul Stewart75897df2011-04-27 09:05:53 -070016#include "shill/device.h"
Paul Stewart0af98bf2011-05-10 17:38:08 -070017#include "shill/device_info.h"
Darin Petkov887f2982011-07-14 16:10:17 -070018#include "shill/modem_info.h"
Chris Masoneb925cc82011-06-22 15:39:57 -070019#include "shill/property_store.h"
Chris Masone9be4a9d2011-05-16 15:44:09 -070020#include "shill/service.h"
21#include "shill/shill_event.h"
Paul Stewart75897df2011-04-27 09:05:53 -070022
23namespace shill {
24
Chris Masoned0ceb8c2011-06-02 10:05:39 -070025class ControlInterface;
Chris Masone8fe2c7e2011-06-09 15:51:19 -070026class Error;
Chris Masoned0ceb8c2011-06-02 10:05:39 -070027class EventDispatcher;
Chris Masone8fe2c7e2011-06-09 15:51:19 -070028class ManagerAdaptorInterface;
Darin Petkov887f2982011-07-14 16:10:17 -070029class GLib;
Chris Masoned0ceb8c2011-06-02 10:05:39 -070030
Chris Masone27c4aa52011-07-02 13:10:14 -070031class Manager {
Paul Stewart75897df2011-04-27 09:05:53 -070032 public:
Chris Masone88cbd5f2011-07-03 14:30:04 -070033 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 Masone9be4a9d2011-05-16 15:44:09 -070042 Manager(ControlInterface *control_interface,
Darin Petkov887f2982011-07-14 16:10:17 -070043 EventDispatcher *dispatcher,
Chris Masone2ae797d2011-08-23 20:41:00 -070044 GLib *glib,
45 const std::string &run_directory,
46 const std::string &storage_directory,
47 const std::string &user_storage_format);
Chris Masone3bd3c8c2011-06-13 08:20:26 -070048 virtual ~Manager();
mukesh agrawal8f317b62011-07-15 11:53:23 -070049
50 void AddDeviceToBlackList(const std::string &device_name);
Paul Stewart75897df2011-04-27 09:05:53 -070051 void Start();
52 void Stop();
53
Chris Masone7aa5f902011-07-11 11:13:35 -070054 const ProfileRefPtr &ActiveProfile();
Chris Masone6791a432011-07-12 13:23:19 -070055 bool MoveToActiveProfile(const ProfileRefPtr &from,
56 const ServiceRefPtr &to_move);
Chris Masone7aa5f902011-07-11 11:13:35 -070057
Chris Masone2b105542011-06-22 10:58:09 -070058 void RegisterDevice(const DeviceRefPtr &to_manage);
mukesh agrawal5029c6c2011-08-25 11:12:40 -070059 void DeregisterDevice(const DeviceRefPtr &to_forget);
Chris Masone9be4a9d2011-05-16 15:44:09 -070060
mukesh agrawal32399322011-09-01 10:53:43 -070061 virtual void RegisterService(const ServiceRefPtr &to_manage);
mukesh agrawal5c4dd0b2011-09-14 13:53:14 -070062 virtual void DeregisterService(const ServiceConstRefPtr &to_forget);
Paul Stewart03dba0b2011-08-22 16:32:45 -070063 virtual void UpdateService(const ServiceConstRefPtr &to_update);
Chris Masone9be4a9d2011-05-16 15:44:09 -070064
65 void FilterByTechnology(Device::Technology tech,
Chris Masonec1e50412011-06-07 13:04:53 -070066 std::vector<DeviceRefPtr> *found);
Chris Masone9be4a9d2011-05-16 15:44:09 -070067
Chris Masonee0dea762011-06-09 09:06:03 -070068 ServiceRefPtr FindService(const std::string& name);
Chris Masone6791a432011-07-12 13:23:19 -070069 std::vector<std::string> EnumerateAvailableServices();
Chris Masone9be4a9d2011-05-16 15:44:09 -070070
mukesh agrawal32399322011-09-01 10:53:43 -070071 // called via RPC (e.g., from ManagerDBusAdaptor)
72 void RequestScan(const std::string &technology, Error *error);
73
Chris Masone626719f2011-08-18 16:58:48 -070074 virtual DeviceInfo *device_info() { return &device_info_; }
mukesh agrawalde29fa82011-09-16 16:16:36 -070075 PropertyStore *mutable_store() { return &store_; }
76 virtual const PropertyStore &store() const { return store_; }
Chris Masoneb925cc82011-06-22 15:39:57 -070077
Chris Masone877ff982011-09-21 16:18:24 -070078 std::vector<DeviceRefPtr>::iterator devices_begin() {
79 return devices_.begin();
80 }
81 std::vector<DeviceRefPtr>::iterator devices_end() { return devices_.end(); }
82
Paul Stewart75897df2011-04-27 09:05:53 -070083 private:
Darin Petkov6f9eaa32011-08-09 15:26:44 -070084 friend class ManagerAdaptorInterface;
85
Chris Masoneb925cc82011-06-22 15:39:57 -070086 std::string CalculateState();
87 std::vector<std::string> AvailableTechnologies();
88 std::vector<std::string> ConnectedTechnologies();
89 std::string DefaultTechnology();
90 std::vector<std::string> EnabledTechnologies();
Chris Masone3c3f6a12011-07-01 10:01:41 -070091 std::vector<std::string> EnumerateDevices();
Chris Masone6791a432011-07-12 13:23:19 -070092 // TODO(cmasone): This should be implemented by filtering |services_|.
Chris Masone3c3f6a12011-07-01 10:01:41 -070093 std::vector<std::string> EnumerateWatchedServices();
Chris Masone7aa5f902011-07-11 11:13:35 -070094 std::string GetActiveProfileName();
Chris Masoneb925cc82011-06-22 15:39:57 -070095
Chris Masone27c4aa52011-07-02 13:10:14 -070096 void HelpRegisterDerivedString(const std::string &name,
Chris Masone7aa5f902011-07-11 11:13:35 -070097 std::string(Manager::*get)(void),
98 bool(Manager::*set)(const std::string&));
Chris Masone27c4aa52011-07-02 13:10:14 -070099 void HelpRegisterDerivedStrings(const std::string &name,
Chris Masone7aa5f902011-07-11 11:13:35 -0700100 Strings(Manager::*get)(void),
101 bool(Manager::*set)(const Strings&));
Chris Masone27c4aa52011-07-02 13:10:14 -0700102
Chris Masone2ae797d2011-08-23 20:41:00 -0700103 const FilePath run_path_;
104 const FilePath storage_path_;
105 const std::string user_storage_format_;
Paul Stewart0af98bf2011-05-10 17:38:08 -0700106 scoped_ptr<ManagerAdaptorInterface> adaptor_;
107 DeviceInfo device_info_;
Darin Petkov887f2982011-07-14 16:10:17 -0700108 ModemInfo modem_info_;
Paul Stewart75897df2011-04-27 09:05:53 -0700109 bool running_;
Chris Masonec1e50412011-06-07 13:04:53 -0700110 std::vector<DeviceRefPtr> devices_;
Chris Masone6791a432011-07-12 13:23:19 -0700111 // We store Services in a vector, because we want to keep them sorted.
Chris Masonec1e50412011-06-07 13:04:53 -0700112 std::vector<ServiceRefPtr> services_;
Chris Masone7aa5f902011-07-11 11:13:35 -0700113 std::vector<ProfileRefPtr> profiles_;
114 ProfileRefPtr ephemeral_profile_;
Chris Masone2ae797d2011-08-23 20:41:00 -0700115 ControlInterface *control_interface_;
116 GLib *glib_;
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700117
Chris Masoneb925cc82011-06-22 15:39:57 -0700118 // Properties to be get/set via PropertyStore calls.
Chris Masone88cbd5f2011-07-03 14:30:04 -0700119 Properties props_;
Chris Masone27c4aa52011-07-02 13:10:14 -0700120 PropertyStore store_;
Paul Stewart75897df2011-04-27 09:05:53 -0700121};
122
123} // namespace shill
124
125#endif // SHILL_MANAGER_