Add interface methods for testing vec<handle>.

Test: hidl_test
Bug: 32160974
Change-Id: I7eda1650fcf8d58778b2aad97a5bd62afc95bc36
This commit is contained in:
Yifan Hong 2016-10-14 10:41:41 -07:00 committed by Martijn Coenen
parent 058ee272fd
commit ebfa633103
7 changed files with 64 additions and 0 deletions

View file

@ -10,6 +10,7 @@ cc_library_shared {
shared_libs: [
"libbase",
"libcutils",
"libhidl",
"libhwbinder",
"liblog",

View file

@ -130,6 +130,18 @@ Return<void> Bar::haveAVectorOfGenericInterfaces(
return Void();
}
Return<void> Bar::createMyHandle(createMyHandle_cb _hidl_cb) {
return mFoo->createMyHandle(_hidl_cb);
}
Return<void> Bar::createHandles(uint32_t size, createHandles_cb _hidl_cb) {
return mFoo->createHandles(size, _hidl_cb);
}
Return<void> Bar::closeHandles() {
return mFoo->closeHandles();
}
// Methods from ::android::hardware::tests::bar::V1_0::IBar follow.
Return<void> Bar::thisIsNew() {
ALOGI("SERVER(Bar) thisIsNew");

View file

@ -48,6 +48,9 @@ struct Bar : public IBar {
virtual Return<void> transpose2(const hidl_array<hidl_string, 5 /* 5 */, 3 /* 3 */>& in, transpose2_cb _hidl_cb) override;
virtual Return<void> sendVec(const hidl_vec<uint8_t>& data, sendVec_cb _hidl_cb) override;
virtual Return<void> sendVecVec(sendVecVec_cb _hidl_cb) override;
virtual Return<void> createMyHandle(createMyHandle_cb _hidl_cb) override;
virtual Return<void> createHandles(uint32_t size, createHandles_cb _hidl_cb) override;
virtual Return<void> closeHandles() override;
Return<void> haveAVectorOfInterfaces(
const hidl_vec<sp<ISimple> > &in,

View file

@ -80,6 +80,11 @@ interface IFoo {
FloatArray myFloatArray;
};
struct MyHandle {
handle h;
int32_t guard;
};
doThis(float param);
doThatAndReturnSomething(int64_t param) generates (int32_t result);
doQuiteABit(int32_t a, int64_t b, float c, double d) generates (double something);
@ -112,4 +117,7 @@ interface IFoo {
haveAVectorOfGenericInterfaces(vec<interface> in)
generates (vec<interface> out);
createMyHandle() generates (MyHandle h);
createHandles(uint32_t size) generates (vec<handle> handles);
closeHandles();
};

View file

@ -10,6 +10,7 @@ cc_library_shared {
shared_libs: [
"libbase",
"libcutils",
"libhidl",
"libfootest",
"libhwbinder",

View file

@ -291,7 +291,40 @@ Return<void> Foo::haveAVectorOfGenericInterfaces(
const hidl_vec<sp<android::hardware::IBinder> > &in,
haveAVectorOfGenericInterfaces_cb _hidl_cb) {
_hidl_cb(in);
return Void();
}
Return<void> Foo::createMyHandle(createMyHandle_cb _hidl_cb) {
native_handle_t* nh = native_handle_create(0, 10);
int data[] = {2,3,5,7,11,13,17,19,21,23};
CHECK(sizeof(data) == 10 * sizeof(int));
memcpy(nh->data, data, sizeof(data));
mHandles.push_back(nh);
MyHandle h;
h.guard = 666;
h.h = nh;
_hidl_cb(h);
return Void();
}
Return<void> Foo::createHandles(uint32_t size, createHandles_cb _hidl_cb) {
hidl_vec<const native_handle_t*> handles;
handles.resize(size);
for(uint32_t i = 0; i < size; ++i) {
createMyHandle([&](const MyHandle& h) {
handles[i] = h.h;
});
}
_hidl_cb(handles);
return Void();
}
Return<void> Foo::closeHandles() {
for(native_handle_t* h : mHandles) {
native_handle_delete(h);
}
mHandles.clear();
return Void();
}

View file

@ -5,6 +5,7 @@
#include <hidl/Status.h>
#include <hidl/MQDescriptor.h>
#include <vector>
namespace android {
namespace hardware {
namespace tests {
@ -44,6 +45,9 @@ struct Foo : public IFoo {
virtual Return<void> transpose2(const hidl_array<hidl_string, 5 /* 5 */, 3 /* 3 */>& in, transpose2_cb _hidl_cb) override;
virtual Return<void> sendVec(const hidl_vec<uint8_t>& data, sendVec_cb _hidl_cb) override;
virtual Return<void> sendVecVec(sendVecVec_cb _hidl_cb) override;
virtual Return<void> createMyHandle(createMyHandle_cb _hidl_cb) override;
virtual Return<void> createHandles(uint32_t size, createHandles_cb _hidl_cb) override;
virtual Return<void> closeHandles() override;
Return<void> haveAVectorOfInterfaces(
const hidl_vec<sp<ISimple> > &in,
@ -52,6 +56,8 @@ struct Foo : public IFoo {
Return<void> haveAVectorOfGenericInterfaces(
const hidl_vec<sp<android::hardware::IBinder> > &in,
haveAVectorOfGenericInterfaces_cb _hidl_cb) override;
private:
std::vector<::native_handle_t *> mHandles;
};
extern "C" IFoo* HIDL_FETCH_IFoo(const char* name);