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

  1 karl  1.4 //%2006////////////////////////////////////////////////////////////////////////
  2 h.sterling 1.1 //
  3                // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  4                // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  5                // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  6                // IBM Corp.; EMC Corporation, The Open Group.
  7                // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8                // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9                // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10                // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl       1.4 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12                // EMC Corporation; Symantec Corporation; The Open Group.
 13 h.sterling 1.1 //
 14                // Permission is hereby granted, free of charge, to any person obtaining a copy
 15                // of this software and associated documentation files (the "Software"), to
 16                // deal in the Software without restriction, including without limitation the
 17                // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 18                // sell copies of the Software, and to permit persons to whom the Software is
 19                // furnished to do so, subject to the following conditions:
 20                // 
 21                // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22                // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 23                // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 24                // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 25                // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 26                // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 27                // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 28                // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 29                //
 30                //==============================================================================
 31                //
 32                //%/////////////////////////////////////////////////////////////////////////////
 33                
 34 h.sterling 1.1 #include <Pegasus/Common/Config.h>
 35                #include <Pegasus/Common/OptionManager.h>
 36                #include <Pegasus/Common/FileSystem.h>
 37                #include <Pegasus/Common/Tracer.h>
 38                #include <Pegasus/Common/Exception.h>
 39                
 40                #include "DynamicListenerConfig.h"
 41                
 42                PEGASUS_NAMESPACE_BEGIN
 43                PEGASUS_USING_STD;
 44                
 45                
 46                const String LISTENER_HOME_DEFAULT  = ".";
 47                String DynamicListenerConfig::_listenerHome = LISTENER_HOME_DEFAULT;
 48                
 49                
 50                static struct OptionRow optionsTable[] =
 51                //optionname defaultvalue rqd  type domain domainsize clname hlpmsg
 52                {
 53                
 54                {"listenerPort", "5999", false, Option::WHOLE_NUMBER, 0, 0, "listenerPort", "specifies system and port"},
 55 h.sterling 1.1 #ifdef PEGASUS_HAS_SSL
 56                {"enableHttpsListenerConnection", "false", false, Option::BOOLEAN, 0, 0, "enableHttpsListenerConnection", "specifies namespace to use for operation"},
 57                
 58                {"sslKeyFilePath", "", false, Option::STRING, 0, 0, "sslKeyFilePath", "path to the listener's SSL private key"},
 59                
 60                {"sslCertificateFilePath", "", false, Option::STRING, 0, 0, "sslCertificateFilePath", "path to the listener's SSL public key certificate."},
 61                #endif
 62                {"consumerDir", "", false, Option::STRING, 0, 0, "consumerDir", "path to the consumer libraries"},
 63                
 64                {"consumerConfigDir", "", false, Option::STRING, 0, 0, "consumerConfigDir", "path to the consumer configuration files"},
 65                
 66                {"enableConsumerUnload", "false", false, Option::BOOLEAN, 0, 0, "enableConsumerUnload", "specifies whether the listener should unload idle consumers"},
 67                
 68                {"consumerIdleTimeout", "300000", false, Option::WHOLE_NUMBER, 0, 0, "consumerIdleTimeout", "period of inactivity, in ms, before consumers are unloaded"},
 69                
 70                {"shutdownTimeout", "10000", false, Option::WHOLE_NUMBER, 0, 0, "shutdownTimeout", "the length of time to wait for consumer threads to complete, in ms"},
 71                
 72                {"traceFilePath", "cimlistener.trc", false, Option::STRING, 0, 0, "traceFilePath", "path to the listener's trace file"},
 73                
 74                {"traceLevel", "0", false, Option::WHOLE_NUMBER, 0, 0, "traceLevel", "the level of logging detail"},
 75                
 76 h.sterling 1.1 {"traceComponents", "LISTENER", false, Option::STRING, 0, 0, "traceComponents", "the components to trace"},
 77                
 78                };
 79                
 80                const Uint32 NUM_OPTIONS = sizeof(optionsTable) / sizeof(optionsTable[0]);
 81                
 82                DynamicListenerConfig* DynamicListenerConfig::_instance = 0;
 83                
 84                DynamicListenerConfig::DynamicListenerConfig()
 85                {
 86                    FileSystem::getCurrentDirectory(_listenerHome);
 87                    FileSystem::translateSlashes(_listenerHome);
 88                }
 89                
 90                DynamicListenerConfig::~DynamicListenerConfig()
 91                {
 92                }
 93                
 94                DynamicListenerConfig* DynamicListenerConfig::getInstance()
 95                {
 96                    if (!_instance)
 97 h.sterling 1.1     {
 98                        _instance = new DynamicListenerConfig();
 99 h.sterling 1.2     } 
100 h.sterling 1.1 
101                    return _instance;
102                }
103                
104                void DynamicListenerConfig::initOptions(const String& configFile)
105                {
106                    _optionMgr.registerOptions(optionsTable, NUM_OPTIONS);
107                
108                    //do not throw an error if there's no config file; just use the defaults
109                    if (FileSystem::exists(configFile))
110                    {
111                        _optionMgr.mergeFile(configFile);
112                    }
113                
114                    _optionMgr.checkRequiredOptions();
115                }
116                
117                Boolean DynamicListenerConfig::lookupValue(const String& name, String& value) const
118                {
119                    String temp;
120                    if (!_optionMgr.lookupValue(name, temp))
121 h.sterling 1.1     {
122                        return false;
123                    }
124                
125                    if (String::equal(name, "consumerDir") || String::equal(name, "consumerConfigDir"))
126                    {
127                        value = DynamicListenerConfig::getHomedPath(temp);
128                
129                        if (!FileSystem::exists(value) || !FileSystem::isDirectory(value) || !FileSystem::canRead(value))
130                        {
131                            throw OMInvalidOptionValue(name, value);
132                        }
133                
134                        //must be able to write pending requests to .dat files in the config directory
135                        if (String::equal(name, "consumerConfigDir") && !FileSystem::canWrite(value))
136                        {
137                            throw OMInvalidOptionValue(name, value);
138                        }
139                
140                    } else if (String::equal(name, "traceFilePath"))
141                    {
142 h.sterling 1.2         //a blank value is acceptable and indicates that no tracing will be done
143 h.sterling 1.1         if (String::equal(temp, ""))
144                        {
145                            value = String::EMPTY;
146                            return true;
147                        }
148                
149 h.sterling 1.2 		value = DynamicListenerConfig::getHomedPath(temp);
150                
151                		//check to make sure we can create trace file
152                		String path = FileSystem::extractFilePath(value);
153 h.sterling 1.1 
154 h.sterling 1.2         if (!FileSystem::exists(path) || !FileSystem::canWrite(path))
155 h.sterling 1.1         {
156 h.sterling 1.2             throw OMInvalidOptionValue(name, value);
157 h.sterling 1.1         }
158                    } 
159                #ifdef PEGASUS_HAS_SSL
160                    else if (String::equal(name, "sslKeyFilePath") || String::equal(name, "sslCertificateFilePath"))
161                    {
162                        //a blank value is acceptable and is the default
163                        if (String::equal(temp, ""))
164                        {
165                            value = String::EMPTY;
166                            return true;
167                        }
168                
169                        value = DynamicListenerConfig::getHomedPath(temp);
170                
171                        if (!FileSystem::exists(value) || !FileSystem::canRead(value))
172                        {
173                            throw OMInvalidOptionValue(name, value);
174                        }
175                    }
176                #endif
177                    else
178 h.sterling 1.1     {
179                        value = temp;
180                    }
181                
182                    return true;
183                }
184                
185                
186                Boolean DynamicListenerConfig::lookupIntegerValue(const String& name, Uint32& value) const
187                {
188                    if (!_optionMgr.lookupIntegerValue(name, value))
189                    {
190                        return false;
191                    }
192                
193                    if (String::equal(name, "listenerPort"))
194                    {
195                    } else if (String::equal(name, "consumerIdleTimeout"))
196                    {
197                    } else if (String::equal(name, "shutdownTimeout"))
198                    {
199 h.sterling 1.1     } else if (String::equal(name, "traceLevel"))
200                    {
201 h.sterling 1.3         if (value > 4)
202 h.sterling 1.1         {
203                            throw OMInvalidOptionValue(name, "");
204                        }
205                    }
206                
207                    return true;
208                }
209                
210                Boolean DynamicListenerConfig::valueEquals(const String& name, const String& value) const
211                {
212                    //not implemented yet -- do we need this in addition to lookupValue()?
213                    return _optionMgr.valueEquals(name, value);
214                }
215                
216                Boolean DynamicListenerConfig::isTrue(const String& name) const
217                {
218                    //no additional checking for booleans
219                    return _optionMgr.isTrue(name);
220                }
221                
222                String DynamicListenerConfig::getListenerHome()
223 h.sterling 1.1 {
224                    return _listenerHome;
225                }
226                
227                //This sets the listener home to the FULL path
228                //We do it once here so we do not have to keep doing file operations later on
229                void DynamicListenerConfig::setListenerHome(const String& home)
230                {
231 h.sterling 1.2 	PEG_METHOD_ENTER(TRC_LISTENER, "DynamicListenerConfig::setListenerHome");
232                
233 h.sterling 1.1     if (System::is_absolute_path((const char *)home.getCString()))
234                    {
235                        _listenerHome = home;
236                
237                    } else
238                    {
239                        String currentDir;
240                        FileSystem::getCurrentDirectory(currentDir);
241                        _listenerHome = FileSystem::getAbsolutePath((const char*)currentDir.getCString(), home);
242                    }
243 h.sterling 1.2 
244                	PEG_METHOD_EXIT();
245 h.sterling 1.1 }
246                
247                String DynamicListenerConfig::getHomedPath(const String& value)
248                {
249 h.sterling 1.2     PEG_METHOD_ENTER(TRC_LISTENER, "DynamicListenerConfig::getHomedPath()");
250                
251 kumpf      1.5     String homedPath;
252 h.sterling 1.1 
253                    if (String::equal(value, String::EMPTY))
254                    {
255                        homedPath = _listenerHome;
256                
257                    } else
258                    {
259 h.sterling 1.2 		homedPath = FileSystem::getAbsolutePath((const char*)_listenerHome.getCString(), value);
260                	}
261 h.sterling 1.1     FileSystem::translateSlashes(homedPath);
262                
263                    PEG_METHOD_EXIT();
264                    return homedPath;
265                }
266                
267                
268                
269                
270                
271                PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2