• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wirenboard / wb-mqtt-smartweb / 47

31 Jul 2026 10:42AM UTC coverage: 33.897% (-0.8%) from 34.703%
47

push

github

web-flow
Use exported vars instead of MAKEFLAGS for coverage options (#40)

307 of 744 branches covered (41.26%)

501 of 1478 relevant lines covered (33.9%)

10.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/ThreadedCanReader.cpp
1
#include "ThreadedCanReader.h"
2

3
#include <cstring>
4
#include <wblib/utils.h>
5

6
namespace
7
{
8
    const auto READ_TIMEOUT = std::chrono::milliseconds(1000);
9
}
10

11
TThreadedCanReader::TThreadedCanReader(const std::string& threadName,
×
12
                                       std::shared_ptr<CAN::IPort> canPort,
13
                                       size_t framesQueueMaxLength,
14
                                       std::function<bool(const CAN::TFrame& frame)> acceptFrame,
15
                                       std::function<void(const CAN::TFrame& frame)> handleFrame)
×
16
    : CanPort(canPort),
×
17
      FramesQueueMaxLength(framesQueueMaxLength),
×
18
      AcceptFrame(acceptFrame)
×
19
{
20
    Enabled.store(true);
×
21
    CanPort->AddHandler(this);
×
22

23
    Thread = std::thread([this, threadName, handleFrame]() {
×
24
        WBMQTT::SetThreadName(threadName);
×
25
        CAN::TFrame frame;
26
        while (Enabled.load()) {
×
27
            memset(&frame, 0, sizeof(CAN::TFrame));
×
28
            if (Get(frame)) {
×
29
                handleFrame(frame);
×
30
            }
31
        }
32
    });
×
33
}
×
34

35
TThreadedCanReader::~TThreadedCanReader()
×
36
{
37
    CanPort->RemoveHandler(this);
×
38
    Enabled.store(false);
×
39
    if (Thread.joinable()) {
×
40
        Thread.join();
×
41
    }
42
}
×
43

44
bool TThreadedCanReader::Handle(const CAN::TFrame& frame)
×
45
{
46
    if (!AcceptFrame(frame)) {
×
47
        return false;
×
48
    }
49
    std::unique_lock<std::mutex> waitLock(Mutex);
×
50
    if (Frames.size() < FramesQueueMaxLength) {
×
51
        Frames.push(frame);
×
52
        Cv.notify_all();
×
53
    }
54
    return true;
×
55
}
×
56

57
bool TThreadedCanReader::Get(CAN::TFrame& frame)
×
58
{
59
    std::unique_lock<std::mutex> waitLock(Mutex);
×
60
    if (Frames.empty()) {
×
61
        if (std::cv_status::timeout == Cv.wait_for(waitLock, READ_TIMEOUT)) {
×
62
            return false;
×
63
        }
64
    }
65
    frame = Frames.front();
×
66
    Frames.pop();
×
67
    return true;
×
68
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc