[BACK] Return to admin_service.cpp CVS log [TXT][DIR] Up to Nevrax / code / nelns / admin_service

Diff for /code/nelns/admin_service/admin_service.cpp between version 1.4 and 1.5

version 1.4, 2001/05/18 16:51:33 version 1.5, 2001/05/31 16:44:54
Line 45 
Line 45 
         CService () : Id(0xFFFFFFFF), Ready(false), Connected(false), InConfig(false) { }         CService () : Id(0xFFFFFFFF), Ready(false), Connected(false), InConfig(false) { }
  
         uint32        Id;                                /// uint32 to identify the service         uint32        Id;                                /// uint32 to identify the service
         string        ServiceAlias;        /// alias of the service used in the AES and AS to find him (unique per AES)         string        AliasName;                /// alias of the service used in the AES and AS to find him (unique per AES)
         string        ShortName;                /// name of the service in short format ("NS" for example)         string        ShortName;                /// name of the service in short format ("NS" for example)
         string        LongName;                /// name of the service in long format ("naming_service")         string        LongName;                /// name of the service in long format ("naming_service")
         bool        Ready;                        /// true if the service is ready         bool        Ready;                        /// true if the service is ready
Line 83 
Line 83 
                 return sit;                 return sit;
         }         }
  
          SIT findService (const string &alias, bool asrt = true)
          {
                  SIT sit;
                  for (sit = Services.begin(); sit != Services.end(); sit++)
                          if ((*sit).AliasName == alias)
                                  break;
  
                  if (asrt)
                          nlassert (sit != Services.end());
                  return sit;
          }
  
 private: private:
         static uint32 NextId;         static uint32 NextId;
 }; };
Line 138 
Line 150 
 //////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////
  
 bool ScriptRunning = false; bool StartAllServices = false;
 string ScriptName; uint32 StartAllServicesPos;
 uint32 ScriptPos; 
  
 void doNextScriptStep () void doNextStartAllServicesStep ()
 { {
         nlassert (ScriptRunning);         nlassert (StartAllServices);
  
  
         // get the script         // get the script
  
         try         try
         {         {
                 CConfigFile::CVar &script = IService::ConfigFile.getVar(ScriptName);                 CConfigFile::CVar &script = IService::ConfigFile.getVar("Services");
  
                 // check the position                 // check the position
  
                 if (ScriptPos*2 >= (uint32)script.size())                 if (StartAllServicesPos*2 >= (uint32)script.size())
                 {                 {
                         ScriptRunning = false;                         StartAllServices = false;
                         nlinfo("end of the script");                         nlinfo("end of the script");
                         // todo send that the script is finish to the admin                         // todo send that the script is finish to the admin
                         return;                         return;
Line 170 
Line 179 
  
                 try                 try
                 {                 {
                         serverAlias = script.asString (ScriptPos*2);                         serverAlias = script.asString (StartAllServicesPos*2);
                         serviceAlias = script.asString (ScriptPos*2+1);                         serviceAlias = script.asString (StartAllServicesPos*2+1);
                 }                 }
                 catch(EBadSize &)                 catch(EBadSize &)
                 {                 {
                         nlwarning ("script '%s' not contains a good number of entries (must be a multiple of 2)", ScriptName.c_str());                         nlwarning ("'Services' variable does not contains a good number of entries (must be a multiple of 2)");
                         ScriptRunning = false;                         StartAllServices = false;
                         return;                         return;
                 }                 }
  
                 AESIT aesit = findAdminExecutorService (serverAlias, false);                 AESIT aesit = findAdminExecutorService (serverAlias, false);
                 if (aesit == AdminExecutorServices.end())                 if (aesit == AdminExecutorServices.end())
                 {                 {
                         ScriptRunning = false;                         StartAllServices = false;
                         nlwarning("don't find the server");                         nlwarning("don't find the server");
                         return;                         return;
                 }                 }
  
                  // check if the service is not currently running
  
                  StartAllServicesPos++;
  
                  SIT sit = (*aesit).findService (serviceAlias);
                  if ((*sit).Connected)
                  {
                          // the service is already running, go to the next process
                          doNextStartAllServicesStep ();
                  }
                  else
                  {
                 // send the resquest to the AES                 // send the resquest to the AES
  
                 CMessage msgout (CNetManager::getSIDA((*aesit).ServerAlias), "STARTS");                 CMessage msgout (CNetManager::getSIDA((*aesit).ServerAlias), "STARTS");
                 msgout.serial (serviceAlias);                 msgout.serial (serviceAlias);
                 CNetManager::send ((*aesit).ServerAlias, msgout);                 CNetManager::send ((*aesit).ServerAlias, msgout);
                  }
                 ScriptPos++; 
         }         }
         catch(EUnknownVar&)         catch(EUnknownVar&)
         {         {
                 nlwarning ("script '%s' not found", ScriptName.c_str());                 nlwarning ("'Services' variable is not found");
                 ScriptRunning = false;                 StartAllServices = false;
                 return;                 return;
         }         }
 } }
  
 void initScript(string scriptName) void initStartAllServices ()
 { {
         if (ScriptRunning)         if (StartAllServices)
         {         {
                 nlwarning("already running a script, reset it");                 nlwarning("already running a script, reset it");
                 ScriptRunning = false;                 StartAllServices = false;
         }         }
  
         try         try
         {         {
                 CConfigFile::CVar &script = IService::ConfigFile.getVar(scriptName);                 CConfigFile::CVar &script = IService::ConfigFile.getVar("Services");
  
                 for (sint i = 0 ; i < script.size (); i+=2)                 for (sint i = 0 ; i < script.size (); i+=2)
                 {                 {
Line 222 
Line 242 
                         AESIT aesit = findAdminExecutorService (serverAlias, false);                         AESIT aesit = findAdminExecutorService (serverAlias, false);
                         if (aesit == AdminExecutorServices.end())                         if (aesit == AdminExecutorServices.end())
                         {                         {
                                 nlwarning("aes not running, can't run the script");                                 nlwarning("aes '%s' not running, can't run the script", serverAlias.c_str());
                                 return;                                 return;
                         }                         }
                 }                 }
Line 233 
Line 253 
                 return;                 return;
         }         }
  
         ScriptName = scriptName;         StartAllServicesPos = 0;
         ScriptPos = 0;         StartAllServices = true;
         ScriptRunning = true; 
  
         doNextScriptStep();         doNextStartAllServicesStep();
 } }
  
  
Line 316 
Line 335 
         CAdminExecutorService *aes = (CAdminExecutorService*) from->appId();         CAdminExecutorService *aes = (CAdminExecutorService*) from->appId();
  
         uint32 sid;         uint32 sid;
         msgin.serial (sid);         string alias;
  
         SIT sit = aes->findService(sid);         msgin.serial (sid, alias);
  
          SIT sit;
          if (!alias.empty())
          {
                  sit = aes->findService (alias, false);
  
                  if (sit == aes->Services.end ())
                  {
                          // the alias is not found
                          nlwarning ("new service with alias (%s) but not in my list", alias.c_str());
  
                          aes->Services.push_back (CService ());
                          sit = aes->Services.end();
                          sit--;
                  }
                  else
                  {
                          // normal case
                  }
          }
          else
          {
                  sit = aes->findService (sid, false);
  
                  if (sit == aes->Services.end ())
                  {
                          // normal case for unknown services
                          nlwarning ("new service with alias (%s) but not in my list", alias.c_str());
                  }
                  else
                  {
                          nlwarning ("new service without alias is already in my list with id %d", sid);
                  }
                  aes->Services.push_back (CService ());
                  sit = aes->Services.end();
                  sit--;
          }
  
          (*sit).Id = sid;
          (*sit).AliasName = alias;
          (*sit).Connected = true;
         msgin.serial ((*sit).ShortName, (*sit).LongName);         msgin.serial ((*sit).ShortName, (*sit).LongName);
  
         nlinfo ("*:%d:%d is identified to be '%s' '%s'", aes->Id, sid, (*sit).ShortName.c_str(), (*sit).LongName.c_str());         nlinfo ("*:%d:%d is identified to be '%s' '%s' '%s'", aes->Id, sid, (*sit).AliasName.c_str(), (*sit).ShortName.c_str(), (*sit).LongName.c_str());
  
         // broadcast the message to all admin client         // broadcast the message to all admin client
         CMessage msgout (CNetManager::getSIDA ("AS"), "SID");         CMessage msgout (CNetManager::getSIDA ("AS"), "SID");
         msgout.serial (aes->Id, sid, (*sit).ShortName, (*sit).LongName);         msgout.serial (aes->Id, sid, (*sit).AliasName, (*sit).ShortName, (*sit).LongName);
         CNetManager::send ("AS", msgout, 0);         CNetManager::send ("AS", msgout, 0);
 } }
  
