ffi-gphoto2 0.4.1 → 0.5.0

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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +2 -1
  3. data/Rakefile +2 -0
  4. data/examples/intervalometer.rb +9 -7
  5. data/examples/list_config.rb +3 -5
  6. data/examples/live_view.rb +6 -12
  7. data/examples/record_movie.rb +10 -13
  8. data/ffi-gphoto2.gemspec +2 -1
  9. data/lib/ffi/gphoto2_port.rb +2 -2
  10. data/lib/gphoto2/camera/capture.rb +59 -0
  11. data/lib/gphoto2/camera/configuration.rb +136 -0
  12. data/lib/gphoto2/camera/event.rb +56 -0
  13. data/lib/gphoto2/camera/filesystem.rb +44 -0
  14. data/lib/gphoto2/camera.rb +95 -166
  15. data/lib/gphoto2/camera_abilities.rb +6 -6
  16. data/lib/gphoto2/camera_abilities_list.rb +7 -6
  17. data/lib/gphoto2/camera_event.rb +1 -8
  18. data/lib/gphoto2/camera_file.rb +15 -5
  19. data/lib/gphoto2/camera_file_path.rb +3 -5
  20. data/lib/gphoto2/camera_folder.rb +11 -0
  21. data/lib/gphoto2/camera_list.rb +3 -10
  22. data/lib/gphoto2/camera_widgets/camera_widget.rb +27 -14
  23. data/lib/gphoto2/camera_widgets/radio_camera_widget.rb +1 -0
  24. data/lib/gphoto2/camera_widgets/range_camera_widget.rb +1 -0
  25. data/lib/gphoto2/context.rb +2 -6
  26. data/lib/gphoto2/entry.rb +2 -0
  27. data/lib/gphoto2/port_info.rb +8 -6
  28. data/lib/gphoto2/port_info_list.rb +5 -6
  29. data/lib/gphoto2/port_result.rb +2 -0
  30. data/lib/gphoto2/struct.rb +11 -0
  31. data/lib/gphoto2/version.rb +1 -1
  32. data/lib/gphoto2.rb +13 -0
  33. data/spec/gphoto2/camera_abilities_list_spec.rb +5 -5
  34. data/spec/gphoto2/camera_abilities_spec.rb +7 -7
  35. data/spec/gphoto2/camera_file_path_spec.rb +2 -2
  36. data/spec/gphoto2/camera_file_spec.rb +7 -7
  37. data/spec/gphoto2/camera_folder_spec.rb +3 -3
  38. data/spec/gphoto2/camera_list_spec.rb +3 -3
  39. data/spec/gphoto2/camera_spec.rb +37 -272
  40. data/spec/gphoto2/camera_widgets/date_camera_widget_spec.rb +1 -1
  41. data/spec/gphoto2/camera_widgets/radio_camera_widget_spec.rb +4 -4
  42. data/spec/gphoto2/camera_widgets/range_camera_widget_spec.rb +2 -2
  43. data/spec/gphoto2/camera_widgets/text_camera_widget_spec.rb +1 -1
  44. data/spec/gphoto2/camera_widgets/toggle_camera_widget_spec.rb +2 -2
  45. data/spec/gphoto2/context_spec.rb +1 -1
  46. data/spec/gphoto2/entry_spec.rb +2 -2
  47. data/spec/gphoto2/port_info_list_spec.rb +4 -4
  48. data/spec/gphoto2/port_info_spec.rb +9 -10
  49. data/spec/spec_helper.rb +0 -7
  50. data/spec/support/shared_examples/camera/capture_examples.rb +41 -0
  51. data/spec/support/shared_examples/camera/configuration_examples.rb +161 -0
  52. data/spec/support/shared_examples/camera/event_examples.rb +39 -0
  53. data/spec/support/shared_examples/camera/filesystem_examples.rb +46 -0
  54. data/spec/support/shared_examples/camera_widget_examples.rb +13 -13
  55. metadata +32 -4
@@ -1,21 +1,19 @@
1
1
  module GPhoto2
2
2
  class CameraFilePath
3
- attr_reader :ptr
3
+ include GPhoto2::Struct
4
4
 
5
5
  def initialize(ptr = nil)
6
6
  @ptr = ptr || FFI::GPhoto2::CameraFilePath.new
7
7
  end
8
8
 
9
+ # @return [String]
9
10
  def name
10
11
  ptr[:name].to_s
11
12
  end
