| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2014 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 PPAPI_SHARED_IMPL_CIRCULAR_BUFFER_H_ |
| 6 #define PPAPI_SHARED_IMPL_CIRCULAR_BUFFER_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "ppapi/shared_impl/ppapi_shared_export.h" |
| 10 |
| 11 namespace ppapi { |
| 12 |
| 13 class PPAPI_SHARED_EXPORT CircularBuffer { |
| 14 public: |
| 15 // Construct a CircularBuffer by given underlying buffer and size. |
| 16 CircularBuffer(void* buffer, uint32_t size); |
| 17 |
| 18 ~CircularBuffer(); |
| 19 |
| 20 // Remaining buffer size for reading or writing. |
| 21 uint32_t remaining() const { |
| 22 return remaining_; |
| 23 } |
| 24 |
| 25 // Moves position forward by given offset. |
| 26 void MovePosition(uint32_t offset); |
| 27 |
| 28 // Moves limit forward by given offset. |
| 29 void MoveLimit(uint32_t offset); |
| 30 |
| 31 // Reads data and move position forward. The actual read size will be |
| 32 // returned. |
| 33 int32_t Read(void* buffer, uint32_t size); |
| 34 |
| 35 // Similar to |Read()|, but it will fail, if the circular buffer does not have |
| 36 // enough data. |
| 37 int32_t ReadAll(void* buffer, uint32_t size); |
| 38 |
| 39 // Writes data and move position forward. The actual write size will be |
| 40 // returned. |
| 41 int32_t Write(const void* buffer, uint32_t size); |
| 42 |
| 43 // Similar to |Write()|, but it will fail, if the circular buffer does not |
| 44 // have enough space for the given size of data. |
| 45 int32_t WriteAll(const void* buffer, uint32_t size); |
| 46 |
| 47 // Locks the given size of underlying buffer for direct accessing. |
| 48 int32_t Lock(void** buffer, uint32_t size); |
| 49 |
| 50 // Relocks underlying buffer. It is used for adjusting locked block size; |
| 51 int32_t Relock(void* buffer, uint32_t size); |
| 52 |
| 53 // Unlocks buffer which is locked by previous |Lock()| call. The locked block |
| 54 // size will be returned. |
| 55 int32_t Unlock(const void* buffer); |
| 56 |
| 57 // Returns true if the circular buffer is locked. |
| 58 bool IsLocked() const { return locked_buffer_; } |
| 59 |
| 60 private: |
| 61 int32_t ReadInternal(void* buffer, uint32_t size); |
| 62 |
| 63 int32_t WriteInternal(const void* buffer, uint32_t size); |
| 64 |
| 65 // Underlying buffer pointer. |
| 66 uint8_t* buffer_; |
| 67 |
| 68 // Underlying buffer size. |
| 69 uint32_t buffer_size_; |
| 70 |
| 71 // Current position for reading or writing. |
| 72 uint32_t position_; |
| 73 |
| 74 // The limit position for reading or writing. |
| 75 uint32_t limit_; |
| 76 |
| 77 // Remaining buffer size for reading or writing. |
| 78 uint32_t remaining_; |
| 79 |
| 80 // Locked buffer pointer returned by |Lock()|. It will be reset to NULL, |
| 81 // When |Unlock()| is called. |
| 82 uint8_t* locked_buffer_; |
| 83 |
| 84 // Locked buffer size. |
| 85 uint32_t locked_buffer_size_; |
| 86 |
| 87 DISALLOW_COPY_AND_ASSIGN(CircularBuffer); |
| 88 }; |
| 89 |
| 90 } // namespace ppapi |
| 91 |
| 92 #endif // PPAPI_SHARED_IMPL_CIRCULAR_BUFFER_H_ |
| OLD | NEW |