Line 347 
Line 407 
         CNetManager::send ("AS", msgout, 0);         CNetManager::send ("AS", msgout, 0);
  
         // if we are in a script execution, continue         // if we are in a script execution, continue
         if (ScriptRunning)         if (StartAllServices)
                 doNextScriptStep();                 doNextStartAllServicesStep();
 } }
  
 static void cbServiceConnection (CMessage& msgin, TSockId from, CCallbackNetBase &netbase) static void cbServiceConnection (CMessage& msgin, TSockId from, CCallbackNetBase &netbase)
 { {
 /*      CAdminExecutorService *aes = (CAdminExecutorService*) from->appId();         CAdminExecutorService *aes = (CAdminExecutorService*) from->appId();
  
         uint32 sid;         uint32 sid;
         msgin.serial (sid);         msgin.serial (sid);
  
         nlinfo ("*:%d:%d connected", aes->Id, sid);         nlinfo ("*:%d:%d connected", aes->Id, sid);
  
         aes->Services.push_back (CService(sid));         // don't do anything. we have to wait identification to add it in out lists
  
  /*
          aes->Services.push_back (CService(sid));
  */
         // broadcast the message to all admin client         // broadcast the message to all admin client
         CMessage msgout (CNetManager::getSIDA ("AS"), "SC");         CMessage msgout (CNetManager::getSIDA ("AS"), "SC");
         msgout.serial (aes->Id, sid);         msgout.serial (aes->Id, sid);
         CNetManager::send ("AS", msgout, 0);         CNetManager::send ("AS", msgout, 0);
 */} }
  
 static void cbServiceDisconnection (CMessage& msgin, TSockId from, CCallbackNetBase &netbase) static void cbServiceDisconnection (CMessage& msgin, TSockId from, CCallbackNetBase &netbase)
 { {
Line 384 
Line 447 
         msgout.serial (aes->Id, (*sit).Id);         msgout.serial (aes->Id, (*sit).Id);
         CNetManager::send ("AS", msgout, 0);         CNetManager::send ("AS", msgout, 0);
  
          if ((*sit).InConfig)
          {
                  (*sit).Ready = (*sit).Connected = false;
                  (*sit).Id = 0xFFFFFFFF;
                  (*sit).ShortName = (*sit).LongName = "";
          }
          else
          {
                  // erase only if it's not a service in the config
         aes->Services.erase (sit);         aes->Services.erase (sit);
 } }
  }
  
 // i'm connected to a new admin executor service // i'm connected to a new admin executor service
 void cbAESConnection (const string &serviceName, TSockId from, void *arg) void cbAESConnection (const string &serviceName, TSockId from, void *arg)
