blob: 74f8d074e9c836bcd832632175398a6dcf4296b0 [file] [log] [blame]
Yifan Hongcc6ad7d2016-10-18 18:44:17 -07001
2#define LOG_TAG "hidl_test"
3
4#include "Fetcher.h"
5#include <android-base/logging.h>
6#include <inttypes.h>
7
8namespace android {
9namespace hardware {
10namespace tests {
11namespace inheritance {
12namespace V1_0 {
13namespace implementation {
14
15Fetcher::Fetcher() {
16 mPrecious = IChild::getService("local child", true);
17 CHECK(!mPrecious->isRemote());
18}
19
20template <typename CB>
21Return<void> selectService(bool sendRemote, CB &_hidl_cb, sp<IChild> &local) {
22 sp<IChild> toSend;
23 if (sendRemote) {
24 toSend = IChild::getService("child");
25 if (!toSend->isRemote()) {
Yifan Hong1f4fbc02016-11-02 16:50:01 -070026 toSend = nullptr;
Yifan Hongcc6ad7d2016-10-18 18:44:17 -070027 }
28 } else {
29 toSend = local;
30 }
31 ALOGI("SERVER(Fetcher) selectService returning %p", toSend.get());
32 _hidl_cb(toSend);
33 return Void();
34}
35
36// Methods from ::android::hardware::tests::inheritance::V1_0::IFetcher follow.
37Return<void> Fetcher::getGrandparent(bool sendRemote, getGrandparent_cb _hidl_cb) {
38 return selectService(sendRemote, _hidl_cb, mPrecious);
39}
40
41Return<void> Fetcher::getParent(bool sendRemote, getParent_cb _hidl_cb) {
42 return selectService(sendRemote, _hidl_cb, mPrecious);
43}
44
45Return<void> Fetcher::getChild(bool sendRemote, getChild_cb _hidl_cb) {
46 return selectService(sendRemote, _hidl_cb, mPrecious);
47}
48
49IFetcher* HIDL_FETCH_IFetcher(const char* /* name */) {
50 return new Fetcher();
51}
52
53} // namespace implementation
54} // namespace V1_0
55} // namespace inheritance
56} // namespace tests
57} // namespace hardware
58} // namespace android