12
13
 
14
+ # @return [String]
13
15
  def folder
14
16
  ptr[:folder].to_s
15
17
  end
16
-
17
- def to_ptr
18
- @ptr
19
- end
20
18
  end
21
19
  end
@@ -2,6 +2,7 @@ module GPhoto2
2
2
  class CameraFolder
3
3
  include FFI::GPhoto2
4
4
 
5
+ # @return [String]
5
6
  attr_reader :path
6
7
 
7
8
  def initialize(camera, path = '/')
@@ -9,10 +10,12 @@ module GPhoto2
9
10
  @path = path
10
11
  end
11
12
 
13
+ # @return [Boolean]
12
14
  def root?
13
15
  @path == '/'
14
16
  end
15
17
 
18
+ # @return [String]
16
19
  def name
17
20
  if root?
18
21
  '/'
@@ -21,14 +24,18 @@ module GPhoto2
21
24
  end
22
25
  end
23
26
 
27
+ # @return [Array<GPhoto2::CameraFolder>]
24
28
  def folders
25
29
  folder_list_folders
26
30
  end
27
31
 
32
+ # @return [Array<GPhoto2::CameraFile>]
28
33
  def files
29
34
  folder_list_files
30
35
  end
31
36
 
37
+ # @param [String] name the name of the directory
38
+ # @return [GPhoto2::CameraFolder]
32
39
  def cd(name)
33
40
  case name
34
41
  when '.'
@@ -41,10 +48,13 @@ module GPhoto2
41
48
  end
42
49
  alias_method :/, :cd
43
50
 
51
+ # @param [String] name the filename of the file to open
52
+ # @return [GPhoto2::CameraFile]
44
53
  def open(name)
45
54
  CameraFile.new(@camera, @path, name)
46
55
  end
47
56
 
57
+ # @return [GPhoto2::CameraFolder]
48
58
  def up
49
59
  if root?
50
60
  self
@@ -55,6 +65,7 @@ module GPhoto2
55
65
  end
56
66
  end
57
67
 
68
+ # @return [String]
58
69
  def to_s
59
70
  name
60
71
  end
@@ -1,30 +1,23 @@
1
1
  module GPhoto2
2
2
  class CameraList
3
3
  include FFI::GPhoto2
4
-
5
- attr_reader :ptr
4
+ include GPhoto2::Struct
6
5
 
7
6
  def initialize
8
7
  new
9
8
  end
10
9
 
11
- def finalize
12
- free
13
- end
14
-
10
+ # @return [Integer]
15
11
  def size
16
12
  count
17
13
  end
18
14
  alias_method :length, :size
19
15
 
16
+ # @return [Array<GPhoto2::Entry>]
20
17
  def to_a
21
18
  size.times.map { |i| Entry.new(self, i) }
22
19
  end
23
20
 
24
- def to_ptr
25
- @ptr
26
- end
27
-
28
21
  private
29
22
 
30
23
  def new
@@ -1,9 +1,11 @@
1
1
  module GPhoto2
2
+ # @abstract
2
3
  class CameraWidget
3
4
  include FFI::GPhoto2
5
+ include GPhoto2::Struct
4
6
 
5
- attr_reader :ptr
6
-
7
+ # @param [FFI::GPhoto2::CameraWidget] ptr
8
+ # @param [GPhoto2::CameraWidget] parent
7
9
  def self.factory(ptr, parent = nil)
8
10
  # ptr fields are supposed to be private, but we ignore that here
9
11
  type = ptr[:type].to_s.split('_').last.capitalize
@@ -11,41 +13,52 @@ module GPhoto2
11
13
  klass.new(ptr, parent)
12
14
  end
13
15
 
16
+ # @param [FFI::GPhoto2::CameraWidget] ptr
17
+ # @param [GPhoto2::CameraWidget] parent
14
18
  def initialize(ptr, parent = nil)
15
19
  @ptr = ptr
16
20
  @parent = parent
17
21
  end
18
22
 
23
+ # @return [void]
19
24
  def finalize
20
25
  free
21
26
  end
22
27
  alias_method :close, :finalize
23
28
 
29
+ # @return [String]
24
30
  def label
25
31
  get_label
26
32
  end
27
33
 
34
+ # @return [String]
28
35
  def name
29
36
  get_name
30
37
  end
31
38
 
39
+ # @return [Object]
32
40
  def value
33
41
  get_value
34
42
  end
35
43
 
