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_
13 #include <ppapi/c/pp_var.h>
15 #include "nacl_io/filesystem.h"
16 #include "nacl_io/node.h"
20 class MessagingInterface
;
21 class VarArrayBufferInterface
;
22 class VarArrayInterface
;
23 class VarDictionaryInterface
;
27 class JsFs
: public Filesystem
{
29 typedef uint32_t RequestId
;
34 virtual Error
Init(const FsInitArgs
& args
);
35 virtual void Destroy();
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
);
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
,
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
);
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_