Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: base/platform_file.h

Issue 10392181: Implement serial API for Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: OSX/Win fixes and review feedback. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/platform_file_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_PLATFORM_FILE_H_ 5 #ifndef BASE_PLATFORM_FILE_H_
6 #define BASE_PLATFORM_FILE_H_ 6 #define BASE_PLATFORM_FILE_H_
7 #pragma once 7 #pragma once
8 8
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #if defined(OS_WIN) 10 #if defined(OS_WIN)
(...skipping 14 matching lines...) Expand all
25 const PlatformFile kInvalidPlatformFileValue = INVALID_HANDLE_VALUE; 25 const PlatformFile kInvalidPlatformFileValue = INVALID_HANDLE_VALUE;
26 #elif defined(OS_POSIX) 26 #elif defined(OS_POSIX)
27 typedef int PlatformFile; 27 typedef int PlatformFile;
28 const PlatformFile kInvalidPlatformFileValue = -1; 28 const PlatformFile kInvalidPlatformFileValue = -1;
29 #endif 29 #endif
30 30
31 // PLATFORM_FILE_(OPEN|CREATE).* are mutually exclusive. You should specify 31 // PLATFORM_FILE_(OPEN|CREATE).* are mutually exclusive. You should specify
32 // exactly one of the five (possibly combining with other flags) when opening 32 // exactly one of the five (possibly combining with other flags) when opening
33 // or creating a file. 33 // or creating a file.
34 enum PlatformFileFlags { 34 enum PlatformFileFlags {
35 PLATFORM_FILE_OPEN = 1, // Opens a file, only if it exists. 35 PLATFORM_FILE_OPEN = 1 << 0, // Opens a file, only if it exists.
36 PLATFORM_FILE_CREATE = 2, // Creates a new file, only if it does not 36 PLATFORM_FILE_CREATE = 1 << 1, // Creates a new file, only if it
37 // already exist. 37 // does not already exist.
38 PLATFORM_FILE_OPEN_ALWAYS = 4, // May create a new file. 38 PLATFORM_FILE_OPEN_ALWAYS = 1 << 2, // May create a new file.
39 PLATFORM_FILE_CREATE_ALWAYS = 8, // May overwrite an old file. 39 PLATFORM_FILE_CREATE_ALWAYS = 1 << 3, // May overwrite an old file.
40 PLATFORM_FILE_OPEN_TRUNCATED = 16, // Opens a file and truncates it, only if 40 PLATFORM_FILE_OPEN_TRUNCATED = 1 << 4, // Opens a file and truncates it,
41 // it exists. 41 // only if it exists.
42 PLATFORM_FILE_READ = 32, 42 PLATFORM_FILE_READ = 1 << 5,
43 PLATFORM_FILE_WRITE = 64, 43 PLATFORM_FILE_WRITE = 1 << 6,
44 PLATFORM_FILE_EXCLUSIVE_READ = 128, // EXCLUSIVE is opposite of Windows SHARE 44 PLATFORM_FILE_EXCLUSIVE_READ = 1 << 7, // EXCLUSIVE is opposite of Windows
45 PLATFORM_FILE_EXCLUSIVE_WRITE = 256, 45 // SHARE
46 PLATFORM_FILE_ASYNC = 512, 46 PLATFORM_FILE_EXCLUSIVE_WRITE = 1 << 8,
47 PLATFORM_FILE_TEMPORARY = 1024, // Used on Windows only 47 PLATFORM_FILE_ASYNC = 1 << 9,
48 PLATFORM_FILE_HIDDEN = 2048, // Used on Windows only 48 PLATFORM_FILE_TEMPORARY = 1 << 10, // Used on Windows only
49 PLATFORM_FILE_DELETE_ON_CLOSE = 4096, 49 PLATFORM_FILE_HIDDEN = 1 << 11, // Used on Windows only
50 PLATFORM_FILE_DELETE_ON_CLOSE = 1 << 12,
50 51
51 PLATFORM_FILE_WRITE_ATTRIBUTES = 8192, // Used on Windows only 52 PLATFORM_FILE_WRITE_ATTRIBUTES = 1 << 13, // Used on Windows only
52 PLATFORM_FILE_ENUMERATE = 16384, // May enumerate directory 53 PLATFORM_FILE_ENUMERATE = 1 << 14, // May enumerate directory
53 54
54 PLATFORM_FILE_SHARE_DELETE = 32768, // Used on Windows only 55 PLATFORM_FILE_SHARE_DELETE = 1 << 15, // Used on Windows only
56
57 PLATFORM_FILE_TERMINAL_DEVICE = 1 << 16, // Serial port flags
55 }; 58 };
56 59
57 // PLATFORM_FILE_ERROR_ACCESS_DENIED is returned when a call fails because of 60 // PLATFORM_FILE_ERROR_ACCESS_DENIED is returned when a call fails because of
58 // a filesystem restriction. PLATFORM_FILE_ERROR_SECURITY is returned when a 61 // a filesystem restriction. PLATFORM_FILE_ERROR_SECURITY is returned when a
59 // browser policy doesn't allow the operation to be executed. 62 // browser policy doesn't allow the operation to be executed.
60 enum PlatformFileError { 63 enum PlatformFileError {
61 PLATFORM_FILE_OK = 0, 64 PLATFORM_FILE_OK = 0,
62 PLATFORM_FILE_ERROR_FAILED = -1, 65 PLATFORM_FILE_ERROR_FAILED = -1,
63 PLATFORM_FILE_ERROR_IN_USE = -2, 66 PLATFORM_FILE_ERROR_IN_USE = -2,
64 PLATFORM_FILE_ERROR_EXISTS = -3, 67 PLATFORM_FILE_ERROR_EXISTS = -3,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 BASE_EXPORT bool ClosePlatformFile(PlatformFile file); 120 BASE_EXPORT bool ClosePlatformFile(PlatformFile file);
118 121
119 // Reads the given number of bytes (or until EOF is reached) starting with the 122 // Reads the given number of bytes (or until EOF is reached) starting with the
120 // given offset. Returns the number of bytes read, or -1 on error. Note that 123 // given offset. Returns the number of bytes read, or -1 on error. Note that
121 // this function makes a best effort to read all data on all platforms, so it is 124 // this function makes a best effort to read all data on all platforms, so it is
122 // not intended for stream oriented files but instead for cases when the normal 125 // not intended for stream oriented files but instead for cases when the normal
123 // expectation is that actually |size| bytes are read unless there is an error. 126 // expectation is that actually |size| bytes are read unless there is an error.
124 BASE_EXPORT int ReadPlatformFile(PlatformFile file, int64 offset, 127 BASE_EXPORT int ReadPlatformFile(PlatformFile file, int64 offset,
125 char* data, int size); 128 char* data, int size);
126 129
130 // Same as above but without seek.
131 BASE_EXPORT int ReadPlatformFileTerminalDevice(PlatformFile file,
darin (slow to review) 2012/05/29 19:04:33 nit: since the point of this function is to read w
132 char* data, int size);
133
127 // Reads the given number of bytes (or until EOF is reached) starting with the 134 // Reads the given number of bytes (or until EOF is reached) starting with the
128 // given offset, but does not make any effort to read all data on all platforms. 135 // given offset, but does not make any effort to read all data on all platforms.
129 // Returns the number of bytes read, or -1 on error. 136 // Returns the number of bytes read, or -1 on error.
130 BASE_EXPORT int ReadPlatformFileNoBestEffort(PlatformFile file, int64 offset, 137 BASE_EXPORT int ReadPlatformFileNoBestEffort(PlatformFile file, int64 offset,
131 char* data, int size); 138 char* data, int size);
132 139
133 // Writes the given buffer into the file at the given offset, overwritting any 140 // Writes the given buffer into the file at the given offset, overwritting any
134 // data that was previously there. Returns the number of bytes written, or -1 141 // data that was previously there. Returns the number of bytes written, or -1
135 // on error. Note that this function makes a best effort to write all data on 142 // on error. Note that this function makes a best effort to write all data on
136 // all platforms. 143 // all platforms.
137 BASE_EXPORT int WritePlatformFile(PlatformFile file, int64 offset, 144 BASE_EXPORT int WritePlatformFile(PlatformFile file, int64 offset,
138 const char* data, int size); 145 const char* data, int size);
139 146
147 // Save as above but without seek.
148 BASE_EXPORT int WritePlatformFileTerminalDevice(PlatformFile file,
149 const char* data, int size);
150
140 // Truncates the given file to the given length. If |length| is greater than 151 // Truncates the given file to the given length. If |length| is greater than
141 // the current size of the file, the file is extended with zeros. If the file 152 // the current size of the file, the file is extended with zeros. If the file
142 // doesn't exist, |false| is returned. 153 // doesn't exist, |false| is returned.
143 BASE_EXPORT bool TruncatePlatformFile(PlatformFile file, int64 length); 154 BASE_EXPORT bool TruncatePlatformFile(PlatformFile file, int64 length);
144 155
145 // Flushes the buffers of the given file. 156 // Flushes the buffers of the given file.
146 BASE_EXPORT bool FlushPlatformFile(PlatformFile file); 157 BASE_EXPORT bool FlushPlatformFile(PlatformFile file);
147 158
148 // Touches the given file. 159 // Touches the given file.
149 BASE_EXPORT bool TouchPlatformFile(PlatformFile file, 160 BASE_EXPORT bool TouchPlatformFile(PlatformFile file,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 return temp; 198 return temp;
188 } 199 }
189 200
190 private: 201 private:
191 PlatformFile* value_; 202 PlatformFile* value_;
192 }; 203 };
193 204
194 } // namespace base 205 } // namespace base
195 206
196 #endif // BASE_PLATFORM_FILE_H_ 207 #endif // BASE_PLATFORM_FILE_H_
OLDNEW
« no previous file with comments | « no previous file | base/platform_file_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698