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

Side by Side Diff: network_property_test.cc

Issue 6896001: Implement SetNetworkDeviceProperty() and ClearNetworkDeviceProperty(). (Closed) Base URL: ssh://gitrw.chromium.org:9222/cros.git@master
Patch Set: Fix comments and whitespace. Created 9 years, 8 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
« chromeos_network.h ('K') | « load.cc ('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
(Empty)
1 // Copyright (c) 2009 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 #include <dlfcn.h>
6 #include <glib-object.h>
7 #include <map>
8 #include <vector>
9
10 #include <base/logging.h>
11 #include <base/time.h>
12 #include <base/values.h>
13
14 #include "chromeos_cros_api.h" // NOLINT
15 #include "chromeos_network.h" // NOLINT
16 #include "chromeos/dbus/dbus.h" // NOLINT
17 #include "chromeos/glib/object.h" // NOLINT
18 #include "monitor_utils.h" //NOLINT
19
20 static void PrintProperty(const char* path,
21 const char* key,
22 const Value* value) {
23 std::string prelude("PropertyChanged [");
24 prelude += path;
25 prelude += "] ";
26 prelude += key;
27 prelude += " : ";
28 if (value->IsType(Value::TYPE_STRING)) {
29 std::string strval;
30 value->GetAsString(&strval);
31 LOG(INFO) << prelude << "\"" << strval << "\"";
32 } else if (value->IsType(Value::TYPE_BOOLEAN)) {
33 bool boolval;
34 value->GetAsBoolean(&boolval);
35 LOG(INFO) << prelude << boolval;
36 } else if (value->IsType(Value::TYPE_INTEGER)) {
37 int intval;
38 value->GetAsInteger(&intval);
39 LOG(INFO) << prelude << intval;
40 } else if (value->IsType(Value::TYPE_LIST)) {
41 const ListValue* list = static_cast<const ListValue*>(value);
42 Value *itemval;
43 std::string liststr;
44 size_t index = 0;
45 while (list->Get(index, &itemval)) {
46 if (!itemval->IsType(Value::TYPE_STRING)) {
47 ++index;
48 continue;
49 }
50 std::string itemstr;
51 itemval->GetAsString(&itemstr);
52 liststr += itemstr;
53 ++index;
54 if (index < list->GetSize())
55 liststr += ", ";
56 }
57 LOG(INFO) << prelude << "\"" << liststr << "\"";
58 } else if (value->IsType(Value::TYPE_DICTIONARY)) {
59 const DictionaryValue* dict = static_cast<const DictionaryValue*>(value);
60 std::string items;
61 std::string itemval;
62 size_t n = 0;
63 DictionaryValue::key_iterator iter = dict->begin_keys();
64 while (iter != dict->end_keys()) {
65 std::string key = *iter;
66 items += "{'" + key + "': '";
67 if (dict->GetStringWithoutPathExpansion(key, &itemval))
68 items += itemval + "'}";
69 else
70 items += "<not-a-string>'}";
71 if (n < dict->size())
72 items += ", ";
73 ++iter;
74 ++n;
75 }
76 LOG(INFO) << prelude << items;
77 } else
78 LOG(INFO) << prelude << "<type " << value->GetType() << ">";
79 }
80
81 class CallbackMonitorNetwork {
82 public:
83 static void Run(void *object,
84 const char *path,
85 const char *key,
86 const Value* value) {
87 PrintProperty(path, key, value);
88 }
89 };
90
91 // A simple program exercising the {Set,Clear}{Device,Service}Property methods.
Eric Shienbrood 2011/04/21 21:48:26 This is all a little bit bogus, since (a) the empt
92 int main(int argc, const char** argv) {
93 ::g_type_init();
94 GMainLoop* loop = ::g_main_loop_new(NULL, false);
95
96 DCHECK(loop) << "Failed to create main loop";
97 if (!LoadCrosLibrary(argv))
98 LOG(INFO) << "Failed to load cros .so";
99
100 if (argc != 4) {
101 LOG(INFO) << "Program must be invoked with one path argument, "
102 << "one property name, and one value.";
103 return 1;
104 }
105
106 chromeos::PropertyChangeMonitor device_mon;
107 if (strncmp(argv[1], "/service/", 9) == 0) {
108
109 LOG(INFO) << "Requesting properties messages on service '"
110 << argv[1] << "'";
111
112 device_mon = chromeos::MonitorNetworkService(&CallbackMonitorNetwork::Run,
113 argv[1], NULL);
114 if (strlen(argv[3]) != 0) {
115 LOG(INFO) << "Setting property '" << argv[2] << "' on '"
116 << argv[1] << "'";
117 chromeos::SetNetworkServiceProperty(argv[1], argv[2],
118 Value::CreateStringValue(argv[3]));
119 } else {
120 LOG(INFO) << "Clearing property '" << argv[2] << "' on '"
121 << argv[1] << "'";
122 chromeos::ClearNetworkServiceProperty(argv[1], argv[2]);
123 }
124 } else if (strncmp(argv[1], "/device/", 8) == 0) {
125 LOG(INFO) << "Requesting properties messages on device '" << argv[1] << "'";
126
127 device_mon = chromeos::MonitorNetworkDevice(&CallbackMonitorNetwork::Run,
128 argv[1], NULL);
129
130 if (strlen(argv[3]) != 0) {
131 LOG(INFO) << "Setting property '" << argv[2] << "' on '"
132 << argv[1] << "'";
133 chromeos::SetNetworkDeviceProperty(argv[1], argv[2],
134 Value::CreateStringValue(argv[3]));
135 } else {
136 LOG(INFO) << "Clearing property '" << argv[2] << "' on '"
137 << argv[1] << "'";
138 chromeos::ClearNetworkDeviceProperty(argv[1], argv[2]);
139 }
140 } else {
141 LOG(INFO) << "Don't know what to do with path '" << argv[1] << "' "
142 << "neither a device nor a service";
143 return 1;
144 }
145
146 LOG(INFO) << "Starting g_main_loop.";
147
148 ::g_main_loop_run(loop);
149
150 LOG(INFO) << "Shutting down.";
151
152 chromeos::DisconnectPropertyChangeMonitor(device_mon);
153 return 0;
154 }
OLDNEW
« chromeos_network.h ('K') | « load.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698