ffi-cups2 0.4.0 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6209044ae5c1ea2448cab3e8d044f33adf328b4fad06cd61869c68dbbf54855
4
- data.tar.gz: e4cdd08e543a84abf899938f47a175910476cb5abbb0ff21005c29d951c3c217
3
+ metadata.gz: eba1754e517994c97f2e5ba9267ec825f66e25d288034fa14c0f95b34a8e595e
4
+ data.tar.gz: 2e60bc299d09ce8e1140ed6a742668d299f9709c10bd3c7d12f8b0af873feede
5
5
  SHA512:
6
- metadata.gz: 3afe3c436e6f6f42f70f716289e27d88890e2460302a1bc2dbad2df1e69157228373a2fc37e2419e4dbb5fd32229d32d3681e5f847260e3b87adada433d8735e
7
- data.tar.gz: 5f189e1fc6dc75c059bece9e7109a1f3e4254cbf8daff8eef768378230cd632f23df1a58611387befea69a16a9ce2e98d094658caec061efa1a3532fc668e12b
6
+ metadata.gz: 479520947edf9e94cef4550f7ad3de1706c49eddb0e22a6fce94d4ea1c9562183863cef41e955e88cdceee2d13a3819fdb6f5a669d2eca2c79488f2cbbf02a5c
7
+ data.tar.gz: ffac852d7a53d8083b7b45869d260353b4a4697fddb2470068ccef370d51cc4b0811bdc6cc658c6a1627454069835539e19555b75df8791ae7824f5f5cd17525
checksums.yaml.gz.sig CHANGED
Binary file
@@ -8,13 +8,13 @@ module Cups
8
8
  @hostname = hostname
9
9
  @port = port.nil? ? 631 : port
10
10
  end
11
-
11
+
12
12
  # Wrapper around {::Cups::Http#httpConnectEncrypt}
13
13
  # @deprecated Use {#httpConnect2} instead
14
- # @return [Pointer] a http pointer
14
+ # @return [Pointer] a http pointer
15
15
  def httpConnectEncrypt
16
16
  http = Cups::Http.httpConnectEncrypt(hostname, port, Cups.cupsEncryption())
17
- raise "Print server at #{hostname}:#{port} is not available" if http.null?
17
+ raise ConnectError, "Print server at #{hostname}:#{port} is not available" if http.null?
18
18
  return http
19
19
  end
20
20
  deprecate :httpConnectEncrypt, "This function is deprecated by CUPS, please use httpConnect2 instead", 2025, 12
@@ -24,7 +24,7 @@ module Cups
24
24
  # @return [Pointer] a http pointer
25
25
  def httpConnect2
26
26
  http = Cups::Http.httpConnect2(hostname, port, nil, 0, Cups.cupsEncryption(), 1, 30000, nil)
27
- raise "Print server at #{hostname}:#{port} is not available" if http.null?
27
+ raise ConnectError, "Print server at #{hostname}:#{port} is not available" if http.null?
28
28
  return http
29
29
  end
30
30
 
data/lib/ffi-cups/job.rb CHANGED
@@ -23,7 +23,7 @@ module Cups
23
23
  def cancel(purge=0, connection=nil)
24
24
  job = self.class.get_job(@id, @printer, -1, connection)
25
25
  r = Cups.cupsCancelJob2(connection, @printer, @id, purge)
26
- raise Cups.cupsLastErrorString() if r == 0
26
+ raise CupsError, Cups.cupsLastErrorString() if r == 0
27
27
  return r
28
28
  end
29
29
 
@@ -60,7 +60,7 @@ module Cups
60
60
  jobs.each do |j|
61
61
  return j if j.id == id
62
62
  end
63
- raise "Job with id: #{id} not found!"
63
+ raise JobNotFound, "Job with id: #{id} not found!"
64
64
  end
65
65
 
66
66
  private
@@ -75,7 +75,7 @@ module Cups
75
75
  num_jobs = Cups.cupsGetJobs2(http, pointer, name, 0, filter)
76
76
  size = Cups::Struct::Job.size
77
77
  jobs = []
