| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package impl | 5 package impl |
| 6 | 6 |
| 7 //#include "mojo/public/platform/native/system_thunks.h" | 7 //#include "mojo/public/platform/native/system_thunks.h" |
| 8 //#include "mojo/public/c/system/main.h" | 8 //#include "mojo/public/c/system/main.h" |
| 9 import "C" | 9 import "C" |
| 10 import "unsafe" |
| 10 | 11 |
| 11 var core *CoreImpl | 12 var core *CoreImpl |
| 12 | 13 |
| 13 func init() { | 14 func init() { |
| 14 core = &CoreImpl{} | 15 core = &CoreImpl{} |
| 15 } | 16 } |
| 16 | 17 |
| 17 // CoreImpl is an implementation of the Mojo system APIs. | 18 // CoreImpl is an implementation of the Mojo system APIs. |
| 18 type CoreImpl struct { | 19 type CoreImpl struct { |
| 19 } | 20 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 func (c *CoreImpl) ReadData(consumer MojoHandle, flags MojoReadDataFlags) (MojoR
esult, []byte) { | 75 func (c *CoreImpl) ReadData(consumer MojoHandle, flags MojoReadDataFlags) (MojoR
esult, []byte) { |
| 75 var num_bytes C.uint32_t | 76 var num_bytes C.uint32_t |
| 76 var result C.MojoResult | 77 var result C.MojoResult |
| 77 if result = C.MojoReadData(consumer.cType(), nil, &num_bytes, C.MOJO_REA
D_DATA_FLAG_QUERY); result != C.MOJO_RESULT_OK { | 78 if result = C.MojoReadData(consumer.cType(), nil, &num_bytes, C.MOJO_REA
D_DATA_FLAG_QUERY); result != C.MOJO_RESULT_OK { |
| 78 return (MojoResult)(result), nil | 79 return (MojoResult)(result), nil |
| 79 } | 80 } |
| 80 data := make([]byte, (uint32)(num_bytes)) | 81 data := make([]byte, (uint32)(num_bytes)) |
| 81 result = C.MojoReadData(consumer.cType(), cArrayBytes(data), &num_bytes,
flags.cType()) | 82 result = C.MojoReadData(consumer.cType(), cArrayBytes(data), &num_bytes,
flags.cType()) |
| 82 return (MojoResult)(result), data | 83 return (MojoResult)(result), data |
| 83 } | 84 } |
| 85 |
| 86 func (c *CoreImpl) CreateSharedBuffer(opts *SharedBufferOptions, numBytes uint64
) (MojoResult, MojoHandle) { |
| 87 var handle C.MojoHandle |
| 88 result := C.MojoCreateSharedBuffer(opts.cType(), (C.uint64_t)(numBytes),
&handle) |
| 89 return (MojoResult)(result), (MojoHandle)(handle) |
| 90 } |
| 91 |
| 92 func (c *CoreImpl) DuplicateBufferHandle(handle MojoHandle, opts *DuplicateBuffe
rHandleOptions) (MojoResult, MojoHandle) { |
| 93 var duplicate C.MojoHandle |
| 94 result := C.MojoDuplicateBufferHandle(handle.cType(), opts.cType(), &dup
licate) |
| 95 return (MojoResult)(result), (MojoHandle)(duplicate) |
| 96 } |
| 97 |
| 98 func (c *CoreImpl) MapBuffer(handle MojoHandle, offset uint64, numBytes uint64,
flags MojoMapBufferFlags) (MojoResult, unsafe.Pointer) { |
| 99 var bufPtr unsafe.Pointer |
| 100 result := C.MojoMapBuffer(handle.cType(), (C.uint64_t)(offset), (C.uint6
4_t)(numBytes), &bufPtr, flags.cType()) |
| 101 if result != C.MOJO_RESULT_OK { |
| 102 return (MojoResult)(result), nil |
| 103 } |
| 104 return MOJO_RESULT_OK, bufPtr |
| 105 } |
| 106 |
| 107 func (c *CoreImpl) UnmapBuffer(buffer unsafe.Pointer) MojoResult { |
| 108 return (MojoResult)(C.MojoUnmapBuffer(buffer)) |
| 109 } |
| OLD | NEW |