Commit 34928ece authored by Abhishek Bhardwaj's avatar Abhishek Bhardwaj Committed by Commit Bot

dbus: Clang format files

Clang format message logic files.

BUG=None
TEST=Compile.

Change-Id: Ia13728381fd16705fba8091236622a42e7e59f0e
Reviewed-on: https://chromium-review.googlesource.com/1069685Reviewed-by: default avatarRyo Hashimoto <hashimoto@chromium.org>
Commit-Queue: Abhishek Bhardwaj <abhishekbh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560989}
parent b6d0db42
...@@ -218,8 +218,8 @@ std::string Message::ToStringInternal(const std::string& indent, ...@@ -218,8 +218,8 @@ std::string Message::ToStringInternal(const std::string& indent,
base::ScopedFD file_descriptor; base::ScopedFD file_descriptor;
if (!reader->PopFileDescriptor(&file_descriptor)) if (!reader->PopFileDescriptor(&file_descriptor))
return kBrokenMessage; return kBrokenMessage;
output += indent + "fd#" + output +=
base::IntToString(file_descriptor.get()) + "\n"; indent + "fd#" + base::IntToString(file_descriptor.get()) + "\n";
break; break;
} }
default: default:
...@@ -428,9 +428,8 @@ std::unique_ptr<ErrorResponse> ErrorResponse::FromMethodCall( ...@@ -428,9 +428,8 @@ std::unique_ptr<ErrorResponse> ErrorResponse::FromMethodCall(
const std::string& error_name, const std::string& error_name,
const std::string& error_message) { const std::string& error_message) {
std::unique_ptr<ErrorResponse> response(new ErrorResponse()); std::unique_ptr<ErrorResponse> response(new ErrorResponse());
response->Init(dbus_message_new_error(method_call->raw_message(), response->Init(dbus_message_new_error(
error_name.c_str(), method_call->raw_message(), error_name.c_str(), error_message.c_str()));
error_message.c_str()));
return response; return response;
} }
...@@ -439,8 +438,7 @@ std::unique_ptr<ErrorResponse> ErrorResponse::FromMethodCall( ...@@ -439,8 +438,7 @@ std::unique_ptr<ErrorResponse> ErrorResponse::FromMethodCall(
// //
MessageWriter::MessageWriter(Message* message) MessageWriter::MessageWriter(Message* message)
: message_(message), : message_(message), container_is_open_(false) {
container_is_open_(false) {
memset(&raw_message_iter_, 0, sizeof(raw_message_iter_)); memset(&raw_message_iter_, 0, sizeof(raw_message_iter_));
if (message) if (message)
dbus_message_iter_init_append(message_->raw_message(), &raw_message_iter_); dbus_message_iter_init_append(message_->raw_message(), &raw_message_iter_);
...@@ -519,9 +517,7 @@ void MessageWriter::OpenArray(const std::string& signature, ...@@ -519,9 +517,7 @@ void MessageWriter::OpenArray(const std::string& signature,
DCHECK(!container_is_open_); DCHECK(!container_is_open_);
const bool success = dbus_message_iter_open_container( const bool success = dbus_message_iter_open_container(
&raw_message_iter_, &raw_message_iter_, DBUS_TYPE_ARRAY, signature.c_str(),
DBUS_TYPE_ARRAY,
signature.c_str(),
&writer->raw_message_iter_); &writer->raw_message_iter_);
CHECK(success) << "Unable to allocate memory"; CHECK(success) << "Unable to allocate memory";
container_is_open_ = true; container_is_open_ = true;
...@@ -532,9 +528,7 @@ void MessageWriter::OpenVariant(const std::string& signature, ...@@ -532,9 +528,7 @@ void MessageWriter::OpenVariant(const std::string& signature,
DCHECK(!container_is_open_); DCHECK(!container_is_open_);
const bool success = dbus_message_iter_open_container( const bool success = dbus_message_iter_open_container(
&raw_message_iter_, &raw_message_iter_, DBUS_TYPE_VARIANT, signature.c_str(),
DBUS_TYPE_VARIANT,
signature.c_str(),
&writer->raw_message_iter_); &writer->raw_message_iter_);
CHECK(success) << "Unable to allocate memory"; CHECK(success) << "Unable to allocate memory";
container_is_open_ = true; container_is_open_ = true;
...@@ -576,9 +570,7 @@ void MessageWriter::AppendArrayOfBytes(const uint8_t* values, size_t length) { ...@@ -576,9 +570,7 @@ void MessageWriter::AppendArrayOfBytes(const uint8_t* values, size_t length) {
MessageWriter array_writer(message_); MessageWriter array_writer(message_);
OpenArray("y", &array_writer); OpenArray("y", &array_writer);
const bool success = dbus_message_iter_append_fixed_array( const bool success = dbus_message_iter_append_fixed_array(
&(array_writer.raw_message_iter_), &(array_writer.raw_message_iter_), DBUS_TYPE_BYTE, &values,
DBUS_TYPE_BYTE,
&values,
static_cast<int>(length)); static_cast<int>(length));
CHECK(success) << "Unable to allocate memory"; CHECK(success) << "Unable to allocate memory";
CloseContainer(&array_writer); CloseContainer(&array_writer);
...@@ -589,9 +581,7 @@ void MessageWriter::AppendArrayOfDoubles(const double* values, size_t length) { ...@@ -589,9 +581,7 @@ void MessageWriter::AppendArrayOfDoubles(const double* values, size_t length) {
MessageWriter array_writer(message_); MessageWriter array_writer(message_);
OpenArray("d", &array_writer); OpenArray("d", &array_writer);
const bool success = dbus_message_iter_append_fixed_array( const bool success = dbus_message_iter_append_fixed_array(
&(array_writer.raw_message_iter_), &(array_writer.raw_message_iter_), DBUS_TYPE_DOUBLE, &values,
DBUS_TYPE_DOUBLE,
&values,
static_cast<int>(length)); static_cast<int>(length));
CHECK(success) << "Unable to allocate memory"; CHECK(success) << "Unable to allocate memory";
CloseContainer(&array_writer); CloseContainer(&array_writer);
...@@ -682,8 +672,8 @@ void MessageWriter::AppendVariantOfObjectPath(const ObjectPath& value) { ...@@ -682,8 +672,8 @@ void MessageWriter::AppendVariantOfObjectPath(const ObjectPath& value) {
void MessageWriter::AppendBasic(int dbus_type, const void* value) { void MessageWriter::AppendBasic(int dbus_type, const void* value) {
DCHECK(!container_is_open_); DCHECK(!container_is_open_);
const bool success = dbus_message_iter_append_basic( const bool success =
&raw_message_iter_, dbus_type, value); dbus_message_iter_append_basic(&raw_message_iter_, dbus_type, value);
// dbus_message_iter_append_basic() fails only when there is not enough // dbus_message_iter_append_basic() fails only when there is not enough
// memory. We don't return this error as there is nothing we can do when // memory. We don't return this error as there is nothing we can do when
// it fails to allocate memory for a byte etc. // it fails to allocate memory for a byte etc.
...@@ -708,8 +698,7 @@ void MessageWriter::AppendFileDescriptor(int value) { ...@@ -708,8 +698,7 @@ void MessageWriter::AppendFileDescriptor(int value) {
// MessageReader implementation. // MessageReader implementation.
// //
MessageReader::MessageReader(Message* message) MessageReader::MessageReader(Message* message) : message_(message) {
: message_(message) {
memset(&raw_message_iter_, 0, sizeof(raw_message_iter_)); memset(&raw_message_iter_, 0, sizeof(raw_message_iter_));
if (message) if (message)
dbus_message_iter_init(message_->raw_message(), &raw_message_iter_); dbus_message_iter_init(message_->raw_message(), &raw_message_iter_);
...@@ -809,8 +798,7 @@ bool MessageReader::PopArrayOfBytes(const uint8_t** bytes, size_t* length) { ...@@ -809,8 +798,7 @@ bool MessageReader::PopArrayOfBytes(const uint8_t** bytes, size_t* length) {
if (!array_reader.CheckDataType(DBUS_TYPE_BYTE)) if (!array_reader.CheckDataType(DBUS_TYPE_BYTE))
return false; return false;
int int_length = 0; int int_length = 0;
dbus_message_iter_get_fixed_array(&array_reader.raw_message_iter_, dbus_message_iter_get_fixed_array(&array_reader.raw_message_iter_, bytes,
bytes,
&int_length); &int_length);
*length = static_cast<size_t>(int_length); *length = static_cast<size_t>(int_length);
return true; return true;
...@@ -828,15 +816,13 @@ bool MessageReader::PopArrayOfDoubles(const double** doubles, size_t* length) { ...@@ -828,15 +816,13 @@ bool MessageReader::PopArrayOfDoubles(const double** doubles, size_t* length) {
if (!array_reader.CheckDataType(DBUS_TYPE_DOUBLE)) if (!array_reader.CheckDataType(DBUS_TYPE_DOUBLE))
return false; return false;
int int_length = 0; int int_length = 0;
dbus_message_iter_get_fixed_array(&array_reader.raw_message_iter_, dbus_message_iter_get_fixed_array(&array_reader.raw_message_iter_, doubles,
doubles,
&int_length); &int_length);
*length = static_cast<size_t>(int_length); *length = static_cast<size_t>(int_length);
return true; return true;
} }
bool MessageReader::PopArrayOfStrings( bool MessageReader::PopArrayOfStrings(std::vector<std::string>* strings) {
std::vector<std::string> *strings) {
strings->clear(); strings->clear();
MessageReader array_reader(message_); MessageReader array_reader(message_);
if (!PopArray(&array_reader)) if (!PopArray(&array_reader))
...@@ -851,7 +837,7 @@ bool MessageReader::PopArrayOfStrings( ...@@ -851,7 +837,7 @@ bool MessageReader::PopArrayOfStrings(
} }
bool MessageReader::PopArrayOfObjectPaths( bool MessageReader::PopArrayOfObjectPaths(
std::vector<ObjectPath> *object_paths) { std::vector<ObjectPath>* object_paths) {
object_paths->clear(); object_paths->clear();
MessageReader array_reader(message_); MessageReader array_reader(message_);
if (!PopArray(&array_reader)) if (!PopArray(&array_reader))
...@@ -956,8 +942,7 @@ std::string MessageReader::GetDataSignature() { ...@@ -956,8 +942,7 @@ std::string MessageReader::GetDataSignature() {
bool MessageReader::CheckDataType(int dbus_type) { bool MessageReader::CheckDataType(int dbus_type) {
const int actual_type = dbus_message_iter_get_arg_type(&raw_message_iter_); const int actual_type = dbus_message_iter_get_arg_type(&raw_message_iter_);
if (actual_type != dbus_type) { if (actual_type != dbus_type) {
VLOG(1) << "Type " << dbus_type << " is expected but got " VLOG(1) << "Type " << dbus_type << " is expected but got " << actual_type;
<< actual_type;
return false; return false;
} }
return true; return true;
...@@ -980,8 +965,7 @@ bool MessageReader::PopContainer(int dbus_type, MessageReader* sub_reader) { ...@@ -980,8 +965,7 @@ bool MessageReader::PopContainer(int dbus_type, MessageReader* sub_reader) {
if (!CheckDataType(dbus_type)) if (!CheckDataType(dbus_type))
return false; return false;
dbus_message_iter_recurse(&raw_message_iter_, dbus_message_iter_recurse(&raw_message_iter_, &sub_reader->raw_message_iter_);
&sub_reader->raw_message_iter_);
dbus_message_iter_next(&raw_message_iter_); dbus_message_iter_next(&raw_message_iter_);
return true; return true;
} }
......
...@@ -26,7 +26,6 @@ class MessageLite; ...@@ -26,7 +26,6 @@ class MessageLite;
} // namespace protobuf } // namespace protobuf
} // namespace google } // namespace google
namespace dbus { namespace dbus {
class MessageWriter; class MessageWriter;
...@@ -34,7 +33,7 @@ class MessageReader; ...@@ -34,7 +33,7 @@ class MessageReader;
// DBUS_TYPE_UNIX_FD was added in D-Bus version 1.4 // DBUS_TYPE_UNIX_FD was added in D-Bus version 1.4
#if !defined(DBUS_TYPE_UNIX_FD) #if !defined(DBUS_TYPE_UNIX_FD)
#define DBUS_TYPE_UNIX_FD ((int) 'h') #define DBUS_TYPE_UNIX_FD ((int)'h')
#endif #endif
// Returns true if Unix FD passing is supported in libdbus. // Returns true if Unix FD passing is supported in libdbus.
...@@ -154,8 +153,7 @@ class CHROME_DBUS_EXPORT MethodCall : public Message { ...@@ -154,8 +153,7 @@ class CHROME_DBUS_EXPORT MethodCall : public Message {
// MethodCall method_call(DBUS_INTERFACE_INTROSPECTABLE, "Get"); // MethodCall method_call(DBUS_INTERFACE_INTROSPECTABLE, "Get");
// //
// The constructor creates the internal raw message. // The constructor creates the internal raw message.
MethodCall(const std::string& interface_name, MethodCall(const std::string& interface_name, const std::string& method_name);
const std::string& method_name);
// Returns a newly created MethodCall from the given raw message of the // Returns a newly created MethodCall from the given raw message of the
// type DBUS_MESSAGE_TYPE_METHOD_CALL. Takes the ownership of |raw_message|. // type DBUS_MESSAGE_TYPE_METHOD_CALL. Takes the ownership of |raw_message|.
...@@ -182,8 +180,7 @@ class CHROME_DBUS_EXPORT Signal : public Message { ...@@ -182,8 +180,7 @@ class CHROME_DBUS_EXPORT Signal : public Message {
// Signal signal(DBUS_INTERFACE_INTROSPECTABLE, "PropertiesChanged"); // Signal signal(DBUS_INTERFACE_INTROSPECTABLE, "PropertiesChanged");
// //
// The constructor creates the internal raw_message_. // The constructor creates the internal raw_message_.
Signal(const std::string& interface_name, Signal(const std::string& interface_name, const std::string& method_name);
const std::string& method_name);
// Returns a newly created SIGNAL from the given raw message of the type // Returns a newly created SIGNAL from the given raw message of the type
// DBUS_MESSAGE_TYPE_SIGNAL. Takes the ownership of |raw_message|. // DBUS_MESSAGE_TYPE_SIGNAL. Takes the ownership of |raw_message|.
...@@ -224,7 +221,7 @@ class CHROME_DBUS_EXPORT Response : public Message { ...@@ -224,7 +221,7 @@ class CHROME_DBUS_EXPORT Response : public Message {
// ErrorResponse is a type of message used to return an error to the // ErrorResponse is a type of message used to return an error to the
// caller of a method. // caller of a method.
class CHROME_DBUS_EXPORT ErrorResponse: public Response { class CHROME_DBUS_EXPORT ErrorResponse : public Response {
public: public:
// Returns a newly created Response from the given raw message of the // Returns a newly created Response from the given raw message of the
// type DBUS_MESSAGE_TYPE_METHOD_RETURN. Takes the ownership of |raw_message|. // type DBUS_MESSAGE_TYPE_METHOD_RETURN. Takes the ownership of |raw_message|.
...@@ -485,7 +482,7 @@ class CHROME_DBUS_EXPORT MessageReader { ...@@ -485,7 +482,7 @@ class CHROME_DBUS_EXPORT MessageReader {
bool CheckDataType(int dbus_type); bool CheckDataType(int dbus_type);
// Helper function used to implement PopByte() etc. // Helper function used to implement PopByte() etc.
bool PopBasic(int dbus_type, void *value); bool PopBasic(int dbus_type, void* value);
// Helper function used to implement PopArray() etc. // Helper function used to implement PopArray() etc.
bool PopContainer(int dbus_type, MessageReader* sub_reader); bool PopContainer(int dbus_type, MessageReader* sub_reader);
......
...@@ -335,7 +335,6 @@ TEST(MessageTest, ProtoBuf) { ...@@ -335,7 +335,6 @@ TEST(MessageTest, ProtoBuf) {
EXPECT_EQ(receive_message.number(), send_message.number()); EXPECT_EQ(receive_message.number(), send_message.number());
} }
// Test that an array can be properly written and read. We only have this // Test that an array can be properly written and read. We only have this
// test for array, as repeating this for other container types is too // test for array, as repeating this for other container types is too
// redundant. // redundant.
...@@ -512,7 +511,8 @@ TEST(MessageTest, MethodCall) { ...@@ -512,7 +511,8 @@ TEST(MessageTest, MethodCall) {
MessageWriter writer(&method_call); MessageWriter writer(&method_call);
writer.AppendString("payload"); writer.AppendString("payload");
EXPECT_EQ("message_type: MESSAGE_METHOD_CALL\n" EXPECT_EQ(
"message_type: MESSAGE_METHOD_CALL\n"
"destination: com.example.Service\n" "destination: com.example.Service\n"
"path: /com/example/Object\n" "path: /com/example/Object\n"
"interface: com.example.Interface\n" "interface: com.example.Interface\n"
...@@ -544,7 +544,8 @@ TEST(MessageTest, Signal) { ...@@ -544,7 +544,8 @@ TEST(MessageTest, Signal) {
MessageWriter writer(&signal); MessageWriter writer(&signal);
writer.AppendString("payload"); writer.AppendString("payload");
EXPECT_EQ("message_type: MESSAGE_SIGNAL\n" EXPECT_EQ(
"message_type: MESSAGE_SIGNAL\n"
"path: /com/example/Object\n" "path: /com/example/Object\n"
"interface: com.example.Interface\n" "interface: com.example.Interface\n"
"member: SomeSignal\n" "member: SomeSignal\n"
...@@ -585,7 +586,7 @@ TEST(MessageTest, Response_FromMethodCall) { ...@@ -585,7 +586,7 @@ TEST(MessageTest, Response_FromMethodCall) {
TEST(MessageTest, ErrorResponse_FromMethodCall) { TEST(MessageTest, ErrorResponse_FromMethodCall) {
const uint32_t kSerial = 123; const uint32_t kSerial = 123;
const char kErrorMessage[] = "error message"; const char kErrorMessage[] = "error message";
MethodCall method_call("com.example.Interface", "SomeMethod"); MethodCall method_call("com.example.Interface", "SomeMethod");
method_call.SetSerial(kSerial); method_call.SetSerial(kSerial);
...@@ -672,7 +673,8 @@ TEST(MessageTest, ToString_LongString) { ...@@ -672,7 +673,8 @@ TEST(MessageTest, ToString_LongString) {
MessageWriter writer(message.get()); MessageWriter writer(message.get());
writer.AppendString(kLongString); writer.AppendString(kLongString);
ASSERT_EQ("message_type: MESSAGE_METHOD_RETURN\n" ASSERT_EQ(
"message_type: MESSAGE_METHOD_RETURN\n"
"signature: s\n\n" "signature: s\n\n"
"string \"oooooooooooooooooooooooooooooooooooooooooooooooo" "string \"oooooooooooooooooooooooooooooooooooooooooooooooo"
"oooooooooooooooooooooooooooooooooooooooooooooooooooo... " "oooooooooooooooooooooooooooooooooooooooooooooooooooo... "
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment