Custody.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #pragma once
  2. #include <AK/String.h>
  3. #include <AK/Badge.h>
  4. #include <AK/InlineLinkedList.h>
  5. #include <AK/RefCounted.h>
  6. #include <AK/RefPtr.h>
  7. class Inode;
  8. class VFS;
  9. // FIXME: Custody needs some locking.
  10. class Custody : public RefCounted<Custody>
  11. , public InlineLinkedListNode<Custody> {
  12. public:
  13. static Custody* get_if_cached(Custody* parent, const StringView& name);
  14. static NonnullRefPtr<Custody> get_or_create(Custody* parent, const StringView& name, Inode&);
  15. static NonnullRefPtr<Custody> create(Custody* parent, const StringView& name, Inode& inode)
  16. {
  17. return adopt(*new Custody(parent, name, inode));
  18. }
  19. ~Custody();
  20. Custody* parent() { return m_parent.ptr(); }
  21. const Custody* parent() const { return m_parent.ptr(); }
  22. Inode& inode() { return *m_inode; }
  23. const Inode& inode() const { return *m_inode; }
  24. const String& name() const { return m_name; }
  25. String absolute_path() const;
  26. bool is_deleted() const { return m_deleted; }
  27. bool is_mounted_on() const { return m_mounted_on; }
  28. void did_delete(Badge<VFS>);
  29. void did_mount_on(Badge<VFS>);
  30. void did_rename(Badge<VFS>, const String& name);
  31. // For InlineLinkedListNode.
  32. Custody* m_next { nullptr };
  33. Custody* m_prev { nullptr };
  34. private:
  35. Custody(Custody* parent, const StringView& name, Inode&);
  36. RefPtr<Custody> m_parent;
  37. String m_name;
  38. NonnullRefPtr<Inode> m_inode;
  39. bool m_deleted { false };
  40. bool m_mounted_on { false };
  41. };