Changeset 2993
- Timestamp:
- 11/07/08 07:53:39 (2 months ago)
- Files:
-
- openwsman/trunk/src/plugins/swig/CMakeLists.txt (modified) (2 diffs)
- openwsman/trunk/src/plugins/swig/plugin.i (modified) (2 diffs)
- openwsman/trunk/src/plugins/swig/python (added)
- openwsman/trunk/src/plugins/swig/python/CMakeLists.txt (added)
- openwsman/trunk/src/plugins/swig/python/pywsmanplugin.py (added)
- openwsman/trunk/src/plugins/swig/python/tests (added)
- openwsman/trunk/src/plugins/swig/python/tests/CMakeLists.txt (added)
- openwsman/trunk/src/plugins/swig/python/tests/loading.py (added)
- openwsman/trunk/src/plugins/swig/ruby/CMakeLists.txt (modified) (5 diffs)
- openwsman/trunk/src/plugins/swig/ruby/rbwsmanplugin.rb (modified) (2 diffs)
- openwsman/trunk/src/plugins/swig/ruby/tests (added)
- openwsman/trunk/src/plugins/swig/ruby/tests/CMakeLists.txt (added)
- openwsman/trunk/src/plugins/swig/ruby/tests/loading.rb (added)
- openwsman/trunk/src/plugins/swig/src/swig-plugin.c (modified) (16 diffs)
- openwsman/trunk/src/plugins/swig/src/target_python.c (added)
- openwsman/trunk/src/plugins/swig/src/target_ruby.c (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openwsman/trunk/src/plugins/swig/CMakeLists.txt
r2848 r2993 3 3 # 4 4 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 ) 5 enable_testing() 11 6 12 7 IF ( 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." ) 16 9 ENDIF ( NOT SWIG_EXECUTABLE ) 17 10 … … 21 14 22 15 IF(BUILD_PYTHON) 23 #add_subdirectory(python)16 add_subdirectory(python) 24 17 ENDIF(BUILD_PYTHON) 18 19 IF(BUILD_PERL) 20 #add_subdirectory(perl) 21 ENDIF(BUILD_PERL) openwsman/trunk/src/plugins/swig/plugin.i
r2848 r2993 43 43 %feature("autodoc","1"); 44 44 45 %include "typemaps.i" 46 %include exception.i 47 45 48 %{ 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 111 SWIGINTERNINLINE SV *SWIG_From_long SWIG_PERL_DECL_ARGS_1(long value); 112 SWIGINTERNINLINE SV *SWIG_FromCharPtr(const char *cptr); 113 SWIGINTERNINLINE 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> 46 138 47 139 #include <wsman-soap.h> … … 50 142 51 143 %} 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 2 2 # CMakeLists.txt for openwsman/src/plugins/swig/ruby 3 3 # 4 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing")5 4 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) 5 enable_testing() 6 ADD_SUBDIRECTORY(tests) 7 8 EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['vendorarchdir']" OUTPUT_VARIABLE RUBY_ARCH_DIR) 9 EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['vendorlibdir']" OUTPUT_VARIABLE RUBY_LIB_DIR) 10 11 IF( "${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) 15 ENDIF( "${RUBY_ARCH_DIR}" STREQUAL "nil" OR "${RUBY_LIB_DIR}" STREQUAL "nil") 8 16 9 17 MESSAGE(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}")18 MESSAGE(STATUS "Ruby arch dir: ${RUBY_ARCH_DIR}") 19 MESSAGE(STATUS "Ruby lib dir: ${RUBY_LIB_DIR}") 12 20 MESSAGE(STATUS "Ruby include path: ${RUBY_INCLUDE_PATH}") 13 21 … … 18 26 OUTPUT ${SWIG_OUTPUT} 19 27 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} 21 29 COMMAND ${CMAKE_COMMAND} -E echo "Done." 22 30 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} … … 26 34 27 35 28 SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -g" )36 SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC" ) 29 37 30 38 INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/../src ) … … 38 46 39 47 # 40 # cmpi_instance: provider.so48 # wsman_ruby_plugin.so 41 49 # 42 50 43 SET( NAME wsman_ swig_plugin )51 SET( NAME wsman_ruby_plugin ) 44 52 ADD_LIBRARY( ${NAME} SHARED ${SWIG_OUTPUT}) 45 53 TARGET_LINK_LIBRARIES( ${NAME} ${RUBY_LIBRARY} ) … … 50 58 # rbwsmanplugin.rb: plugin implementation 51 59 # 52 INSTALL(FILES rbwsmanplugin.rb DESTINATION ${RUBY_ VENDOR_LIB_DIR})60 INSTALL(FILES rbwsmanplugin.rb DESTINATION ${RUBY_LIB_DIR}) openwsman/trunk/src/plugins/swig/ruby/rbwsmanplugin.rb
r2848 r2993 5 5 # 6 6 7 class WsmanPlugin 7 module WsmanPlugin 8 def self.create_plugin 9 Sample.new 10 end 11 class Sample 8 12 SCHEMA = "http://schema.opensuse.org/swig/wsman-schema/1-0" 9 13 def initialize *args … … 50 54 end 51 55 end 56 end 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 *****************************************************************************/ 1 40 2 41 #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 3 51 #include "wsman_config.h" 4 52 #endif … … 16 64 #include <wsman-declarations.h> 17 65 18 #ifdef SWIGRUBY 19 #define PLUGINSCRIPT "rbwsmanplugin" 20 #define PLUGINKLASS "WsmanPlugin" 21 static VALUE klass = 0; 66 int 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 75 static Target_Type 76 string2target(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 96 static Target_Type 97 proplist2target(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 117 static char * 118 fmtstr(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) 162 static PerlInterpreter * _TARGET_INIT = 0; /* acts as a boolean - is target initialized? */ 163 #else 164 static int _TARGET_INIT = 0; /* acts as a boolean - is target initialized? */ 165 #endif 166 static int _PLUGIN_COUNT = 0; /* use count, number of plugins */ 167 static pthread_mutex_t _PLUGIN_INIT_MUTEX = PTHREAD_MUTEX_INITIALIZER; /* mutex around _PLUGIN_COUNT */ 168 static 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" 22 181 #endif 23 182 … … 29 188 30 189 31 // Service endpoint declaration 190 /* 191 * Service endpoint declarations 192 * 193 */ 194 32 195 static int 33 196 Swig_Identify_EP( WsContextH cntx ) 34 197 { 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; 36 205 } 37 206 … … 41 210 void *opaqueData ) 42 211 { 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; 44 219 } 45 220 … … 50 225 void *opaqueData ) 51 226 { 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; 53 234 } 54 235 … … 59 240 void *opaqueData ) 60 241 { 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; 62 249 } 63 250 … … 66 253 Swig_Get_EP( SoapOpH op, void* appData, void *opaqueData ) 67 254 { 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; 69 261 } 70 262 … … 73 265 Swig_Custom_EP( SoapOpH op, void* appData, void *opaqueData ) 74 266 { 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; 76 273 } 77 274 … … 80 277 Swig_Put_EP( SoapOpH op, void* appData, void *opaqueData ) 81 278 { 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 288 static int 289 Swig_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; 89 297 } 90 298 … … 94 302 Swig_Delete_EP( SoapOpH op, void* appData, void *opaqueData ) 95 303 { 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 } 100 311 101 312 … … 123 334 END_POINT_PULL(Swig,NULL), 124 335 END_POINT_CUSTOM_METHOD(Swig, NULL), 336 END_POINT_IDENTIFY(Swig, NULL), 125 337 FINISH_END_POINTS(Swig); 126 338 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 *) 129 345 */ 130 346 131 347 void 132 get_endpoints(void *self, void * *data)348 get_endpoints(void *self, void *data_ifc) 133 349 { 134 350 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); 137 354 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 176 357 WsDispatchEndPointInfo *epi = Swig_EndPoints; 177 358 while (epi->serviceEndPoint) { … … 179 360 ++epi; 180 361 } 181 WsDispatchInterfaceInfo *ifc = (WsDispatchInterfaceInfo *)data;182 362 ifc->flags = 0; 183 363 ifc->actionUriBase = NULL; … … 185 365 ifc->config_id = "swig"; 186 366 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 189 374 ifc->compliance = XML_NS_WS_MAN; 190 375 ifc->wsmanResourceUri = NULL; 191 376 ifc->namespaces = namespaces; 192 ifc->extraData = NULL;193 377 ifc->endPoints = Swig_EndPoints; 194 378 } 195 379 196 /*===============================================================*/197 #ifdef SWIGRUBY198 199 /* protected code (might raise)200 * to load external Ruby script201 */202 static VALUE203 load_code()204 {205 fprintf(stderr, "swig-plugin.c: load_code ()\n");206 rb_require(PLUGINSCRIPT);207 }208 209 static VALUE210 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 #endif218 219 220 380 /*---------------------------------------------------------------- 221 * ?? 381 * set configuration 382 * called from wsman_init_plugins() 383 * 384 * self: p_handle 385 * config: listener->config 222 386 */ 223 387 … … 235 399 cleanup( void *self, void *data ) 236 400 { 237 #ifdef SWIGRUBY 238 ruby_finalize(); 239 #endif 240 #ifdef SWIGPYTHON 241 Py_Finalize(); 242 #endif 401 TargetCleanup( self, data ); 243 402 return; 244 403 } … … 247 406 /*---------------------------------------------------------------- 248 407 * 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 249 413 */ 250 414 … … 252 416 init( void *self, void **data ) 253 417 { 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 }
