00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef _ADD_ON_MANAGER_H
00012 #define _ADD_ON_MANAGER_H
00013
00014 #ifndef _ENTRY_H
00015 #include <Entry.h>
00016 #endif
00017
00018 #ifndef _IMAGE_H
00019 #include <image.h>
00020 #endif
00021
00022 #ifndef _LIST_H
00023 #include <List.h>
00024 #endif
00025
00026 #ifndef _LOCKER_H
00027 #include <Locker.h>
00028 #endif
00029
00030 #ifndef _MESSAGE_H
00031 #include <Message.h>
00032 #endif
00033
00034 #ifndef _SEARCH_PATH_H
00035 #include <SearchPath.h>
00036 #endif
00037
00038 class BNode;
00039 namespace BPrivate {
00040 class AddOnSearchPath;
00041 }
00042
00043 enum {
00044 B_ADD_ONS_CHANGED = 'ADCG'
00045 };
00046
00047
00048 enum {
00049 B_FLUSH_KEEP_LOADED = (1<<0),
00050 B_FLUSH_DYNAMIC = (1<<1),
00051 B_FLUSH_REFERENCED = (1<<2)
00052 };
00053
00054 class BAddOnHandle {
00055 public:
00056
00057
00058
00059
00060 BAddOnHandle(const entry_ref* entry=NULL,
00061 const node_ref* node=NULL);
00062
00063
00064 int32 Acquire() const;
00065 int32 Release() const;
00066
00067
00068 status_t SetEntryRef(const entry_ref* ref);
00069 entry_ref EntryRef() const;
00070
00071 node_ref NodeRef() const;
00072
00073
00074
00075
00076 image_id Open();
00077 void Close();
00078 bool Flush(uint32 flags=0);
00079
00080
00081 bool IsLoaded() const;
00082
00083
00084
00085 bool IsStatic() const;
00086
00087
00088
00089
00090 virtual bool KeepLoaded() const;
00091
00092
00093
00094
00095
00096
00097 virtual bool IsDynamic() const;
00098
00099
00100
00101 virtual size_t GetMemoryUsage() const;
00102
00103
00104
00105
00106 status_t GetIdentifiers(BMessage* into, bool quick=false) const;
00107
00108
00109
00110 bool MatchIdentifier(const char* name, const char* value,
00111 bool quick=false) const;
00112
00113
00114 time_t SecondsSinceOpen() const;
00115
00116 protected:
00117 virtual ~BAddOnHandle();
00118
00119
00120
00121
00122
00123 virtual void ImageLoaded(image_id image);
00124
00125
00126
00127 virtual status_t LoadIdentifiers(BMessage* into, image_id from);
00128
00129
00130
00131
00132
00133 virtual void ImageUnloading(image_id image);
00134
00135
00136
00137 virtual const char* AttrBaseName() const;
00138
00139
00140
00141
00142 const BMessage* LockIdentifiers(bool quick=false) const;
00143 void UnlockIdentifiers(const BMessage* ident) const;
00144
00145
00146
00147 void Lock() const;
00148 void Unlock() const;
00149
00150 private:
00151
00152 virtual void _HoldTheAddOnHandle1();
00153 virtual void _HoldTheAddOnHandle2();
00154 virtual void _HoldTheAddOnHandle3();
00155 virtual void _HoldTheAddOnHandle4();
00156 virtual void _HoldTheAddOnHandle5();
00157 virtual void _HoldTheAddOnHandle6();
00158 virtual void _HoldTheAddOnHandle7();
00159 virtual void _HoldTheAddOnHandle8();
00160 virtual void _HoldTheAddOnHandle9();
00161 virtual void _HoldTheAddOnHandle10();
00162 virtual void _HoldTheAddOnHandle11();
00163 virtual void _HoldTheAddOnHandle12();
00164 virtual void _HoldTheAddOnHandle13();
00165 virtual void _HoldTheAddOnHandle14();
00166 virtual void _HoldTheAddOnHandle15();
00167 virtual void _HoldTheAddOnHandle16();
00168 uint32 _holdTheData[8];
00169
00170 image_id do_open();
00171 void do_close();
00172 bool do_flush(uint32 flags=0);
00173 status_t do_get_identifiers(BMessage* into, bool quick);
00174
00175 status_t do_read_identifiers(BMessage* into, BNode* from);
00176 status_t do_write_identifiers(BNode* into, const BMessage* from);
00177
00178 mutable int32 fAccess;
00179 mutable int32 fRefCount;
00180 node_ref fNode;
00181 entry_ref fEntry;
00182 image_id fImage;
00183 status_t fImageErr;
00184 int32 fUsers;
00185 time_t fLastUsed;
00186 bool fHasIdentifiers;
00187 bool fStaticImage;
00188
00189 BMessage fIdentifiers;
00190 };
00191
00192 class BAddOnManager {
00193 public:
00194 BAddOnManager(const char* name);
00195 virtual ~BAddOnManager();
00196
00197
00198 status_t AddDirectory(const BEntry* dir);
00199 status_t AddDirectory(const entry_ref* dir);
00200 status_t AddDirectory(const char* dir, const char* leaf=NULL);
00201 status_t AddDirectory(directory_which which, const char* leaf=NULL);
00202 status_t AddSearchPath(const char* path, const char* leaf=NULL);
00203 status_t AddEnvVar(const char* name, const char* leaf=NULL,
00204 const char* defEnvVal=NULL);
00205
00206
00207
00208 status_t Scan();
00209 bool IsScanned() const;
00210
00211
00212
00213 virtual status_t Run();
00214 bool IsRunning() const;
00215
00216 virtual void Shutdown(bool force_unload=false);
00217
00218
00219 status_t StartWatching(BMessenger receiver);
00220 status_t StopWatching(BMessenger receiver);
00221
00222
00223 BLocker* Locker() const;
00224
00225
00226 int32 CountAddOns() const;
00227 BAddOnHandle* AddOnAt(int32 i) const;
00228
00229 BAddOnHandle* FindAddOn(const node_ref* node) const;
00230
00231
00232 BAddOnHandle* InstallAddOn(const entry_ref* entry,
00233 const node_ref* node);
00234 virtual void InstallAddOn(BAddOnHandle* addon);
00235 virtual bool RemoveAddOn(BAddOnHandle* addon);
00236
00237
00238
00239
00240
00241 virtual size_t GetMemoryUsage() const;
00242
00243
00244
00245
00246 void UsingAddOn(int32 i);
00247
00248
00249
00250
00251
00252
00253
00254 ssize_t PruneAddOnMemory(ssize_t memory_needed=-1);
00255
00256
00257
00258
00259
00260
00261
00262
00263 int32 PruneAddOnTime(time_t min_seconds, int32 growth=100);
00264
00265 protected:
00266
00267 virtual BAddOnHandle* InstantiateHandle(const entry_ref* entry,
00268 const node_ref* node);
00269
00270 private:
00271
00272 virtual void _AmyTheAddOnManager1();
00273 virtual void _AmyTheAddOnManager2();
00274 virtual void _AmyTheAddOnManager3();
00275 virtual void _AmyTheAddOnManager4();
00276 virtual void _AmyTheAddOnManager5();
00277 virtual void _AmyTheAddOnManager6();
00278 virtual void _AmyTheAddOnManager7();
00279 virtual void _AmyTheAddOnManager8();
00280 virtual void _AmyTheAddOnManager9();
00281 virtual void _AmyTheAddOnManager10();
00282 virtual void _AmyTheAddOnManager11();
00283 virtual void _AmyTheAddOnManager12();
00284 virtual void _AmyTheAddOnManager13();
00285 virtual void _AmyTheAddOnManager14();
00286 virtual void _AmyTheAddOnManager15();
00287 virtual void _AmyTheAddOnManager16();
00288 uint32 _amyTheData[8];
00289
00290 friend class BPrivate::AddOnSearchPath;
00291
00292 void mark_changed(bool needWakeup=true);
00293 void send_notices();
00294
00295 mutable BLocker fLock;
00296
00297 BPrivate::AddOnSearchPath* fSearchPath;
00298 BList fAddOns;
00299 BList fWatchers;
00300 bool fScanned;
00301 bool fRunning;
00302 int32 fChanged;
00303 };
00304
00305 #endif