summaryrefslogtreecommitdiff
path: root/src/test/src-gen/dbus/v1_0/commonapi/tests/managed/SecondRootDBusStubAdapter.cpp
blob: 36b8c104dee3f3645165af0715001204ebebb45a (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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* This file was generated by the CommonAPI Generators.
* Used org.genivi.commonapi.core 3.1.2.v201507021046.
* Used org.franca.core 0.9.1.201412191134.
*
* 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/.
*/
#include <v1_0/commonapi/tests/managed/SecondRoot.hpp>
#include <v1_0/commonapi/tests/managed/SecondRootDBusStubAdapter.hpp>

namespace v1_0 {
namespace commonapi {
namespace tests {
namespace managed {

std::shared_ptr<CommonAPI::DBus::DBusStubAdapter> createSecondRootDBusStubAdapter(
                   const CommonAPI::DBus::DBusAddress &_address,
                   const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection> &_connection,
                   const std::shared_ptr<CommonAPI::StubBase> &_stub) {
    return std::make_shared<SecondRootDBusStubAdapter>(_address, _connection, _stub);
}

INITIALIZER(registerSecondRootDBusStubAdapter) {
    CommonAPI::DBus::Factory::get()->registerStubAdapterCreateMethod(
    	SecondRoot::getInterface(), &createSecondRootDBusStubAdapter);
}

SecondRootDBusStubAdapterInternal::~SecondRootDBusStubAdapterInternal() {
    deactivateManagedInstances();
    SecondRootDBusStubAdapterHelper::deinit();
}

void SecondRootDBusStubAdapterInternal::deactivateManagedInstances() {
    std::set<std::string>::iterator iter;
    std::set<std::string>::iterator iterNext;

    iter = registeredLeafInterfaceInstances.begin();
    while (iter != registeredLeafInterfaceInstances.end()) {
        iterNext = std::next(iter);

        if (deregisterManagedStubLeafInterface(*iter)) {
            iter = iterNext;
        }
        else {
            iter++;
        }
    }
}

const char* SecondRootDBusStubAdapterInternal::getMethodsDBusIntrospectionXmlData() const {
    static const std::string introspectionData =
        "<method name=\"getInterfaceVersion\">\n"
            "<arg name=\"value\" type=\"uu\" direction=\"out\" />"
        "</method>\n"

        ""
    ;
    return introspectionData.c_str();
}

CommonAPI::DBus::DBusGetAttributeStubDispatcher<
        SecondRootStub,
        CommonAPI::Version
        > SecondRootDBusStubAdapterInternal::getSecondRootInterfaceVersionStubDispatcher(&SecondRootStub::getInterfaceVersion, "uu");








const SecondRootDBusStubAdapterHelper::StubDispatcherTable& SecondRootDBusStubAdapterInternal::getStubDispatcherTable() {
    return stubDispatcherTable_;
}

const CommonAPI::DBus::StubAttributeTable& SecondRootDBusStubAdapterInternal::getStubAttributeTable() {
    return stubAttributeTable_;
}
bool SecondRootDBusStubAdapterInternal::registerManagedStubLeafInterface(std::shared_ptr<LeafInterfaceStub> _stub, const std::string &_instance) {
    if (registeredLeafInterfaceInstances.find(_instance) == registeredLeafInterfaceInstances.end()) {
    	std::string itsAddress = "local:commonapi.tests.managed.LeafInterface:" + _instance;
        CommonAPI::DBus::DBusAddress itsDBusAddress;
        CommonAPI::DBus::DBusAddressTranslator::get()->translate(itsAddress, itsDBusAddress);

        std::string objectPath(itsDBusAddress.getObjectPath());
        std::string adapterObjectPath(getDBusAddress().getObjectPath());

        if (objectPath.compare(0, adapterObjectPath.length(), adapterObjectPath) == 0) {
        	std::shared_ptr<CommonAPI::DBus::Factory> itsFactory = CommonAPI::DBus::Factory::get();

            auto stubAdapter = itsFactory->createDBusStubAdapter(_stub, "commonapi.tests.managed.LeafInterface", itsDBusAddress, connection_);
            bool isRegistered = itsFactory->registerManagedService(stubAdapter);
            if (isRegistered) {
                bool isExported = connection_->getDBusObjectManager()->exportManagedDBusStubAdapter(adapterObjectPath, stubAdapter);
                if (isExported) {
                    registeredLeafInterfaceInstances.insert(_instance);
                    return true;
                } else {
                    itsFactory->unregisterManagedService(itsAddress);
                }
            }
        }
    }
    return false;
}

bool SecondRootDBusStubAdapterInternal::deregisterManagedStubLeafInterface(const std::string &_instance) {
    std::string itsAddress = "local:commonapi.tests.managed.LeafInterface:" + _instance;
    if (registeredLeafInterfaceInstances.find(_instance) != registeredLeafInterfaceInstances.end()) {
        std::shared_ptr<CommonAPI::DBus::Factory> itsFactory = CommonAPI::DBus::Factory::get();
        std::shared_ptr<CommonAPI::DBus::DBusStubAdapter> stubAdapter
            = itsFactory->getRegisteredService(itsAddress);
        if (stubAdapter) {
            connection_->getDBusObjectManager()->unexportManagedDBusStubAdapter(
                getDBusAddress().getObjectPath(), stubAdapter);
            itsFactory->unregisterManagedService(itsAddress);
            registeredLeafInterfaceInstances.erase(_instance);
            return true;
        }
    }
    return false;
}

std::set<std::string>& SecondRootDBusStubAdapterInternal::getLeafInterfaceInstances() {
    return registeredLeafInterfaceInstances;
}

SecondRootDBusStubAdapterInternal::SecondRootDBusStubAdapterInternal(
        const CommonAPI::DBus::DBusAddress &_address,
        const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection> &_connection,
        const std::shared_ptr<CommonAPI::StubBase> &_stub)
	: CommonAPI::DBus::DBusStubAdapter(_address, _connection,true),
      SecondRootDBusStubAdapterHelper(_address, _connection, std::dynamic_pointer_cast<SecondRootStub>(_stub), true),
      stubDispatcherTable_({
            }),
        stubAttributeTable_() {

    stubDispatcherTable_.insert({ { "getInterfaceVersion", "" }, &commonapi::tests::managed::SecondRootDBusStubAdapterInternal::getSecondRootInterfaceVersionStubDispatcher });
}

const bool SecondRootDBusStubAdapterInternal::hasFreedesktopProperties() {
    return false;
}

} // namespace managed
} // namespace tests
} // namespace commonapi
} // namespace v1_0