ruby-gr 0.0.16 → 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
data/lib/gr3.rb CHANGED
@@ -2,39 +2,39 @@
2
2
 
3
3
  # OverView of GR.rb
4
4
  #
5
- # +--------------------+ +--------------------+
6
- # | GR module | | GR3 module |
7
- # | +----------------+ | | +----------------+ |
8
- # | | GR::FFI | | | | GR3::FFI | |
9
- # | | + libGR.so | | | | + libGR3.so | |
10
- # | +----------------+ | | +----------------+ |
11
- # | | define_method | | | define_method |
12
- # | +----------------+ | | +----------------+ |
13
- # | | | GR::GRBase | | | | | GR3::GR3Base | |
14
- # | | v (Pri^ate) | | | | v (Pri^ate) | |
15
- # | +++--------------+ | | +++--------------+ |
16
- # | | Extend | | | Extend |
17
- # | v | | v +-------+ |
18
- # | +-----------+ | | | Check | |
19
- # | | GR::Plot | | | <--+ Error | |
20
- # | +-----------+ | | +-------+ |
21
- # +--------------------+ +----------+---------+
22
- # ^ ^
23
- # | +------------------+ |
24
- # Extend | | GRCommons module | | Extend
25
- # | | +--------------+ | |
26
- # | | | Fiddley | | |
27
- # | | +--------------+ | |
28
- # | | +--------------+ | |
29
- # +----+ CommonUtils +----+
30
- # | | +--------------+ | |
31
- # | | +--------------+ | |
32
- # +----+ Version +----+
33
- # | | +--------------+ |
34
- # | | +--------------+ |
35
- # +----+JupyterSupport| |
36
- # | +--------------+ |
37
- # +------------------+
5
+ # +--------------------+ +--------------------+
6
+ # | GR module | | GR3 module |
7
+ # | +----------------+ | | +----------------+ |
8
+ # | | GR::FFI | | | | GR3::FFI | |
9
+ # | | + libGR.so | | | | + libGR3.so | |
10
+ # | +----------------+ | | +----------------+ |
11
+ # | | define_method | | | define_method |
12
+ # | +----------------+ | | +----------------+ |
13
+ # | | | GR::GRBase | | | | | GR3::GR3Base | |
14
+ # | | v (Pri^ate) | | | | v (Pri^ate) | |
15
+ # | +++--------------+ | | +++--------------+ |
16
+ # | | Extend | | | Extend |
17
+ # | v | | v +-------+ |
18
+ # | +-----------+ | | | Check | |
19
+ # | | GR::Plot | | | <--+ Error | |
20
+ # | +-----------+ | | +-------+ |
21
+ # +--------------------+ +----------+---------+
22
+ # ^ ^
23
+ # | +------------------+ |
24
+ # Extend | | GRCommons module | | Extend
25
+ # | | +--------------+ | |
26
+ # | | | Fiddley | | |
27
+ # | | +--------------+ | |
28
+ # | | +--------------+ | |
29
+ # +----+ CommonUtils +----+
30
+ # | | +--------------+ | |
31
+ # | | +--------------+ | |
32
+ # +----+ Version +----+
33
+ # | | +--------------+ |
34
+ # | | +--------------+ |
35
+ # +----+JupyterSupport| |
36
+ # | +--------------+ |
37
+ # +------------------+
38
38
  #
39
39
  # (You can edit the above AA diagram with http://asciiflow.com/)
40
40
  #
@@ -60,23 +60,20 @@ module GR3
60
60
  attr_accessor :ffi_lib
61
61
  end
62
62
 
63
- raise Error, 'Please set env variable GRDIR' unless ENV['GRDIR']
63
+ require_relative 'gr_commons/gr_commons'
64
+ extend GRCommons::SearchSharedLibrary
64
65
 
65
66
  # Platforms | path
66
67
  # Windows | bin/libGR3.dll
