| 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_H_ | 5 #ifndef SRC_SERVICE_H_ |
| 6 #define SRC_SERVICE_H_ | 6 #define SRC_SERVICE_H_ |
| 7 | 7 |
| 8 #include <glib.h> |
| 9 |
| 8 #include <map> | 10 #include <map> |
| 9 #include <string> | 11 #include <string> |
| 10 | 12 |
| 11 #include <base/basictypes.h> // NOLINT | 13 #include <base/basictypes.h> // NOLINT |
| 12 #include <dbus-c++/dbus.h> // NOLINT | 14 #include <dbus-c++/dbus.h> // NOLINT |
| 13 | 15 |
| 14 #include "src/data_plan.h" | 16 #include "src/data_plan.h" |
| 17 #include "src/data_plan_provider.h" |
| 15 #include "src/flimflam_service_client_glue.h" | 18 #include "src/flimflam_service_client_glue.h" |
| 16 | 19 |
| 17 namespace cashew { | 20 namespace cashew { |
| 18 | 21 |
| 19 class Device; | 22 class Device; |
| 23 class Policy; |
| 24 class ServiceManager; |
| 20 | 25 |
| 21 // map of key, value pairs representing service properties received via D-Bus | 26 // map of key, value pairs representing service properties received via D-Bus |
| 22 typedef std::map<std::string, DBus::Variant> PropertyMap; | 27 typedef std::map<std::string, DBus::Variant> PropertyMap; |
| 23 | 28 |
| 24 // represents a cellular service and monitors Flimflam state for that service | 29 // represents a cellular service and monitors Flimflam state for that service |
| 25 class Service : public org::chromium::flimflam::Service_proxy, | 30 class Service : public org::chromium::flimflam::Service_proxy, |
| 26 public DBus::IntrospectableProxy, | 31 public DBus::IntrospectableProxy, |
| 27 public DBus::ObjectProxy { | 32 public DBus::ObjectProxy, |
| 33 public DataPlanProviderDelegate { |
| 28 public: | 34 public: |
| 29 Service(DBus::Connection& connection, const DBus::Path& path); // NOLINT | 35 Service(ServiceManager * const parent, |
| 36 DBus::Connection& connection, // NOLINT |
| 37 const DBus::Path& path); |
| 30 virtual ~Service(); | 38 virtual ~Service(); |
| 31 | 39 |
| 32 // get D-Bus path for this service | 40 // get D-Bus path for this service |
| 33 virtual const DBus::Path& GetPath() const; | 41 virtual const DBus::Path& GetPath() const; |
| 34 | 42 |
| 35 // valid state values for this service | 43 // valid state values for this service |
| 36 typedef enum { | 44 typedef enum { |
| 37 kStateUnknown = 0, | 45 kStateUnknown = 0, |
| 38 kStateIdle, | 46 kStateIdle, |
| 39 kStateCarrier, | 47 kStateCarrier, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 68 | 76 |
| 69 // get data plan info, formatted for D-Bus | 77 // get data plan info, formatted for D-Bus |
| 70 virtual DBusDataPlanList GetDBusDataPlans() const; | 78 virtual DBusDataPlanList GetDBusDataPlans() const; |
| 71 | 79 |
| 72 // Flimflam Service D-Bus Proxy methods | 80 // Flimflam Service D-Bus Proxy methods |
| 73 | 81 |
| 74 // receive incoming PropertyChanged D-Bus signal from Flimflam service | 82 // receive incoming PropertyChanged D-Bus signal from Flimflam service |
| 75 virtual void PropertyChanged(const std::string& property_name, | 83 virtual void PropertyChanged(const std::string& property_name, |
| 76 const DBus::Variant& new_value); | 84 const DBus::Variant& new_value); |
| 77 | 85 |
| 86 // Device methods |
| 87 |
| 88 // we've received updated Cellular.Carrier info from our child Device |
| 89 virtual void OnCarrierUpdate(const std::string& carrier); |
| 90 |
| 91 // DataPlanProviderDelegate methods |
| 92 |
| 93 // a request to our carrier usage API proxy has completed |
| 94 virtual void OnRequestComplete(const DataPlanProvider *provider, |
| 95 bool successful, |
| 96 const Value *parsed_usage_update); |
| 97 |
| 78 private: | 98 private: |
| 99 // back pointer to our parent ServiceManager |
| 100 ServiceManager * const parent_; |
| 101 |
| 79 // D-Bus connection, owned by our creator | 102 // D-Bus connection, owned by our creator |
| 80 // shared with Device obj that we create | 103 // shared with Device obj that we create |
| 81 DBus::Connection& connection_; | 104 DBus::Connection& connection_; |
| 82 | 105 |
| 83 // D-Bus path for Flimflam service that we represent | 106 // D-Bus path for Flimflam service that we represent |
| 84 // this is our unique identifier | 107 // this is our unique identifier |
| 85 const DBus::Path path_; | 108 const DBus::Path path_; |
| 86 | 109 |
| 87 // Service connection state | 110 // Service connection state |
| 88 State state_; | 111 State state_; |
| 89 | 112 |
| 90 // Service type | 113 // Service type |
| 91 Type type_; | 114 Type type_; |
| 92 | 115 |
| 93 // Device corresponding to our service | 116 // Device corresponding to our service |
| 94 Device *device_; | 117 Device *device_; |
| 95 | 118 |
| 96 // cached data plan info | 119 // cached data plan info |
| 97 DataPlanList data_plans_; | 120 DataPlanList data_plans_; |
| 98 | 121 |
| 99 // TODO(vlaviano): reference to back end carrier plugin | 122 // carrier usage API proxy |
| 100 // TODO(vlaviano): refresh data plan info from carrier plugin | 123 DataPlanProvider *provider_; |
| 124 |
| 125 // carrier usage API URL |
| 126 // empty string represents "unknown" |
| 127 std::string usage_url_; |
| 128 |
| 129 // do we have an outstanding usage API request |
| 130 bool request_in_progress_; |
| 131 |
| 132 // periodic update timeout |
| 133 GSource *update_timeout_source_; |
| 134 |
| 135 // carrier policy |
| 136 Policy *policy_; |
| 101 | 137 |
| 102 // convert state string to State enum value | 138 // convert state string to State enum value |
| 103 State StateFromString(const std::string& state) const; | 139 State StateFromString(const std::string& state) const; |
| 104 | 140 |
| 105 // convert type string to Type enum value | 141 // convert type string to Type enum value |
| 106 Type TypeFromString(const std::string& type) const; | 142 Type TypeFromString(const std::string& type) const; |
| 107 | 143 |
| 108 // we've received updated Device info from Flimflam | 144 // we've received updated Device info from Flimflam |
| 109 void OnDeviceUpdate(const DBus::Path& device_path); | 145 void OnDeviceUpdate(const DBus::Path& device_path); |
| 110 | 146 |
| 111 // we've received updated State info from Flimflam | 147 // we've received updated State info from Flimflam |
| 112 void OnStateUpdate(const std::string& state); | 148 void OnStateUpdate(const std::string& state); |
| 113 | 149 |
| 114 // we've received updated Type info from Flimflam | 150 // we've received updated Type info from Flimflam |
| 115 void OnTypeUpdate(const std::string& type); | 151 void OnTypeUpdate(const std::string& type); |
| 116 | 152 |
| 153 // we've received updated Cellular.UsageUrl info from Flimflam |
| 154 void OnUsageUrlUpdate(const std::string& usage_url); |
| 155 |
| 117 // get service properties from Flimflam | 156 // get service properties from Flimflam |
| 118 void GetServiceProperties(); | 157 void GetServiceProperties(); |
| 119 | 158 |
| 120 // clear data_plans_ list and delete data plan objects | 159 // clear a DataPlanList and delete its data plan objects |
| 121 void DeleteDataPlans(); | 160 void DeleteDataPlans(DataPlanList *data_plans); |
| 122 | 161 |
| 123 // create a hardcoded data plan and add it to data_plans_ list | 162 // create a hardcoded data plan and add it to data_plans_ list |
| 124 // for debugging | 163 // for debugging |
| 125 void AddHardcodedDataPlan(); | 164 void AddHardcodedDataPlan(); |
| 126 | 165 |
| 166 // ask provider to request a usage update if it makes sense |
| 167 void RequestUsageUpdate(); |
| 168 |
| 169 // cancel any pending usage API requests that we have |
| 170 void CancelPendingRequests(); |
| 171 |
| 172 // update timeout callback |
| 173 gboolean UpdateTimeoutCallback(); |
| 174 |
| 175 // glib integration: static wrapper for UpdateTimeoutCallback |
| 176 // takes object ptr as data and invokes object->UpdateTimeoutCallback() |
| 177 static gboolean StaticUpdateTimeoutCallback(gpointer data); |
| 178 |
| 179 // create and start an update timer that fires periodically |
| 180 // |provider_| and |policy_| must both be non-NULL |
| 181 // the timer interval is retrieved from the current policy |
| 182 // returns true on success and false on failure |
| 183 bool CreateUpdateTimer(); |
| 184 |
| 185 // stop and destroy the update timer if it exists |
| 186 void DestroyUpdateTimer(); |
| 187 |
| 188 // delete carrier usage API proxy and policy if they exist |
| 189 // this also destroys the update timer and cancels pending requests |
| 190 // NOTE: this does not delete usage url (it's considered service state) |
| 191 void DeleteCarrierState(); |
| 192 |
| 127 DISALLOW_COPY_AND_ASSIGN(Service); | 193 DISALLOW_COPY_AND_ASSIGN(Service); |
| 128 }; | 194 }; |
| 129 | 195 |
| 130 } // namespace cashew | 196 } // namespace cashew |
| 131 | 197 |
| 132 #endif // SRC_SERVICE_H_ | 198 #endif // SRC_SERVICE_H_ |
| OLD | NEW |