(file) Return to tool.c CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / ProviderManager2 / CMPIR

  1 schuur 1.1 //%2003////////////////////////////////////////////////////////////////////////
  2            //
  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            //
  8            // Permission is hereby granted, free of charge, to any person obtaining a copy
  9            // of this software and associated documentation files (the "Software"), to
 10            // deal in the Software without restriction, including without limitation the
 11            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 12            // sell copies of the Software, and to permit persons to whom the Software is
 13            // furnished to do so, subject to the following conditions:
 14            //
 15            // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 16            // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 17            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 18            // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 19            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 20            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 21            // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 22 schuur 1.1 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 23            //
 24            //==============================================================================
 25            //
 26            // Author: Frank Scheffler
 27            //
 28            // Modified By:  Adrian Schuur (schuur@de.ibm.com)
 29 r.kieninger 1.2 //               Marek Szermutzky, IBM (mszermutzky@de.ibm.com)
 30 schuur      1.1 //
 31                 //%/////////////////////////////////////////////////////////////////////////////
 32                 
 33                 /*!
 34                   \file tool.c
 35                   \brief General tooling facility.
 36                 
 37                   This module offers general tooling methods that may be used by different
 38                   components on the CIMOM as well as on the remote side.
 39                 
 40                   \author Frank Scheffler
 41                 */
 42                 
 43                 #include <stdio.h>
 44 r.kieninger 1.2 #ifdef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM
 45                 #include <dll.h>
 46                 #include <errno.h>
 47                 #else
 48 schuur      1.1 #include <dlfcn.h>
 49 r.kieninger 1.2 #endif
 50 schuur      1.1 #include "tool.h"
 51 r.kieninger 1.2 #include "debug.h"
 52 schuur      1.1 
 53                 #define GENERIC_ENTRY_POINT(n) \
 54                         typedef CMPI##n##MI * (* GENERIC_##n##MI) ( CMPIBroker * broker, \
 55                 					            CMPIContext * ctx, \
 56                                                                     const char * provider )
 57                 #define FIXED_ENTRY_POINT(n) \
 58                         typedef CMPI##n##MI * (* FIXED_##n##MI) ( CMPIBroker * broker, \
 59                 					          CMPIContext * ctx )
 60                 
 61                 #define LOAD_MI(n) \
 62                         GENERIC_ENTRY_POINT(n); \
 63                         FIXED_ENTRY_POINT(n); \
 64                 \
 65                         CMPI##n##MI * tool_load_##n##MI ( const char * provider, \
 66                                                           void * library, \
 67                 					  CMPIBroker * broker, \
 68                 					  CMPIContext * ctx ) \
 69                 { \
 70                 	GENERIC_##n##MI g = \
 71                 		(GENERIC_##n##MI) \
 72                                  __get_generic_entry_point ( library, #n ); \
 73 schuur      1.1 \
 74                 	if ( g == NULL ) { \
 75                 		FIXED_##n##MI f = \
 76                 			(FIXED_##n##MI) \
 77                 			__get_fixed_entry_point ( provider, \
 78                 						  library, \
 79                 						  #n ); \
 80                 \
 81                 		if ( f == NULL ) return NULL; \
 82                 		return ( f ) ( broker, ctx ); \
 83                 	} \
 84                 	return ( g ) ( broker, ctx, provider ); \
 85                 }
 86                 
 87                 
 88                 /*****************************************************************************/
 89                 
 90                 //! Loads a dynamic load library.
 91                 /*!
 92                   Loads the libary named lib<libname>.so using dlopen().
 93                 
 94 schuur      1.1   \param libname the library name.
 95                   \return the library handle.
 96                  */
 97                 void * tool_load_lib ( const char * libname )
 98                 {
 99                   char filename[255];
100 r.kieninger 1.2   void * dllhand;
101 schuur      1.1   sprintf ( filename, "lib%s.so", libname );
102 r.kieninger 1.2   #ifndef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM
103 schuur      1.1   return dlopen ( filename, RTLD_LAZY );
104 r.kieninger 1.2   #else
105                 	dllhand = (void *) dllload ( filename );
106                 	if (dllhand == 0) TRACE_CRITICAL( ("Trying to load library: %s failed with %s\n", libname, strerror(errno)) );
107                     return dllhand;
108                   #endif
109 schuur      1.1 }
110                 
111                 
112                 static void * __get_generic_entry_point ( void * library,
113                 					  const char * ptype )
114                 {
115                 	char entry_point[255];
116 r.kieninger 1.2 	void * dll_entry;
117 schuur      1.1 	sprintf ( entry_point, "_Generic_Create_%sMI", ptype );
118                 
119 r.kieninger 1.2     #ifndef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM
120 schuur      1.1 	return dlsym ( library, entry_point );
121 r.kieninger 1.2     #else
122                 		dll_entry = (void*) dllqueryfn ( (dllhandle *) library, entry_point );
123                 		if (dll_entry == 0) TRACE_CRITICAL((stderr,"Getting generic entry point: %s failed with %s\n", entry_point, strerror(errno)));
124                 		return dll_entry;
125                     #endif
126 schuur      1.1 }
127                 
128                 
129                 static void * __get_fixed_entry_point ( const char * provider,
130                 					void * library,
131                 					const char * ptype )
132                 {
133                 	char entry_point[255];
134 r.kieninger 1.2 	void * dll_entry;
135 schuur      1.1 	sprintf ( entry_point, "%s_Create_%sMI", provider, ptype );
136                 
137 r.kieninger 1.2     #ifndef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM
138 schuur      1.1 	return dlsym ( library, entry_point );
139 r.kieninger 1.2     #else
140                 		dll_entry = (void*)dllqueryfn ( (dllhandle*) library, entry_point );
141                 		if (dll_entry == 0) TRACE_CRITICAL((stderr,"Getting fixed entry point: %s failed with %s\n", entry_point, strerror(errno)));
142                 		return dll_entry;
143                     #endif
144 schuur      1.1 }
145                 
146                 
147                 LOAD_MI(Instance);
148                 LOAD_MI(Association);
149                 LOAD_MI(Method);
150                 LOAD_MI(Property);
151                 LOAD_MI(Indication);
152                 
153                 
154                 /****************************************************************************/
155                 
156                 /*** Local Variables:  ***/
157                 /*** mode: C           ***/
158                 /*** c-basic-offset: 8 ***/
159                 /*** End:              ***/

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2