(file) Return to DynamicListenerConfig.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / DynListener

  1 martin 1.7 //%LICENSE////////////////////////////////////////////////////////////////
  2 martin 1.8 //
  3 martin 1.7 // 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.8 //
 10 martin 1.7 // 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.8 //
 17 martin 1.7 // The above copyright notice and this permission notice shall be included
 18            // in all copies or substantial portions of the Software.
 19 martin 1.8 //
 20 martin 1.7 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21 martin 1.8 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 martin 1.7 // 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.8 //
 28 martin 1.7 //////////////////////////////////////////////////////////////////////////
 29 h.sterling 1.1 //
 30                //%/////////////////////////////////////////////////////////////////////////////
 31                
 32                #include <Pegasus/Common/Config.h>
 33                #include <Pegasus/Common/FileSystem.h>
 34                #include <Pegasus/Common/Tracer.h>
 35                #include <Pegasus/Common/Exception.h>
 36                
 37 thilo.boehm 1.10 #include <Pegasus/General/OptionManager.h>
 38                  
 39 h.sterling  1.1  #include "DynamicListenerConfig.h"
 40                  
 41                  PEGASUS_NAMESPACE_BEGIN
 42                  PEGASUS_USING_STD;
 43                  
 44                  
 45                  const String LISTENER_HOME_DEFAULT  = ".";
 46                  String DynamicListenerConfig::_listenerHome = LISTENER_HOME_DEFAULT;
 47                  
 48                  
 49                  static struct OptionRow optionsTable[] =
 50                  //optionname defaultvalue rqd  type domain domainsize clname hlpmsg
 51                  {
 52                  
 53 kumpf       1.9  {"listenerPort", "5999", false, Option::WHOLE_NUMBER, 0, 0,
 54 marek       1.6   "listenerPort", "specifies system and port"},
 55 h.sterling  1.1  #ifdef PEGASUS_HAS_SSL
 56 marek       1.6  {"enableHttpsListenerConnection", "false", false, Option::BOOLEAN, 0, 0,
 57                   "enableHttpsListenerConnection", "specifies namespace to use for operation"},
 58 h.sterling  1.1  
 59 marek       1.6  {"sslKeyFilePath", "", false, Option::STRING, 0, 0,
 60                   "sslKeyFilePath", "path to the listener's SSL private key"},
 61 h.sterling  1.1  
 62 marek       1.6  {"sslCertificateFilePath", "", false, Option::STRING, 0, 0,
 63                   "sslCertificateFilePath",
 64                   "path to the listener's SSL public key certificate."},
 65 h.sterling  1.1  #endif
 66 marek       1.6  {"consumerDir", "", false, Option::STRING, 0, 0,
 67                   "consumerDir", "path to the consumer libraries"},
 68 h.sterling  1.1  
 69 marek       1.6  {"consumerConfigDir", "", false, Option::STRING, 0, 0,
 70                   "consumerConfigDir", "path to the consumer configuration files"},
 71 h.sterling  1.1  
 72 marek       1.6  {"enableConsumerUnload", "false", false, Option::BOOLEAN, 0, 0,
 73                   "enableConsumerUnload",
 74                   "specifies whether the listener should unload idle consumers"},
 75 h.sterling  1.1  
 76 marek       1.6  {"consumerIdleTimeout", "300000", false, Option::WHOLE_NUMBER, 0, 0,
 77                   "consumerIdleTimeout",
 78                   "period of inactivity, in ms, before consumers are unloaded"},
 79 h.sterling  1.1  
 80 marek       1.6  {"shutdownTimeout", "10000", false, Option::WHOLE_NUMBER, 0, 0,
 81                   "shutdownTimeout",
 82                   "the length of time to wait for consumer threads to complete, in ms"},
 83 h.sterling  1.1  
 84 marek       1.6  {"traceFilePath", "cimlistener.trc", false, Option::STRING, 0, 0,
 85                   "traceFilePath", "path to the listener's trace file"},
 86 h.sterling  1.1  
 87 marek       1.6  {"traceLevel", "0", false, Option::WHOLE_NUMBER, 0, 0,
 88                   "traceLevel", "the level of logging detail"},
 89 h.sterling  1.1  
 90 marek       1.6  {"traceComponents", "LISTENER", false, Option::STRING, 0, 0,
 91                   "traceComponents", "the components to trace"},
 92 h.sterling  1.1  
 93                  };
 94                  
 95                  const Uint32 NUM_OPTIONS = sizeof(optionsTable) / sizeof(optionsTable[0]);
 96                  
 97                  DynamicListenerConfig* DynamicListenerConfig::_instance = 0;
 98                  
 99                  DynamicListenerConfig::DynamicListenerConfig()
