• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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/public/system/core_private.h"
6 
7 #include <assert.h>
8 #include <stddef.h>
9 
10 static mojo::CorePrivate* g_core = NULL;
11 
12 extern "C" {
13 
MojoGetTimeTicksNow()14 MojoTimeTicks MojoGetTimeTicksNow() {
15   assert(g_core);
16   return g_core->GetTimeTicksNow();
17 }
18 
MojoClose(MojoHandle handle)19 MojoResult MojoClose(MojoHandle handle) {
20   assert(g_core);
21   return g_core->Close(handle);
22 }
23 
MojoWait(MojoHandle handle,MojoWaitFlags flags,MojoDeadline deadline)24 MojoResult MojoWait(MojoHandle handle,
25                     MojoWaitFlags flags,
26                     MojoDeadline deadline) {
27   assert(g_core);
28   return g_core->Wait(handle, flags, deadline);
29 }
30 
MojoWaitMany(const MojoHandle * handles,const MojoWaitFlags * flags,uint32_t num_handles,MojoDeadline deadline)31 MojoResult MojoWaitMany(const MojoHandle* handles,
32                         const MojoWaitFlags* flags,
33                         uint32_t num_handles,
34                         MojoDeadline deadline) {
35   assert(g_core);
36   return g_core->WaitMany(handles, flags, num_handles, deadline);
37 }
38 
MojoCreateMessagePipe(MojoHandle * message_pipe_handle_0,MojoHandle * message_pipe_handle_1)39 MojoResult MojoCreateMessagePipe(MojoHandle* message_pipe_handle_0,
40                                  MojoHandle* message_pipe_handle_1) {
41   assert(g_core);
42   return g_core->CreateMessagePipe(message_pipe_handle_0,
43                                    message_pipe_handle_1);
44 }
45 
MojoWriteMessage(MojoHandle message_pipe_handle,const void * bytes,uint32_t num_bytes,const MojoHandle * handles,uint32_t num_handles,MojoWriteMessageFlags flags)46 MojoResult MojoWriteMessage(MojoHandle message_pipe_handle,
47                             const void* bytes,
48                             uint32_t num_bytes,
49                             const MojoHandle* handles,
50                             uint32_t num_handles,
51                             MojoWriteMessageFlags flags) {
52   assert(g_core);
53   return g_core->WriteMessage(message_pipe_handle, bytes, num_bytes, handles,
54                               num_handles, flags);
55 }
56 
MojoReadMessage(MojoHandle message_pipe_handle,void * bytes,uint32_t * num_bytes,MojoHandle * handles,uint32_t * num_handles,MojoReadMessageFlags flags)57 MojoResult MojoReadMessage(MojoHandle message_pipe_handle,
58                            void* bytes,
59                            uint32_t* num_bytes,
60                            MojoHandle* handles,
61                            uint32_t* num_handles,
62                            MojoReadMessageFlags flags) {
63   assert(g_core);
64   return g_core->ReadMessage(message_pipe_handle, bytes, num_bytes, handles,
65                              num_handles, flags);
66 }
67 
MojoCreateDataPipe(const MojoCreateDataPipeOptions * options,MojoHandle * data_pipe_producer_handle,MojoHandle * data_pipe_consumer_handle)68 MojoResult MojoCreateDataPipe(const MojoCreateDataPipeOptions* options,
69                               MojoHandle* data_pipe_producer_handle,
70                               MojoHandle* data_pipe_consumer_handle) {
71   assert(g_core);
72   return g_core->CreateDataPipe(options, data_pipe_producer_handle,
73                                 data_pipe_consumer_handle);
74 }
75 
MojoWriteData(MojoHandle data_pipe_producer_handle,const void * elements,uint32_t * num_elements,MojoWriteDataFlags flags)76 MojoResult MojoWriteData(MojoHandle data_pipe_producer_handle,
77                          const void* elements,
78                          uint32_t* num_elements,
79                          MojoWriteDataFlags flags) {
80   assert(g_core);
81   return g_core->WriteData(data_pipe_producer_handle, elements, num_elements,
82                            flags);
83 }
84 
MojoBeginWriteData(MojoHandle data_pipe_producer_handle,void ** buffer,uint32_t * buffer_num_elements,MojoWriteDataFlags flags)85 MojoResult MojoBeginWriteData(MojoHandle data_pipe_producer_handle,
86                               void** buffer,
87                               uint32_t* buffer_num_elements,
88                               MojoWriteDataFlags flags) {
89   assert(g_core);
90   return g_core->BeginWriteData(data_pipe_producer_handle, buffer,
91                                 buffer_num_elements, flags);
92 }
93 
MojoEndWriteData(MojoHandle data_pipe_producer_handle,uint32_t num_elements_written)94 MojoResult MojoEndWriteData(MojoHandle data_pipe_producer_handle,
95                             uint32_t num_elements_written) {
96   assert(g_core);
97   return g_core->EndWriteData(data_pipe_producer_handle, num_elements_written);
98 }
99 
MojoReadData(MojoHandle data_pipe_consumer_handle,void * elements,uint32_t * num_elements,MojoReadDataFlags flags)100 MojoResult MojoReadData(MojoHandle data_pipe_consumer_handle,
101                         void* elements,
102                         uint32_t* num_elements,
103                         MojoReadDataFlags flags) {
104   assert(g_core);
105   return g_core->ReadData(data_pipe_consumer_handle, elements, num_elements,
106                           flags);
107 }
108 
MojoBeginReadData(MojoHandle data_pipe_consumer_handle,const void ** buffer,uint32_t * buffer_num_elements,MojoReadDataFlags flags)109 MojoResult MojoBeginReadData(MojoHandle data_pipe_consumer_handle,
110                              const void** buffer,
111                              uint32_t* buffer_num_elements,
112                              MojoReadDataFlags flags) {
113   assert(g_core);
114   return g_core->BeginReadData(data_pipe_consumer_handle, buffer,
115                                buffer_num_elements, flags);
116 }
117 
MojoEndReadData(MojoHandle data_pipe_consumer_handle,uint32_t num_elements_read)118 MojoResult MojoEndReadData(MojoHandle data_pipe_consumer_handle,
119                            uint32_t num_elements_read) {
120   assert(g_core);
121   return g_core->EndReadData(data_pipe_consumer_handle, num_elements_read);
122 }
123 
124 }  // extern "C"
125 
126 namespace mojo {
127 
~CorePrivate()128 CorePrivate::~CorePrivate() {
129 }
130 
Init(CorePrivate * core)131 void CorePrivate::Init(CorePrivate* core) {
132   assert(!g_core);
133   g_core = core;
134 }
135 
136 }  // namespace mojo
137