1 /* 2 * Copyright 2006, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Author: 6 * Axel Dörfler, axeld@pinc-software.de 7 */ 8 #ifndef TRANSLATOR_ROSTER_PRIVATE_H 9 #define TRANSLATOR_ROSTER_PRIVATE_H 10 11 12 #include <Entry.h> 13 #include <Handler.h> 14 #include <Locker.h> 15 #include <Messenger.h> 16 #include <TranslatorRoster.h> 17 18 #include <map> 19 #include <set> 20 #include <vector> 21 22 struct translator_data; 23 24 25 struct translator_item { 26 BTranslator* translator; 27 entry_ref ref; 28 ino_t node; 29 image_id image; 30 }; 31 32 typedef std::map<translator_id, translator_item> TranslatorMap; 33 typedef std::vector<BMessenger> MessengerList; 34 typedef std::vector<node_ref> NodeRefList; 35 typedef std::set<entry_ref> EntryRefSet; 36 37 class BTranslatorRoster::Private : public BHandler, public BLocker { 38 public: 39 Private(); 40 virtual ~Private(); 41 42 virtual void MessageReceived(BMessage* message); 43 44 void AddDefaultPaths(); 45 status_t AddPaths(const char* paths); 46 status_t AddPath(const char* path, int32* _added = NULL); 47 status_t AddTranslator(BTranslator* translator, image_id image = -1, 48 const entry_ref* ref = NULL, ino_t node = 0); 49 50 void RemoveTranslators(entry_ref& ref); 51 52 BTranslator* FindTranslator(translator_id id); 53 54 status_t StoreTranslators(BMessage& archive); 55 status_t Identify(BPositionIO* source, BMessage* ioExtension, 56 uint32 hintType, const char* hintMIME, uint32 wantType, 57 translator_info* _info); 58 59 status_t GetTranslators(BPositionIO* source, BMessage* ioExtension, 60 uint32 hintType, const char* hintMIME, uint32 wantType, 61 translator_info** _info, int32* _numInfo); 62 status_t GetAllTranslators(translator_id** _ids, int32* _count); 63 status_t GetRefFor(translator_id id, entry_ref& ref); 64 65 bool IsActive() const { return Looper(); } 66 67 status_t CreateTranslators(const entry_ref& ref, int32& count, 68 BMessage* update = NULL); 69 status_t GetTranslatorData(image_id image, translator_data& data); 70 71 status_t StartWatching(BMessenger target); 72 status_t StopWatching(BMessenger target); 73 74 void TranslatorDeleted(translator_id id); 75 76 private: 77 static int _CompareSupport(const void* _a, const void* _b); 78 79 void _RescanChanged(); 80 81 const translation_format* _CheckHints(const translation_format* formats, 82 int32 formatsCount, uint32 hintType, const char* hintMIME); 83 84 const translator_item* _FindTranslator(translator_id id) const; 85 const translator_item* _FindTranslator(const char* name) const; 86 const translator_item* _FindTranslator(entry_ref& ref) const; 87 translator_item* _FindTranslator(node_ref& nodeRef); 88 89 int32 _CompareTranslatorDirectoryPriority(const entry_ref& a, 90 const entry_ref& b) const; 91 bool _IsKnownDirectory(const node_ref& nodeRef) const; 92 93 void _RemoveTranslators(const node_ref* nodeRef, const entry_ref* ref = NULL); 94 void _EntryAdded(const node_ref& nodeRef, const char* name); 95 void _EntryAdded(const entry_ref& ref); 96 void _NotifyListeners(BMessage& update) const; 97 98 NodeRefList fDirectories; 99 TranslatorMap fTranslators; 100 MessengerList fMessengers; 101 EntryRefSet fRescanEntries; 102 int32 fNextID; 103 bool fLazyScanning; 104 bool fSafeMode; 105 }; 106 107 #endif // TRANSLATOR_ROSTER_PRIVATE_H 108