Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / native_client_sdk / src / libraries / nacl_io / stream / stream_fs.h
blobd9f77c78e1df89bf3c1859d84233715fe837ddd1
1 // Copyright 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.
5 #ifndef LIBRARIES_NACL_IO_STREAM_STREAM_H_
6 #define LIBRARIES_NACL_IO_STREAM_STREAM_H_
8 #include "nacl_io/filesystem.h"
10 #include "ppapi/c/pp_completion_callback.h"
11 #include "ppapi/c/pp_resource.h"
13 namespace nacl_io {
15 // StreamFs provides a "mount point" for stream objects which do not provide a
16 // path, such as FDs returned by pipe, socket, and sockpair. It also provides
17 // a background thread for dispatching completion callbacks.
19 class StreamFs;
20 class StreamNode;
22 class StreamFs : public Filesystem {
23 public:
24 class Work {
25 public:
26 explicit Work(StreamFs* filesystem) : filesystem_(filesystem) {}
27 virtual ~Work() {}
29 // Called by adding work the queue, val should be safe to ignore.
30 virtual bool Start(int32_t val) = 0;
32 // Called as a completion of work in Start. Value of val depend on
33 // the function invoked in Start.
34 virtual void Run(int32_t val) = 0;
35 StreamFs* filesystem() { return filesystem_; }
37 private:
38 StreamFs* filesystem_;
41 protected:
42 StreamFs();
43 virtual ~StreamFs();
45 public:
46 // Enqueue a work object onto this StreamFs's thread
47 void EnqueueWork(Work* work);
49 // Returns a completion callback which will execute the StartWork member
50 // of a MountSocketWork object.
51 static PP_CompletionCallback GetStartCompletion(Work* work);
53 // Returns a completion callback which will execute the RunCallback member
54 // of a MountSocketWork object.
55 static PP_CompletionCallback GetRunCompletion(Work* work);
57 virtual Error OpenWithMode(const Path& path, int o_flags, mode_t mode,
58 ScopedNode* out_node);
59 virtual Error Unlink(const Path& path);
60 virtual Error Mkdir(const Path& path, int permissions);
61 virtual Error Rmdir(const Path& path);
62 virtual Error Remove(const Path& path);
63 virtual Error Rename(const Path& path, const Path& newpath);
65 static void* StreamThreadThunk(void*);
66 void StreamThread();
68 private:
69 PP_Resource message_loop_;
70 pthread_cond_t message_cond_;
71 sdk_util::SimpleLock message_lock_;
73 friend class KernelProxy;
74 DISALLOW_COPY_AND_ASSIGN(StreamFs);
77 } // namespace nacl_io
79 #endif // LIBRARIES_NACL_IO_STREAM_STREAM_H_