version 1.4, 2001/05/18 16:51:33 |
version 1.5, 2001/05/31 16:44:54 |
| |
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 |
| |
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; |
}; | }; |
| |
//////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////// |
//////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////// |
| |
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; |
| |
| |
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) |
{ | { |
| |
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; |
} | } |
} | } |
| |
return; | return; |
} | } |
| |
ScriptName = scriptName; | StartAllServicesPos = 0; |
ScriptPos = 0; | StartAllServices = true; |
ScriptRunning = true; | |
| |
doNextScriptStep(); | doNextStartAllServicesStep(); |
} | } |
| |
| |
| |
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); |
} | } |
| |
| |
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) |
{ | { |
| |
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) |
| |
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 |
| |
{ | { |
// 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); |
} | } |
} | } |
| |
} | } |
| |
| |
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; |
| |
| |
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()) |
| |
// 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); |
} | } |
| |
| |
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 }, |
}; | }; |
| |
//////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////// |
| |
/// 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); |
| |
| |
// 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); |
} | } |