67
68
  # MacOSX | lib/libGR3.so (NOT .dylib)
68
69
  # Ubuntu | lib/libGR3.so
69
- if Object.const_defined?(:RubyInstaller)
70
- self.ffi_lib = File.expand_path('bin/libGR3.dll', ENV['GRDIR'])
71
- RubyInstaller::Runtime.add_dll_directory(File.dirname(ffi_lib))
72
- else
73
- self.ffi_lib = File.expand_path('lib/libGR3.so', ENV['GRDIR'])
74
- end
70
+ self.ffi_lib = case RbConfig::CONFIG['host_os']
71
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
72
+ search_shared_library('libGR3.dll')
73
+ else
74
+ search_shared_library('libGR3.so')
75
+ end
75
76
 
76
- # change the default encoding to UTF-8.
77
- ENV['GKS_ENCODING'] ||= 'utf8'
78
-
79
- require_relative 'gr_commons/gr_commons'
80
77
  require_relative 'gr3/version'
81
78
  require_relative 'gr3/ffi'
82
79
  require_relative 'gr3/gr3base'
@@ -13,7 +13,7 @@ module GRCommons
13
13
  # NOTE: This module is only part of the original code.
14
14
  # kojix2 adds, deletes, and modifies several methods.
15
15
  module Fiddley
16
- # NOTE: GR.rb supports 2.4 +. Unpack 1 does not work under 2.3.
16
+ # NOTE: GR.rb supports 2.5 +. Unpack 1 does not work under 2.3.
17
17
 
18
18
  module Utils
19
19
  # assumes short = 16bit, int = 32bit, long long = 64bit
@@ -4,6 +4,10 @@
4
4
  module GRCommons
5
5
  end
6
6
 
7
+ # Change the default encoding to UTF-8.
8
+ ENV['GKS_ENCODING'] ||= 'utf8'
9
+
10
+ require_relative 'search_shared_library'
7
11
  require_relative 'extern'
8
12
  require_relative 'define_methods'
9
13
  require_relative 'gr_common_utils'
