| 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 // TODO(vlaviano): update accessor style (GetFoo/SetFoo -> foo) | 5 // TODO(vlaviano): update accessor style (GetFoo/SetFoo -> foo) |
| 6 | 6 |
| 7 #ifndef SRC_SERVICE_H_ | 7 #ifndef SRC_SERVICE_H_ |
| 8 #define SRC_SERVICE_H_ | 8 #define SRC_SERVICE_H_ |
| 9 | 9 |
| 10 #include <glib.h> | 10 #include <glib.h> |
| 11 | 11 |
| 12 #include <map> | 12 #include <map> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <vector> | |
| 15 | 14 |
| 16 #include <base/basictypes.h> // NOLINT | 15 #include <base/basictypes.h> // NOLINT |
| 17 #include <dbus-c++/dbus.h> // NOLINT | 16 #include <dbus-c++/dbus.h> // NOLINT |
| 18 | 17 |
| 19 #include "src/data_plan.h" | 18 #include "src/data_plan.h" |
| 20 #include "src/data_plan_provider.h" | 19 #include "src/data_plan_provider.h" |
| 21 #include "src/flimflam_service_client_glue.h" | 20 #include "src/flimflam_service_client_glue.h" |
| 22 | 21 |
| 23 namespace cashew { | 22 namespace cashew { |
| 24 | 23 |
| 25 class Device; | 24 class Device; |
| 26 class Policy; | 25 class Policy; |
| 27 class ServiceManager; | 26 class ServiceManager; |
| 28 | 27 |
| 29 // map of key, value pairs representing service properties received via D-Bus | 28 // map of key, value pairs representing service properties received via D-Bus |
| 30 typedef std::map<std::string, DBus::Variant> PropertyMap; | 29 typedef std::map<std::string, DBus::Variant> PropertyMap; |
| 31 | 30 |
| 32 // vector of Device objects | |
| 33 typedef std::vector<Device*> DeviceList; | |
| 34 | |
| 35 // represents a cellular service and monitors Flimflam state for that service | 31 // represents a cellular service and monitors Flimflam state for that service |
| 36 class Service : public org::chromium::flimflam::Service_proxy, | 32 class Service : public org::chromium::flimflam::Service_proxy, |
| 37 public DBus::IntrospectableProxy, | 33 public DBus::IntrospectableProxy, |
| 38 public DBus::ObjectProxy, | 34 public DBus::ObjectProxy, |
| 39 public DataPlanProviderDelegate { | 35 public DataPlanProviderDelegate { |
| 40 public: | 36 public: |
| 41 Service(ServiceManager * const parent, | 37 Service(ServiceManager * const parent, |
| 42 DBus::Connection& connection, // NOLINT | 38 DBus::Connection& connection, // NOLINT |
| 43 const DBus::Path& path); | 39 const DBus::Path& path); |
| 44 virtual ~Service(); | 40 virtual ~Service(); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 | 136 |
| 141 // set idle/timer source id | 137 // set idle/timer source id |
| 142 virtual void SetGetPropertiesSourceId(guint source_id); | 138 virtual void SetGetPropertiesSourceId(guint source_id); |
| 143 | 139 |
| 144 // are we in the process of retrying our GetProperties call? | 140 // are we in the process of retrying our GetProperties call? |
| 145 virtual bool RetryingGetProperties() const; | 141 virtual bool RetryingGetProperties() const; |
| 146 | 142 |
| 147 // set the retrying flag | 143 // set the retrying flag |
| 148 virtual void OnRetryingGetProperties(bool retrying); | 144 virtual void OnRetryingGetProperties(bool retrying); |
| 149 | 145 |
| 150 // get deferred device deletion source id | |
| 151 virtual guint GetDeferredDeviceDeletionSourceId() const; | |
| 152 | |
| 153 // set deferred device deletion source id | |
| 154 virtual void SetDeferredDeviceDeletionSourceId(guint source_id); | |
| 155 | |
| 156 private: | 146 private: |
| 157 // back pointer to our parent ServiceManager | 147 // back pointer to our parent ServiceManager |
| 158 ServiceManager * const parent_; | 148 ServiceManager * const parent_; |
| 159 | 149 |
| 160 // D-Bus connection, owned by our creator | 150 // D-Bus connection, owned by our creator |
| 161 // shared with Device obj that we create | 151 // shared with Device obj that we create |
| 162 DBus::Connection& connection_; | 152 DBus::Connection& connection_; |
| 163 | 153 |
| 164 // D-Bus path for Flimflam service that we represent | 154 // D-Bus path for Flimflam service that we represent |
| 165 // this is our unique identifier | 155 // this is our unique identifier |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 | 192 |
| 203 // are we in the process of retrying our GetProperties call? | 193 // are we in the process of retrying our GetProperties call? |
| 204 // this flag exists to distinguish between our initial g_idle_add call | 194 // this flag exists to distinguish between our initial g_idle_add call |
| 205 // and our subsequent timer calls | 195 // and our subsequent timer calls |
| 206 bool retrying_get_properties_; | 196 bool retrying_get_properties_; |
| 207 | 197 |
| 208 // Service connectivity state | 198 // Service connectivity state |
| 209 // finer-grained connectivity info applicable when |state_| == kStateReady | 199 // finer-grained connectivity info applicable when |state_| == kStateReady |
| 210 ConnectivityState connectivity_state_; | 200 ConnectivityState connectivity_state_; |
| 211 | 201 |
| 212 // Device objects pending deletion from the main loop | |
| 213 // We need to do this to work around a dbus-c++ deadlock issue that arises | |
| 214 // when we send a D-Bus message from a D-Bus callback | |
| 215 DeviceList devices_pending_deletion_; | |
| 216 | |
| 217 // glib source id for deferred device deletion | |
| 218 guint deferred_device_deletion_source_id_; | |
| 219 | |
| 220 // deletes members of |devices_pending_deletion_| immediately | |
| 221 void DeletePendingDevices(); | |
| 222 | |
| 223 // schedule a device for later deletion from the main loop | |
| 224 void ScheduleDeviceForLaterDeletion(Device *device); | |
| 225 | |
| 226 // glib integration: static wrapper for DeletePendingDevices | |
| 227 // takes object ptr as data and invokes object->DeletePendingDevices() | |
| 228 static gboolean StaticDeletePendingDevicesCallback(gpointer data); | |
| 229 | |
| 230 // convert connectivity state string to ConnectivityState enum value | 202 // convert connectivity state string to ConnectivityState enum value |
| 231 static ConnectivityState ConnectivityStateFromString( | 203 static ConnectivityState ConnectivityStateFromString( |
| 232 const std::string& connectivity_state); | 204 const std::string& connectivity_state); |
| 233 | 205 |
| 234 // convert state string to State enum value | 206 // convert state string to State enum value |
| 235 static State StateFromString(const std::string& state); | 207 static State StateFromString(const std::string& state); |
| 236 | 208 |
| 237 // we've received updated Device info from Flimflam | 209 // we've received updated Device info from Flimflam |
| 238 void OnDeviceUpdate(const DBus::Path& device_path); | 210 void OnDeviceUpdate(const DBus::Path& device_path); |
| 239 | 211 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 | 299 |
| 328 // consult policy to determine if we should send an unsolicited update | 300 // consult policy to determine if we should send an unsolicited update |
| 329 void MaybeEmitDataPlansUpdate(); | 301 void MaybeEmitDataPlansUpdate(); |
| 330 | 302 |
| 331 DISALLOW_COPY_AND_ASSIGN(Service); | 303 DISALLOW_COPY_AND_ASSIGN(Service); |
| 332 }; | 304 }; |
| 333 | 305 |
| 334 } // namespace cashew | 306 } // namespace cashew |
| 335 | 307 |
| 336 #endif // SRC_SERVICE_H_ | 308 #endif // SRC_SERVICE_H_ |
| OLD | NEW |