xref: /haiku/src/kits/translation/TranslatorRosterPrivate.h (revision 2b76973fa2401f7a5edf68e6470f3d3210cbcff3)
1 /*
2  * Copyright 2006-2009, 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 #include <map>
12 #include <set>
13 #include <vector>
14 
15 #include <Entry.h>
16 #include <Handler.h>
17 #include <Locker.h>
18 #include <Messenger.h>
19 #include <TranslatorRoster.h>
20 
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 
38 class BTranslatorRoster::Private : public BHandler, public BLocker {
39 public:
40 								Private();
41 	virtual						~Private();
42 
43 	virtual	void				MessageReceived(BMessage* message);
44 
45 			void				AddDefaultPaths();
46 			status_t			AddPaths(const char* paths);
47 			status_t			AddPath(const char* path, int32* _added = NULL);
48 			status_t			AddTranslator(BTranslator* translator,
49 									image_id image = -1,
50 									const entry_ref* ref = NULL,
51 									ino_t node = 0);
52 
53 			void				RemoveTranslators(entry_ref& ref);
54 
55 			BTranslator*		FindTranslator(translator_id id);
56 
57 			status_t			StoreTranslators(BMessage& archive);
58 			status_t			Identify(BPositionIO* source,
59 									BMessage* ioExtension, uint32 hintType,
60 									const char* hintMIME, uint32 wantType,
61 									translator_info* _info);
62 
63 			status_t			GetTranslators(BPositionIO* source,
64 									BMessage* ioExtension, uint32 hintType,
65 									const char* hintMIME, uint32 wantType,
66 									translator_info** _info, int32* _numInfo);
67 			status_t			GetAllTranslators(translator_id** _ids,
68 									int32* _count);
69 			status_t			GetRefFor(translator_id id, entry_ref& ref);
70 
71 			bool				IsActive() const { return Looper(); }
72 
73 			status_t			CreateTranslators(const entry_ref& ref,
74 									int32& count, BMessage* update = NULL);
75 			status_t			GetTranslatorData(image_id image,
76 									translator_data& data);
77 
78 			status_t			StartWatching(BMessenger target);
79 			status_t			StopWatching(BMessenger target);
80 
81 			void				TranslatorDeleted(translator_id id);
82 
83 private:
84 	static	int					_CompareSupport(const void* _a, const void* _b);
85 
86 			void				_RescanChanged();
87 
88 			const translation_format* _CheckHints(
89 									const translation_format* formats,
90 									int32 formatsCount, uint32 hintType,
91 									const char* hintMIME);
92 
93 			const translator_item* _FindTranslator(translator_id id) const;
94 			const translator_item* _FindTranslator(const char* name) const;
95 			const translator_item* _FindTranslator(entry_ref& ref) const;
96 			translator_item*	_FindTranslator(node_ref& nodeRef);
97 
98 			int32				_CompareTranslatorDirectoryPriority(
99 									const entry_ref& a,
100 									const entry_ref& b) const;
101 			bool				_IsKnownDirectory(const node_ref& nodeRef)
102 									const;
103 
104 			void				_RemoveTranslators(const node_ref* nodeRef,
105 									const entry_ref* ref = NULL);
106 			void				_EntryAdded(const node_ref& nodeRef,
107 									const char* name);
108 			void				_EntryAdded(const entry_ref& ref);
109 			void				_NotifyListeners(BMessage& update) const;
110 
111 			NodeRefList			fDirectories;
112 			TranslatorMap		fTranslators;
113 			MessengerList		fMessengers;
114 			EntryRefSet			fRescanEntries;
115 			const char*			fABISubDirectory;
116 			int32				fNextID;
117 			bool				fLazyScanning;
118 			bool				fSafeMode;
119 };
120 
121 
122 #endif	// TRANSLATOR_ROSTER_PRIVATE_H
123