]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/sysman.c
Merge changes from CUPS 1.5svn-r9641
[thirdparty/cups.git] / scheduler / sysman.c
index 9bfc17abbc290b6d1d32636a93af54cb3db5dc5a..65cfc13c3b5e5f10202f9e079554fd04d837da58 100644 (file)
 #ifdef HAVE_VPROC_TRANSACTION_BEGIN
 #  include <vproc.h>
 #endif /* HAVE_VPROC_TRANSACTION_BEGIN */
+#ifdef __APPLE__
+#  include <IOKit/pwr_mgt/IOPMLib.h>
+#  ifdef HAVE_IOKIT_PWR_MGT_IOPMLIBPRIVATE_H
+#    include <IOKit/pwr_mgt/IOPMLibPrivate.h>
+#  endif /* HAVE_IOKIT_PWR_MGT_IOPMLIBPRIVATE_H */
+#endif /* __APPLE__ */
 
 
 /*
  * to wake up in a new location/on a new wireless network.
  */
 
+/*
+ * Local globals...
+ */
+
+#ifdef kIOPMAssertionTypeDenySystemSleep
+static IOPMAssertionID dark_wake = 0;  /* "Dark wake" assertion for sharing */
+#endif /* kIOPMAssertionTypeDenySystemSleep */
+
 
 /*
  * 'cupsdCleanDirty()' - Write dirty config and state files.
@@ -136,8 +150,11 @@ cupsdMarkDirty(int what)           /* I - What file(s) are dirty? */
 void
 cupsdSetBusyState(void)
 {
-  int          newbusy;                /* New busy state */
-  static int   busy = 0;               /* Current busy state */
+  int                  i;              /* Looping var */
+  cupsd_job_t          *job;           /* Current job */
+  cupsd_printer_t      *p;             /* Current printer */
+  int                  newbusy;        /* New busy state */
+  static int           busy = 0;       /* Current busy state */
   static const char * const busy_text[] =
   {                                    /* Text for busy states */
     "Not busy",
@@ -154,10 +171,35 @@ cupsdSetBusyState(void)
 #endif /* HAVE_VPROC_TRANSACTION_BEGIN */
 
 
+ /*
+  * Figure out how busy we are...
+  */
+
   newbusy = (DirtyCleanTime ? 1 : 0) |
-            (cupsArrayCount(PrintingJobs) ? 2 : 0) |
            (cupsArrayCount(ActiveClients) ? 4 : 0);
 
+  for (job = (cupsd_job_t *)cupsArrayFirst(PrintingJobs);
+       job;
+       job = (cupsd_job_t *)cupsArrayNext(PrintingJobs))
+  {
+    if ((p = job->printer) != NULL)
+    {
+      for (i = 0; i < p->num_reasons; i ++)
+       if (!strcmp(p->reasons[i], "connecting-to-device"))
+         break;
+
+      if (!p->num_reasons || i >= p->num_reasons)
+       break;
+    }
+  }
+
+  if (job)
+    newbusy |= 2;
+
+ /*
+  * Manage state changes...
+  */
+
   if (newbusy != busy)
   {
     busy = newbusy;
@@ -172,6 +214,18 @@ cupsdSetBusyState(void)
     }
 #endif /* HAVE_VPROC_TRANSACTION_BEGIN */
 
+#ifdef kIOPMAssertionTypeDenySystemSleep
+    if ((busy & 2) && !dark_wake)
+      IOPMAssertionCreateWithName(kIOPMAssertionTypeDenySystemSleep,
+                                 kIOPMAssertionLevelOn,
+                                 CFSTR("org.cups.cupsd"), &dark_wake);
+    else if (!(busy & 2) && dark_wake)
+    {
+      IOPMAssertionRelease(dark_wake);
+      dark_wake = 0;
+    }
+#endif /* kIOPMAssertionTypeDenySystemSleep */
+
     cupsdLogMessage(CUPSD_LOG_DEBUG, "cupsdSetBusyState: %s", busy_text[busy]);
   }
 }