ffi-cups 0.1.9 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +27 -19
- data/lib/ffi-cups/connection.rb +1 -19
- data/lib/ffi-cups/job.rb +62 -2
- data/lib/ffi-cups/printer.rb +2 -1
- data/lib/ffi-cups/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63c1079a34a2ba53dd1ba0a0be14738700cfc17540ebfffd517674bfe67c9525
|
4
|
+
data.tar.gz: c6bd62d2efc4bce337b774becb392012c899cc345ed7df8fb34b4548d3f53c85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23e2d001e8eb819b52940584b984bedd4f380ff5d41b0fcff97abd36168ffe561dc611ce8e3d1f21ccb70f47c00ef05e381f001493a8dca159ce43f3d55723ea
|
7
|
+
data.tar.gz: e31273be32df34f501b27542b894c7bd73b34cbd18a93af65466a27d3184a0c96e76d10b598f3737215e1634c38eca32c68c762224cc41ead11c317056a547fb
|
data/README.md
CHANGED
@@ -1,31 +1,18 @@
|
|
1
|
-
#
|
1
|
+
# FFI-Cups
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/ffi-cups.svg)](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
|
+
This gem 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'
|
@@ -53,7 +40,18 @@ options = {
|
|
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::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,13 +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.1.9)
|
70
|
+
|
71
|
+
## TODO
|
72
|
+
- Connection to not be a singleton class
|
73
|
+
- Cancel jobs function
|
74
|
+
|
75
|
+
## Authors
|
76
|
+
- Hugo Marquez @ www.hugomarquez.mx
|
77
|
+
- Contributors @ https://github.com/hugomarquez/ffi-cups/graphs/contributors
|
78
|
+
|
71
79
|
## License
|
72
80
|
The MIT License
|
73
81
|
|
data/lib/ffi-cups/connection.rb
CHANGED
@@ -3,30 +3,12 @@ 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
|
-
# Returns or creates a singleton instance
|
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
|
-
|
11
|
+
|
30
12
|
# Wrapper around {::FFI::Cups::Http#httpConnectEncrypt}
|
31
13
|
# @deprecated Use {#httpConnect2} instead
|
32
14
|
# @return [Pointer] a http pointer
|
data/lib/ffi-cups/job.rb
CHANGED
@@ -1,11 +1,71 @@
|
|
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 jobs by filter or destination name
|
14
|
+
# @param name [String]
|
15
|
+
# @param filter [Integer] see Constants
|
16
|
+
# @param connection [Cups::Connection]
|
17
|
+
# @return [Array] jobs
|
18
|
+
def self.get_jobs(name=nil, filter=-1, connection=nil)
|
19
|
+
p_jobs = FFI::MemoryPointer.new :pointer
|
20
|
+
cups_jobs = cupsGetJobs2(p_jobs, name, filter, connection)
|
21
|
+
jobs = []
|
22
|
+
cups_jobs.each do |j|
|
23
|
+
job = Cups::Job.new(j[:id].dup, j[:title].dup, j[:dest].dup)
|
24
|
+
job.format = j[:format]
|
25
|
+
job.state = j[:state]
|
26
|
+
job.size = j[:size]
|
27
|
+
job.completed_time = Time.at(j[:completed_time])
|
28
|
+
job.creation_time = Time.at(j[:creation_time])
|
29
|
+
job.processing_time = Time.at(j[:processing_time])
|
30
|
+
jobs.push(job)
|
31
|
+
end
|
32
|
+
return jobs
|
33
|
+
end
|
34
|
+
|
35
|
+
# Get job from id
|
36
|
+
# @param id [Integer]
|
37
|
+
# @param name [String]
|
38
|
+
# @param filter [Integer] see Constants
|
39
|
+
# @param connection [Cups::Connection]
|
40
|
+
# @return [Job] job object
|
41
|
+
def self.get_job(id, name=nil, filter=-1, connection=nil)
|
42
|
+
jobs = get_jobs(name, filter, connection)
|
43
|
+
jobs.each do |j|
|
44
|
+
return j if j.id == id
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
# Wrapper {::FFI::Cups#cupsGetJobs2}
|
50
|
+
# @param pointer [Pointer] pointer to the jobs
|
51
|
+
# @param name [String] name of the destination or NULL
|
52
|
+
# @param filter [Integer] see Constants for more filters
|
53
|
+
# @param connection [Cups::Connection]
|
54
|
+
# @return [Array] array of job structs
|
55
|
+
def self.cupsGetJobs2(pointer, name=nil, filter=-1, connection=nil)
|
56
|
+
http = connection.nil? ? nil : connection.httpConnect2
|
57
|
+
num_jobs = FFI::Cups.cupsGetJobs2(http, pointer, name, 0, filter)
|
58
|
+
size = Cups::Struct::Job.size
|
59
|
+
jobs = []
|
60
|
+
|
61
|
+
num_jobs.times do |i|
|
62
|
+
job = Cups::Struct::Job.new(pointer.get_pointer(0) + (size * i))
|
63
|
+
jobs.push(job)
|
64
|
+
end
|
65
|
+
|
66
|
+
Cups::Connection.close(http) if http
|
67
|
+
return jobs
|
68
|
+
end
|
9
69
|
end
|
10
70
|
end
|
11
71
|
|
data/lib/ffi-cups/printer.rb
CHANGED
@@ -54,13 +54,14 @@ module Cups
|
|
54
54
|
end
|
55
55
|
|
56
56
|
job_id = FFI::Cups.cupsPrintFile2(http, @name, filename, title, num_options, p_options)
|
57
|
-
job = Cups::Job.new(job_id, title, self)
|
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)
|
data/lib/ffi-cups/version.rb
CHANGED
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.1
|
4
|
+
version: 0.2.1
|
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: 2021-04-
|
12
|
+
date: 2021-04-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|