lwes 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,7 @@
1
+ Version 0.8.3 (erik-s-chang)
2
+ * Emitter can auto-create+emit sparse LWES::Event objects in
3
+ addition to Struct-based objects.
4
+
1
5
  Version 0.8.2 (erik-s-chang)
2
6
  * 100% RDoc coverage.
3
7
 
@@ -1,4 +1,9 @@
1
1
  #include "lwes_ruby.h"
2
+ #ifdef HAVE_RUBY_UTIL_H
3
+ # include <ruby/util.h>
4
+ #else
5
+ # include "util.h"
6
+ #endif
2
7
 
3
8
  static VALUE ENC; /* LWES_ENCODING */
4
9
  static ID id_TYPE_DB, id_TYPE_LIST, id_NAME, id_HAVE_ENCODING;
@@ -41,16 +46,6 @@ static void dump_enc(VALUE enc, LWES_BYTE_P buf, size_t *off)
41
46
  lwesrb_dump_num(LWES_INT_16_TOKEN, enc, buf, off);
42
47
  }
43
48
 
44
- static char *my_strdup(const char *str)
45
- {
46
- long len = strlen(str) + 1;
47
- char *rv = xmalloc(len);
48
-
49
- memcpy(rv, str, len);
50
-
51
- return rv;
52
- }
53
-
54
49
  /* the underlying struct for LWES::Emitter */
55
50
  struct _rb_lwes_emitter {
56
51
  struct lwes_emitter *emitter;
@@ -376,6 +371,7 @@ static VALUE emitter_ltlt(VALUE self, VALUE event)
376
371
  static VALUE emitter_emit(int argc, VALUE *argv, VALUE self)
377
372
  {
378
373
  volatile VALUE raise_inspect;
374
+ char *err;
379
375
  VALUE name = Qnil;
380
376
  VALUE event = Qnil;
381
377
  argc = rb_scan_args(argc, argv, "11", &name, &event);
@@ -405,7 +401,15 @@ static VALUE emitter_emit(int argc, VALUE *argv, VALUE self)
405
401
  * struct created
406
402
  */
407
403
  event = rb_funcall(name, id_new, 1, event);
408
- return emit_struct(self, event);
404
+ if (TYPE(event) == T_STRUCT)
405
+ return emit_struct(self, event);
406
+ if (rb_obj_is_kind_of(event, cLWES_Event))
407
+ return emit_event(self, event);
408
+ name = rb_class_name(name);
409
+ err = StringValuePtr(name);
410
+ rb_raise(rb_eArgError,
411
+ "%s created a bad event: %s",
412
+ err, RAISE_INSPECT(event));
409
413
  default:
410
414
  if (rb_obj_is_kind_of(name, cLWES_Event))
411
415
  return emit_event(self, name);
@@ -467,9 +471,9 @@ static VALUE init_copy(VALUE dest, VALUE obj)
467
471
  struct _rb_lwes_emitter *src = _rle(obj);
468
472
 
469
473
  memcpy(dst, src, sizeof(*dst));
470
- dst->address = my_strdup(src->address);
474
+ dst->address = ruby_strdup(src->address);
471
475
  if (dst->iface)
472
- dst->iface = my_strdup(src->iface);
476
+ dst->iface = ruby_strdup(src->iface);
473
477
  lwesrb_emitter_create(dst);
474
478
 
475
479
  assert(dst->emitter && dst->emitter != src->emitter &&
@@ -496,7 +500,7 @@ static VALUE _create(VALUE self, VALUE options)
496
500
  address = rb_hash_aref(options, ID2SYM(rb_intern("address")));
497
501
  if (TYPE(address) != T_STRING)
498
502
  rb_raise(rb_eTypeError, ":address must be a string");
499
- rle->address = my_strdup(StringValueCStr(address));
503
+ rle->address = ruby_strdup(StringValueCStr(address));
500
504
 
501
505
  iface = rb_hash_aref(options, ID2SYM(rb_intern("iface")));
502
506
  switch (TYPE(iface)) {
@@ -504,7 +508,7 @@ static VALUE _create(VALUE self, VALUE options)
504
508
  rle->iface = NULL;
505
509
  break;
506
510
  case T_STRING:
507
- rle->iface = my_strdup(StringValueCStr(iface));
511
+ rle->iface = ruby_strdup(StringValueCStr(iface));
508
512
  break;
509
513
  default:
510
514
  rb_raise(rb_eTypeError, ":iface must be a String or nil");
data/lwes.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{lwes}
3
- s.version = "0.8.2"
3
+ s.version = "0.8.3"
4
4
  s.date = Time.now
5
5
  s.authors = ["Erik S. Chang", "Frank Maritato"]
6
6
  s.email = %q{lwes-devel@lists.sourceforge.net}
@@ -141,6 +141,23 @@ class TestEvent < Test::Unit::TestCase
141
141
  receiver.close
142
142
  end
143
143
 
144
+ def test_emit_class_from_hash_subclassed
145
+ receiver = UDPSocket.new
146
+ receiver.bind(nil, @options[:port])
147
+ emitter = LWES::Emitter.new(@options)
148
+ tmp = { :t_string => 'hello' }
149
+
150
+ tdb = LWES::TypeDB.new("#{File.dirname(__FILE__)}/test1.esf")
151
+ ev1 = LWES::Event.subclass :name => "Event1", :db => tdb
152
+ emitter.emit ev1, tmp
153
+ buf, _ = receiver.recvfrom(65536)
154
+ parsed = LWES::Event.parse(buf)
155
+ assert_instance_of ev1, parsed
156
+ assert_equal parsed.to_hash, ev1.new(tmp).to_hash
157
+ ensure
158
+ receiver.close
159
+ end
160
+
144
161
  def teardown
145
162
  new_classes = LWES::Event::CLASSES
146
163
  new_classes.each_key { |k| Object.__send__ :remove_const, k.to_sym }
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: lwes
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.8.2
5
+ version: 0.8.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Erik S. Chang
@@ -11,8 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-04-28 00:00:00 +00:00
15
- default_executable:
14
+ date: 2012-06-04 00:00:00 Z
16
15
  dependencies:
17
16
  - !ruby/object:Gem::Dependency
18
17
  name: rake-compiler
@@ -79,7 +78,6 @@ files:
79
78
  - test/unit/test_type_db.rb
80
79
  - test/unit/test_type_db_events.rb
81
80
  - ext/lwes_ext/lwes-0.23.1.tar.gz
82
- has_rdoc: true
83
81
  homepage: http://lwes.rubyforge.org/
84
82
  licenses: []
85
83
 
@@ -103,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
101
  requirements: []
104
102
 
105
103
  rubyforge_project: lwes
106
- rubygems_version: 1.6.0
104
+ rubygems_version: 1.8.11
107
105
  signing_key:
108
106
  specification_version: 3
109
107
  summary: Ruby bindings for the Light Weight Event System