• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 //    * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 //    * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 //    * Neither the name of Google Inc. nor the name Chromium Embedded
14 // Framework nor the names of its contributors may be used to endorse
15 // or promote products derived from this software without specific prior
16 // written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // ---------------------------------------------------------------------------
31 //
32 // The contents of this file must follow a specific format in order to
33 // support the CEF translator tool. See the translator.README.txt file in the
34 // tools directory for more information.
35 //
36 
37 #ifndef CEF_INCLUDE_CEF_STREAM_H_
38 #define CEF_INCLUDE_CEF_STREAM_H_
39 
40 #include "include/cef_base.h"
41 
42 ///
43 // Interface the client can implement to provide a custom stream reader. The
44 // methods of this class may be called on any thread.
45 ///
46 /*--cef(source=client)--*/
47 class CefReadHandler : public virtual CefBaseRefCounted {
48  public:
49   ///
50   // Read raw binary data.
51   ///
52   /*--cef()--*/
53   virtual size_t Read(void* ptr, size_t size, size_t n) = 0;
54 
55   ///
56   // Seek to the specified offset position. |whence| may be any one of
57   // SEEK_CUR, SEEK_END or SEEK_SET. Return zero on success and non-zero on
58   // failure.
59   ///
60   /*--cef()--*/
61   virtual int Seek(int64 offset, int whence) = 0;
62 
63   ///
64   // Return the current offset position.
65   ///
66   /*--cef()--*/
67   virtual int64 Tell() = 0;
68 
69   ///
70   // Return non-zero if at end of file.
71   ///
72   /*--cef()--*/
73   virtual int Eof() = 0;
74 
75   ///
76   // Return true if this handler performs work like accessing the file system
77   // which may block. Used as a hint for determining the thread to access the
78   // handler from.
79   ///
80   /*--cef()--*/
81   virtual bool MayBlock() = 0;
82 };
83 
84 ///
85 // Class used to read data from a stream. The methods of this class may be
86 // called on any thread.
87 ///
88 /*--cef(source=library)--*/
89 class CefStreamReader : public virtual CefBaseRefCounted {
90  public:
91   ///
92   // Create a new CefStreamReader object from a file.
93   ///
94   /*--cef()--*/
95   static CefRefPtr<CefStreamReader> CreateForFile(const CefString& fileName);
96   ///
97   // Create a new CefStreamReader object from data.
98   ///
99   /*--cef()--*/
100   static CefRefPtr<CefStreamReader> CreateForData(void* data, size_t size);
101   ///
102   // Create a new CefStreamReader object from a custom handler.
103   ///
104   /*--cef()--*/
105   static CefRefPtr<CefStreamReader> CreateForHandler(
106       CefRefPtr<CefReadHandler> handler);
107 
108   ///
109   // Read raw binary data.
110   ///
111   /*--cef()--*/
112   virtual size_t Read(void* ptr, size_t size, size_t n) = 0;
113 
114   ///
115   // Seek to the specified offset position. |whence| may be any one of
116   // SEEK_CUR, SEEK_END or SEEK_SET. Returns zero on success and non-zero on
117   // failure.
118   ///
119   /*--cef()--*/
120   virtual int Seek(int64 offset, int whence) = 0;
121 
122   ///
123   // Return the current offset position.
124   ///
125   /*--cef()--*/
126   virtual int64 Tell() = 0;
127 
128   ///
129   // Return non-zero if at end of file.
130   ///
131   /*--cef()--*/
132   virtual int Eof() = 0;
133 
134   ///
135   // Returns true if this reader performs work like accessing the file system
136   // which may block. Used as a hint for determining the thread to access the
137   // reader from.
138   ///
139   /*--cef()--*/
140   virtual bool MayBlock() = 0;
141 };
142 
143 ///
144 // Interface the client can implement to provide a custom stream writer. The
145 // methods of this class may be called on any thread.
146 ///
147 /*--cef(source=client)--*/
148 class CefWriteHandler : public virtual CefBaseRefCounted {
149  public:
150   ///
151   // Write raw binary data.
152   ///
153   /*--cef()--*/
154   virtual size_t Write(const void* ptr, size_t size, size_t n) = 0;
155 
156   ///
157   // Seek to the specified offset position. |whence| may be any one of
158   // SEEK_CUR, SEEK_END or SEEK_SET. Return zero on success and non-zero on
159   // failure.
160   ///
161   /*--cef()--*/
162   virtual int Seek(int64 offset, int whence) = 0;
163 
164   ///
165   // Return the current offset position.
166   ///
167   /*--cef()--*/
168   virtual int64 Tell() = 0;
169 
170   ///
171   // Flush the stream.
172   ///
173   /*--cef()--*/
174   virtual int Flush() = 0;
175 
176   ///
177   // Return true if this handler performs work like accessing the file system
178   // which may block. Used as a hint for determining the thread to access the
179   // handler from.
180   ///
181   /*--cef()--*/
182   virtual bool MayBlock() = 0;
183 };
184 
185 ///
186 // Class used to write data to a stream. The methods of this class may be called
187 // on any thread.
188 ///
189 /*--cef(source=library)--*/
190 class CefStreamWriter : public virtual CefBaseRefCounted {
191  public:
192   ///
193   // Create a new CefStreamWriter object for a file.
194   ///
195   /*--cef()--*/
196   static CefRefPtr<CefStreamWriter> CreateForFile(const CefString& fileName);
197   ///
198   // Create a new CefStreamWriter object for a custom handler.
199   ///
200   /*--cef()--*/
201   static CefRefPtr<CefStreamWriter> CreateForHandler(
202       CefRefPtr<CefWriteHandler> handler);
203 
204   ///
205   // Write raw binary data.
206   ///
207   /*--cef()--*/
208   virtual size_t Write(const void* ptr, size_t size, size_t n) = 0;
209 
210   ///
211   // Seek to the specified offset position. |whence| may be any one of
212   // SEEK_CUR, SEEK_END or SEEK_SET. Returns zero on success and non-zero on
213   // failure.
214   ///
215   /*--cef()--*/
216   virtual int Seek(int64 offset, int whence) = 0;
217 
218   ///
219   // Return the current offset position.
220   ///
221   /*--cef()--*/
222   virtual int64 Tell() = 0;
223 
224   ///
225   // Flush the stream.
226   ///
227   /*--cef()--*/
228   virtual int Flush() = 0;
229 
230   ///
231   // Returns true if this writer performs work like accessing the file system
232   // which may block. Used as a hint for determining the thread to access the
233   // writer from.
234   ///
235   /*--cef()--*/
236   virtual bool MayBlock() = 0;
237 };
238 
239 #endif  // CEF_INCLUDE_CEF_STREAM_H_
240