• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 #ifndef _PROPERTY_H
18 #define _PROPERTY_H
19 
20 #include <netinet/in.h>
21 #include <utils/List.h>
22 
23 class Property {
24     const char *mName;
25     bool       mReadOnly;
26     int        mType;
27     int        mNumElements;
28 
29 public:
30     static const int NameMaxSize   = 128;
31     static const int ValueMaxSize  = 255;
32 
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);
~Property()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 
getType()48     int getType() { return mType; }
getReadOnly()49     bool getReadOnly() { return mReadOnly; }
getNumElements()50     int getNumElements() { return mNumElements; }
getName()51     const char *getName() { return mName; }
52 };
53 
54 class StringProperty : public Property {
55 public:
56     StringProperty(const char *name, bool ro, int elements);
~StringProperty()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 
68 class StringPropertyHelper : public StringProperty {
69     char *mBuffer;
70     size_t mMax;
71 public:
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 
78 class IntegerProperty : public Property {
79 public:
80     IntegerProperty(const char *name, bool ro, int elements);
~IntegerProperty()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 
92 class IntegerPropertyHelper : public IntegerProperty {
93     int *mBuffer;
94 public:
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 
100 class IPV4AddressProperty : public Property {
101 public:
102     IPV4AddressProperty(const char *name, bool ro, int elements);
~IPV4AddressProperty()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 
114 class IPV4AddressPropertyHelper : public IPV4AddressProperty {
115     struct in_addr *mBuffer;
116 public:
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 
122 typedef android::List<Property *> PropertyCollection;
123 
124 class PropertyNamespace {
125     char         *mName;
126     PropertyCollection *mProperties;
127 
128 public:
129     PropertyNamespace(const char *name);
130     virtual ~PropertyNamespace();
131 
getName()132     const char *getName() { return mName; }
getProperties()133     PropertyCollection *getProperties() { return mProperties; }
134 };
135 
136 typedef android::List<PropertyNamespace *> PropertyNamespaceCollection;
137 #endif
138