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

mavlink / MAVSDK / 7317183253

24 Dec 2023 10:25PM UTC coverage: 36.26% (-0.6%) from 36.89%
7317183253

push

github

web-flow
Merge pull request #2088 from tbago/add_more_camera_function

More camera server functionality

28 of 718 new or added lines in 12 files covered. (3.9%)

20 existing lines in 6 files now uncovered.

10035 of 27675 relevant lines covered (36.26%)

127.93 hits per line

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

83.33
/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(
8✔
7
    const std::string& name, const ParamChangedCallback<T>& callback, const void* cookie)
8
{
9
    std::lock_guard<std::mutex> lock(_param_changed_subscriptions_mutex);
16✔
10
    if (callback != nullptr) {
8✔
11
        ParamChangedSubscription subscription{name, callback, cookie};
32✔
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);
8✔
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
}
8✔
38

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

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

51
void MavlinkParameterSubscription::subscribe_param_custom_changed(
8✔
52
    const std::string& name, const ParamCustomChangedCallback& callback, const void* cookie)
53
{
54
    subscribe_param_changed<std::string>(name, callback, cookie);
8✔
55
}
8✔
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) {
16✔
62
        if (subscription.param_name != param_name) {
10✔
63
            continue;
4✔
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()) {
6✔
68
            std::get<ParamFloatChangedCallback>(subscription.callback)(value.get_float().value());
2✔
69
        } else if (
6✔
70
            std::get_if<ParamIntChangedCallback>(&subscription.callback) && value.get_int()) {
6✔
71
            std::get<ParamIntChangedCallback>(subscription.callback)(value.get_int().value());
2✔
72
        } else if (
4✔
73
            std::get_if<ParamCustomChangedCallback>(&subscription.callback) && value.get_custom()) {
4✔
74
            std::get<ParamCustomChangedCallback>(subscription.callback)(value.get_custom().value());
2✔
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
void MavlinkParameterSubscription::unsubscribe_all_params_changed(const void* cookie)
6✔
83
{
84
    std::lock_guard<std::mutex> lock(_param_changed_subscriptions_mutex);
12✔
85

86
    for (auto it = _param_changed_subscriptions.begin(); it != _param_changed_subscriptions.end();
30✔
87
         /* it++ */) {
88
        if (it->cookie == cookie) {
24✔
89
            it = _param_changed_subscriptions.erase(it);
24✔
90
        } else {
NEW
91
            it++;
×
92
        }
93
    }
94
}
6✔
95

96
} // 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

© 2026 Coveralls, Inc