noggin 0.0.1 → 0.0.2
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
- data/Rakefile +2 -1
- data/ext/noggin/extconf.rb +46 -8
- data/ext/noggin/noggin.c +175 -29
- data/ext/noggin/noggin.cr +118 -32
- data/ext/noggin/noggin.rd +4 -0
- data/lib/noggin/version.rb +1 -1
- metadata +49 -57
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4f3c0bc5a5a640b5822bf85970579af604d006d3
|
4
|
+
data.tar.gz: d47a8a20702b937c304b1b7af1fc6aa32c89fbe3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c2474bab572fff36b7f0e7566d8dfad018df21ae0aec337fc02be0c742dda55eab029f80953c0e4ed739bfd0cd20305be3b17d3e8ea891ecad132bc6fd0d70d9
|
7
|
+
data.tar.gz: dac26f05f9844e3763d55b9d917a219c064e13495e0686db719c63ae530a1892084fecf826fb67df3cf973c1ceadc0533af1b76715a7256ad0e96bc6590e5549
|
data/Rakefile
CHANGED
@@ -27,7 +27,8 @@ spec = Gem::Specification.new do |s|
|
|
27
27
|
s.version = Noggin::VERSION
|
28
28
|
s.homepage = "http://github.com/geoffyoungs/noggin"
|
29
29
|
s.summary = "libcups bindings for ruby"
|
30
|
-
s.add_dependency("rubber-generate", ">= 0.0.
|
30
|
+
s.add_dependency("rubber-generate", ">= 0.0.21")
|
31
|
+
s.add_development_dependency("prawn", ">= 0.0.21")
|
31
32
|
s.platform = Gem::Platform::RUBY
|
32
33
|
s.license = 'MIT'
|
33
34
|
s.extensions = FileList["ext/*/extconf.rb"]
|
data/ext/noggin/extconf.rb
CHANGED
@@ -19,21 +19,59 @@ end
|
|
19
19
|
# Look for headers in {gem_root}/ext/{package}
|
20
20
|
if use_gems
|
21
21
|
%w[
|
22
|
-
gdk_pixbuf2 atk gtk2
|
23
|
-
|
24
|
-
|
22
|
+
gdk_pixbuf2 atk gtk2].each do |package|
|
23
|
+
require package
|
24
|
+
if Gem.loaded_specs[package]
|
25
|
+
$CFLAGS += " -I" + Gem.loaded_specs[package].full_gem_path + "/ext/" + package
|
26
|
+
else
|
27
|
+
if fn = $".find { |n| n.sub(/[.](so|rb)$/,'') == package }
|
28
|
+
dr = $:.find { |d| File.exist?(File.join(d, fn)) }
|
29
|
+
pt = File.join(dr,fn) if dr && fn
|
30
|
+
else
|
31
|
+
pt = "??"
|
32
|
+
end
|
33
|
+
STDERR.puts "require '" + package + "' loaded '"+pt+"' instead of the gem - trying to continue, but build may fail"
|
34
|
+
end
|
25
35
|
end
|
26
36
|
end
|
27
37
|
if RbConfig::CONFIG.has_key?('rubyhdrdir')
|
28
|
-
$CFLAGS += " -I" + RbConfig::CONFIG['rubyhdrdir']+'/ruby'
|
38
|
+
$CFLAGS += " -I" + RbConfig::CONFIG['rubyhdrdir']+'/ruby'
|
29
39
|
end
|
30
40
|
|
31
41
|
$CFLAGS += " -I."
|
32
42
|
have_func("rb_errinfo")
|
33
|
-
|
34
|
-
have_header("cups/
|
35
|
-
|
36
|
-
|
43
|
+
|
44
|
+
unless have_header("cups/cups.h")
|
45
|
+
paths = Gem.find_files("cups/cups.h")
|
46
|
+
paths.each do |path|
|
47
|
+
$CFLAGS += " '-I#{File.dirname(path)}'"
|
48
|
+
end
|
49
|
+
have_header("cups/cups.h") or exit -1
|
50
|
+
end
|
51
|
+
|
52
|
+
unless have_header("cups/ipp.h")
|
53
|
+
paths = Gem.find_files("cups/ipp.h")
|
54
|
+
paths.each do |path|
|
55
|
+
$CFLAGS += " '-I#{File.dirname(path)}'"
|
56
|
+
end
|
57
|
+
have_header("cups/ipp.h") or exit -1
|
58
|
+
end
|
59
|
+
|
60
|
+
unless have_header("ruby.h")
|
61
|
+
paths = Gem.find_files("ruby.h")
|
62
|
+
paths.each do |path|
|
63
|
+
$CFLAGS += " '-I#{File.dirname(path)}'"
|
64
|
+
end
|
65
|
+
have_header("ruby.h") or exit -1
|
66
|
+
end
|
67
|
+
|
68
|
+
unless have_header("st.h")
|
69
|
+
paths = Gem.find_files("st.h")
|
70
|
+
paths.each do |path|
|
71
|
+
$CFLAGS += " '-I#{File.dirname(path)}'"
|
72
|
+
end
|
73
|
+
have_header("st.h") or exit -1
|
74
|
+
end
|
37
75
|
have_library("cups") or exit(-1)
|
38
76
|
$LIBS += " -lcups"
|
39
77
|
|
data/ext/noggin/noggin.c
CHANGED
@@ -22,10 +22,18 @@ static VALUE
|
|
22
22
|
Noggin_CLASS_jobs(VALUE self, VALUE printer, VALUE __v_mine, VALUE __v_whichjobs);
|
23
23
|
static VALUE
|
24
24
|
Noggin_CLASS_ippRequest(VALUE self, VALUE __v_operation, VALUE request_attributes);
|
25
|
+
static VALUE
|
26
|
+
Noggin_CLASS_printFile(int __p_argc, VALUE *__p_argv, VALUE self);
|
25
27
|
static VALUE mJob;
|
26
28
|
static VALUE
|
27
29
|
Job_CLASS_cancel(VALUE self, VALUE __v_printer, VALUE __v_job_id);
|
28
30
|
static VALUE mIPP;
|
31
|
+
static VALUE cIppRequest;
|
32
|
+
static VALUE _gcpool_Keep = Qnil;
|
33
|
+
static void __gcpool_Keep_add(VALUE val);
|
34
|
+
static void __gcpool_Keep_del(VALUE val);
|
35
|
+
#define KEEP_ADD(val) __gcpool_Keep_add(val)
|
36
|
+
#define KEEP_DEL(val) __gcpool_Keep_del(val)
|
29
37
|
|
30
38
|
/* Inline C code */
|
31
39
|
|
@@ -34,23 +42,51 @@ VALUE inline as_string(const char *string) { return string ? rb_str_new2(string)
|
|
34
42
|
|
35
43
|
#define TO_STRING(v) ((v) ? rb_str_new2((v)) : Qnil)
|
36
44
|
|
45
|
+
static VALUE sym_aborted = Qnil;
|
46
|
+
static VALUE sym_cancelled = Qnil;
|
47
|
+
static VALUE sym_completed = Qnil;
|
48
|
+
static VALUE sym_held = Qnil;
|
49
|
+
static VALUE sym_pending = Qnil;
|
50
|
+
static VALUE sym_processing = Qnil;
|
51
|
+
static VALUE sym_stopped = Qnil;
|
52
|
+
|
53
|
+
#define STATIC_STR(name) static VALUE str_##name = Qnil;
|
54
|
+
#define STATIC_STR_INIT(name) KEEP_ADD(str_##name = rb_str_new2(#name)); rb_obj_freeze(str_##name);
|
55
|
+
STATIC_STR(completed_time);
|
56
|
+
STATIC_STR(creation_time);
|
57
|
+
STATIC_STR(dest);
|
58
|
+
STATIC_STR(format);
|
59
|
+
STATIC_STR(id);
|
60
|
+
STATIC_STR(priority);
|
61
|
+
STATIC_STR(processing_time);
|
62
|
+
STATIC_STR(size);
|
63
|
+
STATIC_STR(title);
|
64
|
+
STATIC_STR(user);
|
65
|
+
STATIC_STR(state);
|
66
|
+
|
67
|
+
STATIC_STR(name);
|
68
|
+
STATIC_STR(instance);
|
69
|
+
STATIC_STR(is_default);
|
70
|
+
STATIC_STR(options);
|
71
|
+
|
37
72
|
VALUE job_state(ipp_jstate_t state) {
|
38
73
|
switch(state) {
|
39
74
|
case IPP_JOB_ABORTED:
|
40
|
-
return
|
75
|
+
return sym_aborted;
|
41
76
|
case IPP_JOB_CANCELED:
|
42
|
-
return
|
77
|
+
return sym_cancelled;
|
43
78
|
case IPP_JOB_COMPLETED:
|
44
|
-
return
|
79
|
+
return sym_completed;
|
45
80
|
case IPP_JOB_HELD:
|
46
|
-
return
|
81
|
+
return sym_held;
|
47
82
|
case IPP_JOB_PENDING:
|
48
|
-
return
|
83
|
+
return sym_pending;
|
49
84
|
case IPP_JOB_PROCESSING:
|
50
|
-
return
|
85
|
+
return sym_processing;
|
51
86
|
case IPP_JOB_STOPPED:
|
52
|
-
return
|
87
|
+
return sym_stopped;
|
53
88
|
}
|
89
|
+
return INT2FIX(state);
|
54
90
|
}
|
55
91
|
|
56
92
|
VALUE rb_ipp_value(ipp_attribute_t* attr) {
|
@@ -62,13 +98,26 @@ VALUE rb_ipp_value(ipp_attribute_t* attr) {
|
|
62
98
|
case IPP_TAG_NAME:
|
63
99
|
case IPP_TAG_URI:
|
64
100
|
case IPP_TAG_URISCHEME:
|
65
|
-
return as_string(ippGetString(attr, 0, &lang));
|
101
|
+
return as_string(ippGetString(attr, 0, &lang));
|
66
102
|
case IPP_TAG_BOOLEAN:
|
67
103
|
return ippGetBoolean(attr, 0) ? Qtrue : Qfalse;
|
68
104
|
}
|
69
105
|
return Qnil;
|
70
106
|
|
71
107
|
}
|
108
|
+
|
109
|
+
struct svp_it {
|
110
|
+
int num_options;
|
111
|
+
cups_option_t *options;
|
112
|
+
};
|
113
|
+
|
114
|
+
int hash_to_cups_options_it(VALUE key, VALUE val, VALUE data) {
|
115
|
+
struct svp_it *svp = (struct svp_it *)data;
|
116
|
+
|
117
|
+
svp->num_options = cupsAddOption(StringValuePtr(key), StringValuePtr(val), svp->num_options, &(svp->options));
|
118
|
+
|
119
|
+
return ST_CONTINUE;
|
120
|
+
}
|
72
121
|
int add_to_request_iterator(VALUE key, VALUE val, VALUE data) {
|
73
122
|
ipp_t *request = (ipp_t*) data;
|
74
123
|
char *name = RSTRING_PTR(key);
|
@@ -80,7 +129,7 @@ int add_to_request_iterator(VALUE key, VALUE val, VALUE data) {
|
|
80
129
|
case T_STRING:
|
81
130
|
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, name, NULL, RSTRING_PTR(val));
|
82
131
|
break;
|
83
|
-
case T_TRUE:
|
132
|
+
case T_TRUE:
|
84
133
|
case T_FALSE:
|
85
134
|
ippAddBoolean(request, IPP_TAG_OPERATION, name, (val) ? 1 : 0);
|
86
135
|
break;
|
@@ -95,7 +144,7 @@ Noggin_CLASS_destinations(VALUE self)
|
|
95
144
|
{
|
96
145
|
VALUE __p_retval = Qnil;
|
97
146
|
|
98
|
-
#line
|
147
|
+
#line 161 "/home/geoff/Projects/noggin/ext/noggin/noggin.cr"
|
99
148
|
|
100
149
|
do {
|
101
150
|
VALUE list =
|
@@ -111,10 +160,10 @@ Noggin_CLASS_destinations(VALUE self)
|
|
111
160
|
i > 0;
|
112
161
|
i --, dest ++) { VALUE hash =
|
113
162
|
rb_hash_new(), options = rb_hash_new();
|
114
|
-
rb_hash_aset(hash,
|
115
|
-
rb_hash_aset(hash,
|
116
|
-
rb_hash_aset(hash,
|
117
|
-
rb_hash_aset(hash,
|
163
|
+
rb_hash_aset(hash, str_name, as_string(dest->name));
|
164
|
+
rb_hash_aset(hash, str_instance, as_string(dest->instance));
|
165
|
+
rb_hash_aset(hash, str_is_default, INT2NUM(dest->is_default));
|
166
|
+
rb_hash_aset(hash, str_options, options);
|
118
167
|
for (j = 0;
|
119
168
|
j < dest->num_options;
|
120
169
|
j++) { rb_hash_aset(options, as_string(dest->options[j].name), as_string(dest->options[j].value));
|
@@ -139,7 +188,7 @@ Noggin_CLASS_jobs(VALUE self, VALUE printer, VALUE __v_mine, VALUE __v_whichjobs
|
|
139
188
|
__orig_mine = mine = RTEST(__v_mine);
|
140
189
|
__orig_whichjobs = whichjobs = NUM2INT(__v_whichjobs);
|
141
190
|
|
142
|
-
#line
|
191
|
+
#line 192 "/home/geoff/Projects/noggin/ext/noggin/noggin.cr"
|
143
192
|
|
144
193
|
do {
|
145
194
|
VALUE list =
|
@@ -152,17 +201,17 @@ Noggin_CLASS_jobs(VALUE self, VALUE printer, VALUE __v_mine, VALUE __v_whichjobs
|
|
152
201
|
i > 0;
|
153
202
|
i --, job ++) { VALUE hash =
|
154
203
|
rb_hash_new();
|
155
|
-
rb_hash_aset(hash,
|
156
|
-
rb_hash_aset(hash,
|
157
|
-
rb_hash_aset(hash,
|
158
|
-
rb_hash_aset(hash,
|
159
|
-
rb_hash_aset(hash,
|
160
|
-
rb_hash_aset(hash,
|
161
|
-
rb_hash_aset(hash,
|
162
|
-
rb_hash_aset(hash,
|
163
|
-
rb_hash_aset(hash,
|
164
|
-
rb_hash_aset(hash,
|
165
|
-
rb_hash_aset(hash,
|
204
|
+
rb_hash_aset(hash, str_completed_time, rb_time_new(job->completed_time, 0));
|
205
|
+
rb_hash_aset(hash, str_creation_time, rb_time_new(job->creation_time, 0));
|
206
|
+
rb_hash_aset(hash, str_dest, as_string(job->dest));
|
207
|
+
rb_hash_aset(hash, str_format, as_string(job->format));
|
208
|
+
rb_hash_aset(hash, str_id, INT2NUM(job->id));
|
209
|
+
rb_hash_aset(hash, str_priority, INT2NUM(job->priority));
|
210
|
+
rb_hash_aset(hash, str_processing_time, rb_time_new(job->processing_time, 0));
|
211
|
+
rb_hash_aset(hash, str_size, INT2NUM(job->size));
|
212
|
+
rb_hash_aset(hash, str_title, as_string(job->title));
|
213
|
+
rb_hash_aset(hash, str_user, as_string(job->user));
|
214
|
+
rb_hash_aset(hash, str_state, job_state(job->state));
|
166
215
|
rb_ary_push(list, hash);
|
167
216
|
} cupsFreeJobs(num_jobs, jobs);
|
168
217
|
do { __p_retval = list; goto out; } while(0);
|
@@ -180,7 +229,7 @@ Noggin_CLASS_ippRequest(VALUE self, VALUE __v_operation, VALUE request_attribute
|
|
180
229
|
int operation; int __orig_operation;
|
181
230
|
__orig_operation = operation = NUM2INT(__v_operation);
|
182
231
|
|
183
|
-
#line
|
232
|
+
#line 227 "/home/geoff/Projects/noggin/ext/noggin/noggin.cr"
|
184
233
|
|
185
234
|
do {
|
186
235
|
VALUE resp =
|
@@ -204,6 +253,52 @@ out:
|
|
204
253
|
return __p_retval;
|
205
254
|
}
|
206
255
|
|
256
|
+
static VALUE
|
257
|
+
Noggin_CLASS_printFile(int __p_argc, VALUE *__p_argv, VALUE self)
|
258
|
+
{
|
259
|
+
VALUE __p_retval = Qnil;
|
260
|
+
VALUE __v_destinationName = Qnil;
|
261
|
+
char * destinationName; char * __orig_destinationName;
|
262
|
+
VALUE __v_fileName = Qnil;
|
263
|
+
char * fileName; char * __orig_fileName;
|
264
|
+
VALUE __v_title = Qnil;
|
265
|
+
char * title; char * __orig_title;
|
266
|
+
VALUE options = Qnil;
|
267
|
+
|
268
|
+
/* Scan arguments */
|
269
|
+
rb_scan_args(__p_argc, __p_argv, "31",&__v_destinationName, &__v_fileName, &__v_title, &options);
|
270
|
+
|
271
|
+
/* Set defaults */
|
272
|
+
__orig_destinationName = destinationName = ( NIL_P(__v_destinationName) ? NULL : StringValuePtr(__v_destinationName) );
|
273
|
+
|
274
|
+
__orig_fileName = fileName = ( NIL_P(__v_fileName) ? NULL : StringValuePtr(__v_fileName) );
|
275
|
+
|
276
|
+
__orig_title = title = ( NIL_P(__v_title) ? NULL : StringValuePtr(__v_title) );
|
277
|
+
|
278
|
+
if (__p_argc <= 3)
|
279
|
+
options = Qnil;
|
280
|
+
else
|
281
|
+
if (! ((TYPE(options) == T_HASH) || (TYPE(options) == T_NIL)) )
|
282
|
+
rb_raise(rb_eArgError, "options argument must be one of Hash, Nil");
|
283
|
+
|
284
|
+
|
285
|
+
#line 246 "/home/geoff/Projects/noggin/ext/noggin/noggin.cr"
|
286
|
+
|
287
|
+
do {
|
288
|
+
struct svp_it info =
|
289
|
+
{0, NULL};
|
290
|
+
int job_id = -1;
|
291
|
+
if (TYPE(options) == T_HASH) { rb_hash_foreach(options, hash_to_cups_options_it, (VALUE)&info);
|
292
|
+
} job_id = cupsPrintFile(destinationName, fileName, title, info.num_options, info.options);
|
293
|
+
if (info.options) { cupsFreeOptions(info.num_options, info.options);
|
294
|
+
} do { __p_retval = INT2NUM(job_id); goto out; } while(0);
|
295
|
+
|
296
|
+
} while(0);
|
297
|
+
|
298
|
+
out:
|
299
|
+
return __p_retval;
|
300
|
+
}
|
301
|
+
|
207
302
|
static VALUE
|
208
303
|
Job_CLASS_cancel(VALUE self, VALUE __v_printer, VALUE __v_job_id)
|
209
304
|
{
|
@@ -212,21 +307,46 @@ Job_CLASS_cancel(VALUE self, VALUE __v_printer, VALUE __v_job_id)
|
|
212
307
|
__orig_printer = printer = ( NIL_P(__v_printer) ? NULL : StringValuePtr(__v_printer) );
|
213
308
|
__orig_job_id = job_id = NUM2INT(__v_job_id);
|
214
309
|
|
215
|
-
#line
|
310
|
+
#line 152 "/home/geoff/Projects/noggin/ext/noggin/noggin.cr"
|
216
311
|
if (cupsCancelJob(printer, job_id) == 0) { rb_raise(rb_eRuntimeError, "CUPS Error: %d - %s", cupsLastError(), cupsLastErrorString());
|
217
312
|
}
|
218
313
|
return Qnil;
|
219
314
|
}
|
220
315
|
|
316
|
+
static void __gcpool_Keep_add(VALUE val)
|
317
|
+
{
|
318
|
+
if (_gcpool_Keep == Qnil)
|
319
|
+
{
|
320
|
+
_gcpool_Keep = rb_ary_new3(1, val);
|
321
|
+
}
|
322
|
+
else
|
323
|
+
{
|
324
|
+
rb_ary_push(_gcpool_Keep, val);
|
325
|
+
}
|
326
|
+
}
|
327
|
+
|
328
|
+
static void __gcpool_Keep_del(VALUE val)
|
329
|
+
{
|
330
|
+
if (_gcpool_Keep == Qnil)
|
331
|
+
{
|
332
|
+
rb_warn("Trying to remove object from empty GC queue Keep");
|
333
|
+
return;
|
334
|
+
}
|
335
|
+
rb_ary_delete(_gcpool_Keep, val);
|
336
|
+
// If nothing is referenced, don't keep an empty array in the pool...
|
337
|
+
if (RARRAY_LEN(_gcpool_Keep) == 0)
|
338
|
+
_gcpool_Keep = Qnil;
|
339
|
+
}
|
340
|
+
|
221
341
|
/* Init */
|
222
342
|
void
|
223
343
|
Init_noggin(void)
|
224
344
|
{
|
225
|
-
|
226
345
|
mNoggin = rb_define_module("Noggin");
|
227
346
|
rb_define_singleton_method(mNoggin, "destinations", Noggin_CLASS_destinations, 0);
|
228
347
|
rb_define_singleton_method(mNoggin, "jobs", Noggin_CLASS_jobs, 3);
|
229
348
|
rb_define_singleton_method(mNoggin, "ippRequest", Noggin_CLASS_ippRequest, 2);
|
349
|
+
rb_define_singleton_method(mNoggin, "printFile", Noggin_CLASS_printFile, -1);
|
230
350
|
rb_define_const(mNoggin, "WHICHJOBS_ALL", INT2NUM(CUPS_WHICHJOBS_ALL));
|
231
351
|
rb_define_const(mNoggin, "WHICHJOBS_ACTIVE", INT2NUM(CUPS_WHICHJOBS_ACTIVE));
|
232
352
|
rb_define_const(mNoggin, "WHICHJOBS_COMPLETED", INT2NUM(CUPS_WHICHJOBS_COMPLETED));
|
@@ -236,4 +356,30 @@ Init_noggin(void)
|
|
236
356
|
rb_define_const(mJob, "ALL", INT2NUM(CUPS_JOBID_ALL));
|
237
357
|
mIPP = rb_define_module_under(mNoggin, "IPP");
|
238
358
|
rb_define_const(mIPP, "GET_JOBS", INT2NUM(IPP_GET_JOBS));
|
359
|
+
cIppRequest = rb_define_class_under(mNoggin, "IppRequest", rb_cObject);
|
360
|
+
rb_gc_register_address(&_gcpool_Keep);
|
361
|
+
|
362
|
+
KEEP_ADD(sym_cancelled = ID2SYM(rb_intern("cancelled")));
|
363
|
+
KEEP_ADD(sym_completed = ID2SYM(rb_intern("completed")));
|
364
|
+
KEEP_ADD(sym_held = ID2SYM(rb_intern("held")));
|
365
|
+
KEEP_ADD(sym_pending = ID2SYM(rb_intern("pending")));
|
366
|
+
KEEP_ADD(sym_processing = ID2SYM(rb_intern("processing")));
|
367
|
+
KEEP_ADD(sym_stopped = ID2SYM(rb_intern("stopped")));
|
368
|
+
|
369
|
+
STATIC_STR_INIT(completed_time);
|
370
|
+
STATIC_STR_INIT(creation_time);
|
371
|
+
STATIC_STR_INIT(dest);
|
372
|
+
STATIC_STR_INIT(format);
|
373
|
+
STATIC_STR_INIT(id);
|
374
|
+
STATIC_STR_INIT(priority);
|
375
|
+
STATIC_STR_INIT(processing_time);
|
376
|
+
STATIC_STR_INIT(size);
|
377
|
+
STATIC_STR_INIT(title);
|
378
|
+
STATIC_STR_INIT(user);
|
379
|
+
STATIC_STR_INIT(state);
|
380
|
+
|
381
|
+
STATIC_STR_INIT(name);
|
382
|
+
STATIC_STR_INIT(instance);
|
383
|
+
STATIC_STR_INIT(is_default);
|
384
|
+
STATIC_STR_INIT(options);
|
239
385
|
}
|
data/ext/noggin/noggin.cr
CHANGED
@@ -12,23 +12,51 @@ VALUE inline as_string(const char *string) { return string ? rb_str_new2(string)
|
|
12
12
|
|
13
13
|
#define TO_STRING(v) ((v) ? rb_str_new2((v)) : Qnil)
|
14
14
|
|
15
|
+
static VALUE sym_aborted = Qnil;
|
16
|
+
static VALUE sym_cancelled = Qnil;
|
17
|
+
static VALUE sym_completed = Qnil;
|
18
|
+
static VALUE sym_held = Qnil;
|
19
|
+
static VALUE sym_pending = Qnil;
|
20
|
+
static VALUE sym_processing = Qnil;
|
21
|
+
static VALUE sym_stopped = Qnil;
|
22
|
+
|
23
|
+
#define STATIC_STR(name) static VALUE str_##name = Qnil;
|
24
|
+
#define STATIC_STR_INIT(name) KEEP_ADD(str_##name = rb_str_new2(#name)); rb_obj_freeze(str_##name);
|
25
|
+
STATIC_STR(completed_time);
|
26
|
+
STATIC_STR(creation_time);
|
27
|
+
STATIC_STR(dest);
|
28
|
+
STATIC_STR(format);
|
29
|
+
STATIC_STR(id);
|
30
|
+
STATIC_STR(priority);
|
31
|
+
STATIC_STR(processing_time);
|
32
|
+
STATIC_STR(size);
|
33
|
+
STATIC_STR(title);
|
34
|
+
STATIC_STR(user);
|
35
|
+
STATIC_STR(state);
|
36
|
+
|
37
|
+
STATIC_STR(name);
|
38
|
+
STATIC_STR(instance);
|
39
|
+
STATIC_STR(is_default);
|
40
|
+
STATIC_STR(options);
|
41
|
+
|
15
42
|
VALUE job_state(ipp_jstate_t state) {
|
16
43
|
switch(state) {
|
17
44
|
case IPP_JOB_ABORTED:
|
18
|
-
return
|
45
|
+
return sym_aborted;
|
19
46
|
case IPP_JOB_CANCELED:
|
20
|
-
return
|
47
|
+
return sym_cancelled;
|
21
48
|
case IPP_JOB_COMPLETED:
|
22
|
-
return
|
49
|
+
return sym_completed;
|
23
50
|
case IPP_JOB_HELD:
|
24
|
-
return
|
51
|
+
return sym_held;
|
25
52
|
case IPP_JOB_PENDING:
|
26
|
-
return
|
53
|
+
return sym_pending;
|
27
54
|
case IPP_JOB_PROCESSING:
|
28
|
-
return
|
55
|
+
return sym_processing;
|
29
56
|
case IPP_JOB_STOPPED:
|
30
|
-
return
|
57
|
+
return sym_stopped;
|
31
58
|
}
|
59
|
+
return INT2FIX(state);
|
32
60
|
}
|
33
61
|
|
34
62
|
VALUE rb_ipp_value(ipp_attribute_t* attr) {
|
@@ -40,13 +68,26 @@ VALUE rb_ipp_value(ipp_attribute_t* attr) {
|
|
40
68
|
case IPP_TAG_NAME:
|
41
69
|
case IPP_TAG_URI:
|
42
70
|
case IPP_TAG_URISCHEME:
|
43
|
-
return as_string(ippGetString(attr, 0, &lang));
|
71
|
+
return as_string(ippGetString(attr, 0, &lang));
|
44
72
|
case IPP_TAG_BOOLEAN:
|
45
73
|
return ippGetBoolean(attr, 0) ? Qtrue : Qfalse;
|
46
74
|
}
|
47
75
|
return Qnil;
|
48
76
|
|
49
77
|
}
|
78
|
+
|
79
|
+
struct svp_it {
|
80
|
+
int num_options;
|
81
|
+
cups_option_t *options;
|
82
|
+
};
|
83
|
+
|
84
|
+
int hash_to_cups_options_it(VALUE key, VALUE val, VALUE data) {
|
85
|
+
struct svp_it *svp = (struct svp_it *)data;
|
86
|
+
|
87
|
+
svp->num_options = cupsAddOption(StringValuePtr(key), StringValuePtr(val), svp->num_options, &(svp->options));
|
88
|
+
|
89
|
+
return ST_CONTINUE;
|
90
|
+
}
|
50
91
|
int add_to_request_iterator(VALUE key, VALUE val, VALUE data) {
|
51
92
|
ipp_t *request = (ipp_t*) data;
|
52
93
|
char *name = RSTRING_PTR(key);
|
@@ -58,7 +99,7 @@ int add_to_request_iterator(VALUE key, VALUE val, VALUE data) {
|
|
58
99
|
case T_STRING:
|
59
100
|
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, name, NULL, RSTRING_PTR(val));
|
60
101
|
break;
|
61
|
-
case T_TRUE:
|
102
|
+
case T_TRUE:
|
62
103
|
case T_FALSE:
|
63
104
|
ippAddBoolean(request, IPP_TAG_OPERATION, name, (val) ? 1 : 0);
|
64
105
|
break;
|
@@ -68,7 +109,30 @@ int add_to_request_iterator(VALUE key, VALUE val, VALUE data) {
|
|
68
109
|
|
69
110
|
%}
|
70
111
|
|
71
|
-
%
|
112
|
+
%post_init{
|
113
|
+
KEEP_ADD(sym_cancelled = ID2SYM(rb_intern("cancelled")));
|
114
|
+
KEEP_ADD(sym_completed = ID2SYM(rb_intern("completed")));
|
115
|
+
KEEP_ADD(sym_held = ID2SYM(rb_intern("held")));
|
116
|
+
KEEP_ADD(sym_pending = ID2SYM(rb_intern("pending")));
|
117
|
+
KEEP_ADD(sym_processing = ID2SYM(rb_intern("processing")));
|
118
|
+
KEEP_ADD(sym_stopped = ID2SYM(rb_intern("stopped")));
|
119
|
+
|
120
|
+
STATIC_STR_INIT(completed_time);
|
121
|
+
STATIC_STR_INIT(creation_time);
|
122
|
+
STATIC_STR_INIT(dest);
|
123
|
+
STATIC_STR_INIT(format);
|
124
|
+
STATIC_STR_INIT(id);
|
125
|
+
STATIC_STR_INIT(priority);
|
126
|
+
STATIC_STR_INIT(processing_time);
|
127
|
+
STATIC_STR_INIT(size);
|
128
|
+
STATIC_STR_INIT(title);
|
129
|
+
STATIC_STR_INIT(user);
|
130
|
+
STATIC_STR_INIT(state);
|
131
|
+
|
132
|
+
STATIC_STR_INIT(name);
|
133
|
+
STATIC_STR_INIT(instance);
|
134
|
+
STATIC_STR_INIT(is_default);
|
135
|
+
STATIC_STR_INIT(options);
|
72
136
|
%}
|
73
137
|
|
74
138
|
%map ruby - (char *) => (VALUE): rb_str_new2(#0)
|
@@ -81,10 +145,11 @@ module Noggin
|
|
81
145
|
int WHICHJOBS_ACTIVE = CUPS_WHICHJOBS_ACTIVE
|
82
146
|
int WHICHJOBS_COMPLETED = CUPS_WHICHJOBS_COMPLETED
|
83
147
|
|
148
|
+
gcpool Keep
|
84
149
|
module Job
|
85
150
|
int CURRENT = CUPS_JOBID_CURRENT
|
86
151
|
int ALL = CUPS_JOBID_ALL
|
87
|
-
def
|
152
|
+
def self.cancel(char * printer, int job_id)
|
88
153
|
if (cupsCancelJob(printer, job_id) == 0) {
|
89
154
|
rb_raise(rb_eRuntimeError, "CUPS Error: %d - %s", cupsLastError(), cupsLastErrorString());
|
90
155
|
}
|
@@ -103,18 +168,18 @@ module Noggin
|
|
103
168
|
int j;
|
104
169
|
|
105
170
|
list = rb_ary_new2(num_dests);
|
106
|
-
for (i = num_dests, dest = dests; i > 0; i --, dest ++)
|
171
|
+
for (i = num_dests, dest = dests; i > 0; i --, dest ++)
|
107
172
|
{
|
108
173
|
VALUE hash = rb_hash_new(), options = rb_hash_new();
|
109
|
-
rb_hash_aset(hash,
|
110
|
-
rb_hash_aset(hash,
|
111
|
-
rb_hash_aset(hash,
|
112
|
-
rb_hash_aset(hash,
|
174
|
+
rb_hash_aset(hash, str_name, as_string(dest->name));
|
175
|
+
rb_hash_aset(hash, str_instance, as_string(dest->instance));
|
176
|
+
rb_hash_aset(hash, str_is_default, INT2NUM(dest->is_default));
|
177
|
+
rb_hash_aset(hash, str_options, options);
|
113
178
|
|
114
179
|
for (j = 0; j < dest->num_options; j++) {
|
115
180
|
rb_hash_aset(options, as_string(dest->options[j].name), as_string(dest->options[j].value));
|
116
181
|
}
|
117
|
-
|
182
|
+
|
118
183
|
|
119
184
|
rb_ary_push(list, hash);
|
120
185
|
}
|
@@ -124,28 +189,28 @@ module Noggin
|
|
124
189
|
return list;
|
125
190
|
end
|
126
191
|
|
127
|
-
def self.jobs(T_NIL|T_STRING printer, bool mine, int whichjobs)
|
192
|
+
def self.jobs(T_NIL|T_STRING printer, bool mine, int whichjobs)
|
128
193
|
VALUE list = Qnil;
|
129
194
|
cups_job_t *jobs, *job;
|
130
195
|
int num_jobs, i;
|
131
|
-
|
196
|
+
|
132
197
|
num_jobs = cupsGetJobs(&jobs, (NIL_P(printer) ? (char*)0 : RSTRING_PTR(printer)), (mine ? 1 : 0), whichjobs);
|
133
198
|
|
134
199
|
list = rb_ary_new2(num_jobs);
|
135
|
-
for (i = num_jobs, job = jobs; i > 0; i --, job ++)
|
200
|
+
for (i = num_jobs, job = jobs; i > 0; i --, job ++)
|
136
201
|
{
|
137
202
|
VALUE hash = rb_hash_new();
|
138
|
-
rb_hash_aset(hash,
|
139
|
-
rb_hash_aset(hash,
|
140
|
-
rb_hash_aset(hash,
|
141
|
-
rb_hash_aset(hash,
|
142
|
-
rb_hash_aset(hash,
|
143
|
-
rb_hash_aset(hash,
|
144
|
-
rb_hash_aset(hash,
|
145
|
-
rb_hash_aset(hash,
|
146
|
-
rb_hash_aset(hash,
|
147
|
-
rb_hash_aset(hash,
|
148
|
-
rb_hash_aset(hash,
|
203
|
+
rb_hash_aset(hash, str_completed_time, rb_time_new(job->completed_time, 0));
|
204
|
+
rb_hash_aset(hash, str_creation_time, rb_time_new(job->creation_time, 0));
|
205
|
+
rb_hash_aset(hash, str_dest, as_string(job->dest));
|
206
|
+
rb_hash_aset(hash, str_format, as_string(job->format));
|
207
|
+
rb_hash_aset(hash, str_id, INT2NUM(job->id));
|
208
|
+
rb_hash_aset(hash, str_priority, INT2NUM(job->priority));
|
209
|
+
rb_hash_aset(hash, str_processing_time, rb_time_new(job->processing_time, 0));
|
210
|
+
rb_hash_aset(hash, str_size, INT2NUM(job->size));
|
211
|
+
rb_hash_aset(hash, str_title, as_string(job->title));
|
212
|
+
rb_hash_aset(hash, str_user, as_string(job->user));
|
213
|
+
rb_hash_aset(hash, str_state, job_state(job->state));
|
149
214
|
|
150
215
|
rb_ary_push(list, hash);
|
151
216
|
}
|
@@ -155,6 +220,10 @@ module Noggin
|
|
155
220
|
return list;
|
156
221
|
end
|
157
222
|
|
223
|
+
class IppRequest
|
224
|
+
|
225
|
+
end
|
226
|
+
|
158
227
|
def self.ippRequest(int operation, VALUE request_attributes)
|
159
228
|
VALUE resp = Qnil;
|
160
229
|
ipp_t *request = NULL , *response = NULL;
|
@@ -164,7 +233,7 @@ module Noggin
|
|
164
233
|
rb_hash_foreach(request_attributes, add_to_request_iterator, (VALUE)request);
|
165
234
|
|
166
235
|
response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/");
|
167
|
-
|
236
|
+
|
168
237
|
resp = rb_hash_new();
|
169
238
|
|
170
239
|
for (attr = ippFirstAttribute(response); attr != NULL; attr = ippNextAttribute(response)) {
|
@@ -173,4 +242,21 @@ module Noggin
|
|
173
242
|
|
174
243
|
return resp;
|
175
244
|
end
|
245
|
+
|
246
|
+
def int:self.printFile(char *destinationName, char *fileName, char *title, T_HASH|T_NIL options = Qnil)
|
247
|
+
struct svp_it info = {0, NULL};
|
248
|
+
int job_id = -1;
|
249
|
+
|
250
|
+
if (TYPE(options) == T_HASH) {
|
251
|
+
rb_hash_foreach(options, hash_to_cups_options_it, (VALUE)&info);
|
252
|
+
}
|
253
|
+
|
254
|
+
job_id = cupsPrintFile(destinationName, fileName, title, info.num_options, info.options);
|
255
|
+
|
256
|
+
if (info.options) {
|
257
|
+
cupsFreeOptions(info.num_options, info.options);
|
258
|
+
}
|
259
|
+
|
260
|
+
return job_id;
|
261
|
+
end
|
176
262
|
end
|
data/ext/noggin/noggin.rd
CHANGED
@@ -8,6 +8,9 @@
|
|
8
8
|
--- Noggin.ippRequest(Integer operation, request_attributes)
|
9
9
|
|
10
10
|
|
11
|
+
--- Noggin.printFile(String destinationName, String fileName, String title, Hash options)
|
12
|
+
|
13
|
+
|
11
14
|
== Noggin::WHICHJOBS_ALL
|
12
15
|
== Noggin::WHICHJOBS_ACTIVE
|
13
16
|
== Noggin::WHICHJOBS_COMPLETED
|
@@ -19,3 +22,4 @@
|
|
19
22
|
=== Noggin::Job::ALL
|
20
23
|
== module Noggin::IPP
|
21
24
|
=== Noggin::IPP::GET_JOBS
|
25
|
+
== class Noggin::IppRequest
|
data/lib/noggin/version.rb
CHANGED
metadata
CHANGED
@@ -1,49 +1,51 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: noggin
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 1
|
10
|
-
version: 0.0.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Geoff Youngs
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2013-09-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
21
14
|
name: rubber-generate
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
hash: 61
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
- 0
|
32
|
-
- 17
|
33
|
-
version: 0.0.17
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.21
|
34
20
|
type: :runtime
|
35
|
-
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.21
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: prawn
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.21
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.0.21
|
36
41
|
description: |
|
37
42
|
smb
|
38
|
-
|
39
43
|
email: git@intersect-uk.co.uk
|
40
44
|
executables: []
|
41
|
-
|
42
|
-
extensions:
|
45
|
+
extensions:
|
43
46
|
- ext/noggin/extconf.rb
|
44
47
|
extra_rdoc_files: []
|
45
|
-
|
46
|
-
files:
|
48
|
+
files:
|
47
49
|
- ext/noggin/noggin.c
|
48
50
|
- ext/noggin/noggin.cr
|
49
51
|
- ext/noggin/noggin.rd
|
@@ -53,37 +55,27 @@ files:
|
|
53
55
|
- lib/noggin/version.rb
|
54
56
|
- ext/noggin/extconf.rb
|
55
57
|
homepage: http://github.com/geoffyoungs/noggin
|
56
|
-
licenses:
|
58
|
+
licenses:
|
57
59
|
- MIT
|
60
|
+
metadata: {}
|
58
61
|
post_install_message:
|
59
62
|
rdoc_options: []
|
60
|
-
|
61
|
-
require_paths:
|
63
|
+
require_paths:
|
62
64
|
- lib
|
63
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ">="
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
hash: 3
|
78
|
-
segments:
|
79
|
-
- 0
|
80
|
-
version: "0"
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
81
75
|
requirements: []
|
82
|
-
|
83
76
|
rubyforge_project:
|
84
|
-
rubygems_version:
|
77
|
+
rubygems_version: 2.0.3
|
85
78
|
signing_key:
|
86
|
-
specification_version:
|
79
|
+
specification_version: 4
|
87
80
|
summary: libcups bindings for ruby
|
88
81
|
test_files: []
|
89
|
-
|