diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2011-04-11 23:25:23 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2011-04-11 23:25:23 +0200 |
commit | 0c3cbdb988566ea3e2dcd52396b834cbab02d3fa (patch) | |
tree | 837058d3a4fc728287019c401b004650c38a56e9 | |
parent | 846ea53d8844b42ac85bcf3a4c8307212c2c5075 (diff) | |
download | ffi-efl-0c3cbdb988566ea3e2dcd52396b834cbab02d3fa.zip ffi-efl-0c3cbdb988566ea3e2dcd52396b834cbab02d3fa.tar.gz |
add ecore event functions and spec
-rw-r--r-- | lib/efl/ecore/event.rb | 59 | ||||
-rw-r--r-- | spec/ecore_event_spec.rb | 115 |
2 files changed, 174 insertions, 0 deletions
diff --git a/lib/efl/ecore/event.rb b/lib/efl/ecore/event.rb new file mode 100644 index 0000000..ed85a28 --- /dev/null +++ b/lib/efl/ecore/event.rb @@ -0,0 +1,59 @@ +#! /usr/bin/env ruby +# -*- coding: UTF-8 -*- +# +require 'ffi' +# +module EFL + module ECORE + # + extend FFI::Library + # + EVENT_NONE = 0 + EVENT_SIGNAL_USER = 1 # User signal event + EVENT_SIGNAL_HUP = 2 # Hup signal event + EVENT_SIGNAL_EXIT = 3 # Exit signal event + EVENT_SIGNAL_POWER = 4 # Power signal event + EVENT_SIGNAL_REALTIME = 5 # Realtime signal event + EVENT_COUNT = 6 + callback :ecore_event_handler_cb, [:pointer, :int, :pointer], :bool + callback :ecore_end_cb, [:pointer, :pointer], :void + callback :ecore_data_cb, [:pointer], :pointer + callback :ecore_filter_cb, [:pointer, :pointer, :int, :pointer], :bool + # + ffi_lib 'ecore' + functions = [ + [ :ecore_event_handler_add, [:int, :ecore_event_handler_cb, :pointer], :pointer ], + [ :ecore_event_handler_del, [:pointer], :void ], + [ :ecore_event_add, [:int, :pointer, :ecore_end_cb, :pointer], :pointer ], + [ :ecore_event_del, [:pointer], :void ], + [ :ecore_event_handler_data_get, [:pointer], :pointer ], + [ :ecore_event_handler_data_set, [:pointer,:pointer], :void ], + [ :ecore_event_type_new, [], :int ], + [ :ecore_event_filter_add, [:ecore_data_cb, :ecore_filter_cb, :ecore_end_cb, :pointer], :pointer ], + [ :ecore_event_filter_del, [:pointer], :void ], + [ :ecore_event_current_type_get, [], :int ], + [ :ecore_event_current_event_get, [], :pointer], + ].each do |func| + begin + attach_function *func + rescue Object => e + puts "Could not attach #{func} #{e.message}" + end + end + # + class << self + alias event_handler_add ecore_event_handler_add + alias event_handler_del ecore_event_handler_del + alias event_add ecore_event_add + alias event_del ecore_event_del + alias event_handler_data_get ecore_event_handler_data_get + alias event_handler_data_set ecore_event_handler_data_set + alias event_type_new ecore_event_type_new + alias event_current_type_get ecore_event_current_type_get + alias event_current_event_get ecore_event_current_event_get + end + # + end +end +# +# EOF diff --git a/spec/ecore_event_spec.rb b/spec/ecore_event_spec.rb new file mode 100644 index 0000000..7da5bfd --- /dev/null +++ b/spec/ecore_event_spec.rb @@ -0,0 +1,115 @@ +#! /usr/bin/env ruby +# -*- coding: UTF-8 -*- +# +require 'efl/ecore/event' +# +describe EFL::ECORE do + # + include EFL + # + before(:all) do + USER_SIGNAL_CB = Proc.new do |data, type, event| + data.read_string.should eql "666" + type.should eql ECORE::EVENT_SIGNAL_USER + event.read_int.should eql 666 + ECORE.event_current_type_get.should eql ECORE::EVENT_SIGNAL_USER + ECORE.event_current_event_get.address.should eql event.address + ECORE.main_loop_quit + end + EVENT_FREE_CB = Proc.new do |data,event| + data.read_string.should eql "none" + event.read_int.should eql 666 + end + end + # + it 'should be able to add event hanlder and process event' do + ECORE.init + evt = FFI::MemoryPointer.new(:int) + evt.write_int 666 + # add, del, add event handler + evt_handler = ECORE.event_handler_add ECORE::EVENT_SIGNAL_USER, USER_SIGNAL_CB, "wrong" + evt_handler.null?.should be_false + ECORE.event_handler_del evt_handler + evt_handler = ECORE.event_handler_add ECORE::EVENT_SIGNAL_USER, USER_SIGNAL_CB, "666" + evt_handler.null?.should be_false + # add, del, add event + ecore_evt = ECORE.event_add ECORE::EVENT_SIGNAL_USER, evt, EVENT_FREE_CB, FFI::MemoryPointer.from_string("none") + ecore_evt.null?.should be_false + ECORE.event_del ecore_evt + ecore_evt = ECORE.event_add ECORE::EVENT_SIGNAL_USER, evt, EVENT_FREE_CB, FFI::MemoryPointer.from_string("none") + ecore_evt.null?.should be_false + ECORE.main_loop_begin # process event + ECORE.shutdown + end + # + it "should be able to get and set event handler data" do + ECORE.init + evt = FFI::MemoryPointer.new(:int) + evt.write_int 666 + evt_handler = ECORE.event_handler_add ECORE::EVENT_SIGNAL_USER, USER_SIGNAL_CB, "wrong" + evt_handler.null?.should be_false + ECORE.event_handler_data_get(evt_handler).read_string.should eql "wrong" + ECORE.event_handler_data_set evt_handler, FFI::MemoryPointer.from_string("666") + ECORE.event_handler_data_get(evt_handler).read_string.should eql "666" + ecore_evt = ECORE.event_add ECORE::EVENT_SIGNAL_USER, evt, EVENT_FREE_CB, FFI::MemoryPointer.from_string("none") + ecore_evt.null?.should be_false + ECORE.main_loop_begin # process event + ECORE.shutdown + end + # + it "should be able to create new event type" do + ECORE.init + ECORE.ecore_event_type_new.should_not eql 0 + ECORE.ecore_event_type_new.should_not eql 0 + ECORE.ecore_event_type_new.should_not eql 0 + ECORE.shutdown + end + # + it "should be possible to add and del event filters" do + ECORE.init + loop_data = FFI::MemoryPointer.from_string("loop_data") + event_free_cb = Proc.new do |data,event| + data.read_string.should eql "wrong" + event.read_int.should eql 69 + end + start_cb = Proc.new do |data| + data.read_string.should eql "yeah" + loop_data + end + count = 0 + filter_cb = Proc.new do |data,loop_data,type,event| + data.read_string.should eql "yeah" + loop_data.read_string.should eql "loop_data" + type.should eql ECORE::EVENT_SIGNAL_USER + count += 1 + if event.read_int == 69 + count.should eql 1 + false # drop first event + else + count.should eql 2 + event.read_int.should eql 666 + true + end + end + end_cb = Proc.new do |data,loop_data| + data.read_string.should eql "yeah" + loop_data.read_string.should eql "loop_data" + end + m0 = FFI::MemoryPointer.from_string("yeah") + filter = ECORE.ecore_event_filter_add start_cb, filter_cb, end_cb, m0 + ECORE.event_handler_add ECORE::EVENT_SIGNAL_USER, USER_SIGNAL_CB, "666" + e1 = FFI::MemoryPointer.new(:int) + e1.write_int 69 + m1 = FFI::MemoryPointer.from_string("wrong") + evt1 = ECORE.event_add ECORE::EVENT_SIGNAL_USER, e1, event_free_cb, m1 + e2 = FFI::MemoryPointer.new(:int) + e2.write_int 666 + m2 = FFI::MemoryPointer.from_string("none") + evt2 = ECORE.event_add ECORE::EVENT_SIGNAL_USER, e2, EVENT_FREE_CB, m2 + ECORE.main_loop_begin # process event + ECORE.ecore_event_filter_del filter + evt2 = ECORE.event_add ECORE::EVENT_SIGNAL_USER, e2, EVENT_FREE_CB, m2 + ECORE.main_loop_begin # process event + ECORE.shutdown + end +end |