Hridya Valsaraju | 8a70862 | 2017-03-06 14:10:42 -0800 | [diff] [blame^] | 1 | #ifndef ANDROID_HARDWARE_TESTS_MSGQ_V1_0_TESTMSGQ_H |
| 2 | #define ANDROID_HARDWARE_TESTS_MSGQ_V1_0_TESTMSGQ_H |
| 3 | |
| 4 | #include <android/hardware/tests/msgq/1.0/ITestMsgQ.h> |
| 5 | #include <hidl/MQDescriptor.h> |
| 6 | #include <hidl/Status.h> |
| 7 | #include <fmq/MessageQueue.h> |
| 8 | #include <fmq/EventFlag.h> |
| 9 | |
| 10 | namespace android { |
| 11 | namespace hardware { |
| 12 | namespace tests { |
| 13 | namespace msgq { |
| 14 | namespace V1_0 { |
| 15 | namespace implementation { |
| 16 | |
| 17 | using ::android::hardware::tests::msgq::V1_0::ITestMsgQ; |
| 18 | using ::android::hidl::base::V1_0::DebugInfo; |
| 19 | using ::android::hidl::base::V1_0::IBase; |
| 20 | using ::android::hardware::hidl_array; |
| 21 | using ::android::hardware::hidl_memory; |
| 22 | using ::android::hardware::hidl_string; |
| 23 | using ::android::hardware::hidl_vec; |
| 24 | using ::android::hardware::Return; |
| 25 | using ::android::hardware::Void; |
| 26 | using ::android::sp; |
| 27 | |
| 28 | using android::hardware::kSynchronizedReadWrite; |
| 29 | using android::hardware::kUnsynchronizedWrite; |
| 30 | using android::hardware::MQDescriptorSync; |
| 31 | using android::hardware::MQDescriptorUnsync; |
| 32 | |
| 33 | using android::hardware::MessageQueue; |
| 34 | |
| 35 | struct TestMsgQ : public ITestMsgQ { |
| 36 | typedef MessageQueue<uint16_t, kSynchronizedReadWrite> MessageQueueSync; |
| 37 | typedef MessageQueue<uint16_t, kUnsynchronizedWrite> MessageQueueUnsync; |
| 38 | |
| 39 | TestMsgQ() : mFmqSynchronized(nullptr), mFmqUnsynchronized(nullptr) {} |
| 40 | |
| 41 | // Methods from ::android::hardware::tests::msgq::V1_0::ITestMsgQ follow. |
| 42 | Return<void> configureFmqSyncReadWrite(configureFmqSyncReadWrite_cb _hidl_cb) override; |
| 43 | Return<void> getFmqUnsyncWrite(bool configureFmq, getFmqUnsyncWrite_cb _hidl_cb) override; |
| 44 | Return<bool> requestWriteFmqSync(int32_t count) override; |
| 45 | Return<bool> requestReadFmqSync(int32_t count) override; |
| 46 | Return<bool> requestWriteFmqUnsync(int32_t count) override; |
| 47 | Return<bool> requestReadFmqUnsync(int32_t count) override; |
| 48 | Return<void> requestBlockingRead(int32_t count) override; |
| 49 | Return<void> requestBlockingReadDefaultEventFlagBits(int32_t count) override; |
| 50 | Return<void> requestBlockingReadRepeat(int32_t count, int32_t numIter) override; |
| 51 | |
| 52 | // Methods from ::android::hidl::base::V1_0::IBase follow. |
| 53 | private: |
| 54 | std::unique_ptr<MessageQueueSync> mFmqSynchronized; |
| 55 | std::unique_ptr<MessageQueueUnsync> mFmqUnsynchronized; |
| 56 | |
| 57 | /* |
| 58 | * Utility function to verify data read from the fast message queue. |
| 59 | */ |
| 60 | bool verifyData(uint16_t* data, int count) { |
| 61 | for (int i = 0; i < count; i++) { |
| 62 | if (data[i] != i) return false; |
| 63 | } |
| 64 | return true; |
| 65 | } |
| 66 | }; |
| 67 | |
| 68 | extern "C" ITestMsgQ* HIDL_FETCH_ITestMsgQ(const char* name); |
| 69 | |
| 70 | } // namespace implementation |
| 71 | } // namespace V1_0 |
| 72 | } // namespace msgq |
| 73 | } // namespace tests |
| 74 | } // namespace hardware |
| 75 | } // namespace android |
| 76 | |
| 77 | #endif // ANDROID_HARDWARE_TESTS_MSGQ_V1_0_TESTMSGQ_H |