• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 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 // From ppb_file_io.idl modified Tue Apr 16 11:25:44 2013.
6 
7 #include "ppapi/c/pp_completion_callback.h"
8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/c/ppb_file_io.h"
10 #include "ppapi/shared_impl/tracked_callback.h"
11 #include "ppapi/thunk/enter.h"
12 #include "ppapi/thunk/ppb_file_io_api.h"
13 #include "ppapi/thunk/ppb_instance_api.h"
14 #include "ppapi/thunk/resource_creation_api.h"
15 #include "ppapi/thunk/thunk.h"
16 
17 namespace ppapi {
18 namespace thunk {
19 
20 namespace {
21 
Create(PP_Instance instance)22 PP_Resource Create(PP_Instance instance) {
23   VLOG(4) << "PPB_FileIO::Create()";
24   EnterResourceCreation enter(instance);
25   if (enter.failed())
26     return 0;
27   return enter.functions()->CreateFileIO(instance);
28 }
29 
IsFileIO(PP_Resource resource)30 PP_Bool IsFileIO(PP_Resource resource) {
31   VLOG(4) << "PPB_FileIO::IsFileIO()";
32   EnterResource<PPB_FileIO_API> enter(resource, false);
33   return PP_FromBool(enter.succeeded());
34 }
35 
Open(PP_Resource file_io,PP_Resource file_ref,int32_t open_flags,struct PP_CompletionCallback callback)36 int32_t Open(PP_Resource file_io,
37              PP_Resource file_ref,
38              int32_t open_flags,
39              struct PP_CompletionCallback callback) {
40   VLOG(4) << "PPB_FileIO::Open()";
41   EnterResource<PPB_FileIO_API> enter(file_io, callback, true);
42   if (enter.failed())
43     return enter.retval();
44   return enter.SetResult(enter.object()->Open(file_ref,
45                                               open_flags,
46                                               enter.callback()));
47 }
48 
Query(PP_Resource file_io,struct PP_FileInfo * info,struct PP_CompletionCallback callback)49 int32_t Query(PP_Resource file_io,
50               struct PP_FileInfo* info,
51               struct PP_CompletionCallback callback) {
52   VLOG(4) << "PPB_FileIO::Query()";
53   EnterResource<PPB_FileIO_API> enter(file_io, callback, true);
54   if (enter.failed())
55     return enter.retval();
56   return enter.SetResult(enter.object()->Query(info, enter.callback()));
57 }
58 
Touch(PP_Resource file_io,PP_Time last_access_time,PP_Time last_modified_time,struct PP_CompletionCallback callback)59 int32_t Touch(PP_Resource file_io,
60               PP_Time last_access_time,
61               PP_Time last_modified_time,
62               struct PP_CompletionCallback callback) {
63   VLOG(4) << "PPB_FileIO::Touch()";
64   EnterResource<PPB_FileIO_API> enter(file_io, callback, true);
65   if (enter.failed())
66     return enter.retval();
67   return enter.SetResult(enter.object()->Touch(last_access_time,
68                                                last_modified_time,
69                                                enter.callback()));
70 }
71 
Read(PP_Resource file_io,int64_t offset,char * buffer,int32_t bytes_to_read,struct PP_CompletionCallback callback)72 int32_t Read(PP_Resource file_io,
73              int64_t offset,
74              char* buffer,
75              int32_t bytes_to_read,
76              struct PP_CompletionCallback callback) {
77   VLOG(4) << "PPB_FileIO::Read()";
78   EnterResource<PPB_FileIO_API> enter(file_io, callback, true);
79   if (enter.failed())
80     return enter.retval();
81   return enter.SetResult(enter.object()->Read(offset,
82                                               buffer,
83                                               bytes_to_read,
84                                               enter.callback()));
85 }
86 
Write(PP_Resource file_io,int64_t offset,const char * buffer,int32_t bytes_to_write,struct PP_CompletionCallback callback)87 int32_t Write(PP_Resource file_io,
88               int64_t offset,
89               const char* buffer,
90               int32_t bytes_to_write,
91               struct PP_CompletionCallback callback) {
92   VLOG(4) << "PPB_FileIO::Write()";
93   EnterResource<PPB_FileIO_API> enter(file_io, callback, true);
94   if (enter.failed())
95     return enter.retval();
96   return enter.SetResult(enter.object()->Write(offset,
97                                                buffer,
98                                                bytes_to_write,
99                                                enter.callback()));
100 }
101 
SetLength(PP_Resource file_io,int64_t length,struct PP_CompletionCallback callback)102 int32_t SetLength(PP_Resource file_io,
103                   int64_t length,
104                   struct PP_CompletionCallback callback) {
105   VLOG(4) << "PPB_FileIO::SetLength()";
106   EnterResource<PPB_FileIO_API> enter(file_io, callback, true);
107   if (enter.failed())
108     return enter.retval();
109   return enter.SetResult(enter.object()->SetLength(length, enter.callback()));
110 }
111 
Flush(PP_Resource file_io,struct PP_CompletionCallback callback)112 int32_t Flush(PP_Resource file_io, struct PP_CompletionCallback callback) {
113   VLOG(4) << "PPB_FileIO::Flush()";
114   EnterResource<PPB_FileIO_API> enter(file_io, callback, true);
115   if (enter.failed())
116     return enter.retval();
117   return enter.SetResult(enter.object()->Flush(enter.callback()));
118 }
119 
Close(PP_Resource file_io)120 void Close(PP_Resource file_io) {
121   VLOG(4) << "PPB_FileIO::Close()";
122   EnterResource<PPB_FileIO_API> enter(file_io, true);
123   if (enter.failed())
124     return;
125   enter.object()->Close();
126 }
127 
ReadToArray(PP_Resource file_io,int64_t offset,int32_t max_read_length,struct PP_ArrayOutput * output,struct PP_CompletionCallback callback)128 int32_t ReadToArray(PP_Resource file_io,
129                     int64_t offset,
130                     int32_t max_read_length,
131                     struct PP_ArrayOutput* output,
132                     struct PP_CompletionCallback callback) {
133   VLOG(4) << "PPB_FileIO::ReadToArray()";
134   EnterResource<PPB_FileIO_API> enter(file_io, callback, true);
135   if (enter.failed())
136     return enter.retval();
137   return enter.SetResult(enter.object()->ReadToArray(offset,
138                                                      max_read_length,
139                                                      output,
140                                                      enter.callback()));
141 }
142 
143 const PPB_FileIO_1_0 g_ppb_fileio_thunk_1_0 = {
144   &Create,
145   &IsFileIO,
146   &Open,
147   &Query,
148   &Touch,
149   &Read,
150   &Write,
151   &SetLength,
152   &Flush,
153   &Close
154 };
155 
156 const PPB_FileIO_1_1 g_ppb_fileio_thunk_1_1 = {
157   &Create,
158   &IsFileIO,
159   &Open,
160   &Query,
161   &Touch,
162   &Read,
163   &Write,
164   &SetLength,
165   &Flush,
166   &Close,
167   &ReadToArray
168 };
169 
170 }  // namespace
171 
GetPPB_FileIO_1_0_Thunk()172 const PPB_FileIO_1_0* GetPPB_FileIO_1_0_Thunk() {
173   return &g_ppb_fileio_thunk_1_0;
174 }
175 
GetPPB_FileIO_1_1_Thunk()176 const PPB_FileIO_1_1* GetPPB_FileIO_1_1_Thunk() {
177   return &g_ppb_fileio_thunk_1_1;
178 }
179 
180 }  // namespace thunk
181 }  // namespace ppapi
182