QTSS_Error QTSServer::RereadPrefsService(QTSS_ServiceFunctionArgsPtr /*inArgs*/) { // // This function can only be called safely when the server is completely running. // Ensuring this is a bit complicated because of preemption. Here's how it's done... QTSServerInterface* theServer = QTSServerInterface::GetServer(); // This is to make sure this function isn't being called before the server is // completely started up. if ((theServer == NULL) || (theServer->GetServerState() != qtssRunningState)) return QTSS_OutOfState; // Because the server must have started up, and because this object always stays // around (until the process dies), we can now safely get this object. QTSServerPrefs* thePrefs = theServer->GetPrefs(); // Grab the prefs mutex. We want to make sure that calls to RereadPrefsService // are serialized. This also prevents the server from shutting down while in // this function, because the QTSServer destructor grabs this mutex as well. OSMutexLocker locker(thePrefs->GetMutex()); // Finally, check the server state again. The state may have changed // to qtssShuttingDownState or qtssFatalErrorState in this time, though // at this point we have the prefs mutex, so we are guarenteed that the // server can't actually shut down anymore if (theServer->GetServerState() != qtssRunningState) return QTSS_OutOfState; // Ok, we're ready to reread preferences now. // // Reread preferences sPrefsSource->Parse(); thePrefs->RereadServerPreferences(true); // Delete all the streams QTSSModule** theModule = NULL; UInt32 theLen = 0; for (int y = 0; QTSServerInterface::GetServer()->GetValuePtr(qtssSvrModuleObjects, y, (void**)&theModule, &theLen) == QTSS_NoErr; y++) { Assert(theModule != NULL); Assert(theLen == sizeof(QTSSModule*)); (*theModule)->GetPrefsDict()->RereadPreferences(); #if DEBUG theModule = NULL; theLen = 0; #endif } // // Go through each module's prefs object and have those reread as well // // Now that we are done rereading the prefs, invoke all modules in the RereadPrefs // role so they can update their internal prefs caches. for (UInt32 x = 0; x < QTSServerInterface::GetNumModulesInRole(QTSSModule::kRereadPrefsRole); x++) { QTSSModule* theModule = QTSServerInterface::GetModule(QTSSModule::kRereadPrefsRole, x); (void)theModule->CallDispatch(QTSS_RereadPrefs_Role, NULL); } return QTSS_NoErr; }