| Index: native_client_sdk/src/libraries/nacl_io/fifo_packet.h
|
| diff --git a/native_client_sdk/src/libraries/nacl_io/fifo_packet.h b/native_client_sdk/src/libraries/nacl_io/fifo_packet.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..8c9bd313e25c186d8c1478dbe33d87bb8ddca8c8
|
| --- /dev/null
|
| +++ b/native_client_sdk/src/libraries/nacl_io/fifo_packet.h
|
| @@ -0,0 +1,71 @@
|
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef LIBRARIES_NACL_IO_FIFO_PACKET_H_
|
| +#define LIBRARIES_NACL_IO_FIFO_PACKET_H_
|
| +
|
| +#include <string.h>
|
| +
|
| +#include <list>
|
| +#include <vector>
|
| +
|
| +#include "nacl_io/fifo_interface.h"
|
| +#include "ppapi/c/pp_resource.h"
|
| +
|
| +#include "sdk_util/macros.h"
|
| +
|
| +namespace nacl_io {
|
| +
|
| +struct Packet {
|
| + Packet(const void *buffer, size_t len, PP_Resource addr)
|
| + : addr_(addr),
|
| + buffer_(len) {
|
| + memcpy(buffer_.data(), buffer, len);
|
| + }
|
| +
|
| + PP_Resource addr_;
|
| + std::vector<char> buffer_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(Packet);
|
| +};
|
| +
|
| +
|
| +// FIFOPacket
|
| +//
|
| +// A FIFOPackiet is linked list of packets. Data is stored and returned
|
| +// in packet size increments. FIFOPacket signals EMPTY where there are
|
| +// no packets, and FULL when the total bytes of all packets meets or
|
| +// exceeds the max size hint.
|
| +class FIFOPacket : public FIFOInterface {
|
| + public:
|
| + explicit FIFOPacket(size_t size);
|
| + virtual ~FIFOPacket();
|
| +
|
| + virtual bool IsEmpty();
|
| + virtual bool IsFull();
|
| + virtual bool Resize(size_t len);
|
| +
|
| + size_t ReadAvailable();
|
| + size_t WriteAvailable();
|
| +
|
| + // Return a pointer to the top packet without releasing ownership.
|
| + Packet* PeekPacket();
|
| +
|
| + // Relinquish top packet, and remove it from the FIFO.
|
| + Packet* ReadPacket();
|
| +
|
| + // Take ownership of packet and place it in the FIFO.
|
| + void WritePacket(Packet* packet);
|
| +
|
| + private:
|
| + std::list<Packet*> packets_;
|
| + uint32_t max_bytes_;
|
| + uint32_t cur_bytes_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(FIFOPacket);
|
| +};
|
| +
|
| +} // namespace nacl_io
|
| +
|
| +#endif // LIBRARIES_NACL_IO_FIFO_PACKET_H_
|
|
|