]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/sysman.c
Load cups into easysw/current.
[thirdparty/cups.git] / scheduler / sysman.c
index a0edfbd315bd7a79837bd0e0eae4b238bf5ee421..a67b4fa7f06a6b34650547e0c93399fcf028c9ef 100644 (file)
@@ -1,25 +1,16 @@
 /*
- * "$Id: sysman.c 5241 2006-03-07 22:07:44Z mike $"
+ * "$Id: sysman.c 6649 2007-07-11 21:46:42Z mike $"
  *
  *   System management definitions for the Common UNIX Printing System (CUPS).
  *
+ *   Copyright 2007 by Apple Inc.
  *   Copyright 2006 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
- *   property of Easy Software Products and are protected by Federal
- *   copyright law.  Distribution and use rights are outlined in the file
- *   "LICENSE.txt" which should have been included with this file.  If this
- *   file is missing or damaged please contact Easy Software Products
- *   at:
- *
- *       Attn: CUPS Licensing Information
- *       Easy Software Products
- *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
+ *   property of Apple Inc. and are protected by Federal copyright
+ *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
+ *   which should have been included with this file.  If this file is
+ *   file is missing or damaged, see the license at "http://www.cups.org/".
  *
  * Contents:
  *
  * common to wake up in a new location.
  */
 
-#ifndef __APPLE__
-/*
- * 'cupsdStartSystemMonitor()' - Start monitoring for system change.
- */
-
-void
-cupsdStartSystemMonitor(void)
-{
-}
-
-
-/*
- * 'cupsdStopSystemMonitor()' - Stop monitoring for system change.
- */
-
-void
-cupsdStopSystemMonitor(void)
-{
-}
-
-
-/*
- * 'cupsdUpdateSystemMonitor()' - Update the current system state.
- */
-
-void
-cupsdUpdateSystemMonitor(void)
-{
-}
-#endif /* !__APPLE__ */
-
-
 #ifdef __APPLE__
 /*
  * This is the Apple-specific system event code.  It works by creating
@@ -147,11 +106,17 @@ static CFRunLoopRef       SysEventRunloop = NULL;
                                        /* The runloop. Access must be protected! */
 static CFStringRef     ComputerNameKey = NULL,
                                        /* Computer name key */
-                       NetworkGlobalKey = NULL,
-                                       /* Network global key */
+                       NetworkGlobalKeyIPv4 = NULL,
+                                       /* Network global IPv4 key */
+                       NetworkGlobalKeyIPv6 = NULL,
+                                       /* Network global IPv6 key */
+                       NetworkGlobalKeyDNS = NULL,
+                                       /* Network global DNS key */
                        HostNamesKey = NULL,
                                        /* Host name key */
-                       NetworkInterfaceKey = NULL;
+                       NetworkInterfaceKeyIPv4 = NULL,
+                                       /* Netowrk interface key */
+                       NetworkInterfaceKeyIPv6 = NULL;
                                        /* Netowrk interface key */
 
 
@@ -186,10 +151,8 @@ cupsdStartSystemMonitor(void)
     return;
   }
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                  "cupsdStartSystemMonitor: Adding fd %d to InputSet...",
-                  SysEventPipes[0]);
-  FD_SET(SysEventPipes[0], InputSet);
+  cupsdAddSelect(SysEventPipes[0], (cupsd_selfunc_t)cupsdUpdateSystemMonitor,
+                 NULL, NULL);
 
  /*
   * Set non-blocking mode on the descriptor we will be receiving notification
@@ -246,12 +209,7 @@ cupsdStopSystemMonitor(void)
 
   if (SysEventPipes[0] >= 0)
   {
-    cupsdLogMessage(CUPSD_LOG_DEBUG2,
-                    "cupsdStopSystemMonitor: Removing fd %d from InputSet...",
-                   SysEventPipes[0]);
-
-    FD_CLR(SysEventPipes[0], InputSet);
-
+    cupsdRemoveSelect(SysEventPipes[0]);
     cupsdClosePipe(SysEventPipes);
   }
 }
@@ -321,7 +279,7 @@ cupsdUpdateSystemMonitor(void)
 
       Sleeping = 1;
 
-      cupsdStopAllJobs();
+      cupsdStopAllJobs(0);
       cupsdSaveAllJobs();
 
       for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
@@ -338,10 +296,9 @@ cupsdUpdateSystemMonitor(void)
        }
        else
        {
-        /* TODO: Possibly update when MDNS support is added? */
          cupsdLogMessage(CUPSD_LOG_DEBUG,
                          "Deregistering local printer \"%s\"", p->name);
