]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/subscriptions.c
More svn:properties changes.
[thirdparty/cups.git] / scheduler / subscriptions.c
index 2d94eececb601f631bf0ba030e064731bb1246e0..56f21d1d6b7e23f303bfdf3b460fba82755b4838 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: subscriptions.c 5249 2006-03-08 16:45:28Z mike $"
+ * "$Id$"
  *
  *   Subscription routines for the Common UNIX Printing System (CUPS) scheduler.
  *
@@ -25,7 +25,6 @@
  *
  *   cupsdAddEvent()               - Add an event to the global event cache.
  *   cupsdAddSubscription()        - Add a new subscription object.
- *   cupsdDeleteAllEvents()        - Delete all cached events.
  *   cupsdDeleteAllSubscriptions() - Delete all subscriptions.
  *   cupsdDeleteSubscription()     - Delete a subscription object.
  *   cupsdEventName()              - Return a single event name.
  *   cupsdFindSubscription()       - Find a subscription by ID.
  *   cupsdLoadAllSubscriptions()   - Load all subscriptions from the .conf file.
  *   cupsdSaveAllSubscriptions()   - Save all subscriptions to the .conf file.
- *   cupsdSendNotification()       - Send a notification for the specified event.
  *   cupsdStopAllNotifiers()       - Stop all notifier processes.
  *   cupsdUpdateNotifierStatus()   - Read messages from notifiers.
  *   cupsd_compare_subscriptions() - Compare two subscriptions.
+ *   cupsd_delete_all_events()     - Delete all cached events.
  *   cupsd_delete_event()          - Delete a single event...
  *   cupsd_send_dbus()             - Send a DBUS notification...
+ *   cupsd_send_notification()     - Send a notification for the specified
+ *                                   event.
  *   cupsd_start_notifier()        - Start a notifier subprocess...
  */
 
 static int     cupsd_compare_subscriptions(cupsd_subscription_t *first,
                                            cupsd_subscription_t *second,
                                            void *unused);
+static void    cupsd_delete_all_events(void);
 static void    cupsd_delete_event(cupsd_event_t *event);
 #ifdef HAVE_DBUS
 static void    cupsd_send_dbus(cupsd_eventmask_t event, cupsd_printer_t *dest,
                                cupsd_job_t *job);
 #endif /* HAVE_DBUS */
+static void    cupsd_send_notification(cupsd_subscription_t *sub,
+                                       cupsd_event_t *event);
 static void    cupsd_start_notifier(cupsd_subscription_t *sub);
 
 
@@ -226,7 +230,7 @@ cupsdAddEvent(
          ippAddInteger(temp->attrs, IPP_TAG_EVENT_NOTIFICATION, IPP_TAG_INTEGER,
                        "notify-job-id", job->id);
          ippAddInteger(temp->attrs, IPP_TAG_EVENT_NOTIFICATION, IPP_TAG_ENUM,
-                       "job-state", (int)job->state);
+                       "job-state", job->state_value);
 
           if ((attr = ippFindAttribute(job->attrs, "job-name",
                                       IPP_TAG_NAME)) != NULL)
@@ -323,7 +327,7 @@ cupsdAddEvent(
       * Send the notification for this subscription...
       */
 
-      cupsdSendNotification(sub, temp);
+      cupsd_send_notification(sub, temp);
     }
   }
 
