Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: mojo/public/go/system/impl/core_impl.go

Issue 664163004: -Go bindings for creating/managing shared buffers between applications (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Go build patches Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/public/go/system/core.go ('k') | mojo/public/go/system/impl/mojo_types.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
OLDNEW
« no previous file with comments | « mojo/public/go/system/core.go ('k') | mojo/public/go/system/impl/mojo_types.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698