blob: ceea2d3e3ce7ad093af5e3101c1b5cfaeb2fc077 [file] [log] [blame]
San Mehat48765672009-05-20 15:28:43 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
San Mehatc4a895b2009-06-23 21:10:57 -070017#ifndef _PROPERTY_H
18#define _PROPERTY_H
19
20#include <netinet/in.h>
21#include <utils/List.h>
22
San Mehat3c5a6f02009-05-22 15:36:13 -070023class Property {
San Mehatc4a895b2009-06-23 21:10:57 -070024 const char *mName;
25 bool mReadOnly;
26 int mType;
27 int mNumElements;
28
San Mehat3c5a6f02009-05-22 15:36:13 -070029public:
San Mehatc4a895b2009-06-23 21:10:57 -070030 static const int NameMaxSize = 128;
San Mehat3c5a6f02009-05-22 15:36:13 -070031 static const int ValueMaxSize = 255;
San Mehatc4a895b2009-06-23 21:10:57 -070032
33 static const int Type_STRING = 1;
34 static const int Type_INTEGER = 2;
35 static const int Type_IPV4 = 3;
36
37 Property(const char *name, bool ro, int type, int elements);
38 virtual ~Property() {}
39
40 virtual int set(int idx, const char *value) = 0;
41 virtual int set(int idx, int value) = 0;
42 virtual int set(int idx, struct in_addr *value) = 0;
43
44 virtual int get(int idx, char *buffer, size_t max) = 0;
45 virtual int get(int idx, int *buffer) = 0;
46 virtual int get(int idx, struct in_addr *buffer) = 0;
47
48 int getType() { return mType; }
49 bool getReadOnly() { return mReadOnly; }
50 int getNumElements() { return mNumElements; }
51 const char *getName() { return mName; }
San Mehat3c5a6f02009-05-22 15:36:13 -070052};
San Mehatc4a895b2009-06-23 21:10:57 -070053
54class StringProperty : public Property {
55public:
56 StringProperty(const char *name, bool ro, int elements);
57 virtual ~StringProperty() {}
58
59 virtual int set(int idx, const char *value) = 0;
60 int set(int idx, int value);
61 int set(int idx, struct in_addr *value);
62
63 virtual int get(int idx, char *buffer, size_t max) = 0;
64 int get(int idx, int *buffer);
65 int get(int idx, struct in_addr *buffer);
66};
67
68class StringPropertyHelper : public StringProperty {
69 char *mBuffer;
70 size_t mMax;
71public:
72 StringPropertyHelper(const char *name, bool ro,
73 char *buffer, size_t max);
74 int set(int idx, const char *value);
75 int get(int idx, char *buffer, size_t max);
76};
77
78class IntegerProperty : public Property {
79public:
80 IntegerProperty(const char *name, bool ro, int elements);
81 virtual ~IntegerProperty() {}
82
83 int set(int idx, const char *value);
84 virtual int set(int idx, int value) = 0;
85 int set(int idx, struct in_addr *value);
86
87 int get(int idx, char *buffer, size_t max);
88 virtual int get(int idx, int *buffer) = 0;
89 int get(int idx, struct in_addr *buffer);
90};
91
92class IntegerPropertyHelper : public IntegerProperty {
93 int *mBuffer;
94public:
95 IntegerPropertyHelper(const char *name, bool ro, int *buffer);
96 int set(int idx, int value);
97 int get(int idx, int *buffer);
98};
99
100class IPV4AddressProperty : public Property {
101public:
102 IPV4AddressProperty(const char *name, bool ro, int elements);
103 virtual ~IPV4AddressProperty() {}
104
105 int set(int idx, const char *value);
106 int set(int idx, int value);
107 virtual int set(int idx, struct in_addr *value) = 0;
108
109 int get(int idx, char *buffer, size_t max);
110 int get(int idx, int *buffer);
111 virtual int get(int idx, struct in_addr *buffer) = 0;
112};
113
114class IPV4AddressPropertyHelper : public IPV4AddressProperty {
115 struct in_addr *mBuffer;
116public:
117 IPV4AddressPropertyHelper(const char *name, bool ro, struct in_addr *buf);
118 int set(int idx, struct in_addr *value);
119 int get(int idx, struct in_addr *buffer);
120};
121
122typedef android::List<Property *> PropertyCollection;
123
124class PropertyNamespace {
125 char *mName;
126 PropertyCollection *mProperties;
127
128public:
129 PropertyNamespace(const char *name);
130 virtual ~PropertyNamespace();
131
132 const char *getName() { return mName; }
133 PropertyCollection *getProperties() { return mProperties; }
134};
135
136typedef android::List<PropertyNamespace *> PropertyNamespaceCollection;
137#endif