~aleteoryx/muditaos

ref: 4e0f72e70ac08cd9278e1f380b6733662d55114a muditaos/module-sys/Service/Message.cpp -rw-r--r-- 1.5 KiB
4e0f72e7 — Piotr Tanski [EGD-4696] Several stabilization patches. (#1192) 5 years 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
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "Message.hpp"
#include "Service.hpp"
#include "Bus.hpp"
#include "Channel.hpp"
#include "ticks.hpp"

#include <string.h>

namespace sys
{
    SendResult CreateSendResult(ReturnCodes retCode, MessagePointer msg)
    {
        return std::make_pair(retCode, msg);
    }

    Message::Message(BusChannels channel) : channel{channel}
    {}

    MessagePointer Message::Execute(Service *service)
    {
        return Proxy::handleMessage(service, this);
    }

    SystemMessage::SystemMessage(SystemMessageType systemMessageType, ServicePowerMode pwrMode)
        : Message(BusChannels::System), systemMessageType(systemMessageType), powerMode(pwrMode)
    {
        type = Type::System;
    }

    MessagePointer SystemMessage::Execute(Service *service)
    {
        return Proxy::handleSystemMessage(service, this);
    }

    DataMessage::DataMessage(MessageType messageType) : messageType{messageType}
    {
        type = Type::Data;
    }

    DataMessage::DataMessage(BusChannels channel) : Message(channel)
    {
        type = Type::Data;
    }

    ResponseMessage::ResponseMessage(ReturnCodes retCode, MessageType responseTo)
        : retCode(retCode), responseTo(responseTo)
    {
        type = Type::Response;
    }

    MessagePointer ResponseMessage::Execute(Service *service)
    {
        return Proxy::handleMessage(service, nullptr, this);
    }
} // namespace sys