tcp: Add APICall trace entry and move TRACEs into locked parts.
[haiku.git] / src / add-ons / index_server / IndexServerAddOn.cpp
blobe8968b94de2c075a1220b7514f911a48c338f928
1 /*
2 * Copyright 2010, Haiku.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Clemens Zeidler <haiku@clemens-zeidler.de>
7 */
9 #include "IndexServerAddOn.h"
11 #include <Debug.h>
12 #include <Directory.h>
13 #include <File.h>
14 #include <Path.h>
16 #include "IndexServerPrivate.h"
19 analyser_settings::analyser_settings()
21 catchUpEnabled(true),
23 syncPosition(0),
24 watchingStart(0),
25 watchingPosition(0)
31 const char* kAnalyserStatusFile = "AnalyserStatus";
33 const char* kCatchUpEnabledAttr = "CatchUpEnabled";
34 const char* kSyncPositionAttr = "SyncPosition";
35 const char* kWatchingStartAttr = "WatchingStart";
36 const char* kWatchingPositionAttr = "WatchingPosition";
39 AnalyserSettings::AnalyserSettings(const BString& name, const BVolume& volume)
41 fName(name),
42 fVolume(volume)
44 ReadSettings();
48 bool
49 AnalyserSettings::ReadSettings()
51 BAutolock _(fSettingsLock);
53 BDirectory rootDir;
54 fVolume.GetRootDirectory(&rootDir);
55 BPath path(&rootDir);
56 path.Append(kIndexServerDirectory);
57 path.Append(fName);
58 path.Append(kAnalyserStatusFile);
60 BFile file(path.Path(), B_READ_ONLY);
61 if (file.InitCheck() != B_OK)
62 return false;
64 uint32 value;
65 file.ReadAttr(kCatchUpEnabledAttr, B_UINT32_TYPE, 0, &value,
66 sizeof(uint32));
67 fAnalyserSettings.catchUpEnabled = value != 0 ? true : false;
68 file.ReadAttr(kSyncPositionAttr, B_INT64_TYPE, 0,
69 &fAnalyserSettings.syncPosition, sizeof(int64));
70 file.ReadAttr(kWatchingStartAttr, B_INT64_TYPE, 0,
71 &fAnalyserSettings.watchingStart, sizeof(int64));
72 file.ReadAttr(kWatchingPositionAttr, B_INT64_TYPE, 0,
73 &fAnalyserSettings.watchingPosition, sizeof(int64));
75 return true;
79 bool
80 AnalyserSettings::WriteSettings()
82 BAutolock _(fSettingsLock);
84 BDirectory rootDir;
85 fVolume.GetRootDirectory(&rootDir);
86 BPath path(&rootDir);
87 path.Append(kIndexServerDirectory);
88 path.Append(fName);
89 if (create_directory(path.Path(), 777) != B_OK)
90 return false;
91 path.Append(kAnalyserStatusFile);
93 BFile file(path.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
94 if (file.InitCheck() != B_OK)
95 return false;
97 uint32 value = fAnalyserSettings.catchUpEnabled ? 1 : 0;
98 file.WriteAttr(kCatchUpEnabledAttr, B_UINT32_TYPE, 0, &value,
99 sizeof(uint32));
100 file.WriteAttr(kSyncPositionAttr, B_INT64_TYPE, 0,
101 &fAnalyserSettings.syncPosition, sizeof(int64));
102 file.WriteAttr(kWatchingStartAttr, B_INT64_TYPE, 0,
103 &fAnalyserSettings.watchingStart, sizeof(int64));
104 file.WriteAttr(kWatchingPositionAttr, B_INT64_TYPE, 0,
105 &fAnalyserSettings.watchingPosition, sizeof(int64));
107 return true;
111 analyser_settings
112 AnalyserSettings::RawSettings()
114 BAutolock _(fSettingsLock);
116 return fAnalyserSettings;
120 void
121 AnalyserSettings::SetCatchUpEnabled(bool enabled)
123 BAutolock _(fSettingsLock);
125 fAnalyserSettings.catchUpEnabled = enabled;
129 void
130 AnalyserSettings::SetSyncPosition(bigtime_t time)
132 BAutolock _(fSettingsLock);
134 fAnalyserSettings.syncPosition = time;
138 void
139 AnalyserSettings::SetWatchingStart(bigtime_t time)
141 BAutolock _(fSettingsLock);
143 fAnalyserSettings.watchingStart = time;
147 void
148 AnalyserSettings::SetWatchingPosition(bigtime_t time)
150 BAutolock _(fSettingsLock);
152 fAnalyserSettings.watchingPosition = time;
156 bool
157 AnalyserSettings::CatchUpEnabled()
159 BAutolock _(fSettingsLock);
161 return fAnalyserSettings.catchUpEnabled;
165 bigtime_t
166 AnalyserSettings::SyncPosition()
168 BAutolock _(fSettingsLock);
170 return fAnalyserSettings.syncPosition;
174 bigtime_t
175 AnalyserSettings::WatchingStart()
177 BAutolock _(fSettingsLock);
179 return fAnalyserSettings.watchingStart;
183 bigtime_t
184 AnalyserSettings::WatchingPosition()
186 BAutolock _(fSettingsLock);
188 return fAnalyserSettings.watchingPosition;
192 FileAnalyser::FileAnalyser(const BString& name, const BVolume& volume)
194 fVolume(volume),
195 fName(name)
201 void
202 FileAnalyser::SetSettings(AnalyserSettings* settings)
204 ASSERT(fName == settings->Name() && fVolume == settings->Volume());
206 fAnalyserSettings = settings;
207 ASSERT(fAnalyserSettings.Get());
208 UpdateSettingsCache();
212 AnalyserSettings*
213 FileAnalyser::Settings() const
215 return fAnalyserSettings;
219 const analyser_settings&
220 FileAnalyser::CachedSettings() const
222 return fCachedSettings;
226 void
227 FileAnalyser::UpdateSettingsCache()
229 fCachedSettings = fAnalyserSettings->RawSettings();