@@ -351,9 +355,10 @@ cupsdAddSubscription(
 
 
   cupsdLogMessage(CUPSD_LOG_DEBUG,
-                  "cupsdAddSubscription(mask=%x(%s), dest=%p(%s), job=%p(%d), uri=\"%s\")",
-                  mask, cupsdEventName(mask), dest, dest ? dest->name : "",
-                 job, job ? job->id : 0, uri);
+                  "cupsdAddSubscription(mask=%x, dest=%p(%s), job=%p(%d), "
+                 "uri=\"%s\")",
+                  mask, dest, dest ? dest->name : "", job, job ? job->id : 0,
+                 uri);
 
   if (!Subscriptions)
     Subscriptions = cupsArrayNew((cups_array_func_t)cupsd_compare_subscriptions,
@@ -423,27 +428,6 @@ cupsdAddSubscription(
 }
 
 
-/*
- * 'cupsdDeleteAllEvents()' - Delete all cached events.
- */
-
-void
-cupsdDeleteAllEvents(void)
-{
-  int  i;                              /* Looping var */
-
-
-  if (MaxEvents <= 0 || !Events)
-    return;
-
-  for (i = 0; i < NumEvents; i ++)
-    cupsd_delete_event(Events[i]);
-
-  free(Events);
-  Events = NULL;
-}
-
-
 /*
  * 'cupsdDeleteAllSubscriptions()' - Delete all subscriptions.
  */
@@ -454,6 +438,8 @@ cupsdDeleteAllSubscriptions(void)
   cupsd_subscription_t *sub;           /* Subscription */
 
 
+  cupsd_delete_all_events();
+
   if (!Subscriptions)
     return;
 
@@ -571,6 +557,9 @@ cupsdEventName(
     case CUPSD_EVENT_JOB_PROGRESS :
         return ("job-progress");
 
+    case CUPSD_EVENT_JOB_STATE :
+        return ("job-state");
+
     case CUPSD_EVENT_JOB_STATE_CHANGED :
         return ("job-state-changed");
 
@@ -623,6 +612,8 @@ cupsdEventValue(const char *name)   /* I - Name of event */
     return (CUPSD_EVENT_PRINTER_CONFIG_CHANGED);
   else if (!strcmp(name, "printer-changed"))
     return (CUPSD_EVENT_PRINTER_CHANGED);
+  else if (!strcmp(name, "job-state"))
+    return (CUPSD_EVENT_JOB_STATE);
   else if (!strcmp(name, "job-created"))
     return (CUPSD_EVENT_JOB_CREATED);
   else if (!strcmp(name, "job-completed"))
@@ -1218,83 +1209,6 @@ cupsdSaveAllSubscriptions(void)
 }
 
 
-/*
- * 'cupsdSendNotification()' - Send a notification for the specified event.
- */
-
-void
-cupsdSendNotification(
-    cupsd_subscription_t *sub,         /* I - Subscription object */
-    cupsd_event_t        *event)       /* I - Event to send */
-{
-  ipp_state_t  state;                  /* IPP event state */
-
-
-  cupsdLogMessage(CUPSD_LOG_DEBUG,
-                  "cupsdSendNotification(sub=%p(%d), event=%p(%s))\n",
-                  sub, sub->id, event, cupsdEventName(event->event));
-
- /*
-  * Allocate the events array as needed...
-  */
-
-  if (!sub->events)
-  {
-    sub->events = calloc(MaxEvents, sizeof(cupsd_event_t *));
-
-    if (!sub->events)
-    {
-      cupsdLogMessage(CUPSD_LOG_CRIT,
-                      "Unable to allocate memory for subscription #%d!",
-                      sub->id);
-      return;
-    }
-  }
-
- /*
-  * Add the event to the subscription.  Since the events array is
-  * always MaxEvents in length, and since we will have already
-  * removed an event from the subscription cache if we hit the
-  * event cache limit, we don't need to check for overflow here...
-  */
-
-  sub->events[sub->num_events] = event;
-  sub->num_events ++;
-
- /*
-  * Deliver the event...
-  */
-
-  if (sub->recipient)
-  {
-    if (sub->pipe < 0)
-      cupsd_start_notifier(sub);
-
-    cupsdLogMessage(CUPSD_LOG_DEBUG, "sub->pipe=%d", sub->pipe);
-
-    if (sub->pipe >= 0)
-    {
-      event->attrs->state = IPP_IDLE;
-
-      while ((state = ippWriteFile(sub->pipe, event->attrs)) != IPP_DATA)
-        if (state == IPP_ERROR)
-         break;
-
-      if (state == IPP_ERROR)
-        cupsdLogMessage(CUPSD_LOG_ERROR,
-                       "Unable to send event for subscription %d (%s)!",
-                       sub->id, sub->recipient);
-    }
-  }
-
- /*
-  * Bump the event sequence number...
-  */
-
-  sub->next_event_id ++;
-}
-
-
 /*
  * 'cupsdStopAllNotifiers()' - Stop all notifier processes.
  */
@@ -1385,6 +1299,27 @@ cupsd_compare_subscriptions(
 }
 
 
+/*
+ * 'cupsd_delete_all_events()' - Delete all cached events.
+ */
+
+static void
+cupsd_delete_all_events(void)
+{
+  int  i;                              /* Looping var */
+
+
+  if (MaxEvents <= 0 || !Events)
+    return;
+
+  for (i = 0; i < NumEvents; i ++)
+    cupsd_delete_event(Events[i]);
+
+  free(Events);
+  Events = NULL;
+}
+
+
 /*
  * 'cupsd_delete_event()' - Delete a single event...
  *
@@ -1521,6 +1456,83 @@ cupsd_send_dbus(cupsd_eventmask_t event,/* I - Event to send */
 #endif /* HAVE_DBUS */
 
 
+/*
+ * 'cupsd_send_notification()' - Send a notification for the specified event.
+ */
+
+static void
+cupsd_send_notification(
+    cupsd_subscription_t *sub,         /* I - Subscription object */
+    cupsd_event_t        *event)       /* I - Event to send */
+{
+  ipp_state_t  state;                  /* IPP event state */
+
+
+  cupsdLogMessage(CUPSD_LOG_DEBUG,
+                  "cupsd_send_notification(sub=%p(%d), event=%p(%s))\n",
+                  sub, sub->id, event, cupsdEventName(event->event));
+
+ /*
+  * Allocate the events array as needed...
+  */
+
+  if (!sub->events)
+  {
+    sub->events = calloc(MaxEvents, sizeof(cupsd_event_t *));
+
+    if (!sub->events)
+    {
+      cupsdLogMessage(CUPSD_LOG_CRIT,
+                      "Unable to allocate memory for subscription #%d!",
+                      sub->id);
+      return;
+    }
+  }
+
+ /*
+  * Add the event to the subscription.  Since the events array is
+  * always MaxEvents in length, and since we will have already
+  * removed an event from the subscription cache if we hit the
+  * event cache limit, we don't need to check for overflow here...
+  */
+
+  sub->events[sub->num_events] = event;
+  sub->num_events ++;
+
+ /*
+  * Deliver the event...
+  */
+
+  if (sub->recipient)
+  {
+    if (sub->pipe < 0)
+      cupsd_start_notifier(sub);
+
+    cupsdLogMessage(CUPSD_LOG_DEBUG, "sub->pipe=%d", sub->pipe);
+
+    if (sub->pipe >= 0)
+    {
+      event->attrs->state = IPP_IDLE;
+
+      while ((state = ippWriteFile(sub->pipe, event->attrs)) != IPP_DATA)
+        if (state == IPP_ERROR)
+         break;
+
+      if (state == IPP_ERROR)
+        cupsdLogMessage(CUPSD_LOG_ERROR,
+                       "Unable to send event for subscription %d (%s)!",
+                       sub->id, sub->recipient);
+    }
+  }
+
+ /*
+  * Bump the event sequence number...
+  */
+
+  sub->next_event_id ++;
+}
+
+
 /*
  * 'cupsd_start_notifier()' - Start a notifier subprocess...
  */
@@ -1649,5 +1661,5 @@ cupsd_start_notifier(
 
 
 /*
- * End of "$Id: subscriptions.c 5249 2006-03-08 16:45:28Z mike $".
+ * End of "$Id$".
  */