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

wirenboard / wb-mqtt-serial / 6

02 Jul 2025 11:08AM UTC coverage: 73.768% (-0.07%) from 73.835%
6

Pull #956

github

u236
update changelog
Pull Request #956: Refactor device/LoadConfig RPC

6427 of 9048 branches covered (71.03%)

0 of 50 new or added lines in 4 files covered. (0.0%)

2 existing lines in 2 files now uncovered.

12278 of 16644 relevant lines covered (73.77%)

306.79 hits per line

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

0.0
/src/rpc/rpc_device_handler.cpp
1
#include "rpc_device_handler.h"
2
#include "rpc_device_load_config_task.h"
3
#include "rpc_device_probe_task.h"
4
#include "rpc_helpers.h"
5

UNCOV
6
void TRPCDeviceParametersCache::RegisterCallbacks(PHandlerConfig handlerConfig)
×
7
{
8
    for (const auto& portConfig: handlerConfig->PortConfigs) {
×
9
        for (const auto& device: portConfig->Devices) {
×
10
            std::string id = GetId(*portConfig->Port, device->Device->DeviceConfig()->SlaveId);
×
11
            device->Device->AddOnConnectionStateChangedCallback([this, id](PSerialDevice device) {
×
12
                if (device->GetConnectionState() == TDeviceConnectionState::DISCONNECTED) {
×
13
                    Remove(id);
×
14
                }
15
            });
×
16
        }
17
    }
18
}
19

20
std::string TRPCDeviceParametersCache::GetId(const TPort& port, const std::string& slaveId) const
×
21
{
22
    return port.GetDescription(false) + ":" + slaveId;
×
23
}
24

25
void TRPCDeviceParametersCache::Add(const std::string& id, const Json::Value& value)
×
26
{
27
    std::unique_lock lock(Mutex);
×
28
    DeviceParameters[id] = value;
×
29
}
30

31
void TRPCDeviceParametersCache::Remove(const std::string& id)
×
32
{
33
    std::unique_lock lock(Mutex);
×
34
    DeviceParameters.erase(id);
×
35
}
36

37
bool TRPCDeviceParametersCache::Contains(const std::string& id) const
×
38
{
39
    std::unique_lock lock(Mutex);
×
40
    return DeviceParameters.find(id) != DeviceParameters.end();
×
41
}
42

43
const Json::Value& TRPCDeviceParametersCache::Get(const std::string& id, const Json::Value& defaultValue) const
×
44
{
45
    std::unique_lock lock(Mutex);
×
46
    auto it = DeviceParameters.find(id);
×
47
    return it != DeviceParameters.end() ? it->second : defaultValue;
×
48
};
49

50
TRPCDeviceHandler::TRPCDeviceHandler(const std::string& requestDeviceLoadConfigSchemaFilePath,
×
51
                                     const std::string& requestDeviceProbeSchemaFilePath,
52
                                     const TSerialDeviceFactory& deviceFactory,
53
                                     PTemplateMap templates,
54
                                     TSerialClientTaskRunner& serialClientTaskRunner,
55
                                     TRPCDeviceParametersCache& parametersCache,
56
                                     WBMQTT::PMqttRpcServer rpcServer)
×
57
    : DeviceFactory(deviceFactory),
58
      RequestDeviceLoadConfigSchema(LoadRPCRequestSchema(requestDeviceLoadConfigSchemaFilePath, "device/LoadConfig")),
×
59
      RequestDeviceProbeSchema(LoadRPCRequestSchema(requestDeviceProbeSchemaFilePath, "device/Probe")),
×
60
      Templates(templates),
61
      SerialClientTaskRunner(serialClientTaskRunner),
62
      ParametersCache(parametersCache)
×
63
{
64
    rpcServer->RegisterAsyncMethod("device",
×
65
                                   "LoadConfig",
66
                                   std::bind(&TRPCDeviceHandler::LoadConfig,
×
67
                                             this,
×
68
                                             std::placeholders::_1,
69
                                             std::placeholders::_2,
70
                                             std::placeholders::_3));
×
71
    rpcServer->RegisterAsyncMethod("device",
×
72
                                   "Probe",
73
                                   std::bind(&TRPCDeviceHandler::Probe,
×
74
                                             this,
×
75
                                             std::placeholders::_1,
76
                                             std::placeholders::_2,
77
                                             std::placeholders::_3));
×
78
}
79

80
void TRPCDeviceHandler::LoadConfig(const Json::Value& request,
×
81
                                   WBMQTT::TMqttRpcServer::TResultCallback onResult,
82
                                   WBMQTT::TMqttRpcServer::TErrorCallback onError)
83
{
84
    ValidateRPCRequest(request, RequestDeviceLoadConfigSchema);
×
85

86
    try {
87
        auto rpcRequest =
NEW
88
            ParseRPCDeviceLoadConfigRequest(request, DeviceFactory, Templates, ParametersCache, onResult, onError);
×
89
        SerialClientTaskRunner.RunTask(request, std::make_shared<TRPCDeviceLoadConfigSerialClientTask>(rpcRequest));
×
90
    } catch (const TRPCException& e) {
×
91
        ProcessException(e, onError);
×
92
    }
93
}
94

95
void TRPCDeviceHandler::Probe(const Json::Value& request,
×
96
                              WBMQTT::TMqttRpcServer::TResultCallback onResult,
97
                              WBMQTT::TMqttRpcServer::TErrorCallback onError)
98
{
99
    ValidateRPCRequest(request, RequestDeviceProbeSchema);
×
100
    try {
101
        SerialClientTaskRunner.RunTask(request,
×
102
                                       std::make_shared<TRPCDeviceProbeSerialClientTask>(request, onResult, onError));
×
103
    } catch (const TRPCException& e) {
×
104
        ProcessException(e, onError);
×
105
    }
106
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc