| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2010, 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 SRC_SERVICE_MANAGER_IMPL_H_ |
| 6 #define SRC_SERVICE_MANAGER_IMPL_H_ |
| 7 |
| 8 #include <glib.h> |
| 9 |
| 10 #include <map> |
| 11 #include <string> |
| 12 #include <vector> |
| 13 |
| 14 #include <base/basictypes.h> // NOLINT |
| 15 #include <dbus-c++/dbus.h> // NOLINT |
| 16 |
| 17 #include "src/flimflam_manager_client_glue.h" |
| 18 #include "src/property_changed_handler.h" |
| 19 #include "src/service.h" |
| 20 #include "src/service_manager.h" |
| 21 |
| 22 namespace cashew { |
| 23 |
| 24 // monitors Flimflam and maintains a collection of cellular service objects |
| 25 class ServiceManagerImpl : public ServiceManager, |
| 26 public org::chromium::flimflam::Manager_proxy, |
| 27 public DBus::IntrospectableProxy, |
| 28 public DBus::ObjectProxy, |
| 29 public PropertyChangedDelegate { |
| 30 public: |
| 31 ServiceManagerImpl(DBus::Connection& connection, // NOLINT |
| 32 GMainLoop * const main_loop); |
| 33 virtual ~ServiceManagerImpl(); |
| 34 |
| 35 // ServiceManager methods |
| 36 virtual const Service* GetService(const std::string& service_path) const; |
| 37 virtual void SetCashewServer(CashewServer *cashew_server); |
| 38 virtual Service::Type GetDefaultTechnology() const; |
| 39 virtual ConnectivityState GetConnectivityState() const; |
| 40 static bool IsOfflineConnectivityState(ConnectivityState state); |
| 41 static bool IsOnlineConnectivityState(ConnectivityState state); |
| 42 |
| 43 // Flimflam Manager D-Bus Proxy methods |
| 44 |
| 45 // receive incoming PropertyChanged D-Bus signal from Flimflam and |
| 46 // schedule deferred processing |
| 47 virtual void PropertyChanged(const std::string& property_name, |
| 48 const DBus::Variant& new_value); |
| 49 |
| 50 // receive incoming StateChanged D-Bus signal from Flimflam, convert to a |
| 51 // PropertyChanged signal, and schedule deferred processing |
| 52 virtual void StateChanged(const std::string& new_state_string); |
| 53 |
| 54 // PropertyChangedDelegate methods |
| 55 |
| 56 // Perform deferred processing for an incoming PropertyChanged D-Bus signal |
| 57 // from Flimflam |
| 58 virtual void OnPropertyChanged(const PropertyChangedHandler *handler, |
| 59 const std::string& property_name, |
| 60 const DBus::Variant& new_value); |
| 61 |
| 62 // Service methods |
| 63 |
| 64 // a child Service wants us to emit an update about its data plans |
| 65 virtual void EmitDataPlansUpdate(const Service& service); |
| 66 |
| 67 private: |
| 68 // D-Bus connection owned by our creator |
| 69 // shared with Service objs that we create |
| 70 DBus::Connection& connection_; |
| 71 |
| 72 // glib main loop |
| 73 GMainLoop * const main_loop_; |
| 74 |
| 75 // collection of Service objs representing cellular services |
| 76 ServiceMap services_; |
| 77 |
| 78 // Cashew server implementing our front-end interface |
| 79 CashewServer *cashew_server_; |
| 80 |
| 81 // default technology most recently reported by Flimflam |
| 82 Service::Type default_technology_; |
| 83 |
| 84 // the cellular service, if any, that we think is the default service |
| 85 // can be NULL if we don't know the default service or a non-cellular |
| 86 // service is the default |
| 87 Service *default_cellular_service_; |
| 88 |
| 89 // global connectivity state most recently reported by Flimflam |
| 90 ConnectivityState connectivity_state_; |
| 91 |
| 92 // GetProperties timer glib source id |
| 93 // 0 means no source |
| 94 guint get_properties_source_id_; |
| 95 |
| 96 // are we in the process of retrying our GetProperties call? |
| 97 // this flag exists to distinguish between our initial g_idle_add call |
| 98 // and our subsequent timer calls |
| 99 bool retrying_get_properties_; |
| 100 |
| 101 // Handler for deferred processing of D-Bus PropertyChanged signals. |
| 102 // |
| 103 // We construct and enqueue PropertyChangedSignal objects as D-Bus signals |
| 104 // arrive, and the handler calls our OnPropertyChanged method (part of our |
| 105 // PropertyChangedDelegate interface) later from the glib main loop. |
| 106 // |
| 107 // This is done to avoid a libdbus-c++ deadlock that can occur when dbus |
| 108 // messages are sent from within a dbus callback. |
| 109 PropertyChangedHandler property_changed_handler_; |
| 110 |
| 111 // delete a collection of services |
| 112 void DeleteServices(ServiceMap *service_map); |
| 113 |
| 114 // glib integration: static wrapper for GetFlimflamProperties |
| 115 // takes object ptr as data and invokes object->GetFlimflamProperties() |
| 116 static gboolean StaticGetFlimflamPropertiesCallback(gpointer data); |
| 117 |
| 118 // get interesting properties from Flimflam such as Services and |
| 119 // DefaultTechnology |
| 120 // returns true on success and false on failure |
| 121 bool GetFlimflamProperties(); |
| 122 |
| 123 // we've received updated State info from Flimflam |
| 124 void OnStateUpdate(const std::string& new_state_string); |
| 125 |
| 126 // we've received updated DefaultTechnology info from Flimflam |
| 127 void OnDefaultTechnologyUpdate(const std::string& default_technology); |
| 128 |
| 129 // we've received updated Services info from Flimflam |
| 130 void OnServicesUpdate(const ServicePathList& paths); |
| 131 |
| 132 // Flimflam has started advertising a new service |
| 133 void OnNewService(const DBus::Path& path); |
| 134 |
| 135 // we've received updated default service info from Flimflam |
| 136 // NULL |path| means that there is no default service |
| 137 void OnDefaultServiceUpdate(const DBus::Path *path); |
| 138 |
| 139 // if |default_cellular_service_| points to a service, tell it |
| 140 // that it is no longer the default service and clear our ptr |
| 141 void ClearDefaultCellularService(); |
| 142 |
| 143 // tell |service| that it is now the default service and set our |
| 144 // |default_cellular_service_| ptr to point to it. |
| 145 // if there is already a default service, first clear it. |
| 146 // NULL |service| is ok and is equivalent to ClearDefaultCellularService |
| 147 // no-op if |service| == |default_cellular_service_| |
| 148 void SetDefaultCellularService(Service *service); |
| 149 |
| 150 // convert connectivity state string to ConnectivityState enum value |
| 151 static ConnectivityState ConnectivityStateFromString( |
| 152 const std::string& state); |
| 153 |
| 154 // Flimflam has told us that it has come online |
| 155 void OnFlimflamOnline(); |
| 156 |
| 157 // Flimflam has told us that it has gone offline |
| 158 void OnFlimflamOffline(); |
| 159 |
| 160 DISALLOW_COPY_AND_ASSIGN(ServiceManagerImpl); |
| 161 }; |
| 162 |
| 163 } // namespace cashew |
| 164 |
| 165 #endif // SRC_SERVICE_MANAGER_IMPL_H_ |
| OLD | NEW |