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
;
20 namespace entrypoints
{
22 void SetCore(Core
* core
) {
30 } // namespace entrypoints
34 // Definitions of the system functions.
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
) {
48 handle
, signals
, deadline
, mojo::system::NullUserPointer());
51 MojoResult
MojoWaitMany(const MojoHandle
* handles
,
52 const MojoHandleSignals
* signals
,
54 MojoDeadline deadline
) {
55 uint32_t result_index
= static_cast<uint32_t>(-1);
56 MojoResult result
= g_core
->WaitMany(MakeUserPointer(handles
),
57 MakeUserPointer(signals
),
60 MakeUserPointer(&result_index
),
61 mojo::system::NullUserPointer());
62 return (result
== MOJO_RESULT_OK
) ? static_cast<MojoResult
>(result_index
)
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
,
77 const MojoHandle
* handles
,
79 MojoWriteMessageFlags flags
) {
80 return g_core
->WriteMessage(message_pipe_handle
,
81 MakeUserPointer(bytes
),
83 MakeUserPointer(handles
),
88 MojoResult
MojoReadMessage(MojoHandle message_pipe_handle
,
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
),
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
),
120 MojoResult
MojoBeginWriteData(MojoHandle data_pipe_producer_handle
,
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
),
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
,
137 uint32_t* num_elements
,
138 MojoReadDataFlags flags
) {
139 return g_core
->ReadData(data_pipe_consumer_handle
,
140 MakeUserPointer(elements
),
141 MakeUserPointer(num_elements
),
145 MojoResult
MojoBeginReadData(MojoHandle data_pipe_consumer_handle
,
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
),
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
,
163 MojoHandle
* shared_buffer_handle
) {
164 return g_core
->CreateSharedBuffer(MakeUserPointer(options
),
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
,
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
));