Changeset 2993

Show
Ignore:
Timestamp:
11/07/08 07:53:39 (2 months ago)
Author:
kkaempf
Message:

use target abstraction from cmpi-bindings
support Ruby and Python for now

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openwsman/trunk/src/plugins/swig/CMakeLists.txt

    r2848 r2993  
    33# 
    44 
    5 #FIND_PACKAGE(SWIG REQUIRED) 
    6 MESSAGE(STATUS "Looking modules in ${CMAKE_MODULE_PATH}") 
    7 FIND_PROGRAM(SWIG_EXECUTABLE 
    8   NAMES swig-1.3 swig 
    9   PATHS ${SWIG_DIR} ${SWIG_DIR}/.. ${SWIG_DIR}/../../bin /usr/bin /usr/local/bin ${CMAKE_INSTALL_PREFIX}/bin 
    10 
     5enable_testing() 
    116 
    127IF ( NOT SWIG_EXECUTABLE ) 
    13   MESSAGE( FATAL "SWIG not found." ) 
    14 ELSE ( NOT SWIG_EXECUTABLE ) 
    15   MESSAGE( STATUS "SWIG found at ${SWIG_EXECUTABLE}" ) 
     8  MESSAGE( FATAL "SWIG not found, can't build swig plugins." ) 
    169ENDIF ( NOT SWIG_EXECUTABLE ) 
    1710 
     
    2114 
    2215IF(BUILD_PYTHON) 
    23 #add_subdirectory(python) 
     16add_subdirectory(python) 
    2417ENDIF(BUILD_PYTHON) 
     18 
     19IF(BUILD_PERL) 
     20#add_subdirectory(perl) 
     21ENDIF(BUILD_PERL) 
  • openwsman/trunk/src/plugins/swig/plugin.i

    r2848 r2993  
    4343%feature("autodoc","1"); 
    4444 
     45%include "typemaps.i" 
     46%include exception.i 
     47 
    4548%{ 
     49 
     50/* 
     51 * type definitions to keep the C code generic 
     52 */ 
     53  
     54#if defined(SWIGPYTHON) 
     55#define Target_Null_p(x) (x == Py_None) 
     56#define Target_INCREF(x) Py_INCREF(x) 
     57#define Target_DECREF(x) Py_DECREF(x) 
     58#define Target_True Py_True 
     59#define Target_False Py_False 
     60#define Target_Null NULL 
     61#define Target_Void Py_None 
     62#define Target_Type PyObject* 
     63#define Target_Bool(x) PyBool_FromLong(x) 
     64#define Target_WChar(x) PyInt_FromLong(x) 
     65#define Target_Int(x) PyInt_FromLong(x) 
     66#define Target_String(x) PyString_FromString(x) 
     67#define Target_Real(x) Py_None 
     68#define Target_Array() PyList_New(0) 
     69#define Target_SizedArray(len) PyList_New(len) 
     70#define Target_Append(x,y) PyList_Append(x,y) 
     71#define Target_DateTime(x) Py_None 
     72#include <Python.h> 
     73#define TARGET_THREAD_BEGIN_BLOCK SWIG_PYTHON_THREAD_BEGIN_BLOCK 
     74#define TARGET_THREAD_END_BLOCK SWIG_PYTHON_THREAD_END_BLOCK 
     75#define TARGET_THREAD_BEGIN_ALLOW SWIG_PYTHON_THREAD_BEGIN_ALLOW 
     76#define TARGET_THREAD_END_ALLOW SWIG_PYTHON_THREAD_END_ALLOW 
     77#endif 
     78 
     79#if defined(SWIGRUBY) 
     80#define Target_Null_p(x) NIL_P(x) 
     81#define Target_INCREF(x)  
     82#define Target_DECREF(x)  
     83#define Target_True Qtrue 
     84#define Target_False Qfalse 
     85#define Target_Null Qnil 
     86#define Target_Void Qnil 
     87#define Target_Type VALUE 
     88#define Target_Bool(x) ((x)?Qtrue:Qfalse) 
     89#define Target_WChar(x) INT2FIX(x) 
     90#define Target_Int(x) INT2FIX(x) 
     91#define Target_String(x) rb_str_new2(x) 
     92#define Target_Real(x) rb_float_new(x) 
     93#define Target_Array() rb_ary_new() 
     94#define Target_SizedArray(len) rb_ary_new2(len) 
     95#define Target_Append(x,y) rb_ary_push(x,y) 
     96#define Target_DateTime(x) Qnil 
     97#define TARGET_THREAD_BEGIN_BLOCK do {} while(0) 
     98#define TARGET_THREAD_END_BLOCK do {} while(0) 
     99#define TARGET_THREAD_BEGIN_ALLOW do {} while(0) 
     100#define TARGET_THREAD_END_ALLOW do {} while(0) 
     101#include <ruby.h> 
     102#include <rubyio.h> 
     103#endif 
     104 
     105#if defined(SWIGPERL) 
     106#define TARGET_THREAD_BEGIN_BLOCK do {} while(0) 
     107#define TARGET_THREAD_END_BLOCK do {} while(0) 
     108#define TARGET_THREAD_BEGIN_ALLOW do {} while(0) 
     109#define TARGET_THREAD_END_ALLOW do {} while(0) 
     110 
     111SWIGINTERNINLINE SV *SWIG_From_long  SWIG_PERL_DECL_ARGS_1(long value); 
     112SWIGINTERNINLINE SV *SWIG_FromCharPtr(const char *cptr); 
     113SWIGINTERNINLINE SV *SWIG_From_double  SWIG_PERL_DECL_ARGS_1(double value); 
     114 
     115#define Target_Null_p(x) (x == NULL) 
     116#define Target_INCREF(x)  
     117#define Target_DECREF(x)  
     118#define Target_True (&PL_sv_yes) 
     119#define Target_False (&PL_sv_no) 
     120#define Target_Null NULL 
     121#define Target_Void NULL 
     122#define Target_Type SV * 
     123#define Target_Bool(x) (x)?Target_True:Target_False 
     124#define Target_WChar(x) NULL 
     125#define Target_Int(x) SWIG_From_long(x) 
     126#define Target_String(x) SWIG_FromCharPtr(x) 
     127#define Target_Real(x) SWIG_From_double(x) 
     128#define Target_Array() (SV *)newAV() 
     129#define Target_SizedArray(len) (SV *)newAV() 
     130#define Target_Append(x,y) av_push(((AV *)(x)), y) 
     131#define Target_DateTime(x) NULL 
     132#include <perl.h> 
     133#include <EXTERN.h> 
     134#endif 
     135 
     136 
     137#include <stdint.h> 
    46138 
    47139#include <wsman-soap.h> 
     
    50142 
    51143%} 
     144 
     145/* get type declarations from openwsman client bindings */ 
     146%include "../../../bindings/wsman-types.i" 
  • openwsman/trunk/src/plugins/swig/ruby/CMakeLists.txt

    r2848 r2993  
    22# CMakeLists.txt for openwsman/src/plugins/swig/ruby 
    33# 
    4 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing") 
    54 
    6 EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['vendorarchdir']" OUTPUT_VARIABLE RUBY_VENDOR_ARCH_DIR) 
    7 EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['vendorlibdir']" OUTPUT_VARIABLE RUBY_VENDOR_LIB_DIR) 
     5enable_testing() 
     6ADD_SUBDIRECTORY(tests) 
     7 
     8EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['vendorarchdir']" OUTPUT_VARIABLE RUBY_ARCH_DIR) 
     9EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['vendorlibdir']" OUTPUT_VARIABLE RUBY_LIB_DIR) 
     10 
     11IF( "${RUBY_ARCH_DIR}" STREQUAL "nil" OR "${RUBY_LIB_DIR}" STREQUAL "nil") 
     12  MESSAGE(STATUS "Ruby too old, no vendor_dir, going for site_dir") 
     13  EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['sitearchdir']" OUTPUT_VARIABLE RUBY_ARCH_DIR) 
     14  EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['sitelibdir']" OUTPUT_VARIABLE RUBY_LIB_DIR) 
     15ENDIF( "${RUBY_ARCH_DIR}" STREQUAL "nil" OR "${RUBY_LIB_DIR}" STREQUAL "nil") 
    816 
    917MESSAGE(STATUS "Ruby executable: ${RUBY_EXECUTABLE}") 
    10 MESSAGE(STATUS "Ruby vendor arch dir: ${RUBY_VENDOR_ARCH_DIR}") 
    11 MESSAGE(STATUS "Ruby vendor lib dir: ${RUBY_VENDOR_LIB_DIR}") 
     18MESSAGE(STATUS "Ruby arch dir: ${RUBY_ARCH_DIR}") 
     19MESSAGE(STATUS "Ruby lib dir: ${RUBY_LIB_DIR}") 
    1220MESSAGE(STATUS "Ruby include path: ${RUBY_INCLUDE_PATH}") 
    1321 
     
    1826   OUTPUT  ${SWIG_OUTPUT} 
    1927   COMMAND ${CMAKE_COMMAND} -E echo_append "Creating wrapper code for ruby..." 
    20    COMMAND ${SWIG_EXECUTABLE} -ruby -autorename -o ${SWIG_OUTPUT} -I${CMPI_INCLUDE_DIR} ${SWIG_INPUT} 
     28   COMMAND ${SWIG_EXECUTABLE} -ruby -autorename -I${CMAKE_SOURCE_DIR}/include -o ${SWIG_OUTPUT} ${SWIG_INPUT} 
    2129   COMMAND ${CMAKE_COMMAND} -E echo "Done." 
    2230   WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 
     
    2634 
    2735 
    28 SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -g" ) 
     36SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC" ) 
    2937 
    3038INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/../src ) 
     
    3846 
    3947# 
    40 # cmpi_instance: provider .so 
     48# wsman_ruby_plugin.so 
    4149# 
    4250 
    43 SET( NAME wsman_swig_plugin ) 
     51SET( NAME wsman_ruby_plugin ) 
    4452ADD_LIBRARY( ${NAME} SHARED ${SWIG_OUTPUT}) 
    4553TARGET_LINK_LIBRARIES( ${NAME} ${RUBY_LIBRARY} ) 
     
    5058# rbwsmanplugin.rb: plugin implementation 
    5159# 
    52 INSTALL(FILES rbwsmanplugin.rb DESTINATION ${RUBY_VENDOR_LIB_DIR}) 
     60INSTALL(FILES rbwsmanplugin.rb DESTINATION ${RUBY_LIB_DIR}) 
  • openwsman/trunk/src/plugins/swig/ruby/rbwsmanplugin.rb

    r2848 r2993  
    55# 
    66 
    7 class WsmanPlugin 
     7module WsmanPlugin 
     8  def self.create_plugin 
     9    Sample.new 
     10  end 
     11  class Sample 
    812  SCHEMA = "http://schema.opensuse.org/swig/wsman-schema/1-0" 
    913  def initialize *args 
     
    5054  end 
    5155end 
     56end 
  • openwsman/trunk/src/plugins/swig/src/swig-plugin.c

    r2848 r2993  
     1/* 
     2 * swig-plugin.c 
     3 *  
     4 * 'C' interface for swig-based openwsman server plugins 
     5 *  
     6 * This file implements the plugin API as needed by openwsman 
     7 *  
     8 */ 
     9 
     10/***************************************************************************** 
     11* Copyright (C) 2008 Novell Inc. All rights reserved. 
     12* Copyright (C) 2008 SUSE Linux Products GmbH. All rights reserved. 
     13*  
     14* Redistribution and use in source and binary forms, with or without 
     15* modification, are permitted provided that the following conditions are met: 
     16*  
     17*   - Redistributions of source code must retain the above copyright notice, 
     18*     this list of conditions and the following disclaimer. 
     19*  
     20*   - Redistributions in binary form must reproduce the above copyright notice, 
     21*     this list of conditions and the following disclaimer in the documentation 
     22*     and/or other materials provided with the distribution. 
     23*  
     24*   - Neither the name of Novell Inc. nor of SUSE Linux Products GmbH nor the 
     25*     names of its contributors may be used to endorse or promote products 
     26*     derived from this software without specific prior written permission. 
     27*  
     28* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 
     29* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
     30* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
     31* ARE DISCLAIMED. IN NO EVENT SHALL Novell Inc. OR SUSE Linux Products GmbH OR 
     32* THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
     33* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,  
     34* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;  
     35* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,  
     36* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR  
     37* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF  
     38* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     39*****************************************************************************/ 
    140 
    241#ifdef HAVE_CONFIG_H 
     42#undef PACKAGE_NAME 
     43#undef PACKAGE_TARNAME 
     44#undef PACKAGE_VERSION 
     45#undef PACKAGE_STRING 
     46#undef PACKAGE_BUGREPORT 
     47#undef SIZEOF_SHORT 
     48#undef SIZEOF_INT 
     49#undef SIZEOF_LONG 
     50#undef SIZEOF_LONG_LONG 
    351#include "wsman_config.h" 
    452#endif 
     
    1664#include <wsman-declarations.h> 
    1765 
    18 #ifdef SWIGRUBY 
    19 #define PLUGINSCRIPT "rbwsmanplugin" 
    20 #define PLUGINKLASS "WsmanPlugin" 
    21 static VALUE klass = 0; 
     66int init( void *self, void **data ); 
     67 
     68/* 
     69 * string2target 
     70 * char* -> Target_Type 
     71 *  
     72 * *must* be called within TARGET_THREAD_BEGIN_BLOCK/TARGET_THREAD_END_BLOCK 
     73 */ 
     74 
     75static Target_Type 
     76string2target(const char *s) 
     77
     78    Target_Type obj; 
     79 
     80    if (s == NULL) 
     81        return Target_Null; 
     82 
     83    obj = Target_String(s); 
     84  
     85    return obj; 
     86
     87 
     88 
     89/* 
     90 * proplist2target 
     91 * char** -> Target_Type 
     92 *  
     93 * *must* be called within TARGET_THREAD_BEGIN_BLOCK/TARGET_THREAD_END_BLOCK 
     94 */ 
     95 
     96static Target_Type 
     97proplist2target(const char** cplist) 
     98
     99    Target_Type pl; 
     100 
     101    if (cplist == NULL) 
     102    { 
     103        Target_INCREF(Target_Void); 
     104        return Target_Void;  
     105    } 
     106  
     107    pl = Target_Array();  
     108    for (; (cplist!=NULL && *cplist != NULL); ++cplist) 
     109    { 
     110        Target_Append(pl, Target_String(*cplist));  
     111    } 
     112  
     113    return pl;  
     114
     115 
     116 
     117static char * 
     118fmtstr(const char* fmt, ...) 
     119
     120    va_list ap;  
     121    int len;  
     122    char* str; 
     123 
     124    va_start(ap, fmt);  
     125    len = vsnprintf(NULL, 0, fmt, ap);  
     126    va_end(ap);  
     127    if (len <= 0) 
     128    { 
     129        return NULL;  
     130    } 
     131    str = (char*)malloc(len+1);  
     132    if (str == NULL) 
     133    { 
     134        return NULL;  
     135    } 
     136    va_start(ap, fmt);  
     137    vsnprintf(str, len+1, fmt, ap);  
     138    va_end(ap);  
     139    return str;  
     140
     141 
     142 
     143/* 
     144**============================================================================== 
     145** 
     146** Local definitions: 
     147** 
     148**============================================================================== 
     149*/ 
     150 
     151 
     152/* 
     153 * There is one target interpreter, serving multiple plugins 
     154 * The number of plugins using the interpreter is counted in _PLUGIN_COUNT, 
     155 * when the last user goes aways, the target interpreter is unloaded. 
     156 *  
     157 * _PLUGIN_INIT_MUTEX protects this references counter from concurrent access. 
     158 *  
     159 */ 
     160 
     161#if defined(SWIGPERL) 
     162static PerlInterpreter * _TARGET_INIT = 0; /* acts as a boolean - is target initialized? */ 
     163#else 
     164static int _TARGET_INIT = 0; /* acts as a boolean - is target initialized? */ 
     165#endif 
     166static int _PLUGIN_COUNT = 0;    /* use count, number of plugins */ 
     167static pthread_mutex_t _PLUGIN_INIT_MUTEX = PTHREAD_MUTEX_INITIALIZER;  /* mutex around _PLUGIN_COUNT */ 
     168static Target_Type _TARGET_MODULE = Target_Null;  /* The target module (aka namespace) */ 
     169 
     170 
     171#if defined(SWIGPYTHON) 
     172#include "target_python.c" 
     173#endif 
     174 
     175#if defined(SWIGRUBY) 
     176#include "target_ruby.c" 
     177#endif 
     178 
     179#if defined(SWIGPERL) 
     180#include "target_perl.c" 
    22181#endif 
    23182 
     
    29188 
    30189 
    31 // Service endpoint declaration 
     190/* 
     191 * Service endpoint declarations 
     192 *  
     193 */ 
     194 
    32195static int 
    33196Swig_Identify_EP( WsContextH cntx ) 
    34197{ 
    35   return FIX2INT( rb_funcall( klass, rb_intern( "identify" ), 0 ) ); 
     198    int rc; 
     199    Target_Type _context; 
     200    TARGET_THREAD_BEGIN_BLOCK;  
     201    _context = SWIG_NewPointerObj((void*) cntx, SWIGTYPE_p__WS_CONTEXT, 0); 
     202    rc = TargetCall(_TARGET_MODULE, "identify", 1, _context);  
     203    TARGET_THREAD_END_BLOCK; 
     204    return rc; 
    36205} 
    37206 
     
    41210                void *opaqueData ) 
    42211{ 
    43   return FIX2INT( rb_funcall( klass, rb_intern( "enumerate" ), 0 ) ); 
     212    Target_Type _context; 
     213    int rc; 
     214    TARGET_THREAD_BEGIN_BLOCK;  
     215    _context = SWIG_NewPointerObj((void*) cntx, SWIGTYPE_p__WS_CONTEXT, 0); 
     216    rc = TargetCall(_TARGET_MODULE, "enumerate", 1, _context ); 
     217    TARGET_THREAD_END_BLOCK; 
     218    return rc; 
    44219} 
    45220 
     
    50225                void *opaqueData ) 
    51226{ 
    52   return FIX2INT( rb_funcall( klass, rb_intern( "release" ), 0 ) ); 
     227    Target_Type _context; 
     228    int rc; 
     229    TARGET_THREAD_BEGIN_BLOCK;  
     230    _context = SWIG_NewPointerObj((void*) cntx, SWIGTYPE_p__WS_CONTEXT, 0); 
     231    rc = TargetCall(_TARGET_MODULE, "release", 0 ); 
     232    TARGET_THREAD_END_BLOCK; 
     233    return rc; 
    53234} 
    54235 
     
    59240                void *opaqueData ) 
    60241{ 
    61   return FIX2INT( rb_funcall( klass, rb_intern( "pull" ), 0 ) ); 
     242    Target_Type _context; 
     243    int rc; 
     244    TARGET_THREAD_BEGIN_BLOCK;  
     245    _context = SWIG_NewPointerObj((void*) cntx, SWIGTYPE_p__WS_CONTEXT, 0); 
     246    rc = TargetCall(_TARGET_MODULE, "pull", 1, _context ); 
     247    TARGET_THREAD_END_BLOCK; 
     248    return rc; 
    62249} 
    63250 
     
    66253Swig_Get_EP( SoapOpH op, void* appData, void *opaqueData ) 
    67254{ 
    68   return FIX2INT( rb_funcall( klass, rb_intern( "get" ), 0 ) ); 
     255    Target_Type _context; 
     256    int rc; 
     257    TARGET_THREAD_BEGIN_BLOCK;  
     258    rc = TargetCall(_TARGET_MODULE, "get", 0 ); 
     259    TARGET_THREAD_END_BLOCK; 
     260    return rc; 
    69261} 
    70262 
     
    73265Swig_Custom_EP( SoapOpH op, void* appData, void *opaqueData ) 
    74266{ 
    75   return FIX2INT( rb_funcall( klass, rb_intern( "custom" ), 0 ) ); 
     267    Target_Type _context; 
     268    int rc; 
     269    TARGET_THREAD_BEGIN_BLOCK;  
     270    rc = TargetCall(_TARGET_MODULE, "custom", 0 ); 
     271    TARGET_THREAD_END_BLOCK; 
     272    return rc; 
    76273} 
    77274 
     
    80277Swig_Put_EP( SoapOpH op, void* appData, void *opaqueData ) 
    81278{ 
    82   return FIX2INT( rb_funcall( klass, rb_intern( "put" ), 0 ) ); 
    83 
    84  
    85  
    86 static int 
    87 Swig_Create_EP( SoapOpH op, void* appData, void *opaqueData ){ 
    88   return FIX2INT( rb_funcall( klass, rb_intern( "create" ), 0 ) ); 
     279    Target_Type _context; 
     280    int rc; 
     281    TARGET_THREAD_BEGIN_BLOCK;  
     282    rc = TargetCall(_TARGET_MODULE, "put", 0 ); 
     283    TARGET_THREAD_END_BLOCK; 
     284    return rc; 
     285
     286 
     287 
     288static int 
     289Swig_Create_EP( SoapOpH op, void* appData, void *opaqueData ) 
     290
     291    Target_Type _context; 
     292    int rc; 
     293    TARGET_THREAD_BEGIN_BLOCK;  
     294    rc = TargetCall(_TARGET_MODULE, "create", 0 ); 
     295    TARGET_THREAD_END_BLOCK; 
     296    return rc; 
    89297} 
    90298 
     
    94302Swig_Delete_EP( SoapOpH op, void* appData, void *opaqueData ) 
    95303{ 
    96   return FIX2INT( rb_funcall( klass, rb_intern( "delete" ), 0 ) ); 
    97 
    98  
    99  
     304    Target_Type _context; 
     305    int rc; 
     306    TARGET_THREAD_BEGIN_BLOCK;  
     307    rc = TargetCall(_TARGET_MODULE, "delete", 0 ); 
     308    TARGET_THREAD_END_BLOCK; 
     309    return rc; 
     310
    100311 
    101312 
     
    123334   END_POINT_PULL(Swig,NULL), 
    124335   END_POINT_CUSTOM_METHOD(Swig, NULL), 
     336   END_POINT_IDENTIFY(Swig, NULL), 
    125337FINISH_END_POINTS(Swig); 
    126338 
    127 /* register end points with server 
    128  * 
     339/*---------------------------------------------------------------- 
     340 * register end points with server 
     341 * called from wsman_init_plugins() 
     342 *  
     343 * self: p_handle 
     344 * data: ifc (WsDispatchInterfaceInfo *) 
    129345 */ 
    130346 
    131347void 
    132 get_endpoints(void *self, void **data
     348get_endpoints(void *self, void *data_ifc
    133349{ 
    134350    char *namespace = NULL; 
    135  
    136     fprintf(stderr, "swig-plugin.c: get_endpoints (%p, %p)\n", self, data); 
     351    WsDispatchInterfaceInfo *ifc = (WsDispatchInterfaceInfo *)data_ifc;  
     352 
     353    debug("get_endpoints (%p, %p)", self, ifc); 
    137354   
    138     if (!klass) 
    139       init( self, data ); 
    140     if (!klass) 
    141       return; 
    142 #ifdef SWIGRUBY 
    143     /* 
    144      * Get namespaces 
    145      */ 
    146    
    147     list_t *namespaces = list_create(LISTCOUNT_T_MAX); 
    148     VALUE rbnamespaces = rb_funcall( klass, rb_intern( "namespaces" ), 0 ); 
    149     VALUE ary = rb_check_array_type( rbnamespaces ); 
    150     if (NIL_P(ary)) { 
    151       rb_raise( rb_eArgError, "%s.namespaces is not array", PLUGINKLASS); 
    152     } 
    153     int len = RARRAY(ary)->len; 
    154     if (len <= 0) { 
    155       rb_raise( rb_eArgError, "%s.namespaces returned array with %d elements", PLUGINKLASS, len); 
    156     } 
    157     int i; 
    158     for (i = 0; i < len; ++i) { 
    159       lnode_t *node; 
    160       VALUE elem = RARRAY(ary)->ptr[i]; 
    161       VALUE pair = rb_check_array_type( elem ); 
    162       if (NIL_P(pair)) { 
    163         rb_raise( rb_eArgError, "%s.namespaces must return array of arrays", PLUGINKLASS); 
    164       } 
    165       if (RARRAY(pair)->len != 2) { 
    166         rb_raise( rb_eArgError, "%s.namespaces must return array of ['<namespace>','<class_prefix>']", PLUGINKLASS); 
    167       } 
    168       WsSupportedNamespaces *ns = (WsSupportedNamespaces *)u_malloc(sizeof(WsSupportedNamespaces)); 
    169       ns->ns = StringValuePtr( RARRAY(pair)->ptr[0] ); 
    170       if (namespace == 0) namespace = ns->ns; 
    171       ns->class_prefix = StringValuePtr( RARRAY(pair)->ptr[1] ); 
    172       node = lnode_create(ns); 
    173       list_append(namespaces, node); 
    174     } 
    175 #endif 
     355    list_t *namespaces = TargetEndpoints( self, ifc->extraData ); 
     356 
    176357    WsDispatchEndPointInfo *epi = Swig_EndPoints; 
    177358    while (epi->serviceEndPoint) { 
     
    179360      ++epi; 
    180361    } 
    181     WsDispatchInterfaceInfo *ifc = (WsDispatchInterfaceInfo *)data;      
    182362    ifc->flags = 0; 
    183363    ifc->actionUriBase = NULL; 
     
    185365    ifc->config_id = "swig"; 
    186366    ifc->vendor = "Novell, Inc."; 
    187     ifc->displayName = PLUGINSCRIPT; 
    188     ifc->notes = "Swig based Ruby plugin"; 
     367    ifc->displayName = PLUGIN_FILE; 
     368#if defined(SWIGPYTHON) 
     369    ifc->notes = "Python plugin"; 
     370#endif 
     371#if defined(SWIGRUBY) 
     372    ifc->notes = "Ruby plugin"; 
     373#endif 
    189374    ifc->compliance = XML_NS_WS_MAN; 
    190375    ifc->wsmanResourceUri = NULL; 
    191376    ifc->namespaces = namespaces; 
    192     ifc->extraData = NULL; 
    193377    ifc->endPoints = Swig_EndPoints; 
    194378} 
    195379 
    196 /*===============================================================*/ 
    197 #ifdef SWIGRUBY 
    198  
    199 /* protected code (might raise) 
    200  *  to load external Ruby script 
    201  */ 
    202 static VALUE 
    203 load_code() 
    204 {     
    205     fprintf(stderr, "swig-plugin.c: load_code ()\n"); 
    206     rb_require(PLUGINSCRIPT); 
    207 } 
    208  
    209 static VALUE 
    210 create_plugin() 
    211 { 
    212     fprintf(stderr, "swig-plugin.c: create_plugin ()\n"); 
    213     klass = rb_class_new_instance(0, NULL, rb_const_get(rb_cObject, rb_intern(PLUGINKLASS))); 
    214     fprintf(stderr, "swig-plugin.c: create_plugin => %p\n", klass); 
    215     return klass; 
    216 } 
    217 #endif 
    218  
    219  
    220380/*---------------------------------------------------------------- 
    221  * ?? 
     381 * set configuration 
     382 * called from wsman_init_plugins() 
     383 *  
     384 * self: p_handle 
     385 * config: listener->config 
    222386 */ 
    223387 
     
    235399cleanup( void  *self, void *data ) 
    236400{ 
    237 #ifdef SWIGRUBY 
    238     ruby_finalize(); 
    239 #endif 
    240 #ifdef SWIGPYTHON 
    241     Py_Finalize(); 
    242 #endif 
     401    TargetCleanup( self, data ); 
    243402    return; 
    244403} 
     
    247406/*---------------------------------------------------------------- 
    248407 * initialize plugin 
     408 * return zero on error 
     409 *  
     410 * self: p_handle 
     411 * data: pointer to 'void *data' 
     412 *   init can fill this data which is passed to every other call 
    249413 */ 
    250414 
     
    252416init( void *self, void **data ) 
    253417{ 
    254     fprintf(stderr, "swig-plugin.c: init (%p, %p)\n", self, data); 
    255     int rc = 1; 
    256 #ifdef SWIGRUBY 
    257     int error = 0; 
    258     ruby_init(); 
    259     ruby_init_loadpath(); 
    260     /* name the script */ 
    261     ruby_script(PLUGINSCRIPT); 
    262     /* load the script */ 
    263     rb_protect(load_code, Qnil, &error); 
    264     if (error) { 
    265         debug("Ruby: FAILED loading %s.rb", PLUGINSCRIPT); 
    266         rc = 0; 
    267     } 
    268     else { 
    269         VALUE wsmanplugin; 
    270         debug("Ruby: loaded %s.rb", PLUGINSCRIPT); 
    271         wsmanplugin = rb_protect(create_plugin, Qnil, &error); 
    272         if (error) { 
    273             debug("Ruby: FAILED creating %s", PLUGINKLASS); 
    274             rc = 0; 
    275         } 
    276         else { 
    277             debug("Ruby: WsmanPlugin at %p", wsmanplugin); 
    278         } 
    279     } 
    280 #endif 
    281     return rc; 
    282 
     418    return (TargetInitialize( self, data ) == 0); 
     419