44
+ # @return [Object]
36
45
  def value=(value)
37
46
  set_value(value)
38
47
  value
39
48
  end
40
49
 
50
+ # @return [CameraWidgetType]
41
51
  def type
42
52
  get_type
43
53
  end
44
54
 
55
+ # @return [Array<GPhoto2::CameraWidget>]
45
56
  def children
46
57
  count_children.times.map { |i| get_child(i) }
47
58
  end
48
59
 
60
+ # @param [Hash<String,GPhoto2::CameraWidget>] map
61
+ # @return [Hash<String,GPhoto2::CameraWidget>]
49
62
  def flatten(map = {})
50
63
  case type
51
64
  when :window, :section
@@ -59,12 +72,19 @@ module GPhoto2
59
72
  map
60
73
  end
61
74
 
75
+ # @param [String]
62
76
  def to_s
63
77
  value.to_s
64
78
  end
65
79
 
66
- def to_ptr
67
- @ptr
80
+ protected
81
+
82
+ def get_value
83
+ raise NotImplementedError
84
+ end
85
+
86
+ def set_value(value)
87
+ raise NotImplementedError
68
88
  end
69
89
 
70
90
  private
@@ -86,14 +106,6 @@ module GPhoto2
86
106
  str_ptr.null? ? nil : str_ptr.read_string
87
107
  end
88
108
 
89
- def get_value
90
- raise NotImplementedError
91
- end
92
-
93
- def set_value(value)
94
- raise NotImplementedError
95
- end
96
-
97
109
  def get_type
98
110
  # assume CameraWidgetType is an int
99
111
  type = FFI::MemoryPointer.new(:int)
@@ -108,15 +120,16 @@ module GPhoto2
108
120
  str_ptr.write_pointer(str)
109
121
 
110
122
  rc = gp_widget_get_type(ptr, str_ptr)
123
+ GPhoto2.check!(rc)
111
124
 
112
125
  str_ptr = str_ptr.read_pointer
113
126
  str_ptr.null? ? nil : str_ptr.read_string
114
127
  end
115
128
 
116
129
  def count_children
117
- rc = gp_widget_count_children(ptr)
130
+ count = rc = gp_widget_count_children(ptr)
118
131
  GPhoto2.check!(rc)
119
- rc
132
+ count
120
133
  end
121
134
 
122
135
  def get_child(index)
@@ -1,5 +1,6 @@
1
1
  module GPhoto2
2
2
  class RadioCameraWidget < CameraWidget
3
+ # @return [Array<String>]
3
4
  def choices
4
5
  count_choices.times.map { |i| get_choice(i) }
5
6
  end
@@ -1,5 +1,6 @@
1
1
  module GPhoto2
2
2
  class RangeCameraWidget < CameraWidget
3
+ # @return [Array<Number>]
3
4
  def range
4
5
  min, max, inc = get_range
5
6
  (min..max).step(inc).to_a
@@ -1,22 +1,18 @@
1
1
  module GPhoto2
2
2
  class Context
3
3
  include FFI::GPhoto2
4
-
5
- attr_reader :ptr
4
+ include GPhoto2::Struct
6
5
 
7
6
  def initialize
8
7
  new
9
8
  end
10
9
 
10
+ # @return [void]
11
11
  def finalize
12
12
  unref
13
13
  end
14
14
  alias_method :close, :finalize
15
15
 
16
- def to_ptr
17
- @ptr
18
- end
19
-
20
16
  private
21
17
 
22
18
  def new
data/lib/gphoto2/entry.rb CHANGED
@@ -7,10 +7,12 @@ module GPhoto2
7
7
  @index = index
8
8
  end
9
9
 
10
+ # @return [String]
10
11
  def name
11
12
  get_name
12
13
  end
13
14
 
15
+ # @return [String]
14
16
  def value
15
17
  get_value
16
18
  end
@@ -1,37 +1,39 @@
1
1
  module GPhoto2
2
2
  class PortInfo
3
3
  include FFI::GPhoto2Port
4
+ include GPhoto2::Struct
4
5
 
5
- attr_reader :ptr
6
-
6
+ # @param [String] port
7
+ # @return [GPhoto2::PortInfo]
7
8
  def self.find(port)
8
9
  port_info_list = PortInfoList.new
9
10
  index = port_info_list.lookup_path(port)
10
11
  port_info_list[index]
11
12
  end
12
13
 
