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

Side by Side Diff: src/cashew_server.cc

Issue 3595001: D-Bus API: Add GetDataPlans, DataPlansUpdate, and RequestDataPlansUpdate (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/cashew.git
Patch Set: Refactor cashew.xml. Get rid of CreateDBusVariant. Tweak comments. Created 10 years, 2 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/cashew_server.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "src/cashew_server.h" 5 #include "src/cashew_server.h"
6 6
7 #include <glog/logging.h> 7 #include <glog/logging.h>
8 8
9 namespace cashew { 9 namespace cashew {
10 10
11 const char* CashewServer::kServiceName = "org.chromium.Cashew"; 11 const char* CashewServer::kServiceName = "org.chromium.Cashew";
12 const char* CashewServer::kServicePath = "/org/chromium/Cashew"; 12 const char* CashewServer::kServicePath = "/org/chromium/Cashew";
13 13
14 CashewServer::CashewServer(DBus::Connection& connection) // NOLINT 14 CashewServer::CashewServer(DBus::Connection& connection) // NOLINT
15 : DBus::ObjectAdaptor(connection, kServicePath) { 15 : DBus::ObjectAdaptor(connection, kServicePath) {
16 } 16 }
17 17
18 // Cashew D-Bus API Methods 18 // Cashew D-Bus API methods
19
20 DataPlanList CashewServer::GetDataPlans(const std::string& service,
21 DBus::Error& error) { // NOLINT
22 DLOG(INFO) << "GetDataPlans: service = " << service;
23 // TODO(vlaviano): log and return error if we don't like service arg
24
25 // For now, we return hardcoded data.
26 // TODO(vlaviano): return real data.
27 DataPlan hardcoded_plan;
28 GetHardcodedDataPlan(&hardcoded_plan);
29 DataPlanList data_plans;
30 data_plans.push_back(hardcoded_plan);
31 return data_plans;
32 }
33
34 void CashewServer::RequestDataPlansUpdate(const std::string& service,
35 DBus::Error& error) { // NOLINT
36 DLOG(INFO) << "RequestDataPlansUpdate: service = " << service;
37 // TODO(vlaviano): log and return error if we don't like service arg
38
39 // trigger a DataPlansUpdate signal
40 // TODO(vlaviano): rate-limiting?
41 // TODO(vlaviano): if cached data isn't recent, ask carrier API for fresh
42 // data and wait for reply before sending signal.
43 EmitDataPlansUpdateSignal(service);
44 }
19 45
20 bool CashewServer::IsAlive(DBus::Error& error) { // NOLINT 46 bool CashewServer::IsAlive(DBus::Error& error) { // NOLINT
21 DLOG(INFO) << "IsAlive"; 47 DLOG(INFO) << "IsAlive";
22 return true; 48 return true;
23 } 49 }
24 50
51 // Private methods
52
53 void CashewServer::EmitDataPlansUpdateSignal(const std::string& service) {
54 DLOG(INFO) << "EmitDataPlansUpdateSignal: service = " << service;
55 // TODO(vlaviano): log error and return if we don't like service arg
56
57 // For now, we return hardcoded data.
58 // TODO(vlaviano): return real data.
59 DataPlan hardcoded_plan;
60 GetHardcodedDataPlan(&hardcoded_plan);
61 DataPlanList data_plans;
62 data_plans.push_back(hardcoded_plan);
63
64 // send out the signal
65 this->DataPlansUpdate(service, data_plans);
66 }
67
68 void CashewServer::GetHardcodedDataPlan(DataPlan* plan) {
69 DCHECK(plan != NULL);
70
71 const std::string plan_name = "test";
72 const std::string plan_type = "UNLIMITED";
73 int64 plan_update_time = 0;
74 int64 plan_start_time = time(NULL) - 12*3600; // 12 hours ago
75 int64 plan_end_time = time(NULL) + 12*3600; // 12 hours hence
76 int64 plan_data_bytes = 100*1024*1024; // 100 MB
77 int64 plan_data_bytes_used = 30*1024*1024; // 30 MB
78
79 (*plan)["CellularPlanName"].writer().append_string(plan_name.c_str());
80 (*plan)["CellularPlanType"].writer().append_string(plan_type.c_str());
81 (*plan)["CellularPlanUpdateTime"].writer().append_int64(plan_update_time);
82 (*plan)["CellularPlanStart"].writer().append_int64(plan_start_time);
83 (*plan)["CellularPlanEnd"].writer().append_int64(plan_end_time);
84 (*plan)["CellularPlanDataBytes"].writer().append_int64(plan_data_bytes);
85 (*plan)["CellularDataBytesUsed"].writer().append_int64(plan_data_bytes_used);
86 }
87
25 } // namespace cashew 88 } // namespace cashew
OLDNEW
« no previous file with comments | « src/cashew_server.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698