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