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/embedder/embedder_internal.h" | |
6 #include "mojo/edk/system/core.h" | |
7 #include "mojo/public/c/system/buffer.h" | |
8 #include "mojo/public/c/system/data_pipe.h" | |
9 #include "mojo/public/c/system/functions.h" | |
10 #include "mojo/public/c/system/message_pipe.h" | |
11 | |
12 using mojo::embedder::internal::g_core; | |
13 using mojo::system::MakeUserPointer; | |
14 | |
15 // Definitions of the system functions. | |
16 extern "C" { | |
17 MojoTimeTicks MojoGetTimeTicksNow() { | |
18 return g_core->GetTimeTicksNow(); | |
19 } | |
20 | |
21 MojoResult MojoClose(MojoHandle handle) { | |
22 return g_core->Close(handle); | |
23 } | |
24 | |
25 MojoResult MojoWait(MojoHandle handle, | |
26 MojoHandleSignals signals, | |
27 MojoDeadline deadline) { | |
28 return g_core->Wait(handle, signals, deadline, | |
29 mojo::system::NullUserPointer()); | |
30 } | |
31 | |
32 MojoResult MojoWaitMany(const MojoHandle* handles, | |
33 const MojoHandleSignals* signals, | |
34 uint32_t num_handles, | |
35 MojoDeadline deadline) { | |
36 uint32_t result_index = static_cast<uint32_t>(-1); | |
37 MojoResult result = g_core->WaitMany( | |
38 MakeUserPointer(handles), MakeUserPointer(signals), num_handles, deadline, | |
39 MakeUserPointer(&result_index), mojo::system::NullUserPointer()); | |
40 return (result == MOJO_RESULT_OK) ? static_cast<MojoResult>(result_index) | |
41 : result; | |
42 } | |
43 | |
44 MojoResult MojoCreateMessagePipe(const MojoCreateMessagePipeOptions* options, | |
45 MojoHandle* message_pipe_handle0, | |
46 MojoHandle* message_pipe_handle1) { | |
47 return g_core->CreateMessagePipe(MakeUserPointer(options), | |
48 MakeUserPointer(message_pipe_handle0), | |
49 MakeUserPointer(message_pipe_handle1)); | |
50 } | |
51 | |
52 MojoResult MojoWriteMessage(MojoHandle message_pipe_handle, | |
53 const void* bytes, | |
54 uint32_t num_bytes, | |
55 const MojoHandle* handles, | |
56 uint32_t num_handles, | |
57 MojoWriteMessageFlags flags) { | |
58 return g_core->WriteMessage(message_pipe_handle, MakeUserPointer(bytes), | |
59 num_bytes, MakeUserPointer(handles), num_handles, | |
60 flags); | |
61 } | |
62 | |
63 MojoResult MojoReadMessage(MojoHandle message_pipe_handle, | |
64 void* bytes, | |
65 uint32_t* num_bytes, | |
66 MojoHandle* handles, | |
67 uint32_t* num_handles, | |
68 MojoReadMessageFlags flags) { | |
69 return g_core->ReadMessage( | |
70 message_pipe_handle, MakeUserPointer(bytes), MakeUserPointer(num_bytes), | |
71 MakeUserPointer(handles), MakeUserPointer(num_handles), flags); | |
72 } | |
73 | |
74 MojoResult MojoCreateDataPipe(const MojoCreateDataPipeOptions* options, | |
75 MojoHandle* data_pipe_producer_handle, | |
76 MojoHandle* data_pipe_consumer_handle) { | |
77 return g_core->CreateDataPipe(MakeUserPointer(options), | |
78 MakeUserPointer(data_pipe_producer_handle), | |
79 MakeUserPointer(data_pipe_consumer_handle)); | |
80 } | |
81 | |
82 MojoResult MojoWriteData(MojoHandle data_pipe_producer_handle, | |
83 const void* elements, | |
84 uint32_t* num_elements, | |
85 MojoWriteDataFlags flags) { | |
86 return g_core->WriteData(data_pipe_producer_handle, MakeUserPointer(elements), | |
87 MakeUserPointer(num_elements), flags); | |
88 } | |
89 | |
90 MojoResult MojoBeginWriteData(MojoHandle data_pipe_producer_handle, | |
91 void** buffer, | |
92 uint32_t* buffer_num_elements, | |
93 MojoWriteDataFlags flags) { | |
94 return g_core->BeginWriteData(data_pipe_producer_handle, | |
95 MakeUserPointer(buffer), | |
96 MakeUserPointer(buffer_num_elements), flags); | |
97 } | |
98 | |
99 MojoResult MojoEndWriteData(MojoHandle data_pipe_producer_handle, | |
100 uint32_t num_elements_written) { | |
101 return g_core->EndWriteData(data_pipe_producer_handle, num_elements_written); | |
102 } | |
103 | |
104 MojoResult MojoReadData(MojoHandle data_pipe_consumer_handle, | |
105 void* elements, | |
106 uint32_t* num_elements, | |
107 MojoReadDataFlags flags) { | |
108 return g_core->ReadData(data_pipe_consumer_handle, MakeUserPointer(elements), | |
109 MakeUserPointer(num_elements), flags); | |
110 } | |
111 | |
112 MojoResult MojoBeginReadData(MojoHandle data_pipe_consumer_handle, | |
113 const void** buffer, | |
114 uint32_t* buffer_num_elements, | |
115 MojoReadDataFlags flags) { | |
116 return g_core->BeginReadData(data_pipe_consumer_handle, | |
117 MakeUserPointer(buffer), | |
118 MakeUserPointer(buffer_num_elements), flags); | |
119 } | |
120 | |
121 MojoResult MojoEndReadData(MojoHandle data_pipe_consumer_handle, | |
122 uint32_t num_elements_read) { | |
123 return g_core->EndReadData(data_pipe_consumer_handle, num_elements_read); | |
124 } | |
125 | |
126 MojoResult MojoCreateSharedBuffer( | |
127 const struct MojoCreateSharedBufferOptions* options, | |
128 uint64_t num_bytes, | |
129 MojoHandle* shared_buffer_handle) { | |
130 return g_core->CreateSharedBuffer(MakeUserPointer(options), num_bytes, | |
131 MakeUserPointer(shared_buffer_handle)); | |
132 } | |
133 | |
134 MojoResult MojoDuplicateBufferHandle( | |
135 MojoHandle buffer_handle, | |
136 const struct MojoDuplicateBufferHandleOptions* options, | |
137 MojoHandle* new_buffer_handle) { | |
138 return g_core->DuplicateBufferHandle(buffer_handle, MakeUserPointer(options), | |
139 MakeUserPointer(new_buffer_handle)); | |
140 } | |
141 | |
142 MojoResult MojoMapBuffer(MojoHandle buffer_handle, | |
143 uint64_t offset, | |
144 uint64_t num_bytes, | |
145 void** buffer, | |
146 MojoMapBufferFlags flags) { | |
147 return g_core->MapBuffer(buffer_handle, offset, num_bytes, | |
148 MakeUserPointer(buffer), flags); | |
149 } | |
150 | |
151 MojoResult MojoUnmapBuffer(void* buffer) { | |
152 return g_core->UnmapBuffer(MakeUserPointer(buffer)); | |
153 } | |
154 | |
155 } // extern "C" | |
OLD | NEW |