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

  1 karl  1.13 //%2005////////////////////////////////////////////////////////////////////////
  2 kumpf 1.1  //
  3 karl  1.12 // 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 karl  1.7  // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.12 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8            // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 karl  1.13 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 kumpf 1.1  //
 12            // Permission is hereby granted, free of charge, to any person obtaining a copy
 13 kumpf 1.3  // of this software and associated documentation files (the "Software"), to
 14            // deal in the Software without restriction, including without limitation the
 15            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 16 kumpf 1.1  // sell copies of the Software, and to permit persons to whom the Software is
 17            // furnished to do so, subject to the following conditions:
 18 vageesh.umesh 1.19 //
 19 kumpf         1.3  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 20 kumpf         1.1  // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 21                    // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 22 kumpf         1.3  // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 23                    // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 24                    // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 25 kumpf         1.1  // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 26                    // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27                    //
 28                    //==============================================================================
 29                    //
 30                    // Author: Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com)
 31                    //
 32 vageesh.umesh 1.19 // Modified By: Sushma Fernandes,
 33 kumpf         1.2  //                 Hewlett-Packard Company (sushma_fernandes@hp.com)
 34 vageesh.umesh 1.19 //              Yi Zhou Hewlett-Packard Company (yi_zhou@hp.com)
 35                    //              Sean Keenan (sean.keenan@hp.com)
 36 joyce.j       1.15 //              Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) for PEP # 101
 37 vageesh.umesh 1.19 //              Vageesh Umesh, IBM (vagumesh@in.ibm.com) for BUG#2543
 38 kumpf         1.1  //
 39                    //%/////////////////////////////////////////////////////////////////////////////
 40                    
 41                    #include <Pegasus/Common/Config.h>
 42                    #include <cstdlib>
 43                    //#include <dlfcn.h>
 44                    #include <Pegasus/Common/System.h>
 45 konrad.r      1.9  #include <Pegasus/Common/FileSystem.h>
 46 kumpf         1.1  #include "HandlerTable.h"
 47                    
 48 yi.zhou       1.18 PEGASUS_USING_STD;
 49 kumpf         1.1  PEGASUS_NAMESPACE_BEGIN
 50                    
 51                    HandlerTable::HandlerTable()
 52                    {
 53                    
 54                    }
 55                    
 56 yi.zhou       1.18 CIMHandler* HandlerTable::getHandler(
 57                        const String& handlerId,
 58                        CIMRepository* repository)
 59                    {
 60                        CIMHandler * handler;
 61                        {
 62                            ReadLock lock(_handlerTableLock);
 63                            handler = _lookupHandler(handlerId);
 64                    	if (handler)
 65                            {
 66                                return (handler);
 67                            }
 68                        }
 69                    
 70                        {
 71                            WriteLock lock(_handlerTableLock);
 72                    	handler = _lookupHandler(handlerId);
 73                            // Note: Lock handler table until handler initialize is done.
 74                    	// This is ok for handler since the initialization is simple.
 75                    	if (!handler)
 76                            {
 77 yi.zhou       1.18             handler = _loadHandler(handlerId);
 78                                handler->initialize(repository);
 79                            }
 80                    
 81                            return (handler);
 82                        }
 83                    }
 84                    
 85                    CIMHandler* HandlerTable::_lookupHandler(const String& handlerId)
 86 kumpf         1.1  {
 87                        for (Uint32 i = 0, n = _handlers.size(); i < n; i++)
 88                    	if (String::equal(_handlers[i].handlerId, handlerId))
 89                    	    return _handlers[i].handler;
 90                    
 91                        return 0;
 92                    }
 93                    
 94                    typedef CIMHandler* (*CreateHandlerFunc)();
 95                    
 96 yi.zhou       1.18 CIMHandler* HandlerTable::_loadHandler(const String& handlerId)
 97 kumpf         1.1  {
 98 gs.keenan     1.14 #if defined (PEGASUS_OS_VMS)
 99                        String fileName = FileSystem::buildLibraryFileName(handlerId);
100 humberto      1.16 #elif defined(PEGASUS_OS_OS400)
101 chuck         1.17     Uint32 lastSlash = handlerId.reverseFind('/');
102                        if (lastSlash == PEG_NOT_FOUND)
103                          throw DynamicLoadFailed(handlerId);
104                        String fileName = handlerId.subString(0, lastSlash);
105                        String os400HandlerId = handlerId.subString(lastSlash + 1);
106 gs.keenan     1.14 #else
107                        String fileName = ConfigManager::getHomedPath((PEGASUS_DEST_LIB_DIR) +
108                            String("/") + FileSystem::buildLibraryFileName(handlerId));
109                    #endif
110 kumpf         1.1  
111 vageesh.umesh 1.19     DynamicLibraryHandle libraryHandle =
112 kumpf         1.10 	System::loadDynamicLibrary(fileName.getCString());
113 kumpf         1.1  
114                        if (!libraryHandle) {
115 gs.keenan     1.14 #if defined(PEGASUS_OS_TYPE_WINDOWS) || defined(PEGASUS_OS_VMS)
116 kumpf         1.10 	throw DynamicLoadFailed(fileName);
117 kumpf         1.1  #else
118 kumpf         1.5          String errorMsg = System::dynamicLoadError();
119                    	throw DynamicLoadFailed(errorMsg);
120 kumpf         1.1  #endif
121                        }
122                    
123                        // Lookup the create handler symbol:
124                    
125 kumpf         1.5      String functionName = "PegasusCreateHandler_";
126 chuck         1.17 #ifndef PEGASUS_OS_OS400
127 kumpf         1.5      functionName.append(handlerId);
128 chuck         1.17 #else
129                        functionName.append(os400HandlerId);
130                    #endif
131 kumpf         1.1  
132                        CreateHandlerFunc func = (CreateHandlerFunc)System::loadDynamicSymbol(
133 kumpf         1.5  	libraryHandle, functionName.getCString());
134 kumpf         1.1  
135 yi.zhou       1.18 
136 kumpf         1.1      if (!func)
137 yi.zhou       1.18     {
138 kumpf         1.5  	throw DynamicLookupFailed(functionName);
139 yi.zhou       1.18     }
140 kumpf         1.1  
141                        // Create the handler:
142                    
143                        CIMHandler* handler = func();
144                    
145                        if (!handler)
146 yi.zhou       1.18     {
147 kumpf         1.1  	throw CreateHandlerReturnedNull(
148 vageesh.umesh 1.19 	    fileName,
149 kumpf         1.5  	    functionName);
150 yi.zhou       1.18     }
151                        else
152 kumpf         1.1      {
153                    	Entry entry;
154                    	entry.handlerId = handlerId;
155                    	entry.handler = handler;
156                    	_handlers.append(entry);
157                        }
158                    
159                        return handler;
160                    }
161                    
162 vageesh.umesh 1.19 HandlerTable::~HandlerTable()
163                    {
164 vageesh.umesh 1.20     for( Uint32 i = 0; i < _handlers.size(); i++ )
165                        {
166                            delete _handlers[i].handler;
167                        }
168 vageesh.umesh 1.19 }
169                    
170 kumpf         1.1  PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2