blob: 760d931391702f7816b663482983fba97b7a12b6 [file] [log] [blame]
Hridya Valsaraju8a708622017-03-06 14:10:42 -08001#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
10namespace android {
11namespace hardware {
12namespace tests {
13namespace msgq {
14namespace V1_0 {
15namespace implementation {
16
17using ::android::hardware::tests::msgq::V1_0::ITestMsgQ;
18using ::android::hidl::base::V1_0::DebugInfo;
19using ::android::hidl::base::V1_0::IBase;
20using ::android::hardware::hidl_array;
21using ::android::hardware::hidl_memory;
22using ::android::hardware::hidl_string;
23using ::android::hardware::hidl_vec;
24using ::android::hardware::Return;
25using ::android::hardware::Void;
26using ::android::sp;
27
28using android::hardware::kSynchronizedReadWrite;
29using android::hardware::kUnsynchronizedWrite;
30using android::hardware::MQDescriptorSync;
31using android::hardware::MQDescriptorUnsync;
32
33using android::hardware::MessageQueue;
34
35struct 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.
53private:
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
68extern "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