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

mavlink / MAVSDK / 4899817366

pending completion
4899817366

Pull #1772

github

GitHub
Merge c0bb90862 into e4e9c71dd
Pull Request #1772: Refactor MAVLinkParameters into client and server classes

2192 of 2192 new or added lines in 34 files covered. (100.0%)

7708 of 24812 relevant lines covered (31.07%)

19.96 hits per line

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

11.43
/src/mavsdk/core/mavlink_parameter_subscription.cpp
1
#include "mavlink_parameter_subscription.h"
2

3
namespace mavsdk {
4

5
template<class T>
6
void MavlinkParameterSubscription::subscribe_param_changed(
×
7
    const std::string& name, const ParamChangedCallback<T>& callback, const void* cookie)
8
{
9
    std::lock_guard<std::mutex> lock(_param_changed_subscriptions_mutex);
×
10
    if (callback != nullptr) {
×
11
        ParamChangedSubscription subscription{name, callback, cookie};
×
12
        // This is just to let the upper level know of what probably is a bug, but we check again
13
        // when actually calling the callback We also cannot assume here that the user called
14
        // provide_param before subscribe_param_changed, so the only thing that makes sense is to
15
        // log a warning, but then continue anyways.
16
        /*std::lock_guard<std::mutex> lock2(_all_params_mutex);
17
        if (_all_params.find(name) != _all_params.end()) {
18
            const auto curr_value = _all_params.at(name);
19
            if (!curr_value.template is_same_type_templated<T>()) {
20
                LogDebug()
21
                    << "You just registered a param changed callback where the type does not match
22
        the type already stored";
23
            }
24
        }*/
25
        _param_changed_subscriptions.push_back(subscription);
×
26
    } else {
27
        for (auto it = _param_changed_subscriptions.begin();
×
28
             it != _param_changed_subscriptions.end();
×
29
             /* ++it */) {
30
            if (it->param_name == name && it->cookie == cookie) {
×
31
                it = _param_changed_subscriptions.erase(it);
×
32
            } else {
33
                ++it;
×
34
            }
35
        }
36
    }
37
}
×
38

39
void MavlinkParameterSubscription::subscribe_param_float_changed(
×
40
    const std::string& name, const ParamFloatChangedCallback& callback, const void* cookie)
41
{
42
    subscribe_param_changed<float>(name, callback, cookie);
×
43
}
×
44

45
void MavlinkParameterSubscription::subscribe_param_int_changed(
×
46
    const std::string& name, const ParamIntChangedCallback& callback, const void* cookie)
47
{
48
    subscribe_param_changed<int>(name, callback, cookie);
×
49
}
×
50

51
void MavlinkParameterSubscription::subscribe_param_custom_changed(
×
52
    const std::string& name, const ParamCustomChangedCallback& callback, const void* cookie)
53
{
54
    subscribe_param_changed<std::string>(name, callback, cookie);
×
55
}
×
56

57
void MavlinkParameterSubscription::find_and_call_subscriptions_value_changed(
6✔
58
    const std::string& param_name, const ParamValue& value)
59
{
60
    std::lock_guard<std::mutex> lock(_param_changed_subscriptions_mutex);
12✔
61
    for (const auto& subscription : _param_changed_subscriptions) {
6✔
62
        if (subscription.param_name != param_name) {
×
63
            continue;
×
64
        }
65
        // We have a subscription on this param name, now check if the subscription is for the right
66
        // type and call the callback when matching
67
        if (std::get_if<ParamFloatChangedCallback>(&subscription.callback) && value.get_float()) {
×
68
            std::get<ParamFloatChangedCallback>(subscription.callback)(value.get_float().value());
×
69
        } else if (
×
70
            std::get_if<ParamIntChangedCallback>(&subscription.callback) && value.get_int()) {
×
71
            std::get<ParamIntChangedCallback>(subscription.callback)(value.get_int().value());
×
72
        } else if (
×
73
            std::get_if<ParamCustomChangedCallback>(&subscription.callback) && value.get_custom()) {
×
74
            std::get<ParamCustomChangedCallback>(subscription.callback)(value.get_custom().value());
×
75
        } else {
76
            // The callback we have set is not for this type.
77
            LogErr() << "Type and callback mismatch";
×
78
        }
79
    }
80
}
6✔
81

82
} // namespace mavsdk
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