[Sync] Don't synchronously stop datatypes that encounter errors
[chromium-blink-merge.git] / mojo / system / entrypoints.cc
blob32c7235ed2519f91e4fa56de9df0e1d8faec2085
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
3 // found in the LICENSE file.
5 #include "mojo/system/entrypoints.h"
7 #include "base/logging.h"
8 #include "mojo/public/c/system/buffer.h"
9 #include "mojo/public/c/system/data_pipe.h"
10 #include "mojo/public/c/system/functions.h"
11 #include "mojo/public/c/system/message_pipe.h"
12 #include "mojo/system/core.h"
14 static mojo::system::Core* g_core = NULL;
16 using mojo::system::MakeUserPointer;
18 namespace mojo {
19 namespace system {
20 namespace entrypoints {
22 void SetCore(Core* core) {
23 g_core = core;
26 Core* GetCore() {
27 return g_core;
30 } // namespace entrypoints
31 } // namepace system
32 } // namespace mojo
34 // Definitions of the system functions.
35 extern "C" {
36 MojoTimeTicks MojoGetTimeTicksNow() {
37 return g_core->GetTimeTicksNow();
40 MojoResult MojoClose(MojoHandle handle) {
41 return g_core->Close(handle);
44 MojoResult MojoWait(MojoHandle handle,
45 MojoHandleSignals signals,
46 MojoDeadline deadline) {
47 return g_core->Wait(
48 handle, signals, deadline, mojo::system::NullUserPointer());
51 MojoResult MojoWaitMany(const MojoHandle* handles,
52 const MojoHandleSignals* signals,
53 uint32_t num_handles,
54 MojoDeadline deadline) {
55 uint32_t result_index = static_cast<uint32_t>(-1);
56 MojoResult result = g_core->WaitMany(MakeUserPointer(handles),
57 MakeUserPointer(signals),
58 num_handles,
59 deadline,
60 MakeUserPointer(&result_index),
61 mojo::system::NullUserPointer());
62 return (result == MOJO_RESULT_OK) ? static_cast<MojoResult>(result_index)
63 : result;
66 MojoResult MojoCreateMessagePipe(const MojoCreateMessagePipeOptions* options,
67 MojoHandle* message_pipe_handle0,
68 MojoHandle* message_pipe_handle1) {
69 return g_core->CreateMessagePipe(MakeUserPointer(options),
70 MakeUserPointer(message_pipe_handle0),
71 MakeUserPointer(message_pipe_handle1));
74 MojoResult MojoWriteMessage(MojoHandle message_pipe_handle,
75 const void* bytes,
76 uint32_t num_bytes,
77 const MojoHandle* handles,
78 uint32_t num_handles,
79 MojoWriteMessageFlags flags) {
80 return g_core->WriteMessage(message_pipe_handle,
81 MakeUserPointer(bytes),
82 num_bytes,
83 MakeUserPointer(handles),
84 num_handles,
85 flags);
88 MojoResult MojoReadMessage(MojoHandle message_pipe_handle,
89 void* bytes,
90 uint32_t* num_bytes,
91 MojoHandle* handles,
92 uint32_t* num_handles,
93 MojoReadMessageFlags flags) {
94 return g_core->ReadMessage(message_pipe_handle,
95 MakeUserPointer(bytes),
96 MakeUserPointer(num_bytes),
97 MakeUserPointer(handles),
98 MakeUserPointer(num_handles),
99 flags);
102 MojoResult MojoCreateDataPipe(const MojoCreateDataPipeOptions* options,
103 MojoHandle* data_pipe_producer_handle,
104 MojoHandle* data_pipe_consumer_handle) {
105 return g_core->CreateDataPipe(MakeUserPointer(options),
106 MakeUserPointer(data_pipe_producer_handle),
107 MakeUserPointer(data_pipe_consumer_handle));
110 MojoResult MojoWriteData(MojoHandle data_pipe_producer_handle,
111 const void* elements,
112 uint32_t* num_elements,
113 MojoWriteDataFlags flags) {
114 return g_core->WriteData(data_pipe_producer_handle,
115 MakeUserPointer(elements),
116 MakeUserPointer(num_elements),
117 flags);
120 MojoResult MojoBeginWriteData(MojoHandle data_pipe_producer_handle,
121 void** buffer,
122 uint32_t* buffer_num_elements,
123 MojoWriteDataFlags flags) {
124 return g_core->BeginWriteData(data_pipe_producer_handle,
125 MakeUserPointer(buffer),
126 MakeUserPointer(buffer_num_elements),
127 flags);
130 MojoResult MojoEndWriteData(MojoHandle data_pipe_producer_handle,
131 uint32_t num_elements_written) {
132 return g_core->EndWriteData(data_pipe_producer_handle, num_elements_written);
135 MojoResult MojoReadData(MojoHandle data_pipe_consumer_handle,
136 void* elements,
137 uint32_t* num_elements,
138 MojoReadDataFlags flags) {
139 return g_core->ReadData(data_pipe_consumer_handle,
140 MakeUserPointer(elements),
141 MakeUserPointer(num_elements),
142 flags);
145 MojoResult MojoBeginReadData(MojoHandle data_pipe_consumer_handle,
146 const void** buffer,
147 uint32_t* buffer_num_elements,
148 MojoReadDataFlags flags) {
149 return g_core->BeginReadData(data_pipe_consumer_handle,
150 MakeUserPointer(buffer),
151 MakeUserPointer(buffer_num_elements),
152 flags);
155 MojoResult MojoEndReadData(MojoHandle data_pipe_consumer_handle,
156 uint32_t num_elements_read) {
157 return g_core->EndReadData(data_pipe_consumer_handle, num_elements_read);
160 MojoResult MojoCreateSharedBuffer(
161 const struct MojoCreateSharedBufferOptions* options,
162 uint64_t num_bytes,
163 MojoHandle* shared_buffer_handle) {
164 return g_core->CreateSharedBuffer(MakeUserPointer(options),
165 num_bytes,
166 MakeUserPointer(shared_buffer_handle));
169 MojoResult MojoDuplicateBufferHandle(
170 MojoHandle buffer_handle,
171 const struct MojoDuplicateBufferHandleOptions* options,
172 MojoHandle* new_buffer_handle) {
173 return g_core->DuplicateBufferHandle(buffer_handle,
174 MakeUserPointer(options),
175 MakeUserPointer(new_buffer_handle));
178 MojoResult MojoMapBuffer(MojoHandle buffer_handle,
179 uint64_t offset,
180 uint64_t num_bytes,
181 void** buffer,
182 MojoMapBufferFlags flags) {
183 return g_core->MapBuffer(
184 buffer_handle, offset, num_bytes, MakeUserPointer(buffer), flags);
187 MojoResult MojoUnmapBuffer(void* buffer) {
188 return g_core->UnmapBuffer(MakeUserPointer(buffer));
191 } // extern "C"