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.
5 // From ppb_file_io.idl modified Mon Nov 11 16:02:07 2013.
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"
20 PP_Resource
Create(PP_Instance instance
) {
21 VLOG(4) << "PPB_FileIO::Create()";
22 EnterResourceCreation
enter(instance
);
25 return enter
.functions()->CreateFileIO(instance
);
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());
34 int32_t Open(PP_Resource file_io
,
37 struct PP_CompletionCallback callback
) {
38 VLOG(4) << "PPB_FileIO::Open()";
39 EnterResource
<PPB_FileIO_API
> enter(file_io
, callback
, true);
41 return enter
.retval();
42 return enter
.SetResult(
43 enter
.object()->Open(file_ref
, open_flags
, enter
.callback()));
46 int32_t Query(PP_Resource file_io
,
47 struct PP_FileInfo
* info
,
48 struct PP_CompletionCallback callback
) {
49 VLOG(4) << "PPB_FileIO::Query()";
50 EnterResource
<PPB_FileIO_API
> enter(file_io
, callback
, true);
52 return enter
.retval();
53 return enter
.SetResult(enter
.object()->Query(info
, enter
.callback()));
56 int32_t Touch(PP_Resource file_io
,
57 PP_Time last_access_time
,
58 PP_Time last_modified_time
,
59 struct PP_CompletionCallback callback
) {
60 VLOG(4) << "PPB_FileIO::Touch()";
61 EnterResource
<PPB_FileIO_API
> enter(file_io
, callback
, true);
63 return enter
.retval();
64 return enter
.SetResult(enter
.object()->Touch(
65 last_access_time
, last_modified_time
, enter
.callback()));
68 int32_t Read(PP_Resource file_io
,
71 int32_t bytes_to_read
,
72 struct PP_CompletionCallback callback
) {
73 VLOG(4) << "PPB_FileIO::Read()";
74 EnterResource
<PPB_FileIO_API
> enter(file_io
, callback
, true);
76 return enter
.retval();
77 return enter
.SetResult(
78 enter
.object()->Read(offset
, buffer
, bytes_to_read
, enter
.callback()));
81 int32_t Write(PP_Resource file_io
,
84 int32_t bytes_to_write
,
85 struct PP_CompletionCallback callback
) {
86 VLOG(4) << "PPB_FileIO::Write()";
87 EnterResource
<PPB_FileIO_API
> enter(file_io
, callback
, true);
89 return enter
.retval();
90 return enter
.SetResult(
91 enter
.object()->Write(offset
, buffer
, bytes_to_write
, enter
.callback()));
94 int32_t SetLength(PP_Resource file_io
,
96 struct PP_CompletionCallback callback
) {
97 VLOG(4) << "PPB_FileIO::SetLength()";
98 EnterResource
<PPB_FileIO_API
> enter(file_io
, callback
, true);
100 return enter
.retval();
101 return enter
.SetResult(enter
.object()->SetLength(length
, enter
.callback()));
104 int32_t Flush(PP_Resource file_io
, struct PP_CompletionCallback callback
) {
105 VLOG(4) << "PPB_FileIO::Flush()";
106 EnterResource
<PPB_FileIO_API
> enter(file_io
, callback
, true);
108 return enter
.retval();
109 return enter
.SetResult(enter
.object()->Flush(enter
.callback()));
112 void Close(PP_Resource file_io
) {
113 VLOG(4) << "PPB_FileIO::Close()";
114 EnterResource
<PPB_FileIO_API
> enter(file_io
, true);
117 enter
.object()->Close();
120 int32_t ReadToArray(PP_Resource file_io
,
122 int32_t max_read_length
,
123 struct PP_ArrayOutput
* output
,
124 struct PP_CompletionCallback callback
) {
125 VLOG(4) << "PPB_FileIO::ReadToArray()";
126 EnterResource
<PPB_FileIO_API
> enter(file_io
, callback
, true);
128 return enter
.retval();
129 return enter
.SetResult(enter
.object()->ReadToArray(offset
, max_read_length
,
130 output
, enter
.callback()));
133 const PPB_FileIO_1_0 g_ppb_fileio_thunk_1_0
= {&Create
,
144 const PPB_FileIO_1_1 g_ppb_fileio_thunk_1_1
= {&Create
,
158 PPAPI_THUNK_EXPORT
const PPB_FileIO_1_0
* GetPPB_FileIO_1_0_Thunk() {
159 return &g_ppb_fileio_thunk_1_0
;
162 PPAPI_THUNK_EXPORT
const PPB_FileIO_1_1
* GetPPB_FileIO_1_1_Thunk() {
163 return &g_ppb_fileio_thunk_1_1
;