100                  {
101                      FileSystem::getCurrentDirectory(_listenerHome);
102                      FileSystem::translateSlashes(_listenerHome);
103                  }
104                  
105                  DynamicListenerConfig::~DynamicListenerConfig()
106                  {
107                  }
108                  
109                  DynamicListenerConfig* DynamicListenerConfig::getInstance()
110                  {
111                      if (!_instance)
112                      {
113 h.sterling  1.1          _instance = new DynamicListenerConfig();
114 kumpf       1.9      }
115 h.sterling  1.1  
116                      return _instance;
117                  }
118                  
119                  void DynamicListenerConfig::initOptions(const String& configFile)
120                  {
121                      _optionMgr.registerOptions(optionsTable, NUM_OPTIONS);
122                  
123                      //do not throw an error if there's no config file; just use the defaults
124                      if (FileSystem::exists(configFile))
125                      {
126                          _optionMgr.mergeFile(configFile);
127                      }
128                  
129                      _optionMgr.checkRequiredOptions();
130                  }
131                  
132 marek       1.6  Boolean DynamicListenerConfig::lookupValue(
133                              const String& name,
134                              String& value) const
135 h.sterling  1.1  {
136                      String temp;
137                      if (!_optionMgr.lookupValue(name, temp))
138                      {
139                          return false;
140                      }
141                  
142 marek       1.6      if (String::equal(name, "consumerDir") ||
143                          String::equal(name, "consumerConfigDir"))
144 h.sterling  1.1      {
145                          value = DynamicListenerConfig::getHomedPath(temp);
146                  
147 marek       1.6          if (!FileSystem::exists(value) ||
148                              !FileSystem::isDirectory(value) ||
149                              !FileSystem::canRead(value))
150 h.sterling  1.1          {
151                              throw OMInvalidOptionValue(name, value);
152                          }
153                  
154 kumpf       1.9          // must be able to write pending requests to
155 marek       1.6          // .dat files in the config directory
156                          if (String::equal(name, "consumerConfigDir") &&
157                              !FileSystem::canWrite(value))
158 h.sterling  1.1          {
159                              throw OMInvalidOptionValue(name, value);
160                          }
161                  
162                      } else if (String::equal(name, "traceFilePath"))
163                      {
164 marek       1.6          //a blank value is acceptable and indicates
165                          // that no tracing will be done
166 h.sterling  1.1          if (String::equal(temp, ""))
167                          {
168                              value = String::EMPTY;
169                              return true;
170                          }
171                  
172 marek       1.6          value = DynamicListenerConfig::getHomedPath(temp);
173 h.sterling  1.2  
174 marek       1.6          //check to make sure we can create trace file
175                          String path = FileSystem::extractFilePath(value);
176 h.sterling  1.1  
177 h.sterling  1.2          if (!FileSystem::exists(path) || !FileSystem::canWrite(path))
178 h.sterling  1.1          {
179 h.sterling  1.2              throw OMInvalidOptionValue(name, value);
180 h.sterling  1.1          }
181 kumpf       1.9      }
182 h.sterling  1.1  #ifdef PEGASUS_HAS_SSL
183 kumpf       1.9      else if (String::equal(name, "sslKeyFilePath") ||
184 marek       1.6               String::equal(name, "sslCertificateFilePath"))
185 h.sterling  1.1      {
186                          //a blank value is acceptable and is the default
187                          if (String::equal(temp, ""))
188                          {
189                              value = String::EMPTY;
190                              return true;
191                          }
192                  
193                          value = DynamicListenerConfig::getHomedPath(temp);
194                  
195                          if (!FileSystem::exists(value) || !FileSystem::canRead(value))
196                          {
197                              throw OMInvalidOptionValue(name, value);
198                          }
199                      }
200                  #endif
201                      else
202                      {
203                          value = temp;
204                      }
205                  
206 h.sterling  1.1      return true;
207                  }
208                  
209                  
210 marek       1.6  Boolean DynamicListenerConfig::lookupIntegerValue(
211                              const String& name,
212                              Uint32& value) const
213 h.sterling  1.1  {
214                      if (!_optionMgr.lookupIntegerValue(name, value))
215                      {
216                          return false;
217                      }
218                  
219                      if (String::equal(name, "listenerPort"))
220                      {
221                      } else if (String::equal(name, "consumerIdleTimeout"))
222                      {
223                      } else if (String::equal(name, "shutdownTimeout"))
224                      {
225                      } else if (String::equal(name, "traceLevel"))
226                      {
227 h.sterling  1.3          if (value > 4)
228 h.sterling  1.1          {
229                              throw OMInvalidOptionValue(name, "");
230                          }
231                      }
232                  
233                      return true;
234                  }
235                  
236 marek       1.6  Boolean DynamicListenerConfig::valueEquals(
237                              const String& name,
238                              const String& value) const
239 h.sterling  1.1  {
240                      //not implemented yet -- do we need this in addition to lookupValue()?
241                      return _optionMgr.valueEquals(name, value);
242                  }
243                  
244                  Boolean DynamicListenerConfig::isTrue(const String& name) const
245                  {
246                      //no additional checking for booleans
247                      return _optionMgr.isTrue(name);
248                  }
249                  
250                  String DynamicListenerConfig::getListenerHome()
251                  {
252                      return _listenerHome;
253                  }
254                  
255                  //This sets the listener home to the FULL path
256                  //We do it once here so we do not have to keep doing file operations later on
257                  void DynamicListenerConfig::setListenerHome(const String& home)
258                  {
259 marek       1.6      PEG_METHOD_ENTER(TRC_LISTENER, "DynamicListenerConfig::setListenerHome");
260 h.sterling  1.2  
261 h.sterling  1.1      if (System::is_absolute_path((const char *)home.getCString()))
262                      {
263                          _listenerHome = home;
264                  
265                      } else
266                      {
267                          String currentDir;
268                          FileSystem::getCurrentDirectory(currentDir);
269 marek       1.6          _listenerHome = FileSystem::getAbsolutePath(
270                                              (const char*)currentDir.getCString(),
271                                              home);
272 h.sterling  1.1      }
273 h.sterling  1.2  
274 marek       1.6      PEG_METHOD_EXIT();
275 h.sterling  1.1  }
276                  
277                  String DynamicListenerConfig::getHomedPath(const String& value)
278                  {
279 h.sterling  1.2      PEG_METHOD_ENTER(TRC_LISTENER, "DynamicListenerConfig::getHomedPath()");
280                  
281 kumpf       1.5      String homedPath;
282 h.sterling  1.1  
283                      if (String::equal(value, String::EMPTY))
284                      {
285                          homedPath = _listenerHome;
286                  
287                      } else
288                      {
289 marek       1.6          homedPath = FileSystem::getAbsolutePath(
290                                          (const char*)_listenerHome.getCString(),
291                                          value);
292                      }
293 h.sterling  1.1      FileSystem::translateSlashes(homedPath);
294                  
295                      PEG_METHOD_EXIT();
296                      return homedPath;
297                  }
298                  
299                  
300                  
301                  
302                  
303                  PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2