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

Side by Side Diff: native_client_sdk/src/libraries/nacl_mounts/mount_dev.cc

Issue 12166002: Cleanup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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
OLDNEW
1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 #if defined(WIN32) 5 #if defined(WIN32)
6 #define _CRT_RAND_S 6 #define _CRT_RAND_S
7 #endif 7 #endif
8 8
9 #include <errno.h> 9 #include <errno.h>
10 #include <fcntl.h> 10 #include <fcntl.h>
(...skipping 13 matching lines...) Expand all
24 namespace { 24 namespace {
25 25
26 void ReleaseAndNullNode(MountNode** node) { 26 void ReleaseAndNullNode(MountNode** node) {
27 if (*node) 27 if (*node)
28 (*node)->Release(); 28 (*node)->Release();
29 *node = NULL; 29 *node = NULL;
30 } 30 }
31 31
32 class NullNode : public MountNode { 32 class NullNode : public MountNode {
33 public: 33 public:
34 NullNode(Mount* mount, int ino, int dev); 34 NullNode(Mount* mount);
binji 2013/02/02 00:04:44 explicit
noelallen1 2013/02/04 18:40:06 Done.
35 35
36 virtual int Read(size_t offs, void* buf, size_t count); 36 virtual int Read(size_t offs, void* buf, size_t count);
37 virtual int Write(size_t offs, const void* buf, size_t count); 37 virtual int Write(size_t offs, const void* buf, size_t count);
38 }; 38 };
39 39
40 class ConsoleNode : public NullNode { 40 class ConsoleNode : public NullNode {
41 public: 41 public:
42 ConsoleNode(Mount* mount, int ino, int dev, PP_LogLevel level); 42 ConsoleNode(Mount* mount, PP_LogLevel level);
43 43
44 virtual int Write(size_t offs, const void* buf, size_t count); 44 virtual int Write(size_t offs, const void* buf, size_t count);
45 45
46 private: 46 private:
47 PP_LogLevel level_; 47 PP_LogLevel level_;
48 }; 48 };
49 49
50 50
51 class TtyNode : public NullNode { 51 class TtyNode : public NullNode {
52 public: 52 public:
53 TtyNode(Mount* mount, int ino, int dev); 53 TtyNode(Mount* mount);
54 54
55 virtual int Write(size_t offs, const void* buf, size_t count); 55 virtual int Write(size_t offs, const void* buf, size_t count);
56 }; 56 };
57 57
58 58
59 class ZeroNode : public MountNode { 59 class ZeroNode : public MountNode {
60 public: 60 public:
61 ZeroNode(Mount* mount, int ino, int dev); 61 ZeroNode(Mount* mount);
62 62
63 virtual int Read(size_t offs, void* buf, size_t count); 63 virtual int Read(size_t offs, void* buf, size_t count);
64 virtual int Write(size_t offs, const void* buf, size_t count); 64 virtual int Write(size_t offs, const void* buf, size_t count);
65 }; 65 };
66 66
67 class UrandomNode : public MountNode { 67 class UrandomNode : public MountNode {
68 public: 68 public:
69 UrandomNode(Mount* mount, int ino, int dev); 69 UrandomNode(Mount* mount);
70 70
71 virtual int Read(size_t offs, void* buf, size_t count); 71 virtual int Read(size_t offs, void* buf, size_t count);
72 virtual int Write(size_t offs, const void* buf, size_t count); 72 virtual int Write(size_t offs, const void* buf, size_t count);
73 73
74 private: 74 private:
75 #if defined(__native_client__) 75 #if defined(__native_client__)
76 nacl_irt_random random_interface_; 76 nacl_irt_random random_interface_;
77 bool interface_ok_; 77 bool interface_ok_;
78 #endif 78 #endif
79 }; 79 };
80 80
81 NullNode::NullNode(Mount* mount, int ino, int dev) 81 NullNode::NullNode(Mount* mount)
82 : MountNode(mount, ino, dev) { 82 : MountNode(mount) {
83 stat_.st_mode = S_IFCHR;
83 } 84 }
84 85
85 int NullNode::Read(size_t offs, void* buf, size_t count) { 86 int NullNode::Read(size_t offs, void* buf, size_t count) {
86 return 0; 87 return 0;
87 } 88 }
88 89
89 int NullNode::Write(size_t offs, const void* buf, size_t count) { 90 int NullNode::Write(size_t offs, const void* buf, size_t count) {
90 return count; 91 return count;
91 } 92 }
92 93
93 ConsoleNode::ConsoleNode(Mount* mount, int ino, int dev, PP_LogLevel level) 94 ConsoleNode::ConsoleNode(Mount* mount, PP_LogLevel level)
94 : NullNode(mount, ino, dev), 95 : NullNode(mount),
95 level_(level) { 96 level_(level) {
97 stat_.st_mode = S_IFCHR;
96 } 98 }
97 99
98 int ConsoleNode::Write(size_t offs, const void* buf, size_t count) { 100 int ConsoleNode::Write(size_t offs, const void* buf, size_t count) {
99 ConsoleInterface* con_intr = mount_->ppapi()->GetConsoleInterface(); 101 ConsoleInterface* con_intr = mount_->ppapi()->GetConsoleInterface();
100 VarInterface* var_intr = mount_->ppapi()->GetVarInterface(); 102 VarInterface* var_intr = mount_->ppapi()->GetVarInterface();
101 103
102 if (var_intr && con_intr) { 104 if (var_intr && con_intr) {
103 const char* data = static_cast<const char *>(buf); 105 const char* data = static_cast<const char *>(buf);
104 uint32_t len = static_cast<uint32_t>(count); 106 uint32_t len = static_cast<uint32_t>(count);
105 struct PP_Var val = var_intr->VarFromUtf8(data, len); 107 struct PP_Var val = var_intr->VarFromUtf8(data, len);
106 con_intr->Log(mount_->ppapi()->GetInstance(), level_, val); 108 con_intr->Log(mount_->ppapi()->GetInstance(), level_, val);
107 return count; 109 return count;
108 } 110 }
109 return 0; 111 return 0;
110 } 112 }
111 113
112 114
113 TtyNode::TtyNode(Mount* mount, int ino, int dev) 115 TtyNode::TtyNode(Mount* mount)
114 : NullNode(mount, ino, dev) { 116 : NullNode(mount) {
115 } 117 }
116 118
117 int TtyNode::Write(size_t offs, const void* buf, size_t count) { 119 int TtyNode::Write(size_t offs, const void* buf, size_t count) {
118 MessagingInterface* msg_intr = mount_->ppapi()->GetMessagingInterface(); 120 MessagingInterface* msg_intr = mount_->ppapi()->GetMessagingInterface();
119 VarInterface* var_intr = mount_->ppapi()->GetVarInterface(); 121 VarInterface* var_intr = mount_->ppapi()->GetVarInterface();
120 122
121 if (var_intr && msg_intr) { 123 if (var_intr && msg_intr) {
122 const char* data = static_cast<const char *>(buf); 124 const char* data = static_cast<const char *>(buf);
123 uint32_t len = static_cast<uint32_t>(count); 125 uint32_t len = static_cast<uint32_t>(count);
124 struct PP_Var val = var_intr->VarFromUtf8(data, len); 126 struct PP_Var val = var_intr->VarFromUtf8(data, len);
125 msg_intr->PostMessage(mount_->ppapi()->GetInstance(), val); 127 msg_intr->PostMessage(mount_->ppapi()->GetInstance(), val);
126 return count; 128 return count;
127 } 129 }
128 return 0; 130 return 0;
129 } 131 }
130 132
131 133
132 ZeroNode::ZeroNode(Mount* mount, int ino, int dev) 134 ZeroNode::ZeroNode(Mount* mount)
133 : MountNode(mount, ino, dev) { 135 : MountNode(mount) {
136 stat_.st_mode = S_IFCHR;
134 } 137 }
135 138
136 int ZeroNode::Read(size_t offs, void* buf, size_t count) { 139 int ZeroNode::Read(size_t offs, void* buf, size_t count) {
137 memset(buf, 0, count); 140 memset(buf, 0, count);
138 return count; 141 return count;
139 } 142 }
140 143
141 int ZeroNode::Write(size_t offs, const void* buf, size_t count) { 144 int ZeroNode::Write(size_t offs, const void* buf, size_t count) {
142 return count; 145 return count;
143 } 146 }
144 147
145 UrandomNode::UrandomNode(Mount* mount, int ino, int dev) 148 UrandomNode::UrandomNode(Mount* mount)
146 : MountNode(mount, ino, dev) { 149 : MountNode(mount) {
150 stat_.st_mode = S_IFCHR;
147 #if defined(__native_client__) 151 #if defined(__native_client__)
148 size_t result = nacl_interface_query(NACL_IRT_RANDOM_v0_1, &random_interface_, 152 size_t result = nacl_interface_query(NACL_IRT_RANDOM_v0_1, &random_interface_,
149 sizeof(random_interface_)); 153 sizeof(random_interface_));
150 interface_ok_ = result != 0; 154 interface_ok_ = result != 0;
151 #endif 155 #endif
152 } 156 }
153 157
154 int UrandomNode::Read(size_t offs, void* buf, size_t count) { 158 int UrandomNode::Read(size_t offs, void* buf, size_t count) {
155 #if defined(__native_client__) 159 #if defined(__native_client__)
156 if (interface_ok_) { 160 if (interface_ok_) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 console1_node_(NULL), 240 console1_node_(NULL),
237 console2_node_(NULL), 241 console2_node_(NULL),
238 console3_node_(NULL), 242 console3_node_(NULL),
239 tty_node_(NULL) { 243 tty_node_(NULL) {
240 } 244 }
241 245
242 bool MountDev::Init(int dev, StringMap_t& args, PepperInterface* ppapi) { 246 bool MountDev::Init(int dev, StringMap_t& args, PepperInterface* ppapi) {
243 if (!Mount::Init(dev, args, ppapi)) 247 if (!Mount::Init(dev, args, ppapi))
244 return false; 248 return false;
245 249
246 root_ = new MountNodeDir(this, 1, dev_); 250 root_ = new MountNodeDir(this);
247 null_node_ = new NullNode(this, 2, dev_); 251 null_node_ = new NullNode(this);
248 root_->AddChild("/null", null_node_); 252 root_->AddChild("/null", null_node_);
249 zero_node_ = new ZeroNode(this, 3, dev_); 253 zero_node_ = new ZeroNode(this);
250 root_->AddChild("/zero", zero_node_); 254 root_->AddChild("/zero", zero_node_);
251 random_node_ = new UrandomNode(this, 4, dev_); 255 random_node_ = new UrandomNode(this);
252 root_->AddChild("/urandom", random_node_); 256 root_->AddChild("/urandom", random_node_);
253 257
254 console0_node_ = new ConsoleNode(this, 5, dev_, PP_LOGLEVEL_TIP); 258 console0_node_ = new ConsoleNode(this, PP_LOGLEVEL_TIP);
255 root_->AddChild("/console0", console0_node_); 259 root_->AddChild("/console0", console0_node_);
256 console1_node_ = new ConsoleNode(this, 6, dev_, PP_LOGLEVEL_LOG); 260 console1_node_ = new ConsoleNode(this, PP_LOGLEVEL_LOG);
257 root_->AddChild("/console1", console1_node_); 261 root_->AddChild("/console1", console1_node_);
258 console2_node_ = new ConsoleNode(this, 7, dev_, PP_LOGLEVEL_WARNING); 262 console2_node_ = new ConsoleNode(this, PP_LOGLEVEL_WARNING);
259 root_->AddChild("/console2", console2_node_); 263 root_->AddChild("/console2", console2_node_);
260 console3_node_ = new ConsoleNode(this, 8, dev_, PP_LOGLEVEL_ERROR); 264 console3_node_ = new ConsoleNode(this, PP_LOGLEVEL_ERROR);
261 root_->AddChild("/console3", console3_node_); 265 root_->AddChild("/console3", console3_node_);
262 266
263 tty_node_ = new TtyNode(this, 9, dev_); 267 tty_node_ = new TtyNode(this);
264 root_->AddChild("/tty", tty_node_); 268 root_->AddChild("/tty", tty_node_);
265 return true; 269 return true;
266 } 270 }
267 271
268 void MountDev::Destroy() { 272 void MountDev::Destroy() {
269 ReleaseAndNullNode(&tty_node_); 273 ReleaseAndNullNode(&tty_node_);
270 ReleaseAndNullNode(&console3_node_); 274 ReleaseAndNullNode(&console3_node_);
271 ReleaseAndNullNode(&console2_node_); 275 ReleaseAndNullNode(&console2_node_);
272 ReleaseAndNullNode(&console1_node_); 276 ReleaseAndNullNode(&console1_node_);
273 ReleaseAndNullNode(&console0_node_); 277 ReleaseAndNullNode(&console0_node_);
274 ReleaseAndNullNode(&random_node_); 278 ReleaseAndNullNode(&random_node_);
275 ReleaseAndNullNode(&zero_node_); 279 ReleaseAndNullNode(&zero_node_);
276 ReleaseAndNullNode(&null_node_); 280 ReleaseAndNullNode(&null_node_);
277 ReleaseAndNullNode(&root_); 281 ReleaseAndNullNode(&root_);
278 } 282 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698