ffi-cups 0.1.9 → 0.3.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 +4 -4
- data/README.md +26 -22
- data/lib/ffi-cups/connection.rb +7 -25
- data/lib/ffi-cups/constants.rb +89 -89
- data/lib/ffi-cups/ffi/array.rb +2 -2
- data/lib/ffi-cups/ffi/cups.rb +8 -5
- data/lib/ffi-cups/ffi/http.rb +4 -4
- data/lib/ffi-cups/job.rb +80 -2
- data/lib/ffi-cups/printer.rb +18 -17
- data/lib/ffi-cups/version.rb +1 -1
- data/lib/ffi-cups.rb +5 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7522a8f004aef5162693ba55306f59971b2ab415210574b2bd9f64ed5b38e108
|
4
|
+
data.tar.gz: 54631757a4c36c0bfcc97d02e17a4f105d1cbd71562c816305bf8b7856448840
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1019c7ca45a16385c847b756052adbd2c5d0cef20149ec642e14428af3fe2aa20b3e58932e1da2a9b7bd69f5a62b0aea652905fc3aef67da65f3bab2ef4bba63
|
7
|
+
data.tar.gz: 6d17ccd12bc7449f92ce2dd6b9f4f02d0a2fcb277836984651ae8a05bbef6c8f3d878eb7ad732cdcb91935e89db759f7211ff704dc3f91c63124295a2b12deef
|
data/README.md
CHANGED
@@ -1,31 +1,18 @@
|
|
1
|
-
#
|
1
|
+
# FFI-Cups
|
2
2
|
[](https://badge.fury.io/rb/ffi-cups)
|
3
3
|
|
4
|
-
ffi-cups is a FFI
|
5
|
-
It was written using Ruby 2.7.0.
|
4
|
+
ffi-cups is a FFI bindings for libcups providing access to the Cups API through Ruby.
|
6
5
|
|
7
|
-
|
8
|
-
This is a complete rewrite of the cupsffi gem, it will deprecate
|
9
|
-
functions deprecated by the CUPS API, if you wish to continue to use them,
|
10
|
-
use the cupsffi gem.
|
11
|
-
|
12
|
-
## Authors
|
13
|
-
- Hugo Marquez @ www.hugomarquez.mx
|
14
|
-
- Contributors @ https://github.com/hugomarquez/ffi-cups/graphs/contributors
|
6
|
+
CUPS is the standards-based, open source printing system developed by Apple Inc. for macOS® and other UNIX®-like operating systems. CUPS uses the Internet Printing Protocol (IPP) to support printing to local and network printers. - from http://www.cups.org/
|
15
7
|
|
16
8
|
## Installation
|
17
9
|
```bash
|
18
10
|
gem install ffi-cups
|
19
11
|
```
|
20
12
|
|
21
|
-
## Setup
|
13
|
+
## Setup & Requirements
|
22
14
|
ffi-cups requires libcups2 to be installed
|
23
15
|
|
24
|
-
## TODO
|
25
|
-
- Job's state
|
26
|
-
- Cancel jobs
|
27
|
-
- Get all jobs with filters
|
28
|
-
|
29
16
|
## Example usage
|
30
17
|
```ruby
|
31
18
|
require 'ffi-cups'
|
@@ -48,12 +35,23 @@ printer.state_reasons
|
|
48
35
|
# Print a file (PDF, JPG, etc) you can pass a hash of printing options if you
|
49
36
|
# want to override the printer's default. See Cups::Constants for more options
|
50
37
|
options = {
|
51
|
-
Cups::
|
52
|
-
Cups::
|
38
|
+
Cups::MEDIA => Cups::MEDIA_A4,
|
39
|
+
Cups::ORIENTATION => Cups::ORIENTATION_LANDSCAPE
|
53
40
|
}
|
54
41
|
|
55
42
|
job = printer.print_file('/tmp/example.jpg', 'Title', options)
|
43
|
+
# <Cups::Job:0x000055c87104d1e0 @id=10, @title="README", @printer="Virtual_PDF_Printer", @format="text/plain", @state=:processing, @size=4, @completed_time=1969-12-31 18:00:00 -0600, @creation_time=2021-04-18 17:35:04 -0500, @processing_time=2021-04-18 17:35:04 -0500>
|
44
|
+
|
45
|
+
# Get all jobs from a printer
|
46
|
+
jobs = Cups::Job.get_jobs('Virtual_PDF_Printer')
|
47
|
+
# [#<Cups::Job:0x0000563aa6359008 @id=1, @title="Test Print", @printer="Virtual_PDF_Printer", @format="text/plain", @state=:completed, @size=1, @completed_time=2021-04-08 07:06:23 -0500, @creation_time=2021-04-08 07:06:18 -0500, @processing_time=2021-04-08 07:06:18 -0500>, ...]
|
48
|
+
|
49
|
+
# filtering job's query, see Constants file for more options
|
50
|
+
jobs = Cups::Job.get_jobs('Virtual_PDF_Printer', Cups::WHICHJOBS_ACTIVE)
|
56
51
|
|
52
|
+
# Query job with id and printer's name
|
53
|
+
job = Cups::Job.get_job(10, 'Virtual_PDF_Printer')
|
54
|
+
# <Cups::Job:0x000055c870fc8490 @id=10, @title="README", @printer="Virtual_PDF_Printer", @format="text/plain", @state=:completed, @size=4, @completed_time=2021-04-18 17:35:04 -0500, @creation_time=2021-04-18 17:35:04 -0500, @processing_time=2021-04-18 17:35:04 -0500>
|
57
55
|
```
|
58
56
|
|
59
57
|
## Remote CUPS Server
|
@@ -61,17 +59,23 @@ You may create a connection object passing a :hostname and/or :port arguments.
|
|
61
59
|
|
62
60
|
```ruby
|
63
61
|
# Create a Connection object with hostname and/or port
|
64
|
-
connection = Cups::Connection.
|
62
|
+
connection = Cups::Connection.new('print.example.com')
|
65
63
|
|
66
64
|
# Get all printers from the remote connection
|
67
65
|
remote_printers = Cups::Printer.get_destinations(connection)
|
68
|
-
|
69
66
|
```
|
70
67
|
|
68
|
+
## Documentation
|
69
|
+
Check out the documentation - [docs](https://www.rubydoc.info/gems/ffi-cups/0.2.1)
|
70
|
+
|
71
|
+
## Authors
|
72
|
+
- Hugo Marquez @ www.hugomarquez.mx
|
73
|
+
- Contributors @ https://github.com/hugomarquez/ffi-cups/graphs/contributors
|
74
|
+
|
71
75
|
## License
|
72
76
|
The MIT License
|
73
77
|
|
74
|
-
Copyright (c)
|
78
|
+
Copyright (c) 2022 Hugo Marquez & Contributors
|
75
79
|
|
76
80
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
77
81
|
of this software and associated documentation files (the "Software"), to deal
|
data/lib/ffi-cups/connection.rb
CHANGED
@@ -3,54 +3,36 @@ module Cups
|
|
3
3
|
extend Gem::Deprecate
|
4
4
|
|
5
5
|
attr_accessor :hostname, :port
|
6
|
-
|
7
|
-
@instance_mutex = Mutex.new
|
8
|
-
|
9
|
-
private_class_method :new
|
10
6
|
|
11
7
|
def initialize(hostname, port=nil)
|
12
8
|
@hostname = hostname
|
13
9
|
@port = port.nil? ? 631 : port
|
14
10
|
end
|
15
|
-
|
16
|
-
#
|
17
|
-
# @param hostname [String]
|
18
|
-
# @param port [Integer]
|
19
|
-
# @return [Object] a connection object
|
20
|
-
def self.instance(hostname, port=nil)
|
21
|
-
return @instance if @instance
|
22
|
-
|
23
|
-
@instance_mutex.synchronize do
|
24
|
-
@instance ||= new(hostname, port)
|
25
|
-
end
|
26
|
-
|
27
|
-
@instance
|
28
|
-
end
|
29
|
-
|
30
|
-
# Wrapper around {::FFI::Cups::Http#httpConnectEncrypt}
|
11
|
+
|
12
|
+
# Wrapper around {::Cups::Http#httpConnectEncrypt}
|
31
13
|
# @deprecated Use {#httpConnect2} instead
|
32
14
|
# @return [Pointer] a http pointer
|
33
15
|
def httpConnectEncrypt
|
34
|
-
http =
|
16
|
+
http = Cups::Http.httpConnectEncrypt(hostname, port, Cups.cupsEncryption())
|
35
17
|
raise "Print server at #{hostname}:#{port} is not available" if http.null?
|
36
18
|
return http
|
37
19
|
end
|
38
20
|
deprecate :httpConnectEncrypt, "This function is deprecated by CUPS, please use httpConnect2 instead", 2025, 12
|
39
21
|
|
40
|
-
# Wrapper around {::
|
22
|
+
# Wrapper around {::Cups::Http#httpConnect2}
|
41
23
|
# Creates a http connection to a print server
|
42
24
|
# @return [Pointer] a http pointer
|
43
25
|
def httpConnect2
|
44
|
-
http =
|
26
|
+
http = Cups::Http.httpConnect2(hostname, port, nil, 0, Cups.cupsEncryption(), 1, 30000, nil)
|
45
27
|
raise "Print server at #{hostname}:#{port} is not available" if http.null?
|
46
28
|
return http
|
47
29
|
end
|
48
30
|
|
49
31
|
# Closes the http connection and autoreleases the pointer
|
50
|
-
# Wrapper around {::
|
32
|
+
# Wrapper around {::Cups::Http#httpClose}
|
51
33
|
# @param http (Pointer)
|
52
34
|
def self.close(http)
|
53
|
-
|
35
|
+
Cups::Http.httpClose(http)
|
54
36
|
end
|
55
37
|
end
|
56
38
|
end
|
data/lib/ffi-cups/constants.rb
CHANGED
@@ -1,95 +1,95 @@
|
|
1
1
|
module Cups
|
2
2
|
# cups.h
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
FORMAT_JPEG = "image/jpeg"
|
4
|
+
FORMAT_PDF = "application/pdf"
|
5
|
+
FORMAT_TEXT = "text/plain"
|
6
|
+
JOBID_ALL = -1
|
7
|
+
WHICHJOBS_ALL = -1
|
8
|
+
WHICHJOBS_ACTIVE = 0
|
9
|
+
WHICHJOBS_COMPLETED = 1
|
10
|
+
HTTP_DEFAULT = nil
|
11
11
|
|
12
12
|
# Options and Values
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
CUPS_FINISHINGS = "CUPS_FINISHINGS"
|
17
|
-
CUPS_FINISHINGS_SUPPORTED = "finishings-supported"
|
18
|
-
|
19
|
-
CUPS_FINISHINGS_BIND = "7"
|
20
|
-
CUPS_FINISHINGS_COVER = "6"
|
21
|
-
CUPS_FINISHINGS_FOLD = "10"
|
22
|
-
CUPS_FINISHINGS_NONE = "3"
|
23
|
-
CUPS_FINISHINGS_PUNCH = "5"
|
24
|
-
CUPS_FINISHINGS_STAPLE = "4"
|
25
|
-
CUPS_FINISHINGS_TRIM = "11"
|
13
|
+
COPIES = "copies"
|
14
|
+
COPIES_SUPPORTED = "copies-supported"
|
26
15
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
16
|
+
FINISHINGS = "CUPS_FINISHINGS"
|
17
|
+
FINISHINGS_SUPPORTED = "finishings-supported"
|
18
|
+
FINISHINGS_BIND = "7"
|
19
|
+
FINISHINGS_COVER = "6"
|
20
|
+
FINISHINGS_FOLD = "10"
|
21
|
+
FINISHINGS_NONE = "3"
|
22
|
+
FINISHINGS_PUNCH = "5"
|
23
|
+
FINISHINGS_STAPLE = "4"
|
24
|
+
FINISHINGS_TRIM = "11"
|
25
|
+
|
26
|
+
# MEDIA
|
27
|
+
MEDIA = "media"
|
28
|
+
MEDIA_READY = "media-ready"
|
29
|
+
MEDIA_SUPPORTED = "media-supported"
|
30
|
+
|
31
|
+
MEDIA_3X5 = "na_index-3x5_3x5in"
|
32
|
+
MEDIA_4X6 = "na_index-4x6_4x6in"
|
33
|
+
MEDIA_5X7 = "na_5x7_5x7in"
|
34
|
+
MEDIA_8X10 = "na_govt-letter_8x10in"
|
35
|
+
MEDIA_A3 = "iso_a3_297x420mm"
|
36
|
+
MEDIA_A4 = "iso_a4_210x297mm"
|
37
|
+
MEDIA_A5 = "iso_a5_148x210mm"
|
38
|
+
MEDIA_A6 = "iso_a6_105x148mm"
|
39
|
+
MEDIA_ENV10 = "na_number-10_4.125x9.5in"
|
40
|
+
MEDIA_ENVDL = "iso_dl_110x220mm"
|
41
|
+
MEDIA_LEGAL = "na_legal_8.5x14in"
|
42
|
+
MEDIA_LETTER = "na_letter_8.5x11in"
|
43
|
+
MEDIA_PHOTO_L = "oe_photo-l_3.5x5in"
|
44
|
+
MEDIA_SUPERBA3 = "na_super-b_13x19in"
|
45
|
+
MEDIA_TABLOID = "na_ledger_11x17in"
|
46
|
+
|
47
|
+
MEDIA_SOURCE = "media-source"
|
48
|
+
MEDIA_SOURCE_SUPPORTED = "media-source-supported"
|
49
|
+
|
50
|
+
MEDIA_SOURCE_AUTO = "auto"
|
51
|
+
MEDIA_SOURCE_MANUAL = "manual"
|
52
|
+
|
53
|
+
MEDIA_TYPE = "media-type"
|
54
|
+
MEDIA_TYPE_SUPPORTED = "media-type-supported"
|
55
|
+
|
56
|
+
MEDIA_TYPE_AUTO = "auto"
|
57
|
+
MEDIA_TYPE_ENVELOPE = "envelope"
|
58
|
+
MEDIA_TYPE_LABELS = "labels"
|
59
|
+
MEDIA_TYPE_LETTERHEAD = "stationery-letterhead"
|
60
|
+
MEDIA_TYPE_PHOTO = "photographic"
|
61
|
+
MEDIA_TYPE_PHOTO_GLOSSY = "photographic-glossy"
|
62
|
+
MEDIA_TYPE_PHOTO_MATTE = "photographic-matte"
|
63
|
+
MEDIA_TYPE_PLAIN = "stationery"
|
64
|
+
MEDIA_TYPE_TRANSPARENCY = "transparency"
|
65
|
+
|
66
|
+
NUMBER_UP = "number-up"
|
67
|
+
NUMBER_UP_SUPPORTED = "number-up-supported"
|
68
|
+
|
69
|
+
ORIENTATION = "orientation-requested"
|
70
|
+
ORIENTATION_SUPPORTED = "orientation-requested-supported"
|
71
|
+
|
72
|
+
ORIENTATION_PORTRAIT = "3"
|
73
|
+
ORIENTATION_LANDSCAPE = "4"
|
74
|
+
|
75
|
+
PRINT_COLOR_MODE = "print-color-mode"
|
76
|
+
PRINT_COLOR_MODE_SUPPORTED = "print-color-mode-supported"
|
77
|
+
|
78
|
+
PRINT_COLOR_MODE_AUTO = "auto"
|
79
|
+
PRINT_COLOR_MODE_MONOCHROME = "monochrome"
|
80
|
+
PRINT_COLOR_MODE_COLOR = "color"
|
81
|
+
|
82
|
+
PRINT_QUALITY = "print-quality"
|
83
|
+
PRINT_QUALITY_SUPPORTED = "print-quality-supported"
|
84
|
+
|
85
|
+
PRINT_QUALITY_DRAFT = "3"
|
86
|
+
PRINT_QUALITY_NORMAL = "4"
|
87
|
+
PRINT_QUALITY_HIGH = "5"
|
88
|
+
|
89
|
+
SIDES = "sides"
|
90
|
+
SIDES_SUPPORTED = "sides-supported"
|
91
|
+
|
92
|
+
SIDES_ONE_SIDED = "one-sided"
|
93
|
+
SIDES_TWO_SIDED_PORTRAIT = "two-sided-long-edge"
|
94
|
+
SIDES_TWO_SIDED_LANDSCAPE = "two-sided-short-edge"
|
95
95
|
end
|
data/lib/ffi-cups/ffi/array.rb
CHANGED
data/lib/ffi-cups/ffi/cups.rb
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
# {https://www.cups.org/doc/cupspm.html Programming Manual}
|
3
3
|
# {https://github.com/apple/cups/blob/master/cups/cups.h cups.h source}
|
4
4
|
|
5
|
-
module
|
5
|
+
module Cups
|
6
6
|
extend FFI::Library
|
7
|
-
|
8
|
-
ffi_lib('cups')
|
9
7
|
|
8
|
+
ffi_lib(Cups.libcups)
|
9
|
+
|
10
10
|
# Get the current encryption settings.
|
11
11
|
# @return [Integer] encryption settings
|
12
12
|
# {https://www.cups.org/doc/cupspm.html#cupsEncryption}
|
@@ -94,14 +94,17 @@ module FFI::Cups
|
|
94
94
|
# @overload cupsCancelJob(string, int)
|
95
95
|
# @param name [String] of the destination
|
96
96
|
# @param id [Ingeger] of the job
|
97
|
-
|
97
|
+
# @return [Integer] 1 if canceled, 0 otherwise
|
98
|
+
attach_function 'cupsCancelJob', [:string, :int], :int, blocking: true
|
98
99
|
|
99
100
|
# Cancel a job on a destination
|
100
101
|
# @overload cupsCancelJob2(pointer, string, int)
|
101
102
|
# @param pointer [Pointer] of the http connection
|
102
103
|
# @param name [String] of the destination
|
103
104
|
# @param id [Ingeger] of the job
|
104
|
-
|
105
|
+
# @param purge [Integer] 1 to purge, 0 to cancel
|
106
|
+
# @return [Enum] Cups::Enun::IPP::Status
|
107
|
+
attach_function 'cupsCancelJob2', [:pointer, :string, :int, :int], Cups::Enum::IPP::Status, blocking: true
|
105
108
|
|
106
109
|
# Get the jobs from a connection
|
107
110
|
# @overload cupsGetJobs2(pointer, pointer, string, int, int)
|
data/lib/ffi-cups/ffi/http.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
module
|
1
|
+
module Cups
|
2
2
|
module Http
|
3
3
|
extend FFI::Library
|
4
|
-
|
5
|
-
ffi_lib(
|
4
|
+
|
5
|
+
ffi_lib(Cups.libcups)
|
6
6
|
|
7
7
|
# @overload httpConnectEncrypt(string, int, int)
|
8
8
|
# @param hostname [String]
|
@@ -30,7 +30,7 @@ module FFI::Cups
|
|
30
30
|
# @param port [Integer]
|
31
31
|
# @param addrlist [Pointer] can be NULL
|
32
32
|
# @param family [Integer] (AF_UNSPEC=0)
|
33
|
-
# @param encryption_settings [Integer] from
|
33
|
+
# @param encryption_settings [Integer] from Cups.cupsEncryption()
|
34
34
|
# @param blocking [Integer]
|
35
35
|
# @param msec [Integer] use 5000 or less
|
36
36
|
# @param cancel[Pointer] integer pointer, can be NULL
|
data/lib/ffi-cups/job.rb
CHANGED
@@ -1,11 +1,89 @@
|
|
1
1
|
module Cups
|
2
2
|
class Job
|
3
|
-
|
4
|
-
|
3
|
+
attr_accessor :id, :title, :printer,
|
4
|
+
:format, :state, :size, :completed_time,
|
5
|
+
:creation_time, :processing_time
|
6
|
+
|
7
|
+
def initialize(id, title, printer)
|
5
8
|
@id = id
|
6
9
|
@title = title
|
7
10
|
@printer = printer
|
8
11
|
end
|
12
|
+
|
13
|
+
# get a updated job's state
|
14
|
+
# @param connection [Cups::Connection]
|
15
|
+
# @return [Symbol] job's state
|
16
|
+
def status(connection=nil)
|
17
|
+
job = self.class.get_job(@id, @printer, -1, connection)
|
18
|
+
self.state = job.state if job
|
19
|
+
end
|
20
|
+
|
21
|
+
# Cancel or purge a job
|
22
|
+
# @param connection [Cups::Connection]
|
23
|
+
def cancel(purge=0, connection=nil)
|
24
|
+
job = self.class.get_job(@id, @printer, -1, connection)
|
25
|
+
r = Cups.cupsCancelJob2(connection, @printer, @id, purge)
|
26
|
+
raise Cups.cupsLastErrorString() if r == 0
|
27
|
+
return r
|
28
|
+
end
|
29
|
+
|
30
|
+
# Get jobs by filter or destination name
|
31
|
+
# @param name [String]
|
32
|
+
# @param filter [Integer] see Constants
|
33
|
+
# @param connection [Cups::Connection]
|
34
|
+
# @return [Array] jobs
|
35
|
+
def self.get_jobs(name=nil, filter=-1, connection=nil)
|
36
|
+
p_jobs = FFI::MemoryPointer.new :pointer
|
37
|
+
cups_jobs = cupsGetJobs2(p_jobs, name, filter, connection)
|
38
|
+
jobs = []
|
39
|
+
cups_jobs.each do |j|
|
40
|
+
job = Cups::Job.new(j[:id].dup, j[:title].dup, j[:dest].dup)
|
41
|
+
job.format = j[:format]
|
42
|
+
job.state = j[:state]
|
43
|
+
job.size = j[:size]
|
44
|
+
job.completed_time = Time.at(j[:completed_time])
|
45
|
+
job.creation_time = Time.at(j[:creation_time])
|
46
|
+
job.processing_time = Time.at(j[:processing_time])
|
47
|
+
jobs.push(job)
|
48
|
+
end
|
49
|
+
return jobs
|
50
|
+
end
|
51
|
+
|
52
|
+
# Get job from id
|
53
|
+
# @param id [Integer]
|
54
|
+
# @param name [String]
|
55
|
+
# @param filter [Integer] see Constants
|
56
|
+
# @param connection [Cups::Connection]
|
57
|
+
# @return [Job] job object
|
58
|
+
def self.get_job(id, name=nil, filter=-1, connection=nil)
|
59
|
+
jobs = get_jobs(name, filter, connection)
|
60
|
+
jobs.each do |j|
|
61
|
+
return j if j.id == id
|
62
|
+
end
|
63
|
+
raise "Job with id: #{id} not found!"
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
# Wrapper {::Cups#cupsGetJobs2}
|
68
|
+
# @param pointer [Pointer] pointer to the jobs
|
69
|
+
# @param name [String] name of the destination or NULL
|
70
|
+
# @param filter [Integer] see Constants for more filters
|
71
|
+
# @param connection [Cups::Connection]
|
72
|
+
# @return [Array] array of job structs
|
73
|
+
def self.cupsGetJobs2(pointer, name=nil, filter=-1, connection=nil)
|
74
|
+
http = connection.nil? ? nil : connection.httpConnect2
|
75
|
+
num_jobs = Cups.cupsGetJobs2(http, pointer, name, 0, filter)
|
76
|
+
size = Cups::Struct::Job.size
|
77
|
+
jobs = []
|
78
|
+
|
79
|
+
num_jobs.times do |i|
|
80
|
+
job = Cups::Struct::Job.new(pointer.get_pointer(0) + (size * i))
|
81
|
+
jobs.push(job)
|
82
|
+
end
|
83
|
+
|
84
|
+
Cups::Connection.close(http) if http
|
85
|
+
return jobs
|
86
|
+
end
|
9
87
|
end
|
10
88
|
end
|
11
89
|
|
data/lib/ffi-cups/printer.rb
CHANGED
@@ -17,7 +17,7 @@ module Cups
|
|
17
17
|
when '3' then :idle
|
18
18
|
when '4' then :printing
|
19
19
|
when '5' then :stopped
|
20
|
-
else :
|
20
|
+
else :unknown
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -33,10 +33,10 @@ module Cups
|
|
33
33
|
http = @connection.nil? ? nil : @connection.httpConnect2
|
34
34
|
# Get all destinations with cupsGetDests2
|
35
35
|
dests = FFI::MemoryPointer.new :pointer
|
36
|
-
num_dests =
|
36
|
+
num_dests = Cups.cupsGetDests2(http, dests)
|
37
37
|
|
38
38
|
# Get the destination from name with cupsGetDest
|
39
|
-
p_dest =
|
39
|
+
p_dest = Cups.cupsGetDest(@name, nil, num_dests, dests.get_pointer(0))
|
40
40
|
dest = Cups::Struct::Destination.new(p_dest)
|
41
41
|
raise "Destination with name: #{@name} not found!" if dest.null?
|
42
42
|
|
@@ -48,19 +48,20 @@ module Cups
|
|
48
48
|
unless self.class.cupsCheckDestSupported(p_dest, k, v, http)
|
49
49
|
raise "Option:#{k} #{v if v} not supported for printer: #{@name}"
|
50
50
|
end
|
51
|
-
num_options =
|
51
|
+
num_options = Cups.cupsAddOption(k, v, num_options, p_options)
|
52
52
|
end
|
53
53
|
p_options = p_options.get_pointer(0)
|
54
54
|
end
|
55
55
|
|
56
|
-
job_id =
|
57
|
-
job = Cups::Job.new(job_id, title, self)
|
56
|
+
job_id = Cups.cupsPrintFile2(http, @name, filename, title, num_options, p_options)
|
58
57
|
|
59
58
|
if job_id.zero?
|
60
59
|
last_error = Cups.cupsLastErrorString()
|
61
60
|
self.class.cupsFreeOptions(num_options, p_options) unless options.empty?
|
62
61
|
raise last_error
|
63
62
|
end
|
63
|
+
#job = Cups::Job.new(job_id, title, @name)
|
64
|
+
job = Cups::Job.get_job(job_id, @name, 0, @connection)
|
64
65
|
|
65
66
|
self.class.cupsFreeOptions(num_options, p_options) unless options.empty?
|
66
67
|
self.class.cupsFreeDests(num_dests, dests)
|
@@ -90,10 +91,10 @@ module Cups
|
|
90
91
|
http = connection.nil? ? nil : connection.httpConnect2
|
91
92
|
# Get all destinations with cupsGetDests2
|
92
93
|
dests = FFI::MemoryPointer.new :pointer
|
93
|
-
num_dests =
|
94
|
+
num_dests = Cups.cupsGetDests2(http, dests)
|
94
95
|
|
95
96
|
# Get the destination from name with cupsGetDest
|
96
|
-
p_dest =
|
97
|
+
p_dest = Cups.cupsGetDest(name, nil, num_dests, dests.get_pointer(0))
|
97
98
|
dest = Cups::Struct::Destination.new(p_dest)
|
98
99
|
raise "Destination with name: #{name} not found!" if dest.null?
|
99
100
|
|
@@ -104,13 +105,13 @@ module Cups
|
|
104
105
|
end
|
105
106
|
|
106
107
|
private
|
107
|
-
# Wrapper around {::
|
108
|
+
# Wrapper around {::Cups#cupsGetDests2}
|
108
109
|
# @param connection [Pointer] http pointer from {Cups::Connection#httpConnect2}
|
109
110
|
# @param pointer [Pointer] pointer to the destinations
|
110
111
|
# @return [Hash] hashmap of destination structs
|
111
112
|
def self.cupsGetDests2(pointer, connection=nil)
|
112
113
|
http = connection.nil? ? nil : connection.httpConnect2
|
113
|
-
num_dests =
|
114
|
+
num_dests = Cups.cupsGetDests2(http, pointer)
|
114
115
|
size = Cups::Struct::Destination.size
|
115
116
|
destinations = []
|
116
117
|
num_dests.times do |i|
|
@@ -121,15 +122,15 @@ module Cups
|
|
121
122
|
return destinations
|
122
123
|
end
|
123
124
|
|
124
|
-
# Wrapper around {::
|
125
|
+
# Wrapper around {::Cups#cupsCheckDestSupported}
|
125
126
|
# @param dest [Pointer] pointer to the destination
|
126
127
|
# @param option [String]
|
127
128
|
# @param value [String]
|
128
129
|
# @param connection [Pointer] http pointer from {Cups::Connection#httpConnect2}
|
129
130
|
# @return [Boolean] true if supported, false otherwise
|
130
131
|
def self.cupsCheckDestSupported(dest, option, value, connection=nil)
|
131
|
-
info =
|
132
|
-
i =
|
132
|
+
info = Cups.cupsCopyDestInfo(connection, dest)
|
133
|
+
i = Cups.cupsCheckDestSupported(connection, dest, info, option, value)
|
133
134
|
return !i.zero?
|
134
135
|
end
|
135
136
|
|
@@ -159,18 +160,18 @@ module Cups
|
|
159
160
|
return options
|
160
161
|
end
|
161
162
|
|
162
|
-
# Wrapper around {::
|
163
|
+
# Wrapper around {::Cups#cupsFreeDests}
|
163
164
|
# @param num_dests [Integer]
|
164
165
|
# @param pointer [Pointer] pointer to the destinations
|
165
166
|
def self.cupsFreeDests(num_dests, pointer)
|
166
|
-
|
167
|
+
Cups.cupsFreeDests(num_dests, pointer.get_pointer(0))
|
167
168
|
end
|
168
169
|
|
169
|
-
# Wrapper around {::
|
170
|
+
# Wrapper around {::Cups#cupsFreeOptions}
|
170
171
|
# @param num_opts [Integer]
|
171
172
|
# @param pointer [Pointer] pointer to the options
|
172
173
|
def self.cupsFreeOptions(num_opts, pointer)
|
173
|
-
|
174
|
+
Cups.cupsFreeOptions(num_opts, pointer)
|
174
175
|
end
|
175
176
|
end
|
176
177
|
end
|
data/lib/ffi-cups/version.rb
CHANGED
data/lib/ffi-cups.rb
CHANGED
@@ -2,17 +2,16 @@ require 'ffi'
|
|
2
2
|
require 'byebug'
|
3
3
|
|
4
4
|
module Cups
|
5
|
-
extend FFI::Library
|
6
5
|
|
7
|
-
|
6
|
+
# Custom or default path for libcups.so
|
7
|
+
def self.libcups
|
8
8
|
if ENV['CUPS_LIB']
|
9
|
-
|
9
|
+
ENV['CUPS_LIB']
|
10
10
|
else
|
11
|
-
|
11
|
+
'cups'
|
12
12
|
end
|
13
|
-
rescue LoadError => e
|
14
|
-
raise LoadError, "Didn't find libcups on your system."
|
15
13
|
end
|
14
|
+
|
16
15
|
end
|
17
16
|
|
18
17
|
# Constants
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffi-cups
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hugo Marquez
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-07-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '0'
|
77
77
|
requirements: []
|
78
|
-
rubygems_version: 3.1.
|
78
|
+
rubygems_version: 3.1.6
|
79
79
|
signing_key:
|
80
80
|
specification_version: 4
|
81
81
|
summary: FFI wrapper around libcups
|