Debugger: Add dedicated functions for global {un}init.
[haiku.git] / src / apps / debugger / files / LocatableFile.cpp
blob38ebdc56e0e3e396f20622eaa65b8ee88fbd4a06
1 /*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
6 #include "LocatableFile.h"
8 #include <AutoLocker.h>
10 #include "LocatableDirectory.h"
13 // #pragma mark - LocatableFile
16 LocatableFile::LocatableFile(LocatableEntryOwner* owner,
17 LocatableDirectory* directory, const BString& name)
19 LocatableEntry(owner, directory),
20 fName(name),
21 fLocatedPath(),
22 fListeners(8)
27 LocatableFile::~LocatableFile()
32 const char*
33 LocatableFile::Name() const
35 return fName.String();
39 void
40 LocatableFile::GetPath(BString& _path) const
42 fParent->GetPath(_path);
43 _path << '/' << fName;
47 bool
48 LocatableFile::GetLocatedPath(BString& _path) const
50 AutoLocker<LocatableEntryOwner> locker(fOwner);
52 if (fLocatedPath.Length() > 0) {
53 _path = fLocatedPath;
54 return true;
57 if (!fParent->GetLocatedPath(_path))
58 return false;
60 _path << '/' << fName;
61 return true;
65 void
66 LocatableFile::SetLocatedPath(const BString& path, bool implicit)
68 // called with owner already locked
70 if (implicit) {
71 fLocatedPath = (const char*)NULL;
72 fState = LOCATABLE_ENTRY_LOCATED_IMPLICITLY;
73 } else {
74 fLocatedPath = path;
75 fState = LOCATABLE_ENTRY_LOCATED_EXPLICITLY;
78 _NotifyListeners();
82 bool
83 LocatableFile::AddListener(Listener* listener)
85 AutoLocker<LocatableEntryOwner> locker(fOwner);
86 return fListeners.AddItem(listener);
90 void
91 LocatableFile::RemoveListener(Listener* listener)
93 AutoLocker<LocatableEntryOwner> locker(fOwner);
94 fListeners.RemoveItem(listener);
98 void
99 LocatableFile::_NotifyListeners()
101 for (int32 i = fListeners.CountItems() - 1; i >= 0; i--)
102 fListeners.ItemAt(i)->LocatableFileChanged(this);
106 // #pragma mark - Listener
109 LocatableFile::Listener::~Listener()