File: TestAdaptor.h

package info (click to toggle)
sdbus-cpp 1.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,296 kB
  • sloc: cpp: 9,859; xml: 170; ansic: 135; makefile: 27
file content (114 lines) | stat: -rw-r--r-- 4,592 bytes parent folder | download
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
 * (C) 2016 - 2021 KISTLER INSTRUMENTE AG, Winterthur, Switzerland
 * (C) 2016 - 2022 Stanislav Angelovic <stanislav.angelovic@protonmail.com>
 *
 * @file TestAdaptor.h
 *
 * Created on: Jan 2, 2017
 * Project: sdbus-c++
 * Description: High-level D-Bus IPC C++ library based on sd-bus
 *
 * This file is part of sdbus-c++.
 *
 * sdbus-c++ is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * sdbus-c++ 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with sdbus-c++. If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef SDBUS_CPP_INTEGRATIONTESTS_TESTADAPTOR_H_
#define SDBUS_CPP_INTEGRATIONTESTS_TESTADAPTOR_H_

#include "integrationtests-adaptor.h"
#include "Defs.h"
#include <thread>
#include <chrono>
#include <atomic>
#include <utility>

namespace sdbus { namespace test {

class ObjectManagerTestAdaptor final : public sdbus::AdaptorInterfaces< sdbus::ObjectManager_adaptor >
{
public:
    ObjectManagerTestAdaptor(sdbus::IConnection& connection, std::string path) :
        AdaptorInterfaces(connection, std::move(path))
    {
        registerAdaptor();
    }

    ~ObjectManagerTestAdaptor()
    {
        unregisterAdaptor();
    }
};

class TestAdaptor final : public sdbus::AdaptorInterfaces< org::sdbuscpp::integrationtests_adaptor
                                                         , sdbus::Properties_adaptor
                                                         , sdbus::ManagedObject_adaptor >
{
public:
    TestAdaptor(sdbus::IConnection& connection, const std::string& path);
    ~TestAdaptor();

protected:
    void noArgNoReturn() override;
    int32_t getInt() override;
    std::tuple<uint32_t, std::string> getTuple() override;
    double multiply(const int64_t& a, const double& b) override;
    void multiplyWithNoReply(const int64_t& a, const double& b) override;
    std::vector<int16_t> getInts16FromStruct(const sdbus::Struct<uint8_t, int16_t, double, std::string, std::vector<int16_t>>& arg0) override;
    sdbus::Variant processVariant(const sdbus::Variant& variant) override;
    std::map<int32_t, sdbus::Variant> getMapOfVariants(const std::vector<int32_t>& x, const sdbus::Struct<sdbus::Variant, sdbus::Variant>& y) override;
    sdbus::Struct<std::string, sdbus::Struct<std::map<int32_t, int32_t>>> getStructInStruct() override;
    int32_t sumStructItems(const sdbus::Struct<uint8_t, uint16_t>& arg0, const sdbus::Struct<int32_t, int64_t>& arg1) override;
    uint32_t sumVectorItems(const std::vector<uint16_t>& arg0, const std::vector<uint64_t>& arg1) override;
    uint32_t doOperation(const uint32_t& arg0) override;
    void doOperationAsync(sdbus::Result<uint32_t>&& result, uint32_t arg0) override;
    sdbus::Signature getSignature() override;
    sdbus::ObjectPath getObjPath() override;
    sdbus::UnixFd getUnixFd() override;
    std::map<uint64_t, sdbus::Struct<std::map<uint8_t, std::vector<sdbus::Struct<sdbus::ObjectPath, bool, sdbus::Variant, std::map<int32_t, std::string>>>>, sdbus::Signature, std::string>> getComplex() override;
    void throwError() override;
    void throwErrorWithNoReply() override;
    void doPrivilegedStuff() override;
    void emitTwoSimpleSignals() override;

    uint32_t action() override;
    void action(const uint32_t& value) override;
    bool blocking() override;
    void blocking(const bool& value) override;
    std::string state() override;

public:
    void emitSignalWithoutRegistration(const sdbus::Struct<std::string, sdbus::Struct<sdbus::Signature>>& s);
    std::string getExpectedXmlApiDescription() const;

private:
    const std::string m_state{DEFAULT_STATE_VALUE};
    uint32_t m_action{DEFAULT_ACTION_VALUE};
    bool m_blocking{DEFAULT_BLOCKING_VALUE};

public: // for tests
    // For dont-expect-reply method call verifications
    mutable std::atomic<bool> m_wasMultiplyCalled{false};
    mutable double m_multiplyResult{};
    mutable std::atomic<bool> m_wasThrowErrorCalled{false};

    const Message* m_methodCallMsg{};
    std::string m_methodCallMemberName;
    const Message* m_propertySetMsg{};
    std::string m_propertySetSender;
};

}}

#endif /* INTEGRATIONTESTS_TESTADAPTOR_H_ */