lib/ffi-cups/job.rb in ffi-cups-0.2.1 vs lib/ffi-cups/job.rb in ffi-cups-0.2.2
- old
+ new
@@ -8,10 +8,27 @@
@id = id
@title = title
@printer = printer
end
+ # get a updated job's state
+ # @param connection [Cups::Connection]
+ # @return [Symbol] job's state
+ def status(connection=nil)
+ job = self.class.get_job(@id, @printer, -1, connection)
+ self.state = job.state if job
+ end
+
+ # Cancel or purge a job
+ # @param connection [Cups::Connection]
+ def cancel(purge=0, connection=nil)
+ job = self.class.get_job(@id, @printer, -1, connection)
+ r = FFI::Cups.cupsCancelJob2(connection, @printer, @id, purge)
+ raise FFI::Cups.cupsLastErrorString() if r == 0
+ return r
+ end
+
# Get jobs by filter or destination name
# @param name [String]
# @param filter [Integer] see Constants
# @param connection [Cups::Connection]
# @return [Array] jobs
@@ -41,9 +58,10 @@
def self.get_job(id, name=nil, filter=-1, connection=nil)
jobs = get_jobs(name, filter, connection)
jobs.each do |j|
return j if j.id == id
end
+ raise "Job with id: #{id} not found!"
end
private
# Wrapper {::FFI::Cups#cupsGetJobs2}
# @param pointer [Pointer] pointer to the jobs