Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/miminar/ruby-sfcc into mi…
Browse files Browse the repository at this point in the history
…minar-master
  • Loading branch information
dmacvicar committed Mar 17, 2015
2 parents e16bdd2 + 21f38e7 commit 16277bc
Show file tree
Hide file tree
Showing 11 changed files with 947 additions and 153 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.rdoc
@@ -1,6 +1,15 @@
==

== 0.6.1

* Support Ruby 1.9 thread unblocking in client calls
* fixed memory leak in Class
* added support for conversion of Cim::ObjectPath, Cim::Instance,
Cim::Enumeration and Cim::Class to CIMCData
* supported instantiation of Cim::Data
* fixed memory leak in client's invokeMethod
* added support for Float and Bignum in Cim::Data creation
* fixed accessing char array in CIMCValue
* enabled compilation for older sblim-sfcc

== 0.6.0

Expand Down
50 changes: 50 additions & 0 deletions examples/data_instantiation.rb
@@ -0,0 +1,50 @@
%w(../ext/sfcc ../lib).each do |path|
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), path)))
end

require 'rubygems'
require 'sfcc'

include Sfcc

#
# instantiate Cim::Data class
#

# creating data from rb value
data = Cim::Data.from_value("Data created from string:")
puts "#{data.value} #{data}"
data = Cim::Data.from_value(15)
puts "Data created from integer(#{data.value}): #{data}"
data = Cim::Data.from_value([1, 4, 9, 10])
puts "Data created from array(from #{data.value.inspect}): #{data}"
data = Cim::Data.from_value(Cim::ObjectPath.new("namespace", "class_name"))
puts "Data created from object path: #{data}"

# creating data from type and value
data = Cim::Data.new(Cim::Type::String, "Data(type=string):")
puts "#{data.value} #{data}"
data = Cim::Data.new(Cim::Type::UInt8, 10)
puts "Data(type=UInt8): #{data}"
data = Cim::Data.new(Cim::Type::UInt8, -40)
puts "Data(type=UInt8) from value -40 (overflow): #{data}"
data = Cim::Data.new(Cim::Type::SInt16, 2**15)
puts "Data(type=SInt16) from value (2**15) (overflow): #{data}"
# type can be passed also as string
data = Cim::Data.new("String", "created with type passed as string")
puts "Data(type=String): #{data}"
data = Cim::Data.new("Reference", Cim::ObjectPath.new("namespace", "ClassName"))
puts "Data(type=Reference): #{data}"

# changing type and value of created data
data.type = "UInt8"
data.value = 42
begin # this will raise a TypeError
data.value = ["abcd"]
rescue TypeError
puts("you can not change the value of data with different type" +
" before you set the corresponding type")
end
data.type = "StringA" # this will destroy kept value
puts "Data(type=StringA): #{data}"
data.value = ["abcd", "efgh"] # this will pass
7 changes: 5 additions & 2 deletions ext/sfcc/cim_class.c
Expand Up @@ -22,8 +22,11 @@ static VALUE class_name(VALUE self)
CIMCStatus status = { 0 };
Data_Get_Struct(self, CIMCClass, cimclass);
name = cimclass->ft->getClassName(cimclass, &status);
if ( !status.rc )
return CIMSTR_2_RUBYSTR(name);
if ( !status.rc ) {
VALUE ret = CIMSTR_2_RUBYSTR(name);
name->ft->release(name);
return ret;
}

sfcc_rb_raise_if_error(status, "Can't retrieve class name");
return Qnil;
Expand Down
17 changes: 15 additions & 2 deletions ext/sfcc/cim_client.c
Expand Up @@ -1068,7 +1068,7 @@ static VALUE invoke_method(VALUE self,
{
CIMCStatus status = {CIMC_RC_OK, NULL};
CIMCClient *client;
CIMCArgs *cimcargsout;
CIMCArgs *cimcargsin, *cimcargsout;
const char *method_name_cstr;
CIMCData ret;
rb_sfcc_object_path *rso;
Expand All @@ -1078,6 +1078,7 @@ static VALUE invoke_method(VALUE self,

Check_Type(argin, T_HASH);

cimcargsin = sfcc_hash_to_cimargs(argin);
cimcargsout = cimcEnv->ft->newArgs(cimcEnv, NULL);

Data_Get_Struct(self, CIMCClient, client);
Expand All @@ -1097,17 +1098,29 @@ static VALUE invoke_method(VALUE self,
ret = client->ft->invokeMethod(client,
rso->op,
method_name_cstr,
sfcc_hash_to_cimargs(argin),
cimcargsin,
cimcargsout,
&status);
#endif

/** this is a work around the bug:
* * https://sourceforge.net/tracker/?func=detail&aid=3555103&group_id=128809&atid=712784
* release function has wrong declaration
*/
CIMCStatus (*args_release) (CIMCArgs *) =
(CIMCStatus (*) (CIMCArgs *)) cimcargsin->ft->release;
args_release(cimcargsin);

if (!status.rc) {
if (cimcargsout && ! NIL_P(argout)) {
Check_Type(argout, T_HASH);
rb_funcall(argout, rb_intern("merge!"), 1, sfcc_cimargs_to_hash(cimcargsout, self));
args_release(cimcargsout);
}
return sfcc_cimdata_to_value(&ret, self);
}
// in this case cimcargsout needs not to be freed
// this is handled be invokeMethod
sfcc_rb_raise_if_error(status, "Can't invoke method '%s'", method_name_cstr);
return Qnil;
}
Expand Down

0 comments on commit 16277bc

Please sign in to comment.