blob: 87850b082bf5d701aa6ec67f7cc6be376c617aa1 [file] [log] [blame]
Yifan Hongdd39db02016-10-06 13:50:49 -07001
2#define LOG_TAG "hidl_test"
3
4#include "Foo.h"
5#include "FooCallback.h"
6#include <android-base/logging.h>
Yifan Hong9171fb82016-10-17 11:38:15 -07007#include <hidl-test/FooHelper.h>
Yifan Hongdd39db02016-10-06 13:50:49 -07008#include <inttypes.h>
9#include <utils/Timers.h>
10
11namespace android {
12namespace hardware {
13namespace tests {
14namespace foo {
15namespace V1_0 {
16namespace implementation {
17
18// Methods from ::android::hardware::tests::foo::V1_0::IFoo follow.
19Return<void> Foo::doThis(float param) {
20 ALOGI("SERVER(Foo) doThis(%.2f)", param);
21
22 return Void();
23}
24
25Return<void> Foo::doThis(uint32_t param) {
26 ALOGI("SERVER(Foo) doThis (int) (%d)", param);
27 return Void();
28}
29
30Return<int32_t> Foo::doThatAndReturnSomething(
31 int64_t param) {
32 LOG(INFO) << "SERVER(Foo) doThatAndReturnSomething(" << param << ")";
33
34 return 666;
35}
36
37Return<double> Foo::doQuiteABit(
38 int32_t a,
39 int64_t b,
40 float c,
41 double d) {
42 LOG(INFO) << "SERVER(Foo) doQuiteABit("
43 << a
44 << ", "
45 << b
46 << ", "
47 << c
48 << ", "
49 << d
50 << ")";
51
52 return 666.5;
53}
54
55Return<void> Foo::doSomethingElse(
56 const hidl_array<int32_t, 15> &param, doSomethingElse_cb _cb) {
57 ALOGI("SERVER(Foo) doSomethingElse(...)");
58
59 hidl_array<int32_t, 32> result;
60 for (size_t i = 0; i < 15; ++i) {
61 result[i] = 2 * param[i];
62 result[15 + i] = param[i];
63 }
64 result[30] = 1;
65 result[31] = 2;
66
67 _cb(result);
68
69 return Void();
70}
71
72Return<void> Foo::doStuffAndReturnAString(
73 doStuffAndReturnAString_cb _cb) {
74 ALOGI("SERVER(Foo) doStuffAndReturnAString");
75
76 hidl_string s;
77 s = "Hello, world";
78
79 _cb(s);
80
81 return Void();
82}
83
84Return<void> Foo::mapThisVector(
85 const hidl_vec<int32_t> &param, mapThisVector_cb _cb) {
86 ALOGI("SERVER(Foo) mapThisVector");
87
88 hidl_vec<int32_t> out;
89 out.resize(param.size());
90
91 for (size_t i = 0; i < out.size(); ++i) {
92 out[i] = param[i] * 2;
93 }
94
95 _cb(out);
96
97 return Void();
98}
99
100Return<void> Foo::callMe(
101 const sp<IFooCallback> &cb) {
102 ALOGI("SERVER(Foo) callMe %p", cb.get());
103
104 if (cb != NULL) {
105
106 hidl_array<nsecs_t, 3> c;
107 ALOGI("SERVER(Foo) callMe %p calling IFooCallback::heyItsYou, " \
108 "should return immediately", cb.get());
109 c[0] = systemTime();
110 cb->heyItsYou(cb);
111 c[0] = systemTime() - c[0];
112 ALOGI("SERVER(Foo) callMe %p calling IFooCallback::heyItsYou " \
113 "returned after %" PRId64 "ns", cb.get(), c[0]);
114
115 ALOGI("SERVER(Foo) callMe %p calling IFooCallback::heyItsYouIsntIt, " \
116 "should block for %" PRId64 " seconds", cb.get(),
Yifan Hong9171fb82016-10-17 11:38:15 -0700117 DELAY_S);
Yifan Hongdd39db02016-10-06 13:50:49 -0700118 c[1] = systemTime();
119 bool answer = cb->heyItsYouIsntIt(cb);
120 c[1] = systemTime() - c[1];
121 ALOGI("SERVER(Foo) callMe %p IFooCallback::heyItsYouIsntIt " \
122 "responded with %d after %" PRId64 "ns", cb.get(), answer, c[1]);
123
124 ALOGI("SERVER(Foo) callMe %p calling " \
125 "IFooCallback::heyItsTheMeaningOfLife, " \
126 "should return immediately ", cb.get());
127 c[2] = systemTime();
128 cb->heyItsTheMeaningOfLife(42);
129 c[2] = systemTime() - c[2];
130 ALOGI("SERVER(Foo) callMe %p After call to " \
131 "IFooCallback::heyItsTheMeaningOfLife " \
132 "responded after %" PRId64 "ns", cb.get(), c[2]);
133
134 ALOGI("SERVER(Foo) callMe %p calling IFooCallback::youBlockedMeFor " \
135 "to report times", cb.get());
136 cb->youBlockedMeFor(c);
137 ALOGI("SERVER(Foo) callMe %p After call to " \
138 "IFooCallback::heyYouBlockedMeFor", cb.get());
139 }
140
141 return Void();
142}
143
144Return<Foo::SomeEnum> Foo::useAnEnum(SomeEnum param) {
145 ALOGI("SERVER(Foo) useAnEnum %d", (int)param);
146
147 return SomeEnum::goober;
148}
149
150Return<void> Foo::haveAGooberVec(const hidl_vec<Goober>& param) {
151 ALOGI("SERVER(Foo) haveAGooberVec &param = %p", &param);
152
153 return Void();
154}
155
156Return<void> Foo::haveAGoober(const Goober &g) {
157 ALOGI("SERVER(Foo) haveaGoober g=%p", &g);
158
159 return Void();
160}
161
162Return<void> Foo::haveAGooberArray(const hidl_array<Goober, 20> & /* lots */) {
163 ALOGI("SERVER(Foo) haveAGooberArray");
164
165 return Void();
166}
167
168Return<void> Foo::haveATypeFromAnotherFile(const Abc &def) {
169 ALOGI("SERVER(Foo) haveATypeFromAnotherFile def=%p", &def);
170
171 return Void();
172}
173
174Return<void> Foo::haveSomeStrings(
175 const hidl_array<hidl_string, 3> &array,
176 haveSomeStrings_cb _cb) {
177 ALOGI("SERVER(Foo) haveSomeStrings([\"%s\", \"%s\", \"%s\"])",
178 array[0].c_str(),
179 array[1].c_str(),
180 array[2].c_str());
181
182 hidl_array<hidl_string, 2> result;
183 result[0] = "Hello";
184 result[1] = "World";
185
186 _cb(result);
187
188 return Void();
189}
190
191Return<void> Foo::haveAStringVec(
192 const hidl_vec<hidl_string> &vector,
193 haveAStringVec_cb _cb) {
194 ALOGI("SERVER(Foo) haveAStringVec([\"%s\", \"%s\", \"%s\"])",
195 vector[0].c_str(),
196 vector[1].c_str(),
197 vector[2].c_str());
198
199 hidl_vec<hidl_string> result;
200 result.resize(2);
201
202 result[0] = "Hello";
203 result[1] = "World";
204
205 _cb(result);
206
207 return Void();
208}
209
Yifan Hongdd39db02016-10-06 13:50:49 -0700210Return<void> Foo::transposeMe(
211 const hidl_array<float, 3, 5> &in, transposeMe_cb _cb) {
212 ALOGI("SERVER(Foo) transposeMe(%s)", to_string(in).c_str());
213
214 hidl_array<float, 5, 3> out;
215 for (size_t i = 0; i < 5; ++i) {
216 for (size_t j = 0; j < 3; ++j) {
217 out[i][j] = in[j][i];
218 }
219 }
220
221 ALOGI("SERVER(Foo) transposeMe returning %s", to_string(out).c_str());
222
223 _cb(out);
224
225 return Void();
226}
Yifan Hongdd39db02016-10-06 13:50:49 -0700227
228Return<void> Foo::callingDrWho(
229 const MultiDimensional &in, callingDrWho_cb _hidl_cb) {
230 ALOGI("SERVER(Foo) callingDrWho(%s)", MultiDimensionalToString(in).c_str());
231
232 MultiDimensional out;
233 for (size_t i = 0; i < 5; ++i) {
234 for (size_t j = 0; j < 3; ++j) {
235 out.quuxMatrix[i][j].first = in.quuxMatrix[4 - i][2 - j].last;
236 out.quuxMatrix[i][j].last = in.quuxMatrix[4 - i][2 - j].first;
237 }
238 }
239
240 _hidl_cb(out);
241
242 return Void();
243}
244
245Return<void> Foo::transpose(const StringMatrix5x3 &in, transpose_cb _hidl_cb) {
246 LOG(INFO) << "SERVER(Foo) transpose " << to_string(in);
247
248 StringMatrix3x5 out;
249 for (size_t i = 0; i < 3; ++i) {
250 for (size_t j = 0; j < 5; ++j) {
251 out.s[i][j] = in.s[j][i];
252 }
253 }
254
255 _hidl_cb(out);
256
257 return Void();
258}
259
260Return<void> Foo::transpose2(
261 const hidl_array<hidl_string, 5, 3> &in, transpose2_cb _hidl_cb) {
262 LOG(INFO) << "SERVER(Foo) transpose2 " << to_string(in);
263
264 hidl_array<hidl_string, 3, 5> out;
265 for (size_t i = 0; i < 3; ++i) {
266 for (size_t j = 0; j < 5; ++j) {
267 out[i][j] = in[j][i];
268 }
269 }
270
271 _hidl_cb(out);
272
273 return Void();
274}
275
276Return<void> Foo::sendVec(
277 const hidl_vec<uint8_t> &data, sendVec_cb _hidl_cb) {
278 _hidl_cb(data);
279
280 return Void();
281}
282
283Return<void> Foo::sendVecVec(sendVecVec_cb _hidl_cb) {
284 hidl_vec<hidl_vec<uint8_t>> data;
285 _hidl_cb(data);
286
287 return Void();
288}
289
290
291IFoo* HIDL_FETCH_IFoo(const char* /* name */) {
292 return new Foo();
293}
294
295} // namespace implementation
296} // namespace V1_0
297} // namespace foo
298} // namespace tests
299} // namespace hardware
300} // namespace android