-         cupsdSendBrowseDelete(p);
+         cupsdDeregisterPrinter(p, 0);
        }
       }
 
@@ -365,12 +322,6 @@ cupsdUpdateSystemMonitor(void)
         cupsdLogMessage(CUPSD_LOG_DEBUG,
                        "System network configuration changed");
 
-       /*
-        * Force an update of the list of network interfaces in 2 seconds.
-        */
-
-        NetIFTime = time(NULL) - 58;
-
        /*
         * Resetting browse_time before calling cupsdSendBrowseList causes
        * browse packets to be sent for local shared printers.
@@ -382,6 +333,7 @@ cupsdUpdateSystemMonitor(void)
          p->browse_time = 0;
 
         cupsdSendBrowseList();
+       cupsdRestartPolling();
       }
       else
         cupsdLogMessage(CUPSD_LOG_DEBUG,
@@ -402,18 +354,19 @@ cupsdUpdateSystemMonitor(void)
        for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
             p;
             p = (cupsd_printer_t *)cupsArrayNext(Printers))
-         cupsdSendBrowseDelete(p);
+         cupsdDeregisterPrinter(p, 1);
 
        /*
        * Now re-register them...
-       *
-       * TODO: This might need updating for MDNS.
        */
 
        for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
             p;
             p = (cupsd_printer_t *)cupsArrayNext(Printers))
