Skip to content

Commit

Permalink
dbus: Clang format files
Browse files Browse the repository at this point in the history
Clang format message logic files.

BUG=None
TEST=Compile.

Change-Id: Ia13728381fd16705fba8091236622a42e7e59f0e
Reviewed-on: https://chromium-review.googlesource.com/1069685
Reviewed-by: Ryo Hashimoto <hashimoto@chromium.org>
Commit-Queue: Abhishek Bhardwaj <abhishekbh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560989}
  • Loading branch information
Abhishek Bhardwaj authored and Commit Bot committed May 23, 2018
1 parent b6d0db4 commit 34928ec
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 70 deletions.
54 changes: 19 additions & 35 deletions dbus/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ std::string Message::ToStringInternal(const std::string& indent,
base::ScopedFD file_descriptor;
if (!reader->PopFileDescriptor(&file_descriptor))
return kBrokenMessage;
output += indent + "fd#" +
base::IntToString(file_descriptor.get()) + "\n";
output +=
indent + "fd#" + base::IntToString(file_descriptor.get()) + "\n";
break;
}
default:
Expand Down Expand Up @@ -428,9 +428,8 @@ std::unique_ptr<ErrorResponse> ErrorResponse::FromMethodCall(
const std::string& error_name,
const std::string& error_message) {
std::unique_ptr<ErrorResponse> response(new ErrorResponse());
response->Init(dbus_message_new_error(method_call->raw_message(),
error_name.c_str(),
error_message.c_str()));
response->Init(dbus_message_new_error(
method_call->raw_message(), error_name.c_str(), error_message.c_str()));
return response;
}

