- add sources.
[platform/framework/web/crosswalk.git] / src / native_client_sdk / src / libraries / nacl_io / mount_stream.h
1 // Copyright (c) 2013 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_MOUNT_STREAM_H_
6 #define LIBRARIES_NACL_IO_MOUNT_STREAM_H_
7
8 #include "nacl_io/mount.h"
9
10 #include "ppapi/c/pp_completion_callback.h"
11 #include "ppapi/c/pp_resource.h"
12
13
14 namespace nacl_io {
15
16 // MountStreams provides a "mount point" for stream objects which do not
17 // provide a path, such as FDs returned by pipe, socket, and sockpair.  It
18 // also provides a background thread for dispatching completion callbacks.
19
20 class MountStream;
21 class MountNodeStream;
22
23 class MountStream : public Mount {
24  public:
25   class Work {
26    public:
27     explicit Work(MountStream* mount) : mount_(mount) {}
28     virtual ~Work() {}
29
30     // Called by adding work the queue, val should be safe to ignore.
31     virtual bool Start(int32_t val) = 0;
32
33     // Called as a completion of work in Start.  Value of val depend on
34     // the function invoked in Start.
35     virtual void Run(int32_t val) = 0;
36     MountStream* mount() { return mount_; }
37
38   private:
39     MountStream* mount_;
40   };
41
42  protected:
43   MountStream();
44   virtual ~MountStream();
45
46  public:
47   // Enqueue a work object onto this MountStream's thread
48   void EnqueueWork(Work* work);
49
50   // Returns a completion callback which will execute the StartWork member
51   // of a MountSocketWork object.
52   static PP_CompletionCallback GetStartCompletion(Work* work);
53
54   // Returns a completion callback which will execute the RunCallback member
55   // of a MountSocketWork object.
56   static PP_CompletionCallback GetRunCompletion(Work* work);
57
58   virtual Error Access(const Path& path, int a_mode);
59   virtual Error Open(const Path& path,
60                      int o_flags,
61                      ScopedMountNode* out_node);
62   virtual Error Unlink(const Path& path);
63   virtual Error Mkdir(const Path& path, int permissions);
64   virtual Error Rmdir(const Path& path);
65   virtual Error Remove(const Path& path);
66
67   static void* StreamThreadThunk(void*);
68   void StreamThread();
69
70  private:
71   PP_Resource message_loop_;
72   pthread_cond_t message_cond_;
73   sdk_util::SimpleLock message_lock_;
74
75   friend class KernelProxy;
76   DISALLOW_COPY_AND_ASSIGN(MountStream);
77 };
78
79 }  // namespace nacl_io
80
81 #endif  // LIBRARIES_NACL_IO_MOUNT_STREAM_H_