예제 #1
0
void PluginHooks::readConfig(OsConfigDb& configDb)
{
   OsSysLog::add(FAC_KERNEL, PRI_DEBUG, "PluginHooks::readConfig" );

   // Move any existing hooks from the current configured list to
   // a temporary holding list.
   UtlSList existingHooks;
   UtlContainable* existingHook;
   
   UtlSortedListIterator nextHook(mConfiguredHooks);
   while (existingHook = nextHook())
   {
      existingHooks.append(mConfiguredHooks.removeReference(existingHook));
   }
   // the mConfiguredHooks list is now empty
   
   // Walk the current configuration,
   //   any existing hook is moved back to the mConfiguredHooks list,
   //   newly configured hooks are added,
   //   each configured hook is called to read its own configuration.
   UtlString  hookPrefix(mPrefix);
   hookPrefix.append(HOOK_LIB_PREFIX);
   
   OsConfigDb allHooks;
   
   OsSysLog::add(FAC_KERNEL, PRI_DEBUG,
                 "PluginHooks::readConfig looking up hooks '%s'",
                 hookPrefix.data()
                 );
   if (OS_SUCCESS == configDb.getSubHash(hookPrefix, allHooks)) // any hooks configured for prefix?
   {
      UtlString lastHook;
      UtlString hookName;
      UtlString hookLibrary;

      // walk each hook and attempt to load and configure it 
      for ( lastHook = "";
            OS_SUCCESS == allHooks.getNext(lastHook, hookName, hookLibrary);
            lastHook = hookName
           )
      {
         ConfiguredHook* thisHook;
         
         if (NULL == (thisHook = dynamic_cast<ConfiguredHook*>(existingHooks.remove(&hookName))))
         {
            // not an existing hook, so create a new one
            OsSysLog::add(FAC_KERNEL, PRI_DEBUG,
                          "PluginHooks: loading '%s'", hookName.data()
                          );
            thisHook = new ConfiguredHook(hookName, mFactory, hookLibrary);
         }

         // put the hook onto the list of active hooks
         mConfiguredHooks.insert(thisHook);

         // (re)configure the hook
         thisHook->readConfig(mPrefix, configDb);
      }
   }
   else
   {
      OsSysLog::add(FAC_KERNEL, PRI_INFO,
                    "PluginHooks: no '%s' hooks configured", mPrefix.data()
                    );
   }

   // discard any hooks that are no longer in the configuration
   existingHooks.destroyAll();
}