Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(311)

Side by Side Diff: src/service_impl.h

Issue 6395007: cashew: gmock integration (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/cashew.git@master
Patch Set: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/service.cc ('k') | src/service_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010, 2011 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // TODO(vlaviano): update accessor style (GetFoo/SetFoo -> foo)
6
7 #ifndef SRC_SERVICE_IMPL_H_
8 #define SRC_SERVICE_IMPL_H_
9
10 #include <glib.h>
11
12 #include <map>
13 #include <string>
14
15 #include <base/basictypes.h> // NOLINT
16 #include <dbus-c++/dbus.h> // NOLINT
17
18 #include "src/data_plan.h"
19 #include "src/data_plan_provider.h"
20 #include "src/flimflam_service_client_glue.h"
21 #include "src/property_changed_handler.h"
22 #include "src/service.h"
23
24 namespace cashew {
25
26 // represents a cellular service and monitors Flimflam state for that service
27 class ServiceImpl : public Service,
28 public org::chromium::flimflam::Service_proxy,
29 public DBus::IntrospectableProxy,
30 public DBus::ObjectProxy,
31 public DataPlanProviderDelegate,
32 public PropertyChangedDelegate {
33 public:
34 ServiceImpl(ServiceManager * const parent,
35 DBus::Connection& connection, // NOLINT
36 const DBus::Path& path);
37 virtual ~ServiceImpl();
38
39 // Service methods
40 virtual const DBus::Path& GetPath() const;
41 virtual State GetState() const;
42 virtual Type GetType() const;
43 static Type TypeFromString(const std::string& type);
44 virtual Device* GetDevice() const;
45 virtual DBusDataPlanList GetDBusDataPlans() const;
46 virtual bool IsDefaultService() const;
47 virtual ConnectivityState GetConnectivityState() const;
48
49 // Flimflam Service D-Bus Proxy methods
50
51 // receive incoming PropertyChanged D-Bus signal from Flimflam service and
52 // schedule deferred processing
53 virtual void PropertyChanged(const std::string& property_name,
54 const DBus::Variant& new_value);
55
56 // PropertyChangedDelegate methods
57
58 virtual void OnPropertyChanged(const PropertyChangedHandler *handler,
59 const std::string& property_name,
60 const DBus::Variant& new_value);
61
62 // Device methods
63
64 // we've received updated Cellular.Carrier info from our child Device
65 virtual void OnCarrierUpdate(const std::string& carrier);
66
67 // we've received updated byte counter info from our child Device
68 virtual void OnByteCounterUpdate(uint64 rx_bytes, uint64 tx_bytes);
69
70 // DataPlanProviderDelegate methods
71
72 // a request to our carrier usage API proxy has completed
73 virtual void OnRequestComplete(const DataPlanProvider *provider,
74 bool successful,
75 const Value *parsed_usage_update);
76
77 // Service Manager methods
78
79 // we've received an update from our parent about whether or not we're the
80 // default service
81 virtual void OnDefaultServiceUpdate(bool is_default_service);
82
83 // we've received an update from our parent that Flimflam has come online
84 virtual void OnFlimflamOnline();
85
86 // we've received an update from our parent that Flimflam has gone offline
87 virtual void OnFlimflamOffline();
88
89 private:
90 // back pointer to our parent ServiceManager
91 ServiceManager * const parent_;
92
93 // D-Bus connection, owned by our creator
94 // shared with Device obj that we create
95 DBus::Connection& connection_;
96
97 // D-Bus path for Flimflam service that we represent
98 // this is our unique identifier
99 const DBus::Path path_;
100
101 // Service connection state
102 State state_;
103
104 // Service type
105 Type type_;
106
107 // Device corresponding to our service
108 Device *device_;
109
110 // cached data plan info
111 DataPlanList data_plans_;
112
113 // carrier usage API proxy
114 DataPlanProvider *provider_;
115
116 // carrier usage API URL
117 // empty string represents "unknown"
118 std::string usage_url_;
119
120 // do we have an outstanding usage API request
121 bool request_in_progress_;
122
123 // periodic update timeout
124 GSource *update_timeout_source_;
125
126 // carrier policy
127 Policy *policy_;
128
129 // do we think that we're the default service?
130 bool is_default_service_;
131
132 // GetProperties timer glib source id
133 // 0 means no source
134 guint get_properties_source_id_;
135
136 // are we in the process of retrying our GetProperties call?
137 // this flag exists to distinguish between our initial g_idle_add call
138 // and our subsequent timer calls
139 bool retrying_get_properties_;
140
141 // Service connectivity state
142 // finer-grained connectivity info applicable when |state_| == kStateReady
143 ConnectivityState connectivity_state_;
144
145 // Handler for deferred processing of D-Bus PropertyChanged signals.
146 // See comments in service_manager.h
147 PropertyChangedHandler property_changed_handler_;
148
149 // convert connectivity state string to ConnectivityState enum value
150 static ConnectivityState ConnectivityStateFromString(
151 const std::string& connectivity_state);
152
153 // convert state string to State enum value
154 static State StateFromString(const std::string& state);
155
156 // we've received updated Device info from Flimflam
157 void OnDeviceUpdate(const DBus::Path& device_path);
158
159 // we've received updated Connectivity State info from Flimflam
160 void OnConnectivityStateUpdate(const std::string& connectivity_state);
161
162 // we've received updated State info from Flimflam
163 void OnStateUpdate(const std::string& state);
164
165 // we've received updated Type info from Flimflam
166 void OnTypeUpdate(const std::string& type);
167
168 // we've received updated Cellular.UsageUrl info from Flimflam
169 void OnUsageUrlUpdate(const std::string& usage_url);
170
171 // glib integration: static wrapper for GetServiceProperties
172 // takes object ptr as data and invokes object->GetServiceProperties()
173 static gboolean StaticGetServicePropertiesCallback(gpointer data);
174
175 // get service properties from Flimflam
176 // returns true on success and false on failure
177 bool GetServiceProperties();
178
179 // clear a DataPlanList and delete its data plan objects
180 void DeleteDataPlans(DataPlanList *data_plans);
181
182 // create a hardcoded data plan and add it to data_plans_ list
183 // for debugging
184 void AddHardcodedDataPlan();
185
186 // ask provider to request a usage update if it makes sense
187 void RequestUsageUpdate();
188
189 // cancel any pending usage API requests that we have
190 void CancelPendingRequests();
191
192 // update timeout callback
193 gboolean UpdateTimeoutCallback();
194
195 // glib integration: static wrapper for UpdateTimeoutCallback
196 // takes object ptr as data and invokes object->UpdateTimeoutCallback()
197 static gboolean StaticUpdateTimeoutCallback(gpointer data);
198
199 // create and start an update timer that fires periodically
200 // |provider_| and |policy_| must both be non-NULL
201 // the timer interval is retrieved from the current policy
202 // returns true on success and false on failure
203 bool CreateUpdateTimer();
204
205 // stop and destroy the update timer if it exists
206 void DestroyUpdateTimer();
207
208 // delete carrier usage API proxy and policy if they exist
209 // this also destroys the update timer and cancels pending requests
210 // NOTE: this does not delete usage url (it's considered service state)
211 void DeleteCarrierState();
212
213 // does |status| contain a valid usage API status result string?
214 bool IsValidCrosUsageStatus(const std::string& status) const;
215
216 // usage API request returned an error result
217 void OnCrosUsageErrorResult(const std::string& status);
218
219 // do we think that we're connected at this time?
220 bool IsConnected() const;
221
222 // we've just become connected
223 void OnConnected();
224
225 // we've just become disconnected
226 // NOTE: this means we've entered a state other than kStateReady, not
227 // that we're necessarily in kStateDisconnect
228 void OnDisconnected();
229
230 // are we currently sending periodic usage API requests?
231 bool IsSendingUsageRequests() const;
232
233 // based on our best current knowledge and our policy, should we be
234 // sending periodic usage API requests?
235 bool ShouldSendUsageRequests() const;
236
237 // stop sending periodic usage API requests
238 void StopSendingUsageRequests();
239
240 // start sending periodic usage API requests
241 void StartSendingUsageRequests();
242
243 // something has changed, so reevaluate whether or not we should be sending
244 // periodic usage API requests and adjust our behavior if necessary
245 void ReconsiderSendingUsageRequests();
246
247 // consult policy to determine if we should send an unsolicited update
248 void MaybeEmitDataPlansUpdate();
249
250 DISALLOW_COPY_AND_ASSIGN(ServiceImpl);
251 };
252
253 } // namespace cashew
254
255 #endif // SRC_SERVICE_IMPL_H_
OLDNEW
« no previous file with comments | « src/service.cc ('k') | src/service_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698