| 1 | // Copyright (c) 2012, the Dart project authors.  Please see the AUTHORS file | 
|---|
| 2 | // for details. All rights reserved. Use of this source code is governed by a | 
|---|
| 3 | // BSD-style license that can be found in the LICENSE file. | 
|---|
| 4 |  | 
|---|
| 5 | #ifndef RUNTIME_BIN_IO_BUFFER_H_ | 
|---|
| 6 | #define RUNTIME_BIN_IO_BUFFER_H_ | 
|---|
| 7 |  | 
|---|
| 8 | #include "include/dart_api.h" | 
|---|
| 9 | #include "platform/globals.h" | 
|---|
| 10 |  | 
|---|
| 11 | namespace dart { | 
|---|
| 12 | namespace bin { | 
|---|
| 13 |  | 
|---|
| 14 | class IOBuffer { | 
|---|
| 15 | public: | 
|---|
| 16 | // Allocate an IO buffer dart object (of type Uint8List) backed by | 
|---|
| 17 | // an external byte array. | 
|---|
| 18 | static Dart_Handle Allocate(intptr_t size, uint8_t** buffer); | 
|---|
| 19 |  | 
|---|
| 20 | // Allocate IO buffer storage. | 
|---|
| 21 | static uint8_t* Allocate(intptr_t size); | 
|---|
| 22 |  | 
|---|
| 23 | // Function for disposing of IO buffer storage. All backing storage | 
|---|
| 24 | // for IO buffers must be freed using this function. | 
|---|
| 25 | static void Free(void* buffer) { free(buffer); } | 
|---|
| 26 |  | 
|---|
| 27 | // Function for finalizing external byte arrays used as IO buffers. | 
|---|
| 28 | static void Finalizer(void* isolate_callback_data, | 
|---|
| 29 | Dart_WeakPersistentHandle handle, | 
|---|
| 30 | void* buffer) { | 
|---|
| 31 | Free(buffer); | 
|---|
| 32 | } | 
|---|
| 33 |  | 
|---|
| 34 | private: | 
|---|
| 35 | DISALLOW_ALLOCATION(); | 
|---|
| 36 | DISALLOW_IMPLICIT_CONSTRUCTORS(IOBuffer); | 
|---|
| 37 | }; | 
|---|
| 38 |  | 
|---|
| 39 | }  // namespace bin | 
|---|
| 40 | }  // namespace dart | 
|---|
| 41 |  | 
|---|
| 42 | #endif  // RUNTIME_BIN_IO_BUFFER_H_ | 
|---|
| 43 |  | 
|---|