Reorganise to remove redundant folder
[profile/ivi/common-api-dbus-runtime.git] / src / test / commonapi / tests / TestInterfaceDBusStubAdapter.cpp
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 #include "TestInterfaceDBusStubAdapter.h"
5 #include "TestInterface.h"
6
7 namespace commonapi {
8 namespace tests {
9
10 std::shared_ptr<CommonAPI::DBus::DBusStubAdapter> createTestInterfaceDBusStubAdapter(std::string busName,
11                                                            std::string objectPath,
12                                                            std::shared_ptr<CommonAPI::DBus::DBusProxyConnection> dbusProxyConnection,
13                                                            std::shared_ptr<CommonAPI::StubBase> stubBase) {
14     return std::make_shared<TestInterfaceDBusStubAdapter>(busName, objectPath, dbusProxyConnection, stubBase);
15 }
16
17 __attribute__((constructor)) void registerTestInterfaceDBusStubAdapter(void) {
18     CommonAPI::DBus::DBusFactory::registerAdapterFactoryMethod(TestInterface::getInterfaceName(),
19                                                                &createTestInterfaceDBusStubAdapter);
20 }
21
22 TestInterfaceDBusStubAdapter::TestInterfaceDBusStubAdapter(
23         const std::string& dbusBusName,
24         const std::string& dbusObjectPath,
25         const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusConnection,
26         const std::shared_ptr<CommonAPI::StubBase>& stub):
27         TestInterfaceDBusStubAdapterHelper(dbusBusName, dbusObjectPath, TestInterface::getInterfaceName(), dbusConnection, std::dynamic_pointer_cast<TestInterfaceStub>(stub)) {
28 }
29
30 const char* TestInterfaceDBusStubAdapter::getMethodsDBusIntrospectionXmlData() const {
31     return
32         "<method name=\"getTestPredefinedTypeAttributeAttribute\">\n"
33                 "<arg name=\"value\" type=\"u\" direction=\"out\" />"
34         "</method>\n"
35         "<method name=\"setTestPredefinedTypeAttributeAttribute\">\n"
36             "<arg name=\"requestedValue\" type=\"u\" direction=\"in\" />\n"
37             "<arg name=\"setValue\" type=\"u\" direction=\"out\" />\n"
38         "</method>\n"
39         "<signal name=\"onTestPredefinedTypeAttributeAttributeChanged\">\n"
40             "<arg name=\"changedValue\" type=\"u\" />\n"
41         "</signal>\n"
42         "<method name=\"getTestDerivedStructAttributeAttribute\">\n"
43                 "<arg name=\"value\" type=\"(sqi)\" direction=\"out\" />"
44         "</method>\n"
45         "<method name=\"setTestDerivedStructAttributeAttribute\">\n"
46             "<arg name=\"requestedValue\" type=\"(sqi)\" direction=\"in\" />\n"
47             "<arg name=\"setValue\" type=\"(sqi)\" direction=\"out\" />\n"
48         "</method>\n"
49         "<signal name=\"onTestDerivedStructAttributeAttributeChanged\">\n"
50             "<arg name=\"changedValue\" type=\"(sqi)\" />\n"
51         "</signal>\n"
52         "<method name=\"getTestDerivedArrayAttributeAttribute\">\n"
53                 "<arg name=\"value\" type=\"at\" direction=\"out\" />"
54         "</method>\n"
55         "<method name=\"setTestDerivedArrayAttributeAttribute\">\n"
56             "<arg name=\"requestedValue\" type=\"at\" direction=\"in\" />\n"
57             "<arg name=\"setValue\" type=\"at\" direction=\"out\" />\n"
58         "</method>\n"
59         "<signal name=\"onTestDerivedArrayAttributeAttributeChanged\">\n"
60             "<arg name=\"changedValue\" type=\"at\" />\n"
61         "</signal>\n"
62         "<signal name=\"TestPredefinedTypeBroadcast\">\n"
63             "<arg name=\"uint32Value\" type=\"u\" />\n"
64             "<arg name=\"stringValue\" type=\"s\" />\n"
65         "</signal>\n"
66         "<method name=\"testVoidPredefinedTypeMethod\">\n"
67             "<arg name=\"uint32Value\" type=\"u\" direction=\"in\" />\n"
68             "<arg name=\"stringValue\" type=\"s\" direction=\"in\" />\n"
69             "<arg name=\"uint32Value\" type=\"u\" direction=\"out\" />\n"
70             "<arg name=\"stringValue\" type=\"s\" direction=\"out\" />\n"
71         "</method>\n"
72         "<method name=\"testPredefinedTypeMethod\">\n"
73             "<arg name=\"uint32InValue\" type=\"u\" direction=\"in\" />\n"
74             "<arg name=\"stringInValue\" type=\"s\" direction=\"in\" />\n"
75             "<arg name=\"uint32InValue\" type=\"u\" direction=\"out\" />\n"
76             "<arg name=\"stringInValue\" type=\"s\" direction=\"out\" />\n"
77         "</method>\n"
78         "<method name=\"testVoidDerivedTypeMethod\">\n"
79             "<arg name=\"testEnumExtended2Value\" type=\"i\" direction=\"in\" />\n"
80             "<arg name=\"testMapValue\" type=\"a{ua(sq)}\" direction=\"in\" />\n"
81             "<arg name=\"testEnumExtended2Value\" type=\"i\" direction=\"out\" />\n"
82             "<arg name=\"testMapValue\" type=\"a{ua(sq)}\" direction=\"out\" />\n"
83         "</method>\n"
84         "<method name=\"testDerivedTypeMethod\">\n"
85             "<arg name=\"testEnumExtended2InValue\" type=\"i\" direction=\"in\" />\n"
86             "<arg name=\"testMapInValue\" type=\"a{ua(sq)}\" direction=\"in\" />\n"
87             "<arg name=\"testEnumExtended2InValue\" type=\"i\" direction=\"out\" />\n"
88             "<arg name=\"testMapInValue\" type=\"a{ua(sq)}\" direction=\"out\" />\n"
89         "</method>\n"
90     ;
91 }
92
93
94 static CommonAPI::DBus::DBusGetAttributeStubDispatcher<
95         TestInterfaceStub,
96         uint32_t
97         > getTestPredefinedTypeAttributeAttributeStubDispatcher(&TestInterfaceStub::getTestPredefinedTypeAttributeAttribute, "u");
98 static CommonAPI::DBus::DBusSetObservableAttributeStubDispatcher<
99         TestInterfaceStub,
100         uint32_t
101         > setTestPredefinedTypeAttributeAttributeStubDispatcher(
102                 &TestInterfaceStub::getTestPredefinedTypeAttributeAttribute,
103                 &TestInterfaceStubRemoteEvent::onRemoteSetTestPredefinedTypeAttributeAttribute,
104                 &TestInterfaceStubRemoteEvent::onRemoteTestPredefinedTypeAttributeAttributeChanged,
105                 &TestInterfaceStubAdapter::fireTestPredefinedTypeAttributeAttributeChanged,
106                 "u");
107
108 static CommonAPI::DBus::DBusGetAttributeStubDispatcher<
109         TestInterfaceStub,
110         DerivedTypeCollection::TestStructExtended
111         > getTestDerivedStructAttributeAttributeStubDispatcher(&TestInterfaceStub::getTestDerivedStructAttributeAttribute, "(sqi)");
112 static CommonAPI::DBus::DBusSetObservableAttributeStubDispatcher<
113         TestInterfaceStub,
114         DerivedTypeCollection::TestStructExtended
115         > setTestDerivedStructAttributeAttributeStubDispatcher(
116                 &TestInterfaceStub::getTestDerivedStructAttributeAttribute,
117                 &TestInterfaceStubRemoteEvent::onRemoteSetTestDerivedStructAttributeAttribute,
118                 &TestInterfaceStubRemoteEvent::onRemoteTestDerivedStructAttributeAttributeChanged,
119                 &TestInterfaceStubAdapter::fireTestDerivedStructAttributeAttributeChanged,
120                 "(sqi)");
121
122 static CommonAPI::DBus::DBusGetAttributeStubDispatcher<
123         TestInterfaceStub,
124         DerivedTypeCollection::TestArrayUInt64
125         > getTestDerivedArrayAttributeAttributeStubDispatcher(&TestInterfaceStub::getTestDerivedArrayAttributeAttribute, "at");
126 static CommonAPI::DBus::DBusSetObservableAttributeStubDispatcher<
127         TestInterfaceStub,
128         DerivedTypeCollection::TestArrayUInt64
129         > setTestDerivedArrayAttributeAttributeStubDispatcher(
130                 &TestInterfaceStub::getTestDerivedArrayAttributeAttribute,
131                 &TestInterfaceStubRemoteEvent::onRemoteSetTestDerivedArrayAttributeAttribute,
132                 &TestInterfaceStubRemoteEvent::onRemoteTestDerivedArrayAttributeAttributeChanged,
133                 &TestInterfaceStubAdapter::fireTestDerivedArrayAttributeAttributeChanged,
134                 "at");
135
136
137 static CommonAPI::DBus::DBusMethodWithReplyStubDispatcher<
138     TestInterfaceStub,
139     std::tuple<uint32_t, std::string>,
140     std::tuple<>
141     > testVoidPredefinedTypeMethodStubDispatcher(&TestInterfaceStub::testVoidPredefinedTypeMethod, "");
142
143 static CommonAPI::DBus::DBusMethodWithReplyStubDispatcher<
144     TestInterfaceStub,
145     std::tuple<uint32_t, std::string>,
146     std::tuple<uint32_t, std::string>
147     > testPredefinedTypeMethodStubDispatcher(&TestInterfaceStub::testPredefinedTypeMethod, "us");
148
149 static CommonAPI::DBus::DBusMethodWithReplyStubDispatcher<
150     TestInterfaceStub,
151     std::tuple<DerivedTypeCollection::TestEnumExtended2, DerivedTypeCollection::TestMap>,
152     std::tuple<>
153     > testVoidDerivedTypeMethodStubDispatcher(&TestInterfaceStub::testVoidDerivedTypeMethod, "");
154
155 static CommonAPI::DBus::DBusMethodWithReplyStubDispatcher<
156     TestInterfaceStub,
157     std::tuple<DerivedTypeCollection::TestEnumExtended2, DerivedTypeCollection::TestMap>,
158     std::tuple<DerivedTypeCollection::TestEnumExtended2, DerivedTypeCollection::TestMap>
159     > testDerivedTypeMethodStubDispatcher(&TestInterfaceStub::testDerivedTypeMethod, "ia{ua(sq)}");
160
161
162 template<>
163 const TestInterfaceDBusStubAdapterHelper::StubDispatcherTable TestInterfaceDBusStubAdapterHelper::stubDispatcherTable_ = {
164     { { "getTestPredefinedTypeAttributeAttribute", "" }, &commonapi::tests::getTestPredefinedTypeAttributeAttributeStubDispatcher }
165     , { { "setTestPredefinedTypeAttributeAttribute", "u" }, &commonapi::tests::setTestPredefinedTypeAttributeAttributeStubDispatcher },
166     { { "getTestDerivedStructAttributeAttribute", "" }, &commonapi::tests::getTestDerivedStructAttributeAttributeStubDispatcher }
167     , { { "setTestDerivedStructAttributeAttribute", "(sqi)" }, &commonapi::tests::setTestDerivedStructAttributeAttributeStubDispatcher },
168     { { "getTestDerivedArrayAttributeAttribute", "" }, &commonapi::tests::getTestDerivedArrayAttributeAttributeStubDispatcher }
169     , { { "setTestDerivedArrayAttributeAttribute", "at" }, &commonapi::tests::setTestDerivedArrayAttributeAttributeStubDispatcher }
170     ,
171     { { "testVoidPredefinedTypeMethod", "us" }, &commonapi::tests::testVoidPredefinedTypeMethodStubDispatcher },
172     { { "testPredefinedTypeMethod", "us" }, &commonapi::tests::testPredefinedTypeMethodStubDispatcher },
173     { { "testVoidDerivedTypeMethod", "ia{ua(sq)}" }, &commonapi::tests::testVoidDerivedTypeMethodStubDispatcher },
174     { { "testDerivedTypeMethod", "ia{ua(sq)}" }, &commonapi::tests::testDerivedTypeMethodStubDispatcher }
175 };
176
177 void TestInterfaceDBusStubAdapter::fireTestPredefinedTypeAttributeAttributeChanged(const uint32_t& value) {
178     CommonAPI::DBus::DBusStubSignalHelper<CommonAPI::DBus::DBusSerializableArguments<uint32_t>>
179         ::sendSignal(
180             *this,
181             "onTestPredefinedTypeAttributeAttributeChanged",
182             "u",
183             value
184     );
185 }
186 void TestInterfaceDBusStubAdapter::fireTestDerivedStructAttributeAttributeChanged(const DerivedTypeCollection::TestStructExtended& value) {
187         CommonAPI::DBus::DBusStubSignalHelper<CommonAPI::DBus::DBusSerializableArguments<DerivedTypeCollection::TestStructExtended>>
188         ::sendSignal(
189             *this,
190             "onTestDerivedStructAttributeAttributeChanged",
191             "(sqi)",
192             value
193     );
194 }
195 void TestInterfaceDBusStubAdapter::fireTestDerivedArrayAttributeAttributeChanged(const DerivedTypeCollection::TestArrayUInt64& value) {
196         CommonAPI::DBus::DBusStubSignalHelper<CommonAPI::DBus::DBusSerializableArguments<DerivedTypeCollection::TestArrayUInt64>>
197         ::sendSignal(
198             *this,
199             "onTestDerivedArrayAttributeAttributeChanged",
200             "at",
201             value
202     );
203 }
204
205 void TestInterfaceDBusStubAdapter::fireTestPredefinedTypeBroadcastEvent(const uint32_t& uint32Value, const std::string& stringValue) {
206     CommonAPI::DBus::DBusStubSignalHelper<CommonAPI::DBus::DBusSerializableArguments<uint32_t, std::string>>
207             ::sendSignal(
208                 *this,
209                 "TestPredefinedTypeBroadcast",
210                 "us",
211                 uint32Value, stringValue
212         );
213 }
214
215 } // namespace tests
216 } // namespace commonapi