vfs: check userland buffers before reading them.
[haiku.git] / headers / private / storage / DriverSettings.h
blob9e6c3392574b25b4048c393aec09119d1335caa5
1 /*
2 * Copyright 2007-2013, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Ingo Weinhold <ingo_weinhold@gmx.de>
7 */
8 #ifndef _B_DRIVER_SETTINGS_H
9 #define _B_DRIVER_SETTINGS_H
12 #include <SupportDefs.h>
15 struct driver_parameter;
16 struct driver_settings;
17 struct entry_ref;
20 namespace BPrivate {
23 class BDriverParameter;
24 class BDriverParameterContainer;
27 class BDriverParameterIterator {
28 public:
29 BDriverParameterIterator();
30 BDriverParameterIterator(
31 const BDriverParameterIterator& other);
32 ~BDriverParameterIterator();
34 bool HasNext() const;
35 BDriverParameter Next();
37 BDriverParameterIterator& operator=(
38 const BDriverParameterIterator& other);
40 private:
41 friend class BDriverParameterContainer;
42 class Delegate;
44 private:
45 BDriverParameterIterator(Delegate* delegate);
46 void _SetTo(Delegate* delegate, bool addReference);
48 private:
49 Delegate* fDelegate;
53 class BDriverParameterContainer {
54 public:
55 BDriverParameterContainer();
56 virtual ~BDriverParameterContainer();
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;
65 BDriverParameterIterator ParameterIterator() const;
66 BDriverParameterIterator ParameterIterator(const char* name) const;
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;
81 protected:
82 virtual const driver_parameter* GetParametersAndCount(int32& _count) const
83 = 0;
85 private:
86 class Iterator;
87 class NameIterator;
91 class BDriverSettings : public BDriverParameterContainer {
92 public:
93 BDriverSettings();
94 virtual ~BDriverSettings();
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();
101 protected:
102 virtual const driver_parameter* GetParametersAndCount(int32& _count) const;
104 private:
105 void* fSettingsHandle;
106 const driver_settings* fSettings;
110 class BDriverParameter : public BDriverParameterContainer {
111 public:
112 BDriverParameter();
113 BDriverParameter(
114 const driver_parameter* parameter);
115 BDriverParameter(const BDriverParameter& other);
116 virtual ~BDriverParameter();
118 void SetTo(const driver_parameter* parameter);
120 bool IsValid() const;
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;
134 BDriverParameter& operator=(const BDriverParameter& other);
136 protected:
137 virtual const driver_parameter* GetParametersAndCount(int32& _count) const;
139 private:
140 const driver_parameter* fParameter;
144 } // namespace BPrivate
147 using BPrivate::BDriverParameterIterator;
148 using BPrivate::BDriverSettings;
149 using BPrivate::BDriverParameter;
152 #endif // _B_DRIVER_SETTINGS_H