xref: /haiku/src/servers/package/Package.h (revision 25a7b01d15612846f332751841da3579db313082)
1 /*
2  * Copyright 2013, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Ingo Weinhold <ingo_weinhold@gmx.de>
7  */
8 #ifndef PACKAGE_H
9 #define PACKAGE_H
10 
11 
12 #include <Entry.h>
13 #include <Node.h>
14 #include <package/PackageInfo.h>
15 
16 #include <util/OpenHashTable.h>
17 
18 
19 using namespace BPackageKit;
20 
21 
22 class Package {
23 public:
24 								Package();
25 								~Package();
26 
27 			status_t			Init(const entry_ref& entryRef);
28 
29 			const node_ref&		NodeRef() const
30 									{ return fNodeRef; }
31 			const BString&		FileName() const
32 									{ return fFileName; }
33 
34 			const BPackageInfo & Info() const
35 									{ return fInfo; }
36 
37 			bool				IsActive() const
38 									{ return fActive; }
39 			void				SetActive(bool active)
40 									{ fActive = active; }
41 
42 			int32				EntryCreatedIgnoreLevel() const
43 									{ return fIgnoreEntryCreated; }
44 			void				IncrementEntryCreatedIgnoreLevel()
45 									{ fIgnoreEntryCreated++; }
46 			void				DecrementEntryCreatedIgnoreLevel()
47 									{ fIgnoreEntryCreated--; }
48 
49 			int32				EntryRemovedIgnoreLevel() const
50 									{ return fIgnoreEntryRemoved; }
51 			void				IncrementEntryRemovedIgnoreLevel()
52 									{ fIgnoreEntryRemoved++; }
53 			void				DecrementEntryRemovedIgnoreLevel()
54 									{ fIgnoreEntryRemoved--; }
55 
56 			Package*&			FileNameHashTableNext()
57 									{ return fFileNameHashTableNext; }
58 			Package*&			NodeRefHashTableNext()
59 									{ return fNodeRefHashTableNext; }
60 
61 private:
62 			node_ref			fNodeRef;
63 			BString				fFileName;
64 			BPackageInfo		fInfo;
65 			bool				fActive;
66 			Package*			fFileNameHashTableNext;
67 			Package*			fNodeRefHashTableNext;
68 			int32				fIgnoreEntryCreated;
69 			int32				fIgnoreEntryRemoved;
70 };
71 
72 
73 struct PackageFileNameHashDefinition {
74 	typedef const char*		KeyType;
75 	typedef	Package			ValueType;
76 
77 	size_t HashKey(const char* key) const
78 	{
79 		return BString::HashValue(key);
80 	}
81 
82 	size_t Hash(const Package* value) const
83 	{
84 		return HashKey(value->FileName());
85 	}
86 
87 	bool Compare(const char* key, const Package* value) const
88 	{
89 		return value->FileName() == key;
90 	}
91 
92 	Package*& GetLink(Package* value) const
93 	{
94 		return value->FileNameHashTableNext();
95 	}
96 };
97 
98 
99 struct PackageNodeRefHashDefinition {
100 	typedef node_ref		KeyType;
101 	typedef	Package			ValueType;
102 
103 	size_t HashKey(const node_ref& key) const
104 	{
105 		return (size_t)key.device + 17 * (size_t)key.node;
106 	}
107 
108 	size_t Hash(const Package* value) const
109 	{
110 		return HashKey(value->NodeRef());
111 	}
112 
113 	bool Compare(const node_ref& key, const Package* value) const
114 	{
115 		return key == value->NodeRef();
116 	}
117 
118 	Package*& GetLink(Package* value) const
119 	{
120 		return value->NodeRefHashTableNext();
121 	}
122 };
123 
124 
125 typedef BOpenHashTable<PackageFileNameHashDefinition> PackageFileNameHashTable;
126 typedef BOpenHashTable<PackageNodeRefHashDefinition> PackageNodeRefHashTable;
127 
128 
129 #endif	// PACKAGE_H
130