summaryrefslogtreecommitdiff
path: root/include/CommonAPI/Stub.hpp
blob: 8241bf18b35d4a2f623e8221596d020bcf2c8cb0 (plain)
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
// Copyright (C) 2014-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#if !defined (COMMONAPI_INTERNAL_COMPILATION)
#error "Only <CommonAPI/CommonAPI.hpp> can be included directly, this file may disappear or change contents."
#endif

#ifndef COMMONAPI_STUB_HPP_
#define COMMONAPI_STUB_HPP_

#include <memory>
#include <string>
#include <type_traits>

#include <CommonAPI/Address.hpp>
#include <CommonAPI/Types.hpp>

namespace CommonAPI {

class StubAdapter {
public:
    virtual ~StubAdapter() {}
    inline const Address &getAddress() const { return address_; }

protected:
    Address address_;
};

class StubBase {
public:
    virtual ~StubBase() {}
    virtual bool hasElement(const uint32_t _id) const = 0;
};

template<typename StubAdapter_, typename StubRemoteEventHandler_>
class Stub: public virtual StubBase {
    static_assert(std::is_base_of<StubAdapter, StubAdapter_>::value, "Invalid StubAdapter Class!");
public:
    typedef StubAdapter_ StubAdapterType;
    typedef StubRemoteEventHandler_ RemoteEventHandlerType;

    virtual ~Stub() {}

    virtual StubRemoteEventHandler_* initStubAdapter(const std::shared_ptr<StubAdapter_> &_stubAdapter) = 0;

    inline const std::shared_ptr<StubAdapter_> getStubAdapter() const { return stubAdapter_.lock(); }

protected:
    std::weak_ptr<StubAdapter_> stubAdapter_;
};

enum SelectiveBroadcastSubscriptionEvent {
    SUBSCRIBED,
    UNSUBSCRIBED
};

} // namespace CommonAPI

#endif // COMMONAPI_STUB_HPP_