OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "mojo/edk/system/entrypoints.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "mojo/edk/system/core.h" |
| 9 #include "mojo/public/c/system/buffer.h" |
| 10 #include "mojo/public/c/system/data_pipe.h" |
| 11 #include "mojo/public/c/system/functions.h" |
| 12 #include "mojo/public/c/system/message_pipe.h" |
| 13 |
| 14 static mojo::system::Core* g_core = nullptr; |
| 15 |
| 16 using mojo::system::MakeUserPointer; |
| 17 |
| 18 namespace mojo { |
| 19 namespace system { |
| 20 namespace entrypoints { |
| 21 |
| 22 void SetCore(Core* core) { |
| 23 g_core = core; |
| 24 } |
| 25 |
| 26 Core* GetCore() { |
| 27 return g_core; |
| 28 } |
| 29 |
| 30 } // namespace entrypoints |
| 31 } // namepace system |
| 32 } // namespace mojo |
| 33 |
| 34 // Definitions of the system functions. |
| 35 extern "C" { |
| 36 MojoTimeTicks MojoGetTimeTicksNow() { |
| 37 return g_core->GetTimeTicksNow(); |
| 38 } |
| 39 |
| 40 MojoResult MojoClose(MojoHandle handle) { |
| 41 return g_core->Close(handle); |
| 42 } |
| 43 |
| 44 MojoResult MojoWait(MojoHandle handle, |
| 45 MojoHandleSignals signals, |
| 46 MojoDeadline deadline) { |
| 47 return g_core->Wait( |
| 48 handle, signals, deadline, mojo::system::NullUserPointer()); |
| 49 } |
| 50 |
| 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; |
| 64 } |
| 65 |
| 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)); |
| 72 } |
| 73 |
| 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); |
| 86 } |
| 87 |
| 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); |
| 100 } |
| 101 |
| 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)); |
| 108 } |
| 109 |
| 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); |
| 118 } |
| 119 |
| 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); |
| 128 } |
| 129 |
| 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); |
| 133 } |
| 134 |
| 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); |
| 143 } |
| 144 |
| 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); |
| 153 } |
| 154 |
| 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); |
| 158 } |
| 159 |
| 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)); |
| 167 } |
| 168 |
| 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)); |
| 176 } |
| 177 |
| 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); |
| 185 } |
| 186 |
| 187 MojoResult MojoUnmapBuffer(void* buffer) { |
| 188 return g_core->UnmapBuffer(MakeUserPointer(buffer)); |
| 189 } |
| 190 |
| 191 } // extern "C" |
OLD | NEW |