blob: 86e4ac4029cd4655351397228e81f8fae1047399 [file] [log] [blame]
Hridya Valsaraju171603e2017-03-07 20:25:08 -08001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Hridya Valsaraju8a708622017-03-06 14:10:42 -080017#ifndef ANDROID_HARDWARE_TESTS_MSGQ_V1_0_TESTMSGQ_H
18#define ANDROID_HARDWARE_TESTS_MSGQ_V1_0_TESTMSGQ_H
19
20#include <android/hardware/tests/msgq/1.0/ITestMsgQ.h>
21#include <hidl/MQDescriptor.h>
22#include <hidl/Status.h>
23#include <fmq/MessageQueue.h>
24#include <fmq/EventFlag.h>
25
26namespace android {
27namespace hardware {
28namespace tests {
29namespace msgq {
30namespace V1_0 {
31namespace implementation {
32
33using ::android::hardware::tests::msgq::V1_0::ITestMsgQ;
34using ::android::hidl::base::V1_0::DebugInfo;
35using ::android::hidl::base::V1_0::IBase;
36using ::android::hardware::hidl_array;
37using ::android::hardware::hidl_memory;
38using ::android::hardware::hidl_string;
39using ::android::hardware::hidl_vec;
40using ::android::hardware::Return;
41using ::android::hardware::Void;
42using ::android::sp;
43
44using android::hardware::kSynchronizedReadWrite;
45using android::hardware::kUnsynchronizedWrite;
46using android::hardware::MQDescriptorSync;
47using android::hardware::MQDescriptorUnsync;
48
49using android::hardware::MessageQueue;
50
51struct TestMsgQ : public ITestMsgQ {
52 typedef MessageQueue<uint16_t, kSynchronizedReadWrite> MessageQueueSync;
53 typedef MessageQueue<uint16_t, kUnsynchronizedWrite> MessageQueueUnsync;
54
55 TestMsgQ() : mFmqSynchronized(nullptr), mFmqUnsynchronized(nullptr) {}
56
57 // Methods from ::android::hardware::tests::msgq::V1_0::ITestMsgQ follow.
58 Return<void> configureFmqSyncReadWrite(configureFmqSyncReadWrite_cb _hidl_cb) override;
59 Return<void> getFmqUnsyncWrite(bool configureFmq, getFmqUnsyncWrite_cb _hidl_cb) override;
60 Return<bool> requestWriteFmqSync(int32_t count) override;
61 Return<bool> requestReadFmqSync(int32_t count) override;
62 Return<bool> requestWriteFmqUnsync(int32_t count) override;
63 Return<bool> requestReadFmqUnsync(int32_t count) override;
64 Return<void> requestBlockingRead(int32_t count) override;
65 Return<void> requestBlockingReadDefaultEventFlagBits(int32_t count) override;
66 Return<void> requestBlockingReadRepeat(int32_t count, int32_t numIter) override;
67
68 // Methods from ::android::hidl::base::V1_0::IBase follow.
69private:
70 std::unique_ptr<MessageQueueSync> mFmqSynchronized;
71 std::unique_ptr<MessageQueueUnsync> mFmqUnsynchronized;
72
73 /*
74 * Utility function to verify data read from the fast message queue.
75 */
76 bool verifyData(uint16_t* data, int count) {
77 for (int i = 0; i < count; i++) {
78 if (data[i] != i) return false;
79 }
80 return true;
81 }
82};
83
84extern "C" ITestMsgQ* HIDL_FETCH_ITestMsgQ(const char* name);
85
86} // namespace implementation
87} // namespace V1_0
88} // namespace msgq
89} // namespace tests
90} // namespace hardware
91} // namespace android
92
93#endif // ANDROID_HARDWARE_TESTS_MSGQ_V1_0_TESTMSGQ_H