| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef SRC_SERVICE_MANAGER_H_ | 5 #ifndef SRC_SERVICE_MANAGER_H_ |
| 6 #define SRC_SERVICE_MANAGER_H_ | 6 #define SRC_SERVICE_MANAGER_H_ |
| 7 | 7 |
| 8 #include <glib.h> |
| 9 |
| 8 #include <map> | 10 #include <map> |
| 9 #include <string> | 11 #include <string> |
| 10 #include <vector> | 12 #include <vector> |
| 11 | 13 |
| 12 #include <base/basictypes.h> // NOLINT | 14 #include <base/basictypes.h> // NOLINT |
| 13 #include <dbus-c++/dbus.h> // NOLINT | 15 #include <dbus-c++/dbus.h> // NOLINT |
| 14 | 16 |
| 15 #include "src/flimflam_manager_client_glue.h" | 17 #include "src/flimflam_manager_client_glue.h" |
| 18 #include "src/property_changed_handler.h" |
| 16 #include "src/service.h" | 19 #include "src/service.h" |
| 17 | 20 |
| 18 namespace cashew { | 21 namespace cashew { |
| 19 | 22 |
| 20 class CashewServer; | 23 class CashewServer; |
| 21 | 24 |
| 22 // map of service path names to Service objects | 25 // map of service path names to Service objects |
| 23 typedef std::map<std::string, Service*> ServiceMap; | 26 typedef std::map<std::string, Service*> ServiceMap; |
| 24 | 27 |
| 25 // vector of DBus::Path objects (strings) representing service path names | 28 // vector of DBus::Path objects (strings) representing service path names |
| 26 typedef std::vector<DBus::Path> ServicePathList; | 29 typedef std::vector<DBus::Path> ServicePathList; |
| 27 | 30 |
| 28 // monitors Flimflam and maintains a collection of cellular service objects | 31 // monitors Flimflam and maintains a collection of cellular service objects |
| 29 class ServiceManager : public org::chromium::flimflam::Manager_proxy, | 32 class ServiceManager : public org::chromium::flimflam::Manager_proxy, |
| 30 public DBus::IntrospectableProxy, | 33 public DBus::IntrospectableProxy, |
| 31 public DBus::ObjectProxy { | 34 public DBus::ObjectProxy, |
| 35 public PropertyChangedDelegate { |
| 32 public: | 36 public: |
| 33 explicit ServiceManager(DBus::Connection& connection); // NOLINT | 37 ServiceManager(DBus::Connection& connection, // NOLINT |
| 38 GMainLoop * const main_loop); |
| 34 virtual ~ServiceManager(); | 39 virtual ~ServiceManager(); |
| 35 | 40 |
| 36 // look up a service by its path name | 41 // look up a service by its path name |
| 37 // returns NULL if service is not found | 42 // returns NULL if service is not found |
| 38 virtual const Service* GetService(const std::string& service_path) const; | 43 virtual const Service* GetService(const std::string& service_path) const; |
| 39 | 44 |
| 40 // set Cashew server | 45 // set Cashew server |
| 41 // we'll talk to it when we want to emit updates to the world on behalf of | 46 // we'll talk to it when we want to emit updates to the world on behalf of |
| 42 // our child Services. | 47 // our child Services. |
| 43 // it's ok to clear this by setting it to NULL, in which case our updates | 48 // it's ok to clear this by setting it to NULL, in which case our updates |
| (...skipping 15 matching lines...) Expand all Loading... |
| 59 virtual ConnectivityState GetConnectivityState() const; | 64 virtual ConnectivityState GetConnectivityState() const; |
| 60 | 65 |
| 61 // does |state| represent an offline state | 66 // does |state| represent an offline state |
| 62 static bool IsOfflineConnectivityState(ConnectivityState state); | 67 static bool IsOfflineConnectivityState(ConnectivityState state); |
| 63 | 68 |
| 64 // does |state| represent an online state | 69 // does |state| represent an online state |
| 65 static bool IsOnlineConnectivityState(ConnectivityState state); | 70 static bool IsOnlineConnectivityState(ConnectivityState state); |
| 66 | 71 |
| 67 // Flimflam Manager D-Bus Proxy methods | 72 // Flimflam Manager D-Bus Proxy methods |
| 68 | 73 |
| 69 // receive incoming PropertyChanged D-Bus signal from Flimflam | 74 // receive incoming PropertyChanged D-Bus signal from Flimflam and |
| 75 // schedule deferred processing |
| 70 virtual void PropertyChanged(const std::string& property_name, | 76 virtual void PropertyChanged(const std::string& property_name, |
| 71 const DBus::Variant& new_value); | 77 const DBus::Variant& new_value); |
| 72 | 78 |
| 73 // receive incoming StateChanged D-Bus signal from Flimflam | 79 // receive incoming StateChanged D-Bus signal from Flimflam, convert to a |
| 80 // PropertyChanged signal, and schedule deferred processing |
| 74 virtual void StateChanged(const std::string& new_state_string); | 81 virtual void StateChanged(const std::string& new_state_string); |
| 75 | 82 |
| 83 // PropertyChangedDelegate methods |
| 84 |
| 85 // Perform deferred processing for an incoming PropertyChanged D-Bus signal |
| 86 // from Flimflam |
| 87 virtual void OnPropertyChanged(const PropertyChangedHandler *handler, |
| 88 const std::string& property_name, |
| 89 const DBus::Variant& new_value); |
| 90 |
| 76 // Service methods | 91 // Service methods |
| 77 | 92 |
| 78 // a child Service wants us to emit an update about its data plans | 93 // a child Service wants us to emit an update about its data plans |
| 79 virtual void EmitDataPlansUpdate(const Service& service); | 94 virtual void EmitDataPlansUpdate(const Service& service); |
| 80 | 95 |
| 81 // glib integration interface | 96 // glib integration interface |
| 82 | 97 |
| 83 // get idle/timer source id | 98 // get idle/timer source id |
| 84 virtual guint GetGetPropertiesSourceId() const; | 99 virtual guint GetGetPropertiesSourceId() const; |
| 85 | 100 |
| 86 // set idle/timer source id | 101 // set idle/timer source id |
| 87 virtual void SetGetPropertiesSourceId(guint source_id); | 102 virtual void SetGetPropertiesSourceId(guint source_id); |
| 88 | 103 |
| 89 // are we in the process of retrying our GetProperties call? | 104 // are we in the process of retrying our GetProperties call? |
| 90 virtual bool RetryingGetProperties() const; | 105 virtual bool RetryingGetProperties() const; |
| 91 | 106 |
| 92 // set the retrying flag | 107 // set the retrying flag |
| 93 virtual void OnRetryingGetProperties(bool retrying); | 108 virtual void OnRetryingGetProperties(bool retrying); |
| 94 | 109 |
| 95 private: | 110 private: |
| 96 // D-Bus connection owned by our creator | 111 // D-Bus connection owned by our creator |
| 97 // shared with Service objs that we create | 112 // shared with Service objs that we create |
| 98 DBus::Connection& connection_; | 113 DBus::Connection& connection_; |
| 99 | 114 |
| 115 // glib main loop |
| 116 GMainLoop * const main_loop_; |
| 117 |
| 100 // collection of Service objs representing cellular services | 118 // collection of Service objs representing cellular services |
| 101 ServiceMap services_; | 119 ServiceMap services_; |
| 102 | 120 |
| 103 // Cashew server implementing our front-end interface | 121 // Cashew server implementing our front-end interface |
| 104 CashewServer *cashew_server_; | 122 CashewServer *cashew_server_; |
| 105 | 123 |
| 106 // default technology most recently reported by Flimflam | 124 // default technology most recently reported by Flimflam |
| 107 Service::Type default_technology_; | 125 Service::Type default_technology_; |
| 108 | 126 |
| 109 // the cellular service, if any, that we think is the default service | 127 // the cellular service, if any, that we think is the default service |
| 110 // can be NULL if we don't know the default service or a non-cellular | 128 // can be NULL if we don't know the default service or a non-cellular |
| 111 // service is the default | 129 // service is the default |
| 112 Service *default_cellular_service_; | 130 Service *default_cellular_service_; |
| 113 | 131 |
| 114 // global connectivity state most recently reported by Flimflam | 132 // global connectivity state most recently reported by Flimflam |
| 115 ConnectivityState connectivity_state_; | 133 ConnectivityState connectivity_state_; |
| 116 | 134 |
| 117 // GetProperties timer glib source id | 135 // GetProperties timer glib source id |
| 118 // 0 means no source | 136 // 0 means no source |
| 119 guint get_properties_source_id_; | 137 guint get_properties_source_id_; |
| 120 | 138 |
| 121 // are we in the process of retrying our GetProperties call? | 139 // are we in the process of retrying our GetProperties call? |
| 122 // this flag exists to distinguish between our initial g_idle_add call | 140 // this flag exists to distinguish between our initial g_idle_add call |
| 123 // and our subsequent timer calls | 141 // and our subsequent timer calls |
| 124 bool retrying_get_properties_; | 142 bool retrying_get_properties_; |
| 125 | 143 |
| 144 // Handler for deferred processing of D-Bus PropertyChanged signals. |
| 145 // |
| 146 // We construct and enqueue PropertyChangedSignal objects as D-Bus signals |
| 147 // arrive, and the handler calls our OnPropertyChanged method (part of our |
| 148 // PropertyChangedDelegate interface) later from the glib main loop. |
| 149 // |
| 150 // This is done to avoid a libdbus-c++ deadlock that can occur when dbus |
| 151 // messages are sent from within a dbus callback. |
| 152 PropertyChangedHandler property_changed_handler_; |
| 153 |
| 126 // delete a collection of services | 154 // delete a collection of services |
| 127 void DeleteServices(ServiceMap *service_map); | 155 void DeleteServices(ServiceMap *service_map); |
| 128 | 156 |
| 129 // glib integration: static wrapper for GetFlimflamProperties | 157 // glib integration: static wrapper for GetFlimflamProperties |
| 130 // takes object ptr as data and invokes object->GetFlimflamProperties() | 158 // takes object ptr as data and invokes object->GetFlimflamProperties() |
| 131 static gboolean StaticGetFlimflamPropertiesCallback(gpointer data); | 159 static gboolean StaticGetFlimflamPropertiesCallback(gpointer data); |
| 132 | 160 |
| 133 // get interesting properties from Flimflam such as Services and | 161 // get interesting properties from Flimflam such as Services and |
| 134 // DefaultTechnology | 162 // DefaultTechnology |
| 135 // returns true on success and false on failure | 163 // returns true on success and false on failure |
| 136 bool GetFlimflamProperties(); | 164 bool GetFlimflamProperties(); |
| 137 | 165 |
| 166 // we've received updated State info from Flimflam |
| 167 void OnStateUpdate(const std::string& new_state_string); |
| 168 |
| 138 // we've received updated DefaultTechnology info from Flimflam | 169 // we've received updated DefaultTechnology info from Flimflam |
| 139 void OnDefaultTechnologyUpdate(const std::string& default_technology); | 170 void OnDefaultTechnologyUpdate(const std::string& default_technology); |
| 140 | 171 |
| 141 // we've received updated Services info from Flimflam | 172 // we've received updated Services info from Flimflam |
| 142 void OnServicesUpdate(const ServicePathList& paths); | 173 void OnServicesUpdate(const ServicePathList& paths); |
| 143 | 174 |
| 144 // Flimflam has started advertising a new service | 175 // Flimflam has started advertising a new service |
| 145 void OnNewService(const DBus::Path& path); | 176 void OnNewService(const DBus::Path& path); |
| 146 | 177 |
| 147 // we've received updated default service info from Flimflam | 178 // we've received updated default service info from Flimflam |
| (...skipping 20 matching lines...) Expand all Loading... |
| 168 | 199 |
| 169 // Flimflam has told us that it has gone offline | 200 // Flimflam has told us that it has gone offline |
| 170 void OnFlimflamOffline(); | 201 void OnFlimflamOffline(); |
| 171 | 202 |
| 172 DISALLOW_COPY_AND_ASSIGN(ServiceManager); | 203 DISALLOW_COPY_AND_ASSIGN(ServiceManager); |
| 173 }; | 204 }; |
| 174 | 205 |
| 175 } // namespace cashew | 206 } // namespace cashew |
| 176 | 207 |
| 177 #endif // SRC_SERVICE_MANAGER_H_ | 208 #endif // SRC_SERVICE_MANAGER_H_ |
| OLD | NEW |