ruinput 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ *.o
4
+ *.so
5
+ *.dll
6
+ *~
7
+ .bundle
8
+ .config
9
+ .yardoc
10
+ Gemfile.lock
11
+ InstalledFiles
12
+ Makefile
13
+ _yardoc
14
+ core
15
+ coverage
16
+ doc/
17
+ lib/bundler/man
18
+ pkg
19
+ rdoc
20
+ spec/reports
21
+ test/tmp
22
+ test/version_tmp
23
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruinput.gemspec
4
+ gemspec
5
+
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Keiichiro Ui
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Ruinput
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ruinput'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ruinput
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rake/testtask'
4
+ require 'rake/clean'
5
+
6
+ NAME="ruinput"
7
+ MAKEFILES = Dir.glob "ext/**/Makefile"
8
+
9
+ ## dir
10
+ directory "lib/#{NAME}"
11
+
12
+ ## so file
13
+ file "lib/#{NAME}/#{NAME}.so" =>
14
+ (Dir.glob("ext/#{NAME}/*.{rb,c}") << "lib/#{NAME}")do
15
+
16
+ Dir.chdir "ext/#{NAME}" do
17
+ ruby "extconf.rb"
18
+ sh "make"
19
+ end
20
+
21
+ cp "ext/#{NAME}/#{NAME}.so", "lib/#{NAME}"
22
+
23
+ end
24
+
25
+ ## make_clean
26
+ desc "do `make clean` with all Makefiles"
27
+ task :make_clean do
28
+ MAKEFILES.each do |file|
29
+ dir = File.dirname file
30
+ puts "cd #{dir}"
31
+ Dir.chdir dir do
32
+ sh "make clean"
33
+ end
34
+ end
35
+ end
36
+
37
+ ## clobber
38
+ CLOBBER.include "lib/**/*.so"
39
+
40
+ ### clean
41
+ CLEAN.include MAKEFILES
42
+ task :clean => :make_clean
43
+
44
+ ## test
45
+ desc "Run tests"
46
+ task :test => "lib/#{NAME}/#{NAME}.so"
47
+ Rake::TestTask.new :test do |t|
48
+ t.verbose = true
49
+ end
50
+
51
+ ## default
52
+ task :default => :test
@@ -0,0 +1,3 @@
1
+ require "mkmf"
2
+
3
+ create_makefile "ruinput/ruinput"
@@ -0,0 +1,145 @@
1
+ // -*- coding:utf-8; mode:c; -*-
2
+
3
+ #include <stdlib.h>
4
+ #include <stdio.h>
5
+ #include <linux/input.h>
6
+ #include <linux/uinput.h>
7
+
8
+ #include <ruby.h>
9
+
10
+ #define NAME "Ruinput"
11
+ #define BUFF_SIZE 255
12
+
13
+ #define FALSE 0
14
+ #define TRUE !FALSE
15
+
16
+ #define AttrAccessor(klass,name) rb_define_attr(klass,name,TRUE,TRUE)
17
+
18
+ VALUE module_ruinput;
19
+ VALUE class_uinput_user_dev;
20
+
21
+ void type_exception(char* name, char* klass)
22
+ {
23
+ rb_raise(rb_eTypeError, "%s is expected a %s", name, klass);
24
+ }
25
+
26
+ int abs_array_cpy(int abs_arr[], VALUE array_obj)
27
+ {
28
+ int len, i;
29
+ VALUE* ptr;
30
+
31
+ // TODO check class
32
+ len = RARRAY_LEN(array_obj);
33
+ ptr = RARRAY_PTR(array_obj);
34
+ for(i=0; i<len; i++) {
35
+ abs_arr[i] = FIX2INT(ptr[i]);
36
+ }
37
+
38
+ for(; i<ABS_CNT; i++){
39
+ abs_arr[i] = 0;
40
+ }
41
+
42
+ return len;
43
+ }
44
+
45
+ VALUE uinput_user_dev_raw_initalize(VALUE self, VALUE bytes)
46
+ {
47
+ struct uinput_user_dev *uud;
48
+ uud = RSTRING(bytes)->ptr;
49
+ printf("name: %s, ff_effects_max: %d\n", uud->name, uud->ff_effects_max);
50
+ printf("id.bustype: %d, id.version: %d\n", uud->id.bustype, uud->id.version);
51
+ printf("firsts-> absmax: %d, absflat: %d \n", uud->absmax[0], uud->absflat[0]);
52
+ }
53
+
54
+ VALUE uinput_user_dev_to_byte_string(VALUE self)
55
+ {
56
+ struct uinput_user_dev uud;
57
+ char* name;
58
+ VALUE value_tmp;
59
+
60
+ // TODO check @name size
61
+ // @name
62
+ value_tmp = rb_iv_get(self, "@name");
63
+ if(TYPE(value_tmp) != T_STRING){
64
+ type_exception("@name", "String");
65
+ return Qnil;
66
+ }
67
+ strncpy(uud.name, StringValuePtr(value_tmp), UINPUT_MAX_NAME_SIZE);
68
+
69
+ // @id
70
+ value_tmp = rb_iv_get(self, "@id");
71
+ if(TYPE(value_tmp) != T_OBJECT){
72
+ type_exception("@id", "Revdev::UserId");
73
+ return Qnil;
74
+ }
75
+ value_tmp = rb_funcall(value_tmp, rb_intern("to_byte_string"), 0);
76
+ memcpy(&(uud.id), StringValuePtr(value_tmp), sizeof(struct input_id));
77
+
78
+ // @ff_effects_max
79
+ value_tmp = rb_iv_get(self, "@ff_effects_max");
80
+ FIXNUM_P(value_tmp);
81
+ uud.ff_effects_max = FIX2INT(value_tmp);
82
+
83
+ // @absmax
84
+ abs_array_cpy(uud.absmax, rb_iv_get(self, "@absmax"));
85
+
86
+ // @absmin
87
+ abs_array_cpy(uud.absmin, rb_iv_get(self, "@absmin"));
88
+
89
+ // @absfuzz
90
+ abs_array_cpy(uud.absfuzz, rb_iv_get(self, "@absfuzz"));
91
+
92
+ // @absflat
93
+ abs_array_cpy(uud.absflat, rb_iv_get(self, "@absflat"));
94
+
95
+ return rb_str_new(&uud, sizeof(struct uinput_user_dev));
96
+ }
97
+
98
+
99
+ void Init_ruinput()
100
+ {
101
+ /* module Ruinput */
102
+ module_ruinput = rb_define_module("Ruinput");
103
+
104
+ /* class UinputUserDev */
105
+ class_uinput_user_dev =
106
+ rb_define_class_under(module_ruinput, "UinputUserDev", rb_cObject);
107
+ rb_define_method(class_uinput_user_dev, "raw_initialize",
108
+ uinput_user_dev_raw_initalize, 1);
109
+ rb_define_method(class_uinput_user_dev, "to_byte_string",
110
+ uinput_user_dev_to_byte_string, 0);
111
+
112
+ /* consts on uinput.h */
113
+ /*
114
+ generated by
115
+ grep "^#define [A-Z_]* " /usr/include/linux/uinput.h |\
116
+ sed -e 's/^#define \([A-Z_]*\) .*./rb_define_const(module_ruinput, "\1", LONG2FIX(\1));/'
117
+ */
118
+ rb_define_const(module_ruinput, "UINPUT_VERSION", LONG2FIX(UINPUT_VERSION));
119
+ rb_define_const(module_ruinput, "UINPUT_IOCTL_BASE", LONG2FIX(UINPUT_IOCTL_BASE));
120
+ rb_define_const(module_ruinput, "UI_DEV_CREATE", LONG2FIX(UI_DEV_CREATE));
121
+ rb_define_const(module_ruinput, "UI_DEV_DESTROY", LONG2FIX(UI_DEV_DESTROY));
122
+ rb_define_const(module_ruinput, "UI_SET_EVBIT", LONG2FIX(UI_SET_EVBIT));
123
+ rb_define_const(module_ruinput, "UI_SET_KEYBIT", LONG2FIX(UI_SET_KEYBIT));
124
+ rb_define_const(module_ruinput, "UI_SET_RELBIT", LONG2FIX(UI_SET_RELBIT));
125
+ rb_define_const(module_ruinput, "UI_SET_ABSBIT", LONG2FIX(UI_SET_ABSBIT));
126
+ rb_define_const(module_ruinput, "UI_SET_MSCBIT", LONG2FIX(UI_SET_MSCBIT));
127
+ rb_define_const(module_ruinput, "UI_SET_LEDBIT", LONG2FIX(UI_SET_LEDBIT));
128
+ rb_define_const(module_ruinput, "UI_SET_SNDBIT", LONG2FIX(UI_SET_SNDBIT));
129
+ rb_define_const(module_ruinput, "UI_SET_FFBIT", LONG2FIX(UI_SET_FFBIT));
130
+ // rb_define_const(module_ruinput, "UI_SET_PHYS", rb_str_new2(UI_SET_PHYS)); // fix
131
+ rb_define_const(module_ruinput, "UI_SET_SWBIT", LONG2FIX(UI_SET_SWBIT));
132
+ rb_define_const(module_ruinput, "UI_SET_PROPBIT", LONG2FIX(UI_SET_PROPBIT));
133
+ /*
134
+ * these consts return "struct uinput_ff_*"
135
+ * rb_define_const(module_ruinput, "UI_BEGIN_FF_UPLOAD", LONG2FIX(UI_BEGIN_FF_UPLOAD));
136
+ * rb_define_const(module_ruinput, "UI_END_FF_UPLOAD", LONG2FIX(UI_END_FF_UPLOAD));
137
+ * rb_define_const(module_ruinput, "UI_BEGIN_FF_ERASE", LONG2FIX(UI_BEGIN_FF_ERASE));
138
+ * rb_define_const(module_ruinput, "UI_END_FF_ERASE", LONG2FIX(UI_END_FF_ERASE));
139
+ */
140
+ rb_define_const(module_ruinput, "EV_UINPUT", LONG2FIX(EV_UINPUT));
141
+ rb_define_const(module_ruinput, "UI_FF_UPLOAD", LONG2FIX(UI_FF_UPLOAD));
142
+ rb_define_const(module_ruinput, "UI_FF_ERASE", LONG2FIX(UI_FF_ERASE));
143
+ rb_define_const(module_ruinput, "UINPUT_MAX_NAME_SIZE", LONG2FIX(UINPUT_MAX_NAME_SIZE));
144
+ }
145
+
@@ -0,0 +1,36 @@
1
+ # -*- coding:utf-8; mode:ruby; -*-
2
+
3
+ require 'revdev/each_values_equal'
4
+
5
+ module Ruinput
6
+
7
+ # import uinput_user_dev from uinput.h
8
+ #
9
+ # struct uinput_user_dev {
10
+ # char name[UINPUT_MAX_NAME_SIZE];
11
+ # struct input_id id;
12
+ # int ff_effects_max;
13
+ # int absmax[ABS_CNT];
14
+ # int absmin[ABS_CNT];
15
+ # int absfuzz[ABS_CNT];
16
+ # int absflat[ABS_CNT];
17
+ # };
18
+ class UinputUserDev
19
+ attr_accessor(:name, :id, :ff_effects_max, :absmax, :absmin,
20
+ :absfuzz, :absflat)
21
+ include Revdev::EachValuesEqual
22
+
23
+ # TODO String class
24
+ def initialize arg=nil
25
+ if arg.kind_of? Hash
26
+ [:name, :id, :ff_effects_max, :absmax,
27
+ :absmin, :absfuzz, :absflat].each do |n|
28
+ instance_variable_set("@#{n}", arg[n] || arg[n.to_s])
29
+ end
30
+ elsif not arg.nil?
31
+ raise ArgumentError, "expected a Hash"
32
+ end
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module Ruinput
2
+ VERSION = "0.0.1"
3
+ end
data/lib/ruinput.rb ADDED
@@ -0,0 +1,10 @@
1
+ # -*- coding:utf-8; mode:ruby; -*-
2
+
3
+ require "ruinput/version"
4
+ require "ruinput/ruinput.so"
5
+
6
+ require "ruinput/uinput_user_dev"
7
+
8
+ module Ruinput
9
+ class UinputUserDev;end
10
+ end
data/ruinput.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ #-*- coding:utf-8-unix; mode:ruby; -*-
2
+
3
+ require File.expand_path('../lib/ruinput/version', __FILE__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.authors = ["Keiichiro Ui"]
7
+ gem.email = ["keiichiro.ui@gmail.com"]
8
+ gem.description = "a ruby binding for uinput.h"
9
+ gem.summary = "ruinput is a ruby binding for uinput.h."
10
+ gem.homepage = "https://rubygems.org/gems/ruinput"
11
+
12
+ gem.files = `git ls-files`.split($\)
13
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
14
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
+ gem.name = "ruinput"
16
+ gem.require_paths = ["lib"]
17
+ gem.version = Ruinput::VERSION
18
+
19
+ gem.add_dependency 'revdev', '>= 0.1.0'
20
+ gem.add_development_dependency 'rake'
21
+ gem.add_development_dependency 'bundler'
22
+ end
@@ -0,0 +1,14 @@
1
+ # -*- coding:utf-8; mode:ruby; -*-
2
+
3
+ require 'test/unit'
4
+ require 'ruinput'
5
+
6
+ class UinputUserDevTest < Test::Unit::TestCase
7
+ include Ruinput
8
+
9
+ def test_consts
10
+ puts "Ruinput.constants.length = #{Ruinput.constants.length}"
11
+ assert Ruinput.constants.length > 10
12
+ end
13
+
14
+ end
@@ -0,0 +1,28 @@
1
+ # -*- coding:utf-8; mode:ruby; -*-
2
+
3
+ require 'test/unit'
4
+ require 'rubygems'
5
+ require 'revdev'
6
+ require 'ruinput'
7
+
8
+ class UinputUserDevTest < Test::Unit::TestCase
9
+ include Ruinput
10
+
11
+ def test_init
12
+ assert_nothing_raised do
13
+ u = UinputUserDev.new :name => ""
14
+ end
15
+ end
16
+
17
+ def test_to_byte_string
18
+ id = Revdev::InputId.new :bustype => 1, :vendor => 2, :product => 3,
19
+ :version => 4
20
+ u = UinputUserDev.new :name => "foo", :id => id, :ff_effects_max => 100,
21
+ :absmax => [20], :absmin => [30], :absfuzz => [4], :absflat => [5]
22
+
23
+ assert_nothing_raised do
24
+ u.raw_initialize u.to_byte_string
25
+ end
26
+ end
27
+
28
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruinput
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Keiichiro Ui
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-04-15 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: revdev
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 27
29
+ segments:
30
+ - 0
31
+ - 1
32
+ - 0
33
+ version: 0.1.0
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :development
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: bundler
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ type: :development
63
+ version_requirements: *id003
64
+ description: a ruby binding for uinput.h
65
+ email:
66
+ - keiichiro.ui@gmail.com
67
+ executables: []
68
+
69
+ extensions: []
70
+
71
+ extra_rdoc_files: []
72
+
73
+ files:
74
+ - .gitignore
75
+ - Gemfile
76
+ - LICENSE
77
+ - README.md
78
+ - Rakefile
79
+ - ext/ruinput/extconf.rb
80
+ - ext/ruinput/ruinput.c
81
+ - lib/ruinput.rb
82
+ - lib/ruinput/uinput_user_dev.rb
83
+ - lib/ruinput/version.rb
84
+ - ruinput.gemspec
85
+ - test/test_ruinput.rb
86
+ - test/test_uinput_user_dev.rb
87
+ homepage: https://rubygems.org/gems/ruinput
88
+ licenses: []
89
+
90
+ post_install_message:
91
+ rdoc_options: []
92
+
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ requirements: []
114
+
115
+ rubyforge_project:
116
+ rubygems_version: 1.7.2
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: ruinput is a ruby binding for uinput.h.
120
+ test_files:
121
+ - test/test_ruinput.rb
122
+ - test/test_uinput_user_dev.rb