Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 native_cgo | 5 package native_cgo |
| 6 | 6 |
| 7 //#include "mojo/public/c/system/core.h" | 7 //#include "mojo/public/c/system/core.h" |
| 8 // // These functions are used to 8-byte align C structs. | 8 // // These functions are used to 8-byte align C structs. |
| 9 // MojoResult CreateSharedBuffer(struct MojoCreateSharedBufferOptions* options, | 9 // MojoResult CreateSharedBuffer(struct MojoCreateSharedBufferOptions* options, |
| 10 // uint64_t num_bytes, MojoHandle* handle) { | 10 // uint64_t num_bytes, MojoHandle* handle) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 // A nil options pointer in the C interface means use the default values . | 115 // A nil options pointer in the C interface means use the default values . |
| 116 return createDataPipeWithCOptions(nil) | 116 return createDataPipeWithCOptions(nil) |
| 117 } | 117 } |
| 118 | 118 |
| 119 func (c *CGoSystem) WriteData(producerHandle uint32, buf []byte, flags uint32) ( result uint32, bytesWritten uint32) { | 119 func (c *CGoSystem) WriteData(producerHandle uint32, buf []byte, flags uint32) ( result uint32, bytesWritten uint32) { |
| 120 numBytes := C.uint32_t(len(buf)) | 120 numBytes := C.uint32_t(len(buf)) |
| 121 r := C.MojoWriteData(C.MojoHandle(producerHandle), unsafe.Pointer(&buf[0 ]), &numBytes, C.MojoWriteDataFlags(flags)) | 121 r := C.MojoWriteData(C.MojoHandle(producerHandle), unsafe.Pointer(&buf[0 ]), &numBytes, C.MojoWriteDataFlags(flags)) |
| 122 return uint32(r), uint32(numBytes) | 122 return uint32(r), uint32(numBytes) |
| 123 } | 123 } |
| 124 | 124 |
| 125 func (c *CGoSystem) BeginWriteData(producerHandle uint32, numBytes uint32, flags uint32) (result uint32, buf []byte) { | 125 func (c *CGoSystem) BeginWriteData(producerHandle uint32, flags uint32) (result uint32, buf []byte) { |
| 126 var buffer unsafe.Pointer | 126 var buffer unsafe.Pointer |
| 127 » bufferNumBytes := C.uint32_t(numBytes) | 127 » var bufferNumBytes C.uint32_t |
| 128 r := C.MojoBeginWriteData(C.MojoHandle(producerHandle), &buffer, &buffer NumBytes, C.MojoWriteDataFlags(flags)) | 128 r := C.MojoBeginWriteData(C.MojoHandle(producerHandle), &buffer, &buffer NumBytes, C.MojoWriteDataFlags(flags)) |
| 129 if r != C.MOJO_RESULT_OK { | 129 if r != C.MOJO_RESULT_OK { |
| 130 return uint32(r), nil | 130 return uint32(r), nil |
| 131 } | 131 } |
| 132 return uint32(r), unsafeByteSlice(buffer, int(bufferNumBytes)) | 132 return uint32(r), unsafeByteSlice(buffer, int(bufferNumBytes)) |
| 133 } | 133 } |
| 134 | 134 |
| 135 func (c *CGoSystem) EndWriteData(producerHandle uint32, numBytesWritten uint32) (result uint32) { | 135 func (c *CGoSystem) EndWriteData(producerHandle uint32, numBytesWritten uint32) (result uint32) { |
| 136 return uint32(C.MojoEndWriteData(C.MojoHandle(producerHandle), C.uint32_ t(numBytesWritten))) | 136 return uint32(C.MojoEndWriteData(C.MojoHandle(producerHandle), C.uint32_ t(numBytesWritten))) |
| 137 } | 137 } |
| 138 | 138 |
| 139 func (c *CGoSystem) ReadData(consumerHandle uint32, flags uint32) (result uint32 , buf []byte) { | 139 func (c *CGoSystem) ReadData(consumerHandle uint32, flags uint32) (result uint32 , buf []byte) { |
| 140 var numBytes C.uint32_t | 140 var numBytes C.uint32_t |
| 141 if r := C.MojoReadData(C.MojoHandle(consumerHandle), nil, &numBytes, C.M OJO_READ_DATA_FLAG_QUERY); r != C.MOJO_RESULT_OK { | 141 if r := C.MojoReadData(C.MojoHandle(consumerHandle), nil, &numBytes, C.M OJO_READ_DATA_FLAG_QUERY); r != C.MOJO_RESULT_OK { |
| 142 return uint32(r), nil | 142 return uint32(r), nil |
| 143 } | 143 } |
| 144 buf = make([]byte, int(numBytes)) | 144 buf = make([]byte, int(numBytes)) |
| 145 r := C.MojoReadData(C.MojoHandle(consumerHandle), unsafe.Pointer(&buf[0] ), &numBytes, C.MojoReadDataFlags(flags)) | 145 r := C.MojoReadData(C.MojoHandle(consumerHandle), unsafe.Pointer(&buf[0] ), &numBytes, C.MojoReadDataFlags(flags)) |
| 146 buf = buf[0:int(numBytes)] | 146 buf = buf[0:int(numBytes)] |
| 147 return uint32(r), buf | 147 return uint32(r), buf |
| 148 } | 148 } |
| 149 | 149 |
| 150 func (c *CGoSystem) BeginReadData(consumerHandle uint32, numBytes uint32, flags uint32) (result uint32, buf []byte) { | 150 func (c *CGoSystem) BeginReadData(consumerHandle uint32, flags uint32) (result u int32, buf []byte) { |
| 151 var buffer unsafe.Pointer | 151 var buffer unsafe.Pointer |
| 152 » bufferNumBytes := C.uint32_t(numBytes) | 152 var bufferNumBytes C.uint32_t |
|
rogulenko
2015/09/25 23:23:05
indent with tabs
| |
| 153 r := C.MojoBeginReadData(C.MojoHandle(consumerHandle), &buffer, &bufferN umBytes, C.MojoReadDataFlags(flags)) | 153 r := C.MojoBeginReadData(C.MojoHandle(consumerHandle), &buffer, &bufferN umBytes, C.MojoReadDataFlags(flags)) |
| 154 if r != C.MOJO_RESULT_OK { | 154 if r != C.MOJO_RESULT_OK { |
| 155 return uint32(r), nil | 155 return uint32(r), nil |
| 156 } | 156 } |
| 157 return uint32(r), unsafeByteSlice(buffer, int(bufferNumBytes)) | 157 return uint32(r), unsafeByteSlice(buffer, int(bufferNumBytes)) |
| 158 } | 158 } |
| 159 | 159 |
| 160 func (c *CGoSystem) EndReadData(consumerHandle uint32, numBytesRead uint32) (res ult uint32) { | 160 func (c *CGoSystem) EndReadData(consumerHandle uint32, numBytesRead uint32) (res ult uint32) { |
| 161 return uint32(C.MojoEndReadData(C.MojoHandle(consumerHandle), C.uint32_t (numBytesRead))) | 161 return uint32(C.MojoEndReadData(C.MojoHandle(consumerHandle), C.uint32_t (numBytesRead))) |
| 162 } | 162 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 Data: uintptr(ptr), | 249 Data: uintptr(ptr), |
| 250 Len: length, | 250 Len: length, |
| 251 Cap: length, | 251 Cap: length, |
| 252 } | 252 } |
| 253 return unsafe.Pointer(header) | 253 return unsafe.Pointer(header) |
| 254 } | 254 } |
| 255 | 255 |
| 256 func unsafeByteSlice(ptr unsafe.Pointer, length int) []byte { | 256 func unsafeByteSlice(ptr unsafe.Pointer, length int) []byte { |
| 257 return *(*[]byte)(newUnsafeSlice(ptr, length)) | 257 return *(*[]byte)(newUnsafeSlice(ptr, length)) |
| 258 } | 258 } |
| OLD | NEW |