blob: 7094f07d154eaab230e184acdd42ba0d3c64513e [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
Martijn Coenene8b01612017-01-02 15:19:53 +010020sp<IChild> selectService(bool sendRemote, sp<IChild> &local) {
Yifan Hongcc6ad7d2016-10-18 18:44:17 -070021 sp<IChild> toSend;
22 if (sendRemote) {
23 toSend = IChild::getService("child");
24 if (!toSend->isRemote()) {
Yifan Hong1f4fbc02016-11-02 16:50:01 -070025 toSend = nullptr;
Yifan Hongcc6ad7d2016-10-18 18:44:17 -070026 }
27 } else {
28 toSend = local;
29 }
Yifan Hong0c4c7a32016-11-28 15:59:24 -080030 LOG(INFO) << "SERVER(Fetcher) selectService returning " << toSend.get();
Martijn Coenene8b01612017-01-02 15:19:53 +010031 return toSend;
Yifan Hongcc6ad7d2016-10-18 18:44:17 -070032}
33
34// Methods from ::android::hardware::tests::inheritance::V1_0::IFetcher follow.
Martijn Coenene8b01612017-01-02 15:19:53 +010035Return<sp<IGrandparent>> Fetcher::getGrandparent(bool sendRemote) {
36 return selectService(sendRemote, mPrecious);
Yifan Hongcc6ad7d2016-10-18 18:44:17 -070037}
38
Martijn Coenene8b01612017-01-02 15:19:53 +010039Return<sp<IParent>> Fetcher::getParent(bool sendRemote) {
40 return selectService(sendRemote, mPrecious);
Yifan Hongcc6ad7d2016-10-18 18:44:17 -070041}
42
Martijn Coenene8b01612017-01-02 15:19:53 +010043Return<sp<IChild>> Fetcher::getChild(bool sendRemote) {
44 return selectService(sendRemote, mPrecious);
Yifan Hongcc6ad7d2016-10-18 18:44:17 -070045}
46
47IFetcher* HIDL_FETCH_IFetcher(const char* /* name */) {
48 return new Fetcher();
49}
50
51} // namespace implementation
52} // namespace V1_0
53} // namespace inheritance
54} // namespace tests
55} // namespace hardware
56} // namespace android