| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef LIBRARIES_NACL_IO_KERNEL_OBJECT_H_ | 5 #ifndef LIBRARIES_NACL_IO_KERNEL_OBJECT_H_ |
| 6 #define LIBRARIES_NACL_IO_KERNEL_OBJECT_H_ | 6 #define LIBRARIES_NACL_IO_KERNEL_OBJECT_H_ |
| 7 | 7 |
| 8 #include <pthread.h> | 8 #include <pthread.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "nacl_io/error.h" | 14 #include "nacl_io/error.h" |
| 15 #include "nacl_io/event_emitter.h" |
| 15 #include "nacl_io/kernel_handle.h" | 16 #include "nacl_io/kernel_handle.h" |
| 16 #include "nacl_io/mount.h" | 17 #include "nacl_io/mount.h" |
| 17 #include "nacl_io/mount_node.h" | 18 #include "nacl_io/mount_node.h" |
| 18 #include "nacl_io/path.h" | 19 #include "nacl_io/path.h" |
| 19 | 20 |
| 20 #include "sdk_util/simple_lock.h" | 21 #include "sdk_util/simple_lock.h" |
| 21 | 22 |
| 22 namespace nacl_io { | 23 namespace nacl_io { |
| 23 | 24 |
| 24 // KernelObject provides basic functionality for threadsafe access to kernel | 25 // KernelObject provides basic functionality for threadsafe access to kernel |
| 25 // objects such as the CWD, mount points, file descriptors and file handles. | 26 // objects such as the CWD, mount points, file descriptors and file handles. |
| 26 // All Kernel locks are private to ensure the lock order. | 27 // All Kernel locks are private to ensure the lock order. |
| 27 // | 28 // |
| 28 // All calls are assumed to be a relative path. | 29 // All calls are assumed to be a relative path. |
| 29 class KernelObject { | 30 class KernelObject : public EventEmitter { |
| 30 public: | 31 public: |
| 31 typedef std::vector<ScopedKernelHandle> HandleMap_t; | 32 typedef std::vector<ScopedKernelHandle> HandleMap_t; |
| 32 typedef std::map<std::string, ScopedMount> MountMap_t; | 33 typedef std::map<std::string, ScopedMount> MountMap_t; |
| 33 | 34 |
| 34 KernelObject(); | 35 KernelObject(); |
| 35 virtual ~KernelObject(); | 36 virtual ~KernelObject(); |
| 36 | 37 |
| 37 // Attach the given Mount object at the specified path. | 38 // Attach the given Mount object at the specified path. |
| 38 Error AttachMountAtPath(const ScopedMount& mnt, const std::string& path); | 39 Error AttachMountAtPath(const ScopedMount& mnt, const std::string& path); |
| 39 | 40 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 68 void FreeAndReassignFD(int fd, const ScopedKernelHandle& handle); | 69 void FreeAndReassignFD(int fd, const ScopedKernelHandle& handle); |
| 69 void FreeFD(int fd); | 70 void FreeFD(int fd); |
| 70 | 71 |
| 71 // Returns or sets CWD | 72 // Returns or sets CWD |
| 72 std::string GetCWD(); | 73 std::string GetCWD(); |
| 73 Error SetCWD(const std::string& path); | 74 Error SetCWD(const std::string& path); |
| 74 | 75 |
| 75 // Returns parts of the absolute path for the given relative path | 76 // Returns parts of the absolute path for the given relative path |
| 76 Path GetAbsParts(const std::string& path); | 77 Path GetAbsParts(const std::string& path); |
| 77 | 78 |
| 79 // From EventEmitter. The KernelObject emitters events in order |
| 80 // to inturrupt anything waiting in select()/poll() when kill() |
| 81 // is called. It has no readable or wriable state and also no |
| 82 // meaningful type. |
| 83 uint32_t GetEventStatus() { return 0; } |
| 84 int GetType() { |
| 85 // For lack of a better type, report socket to signify it can be in an |
| 86 // used to signal. |
| 87 return S_IFSOCK; |
| 88 } |
| 78 private: | 89 private: |
| 79 std::string cwd_; | 90 std::string cwd_; |
| 80 std::vector<int> free_fds_; | 91 std::vector<int> free_fds_; |
| 81 HandleMap_t handle_map_; | 92 HandleMap_t handle_map_; |
| 82 MountMap_t mounts_; | 93 MountMap_t mounts_; |
| 83 | 94 |
| 84 // Lock to protect free_fds_ and handle_map_. | 95 // Lock to protect free_fds_ and handle_map_. |
| 85 sdk_util::SimpleLock handle_lock_; | 96 sdk_util::SimpleLock handle_lock_; |
| 86 | 97 |
| 87 // Lock to protect handle_map_. | 98 // Lock to protect handle_map_. |
| 88 sdk_util::SimpleLock mount_lock_; | 99 sdk_util::SimpleLock mount_lock_; |
| 89 | 100 |
| 90 // Lock to protect cwd_. | 101 // Lock to protect cwd_. |
| 91 sdk_util::SimpleLock cwd_lock_; | 102 sdk_util::SimpleLock cwd_lock_; |
| 92 | 103 |
| 93 DISALLOW_COPY_AND_ASSIGN(KernelObject); | 104 DISALLOW_COPY_AND_ASSIGN(KernelObject); |
| 94 }; | 105 }; |
| 95 | 106 |
| 107 typedef sdk_util::ScopedRef<KernelObject> ScopedKernelObject; |
| 108 |
| 109 |
| 96 } // namespace nacl_io | 110 } // namespace nacl_io |
| 97 | 111 |
| 98 #endif // LIBRARIES_NACL_IO_KERNEL_OBJECT_H_ | 112 #endif // LIBRARIES_NACL_IO_KERNEL_OBJECT_H_ |
| OLD | NEW |