373
* job_class_get_registered:
375
* @name: name of JobClass to search for,
376
* @session: Session of @class.
378
* Determine the currently registered JobClass with name @name for
381
* Returns: JobClass or NULL if no JobClass with name @name and
382
* session @session is registered.
385
job_class_get_registered (const char *name, Session *session)
387
JobClass *registered;
393
registered = (JobClass *)nih_hash_search (job_classes, name, NULL);
395
/* If we found an entry, ensure we only consider the appropriate session */
396
while (registered && registered->session != session)
397
registered = (JobClass *)nih_hash_search (job_classes, name, ®istered->entry);
374
403
* job_class_consider:
393
423
nih_assert (best != NULL);
394
424
nih_assert (best->session == class->session);
396
registered = (JobClass *)nih_hash_search (job_classes, class->name, NULL);
398
/* If we found an entry, ensure we only consider the appropriate session */
399
while (registered && registered->session != class->session)
400
registered = (JobClass *)nih_hash_search (job_classes, class->name, ®istered->entry);
426
registered = job_class_get_registered (class->name, class->session);
402
428
if (registered != best) {
404
if (! job_class_remove (registered, class->session))
430
job_class_event_block (NULL, registered, best);
432
if (! job_class_remove (registered, class->session)) {
433
/* Couldn't deregister, so undo */
435
event_operator_reset (best->start_on);
407
440
job_class_add (best);
435
469
best = conf_select_job (class->name, class->session);
437
registered = (JobClass *)nih_hash_search (job_classes, class->name, NULL);
439
/* If we found an entry, ensure we only consider the appropriate session */
440
while (registered && registered->session != class->session)
441
registered = (JobClass *)nih_hash_search (job_classes, class->name, ®istered->entry);
471
registered = job_class_get_registered (class->name, class->session);
443
473
if (registered == class) {
444
474
if (class != best) {
490
* job_class_event_block:
492
* @parent: parent object for list,
493
* @old: original JobClass currently registered in job_classes,
494
* @new: new "best" JobClass that is not yet present in job_classes.
496
* Compare @old and @new start on EventOperator trees looking for
497
* matching events that occur in both (_and_ which implicitly still exist
498
* in the global events list). Events that satisfy these criteria will have
499
* their reference count elevated to allow @new to replace @old in job_classes
500
* without the destruction of @old freeing the events in question.
502
* Note that the reference count never needs to be decremented back
503
* again since this function effectively passes "ownership" of the event
504
* block from @old to @new, since @old will be replaced by @new but @new
505
* should replicate the EventOperator state of @old.
508
job_class_event_block (void *parent, JobClass *old, JobClass *new)
510
EventOperator *old_root;
511
EventOperator *new_root;
516
old_root = old->start_on;
517
new_root = new->start_on;
519
/* If either @old or @new are NULL, or have no start_on
520
* condition, there is no need to modify any events.
522
if (! old_root || ! new_root)
525
/* The old JobClass has associated instances meaning it
526
* will not be possible for job_class_remove() to replace it, so
527
* we don't need to manipulate any event reference counts.
529
NIH_HASH_FOREACH (old->instances, iter)
532
NIH_TREE_FOREACH_POST (&old_root->node, iter) {
533
EventOperator *old_oper = (EventOperator *)iter;
536
if (old_oper->type != EVENT_MATCH)
539
/* Ignore nodes that are not blocking events */
540
if (! old_oper->event)
543
/* Since the JobClass is blocking an event,
544
* that event must be valid.
546
event = old_oper->event;
548
NIH_TREE_FOREACH_POST (&new_root->node, niter) {
549
EventOperator *new_oper = (EventOperator *)niter;
551
if (new_oper->type != EVENT_MATCH)
554
/* ignore the return - we just want to ensure
555
* that any events in @new that match those in
556
* @old have identical nodes.
558
(void)event_operator_handle (new_oper, event, NULL);
461
565
* @class: new class to select.