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

Unified Diff: network_property_test.cc

Issue 6896001: Implement SetNetworkDeviceProperty() and ClearNetworkDeviceProperty(). (Closed) Base URL: ssh://gitrw.chromium.org:9222/cros.git@master
Patch Set: Slight tune-up of test program 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « load.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: network_property_test.cc
diff --git a/network_property_test.cc b/network_property_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5b7f89170d0b1d44aecdd14b58e6593878ac8c94
--- /dev/null
+++ b/network_property_test.cc
@@ -0,0 +1,159 @@
+// Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <dlfcn.h>
+#include <glib-object.h>
+#include <map>
+#include <vector>
+
+#include <base/logging.h>
+#include <base/time.h>
+#include <base/values.h>
+
+#include "chromeos_cros_api.h" // NOLINT
+#include "chromeos_network.h" // NOLINT
+#include "chromeos/dbus/dbus.h" // NOLINT
+#include "chromeos/glib/object.h" // NOLINT
+#include "monitor_utils.h" //NOLINT
+
+static void PrintProperty(const char* path,
+ const char* key,
+ const Value* value) {
+ std::string prelude("PropertyChanged [");
+ prelude += path;
+ prelude += "] ";
+ prelude += key;
+ prelude += " : ";
+ if (value->IsType(Value::TYPE_STRING)) {
+ std::string strval;
+ value->GetAsString(&strval);
+ LOG(INFO) << prelude << "\"" << strval << "\"";
+ } else if (value->IsType(Value::TYPE_BOOLEAN)) {
+ bool boolval;
+ value->GetAsBoolean(&boolval);
+ LOG(INFO) << prelude << boolval;
+ } else if (value->IsType(Value::TYPE_INTEGER)) {
+ int intval;
+ value->GetAsInteger(&intval);
+ LOG(INFO) << prelude << intval;
+ } else if (value->IsType(Value::TYPE_LIST)) {
+ const ListValue* list = static_cast<const ListValue*>(value);
+ Value *itemval;
+ std::string liststr;
+ size_t index = 0;
+ while (list->Get(index, &itemval)) {
+ if (!itemval->IsType(Value::TYPE_STRING)) {
+ ++index;
+ continue;
+ }
+ std::string itemstr;
+ itemval->GetAsString(&itemstr);
+ liststr += itemstr;
+ ++index;
+ if (index < list->GetSize())
+ liststr += ", ";
+ }
+ LOG(INFO) << prelude << "\"" << liststr << "\"";
+ } else if (value->IsType(Value::TYPE_DICTIONARY)) {
+ const DictionaryValue* dict = static_cast<const DictionaryValue*>(value);
+ std::string items;
+ std::string itemval;
+ size_t n = 0;
+ DictionaryValue::key_iterator iter = dict->begin_keys();
+ while (iter != dict->end_keys()) {
+ std::string key = *iter;
+ items += "{'" + key + "': '";
+ if (dict->GetStringWithoutPathExpansion(key, &itemval))
+ items += itemval + "'}";
+ else
+ items += "<not-a-string>'}";
+ if (n < dict->size())
+ items += ", ";
+ ++iter;
+ ++n;
+ }
+ LOG(INFO) << prelude << items;
+ } else
+ LOG(INFO) << prelude << "<type " << value->GetType() << ">";
+}
+
+class CallbackMonitorNetwork {
+ public:
+ static void Run(void *object,
+ const char *path,
+ const char *key,
+ const Value* value) {
+ PrintProperty(path, key, value);
+ }
+};
+
+// A simple program exercising the {Set,Clear}{Device,Service}Property methods.
+int main(int argc, const char** argv) {
+ ::g_type_init();
+ GMainLoop* loop = ::g_main_loop_new(NULL, false);
+
+ DCHECK(loop) << "Failed to create main loop";
+ if (!LoadCrosLibrary(argv))
+ LOG(INFO) << "Failed to load cros .so";
+
+ if (argc != 4) {
+ LOG(INFO) << "Usage: " << argv[0] << " <path> <property> <string-value>";
+ LOG(INFO) << " " << argv[0] << " -c <path> <property>";
+ return 1;
+ }
+
+ bool clear;
+ const char *path, *property, *value;
+ if (strcmp(argv[1], "-c") == 0) {
+ clear = true;
+ path = argv[2];
+ property = argv[3];
+ value = NULL;
+ } else {
+ clear = false;
+ path = argv[1];
+ property = argv[2];
+ value = argv[3];
+ }
+
+ chromeos::PropertyChangeMonitor device_mon;
+ if (strncmp(path, "/service/", 9) == 0) {
+ LOG(INFO) << "Requesting properties messages on service '" << path << "'";
+ device_mon = chromeos::MonitorNetworkService(&CallbackMonitorNetwork::Run,
+ path, NULL);
+ if (clear) {
+ LOG(INFO) << "Clearing property '" << property << "' on '" << path << "'";
+ chromeos::ClearNetworkServiceProperty(path, property);
+ } else {
+ LOG(INFO) << "Setting property '" << property << "' on '" << path << "'";
+ chromeos::SetNetworkServiceProperty(path, property,
+ Value::CreateStringValue(value));
+ }
+ } else if (strncmp(path, "/device/", 8) == 0) {
+ LOG(INFO) << "Requesting properties messages on device '" << path << "'";
+ device_mon = chromeos::MonitorNetworkDevice(&CallbackMonitorNetwork::Run,
+ path, NULL);
+ if (clear) {
+ LOG(INFO) << "Clearing property '" << property << "' on '" << path << "'";
+ chromeos::ClearNetworkDeviceProperty(path, property);
+ } else {
+ LOG(INFO) << "Setting property '" << property << "' on '" << path << "'";
+ chromeos::SetNetworkDeviceProperty(path, property,
+ Value::CreateStringValue(value));
+ }
+ } else {
+ LOG(INFO) << "Don't know what to do with path '" << path << "' "
+ << "neither a device nor a service";
+ return 1;
+ }
+
+ LOG(INFO) << "Starting g_main_loop.";
+
+ ::g_main_loop_run(loop);
+
+ LOG(INFO) << "Shutting down.";
+
+ chromeos::DisconnectPropertyChangeMonitor(device_mon);
+ return 0;
+}
« no previous file with comments | « load.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698