183812f67SIngo Weinhold // DriverSettings.cpp
283812f67SIngo Weinhold
383812f67SIngo Weinhold #include <new>
483812f67SIngo Weinhold #include <stdlib.h>
583812f67SIngo Weinhold #include <string.h>
683812f67SIngo Weinhold
783812f67SIngo Weinhold #include <driver_settings.h>
883812f67SIngo Weinhold
9c0509cccSIngo Weinhold #include <Referenceable.h>
10c0509cccSIngo Weinhold
1183812f67SIngo Weinhold #include "DriverSettings.h"
1283812f67SIngo Weinhold #include "String.h"
1383812f67SIngo Weinhold
1483812f67SIngo Weinhold // The parameter values that shall be evaluated to true.
1583812f67SIngo Weinhold static const char* kTrueValueStrings[]
1683812f67SIngo Weinhold = { "1", "true", "yes", "on", "enable", "enabled" };
1783812f67SIngo Weinhold static const int32 kTrueValueStringCount
1883812f67SIngo Weinhold = sizeof(kTrueValueStrings) / sizeof(const char*);
1983812f67SIngo Weinhold
2083812f67SIngo Weinhold
2183812f67SIngo Weinhold // #pragma mark -
2283812f67SIngo Weinhold // #pragma mark ----- DriverParameterIterator -----
2383812f67SIngo Weinhold
2483812f67SIngo Weinhold // Delegate
25*88e38c17SIngo Weinhold class DriverParameterIterator::Delegate : public BReferenceable {
2683812f67SIngo Weinhold public:
Delegate()27*88e38c17SIngo Weinhold Delegate() : BReferenceable() {}
~Delegate()2883812f67SIngo Weinhold virtual ~Delegate() {}
2983812f67SIngo Weinhold
3083812f67SIngo Weinhold virtual Delegate* Clone() const = 0;
3183812f67SIngo Weinhold
3283812f67SIngo Weinhold virtual bool HasNext() const = 0;
3383812f67SIngo Weinhold virtual bool GetNext(DriverParameter* parameter) = 0;
3483812f67SIngo Weinhold };
3583812f67SIngo Weinhold
3683812f67SIngo Weinhold // constructor
DriverParameterIterator()3783812f67SIngo Weinhold DriverParameterIterator::DriverParameterIterator()
3883812f67SIngo Weinhold : fDelegate(NULL)
3983812f67SIngo Weinhold {
4083812f67SIngo Weinhold }
4183812f67SIngo Weinhold
4283812f67SIngo Weinhold // constructor
DriverParameterIterator(Delegate * delegate)4383812f67SIngo Weinhold DriverParameterIterator::DriverParameterIterator(Delegate* delegate)
4483812f67SIngo Weinhold : fDelegate(delegate)
4583812f67SIngo Weinhold {
4683812f67SIngo Weinhold }
4783812f67SIngo Weinhold
4883812f67SIngo Weinhold // copy constructor
DriverParameterIterator(const DriverParameterIterator & other)4983812f67SIngo Weinhold DriverParameterIterator::DriverParameterIterator(
5083812f67SIngo Weinhold const DriverParameterIterator& other)
5183812f67SIngo Weinhold : fDelegate(NULL)
5283812f67SIngo Weinhold {
5383812f67SIngo Weinhold _SetTo(other.fDelegate, true);
5483812f67SIngo Weinhold }
5583812f67SIngo Weinhold
5683812f67SIngo Weinhold // destructor
~DriverParameterIterator()5783812f67SIngo Weinhold DriverParameterIterator::~DriverParameterIterator()
5883812f67SIngo Weinhold {
5983812f67SIngo Weinhold _SetTo(NULL, false);
6083812f67SIngo Weinhold }
6183812f67SIngo Weinhold
6283812f67SIngo Weinhold // HasNext
6383812f67SIngo Weinhold bool
HasNext() const6483812f67SIngo Weinhold DriverParameterIterator::HasNext() const
6583812f67SIngo Weinhold {
6683812f67SIngo Weinhold return (fDelegate ? fDelegate->HasNext() : false);
6783812f67SIngo Weinhold }
6883812f67SIngo Weinhold
6983812f67SIngo Weinhold // GetNext
7083812f67SIngo Weinhold bool
GetNext(DriverParameter * parameter)7183812f67SIngo Weinhold DriverParameterIterator::GetNext(DriverParameter* parameter)
7283812f67SIngo Weinhold {
7383812f67SIngo Weinhold if (!fDelegate)
7483812f67SIngo Weinhold return false;
7583812f67SIngo Weinhold if (fDelegate->CountReferences() > 1) {
7683812f67SIngo Weinhold Delegate* clone = fDelegate->Clone();
7783812f67SIngo Weinhold if (!clone)
7883812f67SIngo Weinhold return false;
7983812f67SIngo Weinhold _SetTo(clone, false);
8083812f67SIngo Weinhold }
8183812f67SIngo Weinhold return fDelegate->GetNext(parameter);
8283812f67SIngo Weinhold }
8383812f67SIngo Weinhold
8483812f67SIngo Weinhold // =
8583812f67SIngo Weinhold DriverParameterIterator&
operator =(const DriverParameterIterator & other)8683812f67SIngo Weinhold DriverParameterIterator::operator=(const DriverParameterIterator& other)
8783812f67SIngo Weinhold {
8883812f67SIngo Weinhold _SetTo(other.fDelegate, true);
8983812f67SIngo Weinhold return *this;
9083812f67SIngo Weinhold }
9183812f67SIngo Weinhold
9283812f67SIngo Weinhold // _SetTo
9383812f67SIngo Weinhold void
_SetTo(Delegate * delegate,bool addReference)9483812f67SIngo Weinhold DriverParameterIterator::_SetTo(Delegate* delegate, bool addReference)
9583812f67SIngo Weinhold {
9683812f67SIngo Weinhold if (fDelegate)
97*88e38c17SIngo Weinhold fDelegate->ReleaseReference();
9883812f67SIngo Weinhold fDelegate = delegate;
9983812f67SIngo Weinhold if (fDelegate && addReference)
100*88e38c17SIngo Weinhold fDelegate->AcquireReference();
10183812f67SIngo Weinhold }
10283812f67SIngo Weinhold
10383812f67SIngo Weinhold
10483812f67SIngo Weinhold // #pragma mark -
10583812f67SIngo Weinhold // #pragma mark ----- DriverParameterContainer -----
10683812f67SIngo Weinhold
10783812f67SIngo Weinhold // Iterator
10883812f67SIngo Weinhold class DriverParameterContainer::Iterator
10983812f67SIngo Weinhold : public DriverParameterIterator::Delegate {
11083812f67SIngo Weinhold public:
Iterator(const driver_parameter * parameters,int32 count)11183812f67SIngo Weinhold Iterator(const driver_parameter* parameters, int32 count)
11283812f67SIngo Weinhold : Delegate(),
11383812f67SIngo Weinhold fParameters(parameters),
11483812f67SIngo Weinhold fCount(count)
11583812f67SIngo Weinhold {
11683812f67SIngo Weinhold }
11783812f67SIngo Weinhold
~Iterator()11883812f67SIngo Weinhold virtual ~Iterator()
11983812f67SIngo Weinhold {
12083812f67SIngo Weinhold }
12183812f67SIngo Weinhold
Clone() const12283812f67SIngo Weinhold virtual Delegate* Clone() const
12383812f67SIngo Weinhold {
124783a5c71SStephan Aßmus return new(std::nothrow) Iterator(fParameters, fCount);
12583812f67SIngo Weinhold }
12683812f67SIngo Weinhold
HasNext() const12783812f67SIngo Weinhold virtual bool HasNext() const
12883812f67SIngo Weinhold {
12983812f67SIngo Weinhold return (fParameters && fCount > 0);
13083812f67SIngo Weinhold }
13183812f67SIngo Weinhold
GetNext(DriverParameter * parameter)13283812f67SIngo Weinhold virtual bool GetNext(DriverParameter* parameter)
13383812f67SIngo Weinhold {
13483812f67SIngo Weinhold if (fParameters && fCount > 0) {
13583812f67SIngo Weinhold if (parameter)
13683812f67SIngo Weinhold parameter->SetTo(fParameters);
13783812f67SIngo Weinhold fParameters++;
13883812f67SIngo Weinhold fCount--;
13983812f67SIngo Weinhold return true;
14083812f67SIngo Weinhold }
14183812f67SIngo Weinhold return false;
14283812f67SIngo Weinhold }
14383812f67SIngo Weinhold
14483812f67SIngo Weinhold private:
14583812f67SIngo Weinhold const driver_parameter* fParameters;
14683812f67SIngo Weinhold int32 fCount;
14783812f67SIngo Weinhold };
14883812f67SIngo Weinhold
14983812f67SIngo Weinhold // NameIterator
15083812f67SIngo Weinhold class DriverParameterContainer::NameIterator
15183812f67SIngo Weinhold : public DriverParameterIterator::Delegate {
15283812f67SIngo Weinhold public:
NameIterator(const driver_parameter * parameters,int32 count,const char * name)15383812f67SIngo Weinhold NameIterator(const driver_parameter* parameters, int32 count,
15483812f67SIngo Weinhold const char* name)
15583812f67SIngo Weinhold : Delegate(),
15683812f67SIngo Weinhold fParameters(parameters),
15783812f67SIngo Weinhold fCount(count),
15883812f67SIngo Weinhold fName(name)
15983812f67SIngo Weinhold {
16083812f67SIngo Weinhold _FindNext(false);
16183812f67SIngo Weinhold }
16283812f67SIngo Weinhold
~NameIterator()16383812f67SIngo Weinhold virtual ~NameIterator()
16483812f67SIngo Weinhold {
16583812f67SIngo Weinhold }
16683812f67SIngo Weinhold
Clone() const16783812f67SIngo Weinhold virtual Delegate* Clone() const
16883812f67SIngo Weinhold {
169783a5c71SStephan Aßmus return new(std::nothrow) NameIterator(fParameters, fCount,
17083812f67SIngo Weinhold fName.GetString());
17183812f67SIngo Weinhold }
17283812f67SIngo Weinhold
HasNext() const17383812f67SIngo Weinhold virtual bool HasNext() const
17483812f67SIngo Weinhold {
17583812f67SIngo Weinhold return (fParameters && fCount > 0);
17683812f67SIngo Weinhold }
17783812f67SIngo Weinhold
GetNext(DriverParameter * parameter)17883812f67SIngo Weinhold virtual bool GetNext(DriverParameter* parameter)
17983812f67SIngo Weinhold {
18083812f67SIngo Weinhold if (fParameters && fCount > 0) {
18183812f67SIngo Weinhold if (parameter)
18283812f67SIngo Weinhold parameter->SetTo(fParameters);
18383812f67SIngo Weinhold _FindNext(true);
18483812f67SIngo Weinhold return true;
18583812f67SIngo Weinhold }
18683812f67SIngo Weinhold return false;
18783812f67SIngo Weinhold }
18883812f67SIngo Weinhold
18983812f67SIngo Weinhold private:
_FindNext(bool skipCurrent)19083812f67SIngo Weinhold void _FindNext(bool skipCurrent)
19183812f67SIngo Weinhold {
19283812f67SIngo Weinhold if (!fParameters || fCount < 1)
19383812f67SIngo Weinhold return;
19483812f67SIngo Weinhold if (skipCurrent) {
19583812f67SIngo Weinhold fParameters++;
19683812f67SIngo Weinhold fCount--;
19783812f67SIngo Weinhold }
19883812f67SIngo Weinhold while (fCount > 0 && fName != fParameters->name) {
19983812f67SIngo Weinhold fParameters++;
20083812f67SIngo Weinhold fCount--;
20183812f67SIngo Weinhold }
20283812f67SIngo Weinhold }
20383812f67SIngo Weinhold
20483812f67SIngo Weinhold private:
20583812f67SIngo Weinhold const driver_parameter* fParameters;
20683812f67SIngo Weinhold int32 fCount;
20783812f67SIngo Weinhold String fName;
20883812f67SIngo Weinhold };
20983812f67SIngo Weinhold
21083812f67SIngo Weinhold // constructor
DriverParameterContainer()21183812f67SIngo Weinhold DriverParameterContainer::DriverParameterContainer()
21283812f67SIngo Weinhold {
21383812f67SIngo Weinhold }
21483812f67SIngo Weinhold
21583812f67SIngo Weinhold // destructor
~DriverParameterContainer()21683812f67SIngo Weinhold DriverParameterContainer::~DriverParameterContainer()
21783812f67SIngo Weinhold {
21883812f67SIngo Weinhold }
21983812f67SIngo Weinhold
22083812f67SIngo Weinhold // CountParameters
22183812f67SIngo Weinhold int32
CountParameters() const22283812f67SIngo Weinhold DriverParameterContainer::CountParameters() const
22383812f67SIngo Weinhold {
22483812f67SIngo Weinhold int32 count;
22583812f67SIngo Weinhold return (GetParametersAndCount(&count) ? count : 0);
22683812f67SIngo Weinhold
22783812f67SIngo Weinhold }
22883812f67SIngo Weinhold
22983812f67SIngo Weinhold // GetParameters
23083812f67SIngo Weinhold const driver_parameter*
GetParameters() const23183812f67SIngo Weinhold DriverParameterContainer::GetParameters() const
23283812f67SIngo Weinhold {
23383812f67SIngo Weinhold int32 count;
23483812f67SIngo Weinhold return GetParametersAndCount(&count);
23583812f67SIngo Weinhold }
23683812f67SIngo Weinhold
23783812f67SIngo Weinhold // GetParameterAt
23883812f67SIngo Weinhold bool
GetParameterAt(int32 index,DriverParameter * parameter) const23983812f67SIngo Weinhold DriverParameterContainer::GetParameterAt(int32 index,
24083812f67SIngo Weinhold DriverParameter* parameter) const
24183812f67SIngo Weinhold {
24283812f67SIngo Weinhold int32 count;
24383812f67SIngo Weinhold if (const driver_parameter* parameters = GetParametersAndCount(&count)) {
24483812f67SIngo Weinhold if (index >= 0 && index < count) {
24583812f67SIngo Weinhold if (parameter)
24683812f67SIngo Weinhold parameter->SetTo(parameters + index);
24783812f67SIngo Weinhold return true;
24883812f67SIngo Weinhold }
24983812f67SIngo Weinhold }
25083812f67SIngo Weinhold return false;
25183812f67SIngo Weinhold }
25283812f67SIngo Weinhold
25383812f67SIngo Weinhold // FindParameter
25483812f67SIngo Weinhold bool
FindParameter(const char * name,DriverParameter * parameter) const25583812f67SIngo Weinhold DriverParameterContainer::FindParameter(const char* name,
25683812f67SIngo Weinhold DriverParameter* parameter) const
25783812f67SIngo Weinhold {
25883812f67SIngo Weinhold if (!name)
25983812f67SIngo Weinhold return false;
26083812f67SIngo Weinhold int32 count;
26183812f67SIngo Weinhold if (const driver_parameter* parameters = GetParametersAndCount(&count)) {
26283812f67SIngo Weinhold for (int32 i = 0; i < count; i++) {
26383812f67SIngo Weinhold if (strcmp(name, parameters[i].name) == 0) {
26483812f67SIngo Weinhold if (parameter)
26583812f67SIngo Weinhold parameter->SetTo(parameters + i);
26683812f67SIngo Weinhold return true;
26783812f67SIngo Weinhold }
26883812f67SIngo Weinhold }
26983812f67SIngo Weinhold }
27083812f67SIngo Weinhold return false;
27183812f67SIngo Weinhold }
27283812f67SIngo Weinhold
27383812f67SIngo Weinhold // GetParameterIterator
27483812f67SIngo Weinhold DriverParameterIterator
GetParameterIterator() const27583812f67SIngo Weinhold DriverParameterContainer::GetParameterIterator() const
27683812f67SIngo Weinhold {
27783812f67SIngo Weinhold int32 count;
27883812f67SIngo Weinhold if (const driver_parameter* parameters = GetParametersAndCount(&count)) {
279783a5c71SStephan Aßmus if (Iterator* iterator = new(std::nothrow) Iterator(parameters, count))
28083812f67SIngo Weinhold return DriverParameterIterator(iterator);
28183812f67SIngo Weinhold }
28283812f67SIngo Weinhold return DriverParameterIterator();
28383812f67SIngo Weinhold }
28483812f67SIngo Weinhold
28583812f67SIngo Weinhold // GetParameterIterator
28683812f67SIngo Weinhold DriverParameterIterator
GetParameterIterator(const char * name) const28783812f67SIngo Weinhold DriverParameterContainer::GetParameterIterator(const char* name) const
28883812f67SIngo Weinhold {
28983812f67SIngo Weinhold int32 count;
29083812f67SIngo Weinhold if (const driver_parameter* parameters = GetParametersAndCount(&count)) {
291783a5c71SStephan Aßmus NameIterator* iterator = new(std::nothrow) NameIterator(parameters, count,
29283812f67SIngo Weinhold name);
29383812f67SIngo Weinhold if (iterator)
29483812f67SIngo Weinhold return DriverParameterIterator(iterator);
29583812f67SIngo Weinhold }
29683812f67SIngo Weinhold return DriverParameterIterator();
29783812f67SIngo Weinhold }
29883812f67SIngo Weinhold
29983812f67SIngo Weinhold // GetParameterValue
30083812f67SIngo Weinhold const char*
GetParameterValue(const char * name,const char * unknownValue,const char * noValue) const30183812f67SIngo Weinhold DriverParameterContainer::GetParameterValue(const char* name,
30283812f67SIngo Weinhold const char* unknownValue, const char* noValue) const
30383812f67SIngo Weinhold {
30483812f67SIngo Weinhold DriverParameter parameter;
30583812f67SIngo Weinhold if (!FindParameter(name, ¶meter))
30683812f67SIngo Weinhold return unknownValue;
30783812f67SIngo Weinhold return parameter.ValueAt(0, noValue);
30883812f67SIngo Weinhold }
30983812f67SIngo Weinhold
31083812f67SIngo Weinhold // GetBoolParameterValue
31183812f67SIngo Weinhold bool
GetBoolParameterValue(const char * name,bool unknownValue,bool noValue) const31283812f67SIngo Weinhold DriverParameterContainer::GetBoolParameterValue(const char* name,
31383812f67SIngo Weinhold bool unknownValue, bool noValue) const
31483812f67SIngo Weinhold {
31583812f67SIngo Weinhold DriverParameter parameter;
31683812f67SIngo Weinhold if (!FindParameter(name, ¶meter))
31783812f67SIngo Weinhold return unknownValue;
31883812f67SIngo Weinhold return parameter.BoolValueAt(0, noValue);
31983812f67SIngo Weinhold }
32083812f67SIngo Weinhold
32183812f67SIngo Weinhold // GetInt32ParameterValue
32283812f67SIngo Weinhold int32
GetInt32ParameterValue(const char * name,int32 unknownValue,int32 noValue) const32383812f67SIngo Weinhold DriverParameterContainer::GetInt32ParameterValue(const char* name,
32483812f67SIngo Weinhold int32 unknownValue, int32 noValue) const
32583812f67SIngo Weinhold {
32683812f67SIngo Weinhold DriverParameter parameter;
32783812f67SIngo Weinhold if (!FindParameter(name, ¶meter))
32883812f67SIngo Weinhold return unknownValue;
32983812f67SIngo Weinhold return parameter.Int32ValueAt(0, noValue);
33083812f67SIngo Weinhold }
33183812f67SIngo Weinhold
33283812f67SIngo Weinhold // GetInt64ParameterValue
33383812f67SIngo Weinhold int64
GetInt64ParameterValue(const char * name,int64 unknownValue,int64 noValue) const33483812f67SIngo Weinhold DriverParameterContainer::GetInt64ParameterValue(const char* name,
33583812f67SIngo Weinhold int64 unknownValue, int64 noValue) const
33683812f67SIngo Weinhold {
33783812f67SIngo Weinhold DriverParameter parameter;
33883812f67SIngo Weinhold if (!FindParameter(name, ¶meter))
33983812f67SIngo Weinhold return unknownValue;
34083812f67SIngo Weinhold return parameter.Int64ValueAt(0, noValue);
34183812f67SIngo Weinhold }
34283812f67SIngo Weinhold
34383812f67SIngo Weinhold
34483812f67SIngo Weinhold // #pragma mark -
34583812f67SIngo Weinhold // #pragma mark ----- DriverSettings -----
34683812f67SIngo Weinhold
34783812f67SIngo Weinhold // constructor
DriverSettings()34883812f67SIngo Weinhold DriverSettings::DriverSettings()
34983812f67SIngo Weinhold : DriverParameterContainer(),
35083812f67SIngo Weinhold fSettingsHandle(NULL),
35183812f67SIngo Weinhold fSettings(NULL)
35283812f67SIngo Weinhold {
35383812f67SIngo Weinhold }
35483812f67SIngo Weinhold
35583812f67SIngo Weinhold // destructor
~DriverSettings()35683812f67SIngo Weinhold DriverSettings::~DriverSettings()
35783812f67SIngo Weinhold {
35883812f67SIngo Weinhold Unset();
35983812f67SIngo Weinhold }
36083812f67SIngo Weinhold
36183812f67SIngo Weinhold // Load
36283812f67SIngo Weinhold status_t
Load(const char * driverName)36383812f67SIngo Weinhold DriverSettings::Load(const char* driverName)
36483812f67SIngo Weinhold {
36583812f67SIngo Weinhold Unset();
36683812f67SIngo Weinhold fSettingsHandle = load_driver_settings(driverName);
36783812f67SIngo Weinhold if (!fSettingsHandle)
36883812f67SIngo Weinhold return B_ENTRY_NOT_FOUND;
36983812f67SIngo Weinhold fSettings = get_driver_settings(fSettingsHandle);
37083812f67SIngo Weinhold if (!fSettings) {
37183812f67SIngo Weinhold Unset();
37283812f67SIngo Weinhold return B_ERROR;
37383812f67SIngo Weinhold }
37483812f67SIngo Weinhold return B_OK;
37583812f67SIngo Weinhold }
37683812f67SIngo Weinhold
37783812f67SIngo Weinhold // Unset
37883812f67SIngo Weinhold void
Unset()37983812f67SIngo Weinhold DriverSettings::Unset()
38083812f67SIngo Weinhold {
38183812f67SIngo Weinhold if (fSettingsHandle)
38283812f67SIngo Weinhold unload_driver_settings(fSettingsHandle);
38383812f67SIngo Weinhold fSettingsHandle = NULL;
38483812f67SIngo Weinhold fSettings = NULL;
38583812f67SIngo Weinhold }
38683812f67SIngo Weinhold
38783812f67SIngo Weinhold // GetParametersAndCount
38883812f67SIngo Weinhold const driver_parameter*
GetParametersAndCount(int32 * count) const38983812f67SIngo Weinhold DriverSettings::GetParametersAndCount(int32* count) const
39083812f67SIngo Weinhold {
39183812f67SIngo Weinhold if (!fSettings)
39283812f67SIngo Weinhold return NULL;
39383812f67SIngo Weinhold *count = fSettings->parameter_count;
39483812f67SIngo Weinhold return fSettings->parameters;
39583812f67SIngo Weinhold }
39683812f67SIngo Weinhold
39783812f67SIngo Weinhold
39883812f67SIngo Weinhold // #pragma mark -
39983812f67SIngo Weinhold // #pragma mark ----- DriverParameter -----
40083812f67SIngo Weinhold
40183812f67SIngo Weinhold // constructor
DriverParameter()40283812f67SIngo Weinhold DriverParameter::DriverParameter()
40383812f67SIngo Weinhold : DriverParameterContainer(),
40483812f67SIngo Weinhold fParameter(NULL)
40583812f67SIngo Weinhold {
40683812f67SIngo Weinhold }
40783812f67SIngo Weinhold
40883812f67SIngo Weinhold // destructor
~DriverParameter()40983812f67SIngo Weinhold DriverParameter::~DriverParameter()
41083812f67SIngo Weinhold {
41183812f67SIngo Weinhold }
41283812f67SIngo Weinhold
41383812f67SIngo Weinhold // SetTo
41483812f67SIngo Weinhold void
SetTo(const driver_parameter * parameter)41583812f67SIngo Weinhold DriverParameter::SetTo(const driver_parameter* parameter)
41683812f67SIngo Weinhold {
41783812f67SIngo Weinhold fParameter = parameter;
41883812f67SIngo Weinhold }
41983812f67SIngo Weinhold
42083812f67SIngo Weinhold // GetName
42183812f67SIngo Weinhold const char*
GetName() const42283812f67SIngo Weinhold DriverParameter::GetName() const
42383812f67SIngo Weinhold {
42483812f67SIngo Weinhold return (fParameter ? fParameter->name : NULL);
42583812f67SIngo Weinhold }
42683812f67SIngo Weinhold
42783812f67SIngo Weinhold // CountValues
42883812f67SIngo Weinhold int32
CountValues() const42983812f67SIngo Weinhold DriverParameter::CountValues() const
43083812f67SIngo Weinhold {
43183812f67SIngo Weinhold return (fParameter ? fParameter->value_count : 0);
43283812f67SIngo Weinhold }
43383812f67SIngo Weinhold
43483812f67SIngo Weinhold // GetValues
43583812f67SIngo Weinhold const char* const*
GetValues() const43683812f67SIngo Weinhold DriverParameter::GetValues() const
43783812f67SIngo Weinhold {
43883812f67SIngo Weinhold return (fParameter ? fParameter->values : 0);
43983812f67SIngo Weinhold }
44083812f67SIngo Weinhold
44183812f67SIngo Weinhold // ValueAt
44283812f67SIngo Weinhold const char*
ValueAt(int32 index,const char * noValue) const44383812f67SIngo Weinhold DriverParameter::ValueAt(int32 index, const char* noValue) const
44483812f67SIngo Weinhold {
44583812f67SIngo Weinhold if (!fParameter || index < 0 || index >= fParameter->value_count)
44683812f67SIngo Weinhold return noValue;
44783812f67SIngo Weinhold return fParameter->values[index];
44883812f67SIngo Weinhold }
44983812f67SIngo Weinhold
45083812f67SIngo Weinhold // BoolValueAt
45183812f67SIngo Weinhold bool
BoolValueAt(int32 index,bool noValue) const45283812f67SIngo Weinhold DriverParameter::BoolValueAt(int32 index, bool noValue) const
45383812f67SIngo Weinhold {
45483812f67SIngo Weinhold const char* value = ValueAt(index, NULL);
45583812f67SIngo Weinhold if (!value)
45683812f67SIngo Weinhold return noValue;
45783812f67SIngo Weinhold for (int32 i = 0; i < kTrueValueStringCount; i++) {
45883812f67SIngo Weinhold if (strcmp(value, kTrueValueStrings[i]) == 0)
45983812f67SIngo Weinhold return true;
46083812f67SIngo Weinhold }
46183812f67SIngo Weinhold return false;
46283812f67SIngo Weinhold }
46383812f67SIngo Weinhold
46483812f67SIngo Weinhold // Int32ValueAt
46583812f67SIngo Weinhold int32
Int32ValueAt(int32 index,int32 noValue) const46683812f67SIngo Weinhold DriverParameter::Int32ValueAt(int32 index, int32 noValue) const
46783812f67SIngo Weinhold {
46883812f67SIngo Weinhold const char* value = ValueAt(index, NULL);
46983812f67SIngo Weinhold if (!value)
47083812f67SIngo Weinhold return noValue;
47183812f67SIngo Weinhold return atol(value);
47283812f67SIngo Weinhold }
47383812f67SIngo Weinhold
47483812f67SIngo Weinhold // Int64ValueAt
47583812f67SIngo Weinhold int64
Int64ValueAt(int32 index,int64 noValue) const47683812f67SIngo Weinhold DriverParameter::Int64ValueAt(int32 index, int64 noValue) const
47783812f67SIngo Weinhold {
47883812f67SIngo Weinhold const char* value = ValueAt(index, NULL);
47983812f67SIngo Weinhold if (!value)
48083812f67SIngo Weinhold return noValue;
48183812f67SIngo Weinhold return strtoll(value, NULL, 10);
48283812f67SIngo Weinhold }
48383812f67SIngo Weinhold
48483812f67SIngo Weinhold // GetParametersAndCount
48583812f67SIngo Weinhold const driver_parameter*
GetParametersAndCount(int32 * count) const48683812f67SIngo Weinhold DriverParameter::GetParametersAndCount(int32* count) const
48783812f67SIngo Weinhold {
48883812f67SIngo Weinhold if (!fParameter)
48983812f67SIngo Weinhold return NULL;
49083812f67SIngo Weinhold *count = fParameter->parameter_count;
49183812f67SIngo Weinhold return fParameter->parameters;
49283812f67SIngo Weinhold }
49383812f67SIngo Weinhold
494