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