From: <kk...@us...> - 2008-10-06 14:56:36
|
Revision: 1073 http://omc.svn.sourceforge.net/omc/?rev=1073&view=rev Author: kkaempf Date: 2008-10-06 14:00:41 +0000 (Mon, 06 Oct 2008) Log Message: ----------- - further Perl support: load & init Perl interpreter Modified Paths: -------------- cmpi-bindings/trunk/src/CMakeLists.txt cmpi-bindings/trunk/src/cmpi_provider.c cmpi-bindings/trunk/swig/cmpi_defs.i cmpi-bindings/trunk/swig/perl/CMakeLists.txt Added Paths: ----------- cmpi-bindings/trunk/src/target_perl.c Modified: cmpi-bindings/trunk/src/CMakeLists.txt =================================================================== --- cmpi-bindings/trunk/src/CMakeLists.txt 2008-10-06 12:58:25 UTC (rev 1072) +++ cmpi-bindings/trunk/src/CMakeLists.txt 2008-10-06 14:00:41 UTC (rev 1073) @@ -16,17 +16,18 @@ # # Ruby: build standalone module, just for testing # +IF (RUBY_LIBRARY AND RUBY_INCLUDE_PATH) + ADD_DEFINITIONS(-DTARGET_RUBY) + MESSAGE(STATUS "Ruby executable: ${RUBY_EXECUTABLE}") + MESSAGE(STATUS "Ruby vendor arch dir: ${RUBY_VENDORARCH_DIR}") + MESSAGE(STATUS "Ruby include path: ${RUBY_INCLUDE_PATH}") -ADD_DEFINITIONS(-DTARGET_RUBY) -MESSAGE(STATUS "Ruby executable: ${RUBY_EXECUTABLE}") -MESSAGE(STATUS "Ruby vendor arch dir: ${RUBY_VENDORARCH_DIR}") -MESSAGE(STATUS "Ruby include path: ${RUBY_INCLUDE_PATH}") + INCLUDE_DIRECTORIES( ${RUBY_INCLUDE_PATH} ) + INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/include/cmpi ) -INCLUDE_DIRECTORIES( ${RUBY_INCLUDE_PATH} ) -INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/include/cmpi ) - -TARGET_LINK_LIBRARIES( cmpi_provider cmpi ) -TARGET_LINK_LIBRARIES( cmpi_provider ${RUBY_LIBRARY} ) + TARGET_LINK_LIBRARIES( cmpi_provider cmpi ) + TARGET_LINK_LIBRARIES( cmpi_provider ${RUBY_LIBRARY} ) +ENDIF (RUBY_LIBRARY AND RUBY_INCLUDE_PATH) # # # Modified: cmpi-bindings/trunk/src/cmpi_provider.c =================================================================== --- cmpi-bindings/trunk/src/cmpi_provider.c 2008-10-06 12:58:25 UTC (rev 1072) +++ cmpi-bindings/trunk/src/cmpi_provider.c 2008-10-06 14:00:41 UTC (rev 1073) @@ -175,7 +175,11 @@ * */ +#if defined(SWIGPERL) +static PerlInterpreter * _TARGET_INIT = 0; /* acts as a boolean - is target initialized? */ +#else static int _TARGET_INIT = 0; /* acts as a boolean - is target initialized? */ +#endif static int _MI_COUNT = 0; /* use count, number of MIs */ static pthread_mutex_t _CMPI_INIT_MUTEX = PTHREAD_MUTEX_INITIALIZER; /* mutex around _MI_COUNT */ static Target_Type _TARGET_MODULE = Target_Null; /* The target module (aka namespace) */ @@ -191,6 +195,10 @@ #include "target_ruby.c" #endif +#if defined(SWIGPERL) +#include "target_perl.c" +#endif + /* * Cleanup * Added: cmpi-bindings/trunk/src/target_perl.c =================================================================== --- cmpi-bindings/trunk/src/target_perl.c (rev 0) +++ cmpi-bindings/trunk/src/target_perl.c 2008-10-06 14:00:41 UTC (rev 1073) @@ -0,0 +1,129 @@ +/* + * target_perl.c + * + * Target language specific functions for cmpi_bindings + * + * Here: Perl + */ + +/* load <RB_BINDINGS_FILE>.pl */ +#define PL_BINDINGS_FILE "cmpi_plwbem_bindings" + +/* expect 'module <PL_BINDINGS_MODULE>' inside */ +#define PL_BINDINGS_MODULE "Cmpi" + + +/* + * get Perl exception trace -> CMPIString + * + */ + +#define TB_ERROR(str) {tbstr = str; goto cleanup;} +static CMPIString * +get_exc_trace(const CMPIBroker* broker) +{ + return broker->eft->newString(broker, "Perl failed", NULL); +} + + +/* + * Global Perl initializer + * loads the Perl interpreter + * init threads + */ + +static int +PlGlobalInitialize(const CMPIBroker* broker, CMPIStatus* st) +{ + int error; + char *embedding[] = { "", "-e", "0" }; + + if (_TARGET_INIT) + { + return 0; + } + + _SBLIM_TRACE(1,("<%d> Perl: Loading", getpid())); + + _TARGET_INIT = perl_alloc(); + perl_construct(_TARGET_INIT); + perl_parse(_TARGET_INIT, NULL, 3, embedding, NULL); + perl_run(_TARGET_INIT); + + extern void SWIG_init(PerlInterpreter* my_perl, CV* cv); + + SWIG_init(_TARGET_INIT, NULL); + + /* load module */ + perl_eval_pv("use cmpi", TRUE); + + return 0; +} + + +/*---------------------------------------------------------------*/ + +/* + * local (per MI) Perl initializer + * keeps track of reference count + */ + +static int +TargetInitialize(ProviderMIHandle* hdl, CMPIStatus* st) +{ + int error; + + /* Set _CMPI_INIT, protected by _CMPI_INIT_MUTEX + * so we call ruby_finalize() only once. + */ + if (pthread_mutex_lock(&_CMPI_INIT_MUTEX)) + { + perror("Can't lock _CMPI_INIT_MUTEX"); + abort(); + } + error = PlGlobalInitialize(hdl->broker, st); + pthread_mutex_unlock(&_CMPI_INIT_MUTEX); + if (error != 0) + { + goto exit; + } + + _SBLIM_TRACE(1,("<%d> TargetInitialize(Perl) called, miName '%s'", getpid(), hdl->miName)); +exit: + _SBLIM_TRACE(1,("Initialize() %s", (error == 0)? "succeeded":"failed")); + return error; +} + + +/* + * call_provider + * + */ + +static int +call_provider(ProviderMIHandle* hdl, CMPIStatus* st, + const char* opname, int nargs, ...) +{ + int i; + va_list vargs; + + + st->rc = CMPI_RC_OK; + return 0; +} + + +/* + * TargetCleanup + */ + +static void +TargetCleanup(void) +{ + _TARGET_MODULE = NULL; + perl_destruct(_TARGET_INIT); + perl_free(_TARGET_INIT); + + return; +} + Modified: cmpi-bindings/trunk/swig/cmpi_defs.i =================================================================== --- cmpi-bindings/trunk/swig/cmpi_defs.i 2008-10-06 12:58:25 UTC (rev 1072) +++ cmpi-bindings/trunk/swig/cmpi_defs.i 2008-10-06 14:00:41 UTC (rev 1073) @@ -120,7 +120,7 @@ #if defined(SWIGPYTHON) PyObject * #endif -#if defined(SWIGPERL5) +#if defined(SWIGPERL) SV * #endif _value() Modified: cmpi-bindings/trunk/swig/perl/CMakeLists.txt =================================================================== --- cmpi-bindings/trunk/swig/perl/CMakeLists.txt 2008-10-06 12:58:25 UTC (rev 1072) +++ cmpi-bindings/trunk/swig/perl/CMakeLists.txt 2008-10-06 14:00:41 UTC (rev 1073) @@ -23,7 +23,7 @@ ADD_CUSTOM_COMMAND ( OUTPUT ${SWIG_OUTPUT} COMMAND ${CMAKE_COMMAND} -E echo_append "Creating wrapper code for Perl ..." - COMMAND ${SWIG_EXECUTABLE} -perl -shadow -features autodoc -o ${SWIG_OUTPUT} -I${CMPI_INCLUDE_DIR} ${SWIG_INPUT} + COMMAND ${SWIG_EXECUTABLE} -perl5 -shadow -features autodoc -o ${SWIG_OUTPUT} -I${CMPI_INCLUDE_DIR} ${SWIG_INPUT} COMMAND ${CMAKE_COMMAND} -E echo "Done." WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../*.i This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |