2 * Copyright 2010, Haiku.
3 * Distributed under the terms of the MIT License.
6 * Clemens Zeidler <haiku@clemens-zeidler.de>
9 #include "IndexServerAddOn.h"
12 #include <Directory.h>
16 #include "IndexServerPrivate.h"
19 analyser_settings::analyser_settings()
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
)
49 AnalyserSettings::ReadSettings()
51 BAutolock
_(fSettingsLock
);
54 fVolume
.GetRootDirectory(&rootDir
);
56 path
.Append(kIndexServerDirectory
);
58 path
.Append(kAnalyserStatusFile
);
60 BFile
file(path
.Path(), B_READ_ONLY
);
61 if (file
.InitCheck() != B_OK
)
65 file
.ReadAttr(kCatchUpEnabledAttr
, B_UINT32_TYPE
, 0, &value
,
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
));
80 AnalyserSettings::WriteSettings()
82 BAutolock
_(fSettingsLock
);
85 fVolume
.GetRootDirectory(&rootDir
);
87 path
.Append(kIndexServerDirectory
);
89 if (create_directory(path
.Path(), 777) != B_OK
)
91 path
.Append(kAnalyserStatusFile
);
93 BFile
file(path
.Path(), B_READ_WRITE
| B_CREATE_FILE
| B_ERASE_FILE
);
94 if (file
.InitCheck() != B_OK
)
97 uint32 value
= fAnalyserSettings
.catchUpEnabled
? 1 : 0;
98 file
.WriteAttr(kCatchUpEnabledAttr
, B_UINT32_TYPE
, 0, &value
,
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
));
112 AnalyserSettings::RawSettings()
114 BAutolock
_(fSettingsLock
);
116 return fAnalyserSettings
;
121 AnalyserSettings::SetCatchUpEnabled(bool enabled
)
123 BAutolock
_(fSettingsLock
);
125 fAnalyserSettings
.catchUpEnabled
= enabled
;
130 AnalyserSettings::SetSyncPosition(bigtime_t time
)
132 BAutolock
_(fSettingsLock
);
134 fAnalyserSettings
.syncPosition
= time
;
139 AnalyserSettings::SetWatchingStart(bigtime_t time
)
141 BAutolock
_(fSettingsLock
);
143 fAnalyserSettings
.watchingStart
= time
;
148 AnalyserSettings::SetWatchingPosition(bigtime_t time
)
150 BAutolock
_(fSettingsLock
);
152 fAnalyserSettings
.watchingPosition
= time
;
157 AnalyserSettings::CatchUpEnabled()
159 BAutolock
_(fSettingsLock
);
161 return fAnalyserSettings
.catchUpEnabled
;
166 AnalyserSettings::SyncPosition()
168 BAutolock
_(fSettingsLock
);
170 return fAnalyserSettings
.syncPosition
;
175 AnalyserSettings::WatchingStart()
177 BAutolock
_(fSettingsLock
);
179 return fAnalyserSettings
.watchingStart
;
184 AnalyserSettings::WatchingPosition()
186 BAutolock
_(fSettingsLock
);
188 return fAnalyserSettings
.watchingPosition
;
192 FileAnalyser::FileAnalyser(const BString
& name
, const BVolume
& volume
)
202 FileAnalyser::SetSettings(AnalyserSettings
* settings
)
204 ASSERT(fName
== settings
->Name() && fVolume
== settings
->Volume());
206 fAnalyserSettings
= settings
;
207 ASSERT(fAnalyserSettings
.Get());
208 UpdateSettingsCache();
213 FileAnalyser::Settings() const
215 return fAnalyserSettings
;
219 const analyser_settings
&
220 FileAnalyser::CachedSettings() const
222 return fCachedSettings
;
227 FileAnalyser::UpdateSettingsCache()
229 fCachedSettings
= fAnalyserSettings
->RawSettings();