From: <kk...@us...> - 2008-10-01 14:21:49
|
Revision: 1057 http://omc.svn.sourceforge.net/omc/?rev=1057&view=rev Author: kkaempf Date: 2008-10-01 14:19:39 +0000 (Wed, 01 Oct 2008) Log Message: ----------- some improvements on the Ruby side Modified Paths: -------------- cmpi-bindings/trunk/src/target_ruby.c cmpi-bindings/trunk/swig/ruby/cmpi_rbwbem_bindings.rb Added Paths: ----------- cmpi-bindings/trunk/test/ruby/ cmpi-bindings/trunk/test/ruby/TestAtomProvider.peg.reg cmpi-bindings/trunk/test/ruby/TestAtomProvider.reg cmpi-bindings/trunk/test/ruby/TestAtomProvider.sfcb.reg cmpi-bindings/trunk/test/ruby/setup.sh cmpi-bindings/trunk/test/ruby/test_atom_provider.rb Modified: cmpi-bindings/trunk/src/target_ruby.c =================================================================== --- cmpi-bindings/trunk/src/target_ruby.c 2008-09-30 12:57:40 UTC (rev 1056) +++ cmpi-bindings/trunk/src/target_ruby.c 2008-10-01 14:19:39 UTC (rev 1057) @@ -10,7 +10,7 @@ #define RB_BINDINGS_FILE "cmpi_rbwbem_bindings" /* expect 'module <RB_BINDINGS_MODULE>' inside */ -#define RB_BINDINGS_MODULE "RbCmpi" +#define RB_BINDINGS_MODULE "Cmpi" /* * load_module @@ -43,14 +43,41 @@ create_mi(VALUE args) { VALUE *values = (VALUE *)args; - _SBLIM_TRACE(1,("Ruby: <MIclass>.new ...")); - VALUE klass = rb_class_new_instance(1, values, rb_const_get(_TARGET_MODULE, values[1])); - _SBLIM_TRACE(1,("Ruby: ... done")); - return klass; + _SBLIM_TRACE(1,("Ruby: %s.new ...", rb_id2name(values[1]))); + VALUE klass = rb_const_get(_TARGET_MODULE, values[1]); + _SBLIM_TRACE(1,("Ruby: ... klass -> %ld", klass)); + if (NIL_P(klass)) + { + _SBLIM_TRACE(1,("Ruby: ... klass is NULL")); + return klass; + } + VALUE instance = rb_class_new_instance(1, values, klass); + _SBLIM_TRACE(1,("Ruby: ... done -> %ld", instance)); + return instance; } /* + * call_mi + * call function of instance + * + * I args: pointer to array of at least 3 values + * args[0] -> (VALUE) instance + * args[1] -> (VALUE) id of function + * args[2] -> (int) number of arguments + * args[3...n] -> (VALUE) arguments + */ + +static VALUE +call_mi(VALUE args) +{ + VALUE *values = (VALUE *)args; + return rb_funcall3(values[0], values[1], (int)values[2], values+3); +} + + + +/* * Global Ruby initializer * loads the Ruby interpreter * init threads @@ -81,12 +108,18 @@ rb_protect(load_module, Qnil, &error); if (error) { - _SBLIM_TRACE(1,("<%d> Ruby: import '%s' failed", getpid(), RB_BINDINGS_FILE)); + _SBLIM_TRACE(1,("<%d> Ruby: import '%s' failed, error %d", getpid(), RB_BINDINGS_FILE, error)); /* _CMPI_SETFAIL(<CMPIString *>); */ abort(); return -1; } - _TARGET_MODULE = rb_intern(RB_BINDINGS_MODULE); + _TARGET_MODULE = rb_const_get(rb_cModule, rb_intern(RB_BINDINGS_MODULE)); + if (NIL_P(_TARGET_MODULE)) + { + _SBLIM_TRACE(1,("<%d> Ruby: import '%s' doesn't define module '%s'", getpid(), RB_BINDINGS_MODULE)); + st->rc = CMPI_RC_ERR_NOT_FOUND; + return -1; + } _SBLIM_TRACE(1,("<%d> RbGlobalInitialize() succeeded -> %ld", getpid(), _TARGET_MODULE)); return 0; } @@ -120,18 +153,17 @@ goto exit; } - _SBLIM_TRACE(1,("<%d> TargetInitialize(Ruby) called", getpid())); - + _SBLIM_TRACE(1,("<%d> TargetInitialize(Ruby) called, miName '%s'", getpid(), hdl->miName)); + args[0] = SWIG_NewPointerObj((void*) hdl->broker, SWIGTYPE_p__CMPIBroker, 0); - args[1] = rb_str_new2(hdl->miName); + args[1] = rb_intern(hdl->miName); hdl->instance = rb_protect(create_mi, (VALUE)args, &error); if (error) { - _SBLIM_TRACE(1,("Ruby: FAILED creating %s", hdl->miName)); - hdl->instance = Qnil; + _SBLIM_TRACE(1,("Ruby: FAILED creating %s, error %d", hdl->miName, error)); if (st != NULL) { - st->rc = CMPI_RC_ERR_FAILED; + st->rc = CMPI_RC_ERR_INVALID_CLASS; } } else @@ -153,6 +185,57 @@ call_provider(ProviderMIHandle* hdl, CMPIStatus* st, const char* opname, int nargs, ...) { + int i; + VALUE *args, result, op = rb_intern(opname); + va_list vargs; + + _SBLIM_TRACE(1,("call_provider %s[%d]", opname, nargs)); + + if (!rb_respond_to(hdl->instance, op)) + { + char* str = fmtstr("Ruby provider does not implement \"%s\"", opname); + _SBLIM_TRACE(1,("%s", str)); + st->rc = CMPI_RC_ERR_FAILED; + st->msg = hdl->broker->eft->newString(hdl->broker, str, NULL); + return 1; + } + + /* add hdl->instance, op and nargs to the args array, so rb_protect can be called */ + nargs += 3; + args = (VALUE *)malloc(nargs * sizeof(VALUE)); + if (args == NULL) + { + _SBLIM_TRACE(1,("Out of memory")); + abort(); + } + args[0] = (VALUE)(hdl->instance); + args[1] = op; + args[2] = (VALUE)(nargs-3); + if (nargs > 3) + { + va_start(vargs, nargs); + for (i = 3; i < nargs; ++i) + { + args[i] = va_arg(vargs, VALUE); + } + va_end(vargs); + } + + + result = rb_protect(call_mi, (VALUE)args, &i); + + free( args ); + + if (i) + { + char* str = fmtstr("Ruby provider call to \"%s\" failed", opname); + _SBLIM_TRACE(1,("%s", str)); + st->rc = CMPI_RC_ERR_FAILED; + st->msg = hdl->broker->eft->newString(hdl->broker, str, NULL); + return 1; + } + + st->rc = CMPI_RC_OK; return 0; } Modified: cmpi-bindings/trunk/swig/ruby/cmpi_rbwbem_bindings.rb =================================================================== --- cmpi-bindings/trunk/swig/ruby/cmpi_rbwbem_bindings.rb 2008-09-30 12:57:40 UTC (rev 1056) +++ cmpi-bindings/trunk/swig/ruby/cmpi_rbwbem_bindings.rb 2008-10-01 14:19:39 UTC (rev 1057) @@ -1,55 +1,31 @@ # +# Module RbCmpi # +# Main entry point for cmpi-bindings-ruby, Ruby based CIM Providers # -STDERR.puts "Hello, from rcmpi_instance.rb" -require "pp" - -class Cmpi_Instance - def initialize name - STDERR.puts "Creating Cmpi_Instance #{name}" - end - def enum_instance_names context, results, reference - STDERR.puts "Running Cmpi_Instance:enum_instance_names" - begin - nm = reference.namespace - object_path = Cmpi::CMPIObjectPath.new nm - - object_path["hello"] = "Hello," - results.return_objectpath object_path - - object_path["hello"] = "world!" - results.return_objectpath object_path - - results.done - rescue Exception - STDERR.puts "Exception: #{$!.message}" +module Cmpi + STDERR.puts "Hello from cmpi-bindings-ruby" + # init + RBCIMPATH = "/usr/lib/rbcim/" + + # look for .rb files below RBCIMPATH + # and load them + if File.directory?(RBCIMPATH) then + $:.unshift RBCIMPATH # add to load path + STDERR.puts "Looking into #{RBCIMPATH}" + Dir.foreach( RBCIMPATH ) do |entry| + STDERR.puts "Found #{entry}" + split = entry.split '.' + if split[1] == 'rb' then + begin + STDERR.puts "Loading #{split[0]}" + require split[0] + rescue Exception => e + STDERR.puts "Loading #{split[0]} failed: #{e}" + end + end end + $:.shift # take load path away end - def enum_instances context, results, reference, properties - STDERR.puts "Running Cmpi_Instance:enum_instances" - begin -# pp "Context #{context}" -# pp "Result #{results}" -# pp "Reference #{reference}" -# pp "Properties #{properties}" - - nm = reference.namespace - pp "nm #{nm}" - - object_path = Cmpi::CMPIObjectPath.new nm - - instance = Cmpi::CMPIInstance.new object_path - instance[:hello] = "Hello," - results.return_instance instance - - instance = Cmpi::CMPIInstance.new object_path - instance["hello"] = "world!" - results.return_instance instance - - results.done - rescue Exception - STDERR.puts "Exception: #{$!.message}" - end - end end Added: cmpi-bindings/trunk/test/ruby/TestAtomProvider.peg.reg =================================================================== --- cmpi-bindings/trunk/test/ruby/TestAtomProvider.peg.reg (rev 0) +++ cmpi-bindings/trunk/test/ruby/TestAtomProvider.peg.reg 2008-10-01 14:19:39 UTC (rev 1057) @@ -0,0 +1,28 @@ +// Provider registration for TestAtom +instance of PG_ProviderModule +{ + Name = "TestAtom_Module"; + Location = "pyCmpiProvider"; + Vendor = "Novell"; + Version = "1.0.0"; + InterfaceType = "CMPI"; + InterfaceVersion = "2.0.0"; +}; + +instance of PG_Provider +{ + Name = "TestAtomProvider"; + ProviderModuleName = "TestAtom_Module"; +}; + +instance of PG_ProviderCapabilities +{ + ProviderModuleName = "TestAtom_Module"; + ProviderName = "TestAtomProvider"; + ClassName = "Test_Atom"; + ProviderType = { 2 }; + Namespaces = {"root/cimv2"}; + SupportedProperties = NULL; + SupportedMethods = NULL; + CapabilityID = "TestAtom-Prov-1"; +}; Added: cmpi-bindings/trunk/test/ruby/TestAtomProvider.reg =================================================================== --- cmpi-bindings/trunk/test/ruby/TestAtomProvider.reg (rev 0) +++ cmpi-bindings/trunk/test/ruby/TestAtomProvider.reg 2008-10-01 14:19:39 UTC (rev 1057) @@ -0,0 +1,9 @@ +// Provider registration for TestAtom +instance of OpenWBEM_PyProviderRegistration +{ + InstanceID = "<org:product:TestAtom:unique_id>"; // TODO + NamespaceNames = {"root/cimv2"}; + ClassName = "Test_Atom"; + ProviderTypes = {1}; // Instance + ModulePath = "/usr/lib/pycim/TestAtomProvider.py"; // TODO +}; Added: cmpi-bindings/trunk/test/ruby/TestAtomProvider.sfcb.reg =================================================================== --- cmpi-bindings/trunk/test/ruby/TestAtomProvider.sfcb.reg (rev 0) +++ cmpi-bindings/trunk/test/ruby/TestAtomProvider.sfcb.reg 2008-10-01 14:19:39 UTC (rev 1057) @@ -0,0 +1,5 @@ +[Test_Atom] + provider: TestAtomProvider + location: rbCmpiProvider + type: instance + namespace: root/cimv2 Added: cmpi-bindings/trunk/test/ruby/setup.sh =================================================================== --- cmpi-bindings/trunk/test/ruby/setup.sh (rev 0) +++ cmpi-bindings/trunk/test/ruby/setup.sh 2008-10-01 14:19:39 UTC (rev 1057) @@ -0,0 +1,62 @@ +#!/bin/sh + +function __install { + + fn=$1 + dir=$2 + + if [ ! -f "$fn" ]; then + echo "no such file: $fn" + exit 1 + fi + + if [ ! -d "$dir" ]; then + echo "no such directory: $dir" + exit 1 + fi + + echo "rm -f $dir/$fn" + rm -f $dir/$fn + echo "ln -s `pwd`/$fn $dir" + ln -s `pwd`/$fn $dir +} + +## +## Check usage +## + +if [ "$#" != 1 ]; then + echo "Usage: $0 [op|sfcb]" + exit 1 +fi + +if [ "$1" != "op" -a "$1" != "sfcb" ]; then + echo "Usage: $0 [op|sfcb]" + exit 1 +fi + +## +## Install Ruby providers: +## + +__install TestMethod.rb /usr/lib/rbcim +__install TestAssocProvider.rb /usr/lib/rbcim +__install TestAtomProvider.rb /usr/lib/rbcim + +if [ "$1" = "op" ]; then + cimmof ../python/TestMethod.mof + cimmof -n root/PG_InterOp TestMethod.peg.reg + cimmof ../python/TestAssoc.mof + cimmof -n root/PG_InterOp TestAssocProvider.peg.reg + cimmof ../python/TestAtom.mof + cimmof -n root/PG_InterOp TestAtomProvider.peg.reg +else + __install ../python/TestMethod.mof /var/lib/sfcb/stage/mofs/root/cimv2 + __install ../python/TestAssoc.mof /var/lib/sfcb/stage/mofs/root/cimv2 + __install ../python/TestAtom.mof /var/lib/sfcb/stage/mofs/root/cimv2 + + __install TestAssocProvider.sfcb.reg /var/lib/sfcb/stage/regs + __install TestMethod.sfcb.reg /var/lib/sfcb/stage/regs + __install TestAtomProvider.sfcb.reg /var/lib/sfcb/stage/regs + sfcbrepos -f +fi Property changes on: cmpi-bindings/trunk/test/ruby/setup.sh ___________________________________________________________________ Added: svn:executable + * Added: cmpi-bindings/trunk/test/ruby/test_atom_provider.rb =================================================================== --- cmpi-bindings/trunk/test/ruby/test_atom_provider.rb (rev 0) +++ cmpi-bindings/trunk/test/ruby/test_atom_provider.rb 2008-10-01 14:19:39 UTC (rev 1057) @@ -0,0 +1,28 @@ +# +# Ruby Provider for TestAtom +# +# Instruments the CIM class TestAtom +# + +module Cmpi + + STDERR.puts "This is test_atom_provider.rb" + # Instrument the CIM class TestAtom + # + # Model an atom, For use with CIMOM and RbWbem Provider + # + + class TestAtomProvider + STDERR.puts "This is TestAtomProvider within test_atom_provider.rb" + + def initialize broker + STDERR.puts "TestAtomProvider initialized!" + @broker = broker + end + + def create_instance context, result, reference, newinst + STDERR.puts "TestAtomProvider.create_instance" + end + end + +end \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |