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.
5 #ifndef LIBRARIES_NACL_IO_MOUNT_STREAM_H_
6 #define LIBRARIES_NACL_IO_MOUNT_STREAM_H_
8 #include "nacl_io/mount.h"
10 #include "ppapi/c/pp_completion_callback.h"
11 #include "ppapi/c/pp_resource.h"
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.
21 class MountNodeStream;
23 class MountStream : public Mount {
27 explicit Work(MountStream* mount) : mount_(mount) {}
30 // Called by adding work the queue, val should be safe to ignore.
31 virtual bool Start(int32_t val) = 0;
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_; }
44 virtual ~MountStream();
47 // Enqueue a work object onto this MountStream's thread
48 void EnqueueWork(Work* work);
50 // Returns a completion callback which will execute the StartWork member
51 // of a MountSocketWork object.
52 static PP_CompletionCallback GetStartCompletion(Work* work);
54 // Returns a completion callback which will execute the RunCallback member
55 // of a MountSocketWork object.
56 static PP_CompletionCallback GetRunCompletion(Work* work);
58 virtual Error Access(const Path& path, int a_mode);
59 virtual Error Open(const Path& path,
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);
67 static void* StreamThreadThunk(void*);
71 PP_Resource message_loop_;
72 pthread_cond_t message_cond_;
73 sdk_util::SimpleLock message_lock_;
75 friend class KernelProxy;
76 DISALLOW_COPY_AND_ASSIGN(MountStream);
79 } // namespace nacl_io
81 #endif // LIBRARIES_NACL_IO_MOUNT_STREAM_H_