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