@@ -0,0 +1,31 @@
1
+ module GRCommons
2
+ module SearchSharedLibrary
3
+ def search_shared_library(gr_lib_name)
4
+ if Object.const_defined?(:RubyInstaller)
5
+ ENV['GRDIR'] ||= [
6
+ RubyInstaller::Runtime.msys2_installation.msys_path,
7
+ RubyInstaller::Runtime.msys2_installation.mingwarch
8
+ ].join(File::ALT_SEPARATOR)
9
+ recursive_search(gr_lib_name, ENV['GRDIR']).tap do |path|
10
+ RubyInstaller::Runtime.add_dll_directory(File.dirname(path))
11
+ end
12
+ else
13
+ unless ENV['GRDIR']
14
+ warn 'Please set environment variable GRDIR'
15
+ exit 1
16
+ end
17
+ recursive_search(gr_lib_name, ENV['GRDIR'])
18
+ end
19
+ end
20
+
21
+ def recursive_search(name, base_dir)
22
+ Dir.chdir(base_dir) do
23
+ if path = Dir["**/#{name}"].first
24
+ File.expand_path(path)
25
+ else
26
+ raise StandardError '#{name} not found in #{base_dir}'
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GRCommons
4
- VERSION = '0.0.16'
4
+ VERSION = '0.0.21'
5
5
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Check Fiddle version.
4
+ require 'fiddle'
5
+
6
+ # Check if fiddle supports variadic arguments.
7
+ # Fiddle is a standard Gem and may not have VERSION constant.
8
+ if !Fiddle.const_defined?(:VERSION) ||
9
+ (Gem::Version.new(Fiddle::VERSION) <= Gem::Version.new('1.0.0'))
10
+ raise LoadError, <<~MSG
11
+ Failed to load GRM module
12
+ Fiddle 1.0.1 or higher is required to run GRM.
13
+ See https://github.com/ruby/fiddle
14
+ MSG
15
+ end
16
+
17
+ module GRM
18
+ class Error < StandardError; end
19
+
20
+ class << self
21
+ attr_accessor :ffi_lib
22
+ end
23
+
24
+ require_relative 'gr_commons/gr_commons'
25
+ extend GRCommons::SearchSharedLibrary
26
+
27
+ # Platforms | path
28
+ # Windows | bin/libGRM.dll
29
+ # MacOSX | lib/libGRM.so (NOT .dylib)
30
+ # Ubuntu | lib/libGRM.so
31
+ self.ffi_lib = case RbConfig::CONFIG['host_os']
32
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
33
+ search_shared_library('libGRM.dll')
34
+ else
35
+ search_shared_library('libGRM.so')
36
+ end
37
+
38
+ require_relative 'grm/version'
39
+ require_relative 'grm/ffi'
40
+ require_relative 'grm/grmbase'
41
+
42
+ # `inquiry` methods etc. are defined here.
43
+ extend GRCommons::GRCommonUtils
44
+
45
+ # `XXX` is the default type in GR.
46
+ # A Ruby array or NArray passed to GR method is automatically converted to
47
+ # a Fiddley::MemoryPointer in the GRBase class.
48
+ extend GRMBase
49
+
50
+ class << self
51
+ end
52
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fiddle/import'
4
+
5
+ module GRM
6
+ # FFI Wrapper module for GRM.
7
+ # The functions for GRM are listed here.
8
+ # Add functions here when a new version of GR is released.
9
+ module FFI
10
+ extend Fiddle::Importer
11
+
12
+ begin
13
+ dlload GRM.ffi_lib
14
+ rescue LoadError
15
+ raise LoadError, 'Could not find GR Framework'
16
+ end
17
+
18
+ extend GRCommons::Extern
19
+
20
+ # Currently, the declarations of GRM functions are distributed in several
21
+ # header files.
22
+
23
+ # https://github.com/sciapp/gr/blob/master/lib/grm/args.h
24
+ try_extern 'grm_args_t *grm_args_new(void)'
25
+ try_extern 'void grm_args_delete(grm_args_t *args)'
26
+ try_extern 'int grm_args_push(grm_args_t *args, const char *key, const char *value_format, ...)'
27
+ try_extern 'int grm_args_push_buf(grm_args_t *args, const char *key, const char *value_format, const void *buffer, int apply_padding)'
28
+ try_extern 'int grm_args_contains(const grm_args_t *args, const char *keyword)'
29
+ try_extern 'void grm_args_clear(grm_args_t *args)'
30
+ try_extern 'void grm_args_remove(grm_args_t *args, const char *key)'
31
+ try_extern 'grm_args_ptr_t grm_length(double value, const char *unit)'
32
+
33
+ # https://github.com/sciapp/gr/blob/master/lib/grm/dump.h
34
+ try_extern 'void grm_dump(const grm_args_t *args, FILE *f)'
35
+ try_extern 'void grm_dump_json(const grm_args_t *args, FILE *f)'
36
+ try_extern 'char *grm_dump_json_str(void)'
37
+
38
+ # https://github.com/sciapp/gr/blob/master/lib/grm/event.h
39
+ try_extern 'int grm_register(grm_event_type_t type, grm_event_callback_t callback)'
40
+ try_extern 'int grm_unregister(grm_event_type_t type)'
41
+
42
+ # https://github.com/sciapp/gr/blob/master/lib/grm/interaction.h
43
+ try_extern 'int grm_input(const grm_args_t *input_args)'
44
+ try_extern 'int grm_get_box(const int x1, const int y1, const int x2, const int y2, const int keep_aspect_ratio, int *x, int *y, int *w, int *h)'
45
+ try_extern 'grm_input(const grm_args_t *input_args)'
46
+ try_extern 'grm_tooltip_info_t *grm_get_tooltip(const int, const int)'
47
+
48
+ # https://github.com/sciapp/gr/blob/master/lib/grm/net.h
49
+ try_extern 'void *grm_open(int is_receiver, const char *name, unsigned int id,
50
+ const char *(*custom_recv)(const char *, unsigned int),
51
+ int (*custom_send)(const char *, unsigned int, const char *))'
52
+ try_extern 'grm_args_t *grm_recv(const void *p, grm_args_t *args)'
53
+ try_extern 'int grm_send(const void *p, const char *data_desc, ...)'
54
+ try_extern 'int grm_send_buf(const void *p, const char *data_desc, const void *buffer, int apply_padding)'
55
+ try_extern 'int grm_send_ref(const void *p, const char *key, char format, const void *ref, int len)'
56
+ try_extern 'int grm_send_args(const void *p, const grm_args_t *args)'
57
+ try_extern 'void grm_close(const void *p)'
58
+
59
+ # https://github.com/sciapp/gr/blob/master/lib/grm/plot.h
60
+ try_extern 'void grm_finalize(void)'
61
+ try_extern 'int grm_clear(void)'
62
+ try_extern 'unsigned int grm_max_plotid(void)'
63
+ try_extern 'int grm_merge(const grm_args_t *args)'
64
+ try_extern 'int grm_merge_extended(const grm_args_t *args, int hold, const char *identificator)'
65
+ try_extern 'int grm_merge_hold(const grm_args_t *args)'
66
+ try_extern 'int grm_merge_named(const grm_args_t *args, const char *identificator)'
67
+ try_extern 'int grm_plot(const grm_args_t *args)'
68
+ try_extern 'int grm_switch(unsigned int id)'
69
+
70
+ # https://github.com/sciapp/gr/blob/master/lib/grm/util.h
71
+ try_extern 'FILE *grm_get_stdout(void)'
72
+ end
73
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GRM
4
+ # This module automatically converts Ruby arrays and Numo::Narray into
5
+ # Fiddley::MemoryPointer.
6
+ module GRMBase
7
+ extend GRCommons::DefineMethods
8
+ define_ffi_methods(FFI,
9
+ prefix: 'grm_',
10
+ default_type: :float) # FIXME!
11
+ end
12
+ private_constant :GRMBase
13
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GRM
4
+ VERSION = GRCommons::VERSION
5
+ end
metadata CHANGED
@@ -1,23 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-gr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-30 00:00:00.000000000 Z
11
+ date: 2020-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: histogram
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
- type: :development
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
@@ -25,7 +25,21 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: histogram
28
+ name: numo-narray
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
@@ -39,7 +53,7 @@ dependencies:
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
- name: numo-narray
56
+ name: fiddle
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - ">="
@@ -146,11 +160,17 @@ files:
146
160
  - lib/gr_commons/gr_common_utils.rb
147
161
  - lib/gr_commons/gr_commons.rb
148
162
  - lib/gr_commons/jupyter_support.rb
163
+ - lib/gr_commons/search_shared_library.rb
149
164
  - lib/gr_commons/version.rb
165
+ - lib/grm.rb
166
+ - lib/grm/ffi.rb
167
+ - lib/grm/grmbase.rb
168
+ - lib/grm/version.rb
150
169
  homepage: https://github.com/red-data-tools/GR.rb
151
170
  licenses:
152
171
  - MIT
153
- metadata: {}
172
+ metadata:
173
+ msys2_mingw_dependencies: gr
154
174
  post_install_message:
155
175
  rdoc_options: []
156
176
  require_paths:
@@ -159,7 +179,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
159
179
  requirements:
160
180
  - - ">="
161
181
  - !ruby/object:Gem::Version
162
- version: '2.4'
182
+ version: '2.5'
163
183
  required_rubygems_version: !ruby/object:Gem::Requirement
164
184
  requirements:
165
185
  - - ">="