Home | History | Annotate | Download | only in jsfs
      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.
      4 
      5 #ifndef LIBRARIES_NACL_IO_JSFS_JS_FS_H_
      6 #define LIBRARIES_NACL_IO_JSFS_JS_FS_H_
      7 
      8 #include <pthread.h>
      9 #include <stdarg.h>
     10 
     11 #include <map>
     12 
     13 #include <ppapi/c/pp_var.h>
     14 
     15 #include "nacl_io/filesystem.h"
     16 #include "nacl_io/node.h"
     17 
     18 namespace nacl_io {
     19 
     20 class MessagingInterface;
     21 class VarArrayBufferInterface;
     22 class VarArrayInterface;
     23 class VarDictionaryInterface;
     24 class VarInterface;
     25 class ScopedVar;
     26 
     27 class JsFs : public Filesystem {
     28  public:
     29   typedef uint32_t RequestId;
     30 
     31  protected:
     32   JsFs();
     33 
     34   virtual Error Init(const FsInitArgs& args);
     35   virtual void Destroy();
     36 
     37  public:
     38   virtual Error Access(const Path& path, int a_mode);
     39   virtual Error Open(const Path& path, int mode, 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);
     46 
     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);
     53 
     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);
     62 
     63   int ScanVar(PP_Var var, const char* format, ...);
     64   int VScanVar(PP_Var var, const char* format, va_list args);
     65 
     66  private:
     67   MessagingInterface* messaging_iface_;
     68   VarArrayInterface* array_iface_;
     69   VarArrayBufferInterface* buffer_iface_;
     70   VarDictionaryInterface* dict_iface_;
     71   VarInterface* var_iface_;
     72 
     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_.
     78 
     79   friend class JsFsNode;
     80   DISALLOW_COPY_AND_ASSIGN(JsFs);
     81 };
     82 
     83 }  // namespace nacl_io
     84 
     85 #endif  // LIBRARIES_NACL_IO_JSFS_JS_FS_H_
     86