+       {
          p->browse_time = 0;
+         cupsdRegisterPrinter(p);
+       }
       }
       else
         cupsdLogMessage(CUPSD_LOG_DEBUG,
@@ -438,8 +391,8 @@ sysEventThreadEntry(void)
   SCDynamicStoreRef    store    = NULL;/* System Config dynamic store */
   CFRunLoopSourceRef   powerRLS = NULL,/* Power runloop source */
                        storeRLS = NULL;/* System Config runloop source */
-  CFStringRef          key[3],         /* System Config keys */
-                       pattern[1];     /* System Config patterns */
+  CFStringRef          key[5],         /* System Config keys */
+                       pattern[2];     /* System Config patterns */
   CFArrayRef           keys = NULL,    /* System Config key array*/
                        patterns = NULL;/* System Config pattern array */
   SCDynamicStoreContext        storeContext;   /* Dynamic store context */
@@ -480,33 +433,58 @@ sysEventThreadEntry(void)
   if (!ComputerNameKey)
     ComputerNameKey = SCDynamicStoreKeyCreateComputerName(NULL);
 
-  if (!NetworkGlobalKey)
-    NetworkGlobalKey =
+  if (!NetworkGlobalKeyIPv4)
+    NetworkGlobalKeyIPv4 =
         SCDynamicStoreKeyCreateNetworkGlobalEntity(NULL,
                                                    kSCDynamicStoreDomainState,
                                                   kSCEntNetIPv4);
 
+  if (!NetworkGlobalKeyIPv6)
+    NetworkGlobalKeyIPv6 =
+        SCDynamicStoreKeyCreateNetworkGlobalEntity(NULL,
+                                                   kSCDynamicStoreDomainState,
+                                                  kSCEntNetIPv6);
+
+  if (!NetworkGlobalKeyDNS)
+    NetworkGlobalKeyDNS = 
+       SCDynamicStoreKeyCreateNetworkGlobalEntity(NULL, 
+                                                  kSCDynamicStoreDomainState,
+                                                  kSCEntNetDNS);
+
   if (!HostNamesKey)
     HostNamesKey = SCDynamicStoreKeyCreateHostNames(NULL);
 
-  if (!NetworkInterfaceKey)
-    NetworkInterfaceKey =
+  if (!NetworkInterfaceKeyIPv4)
+    NetworkInterfaceKeyIPv4 =
         SCDynamicStoreKeyCreateNetworkInterfaceEntity(NULL,
                                                      kSCDynamicStoreDomainState,
                                                      kSCCompAnyRegex,
                                                      kSCEntNetIPv4);
 
-  if (store && ComputerNameKey && NetworkGlobalKey && HostNamesKey &&
-      NetworkInterfaceKey)
+  if (!NetworkInterfaceKeyIPv6)
+    NetworkInterfaceKeyIPv6 =
+        SCDynamicStoreKeyCreateNetworkInterfaceEntity(NULL,
+                                                     kSCDynamicStoreDomainState,
+                                                     kSCCompAnyRegex,
+                                                     kSCEntNetIPv6);
+
+  if (store && ComputerNameKey && HostNamesKey &&
+      NetworkGlobalKeyIPv4 && NetworkGlobalKeyIPv6 && NetworkGlobalKeyDNS &&
+      NetworkInterfaceKeyIPv4 && NetworkInterfaceKeyIPv6)
   {
     key[0]     = ComputerNameKey;
-    key[1]     = NetworkGlobalKey;
-    key[2]     = HostNamesKey;
-    pattern[0] = NetworkInterfaceKey;
+    key[1]     = NetworkGlobalKeyIPv4;
+    key[2]     = NetworkGlobalKeyIPv6;
+    key[3]     = NetworkGlobalKeyDNS;
+    key[4]     = HostNamesKey;
+
+    pattern[0] = NetworkInterfaceKeyIPv4;
+    pattern[1] = NetworkInterfaceKeyIPv6;
 
     keys     = CFArrayCreate(NULL, (const void **)key,
                                     sizeof(key) / sizeof(key[0]),
                                    &kCFTypeArrayCallBacks);
+
     patterns = CFArrayCreate(NULL, (const void **)pattern,
                              sizeof(pattern) / sizeof(pattern[0]),
                             &kCFTypeArrayCallBacks);
@@ -713,12 +691,17 @@ sysEventConfigurationNotifier(
 
   if (CFArrayContainsValue(changedKeys, range, ComputerNameKey))
     threadData->sysevent.event |= SYSEVENT_NAMECHANGED;
-
-  if (CFArrayContainsValue(changedKeys, range, NetworkGlobalKey) ||
-      CFArrayContainsValue(changedKeys, range, HostNamesKey) ||
-      CFArrayContainsValue(changedKeys, range, NetworkInterfaceKey))
+  else
+  {
     threadData->sysevent.event |= SYSEVENT_NETCHANGED;
 
+   /*
+    * Indicate the network interface list needs updating...
+    */
+
+    NetIFUpdate = 1;
+  }
+
  /*
   * Because we registered for several different kinds of change notifications 
   * this callback usually gets called several times in a row. We use a timer to 
@@ -726,7 +709,7 @@ sysEventConfigurationNotifier(
   */
 
   CFRunLoopTimerSetNextFireDate(threadData->timerRef, 
-                               CFAbsoluteTimeGetCurrent() + 2);
+                               CFAbsoluteTimeGetCurrent() + 5);
 }
 
 
@@ -759,5 +742,5 @@ sysEventTimerNotifier(
 
 
 /*
- * End of "$Id: sysman.c 5241 2006-03-07 22:07:44Z mike $".
+ * End of "$Id: sysman.c 6649 2007-07-11 21:46:42Z mike $".
  */