Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / native_client_sdk / src / libraries / nacl_io / jsfs / js_fs.h
blob08b1e4c182f805de7c0b49f66d63b3efcd09909d
1 // Copyright 2014 The Chromium 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.
5 #ifndef LIBRARIES_NACL_IO_JSFS_JS_FS_H_
6 #define LIBRARIES_NACL_IO_JSFS_JS_FS_H_
8 #include <pthread.h>
9 #include <stdarg.h>
11 #include <map>
13 #include <ppapi/c/pp_var.h>
15 #include "nacl_io/filesystem.h"
16 #include "nacl_io/node.h"
18 namespace nacl_io {
20 class MessagingInterface;
21 class VarArrayBufferInterface;
22 class VarArrayInterface;
23 class VarDictionaryInterface;
24 class VarInterface;
25 class ScopedVar;
27 class JsFs : public Filesystem {
28 public:
29 typedef uint32_t RequestId;
31 protected:
32 JsFs();
34 virtual Error Init(const FsInitArgs& args);
35 virtual void Destroy();
37 public:
38 virtual Error OpenWithMode(const Path& path, int open_flags, mode_t mode,
39 ScopedNode* out_node);
40 virtual Error Unlink(const Path& path);
41 virtual Error Mkdir(const Path& path, int perm);
42 virtual Error Rmdir(const Path& path);
43 virtual Error Remove(const Path& path);
44 virtual Error Rename(const Path& path, const Path& newpath);
45 virtual Error Filesystem_VIoctl(int request, va_list args);
47 private:
48 bool SetDictVar(PP_Var dict, const char* key, PP_Var value);
49 PP_Var GetDictVar(PP_Var dict, const char* key);
50 bool GetVarInt32(PP_Var var, int32_t* out_value);
51 bool GetVarUint32(PP_Var var, uint32_t* out_value);
52 bool GetVarInt64(PP_Var var, int64_t* out_value);
54 PP_Var VMakeRequest(RequestId request_id, const char* format, va_list args);
55 uint32_t VSendRequest(const char* format, va_list args);
56 bool VSendRequestAndWait(ScopedVar* out_response,
57 const char* format,
58 va_list args);
59 PP_Var WaitForResponse(uint32_t request_id);
60 bool SendRequestAndWait(ScopedVar* out_response, const char* format, ...);
61 Error ErrorFromResponse(const ScopedVar& response);
63 int ScanVar(PP_Var var, const char* format, ...);
64 int VScanVar(PP_Var var, const char* format, va_list args);
66 private:
67 MessagingInterface* messaging_iface_;
68 VarArrayInterface* array_iface_;
69 VarArrayBufferInterface* buffer_iface_;
70 VarDictionaryInterface* dict_iface_;
71 VarInterface* var_iface_;
73 typedef std::map<RequestId, PP_Var> ResponseMap_t;
74 sdk_util::SimpleLock lock_;
75 RequestId request_id_; // Protected by lock_;
76 pthread_cond_t response_cond_; // protected by lock_.
77 ResponseMap_t responses_; // protected by lock_.
79 friend class JsFsNode;
80 DISALLOW_COPY_AND_ASSIGN(JsFs);
83 } // namespace nacl_io
85 #endif // LIBRARIES_NACL_IO_JSFS_JS_FS_H_