cupsffi 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac820f12c69456581085fbe72a228553dd9a65b8
4
- data.tar.gz: 8de484ae6f6eb15b4c1acf6b2491dbc92a9b1d3e
3
+ metadata.gz: dbc08d6e444be4d168fa260c3cbf956173b8406d
4
+ data.tar.gz: afb009dba1a0297adb2d0ac7f00c1bc6e1c47b65
5
5
  SHA512:
6
- metadata.gz: ebedc3464a41ae253f6a0ebed5ba1d2410e74671777fa8cf5ff33a7afa15b60349f41bc3e4f8138fbdc3491449d7b48c43d0bd783bf0233def6625f67badf662
7
- data.tar.gz: 4b632a6e5f0f0f5a0c135a07c72ce78fcb53e775708f23157e760c6946c4e7283f59716d1d17fcd5d76367e20d2165f86a0c20c31598cdab4c977d3eae5858c5
6
+ metadata.gz: 5f338d344ed18fa3c5807288df26597ac566bea57f08f092110c09c348f459aceeda6173a0cf90042a974da8cb7c1c369d7dae46cbdda2f577de715bb9f6584d
7
+ data.tar.gz: a2f491527db5a40bc39da4e5144f0b0394cfdfa8f604b19a5d826d1963d17281dcf32d307bb5658debe184211a35933d054543a73f3a936c74ff5d4e4f9fc88a
data/cupsffi.gemspec CHANGED
@@ -12,7 +12,6 @@ Gem::Specification.new do |s|
12
12
  s.summary = %q{FFI wrapper around libcups}
13
13
  s.description = %q{Simple wrapper around libcups to give CUPS printing capabilities to Ruby apps.}
14
14
 
15
- s.add_development_dependency "ffi"
16
15
  s.add_runtime_dependency "ffi"
17
16
 
18
17
  s.rubyforge_project = "cupsffi"
data/lib/cupsffi/lib.rb CHANGED
@@ -172,6 +172,7 @@ module CupsFFI
172
172
 
173
173
  attach_function 'cupsEncryption', [], :int
174
174
  attach_function 'httpConnectEncrypt', [ :string, :int, :int], :pointer
175
+ attach_function 'httpClose', [ :pointer ], :void
175
176
 
176
177
 
177
178
  attach_function 'cupsGetDests', [ :pointer ], :int
@@ -37,40 +37,69 @@ class CupsPrinter
37
37
  end
38
38
  end
39
39
 
40
+ def self.walk_attributes(connection)
41
+ p = FFI::MemoryPointer.new :pointer
42
+ dest_count = CupsFFI::cupsGetDests2(connection, p)
43
+ dest_count.times do |i|
44
+ dest = CupsFFI::CupsDestS.new(p.get_pointer(0) + (CupsFFI::CupsDestS.size * i))
45
+ yield dest
46
+ end
47
+ CupsFFI::cupsFreeDests(dest_count, p.get_pointer(0))
48
+ end
49
+
50
+ def self.walk_sub_attributes(dest)
51
+ dest[:num_options].times do |j|
52
+ options = CupsFFI::CupsOptionS.new(dest[:options] + (CupsFFI::CupsOptionS.size * j))
53
+ yield options
54
+ end
55
+ end
56
+
57
+ def self.release_connection(connection)
58
+ CupsFFI::httpClose(connection)
59
+ end
60
+
40
61
  def initialize(name, args = {})
41
62
  raise "Printer not found" unless CupsPrinter.get_all_printer_names(args).include? name
42
63
  @name = name
43
64
  @connection = CupsPrinter.get_connection(args)
44
65
  end
45
66
 
67
+ def close
68
+ CupsPrinter.release_connection(@connection)
69
+ end
70
+
46
71
  def self.get_all_printer_names(args = {})
47
72
  connection = get_connection(args)
48
-
49
- p = FFI::MemoryPointer.new :pointer
50
- dest_count = CupsFFI::cupsGetDests2(connection, p)
51
73
  ary = []
52
- dest_count.times do |i|
53
- d = CupsFFI::CupsDestS.new(p.get_pointer(0) + (CupsFFI::CupsDestS.size * i))
54
- ary.push(d[:name].dup)
74
+ walk_attributes(connection) do |dest|
75
+ ary.push(dest[:name].dup)
55
76
  end
56
- CupsFFI::cupsFreeDests(dest_count, p.get_pointer(0))
77
+ release_connection(connection)
57
78
  ary
58
79
  end
59
80
 
81
+ def self.get_all_printer_attrs(args = {})
82
+ connection = get_connection(args)
83
+ hash = {}
84
+ walk_attributes(connection) do |dest|
85
+ pname = dest[:name].dup
86
+ hash[pname] ||= {}
87
+ walk_sub_attributes(dest) do |options|
88
+ hash[pname][options[:name].dup] = options[:value].dup
89
+ end
90
+ end
91
+ release_connection(connection)
92
+ hash
93
+ end
94
+
60
95
  def attributes
61
- p = FFI::MemoryPointer.new :pointer
62
- dest_count = CupsFFI::cupsGetDests2(@connection, p)
63
96
  hash = {}
64
- dest_count.times do |i|
65
- dest = CupsFFI::CupsDestS.new(p.get_pointer(0) + (CupsFFI::CupsDestS.size * i))
97
+ CupsPrinter.walk_attributes(@connection) do |dest|
66
98
  next unless dest[:name] == @name
67
- dest[:num_options].times do |j|
68
- options = CupsFFI::CupsOptionS.new(dest[:options] + (CupsFFI::CupsOptionS.size * j))
99
+ CupsPrinter.walk_sub_attributes(dest) do |options|
69
100
  hash[options[:name].dup] = options[:value].dup
70
101
  end
71
102
  end
72
- CupsFFI::cupsFreeDests(dest_count, p.get_pointer(0))
73
- hash
74
103
  end
75
104
 
76
105
  def state
@@ -1,3 +1,3 @@
1
1
  module Cupsffi
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cupsffi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Ehresman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-21 00:00:00.000000000 Z
11
+ date: 2014-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: ffi
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '>='
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '>='
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: ffi
29
15
  requirement: !ruby/object:Gem::Requirement