xref: /haiku/headers/private/storage/DriverSettings.h (revision e81a954787e50e56a7f06f72705b7859b6ab06d1)
1 /*
2  * Copyright 2007-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 _B_DRIVER_SETTINGS_H
9 #define _B_DRIVER_SETTINGS_H
10 
11 
12 #include <SupportDefs.h>
13 
14 
15 struct driver_parameter;
16 struct driver_settings;
17 struct entry_ref;
18 
19 
20 namespace BPrivate {
21 
22 
23 class BDriverParameter;
24 class BDriverParameterContainer;
25 
26 
27 class BDriverParameterIterator {
28 public:
29 								BDriverParameterIterator();
30 								BDriverParameterIterator(
31 									const BDriverParameterIterator& other);
32 								~BDriverParameterIterator();
33 
34 			bool				HasNext() const;
35 			BDriverParameter	Next();
36 
37 			BDriverParameterIterator& operator=(
38 									const BDriverParameterIterator& other);
39 
40 private:
41 			friend class BDriverParameterContainer;
42 			class Delegate;
43 
44 private:
45 								BDriverParameterIterator(Delegate* delegate);
46 			void				_SetTo(Delegate* delegate, bool addReference);
47 
48 private:
49 			Delegate*			fDelegate;
50 };
51 
52 
53 class BDriverParameterContainer {
54 public:
55 								BDriverParameterContainer();
56 	virtual						~BDriverParameterContainer();
57 
58 			int32				CountParameters() const;
59 			const driver_parameter*	Parameters() const;
60 			BDriverParameter	ParameterAt(int32 index) const;
61 			bool				FindParameter(const char* name,
62 									BDriverParameter* _parameter) const;
63 			BDriverParameter	GetParameter(const char* name) const;
64 
65 			BDriverParameterIterator ParameterIterator() const;
66 			BDriverParameterIterator ParameterIterator(const char* name) const;
67 
68 			const char*			GetParameterValue(const char* name,
69 									const char* unknownValue = NULL,
70 									const char* noValue = NULL) const;
71 			bool				GetBoolParameterValue(const char* name,
72 									bool unknownValue = false,
73 									bool noValue = false) const;
74 			int32				GetInt32ParameterValue(const char* name,
75 									int32 unknownValue = 0,
76 									int32 noValue = 0) const;
77 			int64				GetInt64ParameterValue(const char* name,
78 									int64 unknownValue = 0,
79 									int64 noValue = 0) const;
80 
81 protected:
82 	virtual	const driver_parameter* GetParametersAndCount(int32& _count) const
83 									= 0;
84 
85 private:
86 			class Iterator;
87 			class NameIterator;
88 };
89 
90 
91 class BDriverSettings : public BDriverParameterContainer {
92 public:
93 								BDriverSettings();
94 	virtual						~BDriverSettings();
95 
96 			status_t			Load(const char* driverNameOrAbsolutePath);
97 			status_t			Load(const entry_ref& ref);
98 			status_t			SetToString(const char* string);
99 			void				Unset();
100 
101 protected:
102 	virtual	const driver_parameter* GetParametersAndCount(int32& _count) const;
103 
104 private:
105 			void*				fSettingsHandle;
106 			const driver_settings* fSettings;
107 };
108 
109 
110 class BDriverParameter : public BDriverParameterContainer {
111 public:
112 								BDriverParameter();
113 								BDriverParameter(
114 									const driver_parameter* parameter);
115 								BDriverParameter(const BDriverParameter& other);
116 	virtual						~BDriverParameter();
117 
118 			void				SetTo(const driver_parameter* parameter);
119 
120 			bool				IsValid() const;
121 
122 			const char*			Name() const;
123 			int32				CountValues() const;
124 			const char* const*	Values() const;
125 			const char*			ValueAt(int32 index,
126 									const char* noValue = NULL) const;
127 			bool				BoolValueAt(int32 index,
128 									bool noValue = false) const;
129 			int32				Int32ValueAt(int32 index,
130 									int32 noValue = 0) const;
131 			int64				Int64ValueAt(int32 index,
132 									int64 noValue = 0) const;
133 
134 			BDriverParameter&	operator=(const BDriverParameter& other);
135 
136 protected:
137 	virtual	const driver_parameter* GetParametersAndCount(int32& _count) const;
138 
139 private:
140 			const driver_parameter*	fParameter;
141 };
142 
143 
144 }	// namespace BPrivate
145 
146 
147 using BPrivate::BDriverParameterIterator;
148 using BPrivate::BDriverSettings;
149 using BPrivate::BDriverParameter;
150 
151 
152 #endif	// _B_DRIVER_SETTINGS_H
153