1 martin 1.30 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.31 //
|
3 martin 1.30 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
|
9 martin 1.31 //
|
10 martin 1.30 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
|
16 martin 1.31 //
|
17 martin 1.30 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.31 //
|
20 martin 1.30 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.31 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.30 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27 martin 1.31 //
|
28 martin 1.30 //////////////////////////////////////////////////////////////////////////
|
29 kumpf 1.1 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32
33 ///////////////////////////////////////////////////////////////////////////////
|
34 kumpf 1.23 //
|
35 kumpf 1.1 // This file has implementation for the file system property owner class.
36 //
37 ///////////////////////////////////////////////////////////////////////////////
38
39 #include <Pegasus/Common/Config.h>
40 #include <Pegasus/Common/Tracer.h>
41 #include <Pegasus/Common/FileSystem.h>
42 #include <Pegasus/Config/ConfigManager.h>
43 #include "FileSystemPropertyOwner.h"
44
45
46 PEGASUS_USING_STD;
47
48 PEGASUS_NAMESPACE_BEGIN
49
50 ///////////////////////////////////////////////////////////////////////////////
51 // FileSystemPropertyOwner
52 //
53 // When a new FileSystem property is added, make sure to add the property name
54 // and the default attributes of that property in the table below.
55 ///////////////////////////////////////////////////////////////////////////////
56 kumpf 1.1
57 static struct ConfigPropertyRow properties[] =
58 {
|
59 kumpf 1.33 {"repositoryDir", PEGASUS_REPOSITORY_DIR, IS_STATIC, IS_VISIBLE},
|
60 ouyang.jian 1.25 #if defined(PEGASUS_OS_PASE)
|
61 kumpf 1.32 {"messageDir", "/QOpenSys/QIBM/ProdData/UME/Pegasus/msg", IS_STATIC,
|
62 kumpf 1.33 IS_VISIBLE},
|
63 ouyang.jian 1.25 #else
|
64 kumpf 1.33 {"messageDir", "msg", IS_STATIC, IS_VISIBLE},
|
65 ouyang.jian 1.25 #endif
|
66 b.whiteley 1.26 #if defined(PEGASUS_OS_TYPE_WINDOWS)
|
67 kumpf 1.33 {"providerManagerDir", "bin", IS_STATIC, IS_VISIBLE},
|
68 r.kieninger 1.28 #elif defined(PEGASUS_OS_ZOS)
|
69 kumpf 1.33 {"providerManagerDir", "lib", IS_STATIC, IS_VISIBLE},
|
70 b.whiteley 1.26 #elif defined(PEGASUS_OS_PASE) && defined(PEGASUS_USE_RELEASE_DIRS)
|
71 kumpf 1.33 {"providerManagerDir", "/QOpenSys/QIBM/ProdData/UME/Pegasus/lib",
|
72 cheng.sp 1.35 IS_STATIC, IS_VISIBLE},
73 #elif defined(PEGASUS_OS_AIX) && defined(PEGASUS_USE_RELEASE_DIRS)
74 {"providerManagerDir", "/usr/lib", IS_STATIC, IS_VISIBLE},
|
75 b.whiteley 1.26 #elif defined(PEGASUS_OS_VMS)
|
76 kumpf 1.33 {"providerManagerDir", "/wbem_lib", IS_STATIC, IS_VISIBLE},
|
77 b.whiteley 1.26 #else
|
78 kumpf 1.33 {"providerManagerDir", "lib", IS_STATIC, IS_VISIBLE},
|
79 b.whiteley 1.26 #endif
|
80 kumpf 1.1 };
81
82 const Uint32 NUM_PROPERTIES = sizeof(properties) / sizeof(properties[0]);
83
84
85 /** Constructors */
86 FileSystemPropertyOwner::FileSystemPropertyOwner()
87 {
|
88 a.arora 1.10 _repositoryDir.reset(new ConfigProperty);
89 _messageDir.reset(new ConfigProperty);
|
90 b.whiteley 1.26 _providerManagerDir.reset(new ConfigProperty);
|
91 kumpf 1.1 }
92
93
94 /**
|
95 kumpf 1.23 Checks if the given directory is existing and writable
|
96 kumpf 1.1 */
97 Boolean isDirValid(const String& dirName)
98 {
|
99 marek 1.22 String directoryName(ConfigManager::getHomedPath(dirName));
|
100 kumpf 1.23 if (FileSystem::isDirectory(directoryName) &&
|
101 marek 1.22 FileSystem::canWrite(directoryName))
|
102 kumpf 1.1 {
103 return true;
104 }
105 return false;
106 }
|
107 kumpf 1.23
|
108 kumpf 1.1 /**
|
109 kumpf 1.23 Initialize the config properties.
|
110 kumpf 1.1 */
111 void FileSystemPropertyOwner::initialize()
112 {
113 for (Uint32 i = 0; i < NUM_PROPERTIES; i++)
114 {
115 //
116 // Initialize the properties with default values
117 //
118 if (String::equalNoCase(properties[i].propertyName, "repositoryDir"))
119 {
120 _repositoryDir->propertyName = properties[i].propertyName;
121 _repositoryDir->defaultValue = properties[i].defaultValue;
122 _repositoryDir->currentValue = properties[i].defaultValue;
123 _repositoryDir->plannedValue = properties[i].defaultValue;
124 _repositoryDir->dynamic = properties[i].dynamic;
|
125 kumpf 1.6 _repositoryDir->externallyVisible = properties[i].externallyVisible;
|
126 kumpf 1.1 }
|
127 david 1.9 else if (String::equalNoCase(properties[i].propertyName, "messageDir"))
128 {
129 _messageDir->propertyName = properties[i].propertyName;
130 _messageDir->defaultValue = properties[i].defaultValue;
131 _messageDir->currentValue = properties[i].defaultValue;
132 _messageDir->plannedValue = properties[i].defaultValue;
133 _messageDir->dynamic = properties[i].dynamic;
134 _messageDir->externallyVisible = properties[i].externallyVisible;
135 }
|
136 kumpf 1.32 else if (String::equalNoCase(properties[i].propertyName,
|
137 b.whiteley 1.26 "providerManagerDir"))
138 {
139 _providerManagerDir->propertyName = properties[i].propertyName;
140 _providerManagerDir->defaultValue = properties[i].defaultValue;
141 _providerManagerDir->currentValue = properties[i].defaultValue;
142 _providerManagerDir->plannedValue = properties[i].defaultValue;
143 _providerManagerDir->dynamic = properties[i].dynamic;
|
144 kumpf 1.32 _providerManagerDir->externallyVisible =
|
145 b.whiteley 1.26 properties[i].externallyVisible;
146 }
|
147 kumpf 1.1 }
148 }
149
|
150 kumpf 1.3 struct ConfigProperty* FileSystemPropertyOwner::_lookupConfigProperty(
|
151 aruran.ms 1.18 const String& name) const
|
152 kumpf 1.1 {
153 if (String::equalNoCase(_repositoryDir->propertyName, name))
154 {
|
155 a.arora 1.10 return _repositoryDir.get();
|
156 david 1.9 }
157 if (String::equalNoCase(_messageDir->propertyName, name))
158 {
|
159 a.arora 1.10 return _messageDir.get();
|
160 kumpf 1.1 }
|
161 b.whiteley 1.26 if (String::equalNoCase(_providerManagerDir->propertyName, name))
|
162 kumpf 1.1 {
|
163 b.whiteley 1.26 return _providerManagerDir.get();
|
164 kumpf 1.1 }
|
165 b.whiteley 1.26 throw UnrecognizedConfigProperty(name);
|
166 kumpf 1.1 }
167
|
168 kumpf 1.23 /**
169 Get information about the specified property.
|
170 kumpf 1.1 */
|
171 kumpf 1.3 void FileSystemPropertyOwner::getPropertyInfo(
|
172 kumpf 1.23 const String& name,
|
173 vijay.eli 1.17 Array<String>& propertyInfo) const
|
174 kumpf 1.1 {
|
175 kumpf 1.3 propertyInfo.clear();
|
176 aruran.ms 1.18 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
|
177 kumpf 1.3
178 propertyInfo.append(configProperty->propertyName);
179 propertyInfo.append(configProperty->defaultValue);
180 propertyInfo.append(configProperty->currentValue);
181 propertyInfo.append(configProperty->plannedValue);
182 if (configProperty->dynamic)
|
183 kumpf 1.6 {
184 propertyInfo.append(STRING_TRUE);
185 }
186 else
187 {
188 propertyInfo.append(STRING_FALSE);
189 }
190 if (configProperty->externallyVisible)
|
191 kumpf 1.1 {
|
192 kumpf 1.3 propertyInfo.append(STRING_TRUE);
|
193 kumpf 1.1 }
194 else
195 {
|
196 kumpf 1.3 propertyInfo.append(STRING_FALSE);
|
197 kumpf 1.1 }
198 }
199
|
200 kumpf 1.3
201 /**
|
202 kumpf 1.23 Get default value of the specified property.
|
203 kumpf 1.3 */
|
204 vijay.eli 1.17 String FileSystemPropertyOwner::getDefaultValue(const String& name) const
|
205 kumpf 1.3 {
|
206 kumpf 1.23 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
|
207 vijay.eli 1.17
|
208 kumpf 1.3 return configProperty->defaultValue;
209 }
210
|
211 kumpf 1.23 /**
212 Get current value of the specified property.
|
213 kumpf 1.1 */
|
214 vijay.eli 1.17 String FileSystemPropertyOwner::getCurrentValue(const String& name) const
|
215 kumpf 1.1 {
|
216 aruran.ms 1.18 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
|
217 vijay.eli 1.17
|
218 kumpf 1.3 return configProperty->currentValue;
|
219 kumpf 1.1 }
220
|
221 kumpf 1.23 /**
222 Get planned value of the specified property.
|
223 kumpf 1.1 */
|
224 vijay.eli 1.17 String FileSystemPropertyOwner::getPlannedValue(const String& name) const
|
225 kumpf 1.1 {
|
226 aruran.ms 1.18 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
|
227 vijay.eli 1.17
|
228 kumpf 1.3 return configProperty->plannedValue;
|
229 kumpf 1.1 }
230
|
231 kumpf 1.23 /**
232 Init current value of the specified property to the specified value.
|
233 kumpf 1.1 */
234 void FileSystemPropertyOwner::initCurrentValue(
|
235 kumpf 1.23 const String& name,
|
236 kumpf 1.1 const String& value)
237 {
|
238 kumpf 1.3 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
239 configProperty->currentValue = value;
|
240 kumpf 1.1 }
241
242
|
243 kumpf 1.23 /**
244 Init planned value of the specified property to the specified value.
|
245 kumpf 1.1 */
246 void FileSystemPropertyOwner::initPlannedValue(
|
247 kumpf 1.23 const String& name,
|
248 kumpf 1.1 const String& value)
249 {
|
250 kumpf 1.3 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
251 configProperty->plannedValue = value;
|
252 kumpf 1.1 }
253
|
254 kumpf 1.23 /**
255 Update current value of the specified property to the specified value.
|
256 kumpf 1.1 */
257 void FileSystemPropertyOwner::updateCurrentValue(
|
258 kumpf 1.23 const String& name,
259 const String& value)
|
260 kumpf 1.1 {
261 //
262 // make sure the property is dynamic before updating the value.
263 //
264 if (!isDynamic(name))
265 {
|
266 kumpf 1.23 throw NonDynamicConfigProperty(name);
|
267 kumpf 1.1 }
|
268 kumpf 1.3
269 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
270 configProperty->currentValue = value;
|
271 kumpf 1.1 }
272
273
|
274 kumpf 1.23 /**
275 Update planned value of the specified property to the specified value.
|
276 kumpf 1.1 */
277 void FileSystemPropertyOwner::updatePlannedValue(
|
278 kumpf 1.23 const String& name,
|
279 kumpf 1.1 const String& value)
280 {
|
281 kumpf 1.3 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
282 configProperty->plannedValue = value;
|
283 kumpf 1.1 }
284
|
285 kumpf 1.23 /**
286 Checks to see if the given value is valid or not.
|
287 kumpf 1.1 */
|
288 kumpf 1.23 Boolean FileSystemPropertyOwner::isValid(
289 const String& name,
290 const String& value) const
|
291 kumpf 1.1 {
|
292 kumpf 1.23 if (!isDirValid(value))
|
293 kumpf 1.1 {
|
294 thilo.boehm 1.34 throw InvalidDirectoryPropertyValue(name, value);
|
295 kumpf 1.1 }
|
296 kumpf 1.23
|
297 kumpf 1.1 return true;
298 }
299
|
300 kumpf 1.23 /**
301 Checks to see if the specified property is dynamic or not.
|
302 kumpf 1.1 */
|
303 vijay.eli 1.17 Boolean FileSystemPropertyOwner::isDynamic(const String& name) const
|
304 kumpf 1.1 {
|
305 aruran.ms 1.18 struct ConfigProperty* configProperty = _lookupConfigProperty(name);
|
306 vijay.eli 1.17
|
307 kumpf 1.23 return (configProperty->dynamic == IS_DYNAMIC);
|
308 kumpf 1.1 }
309
310
311 PEGASUS_NAMESPACE_END
|