libmems: Add IioDevice::ReadEvents
This commit adds ReadEvents function in IioDevice to read events in
raw.
BUG=chromium:971175
TEST=build with debug code in mems_setup/main.cc and camera/hal_adapter
observe events are retrieved
Change-Id: I79cb477d91e0a4b1fa19d9803b51f036abcedc3b
Reviewed-on: https://chromium-review.googlesource.com/1644833
Tested-by: Cheng-Hao Yang <chenghaoyang@chromium.org>
Commit-Ready: Cheng-Hao Yang <chenghaoyang@chromium.org>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Heng-ruey Hsu <henryhsu@google.com>
diff --git a/libmems/iio_device_impl.h b/libmems/iio_device_impl.h
index 9ad5e06..0126f3a 100644
--- a/libmems/iio_device_impl.h
+++ b/libmems/iio_device_impl.h
@@ -10,6 +10,7 @@
#include <map>
#include <memory>
#include <string>
+#include <vector>
#include <base/optional.h>
@@ -51,13 +52,27 @@
IioChannel* GetChannel(const std::string& name) override;
+ base::Optional<size_t> GetSampleSize() const override;
+
bool EnableBuffer(size_t num) override;
bool DisableBuffer() override;
bool IsBufferEnabled(size_t* num = nullptr) const override;
+ bool ReadEvents(uint32_t num_samples, std::vector<uint8_t>* events) override;
+
private:
+ static void IioBufferDeleter(iio_buffer* buffer);
+
+ bool CreateBuffer(uint32_t num_samples);
+
IioContextImpl* context_; // non-owned
iio_device* const device_; // non-owned
+
+ using ScopedBuffer = std::unique_ptr<iio_buffer, decltype(&IioBufferDeleter)>;
+ ScopedBuffer buffer_;
+
+ uint32_t buffer_size_;
+
std::map<std::string, std::unique_ptr<IioChannelImpl>> channels_;
DISALLOW_COPY_AND_ASSIGN(IioDeviceImpl);
};