~aleteoryx/muditaos

muditaos/module-sys/Service/BusProxy.cpp -rw-r--r-- 2.2 KiB
a405cad6Aleteoryx trim readme 6 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#include <Service/BusProxy.hpp>

#include "details/bus/Bus.hpp"

namespace sys
{
    BusProxy::BusProxy(Service *owner, Watchdog &watchdog)
        : owner{owner}, watchdog{watchdog}, busImpl{std::make_unique<Bus>()}
    {
        channels.push_back(BusChannel::System); // Mandatory for each service.
    }

    BusProxy::~BusProxy() noexcept = default;

    bool BusProxy::sendUnicast(std::shared_ptr<Message> message, const std::string &targetName)
    {
        auto ret = busImpl->SendUnicast(std::move(message), targetName, owner);
        if (ret) {
            watchdog.refresh();
        }
        return ret;
    }

    SendResult BusProxy::unicastSync(std::shared_ptr<Message> message, sys::Service *whose, std::uint32_t timeout)
    {
        auto ret = busImpl->UnicastSync(message, whose, timeout);
        if (ret.first != ReturnCodes::Failure) {
            watchdog.refresh();
        }
        return ret;
    }

    SendResult BusProxy::sendUnicastSync(std::shared_ptr<Message> message,
                                         const std::string &targetName,
                                         uint32_t timeout)
    {
        auto ret = busImpl->SendUnicastSync(std::move(message), targetName, owner, timeout);
        if (ret.first != ReturnCodes::Failure) {
            watchdog.refresh();
        }
        return ret;
    }

    void BusProxy::sendMulticast(std::shared_ptr<Message> message, BusChannel channel)
    {
        busImpl->SendMulticast(std::move(message), channel, owner);
        watchdog.refresh();
    }

    void BusProxy::sendBroadcast(std::shared_ptr<Message> message)
    {
        busImpl->SendBroadcast(std::move(message), owner);
        watchdog.refresh();
    }

    void BusProxy::sendResponse(std::shared_ptr<Message> response, std::shared_ptr<Message> request)
    {
        busImpl->SendResponse(std::move(response), std::move(request), owner);
    }

    void BusProxy::connect()
    {
        Bus::Add(owner);
    }

    void BusProxy::disconnect()
    {
        Bus::Remove(owner);
    }
} // namespace sys