Yifan Hong | cc6ad7d | 2016-10-18 18:44:17 -0700 | [diff] [blame] | 1 | |
| 2 | #define LOG_TAG "hidl_test" |
| 3 | |
| 4 | #include "Fetcher.h" |
| 5 | #include <android-base/logging.h> |
| 6 | #include <inttypes.h> |
| 7 | |
| 8 | namespace android { |
| 9 | namespace hardware { |
| 10 | namespace tests { |
| 11 | namespace inheritance { |
| 12 | namespace V1_0 { |
| 13 | namespace implementation { |
| 14 | |
| 15 | Fetcher::Fetcher() { |
| 16 | mPrecious = IChild::getService("local child", true); |
| 17 | CHECK(!mPrecious->isRemote()); |
| 18 | } |
| 19 | |
| 20 | template <typename CB> |
| 21 | Return<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 Hong | 1f4fbc0 | 2016-11-02 16:50:01 -0700 | [diff] [blame^] | 26 | toSend = nullptr; |
Yifan Hong | cc6ad7d | 2016-10-18 18:44:17 -0700 | [diff] [blame] | 27 | } |
| 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. |
| 37 | Return<void> Fetcher::getGrandparent(bool sendRemote, getGrandparent_cb _hidl_cb) { |
| 38 | return selectService(sendRemote, _hidl_cb, mPrecious); |
| 39 | } |
| 40 | |
| 41 | Return<void> Fetcher::getParent(bool sendRemote, getParent_cb _hidl_cb) { |
| 42 | return selectService(sendRemote, _hidl_cb, mPrecious); |
| 43 | } |
| 44 | |
| 45 | Return<void> Fetcher::getChild(bool sendRemote, getChild_cb _hidl_cb) { |
| 46 | return selectService(sendRemote, _hidl_cb, mPrecious); |
| 47 | } |
| 48 | |
| 49 | IFetcher* 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 |