diff --git a/tests/bar/1.0/default/Bar.cpp b/tests/bar/1.0/default/Bar.cpp index 6a8a3603dd..46144281d7 100644 --- a/tests/bar/1.0/default/Bar.cpp +++ b/tests/bar/1.0/default/Bar.cpp @@ -19,6 +19,11 @@ Bar::Bar() { } // Methods from ::android::hardware::tests::foo::V1_0::IFoo follow. +Return Bar::convertToBoolIfSmall(Discriminator d, const hidl_vec& u, + convertToBoolIfSmall_cb _hidl_cb) { + return mFoo->convertToBoolIfSmall(d, u, _hidl_cb); +} + Return Bar::doThis(float param) { return mFoo->doThis(param); } diff --git a/tests/bar/1.0/default/Bar.h b/tests/bar/1.0/default/Bar.h index b276823b33..acb976f85f 100644 --- a/tests/bar/1.0/default/Bar.h +++ b/tests/bar/1.0/default/Bar.h @@ -31,6 +31,8 @@ struct Bar : public IBar { Bar(); // Methods from ::android::hardware::tests::foo::V1_0::IFoo follow. + virtual Return convertToBoolIfSmall(Discriminator d, const hidl_vec& u, + convertToBoolIfSmall_cb _hidl_cb) override; virtual Return doThis(float param) override; virtual Return doThatAndReturnSomething(int64_t param) override; virtual Return doQuiteABit(int32_t a, int64_t b, float c, double d) override; diff --git a/tests/foo/1.0/IFoo.hal b/tests/foo/1.0/IFoo.hal index c1ce7b093e..4a930a28d1 100644 --- a/tests/foo/1.0/IFoo.hal +++ b/tests/foo/1.0/IFoo.hal @@ -122,6 +122,19 @@ interface IFoo { bitfield bf; }; + enum Discriminator : uint8_t { + BOOL, + INT, + }; + union Union { + bool boolValue; + int64_t intValue; + }; + struct ContainsUnion { + Discriminator discriminator; + Union value; + }; + typedef int32_t[5][6][7] multidimArrayOne; typedef multidimArrayOne[8][9][10] multidimArrayTwo; typedef multidimArrayTwo[2][3][4] multidimArrayThree; @@ -144,6 +157,16 @@ interface IFoo { InnerTestEnumTypedef foo; }; + /** + * If d is INT, converts all values to bools which are small enough (0 or 1). + * If d is BOOL, should leave all values as BOOLs. + * + * @param d discriminator for all values in u + * @param u values to be expanded + * @return c must have same length as u unless there is an error in which case it will be empty. + */ + convertToBoolIfSmall(Discriminator d, vec u) generates (vec c); + 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); diff --git a/tests/foo/1.0/default/Foo.cpp b/tests/foo/1.0/default/Foo.cpp index a860ce77f2..a31ab9f011 100644 --- a/tests/foo/1.0/default/Foo.cpp +++ b/tests/foo/1.0/default/Foo.cpp @@ -15,6 +15,30 @@ namespace V1_0 { namespace implementation { // Methods from ::android::hardware::tests::foo::V1_0::IFoo follow. +Return Foo::convertToBoolIfSmall(Discriminator d, const hidl_vec& u, + convertToBoolIfSmall_cb _hidl_cb) { + hidl_vec res(u.size()); + for (size_t i = 0; i < u.size(); i++) { + ContainsUnion& outValue = res[i]; + + if (d == Discriminator::BOOL) { + outValue.discriminator = Discriminator::BOOL; + outValue.value.boolValue = u[i].boolValue; + } else { + uint64_t value = u[i].intValue; + if (value == 0 || value == 1) { + outValue.discriminator = Discriminator::BOOL; + outValue.value.boolValue = static_cast(value); + } else { + outValue.discriminator = Discriminator::INT; + outValue.value.intValue = value; + } + } + } + _hidl_cb(res); + return Void(); +} + Return Foo::doThis(float param) { LOG(INFO) << "SERVER(Foo) doThis(" << param << ")"; diff --git a/tests/foo/1.0/default/Foo.h b/tests/foo/1.0/default/Foo.h index 4558a734a5..7dd672b830 100644 --- a/tests/foo/1.0/default/Foo.h +++ b/tests/foo/1.0/default/Foo.h @@ -22,9 +22,14 @@ using ::android::hardware::Void; using ::android::hardware::hidl_vec; using ::android::hardware::hidl_string; using ::android::sp; +using ContainsUnion = ::android::hardware::tests::foo::V1_0::IFoo::ContainsUnion; +using Discriminator = ::android::hardware::tests::foo::V1_0::IFoo::Discriminator; +using Union = ::android::hardware::tests::foo::V1_0::IFoo::Union; struct Foo : public IFoo { // Methods from ::android::hardware::tests::foo::V1_0::IFoo follow. + virtual Return convertToBoolIfSmall(Discriminator d, const hidl_vec& u, + convertToBoolIfSmall_cb _hidl_cb) override; virtual Return doThis(float param) override; virtual Return doThatAndReturnSomething(int64_t param) override; virtual Return doQuiteABit(int32_t a, int64_t b, float c, double d) override;