forked from Kistler-Group/sdbus-cpp
Compare commits
3 Commits
fix/signal
...
fix_deprec
Author | SHA1 | Date | |
---|---|---|---|
e199dc58cf | |||
ad7731d900 | |||
101dd1c2ba |
@ -81,6 +81,7 @@ set(SDBUSCPP_PUBLIC_HDRS
|
||||
${SDBUSCPP_INCLUDE_DIR}/Types.h
|
||||
${SDBUSCPP_INCLUDE_DIR}/TypeTraits.h
|
||||
${SDBUSCPP_INCLUDE_DIR}/Flags.h
|
||||
${SDBUSCPP_INCLUDE_DIR}/SdbusAsio.h
|
||||
${SDBUSCPP_INCLUDE_DIR}/sdbus-c++.h)
|
||||
|
||||
set(SDBUSCPP_SRCS ${SDBUSCPP_CPP_SRCS} ${SDBUSCPP_HDR_SRCS} ${SDBUSCPP_PUBLIC_HDRS})
|
||||
|
67
include/sdbus-c++/SdbusAsio.h
Normal file
67
include/sdbus-c++/SdbusAsio.h
Normal file
@ -0,0 +1,67 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <memory>
|
||||
#include <sdbus-c++/sdbus-c++.h>
|
||||
|
||||
class SdbusAsio final : boost::noncopyable {
|
||||
public:
|
||||
explicit SdbusAsio(boost::asio::io_context& io_context,
|
||||
std::unique_ptr<sdbus::IConnection> conn = sdbus::createDefaultBusConnection())
|
||||
: conn_ { std::move(conn) }
|
||||
, timer_ { io_context }
|
||||
, dbus_desc_ { io_context }
|
||||
, event_desc_ { io_context }
|
||||
|
||||
{
|
||||
auto poll_data = conn_->getEventLoopPollData();
|
||||
dbus_desc_.async_wait(boost::asio::posix::stream_descriptor::wait_read,
|
||||
[this](const boost::system::error_code&) { processRead(); });
|
||||
dbus_desc_.assign(poll_data.fd);
|
||||
|
||||
event_desc_.async_read_some(boost::asio::null_buffers(), [this](auto&, auto) { processEvent(); });
|
||||
event_desc_.assign(poll_data.event_fd);
|
||||
|
||||
if (poll_data.timeout_usec != UINT64_MAX) {
|
||||
timer_.async_wait([this](boost::system::error_code const&) { processTimeout(); });
|
||||
timer_.expires_after(boost::posix_time::microsec(poll_data.timeout_usec));
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<sdbus::IConnection> getConnection() { return conn_; }
|
||||
|
||||
private:
|
||||
void process()
|
||||
{
|
||||
for (auto i = 0; i < DBUS_PROCESS_MAX; i++) {
|
||||
if (!conn_->processPendingRequest()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
void processRead()
|
||||
{
|
||||
process();
|
||||
dbus_desc_.async_wait(boost::asio::posix::stream_descriptor::wait_read,
|
||||
[this](const boost::system::error_code&) { processRead(); });
|
||||
}
|
||||
|
||||
void processEvent()
|
||||
{
|
||||
process();
|
||||
event_desc_.async_read_some(boost::asio::null_buffers(), [this](auto, auto) { processEvent(); });
|
||||
}
|
||||
|
||||
void processTimeout()
|
||||
{
|
||||
process();
|
||||
timer_.async_wait([this](boost::system::error_code const&) { processTimeout(); });
|
||||
}
|
||||
|
||||
static constexpr auto DBUS_PROCESS_MAX = 32;
|
||||
std::shared_ptr<sdbus::IConnection> conn_;
|
||||
boost::asio::deadline_timer timer_;
|
||||
boost::asio::posix::stream_descriptor dbus_desc_;
|
||||
boost::asio::posix::stream_descriptor event_desc_;
|
||||
};
|
@ -292,12 +292,12 @@ void Document::Expat::character_data_handler(void* data, const XML_Char* chars,
|
||||
nod = &(nod->children.back());
|
||||
}
|
||||
|
||||
int x = 0, y = len - 1;
|
||||
int offset = 0, count = len;
|
||||
|
||||
while (isspace(chars[y]) && y > 0) --y;
|
||||
while (isspace(chars[x]) && x < y) ++x;
|
||||
while (count > 0 && isspace(chars[count - 1])) --count;
|
||||
while (offset < count && isspace(chars[offset])) { ++offset; --count; }
|
||||
|
||||
nod->cdata = std::string(chars, x, y + 1);
|
||||
nod->cdata = std::string{chars + offset, static_cast<std::string::size_type>(count)};
|
||||
}
|
||||
|
||||
void Document::Expat::end_element_handler(void* data, const XML_Char* /*name*/)
|
||||
|
Reference in New Issue
Block a user