-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpepper_file.h
95 lines (71 loc) · 2.48 KB
/
pepper_file.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PEPPER_FILE_H
#define PEPPER_FILE_H
#include <deque>
#include <vector>
#include "ppapi/utility/completion_callback_factory.h"
#include "ppapi/cpp/file_io.h"
#include "ppapi/cpp/file_system.h"
#include "file_interfaces.h"
#include "pthread_helpers.h"
class PepperFileHandler : public PathHandler {
public:
explicit PepperFileHandler(pp::FileSystem* file_system);
virtual ~PepperFileHandler();
virtual void addref();
virtual void release();
virtual FileStream* open(int fd, const char* pathname, int oflag, int* err);
virtual int stat(const char* pathname, nacl_abi_stat* out);
private:
int ref_;
pp::FileSystem* file_system_;
DISALLOW_COPY_AND_ASSIGN(PepperFileHandler);
};
class PepperFile : public FileStream {
public:
PepperFile(int fd, int oflag, pp::FileSystem* file_system);
virtual ~PepperFile();
bool is_block() { return !(oflag_ & O_NONBLOCK); }
bool is_open() { return file_io_ != NULL; }
int32_t open(const char* pathname);
virtual void addref();
virtual void release();
virtual FileStream* dup(int fd);
virtual void close();
virtual int read(char* buf, size_t count, size_t* nread);
virtual int write(const char* buf, size_t count, size_t* nwrote);
virtual int seek(nacl_abi_off_t offset, int whence,
nacl_abi_off_t* new_offset);
virtual int fstat(nacl_abi_stat* out);
virtual int fcntl(int cmd, va_list ap);
virtual bool is_read_ready();
virtual bool is_write_ready();
virtual bool is_exception();
private:
void Open(int32_t result, const char* pathname, int32_t* pres);
void OnOpen(int32_t result, int32_t* pres);
void OnQuery(int32_t result, int32_t* pres);
void Read(int32_t result, size_t count, int32_t* pres);
void OnRead(int32_t result, int32_t* pres);
void Write(int32_t result, int32_t* pres);
void OnWrite(int32_t result, int32_t* pres);
void Close(int32_t result, int32_t* pres);
static const size_t kBufSize = 64 * 1024;
int ref_;
int fd_;
int oflag_;
pp::CompletionCallbackFactory<PepperFile> factory_;
pp::FileSystem* file_system_;
pp::FileIO* file_io_;
int64_t offset_;
PP_FileInfo file_info_;
std::deque<char> in_buf_;
std::vector<char> out_buf_;
std::vector<char> read_buf_;
std::vector<char> write_buf_;
bool write_sent_;
DISALLOW_COPY_AND_ASSIGN(PepperFile);
};
#endif // PEPPER_FILE_H