Line 420 
Line 493 
         CAdminExecutorService *aes = (CAdminExecutorService*) from->appId();         CAdminExecutorService *aes = (CAdminExecutorService*) from->appId();
  
         aes->Connected = false;         aes->Connected = false;
  
          SIT sit;
          for (sit = aes->Services.begin(); sit != aes->Services.end(); sit++)
          {
                  (*sit).Id = 0xFFFFFFFF;
                  (*sit).ShortName = (*sit).LongName = "";
                  (*sit).Ready = (*sit).Connected = false;
          }
  
         nlinfo ("*:%d:* disconnected", aes->Id);         nlinfo ("*:%d:* disconnected", aes->Id);
 /*       /*      
         // broadcast the message to all admin client that an admin exec is disconnected         // broadcast the message to all admin client that an admin exec is disconnected
Line 521 
Line 603 
                 {                 {
                         // send info about services of the AES                         // send info about services of the AES
                                                  
                         msgout.serial ((*sit).Id, (*sit).ServiceAlias, (*sit).ShortName, (*sit).LongName);                         msgout.serial ((*sit).Id, (*sit).AliasName, (*sit).ShortName, (*sit).LongName);
                         msgout.serial ((*sit).Ready, (*sit).Connected, (*sit).InConfig);                         msgout.serial ((*sit).Ready, (*sit).Connected, (*sit).InConfig);
                 }                 }
         }         }
Line 541 
Line 623 
 } }
  
  
 static void cbExecuteScript (CMessage& msgin, TSockId from, CCallbackNetBase &netbase) 
 { 
         string script; 
         msgin.serial (script); 
         initScript (script); 
 } 
  
  
 static void cbExecuteSystemCommand (CMessage& msgin, TSockId from, CCallbackNetBase &netbase) static void cbExecuteSystemCommand (CMessage& msgin, TSockId from, CCallbackNetBase &netbase)
 { {
         string command;         string command;
Line 574 
Line 648 
  
 static void cbStartService (CMessage& msgin, TSockId from, CCallbackNetBase &netbase) static void cbStartService (CMessage& msgin, TSockId from, CCallbackNetBase &netbase)
 { {
         string serviceName;         string serviceAlias;
         uint32 aesid;         uint32 aesid;
         msgin.serial (aesid);         msgin.serial (aesid);
         msgin.serial (serviceName);         msgin.serial (serviceAlias);
  
         AESIT aesit = findAdminExecutorService (aesid, false);         AESIT aesit = findAdminExecutorService (aesid, false);
         if (aesit == AdminExecutorServices.end())         if (aesit == AdminExecutorServices.end())
Line 590 
Line 664 
         // send the resquest to the AES         // send the resquest to the AES
  
         CMessage msgout (CNetManager::getSIDA((*aesit).ServerAlias), "STARTS");         CMessage msgout (CNetManager::getSIDA((*aesit).ServerAlias), "STARTS");
         msgout.serial (serviceName);         msgout.serial (serviceAlias);
         CNetManager::send ((*aesit).ServerAlias, msgout);         CNetManager::send ((*aesit).ServerAlias, msgout);
 } }
  
Line 655 
Line 729 
         CNetManager::send ((*aesit).ServerAlias, msgout);         CNetManager::send ((*aesit).ServerAlias, msgout);
 } }
  
  static void cbStartAllServices (CMessage& msgin, TSockId from, CCallbackNetBase &netbase)
  {
          initStartAllServices ();
  }
  
  static void cbStopAllServices (CMessage& msgin, TSockId from, CCallbackNetBase &netbase)
  {
          for (AESIT aesit = AdminExecutorServices.begin(); aesit != AdminExecutorServices.end(); aesit++)
          {
                  for (SIT sit = (*aesit).Services.begin(); sit != (*aesit).Services.end(); sit++)
                  {
                          if ((*sit).Connected)
                          {
                                  CMessage msgout (CNetManager::getSIDA((*aesit).ServerAlias), "STOPS");
                                  msgout.serial ((*sit).Id);
                                  CNetManager::send ((*aesit).ServerAlias, msgout);
                          }
                  }
          }
  }
  
 TCallbackItem ClientCallbackArray[] = TCallbackItem ClientCallbackArray[] =
 { {
         { "SYS", cbExecuteSystemCommand },         { "SYS", cbExecuteSystemCommand },
         { "EXEC", cbExecuteScript }, 
         { "STARTS", cbStartService },         { "STARTS", cbStartService },
         { "STOPS", cbStopService },         { "STOPS", cbStopService },
         { "EXEC_COMMAND", cbExecCommand },         { "EXEC_COMMAND", cbExecCommand },
          { "START_ALL_SERVICES", cbStartAllServices },
          { "STOP_ALL_SERVICES", cbStopAllServices },
 }; };
  
 //////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////
Line 678 
Line 773 
         /// Init the service, load the universal time.         /// Init the service, load the universal time.
         void                init ()         void                init ()
         {         {
                 DebugLog->addNegativeFilter ("L0:"); //              DebugLog->addNegativeFilter ("L0:");
                 DebugLog->addNegativeFilter ("L1:"); //              DebugLog->addNegativeFilter ("L1:");
                 DebugLog->addNegativeFilter ("L2:"); //              DebugLog->addNegativeFilter ("L2:");
                                  
                                  
                 CNetManager::setConnectionCallback ("AS", clientConnection, NULL);                 CNetManager::setConnectionCallback ("AS", clientConnection, NULL);
Line 722 
Line 817 
  
                         // add new AES in the list                         // add new AES in the list
                         CService s;                         CService s;
                         s.ServiceAlias = serviceAlias;                         s.AliasName = serviceAlias;
                         s.InConfig = true;                         s.InConfig = true;
                         (*aesit).Services.push_back (s);                         (*aesit).Services.push_back (s);
                 }                 }


Legend:
Removed from v.1.4 
changed lines
 Added in v.1.5