Expand All @@ -439,8 +438,7 @@ std::unique_ptr<ErrorResponse> ErrorResponse::FromMethodCall(
//

MessageWriter::MessageWriter(Message* message)
: message_(message),
container_is_open_(false) {
: message_(message), container_is_open_(false) {
memset(&raw_message_iter_, 0, sizeof(raw_message_iter_));
if (message)
dbus_message_iter_init_append(message_->raw_message(), &raw_message_iter_);
Expand Down Expand Up @@ -519,9 +517,7 @@ void MessageWriter::OpenArray(const std::string& signature,
DCHECK(!container_is_open_);

const bool success = dbus_message_iter_open_container(
&raw_message_iter_,
DBUS_TYPE_ARRAY,
signature.c_str(),
&raw_message_iter_, DBUS_TYPE_ARRAY, signature.c_str(),
&writer->raw_message_iter_);
CHECK(success) << "Unable to allocate memory";
container_is_open_ = true;
Expand All @@ -532,9 +528,7 @@ void MessageWriter::OpenVariant(const std::string& signature,
DCHECK(!container_is_open_);

const bool success = dbus_message_iter_open_container(
&raw_message_iter_,
DBUS_TYPE_VARIANT,
signature.c_str(),
&raw_message_iter_, DBUS_TYPE_VARIANT, signature.c_str(),
&writer->raw_message_iter_);
CHECK(success) << "Unable to allocate memory";
container_is_open_ = true;
Expand Down Expand Up @@ -576,9 +570,7 @@ void MessageWriter::AppendArrayOfBytes(const uint8_t* values, size_t length) {
MessageWriter array_writer(message_);
OpenArray("y", &array_writer);
const bool success = dbus_message_iter_append_fixed_array(
&(array_writer.raw_message_iter_),
DBUS_TYPE_BYTE,
&values,
&(array_writer.raw_message_iter_), DBUS_TYPE_BYTE, &values,
static_cast<int>(length));
CHECK(success) << "Unable to allocate memory";
CloseContainer(&array_writer);
Expand All @@ -589,9 +581,7 @@ void MessageWriter::AppendArrayOfDoubles(const double* values, size_t length) {
MessageWriter array_writer(message_);
OpenArray("d", &array_writer);
const bool success = dbus_message_iter_append_fixed_array(
&(array_writer.raw_message_iter_),
DBUS_TYPE_DOUBLE,
&values,
&(array_writer.raw_message_iter_), DBUS_TYPE_DOUBLE, &values,
static_cast<int>(length));
CHECK(success) << "Unable to allocate memory";
CloseContainer(&array_writer);
Expand Down Expand Up @@ -682,8 +672,8 @@ void MessageWriter::AppendVariantOfObjectPath(const ObjectPath& value) {
void MessageWriter::AppendBasic(int dbus_type, const void* value) {
DCHECK(!container_is_open_);

const bool success = dbus_message_iter_append_basic(
&raw_message_iter_, dbus_type, value);
const bool success =
dbus_message_iter_append_basic(&raw_message_iter_, dbus_type, value);
// 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
// it fails to allocate memory for a byte etc.
Expand All @@ -708,8 +698,7 @@ void MessageWriter::AppendFileDescriptor(int value) {
// MessageReader implementation.
//

MessageReader::MessageReader(Message* message)
: message_(message) {
MessageReader::MessageReader(Message* message) : message_(message) {
memset(&raw_message_iter_, 0, sizeof(raw_message_iter_));
if (message)
dbus_message_iter_init(message_->raw_message(), &raw_message_iter_);
Expand Down Expand Up @@ -799,7 +788,7 @@ bool MessageReader::PopVariant(MessageReader* sub_reader) {
bool MessageReader::PopArrayOfBytes(const uint8_t** bytes, size_t* length) {
MessageReader array_reader(message_);
if (!PopArray(&array_reader))
return false;
return false;
// An empty array is allowed.
if (!array_reader.HasMoreData()) {
*length = 0;
Expand All @@ -809,8 +798,7 @@ bool MessageReader::PopArrayOfBytes(const uint8_t** bytes, size_t* length) {
if (!array_reader.CheckDataType(DBUS_TYPE_BYTE))
return false;
int int_length = 0;
dbus_message_iter_get_fixed_array(&array_reader.raw_message_iter_,
bytes,
dbus_message_iter_get_fixed_array(&array_reader.raw_message_iter_, bytes,
&int_length);
*length = static_cast<size_t>(int_length);
return true;
Expand All @@ -828,15 +816,13 @@ bool MessageReader::PopArrayOfDoubles(const double** doubles, size_t* length) {
if (!array_reader.CheckDataType(DBUS_TYPE_DOUBLE))
return false;
int int_length = 0;
dbus_message_iter_get_fixed_array(&array_reader.raw_message_iter_,
doubles,
dbus_message_iter_get_fixed_array(&array_reader.raw_message_iter_, doubles,
&int_length);
*length = static_cast<size_t>(int_length);
return true;
}

bool MessageReader::PopArrayOfStrings(
std::vector<std::string> *strings) {
bool MessageReader::PopArrayOfStrings(std::vector<std::string>* strings) {
strings->clear();
MessageReader array_reader(message_);
if (!PopArray(&array_reader))
Expand All @@ -851,7 +837,7 @@ bool MessageReader::PopArrayOfStrings(
}

bool MessageReader::PopArrayOfObjectPaths(
std::vector<ObjectPath> *object_paths) {
std::vector<ObjectPath>* object_paths) {
object_paths->clear();
MessageReader array_reader(message_);
if (!PopArray(&array_reader))
Expand Down Expand Up @@ -956,8 +942,7 @@ std::string MessageReader::GetDataSignature() {
bool MessageReader::CheckDataType(int dbus_type) {
const int actual_type = dbus_message_iter_get_arg_type(&raw_message_iter_);
if (actual_type != dbus_type) {
VLOG(1) << "Type " << dbus_type << " is expected but got "
<< actual_type;
VLOG(1) << "Type " << dbus_type << " is expected but got " << actual_type;
return false;
}
return true;
Expand All @@ -980,8 +965,7 @@ bool MessageReader::PopContainer(int dbus_type, MessageReader* sub_reader) {

if (!CheckDataType(dbus_type))
return false;
dbus_message_iter_recurse(&raw_message_iter_,
&sub_reader->raw_message_iter_);
dbus_message_iter_recurse(&raw_message_iter_, &sub_reader->raw_message_iter_);
dbus_message_iter_next(&raw_message_iter_);
return true;
}
Expand Down
15 changes: 6 additions & 9 deletions dbus/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ class MessageLite;
} // namespace protobuf
} // namespace google


namespace dbus {

class MessageWriter;
class MessageReader;

// DBUS_TYPE_UNIX_FD was added in D-Bus version 1.4
#if !defined(DBUS_TYPE_UNIX_FD)
#define DBUS_TYPE_UNIX_FD ((int) 'h')
#define DBUS_TYPE_UNIX_FD ((int)'h')
#endif

// Returns true if Unix FD passing is supported in libdbus.
Expand All @@ -61,7 +60,7 @@ class CHROME_DBUS_EXPORT Message {
MESSAGE_METHOD_RETURN = DBUS_MESSAGE_TYPE_METHOD_RETURN,
MESSAGE_SIGNAL = DBUS_MESSAGE_TYPE_SIGNAL,
MESSAGE_ERROR = DBUS_MESSAGE_TYPE_ERROR,
};
};

// The data type used in the D-Bus type system. See the comment at
// MessageType for why we are redefining data types here.
Expand Down Expand Up @@ -154,8 +153,7 @@ class CHROME_DBUS_EXPORT MethodCall : public Message {
// MethodCall method_call(DBUS_INTERFACE_INTROSPECTABLE, "Get");
//
// The constructor creates the internal raw message.
MethodCall(const std::string& interface_name,
const std::string& method_name);
MethodCall(const std::string& interface_name, const std::string& method_name);

// Returns a newly created MethodCall from the given raw message of the
// type DBUS_MESSAGE_TYPE_METHOD_CALL. Takes the ownership of |raw_message|.
Expand All @@ -182,8 +180,7 @@ class CHROME_DBUS_EXPORT Signal : public Message {
// Signal signal(DBUS_INTERFACE_INTROSPECTABLE, "PropertiesChanged");
//
// The constructor creates the internal raw_message_.
Signal(const std::string& interface_name,
const std::string& method_name);
Signal(const std::string& interface_name, const std::string& method_name);

// Returns a newly created SIGNAL from the given raw message of the type
// DBUS_MESSAGE_TYPE_SIGNAL. Takes the ownership of |raw_message|.
Expand Down Expand Up @@ -224,7 +221,7 @@ class CHROME_DBUS_EXPORT Response : public Message {

// ErrorResponse is a type of message used to return an error to the
// caller of a method.
class CHROME_DBUS_EXPORT ErrorResponse: public Response {
class CHROME_DBUS_EXPORT ErrorResponse : public Response {
public:
// Returns a newly created Response from the given raw message of the
// type DBUS_MESSAGE_TYPE_METHOD_RETURN. Takes the ownership of |raw_message|.
Expand Down Expand Up @@ -485,7 +482,7 @@ class CHROME_DBUS_EXPORT MessageReader {
bool CheckDataType(int dbus_type);

// 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.
bool PopContainer(int dbus_type, MessageReader* sub_reader);
Expand Down
54 changes: 28 additions & 26 deletions dbus/message_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ TEST(MessageTest, AppendAndPopByte) {

uint8_t byte_value = 0;
ASSERT_TRUE(reader.PopByte(&byte_value));
EXPECT_EQ(123, byte_value); // Should match with the input.
EXPECT_EQ(123, byte_value); // Should match with the input.
ASSERT_FALSE(reader.HasMoreData()); // Should not have more data to read.

// Try to get another byte. Should fail.
Expand Down Expand Up @@ -335,7 +335,6 @@ TEST(MessageTest, ProtoBuf) {
EXPECT_EQ(receive_message.number(), send_message.number());
}


// 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
// redundant.
Expand Down Expand Up @@ -512,15 +511,16 @@ TEST(MessageTest, MethodCall) {
MessageWriter writer(&method_call);
writer.AppendString("payload");

EXPECT_EQ("message_type: MESSAGE_METHOD_CALL\n"
"destination: com.example.Service\n"
"path: /com/example/Object\n"
"interface: com.example.Interface\n"
"member: SomeMethod\n"
"signature: s\n"
"\n"
"string \"payload\"\n",
method_call.ToString());
EXPECT_EQ(
"message_type: MESSAGE_METHOD_CALL\n"
"destination: com.example.Service\n"
"path: /com/example/Object\n"
"interface: com.example.Interface\n"
"member: SomeMethod\n"
"signature: s\n"
"\n"
"string \"payload\"\n",
method_call.ToString());
}

TEST(MessageTest, MethodCall_FromRawMessage) {
Expand All @@ -544,14 +544,15 @@ TEST(MessageTest, Signal) {
MessageWriter writer(&signal);
writer.AppendString("payload");

EXPECT_EQ("message_type: MESSAGE_SIGNAL\n"
"path: /com/example/Object\n"
"interface: com.example.Interface\n"
"member: SomeSignal\n"
"signature: s\n"
"\n"
"string \"payload\"\n",
signal.ToString());
EXPECT_EQ(
"message_type: MESSAGE_SIGNAL\n"
"path: /com/example/Object\n"
"interface: com.example.Interface\n"
"member: SomeSignal\n"
"signature: s\n"
"\n"
"string \"payload\"\n",
signal.ToString());
}

TEST(MessageTest, Signal_FromRawMessage) {
Expand Down Expand Up @@ -585,7 +586,7 @@ TEST(MessageTest, Response_FromMethodCall) {

TEST(MessageTest, ErrorResponse_FromMethodCall) {
const uint32_t kSerial = 123;
const char kErrorMessage[] = "error message";
const char kErrorMessage[] = "error message";

MethodCall method_call("com.example.Interface", "SomeMethod");
method_call.SetSerial(kSerial);
Expand Down Expand Up @@ -672,12 +673,13 @@ TEST(MessageTest, ToString_LongString) {
MessageWriter writer(message.get());
writer.AppendString(kLongString);

ASSERT_EQ("message_type: MESSAGE_METHOD_RETURN\n"
"signature: s\n\n"
"string \"oooooooooooooooooooooooooooooooooooooooooooooooo"
"oooooooooooooooooooooooooooooooooooooooooooooooooooo... "
"(1000 bytes in total)\"\n",
message->ToString());
ASSERT_EQ(
"message_type: MESSAGE_METHOD_RETURN\n"
"signature: s\n\n"
"string \"oooooooooooooooooooooooooooooooooooooooooooooooo"
"oooooooooooooooooooooooooooooooooooooooooooooooooooo... "
"(1000 bytes in total)\"\n",
message->ToString());
}

} // namespace dbus

0 comments on commit 34928ec

Please sign in to comment.