| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MOJO_SERVICES_FLOG_FLOG_READER_IMPL_H_ |
| 6 #define MOJO_SERVICES_FLOG_FLOG_READER_IMPL_H_ |
| 7 |
| 8 #include <limits> |
| 9 |
| 10 #include "mojo/public/cpp/bindings/binding.h" |
| 11 #include "mojo/services/flog/interfaces/flog.mojom.h" |
| 12 #include "services/flog/flog_service_impl.h" |
| 13 |
| 14 namespace mojo { |
| 15 namespace flog { |
| 16 |
| 17 // FlogReader implementation. |
| 18 class FlogReaderImpl : public FlogServiceImpl::Product<FlogReader>, |
| 19 public FlogReader, |
| 20 private FlogLogger { |
| 21 public: |
| 22 static std::shared_ptr<FlogReaderImpl> Create( |
| 23 InterfaceRequest<FlogReader> request, |
| 24 uint32_t log_id, |
| 25 const std::string& label, |
| 26 std::shared_ptr<FlogDirectory> directory, |
| 27 FlogServiceImpl* owner); |
| 28 |
| 29 ~FlogReaderImpl() override; |
| 30 |
| 31 // FlogReader implementation. |
| 32 void GetEntries(uint32_t start_index, |
| 33 uint32_t max_count, |
| 34 const GetEntriesCallback& callback) override; |
| 35 |
| 36 private: |
| 37 static const size_t kReadBufferSize = 16 * 1024; |
| 38 |
| 39 FlogReaderImpl(InterfaceRequest<FlogReader> request, |
| 40 uint32_t log_id, |
| 41 const std::string& label, |
| 42 std::shared_ptr<FlogDirectory> directory, |
| 43 FlogServiceImpl* owner); |
| 44 |
| 45 bool DiscardEntry(); |
| 46 |
| 47 FlogEntryPtr GetEntry(); |
| 48 |
| 49 // Reads data and returns the number of bytes read. |data_size| must be |
| 50 // non-zero. |data| may be nullptr, in which case the data is discarded. |
| 51 size_t ReadData(size_t data_size, void* data); |
| 52 |
| 53 void FillReadBuffer(bool restart); |
| 54 |
| 55 size_t read_buffer_bytes_remaining() { |
| 56 return read_buffer_.size() - read_buffer_bytes_used_; |
| 57 } |
| 58 |
| 59 // Creates an entry with an uninitialized details field. |
| 60 FlogEntryPtr CreateEntry(int64_t time_us, uint32_t channel_id); |
| 61 |
| 62 // FlogLogger implementation (called by stub_). |
| 63 void LogChannelCreation(int64_t time_us, |
| 64 uint32_t channel_id, |
| 65 const mojo::String& type_name) override; |
| 66 |
| 67 void LogChannelMessage(int64_t time_us, |
| 68 uint32_t channel_id, |
| 69 mojo::Array<uint8_t> data) override; |
| 70 |
| 71 void LogChannelDeletion(int64_t time_us, uint32_t channel_id) override; |
| 72 |
| 73 uint32_t log_id_; |
| 74 files::FilePtr file_; |
| 75 uint32_t current_entry_index_ = 0; |
| 76 std::vector<uint8_t> read_buffer_; |
| 77 size_t read_buffer_bytes_used_; |
| 78 bool fault_ = false; |
| 79 FlogLoggerStub stub_; |
| 80 FlogEntryPtr entry_; |
| 81 }; |
| 82 |
| 83 } // namespace flog |
| 84 } // namespace mojo |
| 85 |
| 86 #endif // MOJO_SERVICES_FLOG_FLOG_READER_IMPL_H_ |
| OLD | NEW |