Module: Noggin

Defined in:
lib/noggin/version.rb,
ext/noggin/noggin.c

Defined Under Namespace

Modules: IPP, Job, Subscription

Constant Summary collapse

VERSION =
"0.0.4"
WHICHJOBS_ALL =
INT2NUM(CUPS_WHICHJOBS_ALL)
WHICHJOBS_ACTIVE =
INT2NUM(CUPS_WHICHJOBS_ACTIVE)
WHICHJOBS_COMPLETED =
INT2NUM(CUPS_WHICHJOBS_COMPLETED)

Class Method Summary collapse

Class Method Details

.destinationsObject

Code



399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
# File 'ext/noggin/noggin.c', line 399

static VALUE
Noggin_CLASS_destinations(VALUE self OPTIONAL_ATTR )
{
  VALUE __p_retval OPTIONAL_ATTR = Qnil;

#line 408 "/home/geoff/Projects/noggin/ext/noggin/noggin.cr"

  do {
  VALUE  list  =
 Qnil;
  cups_dest_t * dests  ;
 int num_dests = cupsGetDests(&dests);
  cups_dest_t * dest  ;
 int  i  ;
 int  j  ;
 list = rb_ary_new2(num_dests);
  for (i = num_dests, dest = dests;
  i > 0;
  i --, dest ++) { VALUE  hash  =
 rb_hash_new(), options = rb_hash_new();
  rb_hash_aset(hash, str_name, as_string(dest->name));
  rb_hash_aset(hash, str_instance, as_string(dest->instance));
  rb_hash_aset(hash, str_is_default, INT2NUM(dest->is_default));
  rb_hash_aset(hash, str_options, options);
  for (j = 0;
  j < dest->num_options;
  j++) { rb_hash_aset(options, as_string((dest->options[j].name)), as_string((dest->options[j].value)));
  } rb_ary_push(list, hash);
  } cupsFreeDests(num_dests, dests);
  do { __p_retval = list; goto out; } while(0);

  } while(0);

out:
  return __p_retval;
}

.jobs(printer, __v_mine, __v_whichjobs) ⇒ Object



436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
# File 'ext/noggin/noggin.c', line 436

static VALUE
Noggin_CLASS_jobs(VALUE self OPTIONAL_ATTR , VALUE printer OPTIONAL_ATTR, VALUE __v_mine OPTIONAL_ATTR, VALUE __v_whichjobs OPTIONAL_ATTR)
{
  VALUE __p_retval OPTIONAL_ATTR = Qnil;
  bool mine; bool __orig_mine;
  int whichjobs; int __orig_whichjobs;
  if (! ((TYPE(printer) == T_NIL) || (TYPE(printer) == T_STRING)) )
    rb_raise(rb_eArgError, "printer argument must be one of Nil, String");
  __orig_mine = mine = RTEST(__v_mine);
  __orig_whichjobs = whichjobs = NUM2INT(__v_whichjobs);

#line 437 "/home/geoff/Projects/noggin/ext/noggin/noggin.cr"

  do {
  VALUE  list  =
 Qnil;
  cups_job_t *jobs, *job;
  int num_jobs, i;
  num_jobs = cupsGetJobs(&jobs, (NIL_P(printer) ? (char*)0 : RSTRING_PTR(printer)), (mine ? 1 : 0), whichjobs);
  list = rb_ary_new2(num_jobs);
  for (i = num_jobs, job = jobs;
  i > 0;
  i --, job ++) { VALUE  hash  =
 rb_hash_new();
  rb_hash_aset(hash, str_completed_time, rb_time_new(job->completed_time, 0));
  rb_hash_aset(hash, str_creation_time, rb_time_new(job->creation_time, 0));
  rb_hash_aset(hash, str_dest, as_string(job->dest));
  rb_hash_aset(hash, str_format, as_string(job->format));
  rb_hash_aset(hash, str_id, INT2NUM(job->id));
  rb_hash_aset(hash, str_priority, INT2NUM(job->priority));
  rb_hash_aset(hash, str_processing_time, rb_time_new(job->processing_time, 0));
  rb_hash_aset(hash, str_size, INT2NUM(job->size));
  rb_hash_aset(hash, str_title, as_string(job->title));
  rb_hash_aset(hash, str_user, as_string(job->user));
  rb_hash_aset(hash, str_state, job_state(job->state));
  rb_ary_push(list, hash);
  } cupsFreeJobs(num_jobs, jobs);
  do { __p_retval = list; goto out; } while(0);

  } while(0);

out:
  return __p_retval;
}

.printFile(*__p_argv, self) ⇒ Object



481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
# File 'ext/noggin/noggin.c', line 481

static VALUE
Noggin_CLASS_printFile(int __p_argc, VALUE *__p_argv, VALUE self)
{
  VALUE __p_retval OPTIONAL_ATTR = Qnil;
  VALUE __v_destinationName = Qnil;
  char * destinationName; char * __orig_destinationName;
  VALUE __v_fileName = Qnil;
  char * fileName; char * __orig_fileName;
  VALUE __v_title = Qnil;
  char * title; char * __orig_title;
  VALUE options = Qnil;

  /* Scan arguments */
  rb_scan_args(__p_argc, __p_argv, "31",&__v_destinationName, &__v_fileName, &__v_title, &options);

  /* Set defaults */
  __orig_destinationName = destinationName = ( NIL_P(__v_destinationName) ? NULL : StringValuePtr(__v_destinationName) );

  __orig_fileName = fileName = ( NIL_P(__v_fileName) ? NULL : StringValuePtr(__v_fileName) );

  __orig_title = title = ( NIL_P(__v_title) ? NULL : StringValuePtr(__v_title) );

  if (__p_argc <= 3)
    options = Qnil;
  else
  if (! ((TYPE(options) == T_HASH) || (TYPE(options) == T_NIL)) )
    rb_raise(rb_eArgError, "options argument must be one of Hash, Nil");


#line 468 "/home/geoff/Projects/noggin/ext/noggin/noggin.cr"

  do {
  struct svp_it  info  =
 {0, NULL};
  int job_id = -1;
  if (TYPE(options) == T_HASH) { rb_hash_foreach(options, hash_to_cups_options_it, (VALUE)&info);
  } job_id = cupsPrintFile(destinationName, fileName, title, info.num_options, info.options);
  if (info.options) { cupsFreeOptions(info.num_options, info.options);
  } do { __p_retval =  INT2NUM(job_id); goto out; } while(0);

  } while(0);

out:
  return __p_retval;
}