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 +4 -4
- data/cupsffi.gemspec +0 -1
- data/lib/cupsffi/lib.rb +1 -0
- data/lib/cupsffi/printer.rb +44 -15
- data/lib/cupsffi/version.rb +1 -1
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbc08d6e444be4d168fa260c3cbf956173b8406d
|
4
|
+
data.tar.gz: afb009dba1a0297adb2d0ac7f00c1bc6e1c47b65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/cupsffi/printer.rb
CHANGED
@@ -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
|
-
|
53
|
-
|
54
|
-
ary.push(d[:name].dup)
|
74
|
+
walk_attributes(connection) do |dest|
|
75
|
+
ary.push(dest[:name].dup)
|
55
76
|
end
|
56
|
-
|
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
|
-
|
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
|
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
|
data/lib/cupsffi/version.rb
CHANGED
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.
|
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-
|
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
|