diff options
author | dpapad@chromium.org <dpapad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-14 20:22:53 +0000 |
---|---|---|
committer | dpapad@chromium.org <dpapad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-14 20:22:53 +0000 |
commit | 02743b707e2743cd0f0916e3b405191a48fa3947 (patch) | |
tree | 2b0c0be422f99a2e0dce81c6de92f9a8bc80b969 /dbus/message.cc | |
parent | 7f58f3f417a0598ad796ca7de7b14a38252d91bd (diff) | |
download | chromium_src-02743b707e2743cd0f0916e3b405191a48fa3947.zip chromium_src-02743b707e2743cd0f0916e3b405191a48fa3947.tar.gz chromium_src-02743b707e2743cd0f0916e3b405191a48fa3947.tar.bz2 |
Revert 121920 - dbus: add ObjectPath type
Rather than use std::string for object paths, add a dbus::ObjectPath type
that wraps one while allowing more type-safety. This solves all sorts of
issues with confusing object paths for strings, and allows us to do
Properties code using templates disambiguating them from strings.
BUG=chromium:109194
TEST=built and run tests
Change-Id: Icaf6f19daea4af23a9d2ec0ed76d2cbd379d680e
Review URL: http://codereview.chromium.org/9378039
TBR=keybuk@chromium.org
Review URL: https://chromiumcodereview.appspot.com/9363045
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121923 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'dbus/message.cc')
-rw-r--r-- | dbus/message.cc | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/dbus/message.cc b/dbus/message.cc index 486538a..4a94b54 100644 --- a/dbus/message.cc +++ b/dbus/message.cc @@ -10,7 +10,6 @@ #include "base/format_macros.h" #include "base/logging.h" #include "base/stringprintf.h" -#include "dbus/object_path.h" #include "third_party/protobuf/src/google/protobuf/message_lite.h" namespace { @@ -158,10 +157,10 @@ std::string Message::ToStringInternal(const std::string& indent, break; } case OBJECT_PATH: { - ObjectPath value; + std::string value; if (!reader->PopObjectPath(&value)) return kBrokenMessage; - output += indent + "object_path \"" + value.value() + "\"\n"; + output += indent + "object_path \"" + value + "\"\n"; break; } case ARRAY: { @@ -225,7 +224,7 @@ std::string Message::ToString() { std::string headers; AppendStringHeader("message_type", GetMessageTypeAsString(), &headers); AppendStringHeader("destination", GetDestination(), &headers); - AppendStringHeader("path", GetPath().value(), &headers); + AppendStringHeader("path", GetPath(), &headers); AppendStringHeader("interface", GetInterface(), &headers); AppendStringHeader("member", GetMember(), &headers); AppendStringHeader("error_name", GetErrorName(), &headers); @@ -245,9 +244,9 @@ void Message::SetDestination(const std::string& destination) { CHECK(success) << "Unable to allocate memory"; } -void Message::SetPath(const ObjectPath& path) { +void Message::SetPath(const std::string& path) { const bool success = dbus_message_set_path(raw_message_, - path.value().c_str()); + path.c_str()); CHECK(success) << "Unable to allocate memory"; } @@ -288,9 +287,9 @@ std::string Message::GetDestination() { return destination ? destination : ""; } -ObjectPath Message::GetPath() { +std::string Message::GetPath() { const char* path = dbus_message_get_path(raw_message_); - return ObjectPath(path ? path : ""); + return path ? path : ""; } std::string Message::GetInterface() { @@ -491,8 +490,8 @@ void MessageWriter::AppendString(const std::string& value) { // bool AppendStringWithErrorChecking(). } -void MessageWriter::AppendObjectPath(const ObjectPath& value) { - const char* pointer = value.value().c_str(); +void MessageWriter::AppendObjectPath(const std::string& value) { + const char* pointer = value.c_str(); AppendBasic(DBUS_TYPE_OBJECT_PATH, &pointer); } @@ -588,7 +587,7 @@ void MessageWriter::AppendArrayOfStrings( } void MessageWriter::AppendArrayOfObjectPaths( - const std::vector<ObjectPath>& object_paths) { + const std::vector<std::string>& object_paths) { DCHECK(!container_is_open_); MessageWriter array_writer(message_); OpenArray("o", &array_writer); @@ -653,8 +652,8 @@ void MessageWriter::AppendVariantOfString(const std::string& value) { AppendVariantOfBasic(DBUS_TYPE_STRING, &pointer); } -void MessageWriter::AppendVariantOfObjectPath(const ObjectPath& value) { - const char* pointer = value.value().c_str(); +void MessageWriter::AppendVariantOfObjectPath(const std::string& value) { + const char* pointer = value.c_str(); AppendVariantOfBasic(DBUS_TYPE_OBJECT_PATH, &pointer); } @@ -747,11 +746,11 @@ bool MessageReader::PopString(std::string* value) { return success; } -bool MessageReader::PopObjectPath(ObjectPath* value) { +bool MessageReader::PopObjectPath(std::string* value) { char* tmp_value = NULL; const bool success = PopBasic(DBUS_TYPE_OBJECT_PATH, &tmp_value); if (success) - *value = ObjectPath(tmp_value); + value->assign(tmp_value); return success; } @@ -806,12 +805,12 @@ bool MessageReader::PopArrayOfStrings( } bool MessageReader::PopArrayOfObjectPaths( - std::vector<ObjectPath> *object_paths) { + std::vector<std::string> *object_paths) { MessageReader array_reader(message_); if (!PopArray(&array_reader)) return false; while (array_reader.HasMoreData()) { - ObjectPath object_path; + std::string object_path; if (!array_reader.PopObjectPath(&object_path)) return false; object_paths->push_back(object_path); @@ -883,11 +882,11 @@ bool MessageReader::PopVariantOfString(std::string* value) { return success; } -bool MessageReader::PopVariantOfObjectPath(ObjectPath* value) { +bool MessageReader::PopVariantOfObjectPath(std::string* value) { char* tmp_value = NULL; const bool success = PopVariantOfBasic(DBUS_TYPE_OBJECT_PATH, &tmp_value); if (success) - *value = ObjectPath(tmp_value); + value->assign(tmp_value); return success; } |