syncinterfacecommandtranslator.cpp 4.6 KB
Newer Older
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
/** @file
 * This file is part of the SpaceCreator.
 *
 * @copyright (C) 2021 N7 Space Sp. z o.o.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this program. If not, see <https://www.gnu.org/licenses/lgpl-2.1.html>.
 */

#include "specialized/syncinterfacecommandtranslator.h"

#include <conversion/common/translation/exceptions.h>
#include <ivcore/ivfunction.h>
#include <seds/SedsModel/interfaces/argumentscombination.h>
#include <seds/SedsModel/interfaces/interfacecommand.h>

using conversion::translator::TranslationException;
using conversion::translator::UnhandledValueException;
29
using conversion::translator::UnsupportedValueException;
30
31
32
33
34
35
36
37
38
39
40
41
42

namespace conversion::iv::translator {

SyncInterfaceCommandTranslator::SyncInterfaceCommandTranslator(
        const seds::model::Interface &interface, ivm::IVFunction *ivFunction)
    : InterfaceCommandTranslator(interface, ivFunction)
{
}

void SyncInterfaceCommandTranslator::translateCommand(
        const seds::model::InterfaceCommand &command, ivm::IVInterface::InterfaceType interfaceType)
{
    switch (command.argumentsCombination()) {
43
44
45
46
47
    case seds::model::ArgumentsCombination::InOnly:
    case seds::model::ArgumentsCombination::OutOnly:
    case seds::model::ArgumentsCombination::InAndOut: {
        auto *ivInterface = createIvInterface(command, interfaceType, ivm::IVInterface::OperationKind::Protected);
        translateArguments(command.arguments(), ivInterface);
48
49
50
51
        m_ivFunction->addChild(ivInterface);
    } break;
    case seds::model::ArgumentsCombination::NoArgs:
    case seds::model::ArgumentsCombination::NotifyOnly:
52
    case seds::model::ArgumentsCombination::InAndNotify:
53
54
55
56
57
58
59
60
61
62
63
64
65
    case seds::model::ArgumentsCombination::OutAndNotify:
    case seds::model::ArgumentsCombination::All: {
        const auto message = QString(
                "Interface command arguments combination '%1' is not supported for TASTE InterfaceView async interface")
                                     .arg(argumentsCombinationToString(command.argumentsCombination()));
        throw TranslationException(message);
    } break;
    default:
        throw UnhandledValueException("ArgumentsCombination");
        break;
    }
}

66
67
68
69
70
71
72
void SyncInterfaceCommandTranslator::translateArguments(
        const std::vector<seds::model::CommandArgument> &arguments, ivm::IVInterface *ivInterface)
{
    for (const auto &argument : arguments) {
        switch (argument.mode()) {
        case seds::model::CommandArgumentMode::In: {
            const auto ivParameter = createIvInterfaceParameter(
Filip Demski's avatar
Filip Demski committed
73
                    argument.nameStr(), argument.type().nameStr(), shared::InterfaceParameter::Direction::IN);
74
75
76
77
            ivInterface->addParam(ivParameter);
        } break;
        case seds::model::CommandArgumentMode::Out: {
            const auto ivParameter = createIvInterfaceParameter(
Filip Demski's avatar
Filip Demski committed
78
                    argument.nameStr(), argument.type().nameStr(), shared::InterfaceParameter::Direction::OUT);
79
80
81
82
            ivInterface->addParam(ivParameter);
        } break;
        case seds::model::CommandArgumentMode::InOut: {
            const auto ivParameterIn = createIvInterfaceParameter(QString("%1_In").arg(argument.nameStr()),
Filip Demski's avatar
Filip Demski committed
83
                    argument.type().nameStr(), shared::InterfaceParameter::Direction::IN);
84
85
            ivInterface->addParam(ivParameterIn);
            const auto ivParameterOut = createIvInterfaceParameter(QString("%2_Out").arg(argument.nameStr()),
Filip Demski's avatar
Filip Demski committed
86
                    argument.type().nameStr(), shared::InterfaceParameter::Direction::OUT);
87
88
89
90
91
92
93
94
95
            ivInterface->addParam(ivParameterOut);
        } break;
        case seds::model::CommandArgumentMode::Notify:
            throw UnsupportedValueException("CommandArgumentMode", "Notify");
            break;
        }
    }
}

Filip Demski's avatar
Filip Demski committed
96
97
shared::InterfaceParameter SyncInterfaceCommandTranslator::createIvInterfaceParameter(
        const QString &name, const QString &typeName, shared::InterfaceParameter::Direction direction)
98
{
Filip Demski's avatar
Filip Demski committed
99
100
    return shared::InterfaceParameter(
            name, shared::BasicParameter::Type::Other, typeName, m_interfaceParameterEncoding, direction);
101
102
}

103
} // namespace conversion::iv::translator