vigilem-core 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/vigilem/core.rb +9 -0
- data/lib/vigilem/core/abstract_device.rb +97 -0
- data/lib/vigilem/core/adapters.rb +2 -0
- data/lib/vigilem/core/adapters/adapter.rb +57 -0
- data/lib/vigilem/core/adapters/basic_adapter.rb +43 -0
- data/lib/vigilem/core/adapters/buffered_adapter.rb +28 -0
- data/lib/vigilem/core/buffer.rb +151 -0
- data/lib/vigilem/core/buffer_handler.rb +95 -0
- data/lib/vigilem/core/default_buffer.rb +45 -0
- data/lib/vigilem/core/demultiplexer.rb +225 -0
- data/lib/vigilem/core/device.rb +43 -0
- data/lib/vigilem/core/event_handler.rb +156 -0
- data/lib/vigilem/core/eventable.rb +80 -0
- data/lib/vigilem/core/hooks.rb +36 -0
- data/lib/vigilem/core/hooks/callback.rb +66 -0
- data/lib/vigilem/core/hooks/callback_proc.rb +25 -0
- data/lib/vigilem/core/hooks/conditional_hook.rb +62 -0
- data/lib/vigilem/core/hooks/hook.rb +193 -0
- data/lib/vigilem/core/hooks/inheritable.rb +24 -0
- data/lib/vigilem/core/hooks/meta_callback.rb +53 -0
- data/lib/vigilem/core/hooks/utils.rb +23 -0
- data/lib/vigilem/core/hub.rb +50 -0
- data/lib/vigilem/core/input_system_handler.rb +55 -0
- data/lib/vigilem/core/lockable_pipeline_component.rb +30 -0
- data/lib/vigilem/core/multiplexer.rb +168 -0
- data/lib/vigilem/core/pipeline.rb +68 -0
- data/lib/vigilem/core/stat.rb +121 -0
- data/lib/vigilem/core/system.rb +9 -0
- data/lib/vigilem/core/system/check.rb +33 -0
- data/lib/vigilem/core/transfer_agent.rb +67 -0
- data/lib/vigilem/core/version.rb +5 -0
- data/spec/bug_notes.txt +12 -0
- data/spec/given_helper.rb +12 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/vigilem/core/abstract_device_spec.rb +103 -0
- data/spec/vigilem/core/adapters/adapter_spec.rb +28 -0
- data/spec/vigilem/core/adapters/basic_adapter_spec.rb +53 -0
- data/spec/vigilem/core/adapters/buffered_adapter_spec.rb +16 -0
- data/spec/vigilem/core/buffer_handler_spec.rb +51 -0
- data/spec/vigilem/core/buffer_spec.rb +236 -0
- data/spec/vigilem/core/default_buffer_spec.rb +17 -0
- data/spec/vigilem/core/demultiplexer_spec.rb +166 -0
- data/spec/vigilem/core/device_spec.rb +62 -0
- data/spec/vigilem/core/event_handler_spec.rb +134 -0
- data/spec/vigilem/core/hooks/callback_proc_spec.rb +66 -0
- data/spec/vigilem/core/hooks/hook_spec.rb +230 -0
- data/spec/vigilem/core/hooks/inheritable_spec.rb +19 -0
- data/spec/vigilem/core/hooks/meta_callback_spec.rb +69 -0
- data/spec/vigilem/core/hooks/utils_spec.rb +25 -0
- data/spec/vigilem/core/hooks_spec.rb +50 -0
- data/spec/vigilem/core/hub_spec.rb +51 -0
- data/spec/vigilem/core/input_system_handler_spec.rb +33 -0
- data/spec/vigilem/core/lockable_pipeline_component_spec.rb +19 -0
- data/spec/vigilem/core/multiplexer_spec.rb +113 -0
- data/spec/vigilem/core/pipeline_spec.rb +5 -0
- data/spec/vigilem/core/stat_spec.rb +63 -0
- data/spec/vigilem/core/system/check_spec.rb +24 -0
- data/spec/vigilem/core/system_spec.rb +29 -0
- data/spec/vigilem/core/transfer_agent_spec.rb +80 -0
- metadata +273 -0
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'vigilem/support/core_ext'
|
2
|
+
|
3
|
+
require 'vigilem/support/obj_space'
|
4
|
+
|
5
|
+
require 'vigilem/core/system'
|
6
|
+
|
7
|
+
require 'rubygems/dependency_installer'
|
8
|
+
|
9
|
+
module Vigilem
|
10
|
+
module Core
|
11
|
+
#
|
12
|
+
# Stat(us) of the input_system and the handler
|
13
|
+
# gem associated with it
|
14
|
+
class Stat
|
15
|
+
attr_reader :platform_masks, :gem_name, :input_system_name
|
16
|
+
|
17
|
+
attr_accessor :api_check
|
18
|
+
|
19
|
+
private :api_check, :api_check=
|
20
|
+
|
21
|
+
# @fixme duplicates in ::all
|
22
|
+
# @param [String] gem_name
|
23
|
+
# @param [Hash] opts
|
24
|
+
# @param [Proc] api_check
|
25
|
+
# @return
|
26
|
+
def self.new(*args, &block)
|
27
|
+
obj_register(super(*args, &block))
|
28
|
+
end
|
29
|
+
|
30
|
+
#
|
31
|
+
# @param [Array] args
|
32
|
+
# @param [Proc] block
|
33
|
+
# @return [TrueClass || FalseClass]
|
34
|
+
def api_check?(*args, &block)
|
35
|
+
!!api_check.call(*args, &block)
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# @param [String] input_system, the descriptive name of the input_system
|
40
|
+
# @param [String] gemname, the gem name of the handler to install
|
41
|
+
# @param [Hash] opts
|
42
|
+
# @option opts [Array<Regexp || Symbol>] :platforms
|
43
|
+
# @option opts :requirement, defaults to Gem::Requirement.default
|
44
|
+
# @param [Proc] api_check
|
45
|
+
# @return
|
46
|
+
def initialize(input_system, gemname, opts={}, &api_check)
|
47
|
+
@input_system_name = input_system
|
48
|
+
@gem_name = gemname
|
49
|
+
@gem_requirement = opts[:requirement] ||= Gem::Requirement.default
|
50
|
+
|
51
|
+
@platform_masks = [*opts[:platforms] || /.+/].map do |plats|
|
52
|
+
if plats.is_a?(Symbol)
|
53
|
+
System::SYSTEM_NAME_MASKS[plats]
|
54
|
+
elsif plats.is_a?(Regexp)
|
55
|
+
plats
|
56
|
+
else
|
57
|
+
raise NotImplementedError, "UnSupported type #{plats.class}:#{plats}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
@api_check = api_check
|
61
|
+
end
|
62
|
+
|
63
|
+
#
|
64
|
+
#
|
65
|
+
def gem_requirement
|
66
|
+
@gem_requirement ||= Gem::Requirement.default
|
67
|
+
end
|
68
|
+
|
69
|
+
# whether or not this input_system is availble on given os
|
70
|
+
# @param [String || Regexp] os
|
71
|
+
# @return [TrueClass || FalseClass]
|
72
|
+
def available_on?(os)
|
73
|
+
System.check[:os][Regexp.union(platform_masks), os]
|
74
|
+
end
|
75
|
+
|
76
|
+
alias_method :is_available_on?, :available_on?
|
77
|
+
|
78
|
+
#
|
79
|
+
# @param version_requirement, optional
|
80
|
+
# @return
|
81
|
+
def install(version_requirement=nil)
|
82
|
+
@installed = installer.install(gem_name, *version_requirement)
|
83
|
+
end
|
84
|
+
|
85
|
+
#
|
86
|
+
# @return [TrueClass || FalseCLass]
|
87
|
+
def installed?
|
88
|
+
if @installed.nil?
|
89
|
+
@installed = Gem::Specification.find_all_by_name(gem_name, *gem_requirement).any?
|
90
|
+
else
|
91
|
+
@installed
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
#
|
96
|
+
# whether or not this input_system is avaialble on this system
|
97
|
+
# @return [TrueClass || FalseClass]
|
98
|
+
def available?
|
99
|
+
available_on?(System.os) and api_check?
|
100
|
+
end
|
101
|
+
|
102
|
+
extend Support::ObjSpace
|
103
|
+
|
104
|
+
class << self
|
105
|
+
#
|
106
|
+
# @return [Array<Stat>]
|
107
|
+
def all_available
|
108
|
+
all.select(&:available?)
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
private
|
113
|
+
|
114
|
+
#
|
115
|
+
# @return [Gem::DependencyInstaller]
|
116
|
+
def installer
|
117
|
+
@installer ||= Gem::DependencyInstaller.new
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'vigilem/core/stat'
|
2
|
+
|
3
|
+
module Vigilem
|
4
|
+
module Core
|
5
|
+
#
|
6
|
+
#
|
7
|
+
module System
|
8
|
+
|
9
|
+
# common checks for os and input_system
|
10
|
+
# pass `check[:os][/win/]` and it will #=~ against `RbConfig::CONFIG['host_os']`
|
11
|
+
# pass a string and it uses #==
|
12
|
+
# for input_sysmte_handlers it #find's the input_system_handler with the name that #=~
|
13
|
+
# the argument or #== it
|
14
|
+
# @return (TruceClass || FalseClass) whether or not the check passed
|
15
|
+
def self.check
|
16
|
+
@checks ||= {
|
17
|
+
:os => lambda do |str_or_regex, os=nil|
|
18
|
+
os ||= Support::System.os
|
19
|
+
!!(str_or_regex.is_a?(Regexp) and
|
20
|
+
str_or_regex =~ os) or
|
21
|
+
(str_or_regex.to_s == os.to_s)
|
22
|
+
end,
|
23
|
+
:input_system => lambda do |name_or_regex|
|
24
|
+
((name_or_regex.is_a?(Regexp) and
|
25
|
+
(stats = Stat.all_available).find {|isys| isys.input_system_name =~ name_or_regex }) or
|
26
|
+
(stats.find {|isys| isys.input_system_name.to_s == name_or_regex.to_s })
|
27
|
+
)
|
28
|
+
end
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
|
2
|
+
require 'forwardable'
|
3
|
+
|
4
|
+
require 'vigilem/support/core_ext'
|
5
|
+
|
6
|
+
require 'vigilem/support/obj_space'
|
7
|
+
|
8
|
+
require 'vigilem/core/multiplexer'
|
9
|
+
|
10
|
+
require 'vigilem/core/demultiplexer'
|
11
|
+
|
12
|
+
module Vigilem
|
13
|
+
module Core
|
14
|
+
#
|
15
|
+
# facade for demultiplexer <-> multiplexer coupling
|
16
|
+
class TransferAgent
|
17
|
+
|
18
|
+
extend Forwardable
|
19
|
+
|
20
|
+
attr_reader :multiplexer, :demultiplexer
|
21
|
+
|
22
|
+
def_delegators :demultiplexer, :add_observer, :add_observers, :outputs
|
23
|
+
|
24
|
+
def_delegator :multiplexer, :add_inputs
|
25
|
+
|
26
|
+
#
|
27
|
+
#
|
28
|
+
def self.new(*args)
|
29
|
+
obj_register(super(*args))
|
30
|
+
end
|
31
|
+
|
32
|
+
# sets the input on demultiplexer to the ouput of multiplexer
|
33
|
+
# if both are nil it sets it to an Array
|
34
|
+
# @param [#input=, #demux]
|
35
|
+
# @param [#out, #mux]
|
36
|
+
def initialize(demuxer, muxer)
|
37
|
+
@demultiplexer, @multiplexer = demuxer, muxer
|
38
|
+
if (junction = (din = demultiplexer.input) || (mout = multiplexer.out)).nil? or not mout.equal?(din)
|
39
|
+
@demultiplexer.input = @multiplexer.out = (junction || [])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# checks
|
44
|
+
# @param [Integer] num_of_events, defaults to 1
|
45
|
+
# @return [NilClass]
|
46
|
+
def relay(num_of_events=1)
|
47
|
+
multiplexer.mux(num_of_events)
|
48
|
+
demultiplexer.demux(num_of_events)
|
49
|
+
nil
|
50
|
+
end
|
51
|
+
|
52
|
+
extend Support::ObjSpace
|
53
|
+
|
54
|
+
class << self
|
55
|
+
|
56
|
+
#
|
57
|
+
# @param [Module]
|
58
|
+
# @return
|
59
|
+
def inherited(base)
|
60
|
+
base.extend Support::ObjSpace
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/spec/bug_notes.txt
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
RangeError: bignum too big to convert into `long'/int
|
2
|
+
ruby bug Issue #6127
|
3
|
+
|
4
|
+
doesnt work on default ubuntu ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
|
5
|
+
|
6
|
+
https://bugs.launchpad.net/ubuntu/+source/ruby1.9.1/+bug/997150
|
7
|
+
|
8
|
+
|
9
|
+
EVIOCGNAME 2164212998
|
10
|
+
|
11
|
+
|
12
|
+
EVIOCGABS
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# defines a given that takes a block and argument so that the argument given can be used as the description and
|
2
|
+
# retrieved by given_value, essentially making bad tests
|
3
|
+
RSpec::Core::ExampleGroup.define_singleton_method(:given) do |arg, &example_group_block|
|
4
|
+
thread_data = RSpec.thread_local_metadata
|
5
|
+
ret = subclass(self, 'given', arg.to_s, &example_group_block).tap do |child|
|
6
|
+
children << child
|
7
|
+
end
|
8
|
+
ret.send(:define_method, :given_value) do
|
9
|
+
arg
|
10
|
+
end
|
11
|
+
ret.new
|
12
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'vigilem/core/abstract_device'
|
4
|
+
|
5
|
+
describe Vigilem::Core::AbstractDevice do
|
6
|
+
|
7
|
+
describe '#setting?' do
|
8
|
+
describe 'will test whether or not the hook is a setting' do
|
9
|
+
context 'Hook' do
|
10
|
+
let(:hook) { ::Vigilem::Core::Hooks::Hook.new('tmp') }
|
11
|
+
|
12
|
+
let!(:callbacks) { hook << ::Vigilem::Core::Hooks::Callback.new { true } }
|
13
|
+
|
14
|
+
it 'will pass before ran' do
|
15
|
+
expect(subject.setting?(hook)).to be_truthy
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'will pass after ran' do
|
19
|
+
expect(subject.setting?(hook)).to be_truthy
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'ConditionalHook' do
|
24
|
+
context 'passes' do
|
25
|
+
let(:hook) do
|
26
|
+
::Vigilem::Core::Hooks::ConditionalHook.new('tmp') do
|
27
|
+
condition { true }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
let!(:callbacks) { hook << ::Vigilem::Core::Hooks::Callback.new { true } }
|
32
|
+
|
33
|
+
it 'will fail before ran' do
|
34
|
+
expect(subject.setting?(hook)).to be_falsey
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'will be a setting when condition passes' do
|
38
|
+
hook.call
|
39
|
+
expect(subject.setting?(hook)).to be_truthy
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'fails' do
|
44
|
+
let(:hook) do
|
45
|
+
::Vigilem::Core::Hooks::ConditionalHook.new('tmp') do
|
46
|
+
condition { false }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
let!(:callbacks) { hook << ::Vigilem::Core::Hooks::Callback.new { true } }
|
51
|
+
|
52
|
+
it 'will not be a setting when the condition fails' do
|
53
|
+
hook.call
|
54
|
+
expect(subject.setting?(hook)).to be_falsey
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#new' do
|
63
|
+
|
64
|
+
it 'will have one init setting after_init' do
|
65
|
+
expect(described_class.new.settings.first.name).to eql(:after_init)
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'system checks' do
|
69
|
+
|
70
|
+
it 'runs the system_check' do
|
71
|
+
expect_any_instance_of(described_class).to receive(:run_system_checks)
|
72
|
+
described_class.new
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'will add to settings when the check passes' do
|
76
|
+
hook = ::Vigilem::Core::Hooks::ConditionalHook.new(:on_always,
|
77
|
+
{:type => :system_check, :inheritable => false }) { condition { true } }
|
78
|
+
described_class.hooks << hook
|
79
|
+
hook << lambda { 'do something' }
|
80
|
+
abs = described_class.new
|
81
|
+
expect(abs.settings).to_not be_empty
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe 'pipeline building' do
|
87
|
+
before :all do
|
88
|
+
class Cheese
|
89
|
+
def yarg?
|
90
|
+
puts 'yarg!'
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
context 'after_import' do
|
95
|
+
let(:cheese) { Cheese.new }
|
96
|
+
|
97
|
+
it 'will set @delegate_sd_obj to the import arg' do
|
98
|
+
subject.import(cheese)
|
99
|
+
expect(subject.instance_variable_get(:@delegate_sd_obj)).to eql cheese
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'vigilem/core/adapters/adapter'
|
2
|
+
|
3
|
+
describe Vigilem::Core::Adapters::Adapter do
|
4
|
+
|
5
|
+
class Host
|
6
|
+
include Vigilem::Core::Adapters::Adapter
|
7
|
+
|
8
|
+
def initialize(lnk=nil)
|
9
|
+
initialize_adapter(lnk)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
subject { Host.new }
|
14
|
+
|
15
|
+
describe '#attach' do
|
16
|
+
it 'will set the link return self' do
|
17
|
+
expect(subject).to receive(:link=).with('new').and_return(subject)
|
18
|
+
subject.attach('new')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#affix' do
|
23
|
+
it 'will set the link and return the new link' do
|
24
|
+
expect(subject).to receive(:link=).with('new').and_return('new')
|
25
|
+
subject.affix('new')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'vigilem/core/adapters/basic_adapter'
|
2
|
+
|
3
|
+
describe Vigilem::Core::Adapters::BasicAdapter do
|
4
|
+
|
5
|
+
class InitlessBasicHost
|
6
|
+
include Vigilem::Core::Adapters::BasicAdapter
|
7
|
+
end
|
8
|
+
|
9
|
+
class BasicHost
|
10
|
+
include Vigilem::Core::Adapters::BasicAdapter
|
11
|
+
|
12
|
+
def initialize(lnk=nil)
|
13
|
+
initialize_basic_adapter(lnk)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
subject { BasicHost.new }
|
18
|
+
|
19
|
+
describe '#initialize_basic_adapter' do
|
20
|
+
it 'sets @link' do
|
21
|
+
expect(InitlessBasicHost.new.instance_variable_defined?(:@link)).to be_falsey
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Observe
|
26
|
+
|
27
|
+
attr_writer :notifications
|
28
|
+
|
29
|
+
def update(type, value)
|
30
|
+
notifications << [type, value]
|
31
|
+
end
|
32
|
+
|
33
|
+
def notifications
|
34
|
+
@notifications ||= []
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#link=' do
|
39
|
+
it 'will set to changed when link is changed' do
|
40
|
+
subject.add_observer(obs = Observe.new)
|
41
|
+
subject.link = 'new'
|
42
|
+
expect(obs.notifications).to include(['link', 'new'])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#source' do
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#link' do
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|