OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Chromium OS 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 #ifndef REQUEST_H_ | |
6 #define REQUEST_H_ | |
7 | |
8 #include "ppapi/cpp/var_array_buffer.h" | |
9 #include "ppapi/cpp/var_dictionary.h" | |
10 | |
11 // Defines the protocol messsage used to communicate between JS and NaCL. | |
12 // This should be consistent with js/request.h. | |
13 namespace request { | |
14 | |
15 // Defines requests keys. Every key should be unique and the same as the keys | |
16 // on the JS side. | |
17 namespace key { | |
18 | |
19 // Mandatory keys for all unpacking requests. | |
20 const char kOperation[] = "operation"; // Should be a request::Operation. | |
21 const char kFileSystemId[] = "file_system_id"; // Should be a string. | |
22 const char kRequestId[] = "request_id"; // Should be a string. | |
23 | |
24 // Optional keys unique to unpacking operations. | |
25 const char kMetadata[] = "metadata"; // Should be a pp:VarDictionary. | |
26 const char kArchiveSize[] = | |
27 "archive_size"; // Should be a string as int64_t is not support by pp::Var. | |
28 const char kIndex[] = "index"; // Should be a string as int64_t is not | |
29 // supported by pp::Var. | |
30 const char kEncoding[] = "encoding"; // Should be a string. | |
31 const char kOpenRequestId[] = "open_request_id"; // Should be a string, just | |
32 // like kRequestId. | |
33 const char kReadFileData[] = "read_file_data"; // Should be a | |
34 // pp::VarArrayBuffer. | |
35 const char kHasMoreData[] = "has_more_data"; // Should be a bool. | |
36 const char kPassphrase[] = "passphrase"; // Should be a string. | |
37 | |
38 // Mandatory keys for all packing requests. | |
39 const char kCompressorId[] = "compressor_id"; // Should be an int. | |
40 | |
41 // Optional keys unique to packing operations. | |
42 const char kEntryId[] = "entry_id"; // Should be an int. | |
43 const char kPathname[] = "pathname"; // Should be a string. | |
44 const char kFileSize[] = "file_size"; // Should be a string. | |
45 const char kIsDirectory[] = "is_directory"; // Should be a bool. | |
46 const char kModificationTime[] = "modification_time"; // Should be a string | |
47 // (mm/dd/yy h:m:s). | |
48 const char kHasError[] = "has_error"; // Should be a bool. | |
49 | |
50 // Optional keys used for both packing and unpacking operations. | |
51 const char kError[] = "error"; // Should be a string. | |
52 const char kChunkBuffer[] = "chunk_buffer"; // Should be a pp::VarArrayBuffer. | |
53 const char kOffset[] = "offset"; // Should be a string as int64_t is not | |
54 // supported by pp::Var. | |
55 const char kLength[] = "length"; // Should be a string as int64_t is not | |
56 // supported by pp::Var. | |
57 const char kSrcFile[] = "src_file"; // Should be a string. | |
58 const char kSrcLine[] = "src_line"; // Should be a string. | |
59 const char kSrcFunc[] = "src_func"; // Should be a string. | |
60 const char kMessage[] = "message"; // Should be a string. | |
61 } // namespace key | |
62 | |
63 // Defines request operations. These operations should be the same as the | |
64 // operations on the JavaScript side. | |
65 enum Operation { | |
66 READ_METADATA = 0, | |
67 READ_METADATA_DONE = 1, | |
68 READ_CHUNK = 2, | |
69 READ_CHUNK_DONE = 3, | |
70 READ_CHUNK_ERROR = 4, | |
71 READ_PASSPHRASE = 5, | |
72 READ_PASSPHRASE_DONE = 6, | |
73 READ_PASSPHRASE_ERROR = 7, | |
74 CLOSE_VOLUME = 8, | |
75 OPEN_FILE = 9, | |
76 OPEN_FILE_DONE = 10, | |
77 CLOSE_FILE = 11, | |
78 CLOSE_FILE_DONE = 12, | |
79 READ_FILE = 13, | |
80 READ_FILE_DONE = 14, | |
81 CONSOLE_LOG = 15, | |
82 CONSOLE_DEBUG = 16, | |
83 CREATE_ARCHIVE = 17, | |
84 CREATE_ARCHIVE_DONE = 18, | |
85 ADD_TO_ARCHIVE = 19, | |
86 ADD_TO_ARCHIVE_DONE = 20, | |
87 READ_FILE_CHUNK = 21, | |
88 READ_FILE_CHUNK_DONE = 22, | |
89 WRITE_CHUNK = 23, | |
90 WRITE_CHUNK_DONE = 24, | |
91 CLOSE_ARCHIVE = 25, | |
92 CLOSE_ARCHIVE_DONE = 26, | |
93 FILE_SYSTEM_ERROR = -1, // Errors specific to a file system. | |
94 COMPRESSOR_ERROR = -2 // Errors specific to a compressor. | |
95 }; | |
96 | |
97 // Operations greater than or equal to this value are for packing. | |
98 const int MINIMUM_PACK_REQUEST_VALUE = 17; | |
99 | |
100 // Return true if the given operation is related to packing. | |
101 bool IsPackRequest(int operation); | |
102 | |
103 // Creates a response to READ_METADATA request. | |
104 pp::VarDictionary CreateReadMetadataDoneResponse( | |
105 const std::string& file_system_id, | |
106 const std::string& request_id, | |
107 const pp::VarDictionary& metadata); | |
108 | |
109 // Creates a request for a file chunk from JavaScript. | |
110 pp::VarDictionary CreateReadChunkRequest(const std::string& file_system_id, | |
111 const std::string& request_id, | |
112 int64_t offset, | |
113 int64_t length); | |
114 | |
115 // Creates a request for a passphrase for a file from JavaScript. | |
116 pp::VarDictionary CreateReadPassphraseRequest(const std::string& file_system_id, | |
117 const std::string& request_id); | |
118 | |
119 // Creates a response to OPEN_FILE request. | |
120 pp::VarDictionary CreateOpenFileDoneResponse(const std::string& file_system_id, | |
121 const std::string& request_id); | |
122 | |
123 // Creates a response to CLOSE_FILE request. | |
124 pp::VarDictionary CreateCloseFileDoneResponse( | |
125 const std::string& file_system_id, | |
126 const std::string& request_id, | |
127 const std::string& open_request_id); | |
128 | |
129 // Creates a response to READ_FILE request. | |
130 pp::VarDictionary CreateReadFileDoneResponse( | |
131 const std::string& file_system_id, | |
132 const std::string& request_id, | |
133 const pp::VarArrayBuffer& array_buffer, | |
134 bool has_more_data); | |
135 | |
136 pp::VarDictionary CreateCreateArchiveDoneResponse(int compressor_id); | |
137 | |
138 pp::VarDictionary CreateReadFileChunkRequest(int compressor_id, | |
139 int64_t length); | |
140 | |
141 pp::VarDictionary CreateWriteChunkRequest(int compressor_id, | |
142 const pp::VarArrayBuffer& array_buffer
, | |
143 int64_t length); | |
144 | |
145 pp::VarDictionary CreateAddToArchiveDoneResponse(int compressor_id); | |
146 | |
147 pp::VarDictionary CreateCloseArchiveDoneResponse(int compressor_id); | |
148 | |
149 // Creates a file system error. | |
150 pp::VarDictionary CreateFileSystemError(const std::string& file_system_id, | |
151 const std::string& request_id, | |
152 const std::string& error); | |
153 | |
154 pp::VarDictionary CreateConsoleLog( | |
155 const std::string& file_system_id, | |
156 const std::string& request_id, | |
157 const std::string& src_file, | |
158 int src_line, | |
159 const std::string& src_func, | |
160 const std::string& message); | |
161 | |
162 // Creates a compressor error. | |
163 pp::VarDictionary CreateCompressorError(int compressor_id, | |
164 const std::string& error); | |
165 | |
166 // Obtains a int64_t from a string value inside dictionary based on a | |
167 // request::Key. | |
168 int64_t GetInt64FromString(const pp::VarDictionary& dictionary, | |
169 const std::string& request_key); | |
170 | |
171 } // namespace request | |
172 | |
173 #endif // REQUEST_H_ | |
OLD | NEW |