| 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 | |
| 10 #include <map> | 8 #include <map> |
| 11 #include <string> | 9 #include <string> |
| 12 #include <vector> | 10 #include <vector> |
| 13 | 11 |
| 14 #include <base/basictypes.h> // NOLINT | 12 #include <base/basictypes.h> // NOLINT |
| 15 #include <dbus-c++/dbus.h> // NOLINT | 13 #include <dbus-c++/dbus.h> // NOLINT |
| 16 | 14 |
| 17 #include "src/flimflam_manager_client_glue.h" | 15 #include "src/flimflam_manager_client_glue.h" |
| 18 #include "src/service.h" | 16 #include "src/service.h" |
| 19 | 17 |
| 20 namespace cashew { | 18 namespace cashew { |
| 21 | 19 |
| 22 class CashewServer; | 20 class CashewServer; |
| 23 | 21 |
| 24 // map of service path names to Service objects | 22 // map of service path names to Service objects |
| 25 typedef std::map<std::string, Service*> ServiceMap; | 23 typedef std::map<std::string, Service*> ServiceMap; |
| 26 | 24 |
| 27 // vector of Service objects | |
| 28 typedef std::vector<Service*> ServiceList; | |
| 29 | |
| 30 // vector of DBus::Path objects (strings) representing service path names | 25 // vector of DBus::Path objects (strings) representing service path names |
| 31 typedef std::vector<DBus::Path> ServicePathList; | 26 typedef std::vector<DBus::Path> ServicePathList; |
| 32 | 27 |
| 33 // monitors Flimflam and maintains a collection of cellular service objects | 28 // monitors Flimflam and maintains a collection of cellular service objects |
| 34 class ServiceManager : public org::chromium::flimflam::Manager_proxy, | 29 class ServiceManager : public org::chromium::flimflam::Manager_proxy, |
| 35 public DBus::IntrospectableProxy, | 30 public DBus::IntrospectableProxy, |
| 36 public DBus::ObjectProxy { | 31 public DBus::ObjectProxy { |
| 37 public: | 32 public: |
| 38 explicit ServiceManager(DBus::Connection& connection, // NOLINT | 33 explicit ServiceManager(DBus::Connection& connection); // NOLINT |
| 39 GMainLoop * const main_loop); | |
| 40 virtual ~ServiceManager(); | 34 virtual ~ServiceManager(); |
| 41 | 35 |
| 42 // look up a service by its path name | 36 // look up a service by its path name |
| 43 // returns NULL if service is not found | 37 // returns NULL if service is not found |
| 44 virtual const Service* GetService(const std::string& service_path) const; | 38 virtual const Service* GetService(const std::string& service_path) const; |
| 45 | 39 |
| 46 // set Cashew server | 40 // set Cashew server |
| 47 // we'll talk to it when we want to emit updates to the world on behalf of | 41 // we'll talk to it when we want to emit updates to the world on behalf of |
| 48 // our child Services. | 42 // our child Services. |
| 49 // it's ok to clear this by setting it to NULL, in which case our updates | 43 // it's ok to clear this by setting it to NULL, in which case our updates |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 85 |
| 92 // set idle/timer source id | 86 // set idle/timer source id |
| 93 virtual void SetGetPropertiesSourceId(guint source_id); | 87 virtual void SetGetPropertiesSourceId(guint source_id); |
| 94 | 88 |
| 95 // are we in the process of retrying our GetProperties call? | 89 // are we in the process of retrying our GetProperties call? |
| 96 virtual bool RetryingGetProperties() const; | 90 virtual bool RetryingGetProperties() const; |
| 97 | 91 |
| 98 // set the retrying flag | 92 // set the retrying flag |
| 99 virtual void OnRetryingGetProperties(bool retrying); | 93 virtual void OnRetryingGetProperties(bool retrying); |
| 100 | 94 |
| 101 // get deferred service deletion source id | |
| 102 virtual guint GetDeferredServiceDeletionSourceId() const; | |
| 103 | |
| 104 // set deferred service deletion source id | |
| 105 virtual void SetDeferredServiceDeletionSourceId(guint source_id); | |
| 106 | |
| 107 private: | 95 private: |
| 108 // D-Bus connection owned by our creator | 96 // D-Bus connection owned by our creator |
| 109 // shared with Service objs that we create | 97 // shared with Service objs that we create |
| 110 DBus::Connection& connection_; | 98 DBus::Connection& connection_; |
| 111 | 99 |
| 112 // glib main loop | |
| 113 GMainLoop * const main_loop_; | |
| 114 | |
| 115 // collection of Service objs representing cellular services | 100 // collection of Service objs representing cellular services |
| 116 ServiceMap services_; | 101 ServiceMap services_; |
| 117 | 102 |
| 118 // Cashew server implementing our front-end interface | 103 // Cashew server implementing our front-end interface |
| 119 CashewServer *cashew_server_; | 104 CashewServer *cashew_server_; |
| 120 | 105 |
| 121 // default technology most recently reported by Flimflam | 106 // default technology most recently reported by Flimflam |
| 122 Service::Type default_technology_; | 107 Service::Type default_technology_; |
| 123 | 108 |
| 124 // the cellular service, if any, that we think is the default service | 109 // the cellular service, if any, that we think is the default service |
| 125 // can be NULL if we don't know the default service or a non-cellular | 110 // can be NULL if we don't know the default service or a non-cellular |
| 126 // service is the default | 111 // service is the default |
| 127 Service *default_cellular_service_; | 112 Service *default_cellular_service_; |
| 128 | 113 |
| 129 // global connectivity state most recently reported by Flimflam | 114 // global connectivity state most recently reported by Flimflam |
| 130 ConnectivityState connectivity_state_; | 115 ConnectivityState connectivity_state_; |
| 131 | 116 |
| 132 // GetProperties timer glib source id | 117 // GetProperties timer glib source id |
| 133 // 0 means no source | 118 // 0 means no source |
| 134 guint get_properties_source_id_; | 119 guint get_properties_source_id_; |
| 135 | 120 |
| 136 // are we in the process of retrying our GetProperties call? | 121 // are we in the process of retrying our GetProperties call? |
| 137 // this flag exists to distinguish between our initial g_idle_add call | 122 // this flag exists to distinguish between our initial g_idle_add call |
| 138 // and our subsequent timer calls | 123 // and our subsequent timer calls |
| 139 bool retrying_get_properties_; | 124 bool retrying_get_properties_; |
| 140 | 125 |
| 141 // Service objects pending deletion from the main loop | |
| 142 // we need to do this to work around a dbus-c++ deadlock issue that arises | |
| 143 // when we send a D-Bus message from a D-Bus callback | |
| 144 ServiceList services_pending_deletion_; | |
| 145 | |
| 146 // glib source id for deferred service deletion | |
| 147 guint deferred_service_deletion_source_id_; | |
| 148 | |
| 149 // delete a collection of services | 126 // delete a collection of services |
| 150 // deletes services immediately if |defer| == false | 127 void DeleteServices(ServiceMap *service_map); |
| 151 // schedules services for later deletion if |defer| == true | |
| 152 void DeleteServices(ServiceMap *service_map, bool defer); | |
| 153 | |
| 154 // deletes members of |services_pending_deletion_| immediately | |
| 155 void DeletePendingServices(); | |
| 156 | |
| 157 // schedule service for later deletion from the main loop | |
| 158 void ScheduleServiceForLaterDeletion(Service *service); | |
| 159 | |
| 160 // glib integration: static wrapper for DeletePendingServices | |
| 161 // takes object ptr as data and invokes object->DeletePendingServices() | |
| 162 // does not reschedule itself to run again | |
| 163 static gboolean StaticDeletePendingServicesCallback(gpointer data); | |
| 164 | 128 |
| 165 // glib integration: static wrapper for GetFlimflamProperties | 129 // glib integration: static wrapper for GetFlimflamProperties |
| 166 // takes object ptr as data and invokes object->GetFlimflamProperties() | 130 // takes object ptr as data and invokes object->GetFlimflamProperties() |
| 167 static gboolean StaticGetFlimflamPropertiesCallback(gpointer data); | 131 static gboolean StaticGetFlimflamPropertiesCallback(gpointer data); |
| 168 | 132 |
| 169 // get interesting properties from Flimflam such as Services and | 133 // get interesting properties from Flimflam such as Services and |
| 170 // DefaultTechnology | 134 // DefaultTechnology |
| 171 // returns true on success and false on failure | 135 // returns true on success and false on failure |
| 172 bool GetFlimflamProperties(); | 136 bool GetFlimflamProperties(); |
| 173 | 137 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 204 | 168 |
| 205 // Flimflam has told us that it has gone offline | 169 // Flimflam has told us that it has gone offline |
| 206 void OnFlimflamOffline(); | 170 void OnFlimflamOffline(); |
| 207 | 171 |
| 208 DISALLOW_COPY_AND_ASSIGN(ServiceManager); | 172 DISALLOW_COPY_AND_ASSIGN(ServiceManager); |
| 209 }; | 173 }; |
| 210 | 174 |
| 211 } // namespace cashew | 175 } // namespace cashew |
| 212 | 176 |
| 213 #endif // SRC_SERVICE_MANAGER_H_ | 177 #endif // SRC_SERVICE_MANAGER_H_ |
| OLD | NEW |