aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Langlois <pierre.langlois@arm.com>2015-03-09 12:10:52 +0000
committerPierre Langlois <pierre.langlois@arm.com>2016-03-04 17:48:44 +0000
commite795732d50fbdadbf1550bd3e476bb99fd2f9aa3 (patch)
tree00eec549ee024aee009d86431caac001f71ae839
parentbb10989825f7d545ab74b102c02daaf79cee323a (diff)
downloadkdbinder-e795732d50fbdadbf1550bd3e476bb99fd2f9aa3.tar.gz
libkdbinder: kdbus: comply with Google coding style
This commit is the result of running the cpplint.py script on every file in the project. Also, function/method calls and declaration were changed so they would not spread on so many lines. Change-Id: I6b732f1c58e0edd68bfb688e55ca4ba91ccdb736
-rw-r--r--include/kdbinder/kdbus/KDBinder.h6
-rw-r--r--include/kdbinder/kdbus/bus.h9
-rw-r--r--include/kdbinder/kdbus/connection.h48
-rw-r--r--include/kdbinder/kdbus/item.h10
-rw-r--r--include/kdbinder/kdbus/message.h48
-rw-r--r--libs/kdbinder/kdbus/bus.cpp14
-rw-r--r--libs/kdbinder/kdbus/command.h105
-rw-r--r--libs/kdbinder/kdbus/connection.cpp157
-rw-r--r--libs/kdbinder/kdbus/globals.h8
-rw-r--r--libs/kdbinder/kdbus/item.cpp7
-rw-r--r--libs/kdbinder/kdbus/iterable.cpp2
-rw-r--r--libs/kdbinder/kdbus/iterable.h9
-rw-r--r--libs/kdbinder/kdbus/message.cpp13
13 files changed, 162 insertions, 274 deletions
diff --git a/include/kdbinder/kdbus/KDBinder.h b/include/kdbinder/kdbus/KDBinder.h
index 24e9e08..4cbbe87 100644
--- a/include/kdbinder/kdbus/KDBinder.h
+++ b/include/kdbinder/kdbus/KDBinder.h
@@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#ifndef INCLUDE_KDBINDER_KDBINDER_H_
-#define INCLUDE_KDBINDER_KDBINDER_H_
+#ifndef INCLUDE_KDBINDER_KDBUS_KDBINDER_H_
+#define INCLUDE_KDBINDER_KDBUS_KDBINDER_H_
#include <kdbinder/kdbus/bus.h>
#include <kdbinder/kdbus/connection.h>
#include <kdbinder/kdbus/item.h>
#include <kdbinder/kdbus/message.h>
-#endif // INCLUDE_KDBINDER_KDBINDER_H_
+#endif // INCLUDE_KDBINDER_KDBUS_KDBINDER_H_
diff --git a/include/kdbinder/kdbus/bus.h b/include/kdbinder/kdbus/bus.h
index a0e5d6d..879550e 100644
--- a/include/kdbinder/kdbus/bus.h
+++ b/include/kdbinder/kdbus/bus.h
@@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#ifndef INCLUDE_KDBINDER_BUS_H_
-#define INCLUDE_KDBINDER_BUS_H_
+#ifndef INCLUDE_KDBINDER_KDBUS_BUS_H_
+#define INCLUDE_KDBINDER_KDBUS_BUS_H_
#include <string>
#include <memory>
@@ -52,8 +52,7 @@ class Bus {
private:
Bus(FILE *control_file, const std::string& name)
- : name(name),
- control_file_(control_file, &fclose) {}
+ : name(name), control_file_(control_file, &fclose) {}
// A Bus needs to have exclusive ownership on the file descriptor, as closing
// it will destroy the underlying bus.
@@ -63,4 +62,4 @@ class Bus {
} // namespace kdbus
} // namespace android
-#endif // INCLUDE_KDBINDER_KDBINDER_H_
+#endif // INCLUDE_KDBINDER_KDBUS_BUS_H_
diff --git a/include/kdbinder/kdbus/connection.h b/include/kdbinder/kdbus/connection.h
index eaee72f..14ea750 100644
--- a/include/kdbinder/kdbus/connection.h
+++ b/include/kdbinder/kdbus/connection.h
@@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#ifndef INCLUDE_KDBINDER_CONNECTION_H_
-#define INCLUDE_KDBINDER_CONNECTION_H_
+#ifndef INCLUDE_KDBINDER_KDBUS_CONNECTION_H_
+#define INCLUDE_KDBINDER_KDBUS_CONNECTION_H_
#include <kdbinder/kdbus/bus.h>
#include <kdbinder/kdbus/message.h>
@@ -22,8 +22,8 @@
// TODO: We need to include <sys/limits.h> because <vector> needs
// CHAR_BIT defined.
#include <sys/limits.h>
-#include <vector>
+#include <vector>
#include <string>
#include <memory>
#include <cstdio>
@@ -32,13 +32,9 @@ namespace android {
namespace kdbus {
struct NameInfo {
- NameInfo(const std::string& name,
- const uint64_t flags,
- const uint64_t connection_flags,
- const uint64_t owner_id)
- : name(name),
- flags(flags),
- connection_flags(connection_flags),
+ NameInfo(const std::string& name, const uint64_t flags,
+ const uint64_t connection_flags, const uint64_t owner_id)
+ : name(name), flags(flags), connection_flags(connection_flags),
owner_id(owner_id) {}
const std::string name;
@@ -49,8 +45,7 @@ struct NameInfo {
struct Reply {
Reply(int error_code, const std::string& error_string)
- : error_code(error_code),
- error_string(error_string) {}
+ : error_code(error_code), error_string(error_string) {}
const int error_code;
const std::string error_string;
@@ -65,21 +60,12 @@ struct DataReply : Reply {
};
- DataReply(const Reply& reply)
- : Reply(reply),
- data({}),
- offset(0),
- src_id(0),
- cookie(0) {}
- DataReply(const Reply& reply,
- const std::vector<Data> data,
- const uint64_t offset,
- const uint64_t src_id,
- const uint64_t cookie)
- : Reply(reply),
- data(data),
- offset(offset),
- src_id(src_id),
+ // We are allowing implicit conversion from a Reply object.
+ DataReply(const Reply& reply) // NOLINT
+ : Reply(reply), data({}), offset(0), src_id(0), cookie(0) {}
+ DataReply(const Reply& reply, const std::vector<Data> data,
+ const uint64_t offset, const uint64_t src_id, const uint64_t cookie)
+ : Reply(reply), data(data), offset(offset), src_id(src_id),
cookie(cookie) {}
const std::vector<Data> data;
@@ -144,7 +130,8 @@ class Connection {
const Reply notify_when_dead(uint64_t src_id) const;
const DataReply dequeue_death_notification() const;
- const DataReply dequeue_death_notification_blocking(int timeout_ms = -1) const;
+ const DataReply dequeue_death_notification_blocking(
+ int timeout_ms = -1) const;
const Reply free(const DataReply& data) const;
@@ -155,8 +142,7 @@ class Connection {
: id(id),
// There is no need to call munmap as closing the bus_file_ file
// descriptor will take care of it.
- buf_(buf, [](void *){}),
- bus_file_(bus_file, &fclose) {}
+ buf_(buf, [](void *addr){}), bus_file_(bus_file, &fclose) {}
std::unique_ptr<void, void (*)(void *)> buf_;
std::unique_ptr<FILE, decltype(&fclose)> bus_file_;
@@ -165,4 +151,4 @@ class Connection {
} // namespace kdbus
} // namespace android
-#endif // INCLUDE_KDBINDER_KDBINDER_H_
+#endif // INCLUDE_KDBINDER_KDBUS_CONNECTION_H_
diff --git a/include/kdbinder/kdbus/item.h b/include/kdbinder/kdbus/item.h
index bc055be..9dbc37c 100644
--- a/include/kdbinder/kdbus/item.h
+++ b/include/kdbinder/kdbus/item.h
@@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#ifndef INCLUDE_KDBINDER_ITEMS_H_
-#define INCLUDE_KDBINDER_ITEMS_H_
+#ifndef INCLUDE_KDBINDER_KDBUS_ITEM_H_
+#define INCLUDE_KDBINDER_KDBUS_ITEM_H_
#include <string>
@@ -26,7 +26,7 @@ namespace kdbus {
// Base abstract class for all items.
class Item {
public:
- Item(uint64_t size) : size(size) {}
+ explicit Item(uint64_t size) : size(size) {}
virtual ~Item() {}
// Populate the current Item to the given `struct kdbus_item` and return a
@@ -57,7 +57,7 @@ class ItemMakeName : public ItemStr {
public:
using ItemStr::ItemStr;
- virtual struct kdbus_item* Queue(struct kdbus_item *item) const override;
+ struct kdbus_item* Queue(struct kdbus_item *item) const override;
};
class ItemBloomParameter : public Item {
@@ -114,4 +114,4 @@ class ItemIdRemove : public ItemIdChange {
} // namespace kdbus
} // namespace android
-#endif // INCLUDE_KDBINDER_ITEMS_H_
+#endif // INCLUDE_KDBINDER_KDBUS_ITEM_H_
diff --git a/include/kdbinder/kdbus/message.h b/include/kdbinder/kdbus/message.h
index 45811cf..9c59e9c 100644
--- a/include/kdbinder/kdbus/message.h
+++ b/include/kdbinder/kdbus/message.h
@@ -13,15 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#ifndef INCLUDE_KDBINDER_MSG_H_
-#define INCLUDE_KDBINDER_MSG_H_
+#ifndef INCLUDE_KDBINDER_KDBUS_MESSAGE_H_
+#define INCLUDE_KDBINDER_KDBUS_MESSAGE_H_
#include <kdbinder/kdbus/item.h>
-#include <cstdlib>
// TODO: We need to include <sys/limits.h> because <vector> needs
// CHAR_BIT defined.
#include <sys/limits.h>
+
+#include <cstdlib>
#include <vector>
struct kdbus_msg;
@@ -31,10 +32,7 @@ namespace kdbus {
class Message {
public:
- Message(uint64_t dst_id,
- uint64_t src_id,
- uint64_t cookie,
- uint64_t flags,
+ Message(uint64_t dst_id, uint64_t src_id, uint64_t cookie, uint64_t flags,
std::vector<Item *> items)
: size_(message_size(items)),
msg_(reinterpret_cast<struct kdbus_msg *>(malloc(size_)), &free) {
@@ -42,10 +40,7 @@ class Message {
}
template<typename... ITEMS>
- Message(uint64_t dst_id,
- uint64_t src_id,
- uint64_t cookie,
- uint64_t flags,
+ Message(uint64_t dst_id, uint64_t src_id, uint64_t cookie, uint64_t flags,
ITEMS... item)
: size_(message_size(item...)),
msg_(reinterpret_cast<struct kdbus_msg *>(malloc(size_)), &free) {
@@ -85,30 +80,21 @@ class Message {
std::unique_ptr<struct kdbus_msg, decltype(&free)> msg_;
private:
- void init(uint64_t dst_id,
- uint64_t src_id,
- uint64_t cookie,
- uint64_t flags,
+ void init(uint64_t dst_id, uint64_t src_id, uint64_t cookie, uint64_t flags,
std::vector<Item *> items);
};
class MessageSync : public Message {
public:
- MessageSync(uint64_t dst_id,
- uint64_t src_id,
- uint64_t cookie,
- uint64_t timeout_ms,
- std::vector<Item *> items)
+ MessageSync(uint64_t dst_id, uint64_t src_id, uint64_t cookie,
+ uint64_t timeout_ms, std::vector<Item *> items)
: Message(dst_id, src_id, cookie, 0, items) {
init(timeout_ms);
}
template<typename... ITEMS>
- MessageSync(uint64_t dst_id,
- uint64_t src_id,
- uint64_t cookie,
- uint64_t timeout_ms,
- ITEMS... item)
+ MessageSync(uint64_t dst_id, uint64_t src_id, uint64_t cookie,
+ uint64_t timeout_ms, ITEMS... item)
: Message(dst_id, src_id, cookie, 0, item...) {
init(timeout_ms);
}
@@ -119,24 +105,20 @@ class MessageSync : public Message {
class MessageReply : public Message {
public:
- MessageReply(uint64_t dst_id,
- uint64_t src_id,
- uint64_t cookie,
+ MessageReply(uint64_t dst_id, uint64_t src_id, uint64_t cookie,
std::vector<Item *> items)
: Message(dst_id, src_id, 0, 0, items) {
init(cookie);
}
template<typename... ITEMS>
- MessageReply(uint64_t dst_id,
- uint64_t src_id,
- uint64_t cookie_reply,
+ MessageReply(uint64_t dst_id, uint64_t src_id, uint64_t cookie_reply,
ITEMS... item)
: Message(dst_id, src_id, 0, 0, item...) {
init(cookie_reply);
}
- uint64_t cookie_reply() const;
+ uint64_t cookie_reply() const;
private:
void init(uint64_t cookie_reply);
@@ -145,4 +127,4 @@ class MessageReply : public Message {
} // namespace kdbus
} // namespace android
-#endif // INCLUDE_KDBINDER_MSG_H_
+#endif // INCLUDE_KDBINDER_KDBUS_MESSAGE_H_
diff --git a/libs/kdbinder/kdbus/bus.cpp b/libs/kdbinder/kdbus/bus.cpp
index 712c351..c7ef564 100644
--- a/libs/kdbinder/kdbus/bus.cpp
+++ b/libs/kdbinder/kdbus/bus.cpp
@@ -14,17 +14,17 @@
* limitations under the License.
*/
-#define LOG_TAG "KDBUS::Bus"
-#include <cutils/log.h>
-
#include <kdbinder/kdbus/bus.h>
-#include "command.h"
+#define LOG_TAG "KDBUS::Bus"
+#include <cutils/log.h>
#include <kdbus.h>
#include <errno.h>
#include <string>
+#include "kdbus/command.h"
+
namespace android {
namespace kdbus {
@@ -34,7 +34,8 @@ std::unique_ptr<Bus> Bus::make(const std::string& name) {
std::string control_path = domain + "control";
FILE *control_file = fopen(control_path.c_str(), "r+");
if (control_file == nullptr) {
- ALOGE("Could not open bus file %s: %s\n", control_path.c_str(), strerror(errno));
+ ALOGE("Could not open bus file %s: %s\n", control_path.c_str(),
+ strerror(errno));
return nullptr;
}
@@ -45,8 +46,7 @@ std::unique_ptr<Bus> Bus::make(const std::string& name) {
// - KDBUS_ITEM_BLOOM_PARAMETER: bus-wide bloom parameter,
// TODO: why does each bus need this? What does it do?
// - KDBUS_ITEM_MAKE_NAME: name of the bus
- auto reply = send_command_make(control_file,
- ItemBloomParameter(64, 1),
+ auto reply = send_command_make(control_file, ItemBloomParameter(64, 1),
ItemMakeName(name_with_uid));
if (reply.error_code < 0) {
ALOGE("Could not create bus: %s\n", reply.error_string.c_str());
diff --git a/libs/kdbinder/kdbus/command.h b/libs/kdbinder/kdbus/command.h
index 49cb1f9..3a77bd2 100644
--- a/libs/kdbinder/kdbus/command.h
+++ b/libs/kdbinder/kdbus/command.h
@@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#ifndef INCLUDE_KDBINDER_CMDS_H_
-#define INCLUDE_KDBINDER_CMDS_H_
+#ifndef LIBS_KDBINDER_KDBUS_COMMAND_H_
+#define LIBS_KDBINDER_KDBUS_COMMAND_H_
#include <kdbinder/kdbus/connection.h>
#include <kdbinder/kdbus/item.h>
@@ -28,14 +28,13 @@
#include <memory>
#include <initializer_list>
#include <functional>
+#include <string>
namespace android {
namespace kdbus {
template<typename TYPE, typename... ITEMS>
-const Reply send_command(FILE *file,
- uint64_t flags,
- int ioctl_cmd,
+const Reply send_command(FILE *file, uint64_t flags, int ioctl_cmd,
// Initialize extra fields before sending the
// command.
const std::function<void(TYPE *)>& pre_ioctl,
@@ -79,8 +78,7 @@ const Reply send_command(FILE *file,
template<typename... ITEMS>
inline const Reply send_command_make(FILE *file, ITEMS...item) {
- return send_command<struct kdbus_cmd_make>(file,
- KDBUS_MAKE_ACCESS_WORLD,
+ return send_command<struct kdbus_cmd_make>(file, KDBUS_MAKE_ACCESS_WORLD,
KDBUS_CMD_BUS_MAKE,
[](struct kdbus_cmd_make *){},
[](const kdbus_cmd_make&){},
@@ -88,21 +86,15 @@ inline const Reply send_command_make(FILE *file, ITEMS...item) {
}
struct ReplyHello : Reply {
- ReplyHello(const Reply& reply, uint64_t id)
- : Reply(reply),
- id(id) {}
+ ReplyHello(const Reply& reply, uint64_t id) : Reply(reply), id(id) {}
const uint64_t id;
};
template<typename... ITEMS>
-inline const ReplyHello send_command_hello(FILE *file,
- uint64_t pool_size,
- ITEMS... item) {
+inline const ReplyHello send_command_hello(FILE *file, uint64_t pool_size,
+ ITEMS... item) {
uint64_t id = 0;
- auto reply = send_command<struct kdbus_cmd_hello>(
- file,
- 0,
- KDBUS_CMD_HELLO,
+ auto reply = send_command<struct kdbus_cmd_hello>(file, 0, KDBUS_CMD_HELLO,
[&pool_size](struct kdbus_cmd_hello *cmd){
cmd->pool_size = pool_size;
// For now, we do not want KDBUS to attach any extra metadata on
@@ -113,19 +105,16 @@ inline const ReplyHello send_command_hello(FILE *file,
[&id](const kdbus_cmd_hello& cmd){
// Retreive the ID that KDBUS gave us.
id = cmd.id;
- },
- item...);
+ }, item...);
return ReplyHello(reply, id);
}
// Give the current connection a well-known name.
template<typename... ITEMS>
-inline const Reply send_command_name_acquire(FILE *file,
- uint64_t flags,
+inline const Reply send_command_name_acquire(FILE *file, uint64_t flags,
ITEMS... item) {
- return send_command<struct kdbus_cmd_name>(file,
- flags,
+ return send_command<struct kdbus_cmd_name>(file, flags,
KDBUS_CMD_NAME_ACQUIRE,
[](struct kdbus_cmd_name *){},
[](const struct kdbus_cmd_name&){},
@@ -135,8 +124,7 @@ inline const Reply send_command_name_acquire(FILE *file,
// Tell the current connection to release its well-known name.
template<typename... ITEMS>
inline const Reply send_command_name_release(FILE *file, ITEMS... item) {
- return send_command<struct kdbus_cmd_name>(file,
- 0,
+ return send_command<struct kdbus_cmd_name>(file, 0,
KDBUS_CMD_NAME_RELEASE,
[](struct kdbus_cmd_name *){},
[](const struct kdbus_cmd_name&){},
@@ -145,9 +133,7 @@ inline const Reply send_command_name_release(FILE *file, ITEMS... item) {
struct ReplyNameList : Reply {
ReplyNameList(const Reply& reply, uint64_t offset, uint64_t list_size)
- : Reply(reply),
- offset(offset),
- list_size(list_size) {}
+ : Reply(reply), offset(offset), list_size(list_size) {}
const uint64_t offset;
const uint64_t list_size;
@@ -155,21 +141,17 @@ struct ReplyNameList : Reply {
// Retreive the list of well-known names registered on the bus.
template<typename... ITEMS>
-inline const ReplyNameList send_command_name_list(FILE *file,
- uint64_t flags,
+inline const ReplyNameList send_command_name_list(FILE *file, uint64_t flags,
ITEMS... item) {
uint64_t offset = 0;
uint64_t list_size = 0;
auto reply = send_command<struct kdbus_cmd_name_list>(
- file,
- flags,
- KDBUS_CMD_NAME_LIST,
+ file, flags, KDBUS_CMD_NAME_LIST,
[](struct kdbus_cmd_name_list *){},
[&offset, &list_size](const struct kdbus_cmd_name_list& cmd){
offset = cmd.offset;
list_size = cmd.list_size;
- },
- item...);
+ }, item...);
return ReplyNameList(reply, offset, list_size);
}
@@ -178,20 +160,17 @@ template<typename... ITEMS>
inline const Reply send_command_send_message(FILE *file,
const Message& msg,
ITEMS... item) {
- return send_command<struct kdbus_cmd_send>(file,
- 0,
- KDBUS_CMD_SEND,
- [&msg](struct kdbus_cmd_send *cmd){
- cmd->msg_address = msg.get_address();
- },
- [](const struct kdbus_cmd_send&){},
- item...);
+ return send_command<struct kdbus_cmd_send>(
+ file, 0, KDBUS_CMD_SEND,
+ [&msg](struct kdbus_cmd_send *cmd){
+ cmd->msg_address = msg.get_address();
+ },
+ [](const struct kdbus_cmd_send&){}, item...);
}
struct ReplyReceive : Reply {
ReplyReceive(const Reply& reply, uint64_t offset)
- : Reply(reply),
- offset(offset) {}
+ : Reply(reply), offset(offset) {}
const uint64_t offset;
};
@@ -201,16 +180,13 @@ inline const ReplyReceive send_command_receive_message(FILE *file,
ITEMS... item) {
uint64_t offset;
auto reply = send_command<struct kdbus_cmd_recv>(
- file,
- 0,
- KDBUS_CMD_RECV,
+ file, 0, KDBUS_CMD_RECV,
[](struct kdbus_cmd_recv *cmd){
cmd->priority = 0;
},
[&offset](const struct kdbus_cmd_recv& cmd){
offset = cmd.msg.offset;
- },
- item...);
+ }, item...);
return ReplyReceive(reply, offset);
}
@@ -221,50 +197,39 @@ inline const ReplyReceive send_command_transact_message(FILE *file,
ITEMS... item) {
uint64_t offset;
auto reply = send_command<struct kdbus_cmd_send>(
- file,
- KDBUS_SEND_SYNC_REPLY,
- KDBUS_CMD_SEND,
+ file, KDBUS_SEND_SYNC_REPLY, KDBUS_CMD_SEND,
[&msg](struct kdbus_cmd_send *cmd){
cmd->msg_address = msg.get_address();
},
[&offset](const struct kdbus_cmd_send& cmd){
offset = cmd.reply.offset;
- },
- item...);
+ }, item...);
return ReplyReceive(reply, offset);
}
template<typename... ITEMS>
-inline const Reply send_command_add_match(FILE *file,
- ITEMS... item) {
+inline const Reply send_command_add_match(FILE *file, ITEMS... item) {
return send_command<struct kdbus_cmd_match>(
- file,
- 0,
- KDBUS_CMD_MATCH_ADD,
+ file, 0, KDBUS_CMD_MATCH_ADD,
[](struct kdbus_cmd_match *cmd){
cmd->cookie = 0xbadbeef;
},
- [](const struct kdbus_cmd_match&){},
- item...);
+ [](const struct kdbus_cmd_match&){}, item...);
}
template<typename... ITEMS>
-inline const Reply send_command_free(FILE *file,
- uint64_t offset,
+inline const Reply send_command_free(FILE *file, uint64_t offset,
ITEMS... item) {
return send_command<struct kdbus_cmd_free>(
- file,
- 0,
- KDBUS_CMD_FREE,
+ file, 0, KDBUS_CMD_FREE,
[&offset](struct kdbus_cmd_free *cmd){
cmd->offset = offset;
},
- [](const struct kdbus_cmd_free&){},
- item...);
+ [](const struct kdbus_cmd_free&){}, item...);
}
} // namespace kdbus
} // namespace android
-#endif // INCLUDE_KDBINDER_CMDS_H_
+#endif // LIBS_KDBINDER_KDBUS_COMMAND_H_
diff --git a/libs/kdbinder/kdbus/connection.cpp b/libs/kdbinder/kdbus/connection.cpp
index 27958a7..134c7d4 100644
--- a/libs/kdbinder/kdbus/connection.cpp
+++ b/libs/kdbinder/kdbus/connection.cpp
@@ -14,39 +14,36 @@
* limitations under the License.
*/
-#define LOG_TAG "KDBUS::Connection"
-#include <cutils/log.h>
-
-#include <kdbinder/kdbus/bus.h>
#include <kdbinder/kdbus/connection.h>
-#include "command.h"
-#include "iterable.h"
+#include <kdbinder/kdbus/bus.h>
+#define LOG_TAG "KDBUS::Connection"
+#include <cutils/log.h>
#include <kdbus.h>
#include <poll.h>
#include <sys/mman.h>
#include <errno.h>
-
// TODO: We need to include <sys/limits.h> because <vector> and
// <sstream> need CHAR_BIT defined.
#include <sys/limits.h>
+
#include <vector>
#include <sstream>
-
#include <string>
+#include "kdbus/command.h"
+#include "kdbus/iterable.h"
+
namespace android {
namespace kdbus {
-std::unique_ptr<Connection> Connection::hello(
- const Bus& bus,
- const std::string& description) {
+std::unique_ptr<Connection> Connection::hello(const Bus& bus,
+ const std::string& description) {
return hello(bus.name, description);
}
-std::unique_ptr<Connection> Connection::hello(
- const std::string& bus_name,
- const std::string& description) {
+std::unique_ptr<Connection> Connection::hello(const std::string& bus_name,
+ const std::string& description) {
std::string path(Bus::domain + bus_name + "/bus");
FILE *bus_file = fopen(path.c_str(), "re");
@@ -57,14 +54,11 @@ std::unique_ptr<Connection> Connection::hello(
// struct kdbus_cmd_hello takes the following items:
// - KDBUS_ITEM_CONN_DESCRIPTION: description of the connection
- auto reply = send_command_hello(bus_file,
- Connection::kPoolSize(),
+ auto reply = send_command_hello(bus_file, Connection::kPoolSize(),
ItemConnDescription(description));
if (reply.error_code < 0) {
ALOGE("Could not connect to Bus \"%s\" with Connection \"%s\": %s\n",
- bus_name.c_str(),
- description.c_str(),
- reply.error_string.c_str());
+ bus_name.c_str(), description.c_str(), reply.error_string.c_str());
fclose(bus_file);
return nullptr;
}
@@ -72,19 +66,17 @@ std::unique_ptr<Connection> Connection::hello(
// map a memory region for future communications. Note that we
// do not need to unmap it since it will be done automatically by the
// kernel when we close the file descriptor.
- void *buf = mmap(NULL, Connection::kPoolSize(), PROT_READ, MAP_SHARED, fileno(bus_file), 0);
+ void *buf = mmap(NULL, Connection::kPoolSize(), PROT_READ, MAP_SHARED,
+ fileno(bus_file), 0);
if (buf == MAP_FAILED) {
ALOGE("Could not mmap a memory pool for Connection %s: %s\n",
- description.c_str(),
- strerror(errno));
+ description.c_str(), strerror(errno));
fclose(bus_file);
return nullptr;
}
ALOGV("New Connection on Bus \"%s\": ID %d, description \"%s\"",
- bus_name.c_str(),
- (int) reply.id,
- description.c_str());
+ bus_name.c_str(), (int) reply.id, description.c_str());
return std::unique_ptr<Connection>(new Connection(bus_file, reply.id, buf));
}
@@ -92,17 +84,14 @@ std::unique_ptr<Connection> Connection::hello(
const Reply Connection::acquire_name(const std::string& name,
uint64_t flags) const {
// struct kdbus_cmd_name requires a KDBUS_ITEM_NAME.
- auto reply = send_command_name_acquire(bus_file_.get(),
- flags,
+ auto reply = send_command_name_acquire(bus_file_.get(), flags,
ItemName(name));
// TODO: Check for the validity of the name according to KDBUS's
// documentation. And return an error if it's invalid.
if (reply.error_code < 0) {
- ALOGE("ID %d could not acquire name \"%s\": %s\n",
- (int) id,
- name.c_str(),
+ ALOGE("ID %d could not acquire name \"%s\": %s\n", (int) id, name.c_str(),
reply.error_string.c_str());
}
@@ -116,9 +105,7 @@ const Reply Connection::release_name(const std::string& name) const {
auto reply = send_command_name_release(bus_file_.get(), ItemName(name));
if (reply.error_code < 0) {
- ALOGE("ID %d could not release name \"%s\": %s\n",
- (int) id,
- name.c_str(),
+ ALOGE("ID %d could not release name \"%s\": %s\n", (int) id, name.c_str(),
reply.error_string.c_str());
}
@@ -134,8 +121,7 @@ std::vector<NameInfo> Connection::name_list(uint64_t flags) const {
auto reply = send_command_name_list(bus_file_.get(), flags);
if (reply.error_code < 0) {
- ALOGE("ID %d could not get the list of acquired names: %s\n",
- (int) id,
+ ALOGE("ID %d could not get the list of acquired names: %s\n", (int) id,
reply.error_string.c_str());
return {};
}
@@ -150,7 +136,8 @@ std::vector<NameInfo> Connection::name_list(uint64_t flags) const {
return {};
}
- for_each_name_info(list, [&list_vector, &flags](struct kdbus_name_info *name) {
+ for_each_name_info(list,
+ [&list_vector, &flags](struct kdbus_name_info *name) {
// Include IDs.
if ((flags & Unique) == Unique) {
list_vector.emplace_back("", 0, name->conn_flags, name->owner_id);
@@ -160,10 +147,8 @@ std::vector<NameInfo> Connection::name_list(uint64_t flags) const {
if ((flags & Names) == Names) {
for_each_item(name, [&list_vector, &name](struct kdbus_item *item) {
if (item->type == KDBUS_ITEM_OWNED_NAME) {
- list_vector.emplace_back(item->name.name,
- item->name.flags,
- name->conn_flags,
- name->owner_id);
+ list_vector.emplace_back(item->name.name, item->name.flags,
+ name->conn_flags, name->owner_id);
}
});
}
@@ -171,15 +156,12 @@ std::vector<NameInfo> Connection::name_list(uint64_t flags) const {
std::ostringstream list_dump;
for (const auto& n : list_vector) {
- list_dump << "- name: " << n.name
- << ", flags: " << n.flags
+ list_dump << "- name: " << n.name << ", flags: " << n.flags
<< ", connection flags: " << n.connection_flags
- << ", owner ID: " << n.owner_id
- << "\n";
+ << ", owner ID: " << n.owner_id << "\n";
}
- ALOGV("ID %d received the following list of names:\n%s",
- (int) id,
+ ALOGV("ID %d received the following list of names:\n%s", (int) id,
list_dump.str().c_str());
return list_vector;
@@ -192,14 +174,11 @@ const Reply Connection::queue_message(const Message& message) const {
auto reply = send_command_send_message(bus_file_.get(), message);
if (reply.error_code < 0) {
- ALOGE("ID %d could not queue message: %s\n",
- (int) id,
+ ALOGE("ID %d could not queue message: %s\n", (int) id,
reply.error_string.c_str());
}
- ALOGV("ID %d queued a message to ID %d\n",
- (int) id,
- (int) message.dst_id());
+ ALOGV("ID %d queued a message to ID %d\n", (int) id, (int) message.dst_id());
return reply;
}
@@ -207,8 +186,7 @@ const Reply Connection::queue_message(const Message& message) const {
const DataReply Connection::dequeue_message() const {
auto reply = send_command_receive_message(bus_file_.get());
if (reply.error_code < 0) {
- ALOGE("ID %d could not dequeue message: %s\n",
- (int) id,
+ ALOGE("ID %d could not dequeue message: %s\n", (int) id,
reply.error_string.c_str());
return DataReply(reply);
}
@@ -220,7 +198,8 @@ const DataReply Connection::dequeue_message() const {
for_each_item(msg, [&vecs, this](struct kdbus_item *item) {
switch (item->type) {
case KDBUS_ITEM_PAYLOAD_OFF: {
- uint8_t *data = reinterpret_cast<uint8_t *>(buf_.get()) + item->vec.offset;
+ uint8_t *data = reinterpret_cast<uint8_t *>(buf_.get()) +
+ item->vec.offset;
vecs.emplace_back(data, item->vec.size);
break;
@@ -228,10 +207,8 @@ const DataReply Connection::dequeue_message() const {
}
});
- ALOGV("ID %d dequeued a message from ID %d with %d payload item(s) and cookie %d\n",
- (int) id,
- (int) msg->src_id,
- (int) vecs.size(),
+ ALOGV("ID %d dequeued a message from ID %d with %d payload item(s) "
+ "and cookie %d\n", (int) id, (int) msg->src_id, (int) vecs.size(),
(int) msg->cookie);
return DataReply(reply, vecs, reply.offset, msg->src_id, msg->cookie);
@@ -247,8 +224,7 @@ const DataReply Connection::dequeue_message_blocking(int timeout_ms) const {
int ret = poll(&pollfd, 1, timeout_ms);
if (ret == 0) {
- ALOGV("ID %d timed out dequeuing a message: timeout of %d ms\n",
- (int) id,
+ ALOGV("ID %d timed out dequeuing a message: timeout of %d ms\n", (int) id,
timeout_ms);
return DataReply(Reply(-ETIMEDOUT, std::string(strerror(-errno))));
} else if (ret > 0) {
@@ -275,8 +251,7 @@ const DataReply Connection::transact(const MessageSync& message) const {
auto reply = send_command_transact_message(bus_file_.get(), message);
if (reply.error_code < 0) {
- ALOGE("ID %d could not issue transaction: %s\n",
- (int) id,
+ ALOGE("ID %d could not issue transaction: %s\n", (int) id,
reply.error_string.c_str());
return DataReply(reply);
}
@@ -300,18 +275,11 @@ const DataReply Connection::transact(const MessageSync& message) const {
}
});
- ALOGV("ID %d issued a transaction and received a reply message from "
- "ID %d with %d payload item(s) and cookie %d\n",
- (int) id,
- (int) msg->src_id,
- (int) vecs.size(),
- (int) msg->cookie_reply);
-
- return DataReply(reply,
- vecs,
- reply.offset,
- msg->src_id,
- msg->cookie_reply);
+ ALOGV("ID %d issued a transaction and received a reply message from ID %d "
+ "with %d payload item(s) and cookie %d\n", (int) id, (int) msg->src_id,
+ (int) vecs.size(), (int) msg->cookie_reply);
+
+ return DataReply(reply, vecs, reply.offset, msg->src_id, msg->cookie_reply);
}
const Reply Connection::reply(const MessageReply& message) const {
@@ -325,15 +293,12 @@ const Reply Connection::reply(const MessageReply& message) const {
auto reply = send_command_send_message(bus_file_.get(), message);
if (reply.error_code < 0) {
- ALOGE("ID %d could not send a reply: %s\n",
- (int) id,
+ ALOGE("ID %d could not send a reply: %s\n", (int) id,
reply.error_string.c_str());
}
- ALOGV("ID %d sent a reply message to ID %d with cookie %d\n",
- (int) id,
- (int) message.dst_id(),
- (int) message.cookie_reply());
+ ALOGV("ID %d sent a reply message to ID %d with cookie %d\n", (int) id,
+ (int) message.dst_id(), (int) message.cookie_reply());
return reply;
}
@@ -346,15 +311,11 @@ const Reply Connection::notify_when_dead(uint64_t src_id) const {
auto reply = send_command_add_match(bus_file_.get(), ItemIdRemove(src_id));
if (reply.error_code < 0) {
- ALOGE("ID %d could not request notification for when ID %d is removed from the bus: %s\n",
- (int) id,
- (int) src_id,
- reply.error_string.c_str());
+ ALOGE("ID %d could not request notification for when ID %d is removed from "
+ "the bus: %s\n", (int) id, (int) src_id, reply.error_string.c_str());
}
- ALOGV("ID %d will be notified when ID %d dies\n",
- (int) id,
- (int) src_id);
+ ALOGV("ID %d will be notified when ID %d dies\n", (int) id, (int) src_id);
return reply;
}
@@ -362,8 +323,7 @@ const Reply Connection::notify_when_dead(uint64_t src_id) const {
const DataReply Connection::dequeue_death_notification() const {
auto reply = send_command_receive_message(bus_file_.get());
if (reply.error_code < 0) {
- ALOGE("ID %d could not dequeue notification: %s\n",
- (int) id,
+ ALOGE("ID %d could not dequeue notification: %s\n", (int) id,
reply.error_string.c_str());
return reply;
}
@@ -382,14 +342,13 @@ const DataReply Connection::dequeue_death_notification() const {
}
});
- ALOGV("ID %d was notified that ID %d died\n",
- (int) id,
- (int) src_id);
+ ALOGV("ID %d was notified that ID %d died\n", (int) id, (int) src_id);
return DataReply(reply, {}, reply.offset, src_id, 0);
}
-const DataReply Connection::dequeue_death_notification_blocking(int timeout_ms) const {
+const DataReply Connection::dequeue_death_notification_blocking(
+ int timeout_ms) const {
struct pollfd pollfd = {
.fd = fileno(bus_file_.get()),
.events = POLLIN | POLLPRI | POLLHUP,
@@ -399,8 +358,7 @@ const DataReply Connection::dequeue_death_notification_blocking(int timeout_ms)
int ret = poll(&pollfd, 1, timeout_ms);
if (ret == 0) {
- ALOGV("ID %d timed out dequeuing a message: timeout of %d ms\n",
- (int) id,
+ ALOGV("ID %d timed out dequeuing a message: timeout of %d ms\n", (int) id,
timeout_ms);
return DataReply(Reply(-ETIMEDOUT, std::string(strerror(-errno))));
} else if (ret > 0) {
@@ -422,14 +380,11 @@ const Reply Connection::free(const DataReply& msg_info) const {
auto reply = send_command_free(bus_file_.get(), msg_info.offset);
if (reply.error_code < 0) {
- ALOGE("ID %d could not free a slice from the pool at 0x%x: %s\n",
- (int) id,
- (int) msg_info.offset,
- reply.error_string.c_str());
+ ALOGE("ID %d could not free a slice from the pool at 0x%x: %s\n", (int) id,
+ (int) msg_info.offset, reply.error_string.c_str());
}
- ALOGV("ID %d freed a slice from the pool at 0x%x\n",
- (int) id,
+ ALOGV("ID %d freed a slice from the pool at 0x%x\n", (int) id,
(int) msg_info.offset);
return reply;
diff --git a/libs/kdbinder/kdbus/globals.h b/libs/kdbinder/kdbus/globals.h
index a6068f4..34418e5 100644
--- a/libs/kdbinder/kdbus/globals.h
+++ b/libs/kdbinder/kdbus/globals.h
@@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#ifndef INCLUDE_KDBINDER_GLOBALS_H_
-#define INCLUDE_KDBINDER_GLOBALS_H_
+#ifndef LIBS_KDBINDER_KDBUS_GLOBALS_H_
+#define LIBS_KDBINDER_KDBUS_GLOBALS_H_
#include <cstdint>
@@ -23,7 +23,7 @@
// Use KDBUS_STATIC_ASSERT for compile time assertions.
#define KDBUS_ASSERT(cond) assert(cond)
// TODO: Use LOGCAT
-#define KDBUS_CHECK(cond) if(!(cond)) std::terminate()
+#define KDBUS_CHECK(cond) if (!(cond)) std::terminate()
#define KDBUS_STATIC_ASSERT(cond) static_assert(cond, "")
namespace android {
@@ -42,4 +42,4 @@ constexpr uint64_t kAlignTo8Bit(uint64_t s) {
} // namespace kdbus
} // namespace android
-#endif // INCLUDE_KDBINDER_GLOBALS_H_
+#endif // LIBS_KDBINDER_KDBUS_GLOBALS_H_
diff --git a/libs/kdbinder/kdbus/item.cpp b/libs/kdbinder/kdbus/item.cpp
index 18e0bc2..1d70922 100644
--- a/libs/kdbinder/kdbus/item.cpp
+++ b/libs/kdbinder/kdbus/item.cpp
@@ -15,9 +15,11 @@
*/
#include <kdbinder/kdbus/item.h>
-#include "globals.h"
#include <kdbus.h>
+#include <string>
+
+#include "kdbus/globals.h"
namespace android {
namespace kdbus {
@@ -38,8 +40,7 @@ struct kdbus_item* Item::Next(struct kdbus_item *item) {
ItemBloomParameter::ItemBloomParameter(uint64_t size, uint64_t n_hash)
: Item(Item::kComputeSizeAligned(sizeof(struct kdbus_bloom_parameter))),
- bloom_size_(size),
- n_hash_(n_hash) {}
+ bloom_size_(size), n_hash_(n_hash) {}
struct kdbus_item* ItemBloomParameter::Queue(struct kdbus_item *item) const {
struct kdbus_bloom_parameter bloom {
diff --git a/libs/kdbinder/kdbus/iterable.cpp b/libs/kdbinder/kdbus/iterable.cpp
index 5ae66bb..d45221a 100644
--- a/libs/kdbinder/kdbus/iterable.cpp
+++ b/libs/kdbinder/kdbus/iterable.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "iterable.h"
+#include "kdbus/iterable.h"
namespace android {
namespace kdbus {
diff --git a/libs/kdbinder/kdbus/iterable.h b/libs/kdbinder/kdbus/iterable.h
index 5d979c9..ab8e4c4 100644
--- a/libs/kdbinder/kdbus/iterable.h
+++ b/libs/kdbinder/kdbus/iterable.h
@@ -13,14 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#ifndef INCLUDE_KDBINDER_ITERABLE_H_
-#define INCLUDE_KDBINDER_ITERABLE_H_
+#ifndef LIBS_KDBINDER_KDBUS_ITERABLE_H_
+#define LIBS_KDBINDER_KDBUS_ITERABLE_H_
-#include "globals.h"
#include <kdbus.h>
#include <functional>
+#include "kdbus/globals.h"
+
namespace android {
namespace kdbus {
@@ -49,4 +50,4 @@ void for_each_name_info(struct kdbus_name_list *list,
} // namespace kdbus
} // namespace android
-#endif // INCLUDE_KDBINDER_ITERABLE_H_
+#endif // LIBS_KDBINDER_KDBUS_ITERABLE_H_
diff --git a/libs/kdbinder/kdbus/message.cpp b/libs/kdbinder/kdbus/message.cpp
index 24430d5..0e0c297 100644
--- a/libs/kdbinder/kdbus/message.cpp
+++ b/libs/kdbinder/kdbus/message.cpp
@@ -17,11 +17,13 @@
#include <kdbinder/kdbus/message.h>
#include <kdbinder/kdbus/item.h>
-#include "globals.h"
-
#include <kdbus.h>
+
#include <cstdlib>
#include <ctime>
+#include <vector>
+
+#include "kdbus/globals.h"
namespace android {
namespace kdbus {
@@ -48,11 +50,8 @@ uint64_t Message::message_size(std::vector<Item *> items) {
return size;
}
-void Message::init(uint64_t dst_id,
- uint64_t src_id,
- uint64_t cookie,
- uint64_t flags,
- std::vector<Item *> items) {
+void Message::init(uint64_t dst_id, uint64_t src_id, uint64_t cookie,
+ uint64_t flags, std::vector<Item *> items) {
msg_->flags = flags;
msg_->size = size_;
msg_->priority = 0;