ffi-cups2 0.4.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 +7 -0
- checksums.yaml.gz.sig +0 -0
- data/.gitignore +14 -0
- data/Gemfile +7 -0
- data/LICENSE +21 -0
- data/README.md +110 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ffi-cups.gemspec +26 -0
- data/lib/ffi-cups/connection.rb +39 -0
- data/lib/ffi-cups/constants.rb +98 -0
- data/lib/ffi-cups/enum/http/ppd.rb +22 -0
- data/lib/ffi-cups/enum/http/status.rb +50 -0
- data/lib/ffi-cups/enum/ipp/job_state.rb +15 -0
- data/lib/ffi-cups/enum/ipp/res.rb +10 -0
- data/lib/ffi-cups/enum/ipp/status.rb +53 -0
- data/lib/ffi-cups/enum/ipp/tag.rb +51 -0
- data/lib/ffi-cups/ffi/array.rb +17 -0
- data/lib/ffi-cups/ffi/cups.rb +216 -0
- data/lib/ffi-cups/ffi/http.rb +40 -0
- data/lib/ffi-cups/ffi/ipp_attribute.rb +74 -0
- data/lib/ffi-cups/ffi/ppd.rb +65 -0
- data/lib/ffi-cups/job.rb +89 -0
- data/lib/ffi-cups/printer.rb +342 -0
- data/lib/ffi-cups/struct/destination.rb +9 -0
- data/lib/ffi-cups/struct/ipp_attribute.rb +6 -0
- data/lib/ffi-cups/struct/job.rb +15 -0
- data/lib/ffi-cups/struct/option.rb +5 -0
- data/lib/ffi-cups/struct/ppd_choice.rb +9 -0
- data/lib/ffi-cups/struct/ppd_file.rb +6 -0
- data/lib/ffi-cups/struct/ppd_option.rb +14 -0
- data/lib/ffi-cups/version.rb +3 -0
- data/lib/ffi-cups.rb +48 -0
- data/lib/ffi-cups2.rb +1 -0
- data.tar.gz.sig +4 -0
- metadata +117 -0
- metadata.gz.sig +0 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# cups.h
|
|
2
|
+
# {https://www.cups.org/doc/cupspm.html Programming Manual}
|
|
3
|
+
# {https://github.com/apple/cups/blob/master/cups/cups.h cups.h source}
|
|
4
|
+
|
|
5
|
+
module Cups
|
|
6
|
+
extend FFI::Library
|
|
7
|
+
|
|
8
|
+
ffi_lib(Cups.libcups)
|
|
9
|
+
|
|
10
|
+
# Get the current encryption settings.
|
|
11
|
+
# @return [Integer] encryption settings
|
|
12
|
+
# {https://www.cups.org/doc/cupspm.html#cupsEncryption}
|
|
13
|
+
attach_function 'cupsEncryption', [], :int, blocking: true
|
|
14
|
+
|
|
15
|
+
# Check that the option and value are supported by the destination.
|
|
16
|
+
# @overload cupsCheckDestSupported(pointer, pointer, pointer, string, string)
|
|
17
|
+
# @param http [Pointer]
|
|
18
|
+
# @param destination [Pointer]
|
|
19
|
+
# @param dinfo [Pointer]
|
|
20
|
+
# @param option [String]
|
|
21
|
+
# @param value [String]
|
|
22
|
+
# @return [Integer] 1 if supported, 0 otherwise
|
|
23
|
+
# {https://www.cups.org/doc/cupspm.html#cupsCheckDestSupported}
|
|
24
|
+
attach_function 'cupsCheckDestSupported', [:pointer, :pointer, :pointer, :string, :string], :int, blocking: true
|
|
25
|
+
|
|
26
|
+
# Check that the option and value are supported by the destination.
|
|
27
|
+
# @overload cupsFindDestSupported(pointer, pointer, pointer, string)
|
|
28
|
+
# @param http [Pointer]
|
|
29
|
+
# @param destination [Pointer]
|
|
30
|
+
# @param dinfo [Pointer]
|
|
31
|
+
# @param option [String]
|
|
32
|
+
# @return [p_ipp_attribute_t] opaque pointer to an IPP attribute
|
|
33
|
+
# {https://www.cups.org/doc/cupspm.html#cupsFindDestSupported}
|
|
34
|
+
attach_function 'cupsFindDestSupported', [:pointer, :pointer, :pointer, :string], Struct::IppAttribute.by_ref, blocking: true
|
|
35
|
+
|
|
36
|
+
# Check that the option and value are supported by the destination.
|
|
37
|
+
# @overload cupsFindDestReady(pointer, pointer, pointer, string)
|
|
38
|
+
# @param http [Pointer]
|
|
39
|
+
# @param destination [Pointer]
|
|
40
|
+
# @param dinfo [Pointer]
|
|
41
|
+
# @param option [String]
|
|
42
|
+
# @return [p_ipp_attribute_t] opaque pointer to an IPP attribute
|
|
43
|
+
# {https://www.cups.org/doc/cupspm.html#cupsFindDestReady}
|
|
44
|
+
attach_function 'cupsFindDestReady', [:pointer, :pointer, :pointer, :string], Struct::IppAttribute.by_ref, blocking: true
|
|
45
|
+
|
|
46
|
+
# Get the supported values/capabilities for the destination.
|
|
47
|
+
# @overload cupsCopyDestInfo(pointer, pointer)
|
|
48
|
+
# @param http [Pointer]
|
|
49
|
+
# @param dest [Pointer]
|
|
50
|
+
# @return [Pointer] Destination information
|
|
51
|
+
# {https://www.cups.org/doc/cupspm.html#cupsCopyDestInfo}
|
|
52
|
+
attach_function 'cupsCopyDestInfo', [:pointer, :pointer], :pointer, blocking: true
|
|
53
|
+
|
|
54
|
+
# Get the named destination from the list.
|
|
55
|
+
# @overload cupsGetDest(string, string, int, pointer)
|
|
56
|
+
# @param name [String]
|
|
57
|
+
# @param instance [String] instance name or NULL
|
|
58
|
+
# @param num_dests [Integer] number of destinations
|
|
59
|
+
# @param destinations [Pointer]
|
|
60
|
+
# @return [Pointer, NULL] destination or NULL
|
|
61
|
+
# {https://www.cups.org/doc/cupspm.html#cupsGetDest}
|
|
62
|
+
attach_function 'cupsGetDest', [:string, :string, :int, :pointer], :pointer, blocking: true
|
|
63
|
+
|
|
64
|
+
# Get the list of destinations from the specified server.
|
|
65
|
+
# @overload cupsGetDests2(pointer, pointer)
|
|
66
|
+
# @param pointer [Pointer] to http connection for server or CUPS_HTTP_DEFAULT
|
|
67
|
+
# @param pointer [Pointer] to destinations
|
|
68
|
+
# @return [Integer] number of destinations
|
|
69
|
+
# {https://www.cups.org/doc/cupspm.html#cupsGetDests2}
|
|
70
|
+
attach_function 'cupsGetDests2', [:pointer, :pointer], :int, blocking: true
|
|
71
|
+
|
|
72
|
+
# Free the memory used by the list of destinations.
|
|
73
|
+
# @overload cupsFreeDests(int, pointer)
|
|
74
|
+
# @param number [Integer] of destinations
|
|
75
|
+
# @param pointer [Pointer] to destinations
|
|
76
|
+
# {https://www.cups.org/doc/cupspm.html#cupsFreeDests}
|
|
77
|
+
attach_function 'cupsFreeDests', [:int, :pointer], :void, blocking: true
|
|
78
|
+
|
|
79
|
+
# Prints a File
|
|
80
|
+
# @overload cupsPrintFile(string, string, string, int, pointer)
|
|
81
|
+
# @param name [String] of the printer
|
|
82
|
+
# @param name [String] of the file
|
|
83
|
+
# @param title [String] of the job
|
|
84
|
+
# @param number [Integer] of options
|
|
85
|
+
# @param pointer [Pointer] to a CupsOptionS struct
|
|
86
|
+
# @return [Integer] job number or 0 on error
|
|
87
|
+
attach_function 'cupsPrintFile', [ :string, :string, :string, :int, :pointer ], :int, blocking: true
|
|
88
|
+
|
|
89
|
+
# Prints a file from a specific connection
|
|
90
|
+
# @overload cupsPrintFile2(pointer, string, string, string, int, pointer)
|
|
91
|
+
# @param pointer [Pointer] to an http connection
|
|
92
|
+
# @param name [String] of the printer
|
|
93
|
+
# @param name [String] of the file
|
|
94
|
+
# @param title [String] of the title
|
|
95
|
+
# @param number [Integer] of options
|
|
96
|
+
# @param pointer [Pointer] to a CupsOptionS struct
|
|
97
|
+
# @return [Integer] number of the job or 0 on error
|
|
98
|
+
attach_function 'cupsPrintFile2', [ :pointer, :string, :string, :string, :int, :pointer ], :int, blocking: true
|
|
99
|
+
|
|
100
|
+
# Returns the last error in string format
|
|
101
|
+
# @return [String] error
|
|
102
|
+
attach_function 'cupsLastErrorString', [], :string, blocking: true
|
|
103
|
+
|
|
104
|
+
# Cancel a job on a destination.
|
|
105
|
+
# @overload cupsCancelDestJob(string, int)
|
|
106
|
+
# @param connection [Pointer] to a http server
|
|
107
|
+
# @param pointer [Pointer] to a destination
|
|
108
|
+
# @param id [Integer] of the job
|
|
109
|
+
# @return [Integer] IPP status
|
|
110
|
+
# {https://www.cups.org/doc/cupspm.html#cupsCancelDestJob}
|
|
111
|
+
attach_function 'cupsCancelDestJob', [:string, :int], :void, blocking: true
|
|
112
|
+
|
|
113
|
+
# Cancel a job on a destination name
|
|
114
|
+
# @overload cupsCancelJob(string, int)
|
|
115
|
+
# @param name [String] of the destination
|
|
116
|
+
# @param id [Ingeger] of the job
|
|
117
|
+
# @return [Integer] 1 if canceled, 0 otherwise
|
|
118
|
+
attach_function 'cupsCancelJob', [:string, :int], :int, blocking: true
|
|
119
|
+
|
|
120
|
+
# Cancel a job on a destination
|
|
121
|
+
# @overload cupsCancelJob2(pointer, string, int)
|
|
122
|
+
# @param pointer [Pointer] of the http connection
|
|
123
|
+
# @param name [String] of the destination
|
|
124
|
+
# @param id [Ingeger] of the job
|
|
125
|
+
# @param purge [Integer] 1 to purge, 0 to cancel
|
|
126
|
+
# @return [Enum] Cups::Enun::IPP::Status
|
|
127
|
+
attach_function 'cupsCancelJob2', [:pointer, :string, :int, :int], Cups::Enum::IPP::Status, blocking: true
|
|
128
|
+
|
|
129
|
+
# Get the jobs from a connection
|
|
130
|
+
# @overload cupsGetJobs2(pointer, pointer, string, int, int)
|
|
131
|
+
# @param pointer [Pointer] to a http connection object
|
|
132
|
+
# @param pointer [Pointer] to Cups::Struct::Job
|
|
133
|
+
# @param name [String] of the printer
|
|
134
|
+
# @param number [Integer] of type of job (0 == all users, 1 == mine)
|
|
135
|
+
# @param which [Integer] jobs (CUPS_WHICHJOBS_ALL, CUPS_WHICHJOBS_ACTIVE, or CUPS_WHICHJOBS_COMPLETED)
|
|
136
|
+
# @return [Integer] number of jobs
|
|
137
|
+
# {https://www.cups.org/doc/cupspm.html#cupsGetJobs2}
|
|
138
|
+
attach_function 'cupsGetJobs2', [:pointer, :pointer, :string, :int, :int], :int, blocking: true
|
|
139
|
+
|
|
140
|
+
# Get the jobs
|
|
141
|
+
# @overload cupsGetJobs(pointer, string, int, int)
|
|
142
|
+
# @param pointer [Pointer] to Cups::Struct::Job to populate
|
|
143
|
+
# @param name [String] of the printer
|
|
144
|
+
# @param number [Integer] of type of job (0 == all users, 1 == mine)
|
|
145
|
+
# @param which [Integer] jobs (CUPS_WHICHJOBS_ALL, CUPS_WHICHJOBS_ACTIVE, or CUPS_WHICHJOBS_COMPLETED)
|
|
146
|
+
# @return [Integer] number of jobs
|
|
147
|
+
attach_function 'cupsGetJobs', [:pointer, :string, :int, :int], :int, blocking: true
|
|
148
|
+
|
|
149
|
+
# Free memory used by job data.
|
|
150
|
+
# @overload cupsFreeJobs(int, pointer)
|
|
151
|
+
# @param number [Integer] of jobs
|
|
152
|
+
# @param pointer [Pointer] to the first Cups::Struct::Job to free
|
|
153
|
+
# {https://www.cups.org/doc/cupspm.html#cupsFreeJobs}
|
|
154
|
+
attach_function 'cupsFreeJobs', [:int, :pointer ], :void, blocking: true
|
|
155
|
+
|
|
156
|
+
# Create a job on a destination.
|
|
157
|
+
# @overload cupsCreateJob(pointer, string, string, int, pointer)
|
|
158
|
+
# @param pointer [Pointer] to http connection to server or CUPS_HTTP_DEFAULT
|
|
159
|
+
# @param name [String] of the printer
|
|
160
|
+
# @param title [String] of the job
|
|
161
|
+
# @param number [Integer] of options
|
|
162
|
+
# @param pointer [Pointer] to a Cups::Struct::Option object
|
|
163
|
+
# @return [Integer] job number or 0 on error
|
|
164
|
+
attach_function 'cupsCreateJob', [:pointer, :string, :string, :int, :pointer], :int, blocking: true
|
|
165
|
+
|
|
166
|
+
# Start a document
|
|
167
|
+
# @overload cupsStartDocument(pointer, string, int, string, string, int)
|
|
168
|
+
# @param pointer [Pointer] to http connection to server or CUPS_HTTP_DEFAULT
|
|
169
|
+
# @param name [String] of the printer
|
|
170
|
+
# @param id [Integer] of the job
|
|
171
|
+
# @param name [String] of the document
|
|
172
|
+
# @param mime_type [String] format of the document
|
|
173
|
+
# @param number [Integer] of the last document (1 for last document in job, 0 otherwise)
|
|
174
|
+
# @return [Cups::Enum::HTTP::Status] HttpStatus
|
|
175
|
+
# {https://www.cups.org/doc/cupspm.html#submitting-a-print-job}
|
|
176
|
+
attach_function 'cupsStartDocument', [:pointer, :string, :int, :string, :string, :int], Cups::Enum::HTTP::Status, blocking: true
|
|
177
|
+
|
|
178
|
+
# @overload cupsWriteRequestData(pointer, pointer, bytesize)
|
|
179
|
+
# @param pointer [Pointer] to http connection to server or CUPS_HTTP_DEFAULT
|
|
180
|
+
# @param data [Pointer] in a character string pointer
|
|
181
|
+
# @param length [Byte] of data
|
|
182
|
+
# @return [Cups::Enum::HTTP::Status] HttpStatus
|
|
183
|
+
attach_function 'cupsWriteRequestData', [:pointer, :pointer, :size_t], Cups::Enum::HTTP::Status, blocking: true
|
|
184
|
+
|
|
185
|
+
# @overload cupsFinishDocument(pointer, string)
|
|
186
|
+
# @param pointer [Pointer] to http connection to server or CUPS_HTTP_DEFAULT
|
|
187
|
+
# @param name [String] of the printer
|
|
188
|
+
# @return [Cups::Enum::IPP::Status] IppStatus
|
|
189
|
+
attach_function 'cupsFinishDocument', [:pointer, :string], Cups::Enum::IPP::Status, blocking: true
|
|
190
|
+
|
|
191
|
+
# Add an option to an option array.
|
|
192
|
+
# @overload cupsAddOption(string, string, int, pointer)
|
|
193
|
+
# @param name [String] of option
|
|
194
|
+
# @param value [String] of option
|
|
195
|
+
# @param number [Integer] of options
|
|
196
|
+
# @param pointer [Pointer] to options
|
|
197
|
+
# @return [Integer] number of options
|
|
198
|
+
# {https://www.cups.org/doc/cupspm.html#cupsAddOption}
|
|
199
|
+
attach_function 'cupsAddOption', [:string, :string, :int, :pointer], :int, blocking: true
|
|
200
|
+
|
|
201
|
+
# Free all memory used by options.
|
|
202
|
+
# @overload cupsFreeOptions(int, pointer)
|
|
203
|
+
# @param number [Integer] of options
|
|
204
|
+
# @param pointer [Pointer] to options
|
|
205
|
+
# {https://www.cups.org/doc/cupspm.html#cupsFreeOptions}
|
|
206
|
+
attach_function 'cupsFreeOptions', [:int, :pointer], :void, blocking: true
|
|
207
|
+
|
|
208
|
+
# Get the destination profile matching the given printer name string.
|
|
209
|
+
#
|
|
210
|
+
# @param http [FFI::Pointer] Connection token handle, or NULL to utilize default standard behaviors.
|
|
211
|
+
# @param name [String] The explicit destination name string targeting verification.
|
|
212
|
+
# @param instance [String, nil] The specific profile instance context name, or nil for standard configurations.
|
|
213
|
+
# @return [FFI::Pointer] Explicit pointer targeting a filled out `cups_dest_t` entry structure block, or NULL.
|
|
214
|
+
attach_function :cupsGetNamedDest, [:pointer, :string, :string], :pointer
|
|
215
|
+
|
|
216
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
module Cups
|
|
2
|
+
module Http
|
|
3
|
+
extend FFI::Library
|
|
4
|
+
|
|
5
|
+
ffi_lib(Cups.libcups)
|
|
6
|
+
|
|
7
|
+
# @overload httpConnectEncrypt(string, int, int)
|
|
8
|
+
# @param hostname [String]
|
|
9
|
+
# @param port [int]
|
|
10
|
+
# @param encryption_settings [int]
|
|
11
|
+
# @return [Pointer] pointer to a http_t object
|
|
12
|
+
# @deprecated Please use httpConnect2 instead
|
|
13
|
+
attach_function 'httpConnectEncrypt', [ :string, :int, :int], :pointer, blocking: true
|
|
14
|
+
|
|
15
|
+
# @overload httpClose(pointer)
|
|
16
|
+
# @param pointer [Pointer] to a http_t object
|
|
17
|
+
attach_function 'httpClose', [ :pointer ], :void, blocking: true
|
|
18
|
+
|
|
19
|
+
# Get a list of addresses for a hostname.
|
|
20
|
+
# @overload httpAddrGetList(string, int, string)
|
|
21
|
+
# @param hostname [String]
|
|
22
|
+
# @param family [Integer]
|
|
23
|
+
# @param port [String]
|
|
24
|
+
# @return [Pointer] List of addresses or NULL
|
|
25
|
+
attach_function 'httpAddrGetList', [:string, :int, :string], :pointer, blocking: true
|
|
26
|
+
|
|
27
|
+
# Connect to a HTTP server.
|
|
28
|
+
# @overload httpConnect2(string, int, pointer, int, int, int, int, pointer)
|
|
29
|
+
# @param hostname [String]
|
|
30
|
+
# @param port [Integer]
|
|
31
|
+
# @param addrlist [Pointer] can be NULL
|
|
32
|
+
# @param family [Integer] (AF_UNSPEC=0)
|
|
33
|
+
# @param encryption_settings [Integer] from Cups.cupsEncryption()
|
|
34
|
+
# @param blocking [Integer]
|
|
35
|
+
# @param msec [Integer] use 5000 or less
|
|
36
|
+
# @param cancel[Pointer] integer pointer, can be NULL
|
|
37
|
+
# @return [Pointer] http_t object
|
|
38
|
+
attach_function 'httpConnect2', [:string, :int, :pointer, :int, :int, :int, :int, :pointer], :pointer, blocking: true
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
module Cups
|
|
2
|
+
module IppAttibute
|
|
3
|
+
extend FFI::Library
|
|
4
|
+
|
|
5
|
+
ffi_lib(Cups.libcups)
|
|
6
|
+
|
|
7
|
+
typedef Enum::IPP::Tag, :ipp_tag_t
|
|
8
|
+
typedef Enum::IPP::Res, :ipp_res_t
|
|
9
|
+
|
|
10
|
+
# Get the number of values in an attribute.
|
|
11
|
+
#
|
|
12
|
+
# @overload ippGetCount(pointer)
|
|
13
|
+
# @param pointer [Struct::IppAttibute] to ipp_attribute_t struct
|
|
14
|
+
# @return [Integer]
|
|
15
|
+
attach_function 'ippGetCount', [Struct::IppAttribute.by_ref], :int, blocking: true
|
|
16
|
+
attach_function 'ippGetGroupTag', [Struct::IppAttribute.by_ref], :ipp_tag_t, blocking: true
|
|
17
|
+
attach_function 'ippGetValueTag', [Struct::IppAttribute.by_ref], :ipp_tag_t, blocking: true
|
|
18
|
+
attach_function 'ippGetString', [Struct::IppAttribute.by_ref, :int, :pointer], :string, blocking: true
|
|
19
|
+
attach_function 'ippGetInteger', [Struct::IppAttribute.by_ref, :int], :int, blocking: true
|
|
20
|
+
|
|
21
|
+
# Get the attribute name.
|
|
22
|
+
#
|
|
23
|
+
# const char *ippGetName(ipp_attribute_t *attr);
|
|
24
|
+
# Parameters:
|
|
25
|
+
# attr IPP attribute
|
|
26
|
+
# Return Value: Attribute name or NULL for separators
|
|
27
|
+
attach_function 'ippGetName', [Struct::IppAttribute.by_ref], :string, blocking: true
|
|
28
|
+
|
|
29
|
+
# Get a resolution value for an attribute.
|
|
30
|
+
#
|
|
31
|
+
# int ippGetResolution(ipp_attribute_t *attr, int element, int *yres, ipp_res_t *units);
|
|
32
|
+
# Parameters:
|
|
33
|
+
# attr IPP attribute
|
|
34
|
+
# element Value number (0-based)
|
|
35
|
+
# yres Vertical/feed resolution
|
|
36
|
+
# units Units for resolution
|
|
37
|
+
#
|
|
38
|
+
# Return Value: Horizontal/cross feed resolution or 0
|
|
39
|
+
#
|
|
40
|
+
# The element parameter specifies which value to get from 0 to ippGetCount(attr) - 1.
|
|
41
|
+
attach_function 'ippGetResolution', [Struct::IppAttribute.by_ref, :int, :pointer, :pointer], :int, blocking: true
|
|
42
|
+
|
|
43
|
+
# Get a rangeOfInteger value from an attribute.
|
|
44
|
+
#
|
|
45
|
+
# int ippGetRange(ipp_attribute_t *attr, int element, int *uppervalue);
|
|
46
|
+
# Parameters:
|
|
47
|
+
# attr IPP attribute
|
|
48
|
+
# element Value number (0-based)
|
|
49
|
+
# uppervalue Upper value of range
|
|
50
|
+
# Return Value:
|
|
51
|
+
# Lower value of range or 0
|
|
52
|
+
#
|
|
53
|
+
# The element parameter specifies which value to get from 0 to ippGetCount(attr) - 1.
|
|
54
|
+
attach_function 'ippGetRange', [Struct::IppAttribute.by_ref, :int, :pointer], :int, blocking: true
|
|
55
|
+
|
|
56
|
+
# Return a string corresponding to the enum value.
|
|
57
|
+
#
|
|
58
|
+
# const char *ippEnumString(const char *attrname, int enumvalue);
|
|
59
|
+
# Parameters:
|
|
60
|
+
# attrname Attribute name
|
|
61
|
+
# enumvalue Enum value
|
|
62
|
+
# Return Value: Enum string
|
|
63
|
+
attach_function 'ippEnumString', [:string, :int], :string, blocking: true
|
|
64
|
+
|
|
65
|
+
# Return the value associated with a given enum string.
|
|
66
|
+
#
|
|
67
|
+
# int ippEnumValue(const char *attrname, const char *enumstring);
|
|
68
|
+
# Parameters:
|
|
69
|
+
# attrname Attribute name
|
|
70
|
+
# enumstring Enum string
|
|
71
|
+
# Return Value: Enum value or -1 if unknown
|
|
72
|
+
attach_function 'ippEnumValue', [:string, :string], :int, blocking: true
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
module Cups
|
|
2
|
+
module Ppd
|
|
3
|
+
extend FFI::Library
|
|
4
|
+
|
|
5
|
+
ffi_lib(Cups.libcups)
|
|
6
|
+
typedef Struct::PpdFile.by_ref, :ppd_file_t
|
|
7
|
+
|
|
8
|
+
# @note This function is deprecated and will be removed in a future release of CUPS.
|
|
9
|
+
# Get the PPD file for a printer from the default server.
|
|
10
|
+
# The returned filename is stored in a static buffer and is overwritten with subsequent calls.
|
|
11
|
+
# The caller "owns" the file that is created and must unlink (delete) the returned filename.
|
|
12
|
+
#
|
|
13
|
+
# @param printer [String] The name of the printer destination.
|
|
14
|
+
# @return [String, nil] A local path string pointing to a temporary file containing the PPD data, or nil on failure.
|
|
15
|
+
# @see https://www.cups.org/doc/api-ppd.html CUPS PPD API Reference
|
|
16
|
+
attach_function :cupsGetPPD, [:string], :string
|
|
17
|
+
|
|
18
|
+
# @note This function is deprecated and will be removed in a future release of CUPS.
|
|
19
|
+
# Read a PPD file into a parsed structure memory block.
|
|
20
|
+
# Opens the specified local filename context and safely allocates a matching internal configuration handle.
|
|
21
|
+
#
|
|
22
|
+
# @param filename [String] Local filesystem path layout matching target file boundaries.
|
|
23
|
+
# @return [FFI::Pointer] Opaque pointer handle to a newly allocated `ppd_file_t` structure, or NULL if it fails.
|
|
24
|
+
# @see https://www.cups.org/doc/api-ppd.html CUPS PPD API Reference
|
|
25
|
+
attach_function :ppdOpenFile, [:string], :ppd_file_t
|
|
26
|
+
|
|
27
|
+
# @note This function is deprecated and will be removed in a future release of CUPS.
|
|
28
|
+
# Mark command-line options in a PPD file structure context.
|
|
29
|
+
# Maps IPP attributes like "media", "sides", or "print-quality" directly onto underlying physical PPD options.
|
|
30
|
+
#
|
|
31
|
+
# @param ppd [FFI::Pointer] The parsed `ppd_file_t` structural memory context handler.
|
|
32
|
+
# @param num_options [Integer] Count of command-line items mapped within option pointers array block.
|
|
33
|
+
# @param options [FFI::Pointer] Underlying pointer referencing a flat array of `cups_option_t` values.
|
|
34
|
+
# @return [Integer] Returns 1 if conflicting printer options are uncovered, 0 if mapping succeeds completely.
|
|
35
|
+
# @see https://refspecs.linuxfoundation.org/LSB_3.2.0/LSB-Printing/LSB-Printing/libcups.cupsmarkoptions.1.html Linux API Reference
|
|
36
|
+
attach_function :cupsMarkOptions, [:ppd_file_t, :int, :pointer], :int
|
|
37
|
+
|
|
38
|
+
# @note This function is deprecated and will be removed in a future release of CUPS.
|
|
39
|
+
# Free all memory space allocations consumed by a loaded PPD file descriptor layout.
|
|
40
|
+
# Once closed, pointers referencing any elements inside this memory context are invalidated.
|
|
41
|
+
#
|
|
42
|
+
# @param ppd [FFI::Pointer] The parsed `ppd_file_t` structure reference pointer returned via `ppdOpenFile`.
|
|
43
|
+
# @return [void]
|
|
44
|
+
# @see https://www.cups.org/doc/api-ppd.html CUPS PPD API Reference
|
|
45
|
+
attach_function :ppdClose, [:ppd_file_t], :void
|
|
46
|
+
|
|
47
|
+
# @note This function is deprecated and will be removed in a future release of CUPS.
|
|
48
|
+
# Return the very first structured option tracking entry recorded inside the loaded PPD file.
|
|
49
|
+
# Iterates down through the nested array layout of groups into a linear traversal abstraction loop.
|
|
50
|
+
#
|
|
51
|
+
# @param ppd [FFI::Pointer] The parsed `ppd_file_t` structure memory context.
|
|
52
|
+
# @return [FFI::Pointer] A structural pointer highlighting the first `ppd_option_t` allocation, or NULL if empty.
|
|
53
|
+
# @see https://www.cups.org/doc/api-ppd.html CUPS PPD API Reference
|
|
54
|
+
attach_function :ppdFirstOption, [:ppd_file_t], :pointer
|
|
55
|
+
|
|
56
|
+
# @note This function is deprecated and will be removed in a future release of CUPS.
|
|
57
|
+
# Return the next recorded option tracking layout context inside the active linear traversal loop.
|
|
58
|
+
# Automatically steps into adjacent options or groups tracking across structural array lines.
|
|
59
|
+
#
|
|
60
|
+
# @param ppd [FFI::Pointer] The parsed `ppd_file_t` structure memory context.
|
|
61
|
+
# @return [FFI::Pointer] A structural pointer highlighting the next concurrent `ppd_option_t`, or NULL when finalized.
|
|
62
|
+
# @see https://www.cups.org/doc/api-ppd.html CUPS PPD API Reference
|
|
63
|
+
attach_function :ppdNextOption, [:ppd_file_t], :pointer
|
|
64
|
+
end
|
|
65
|
+
end
|
data/lib/ffi-cups/job.rb
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
module Cups
|
|
2
|
+
class Job
|
|
3
|
+
attr_accessor :id, :title, :printer,
|
|
4
|
+
:format, :state, :size, :completed_time,
|
|
5
|
+
:creation_time, :processing_time
|
|
6
|
+
|
|
7
|
+
def initialize(id, title, printer)
|
|
8
|
+
@id = id
|
|
9
|
+
@title = title
|
|
10
|
+
@printer = printer
|
|
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
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|