78
-
78
+
79
79
  num_jobs.times do |i|
80
80
  job = Cups::Struct::Job.new(pointer.get_pointer(0) + (size * i))
81
81
  jobs.push(job)
@@ -34,7 +34,7 @@ module Cups
34
34
  #
35
35
  # @return [Cups::Job] can be used to check on the job status.
36
36
  def print_file(filename, title, options={})
37
- raise "File not found: #{filename}" unless File.exist? filename
37
+ raise FileNotFound, "File not found: #{filename}" unless File.exist? filename
38
38
 
39
39
  http = @connection.nil? ? nil : @connection.httpConnect2
40
40
  with_destination(http) do |dest|
@@ -55,7 +55,7 @@ module Cups
55
55
  job_id = Cups.cupsPrintFile2(http, @name, filename, title, num_options, p_options)
56
56
 
57
57
  if job_id == 0
58
- raise Cups.cupsLastErrorString()
58
+ raise CupsError, Cups.cupsLastErrorString()
59
59
  end
60
60
  #Cups::Job.new(job_id, title, @name)
61
61
  Cups::Job.get_job(job_id, @name, 0, @connection)
@@ -87,7 +87,7 @@ module Cups
87
87
 
88
88
  job_id = Cups.cupsCreateJob(http, @name, title, num_options, p_options)
89
89
  if job_id == 0
90
- raise CupsFFI::cupsLastErrorString()
90
+ raise CupsError, CupsFFI::cupsLastErrorString()
91
91
  end
92
92
 
93
93
  # Copy the data into a char pointer to allow null bytes
@@ -103,7 +103,7 @@ module Cups
103
103
 
104
104
  data_pointer.free
105
105
 
106
- raise ipp_status.to_s unless ipp_status == :ipp_ok
106
+ raise CupsError, ipp_status.to_s unless ipp_status == :ipp_ok
107
107
 
108
108
  Cups::Job.get_job(job_id, @name, 0, @connection)
109
109
  ensure
@@ -125,7 +125,7 @@ module Cups
125
125
  # Get the destination from name with cupsGetDest
126
126
  p_dest = Cups.cupsGetDest(name, nil, num_dests, dests.get_pointer(0))
127
127
  dest = Cups::Struct::Destination.new(p_dest)
128
- raise "Destination with name: #{name} not found!" if dest.null?
128
+ raise DestinationNotFound, "Destination with name: #{name} not found!" if dest.null?
129
129
  yield dest
130
130
  ensure
131
131
  Cups.cupsFreeDests(num_dests, dests.get_pointer(0))
@@ -213,12 +213,12 @@ module Cups
213
213
  def ppd_options
214
214
  ppd_path = Cups::Ppd.cupsGetPPD(name)
215
215
  if ppd_path.nil? || ppd_path.empty?
216
- raise "Error: Could not retrieve PPD for printer '#{name}'"
216
+ raise CupsError, "Error: Could not retrieve PPD for printer '#{name}'"
217
217
  end
218
218
 
219
219
  ppd_ptr = Cups::Ppd.ppdOpenFile(ppd_path)
220
220
  if ppd_ptr.null?
221
- raise "Error: Failed to open PPD file at #{ppd_path}"
221
+ raise CupsError, "Error: Failed to open PPD file at #{ppd_path}"
222
222
  end
223
223
 
224
224
  # Let CUPS evaluate current printer system runtime option defaults
@@ -1,3 +1,3 @@
1
1
  module Cups
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/ffi-cups.rb CHANGED
@@ -1,6 +1,18 @@
1
1
  require 'ffi'
2
2
 
3
3
  module Cups
4
+ class Error < RuntimeError
5
+ end
6
+ class FileNotFound < Error
7
+ end
8
+ class JobNotFound < Error
9
+ end
10
+ class ConnectError < Error
11
+ end
12
+ class DestinationNotFound < Error
13
+ end
14
+ class CupsError < Error
15
+ end
4
16
 
5
17
  # Custom or default path for libcups.so
6
18
  def self.libcups
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-cups2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hugo Marquez
metadata.gz.sig CHANGED
Binary file