Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ce/async api #2

Open
wants to merge 8 commits into
base: async_api
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 36 additions & 36 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,42 @@ set(CMAKE_CXX_VISIBILITY_PRESET protected)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=gold")

set(HEADER_FILES
src/dbus_asio.h
src/dbus_auth.h
src/dbus_connection.h
src/dbus_error.h
src/dbus.h
src/dbus_introspectable.h
src/dbus_log.h
src/dbus_matchrule.h
src/dbus_message.h
src/dbus_messageprotocol.h
src/dbus_messageostream.h
src/dbus_messageistream.h
src/dbus_names.h
src/dbus_octetbuffer.h
src/dbus_platform.h
src/dbus_transport.h
src/dbus_type.h
src/dbus_type_any.h
src/dbus_type_array.h
src/dbus_type_boolean.h
src/dbus_type_byte.h
src/dbus_type_dictentry.h
src/dbus_type_double.h
src/dbus_type_int16.h
src/dbus_type_int32.h
src/dbus_type_int64.h
src/dbus_type_objectpath.h
src/dbus_type_signature.h
src/dbus_type_string.h
src/dbus_type_struct.h
src/dbus_type_uint16.h
src/dbus_type_uint32.h
src/dbus_type_uint64.h
src/dbus_type_unixfd.h
src/dbus_type_variant.h
src/dbus_utils.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_asio.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_auth.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_connection.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_error.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_introspectable.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_log.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_matchrule.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_message.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_messageprotocol.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_messageostream.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_messageistream.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_names.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_octetbuffer.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_platform.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_transport.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_type.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_type_any.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_type_array.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_type_boolean.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_type_byte.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_type_dictentry.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_type_double.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_type_int16.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_type_int32.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_type_int64.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_type_objectpath.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_type_signature.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_type_string.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_type_struct.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_type_uint16.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_type_uint32.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_type_uint64.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_type_unixfd.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_type_variant.h
${CMAKE_CURRENT_LIST_DIR}/src/dbus_utils.h
)

add_library(dbus-asio SHARED
Expand Down
11 changes: 9 additions & 2 deletions src/dbus_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,21 @@

#include "dbus_asio.h"
#include "dbus_auth.h"
#include "dbus_matchrule.h"
#include "dbus_messageprotocol.h"
#include "dbus_transport.h"

#include <cstdint>
#include <memory>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>

namespace DBus {

struct WellKnownName;

static constexpr char const *Name = "org.freedesktop.DBus";
static constexpr char const *Object = "/org/freedesktop/DBus";
static constexpr char const *Interface = "org.freedesktop.DBus";
Expand Down Expand Up @@ -344,15 +351,15 @@ class Connection : public std::enable_shared_from_this<Connection> {
}

template<typename CompletionToken>
auto addMatch(const MatchRule& rule, CompletionToken&& token) const
auto addMatch(const MatchRule& rule, CompletionToken&& token)
{
return sendMethodCall({ DBus::Name,
{DBus::Object, DBus::Interface, "AddMatch"}, {rule.str()} },
std::forward<CompletionToken>(token));
}

template<typename CompletionToken>
auto removeMatch(const MatchRule& rule, CompletionToken&& token) const
auto removeMatch(const MatchRule& rule, CompletionToken&& token)
{
return sendMethodCall({ DBus::Name,
{DBus::Object, DBus::Interface, "RemoveMatch"}, {rule.str()} },
Expand Down
2 changes: 1 addition & 1 deletion src/dbus_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void DBus::Log::writeHex(std::size_t type, const std::string& prefix,
for (std::size_t i = 0; i < size; ++i) {
const unsigned char byte = *(first + i);
oss << std::hex << std::setw(2) << std::setfill('0')
<< static_cast<const unsigned>(byte) << ' ';
<< static_cast<unsigned>(byte) << ' ';
*ascii++ = ::isprint(byte) ? byte : '.';
if (++column == maxColumns) {
column = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/dbus_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ DBus::Message::Header::getSize(const OctetBuffer& message)

// Add size of the header fields array
const Endian endianness = Message::endianness(message);
size += correctEndianess(endianness, *(uint32_t*)(message.data() + 12));
size += correctEndianess(endianness, *reinterpret_cast<uint32_t const *>(message.data() + 12));
// Add padding to an 8 byte boundary
size += (size % 8 == 0) ? 0 : 8 - (size % 8);

Expand All @@ -250,7 +250,7 @@ DBus::Message::Header::getMessageSize(const OctetBuffer& message)
return 0; // TODO: throw instead?

const Endian endianness = Message::endianness(message);
std::size_t body_size = correctEndianess(endianness, *(uint32_t*)(message.data() + 4));
std::size_t body_size = correctEndianess(endianness, *reinterpret_cast<uint32_t const*>(message.data() + 4));
std::size_t msg_size = getSize(message) + body_size;

if (msg_size > Message::MaximumSize)
Expand Down
2 changes: 1 addition & 1 deletion src/dbus_names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ DBus::Name::validate(const std::string& name, Type type) const
bool havePeriod = false;

char prev = '.';
for (int i = isUnique ? 1 : 0; i < name.size(); ++i) {
for (std::size_t i = isUnique ? 1 : 0; i < name.size(); ++i) {
const char ch = name[i];
if (allowPeriod && ch == '.') {
if (prev == '.')
Expand Down
14 changes: 8 additions & 6 deletions src/dbus_transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ class Transport : public std::enable_shared_from_this<Transport> {
msg.msg_iov = &iov;
msg.msg_iovlen = 1;

char fdbuf[CMSG_SPACE(self->m_maxRecvUnixFds * sizeof(int))];
msg.msg_control = fdbuf;
msg.msg_controllen = sizeof(fdbuf);
std::size_t fdbufSize = CMSG_SPACE(self->m_maxRecvUnixFds * sizeof(int));
std::unique_ptr<char> fdbuf(::new char[fdbufSize]);
msg.msg_control = fdbuf.get();
msg.msg_controllen = fdbufSize;

ssize_t read_total = 0;
do {
Expand Down Expand Up @@ -163,9 +164,10 @@ class Transport : public std::enable_shared_from_this<Transport> {
msg.msg_iovlen = 1;

const size_t fdlen = payload->fds.size() * sizeof(int);
char fdbuf[CMSG_SPACE(fdlen)];
msg.msg_control = fdbuf;
msg.msg_controllen = sizeof(fdbuf);
std::size_t fdbufSize = CMSG_SPACE(fdlen);
std::unique_ptr<char> fdbuf(::new char[fdbufSize]);
msg.msg_control = fdbuf.get();
msg.msg_controllen = fdbufSize;

struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg);
cmsg->cmsg_len = CMSG_LEN(fdlen);
Expand Down
2 changes: 1 addition & 1 deletion src/dbus_type_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void DBus::Type::Array::marshall(MessageOStream& stream) const
if (contentsSize > Array::MaximumSize)
throw std::out_of_range("Array " + getSignature() +
": size " + std::to_string(contentsSize) + " exceeds 64 MiB");
stream.data.replace(sizePos, 4, (char*)&contentsSize, sizeof(uint32_t));
stream.data.replace(sizePos, 4, reinterpret_cast<const char*>(&contentsSize), sizeof(uint32_t));
}

void DBus::Type::Array::unmarshall(MessageIStream& stream)
Expand Down