Skip to content
Closed
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
8 changes: 4 additions & 4 deletions include/dmn-async.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ class Dmn_Async {
* @return shared_ptr<Dmn_Async_Handle> Rendezvous object for task completion.
*/
template <typename Callable, typename... Args>
auto addExecTaskWithWait(Callable &&func, Args &&...args)
-> std::shared_ptr<Dmn_Async_Handle>;
auto addExecTaskWithWait(Callable &&func,
Args &&...args) -> std::shared_ptr<Dmn_Async_Handle>;

/**
* @brief Schedule a callable task to run after the given duration has
Expand Down Expand Up @@ -223,8 +223,8 @@ class Dmn_Async {
template <class Rep, class Period, typename Callable, typename... Args>
auto
addExecTaskAfterWithWait(const std::chrono::duration<Rep, Period> &duration,
Callable &&func, Args &&...args)
-> std::shared_ptr<Dmn_Async_Handle>;
Callable &&func,
Args &&...args) -> std::shared_ptr<Dmn_Async_Handle>;

/**
* @brief Block until the async is empty and no task pending to be executed.
Expand Down
14 changes: 7 additions & 7 deletions include/dmn-blockingqueue-lf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ class Dmn_BlockingQueue_Lf
* @return An optional containing the data from the head of the queue, or
* std::nullopt if the queue is empty and wait is false.
*/
virtual auto popOptional(bool wait,
const Inflight_Guard_Ticket &inflightTicket)
-> std::optional<T>;
virtual auto
popOptional(bool wait,
const Inflight_Guard_Ticket &inflightTicket) -> std::optional<T>;

/**
* @brief Wrapper call to pushImpl to copy and enqueue the item into the
Expand Down Expand Up @@ -459,8 +459,8 @@ auto dmn::Dmn_BlockingQueue_Lf<T>::freeRetiredNodeList(Node *head) -> uint64_t {
}

template <typename T>
auto Dmn_BlockingQueue_Lf<T>::pop(size_t count, long timeout)
-> std::vector<T> {
auto Dmn_BlockingQueue_Lf<T>::pop(size_t count,
long timeout) -> std::vector<T> {
assert(count > 0);

auto inflightTicket = this->enterInflightGate();
Expand Down Expand Up @@ -506,8 +506,8 @@ auto Dmn_BlockingQueue_Lf<T>::popOptional(bool wait) -> std::optional<T> {

template <typename T>
auto Dmn_BlockingQueue_Lf<T>::popOptional(
bool wait, const Inflight_Guard_Ticket &inflightTicket)
-> std::optional<T> {
bool wait,
const Inflight_Guard_Ticket &inflightTicket) -> std::optional<T> {
std::optional<T> res{};

do {
Expand Down
4 changes: 2 additions & 2 deletions include/dmn-blockingqueue-mt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@ template <typename T> auto Dmn_BlockingQueue_Mt<T>::waitForEmpty() -> uint64_t {
}

template <typename T>
auto Dmn_BlockingQueue_Mt<T>::pop(size_t count, long timeout)
-> std::vector<T> {
auto Dmn_BlockingQueue_Mt<T>::pop(size_t count,
long timeout) -> std::vector<T> {
std::vector<T> ret{};

assert(count > 0);
Expand Down
4 changes: 2 additions & 2 deletions include/dmn-blockingqueue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ template <typename Derived, typename T> class Dmn_BlockingQueue {
}; // class Dmn_BlockingQueue

template <typename Derived, typename T>
inline auto Dmn_BlockingQueue<Derived, T>::pop(std::size_t count, long timeout)
-> std::vector<T> {
inline auto Dmn_BlockingQueue<Derived, T>::pop(std::size_t count,
long timeout) -> std::vector<T> {
return static_cast<Derived *>(this)->pop(count, timeout);
}

Expand Down
4 changes: 2 additions & 2 deletions include/dmn-dmesg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,8 @@ class Dmn_DMesg : public Dmn_Pub<dmn::DMesgPb> {
*
* @return last message of topic or nullptr if no message for such topic.
*/
auto getTopicLastMessage(std::string_view topic)
-> std::optional<dmn::DMesgPb>;
auto
getTopicLastMessage(std::string_view topic) -> std::optional<dmn::DMesgPb>;

/**
* @brief Reset conflict state by posting last message of the topic.
Expand Down
6 changes: 3 additions & 3 deletions include/dmn-dmesgnet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ class Dmn_DMesgNet : public Dmn_DMesg {
///< acknowledgement.
long long m_master_sync_pending_counter{}; ///< Cycles spent waiting for
///< master synchronisation.
struct timeval
m_last_remote_master_timestamp{}; ///< Timestamp of the last received
///< master heartbeat.
struct timeval m_last_remote_master_timestamp {
}; ///< Timestamp of the last received
///< master heartbeat.
std::unordered_map<std::string, dmn::DMesgPb>
m_topic_last_dmesgpb{}; ///< Last published message per topic.
std::unordered_map<std::string, std::vector<dmn::DMesgPb>>
Expand Down
8 changes: 4 additions & 4 deletions include/dmn-pipe.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ class Dmn_Pipe : public Dmn_Io<T>, private QueueType, private Dmn_Proc {
*
* @return The number of items read and processed.
*/
auto readAndProcess(Dmn_Pipe::Task fn, size_t count = 1, long timeout = 0)
-> size_t;
auto readAndProcess(Dmn_Pipe::Task fn, size_t count = 1,
long timeout = 0) -> size_t;

/**
* @brief Write (copy) an item into the pipe.
Expand Down Expand Up @@ -294,8 +294,8 @@ auto Dmn_Pipe<T, QueueType>::read() -> std::optional<T> {
}

template <typename T, typename QueueType>
auto Dmn_Pipe<T, QueueType>::read(size_t count, long timeout)
-> std::vector<T> {
auto Dmn_Pipe<T, QueueType>::read(size_t count,
long timeout) -> std::vector<T> {
std::vector<T> dataList{};

readAndProcess([&dataList](T &&item) { dataList.push_back(std::move(item)); },
Expand Down
47 changes: 32 additions & 15 deletions run-clang-format.sh → scripts/run-tab-check-and-clang-format.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
#!/bin/sh
#
# Copyright © 2023 Chee Bin HOH. All rights reserved.
# Copyright © 2023 - 2026 Chee Bin HOH. All rights reserved.
#

ROOT_DIR="."

for arg in "$@"; do
case "$arg" in
--root=*)
ROOT_DIR="${arg#--root=}"
;;
*)
echo "Usage: $0 [--root=dir]" >&2
exit 2
;;
esac
done

if [ ! -d "$ROOT_DIR" ]; then
echo "Error: root directory '$ROOT_DIR' does not exist." >&2
exit 2
fi

cd "$ROOT_DIR" || exit 2

DIRS=". include src include/kafka src/kafka test"
FILE_PATTERN='*.cpp *.hpp'

# extra space following newline is never intended to be checked in, so we trim it.
# Extra space following newline is never intended to be checked in, so we trim it.
#
# Tab at the beginning of lines are not consistent cross IDE, it is particular
# annoying for source files saved in visual studio kind of IDE and reopen in
# vi.

ROOT_DIR=`pwd`

echo "******** check for tab character..."

has_invalid_tab=""
Expand All @@ -26,32 +49,26 @@ for d in `echo ${DIRS}`; do
fi
done

cd - &>/dev/null
cd $ROOT_DIR
done

if [ "$has_invalid_tab" == "yes" ]; then
if [ "$has_invalid_tab" = "yes" ]; then
exit 1
fi

# clang-format the source files
if which clang-format &>/dev/null; then
if which clang-format >/dev/null; then
echo "******** perform clang-format..."

for d in `echo ${DIRS}`; do
cd ${d};

for f in `ls ${FILE_PATTERN} 2>/dev/null`; do
clang-format --style=LLVM ${f} > ${f}_tmp
if ! diff $f ${f}_tmp &>/dev/null; then
echo "- formatting ${f}..."
cp ${f}_tmp ${f}
fi

rm ${f}_tmp
clang-format -i --style=LLVM ${f}
done

cd - &>/dev/null
cd $ROOT_DIR
done
else
echo "Error: clang-format is not found, skip it..."
fi


12 changes: 5 additions & 7 deletions src/dmn-dmesg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,8 @@ void Dmn_DMesg::Dmn_DMesgHandler::write(const dmn::DMesgPb &dmesgpb,
* @param flags Additional WriteOptions (kForce, etc.).
* @return true if write succeeded without conflict, false otherwise.
*/
auto Dmn_DMesg::Dmn_DMesgHandler::writeAndCheckConflict(dmn::DMesgPb &&dmesgpb,
WriteFlags flags)
-> bool {
auto Dmn_DMesg::Dmn_DMesgHandler::writeAndCheckConflict(
dmn::DMesgPb &&dmesgpb, WriteFlags flags) -> bool {
std::string topic = dmesgpb.topic();

flags.set(kBlock);
Expand All @@ -421,9 +420,8 @@ auto Dmn_DMesg::Dmn_DMesgHandler::writeAndCheckConflict(dmn::DMesgPb &&dmesgpb,
* @param flags Additional WriteOptions (kForce, etc.).
* @return true if write succeeded without conflict, false otherwise.
*/
auto Dmn_DMesg::Dmn_DMesgHandler::writeAndCheckConflict(dmn::DMesgPb &dmesgpb,
WriteFlags flags)
-> bool {
auto Dmn_DMesg::Dmn_DMesgHandler::writeAndCheckConflict(
dmn::DMesgPb &dmesgpb, WriteFlags flags) -> bool {
std::string topic = dmesgpb.topic();

flags.set(kBlock);
Expand Down Expand Up @@ -454,7 +452,7 @@ void Dmn_DMesg::Dmn_DMesgHandler::writeDMesgInternal(dmn::DMesgPb &dmesgpb,
"handler needs to be reset");
}

struct timeval tval{};
struct timeval tval {};
gettimeofday(&tval, nullptr);

DMESG_PB_SET_MSG_TIMESTAMP_FROM_TV(dmesgpb, tval);
Expand Down
8 changes: 4 additions & 4 deletions src/dmn-dmesgnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Dmn_DMesgNet::Dmn_DMesgNet(std::string_view name,
m_output_handler{std::move(output_handler)} {

// Initialize the DMesgNet state
struct timeval tval{};
struct timeval tval {};
gettimeofday(&tval, nullptr);

DMESG_PB_SET_MSG_TOPIC(this->m_sys, kDMesgSysIdentifier);
Expand Down Expand Up @@ -143,7 +143,7 @@ Dmn_DMesgNet::~Dmn_DMesgNet() noexcept try {
// we avoid use of m_sys_handler as we are to destroy it, so we
// do not want to hold the object life up and have to wait for
// asynchrononous action to send last heartbeat messge.
struct timeval tval{};
struct timeval tval {};
gettimeofday(&tval, nullptr);

DMESG_PB_SET_MSG_SOURCEIDENTIFIER(this->m_sys, this->m_name);
Expand Down Expand Up @@ -400,7 +400,7 @@ void Dmn_DMesgNet::createTimerProc() {
DMESG_PB_SYS_NODE_SET_STATE(self, dmn::DMesgStatePb::Ready);
DMESG_PB_SYS_NODE_SET_MASTERIDENTIFIER(self, this->m_name);

struct timeval tval{};
struct timeval tval {};
gettimeofday(&tval, nullptr);

DMESG_PB_SYS_NODE_SET_UPDATEDTIMESTAMP_FROM_TV(self, tval);
Expand Down Expand Up @@ -515,7 +515,7 @@ void Dmn_DMesgNet::reconciliateDMesgPbSys(const dmn::DMesgPb &dmesgpb_other) {
auto other = dmesgpb_other.body().sys().self();
auto *self = this->m_sys.mutable_body()->mutable_sys()->mutable_self();

struct timeval tval{};
struct timeval tval {};
gettimeofday(&tval, nullptr);

if (self->state() == dmn::DMesgStatePb::MasterPending &&
Expand Down
6 changes: 3 additions & 3 deletions src/dmn-runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ auto Dmn_Runtime_Manager_Impl_create() -> Dmn_Runtime_Manager_Impl * {
auto *impl = new Dmn_Runtime_Manager_Impl;

#ifdef _POSIX_TIMERS
struct sigevent sev{};
struct sigevent sev {};

// 1. Setup signal delivery
sev.sigev_notify = SIGEV_SIGNAL;
Expand Down Expand Up @@ -152,7 +152,7 @@ void Dmn_Runtime_Manager_Impl_setNextTimer(Dmn_Runtime_Manager_Impl *impl,
assert(impl->m_timer_created);

#ifdef _POSIX_TIMERS
struct itimerspec its{};
struct itimerspec its {};

its.it_value.tv_sec = sec;
its.it_value.tv_nsec = nsec;
Expand All @@ -165,7 +165,7 @@ void Dmn_Runtime_Manager_Impl_setNextTimer(Dmn_Runtime_Manager_Impl *impl,
std::system_category().message(errno));
}
#else /* _POSIX_TIMERS */
struct itimerval timer{};
struct itimerval timer {};

timer.it_value.tv_sec = sec;
timer.it_value.tv_usec = nsec / 1000;
Expand Down
4 changes: 2 additions & 2 deletions src/dmn-socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace dmn {
Dmn_Socket::Dmn_Socket(std::string_view ip4, int port_no, bool write_only)
: m_ip4{ip4}, m_port_no{port_no}, m_write_only{write_only} {
constexpr int broadcast{1};
struct sockaddr_in servaddr{};
struct sockaddr_in servaddr {};
const int type{SOCK_DGRAM};

m_fd = socket(AF_INET, type, 0);
Expand Down Expand Up @@ -111,7 +111,7 @@ void Dmn_Socket::write(const std::string &item) {
* as a member value per object to avoid reconstructing it on every
* write call.
*/
struct sockaddr_in servaddr{};
struct sockaddr_in servaddr {};
memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(m_port_no);
Expand Down
4 changes: 2 additions & 2 deletions test/dmn-test-async-queue-lf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ int main(int argc, char *argv[]) {
waitHandler->wait();
EXPECT_TRUE(done);

struct sigaction sact{};
struct itimerval timer{};
struct sigaction sact {};
struct itimerval timer {};

// Install timer_handler as the signal handler for SIGALRM
sact.sa_handler = &timer_handler;
Expand Down
4 changes: 2 additions & 2 deletions test/dmn-test-async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ int main(int argc, char *argv[]) {
waitHandler->wait();
EXPECT_TRUE(done);

struct sigaction sact{};
struct itimerval timer{};
struct sigaction sact {};
struct itimerval timer {};

// Install timer_handler as the signal handler for SIGALRM
sact.sa_handler = &timer_handler;
Expand Down
Loading