14
+ # @param [GPhoto2::PortInfoList] port_info_list
15
+ # @param [Integer] index
13
16
  def initialize(port_info_list, index)
14
17
  @port_info_list = port_info_list
15
18
  @index = index
16
19
  new
17
20
  end
18
21
 
22
+ # @return [String]
19
23
  def name
20
24
  get_name
21
25
  end
22
26
 
27
+ # @return [String]
23
28
  def path
24
29
  get_path
25
30
  end
26
31
 
32
+ # @return [GPPortType]
27
33
  def type
28
34
  get_type
29
35
  end
30
36
 
31
- def to_ptr
32
- @ptr
33
- end
34
-
35
37
  private
36
38
 
37
39
  def new
@@ -1,28 +1,27 @@
1
1
  module GPhoto2
2
2
  class PortInfoList
3
3
  include FFI::GPhoto2Port
4
-
5
- attr_reader :ptr
4
+ include GPhoto2::Struct
6
5
 
7
6
  def initialize
8
7
  new
9
8
  load
10
9
  end
11
10
 
11
+ # @param [String] port
12
+ # @return [Integer]
12
13
  def lookup_path(port)
13
14
  _lookup_path(port)
14
15
  end
15
16
  alias_method :index, :lookup_path
16
17
 
18
+ # @param [Integer] index
19
+ # @return [GPhoto2::PortInfo]
17
20
  def at(index)
18
21
  PortInfo.new(self, index)
19
22
  end
20
23
  alias_method :[], :at
21
24
 
22
- def to_ptr
23
- @ptr
24
- end
25
-
26
25
  private
27
26
 
28
27
  def new
@@ -1,5 +1,7 @@
1
1
  module GPhoto2
2
2
  class PortResult
3
+ # @param [Integer] rc
4
+ # @return [String]
3
5
  def self.as_string(rc)
4
6
  FFI::GPhoto2Port.gp_port_result_as_string(rc)
5
7
  end
@@ -0,0 +1,11 @@
1
+ module GPhoto2
2
+ module Struct
3
+ # @return [FFI::Struct]
4
+ attr_reader :ptr
5
+
6
+ # @return [FFI::Struct]
7
+ def to_ptr
8
+ ptr
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module GPhoto2
2
- VERSION = '0.4.1'
2
+ VERSION = '0.5.0'
3
3
  end
data/lib/gphoto2.rb CHANGED
@@ -5,6 +5,8 @@ require 'ffi'
5
5
  require 'ffi/gphoto2'
6
6
  require 'ffi/gphoto2_port'
7
7
 
8
+ require 'gphoto2/struct'
9
+
8
10
  require 'gphoto2/camera_widgets/camera_widget'
9
11
  require 'gphoto2/camera_widgets/date_camera_widget'
10
12
  require 'gphoto2/camera_widgets/menu_camera_widget'
@@ -14,7 +16,13 @@ require 'gphoto2/camera_widgets/section_camera_widget'
14
16
  require 'gphoto2/camera_widgets/text_camera_widget'
15
17
  require 'gphoto2/camera_widgets/toggle_camera_widget'
16
18
  require 'gphoto2/camera_widgets/window_camera_widget'
19
+
20
+ require 'gphoto2/camera/capture'
21
+ require 'gphoto2/camera/configuration'
22
+ require 'gphoto2/camera/event'
23
+ require 'gphoto2/camera/filesystem'
17
24
  require 'gphoto2/camera'
25
+
18
26
  require 'gphoto2/camera_abilities'
19
27
  require 'gphoto2/camera_abilities_list'
20
28
  require 'gphoto2/camera_event'
@@ -27,13 +35,18 @@ require 'gphoto2/entry'
27
35
  require 'gphoto2/port_info'
28
36
  require 'gphoto2/port_info_list'
29
37
  require 'gphoto2/port_result'
38
+
30
39
  require 'gphoto2/version'
31
40
 
32
41
  module GPhoto2
42
+ # @return [Logger]
33
43
  def self.logger
34
44
  @logger ||= Logger.new(STDERR)
35
45
  end
36
46
 
47
+ # @param [Integer] rc
48
+ # @return [void]
49
+ # @raise RuntimeError when the return code is not {FFI::GPhoto2Port::GP_OK}
37
50
  def self.check!(rc)
38
51
  logger.debug "#{caller.first} => #{rc}" if ENV['DEBUG']
39
52
  return if rc >= FFI::GPhoto2Port::GP_OK