version 1.5, 2001/05/31 16:44:54 |
version 1.6, 2001/06/07 16:19:05 |
| |
bool Ready; /// true if the service is ready | bool Ready; /// true if the service is ready |
bool Connected; /// true if the service is connected to the AES | bool Connected; /// true if the service is connected to the AES |
bool InConfig; /// true if the service is in the configuration | bool InConfig; /// true if the service is in the configuration |
| vector<string> Commands; |
| |
| void setValues (const CService &t) |
| { |
| // copy all except gtk stuffs |
| Id = t.Id; |
| AliasName = t.AliasName; |
| ShortName = t.ShortName; |
| LongName = t.LongName; |
| Ready = t.Ready; |
| Connected = t.Connected; |
| //InConfig = t.InConfig; never change the inconfig value |
| } |
}; | }; |
| |
typedef list<CService> TServices; | typedef list<CService> TServices; |
| |
{ | { |
for (AESIT aesit = AdminExecutorServices.begin(); aesit != AdminExecutorServices.end(); aesit++) | for (AESIT aesit = AdminExecutorServices.begin(); aesit != AdminExecutorServices.end(); aesit++) |
{ | { |
| nlinfo ("> Admin"); |
for (SIT sit = (*aesit).Services.begin(); sit != (*aesit).Services.end(); sit++) | for (SIT sit = (*aesit).Services.begin(); sit != (*aesit).Services.end(); sit++) |
{ | { |
nlinfo ("> %s %s %s %d %d", (*aesit).SockId->asString().c_str(), (*sit).ShortName.c_str(), (*sit).LongName.c_str(), (*aesit).Id, (*sit).Id); | nlinfo (" > '%s' '%s' '%s' '%s' %d %d", (*aesit).SockId->asString().c_str(), (*sit).AliasName.c_str(), (*sit).ShortName.c_str(), (*sit).LongName.c_str(), (*aesit).Id, (*sit).Id); |
} | } |
} | } |
} | } |
| |
| |
| // send a message to a client. if ok is 0 it s an error or it s a normal |
| void messageToClient (uint8 ok, string msg, TSockId from = NULL) |
| { |
| CMessage msgout (CNetManager::getSIDA ("AS"), "MESSAGE"); |
| msgout.serial (ok, msg); |
| CNetManager::send ("AS", msgout, from); |
| } |
| |
| |
//////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////// |
//////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////// |
/////////////////// SCRIPT MANAGER ///////////////////////////////////////////////////////////////////// | /////////////////// SCRIPT MANAGER ///////////////////////////////////////////////////////////////////// |
| |
if (StartAllServicesPos*2 >= (uint32)script.size()) | if (StartAllServicesPos*2 >= (uint32)script.size()) |
{ | { |
StartAllServices = false; | StartAllServices = false; |
| |
nlinfo("end of the script"); | nlinfo("end of the script"); |
// todo send that the script is finish to the admin | messageToClient (1, "Start All Service finnished correctly"); |
return; | return; |
} | } |
| |
| |
} | } |
catch(EBadSize &) | catch(EBadSize &) |
{ | { |
| messageToClient (1, "'Services' variable does not contains a good number of entries (must be a multiple of 2)"); |
nlwarning ("'Services' variable does not contains a good number of entries (must be a multiple of 2)"); | nlwarning ("'Services' variable does not contains a good number of entries (must be a multiple of 2)"); |
StartAllServices = false; | StartAllServices = false; |
return; | return; |
| |
AESIT aesit = findAdminExecutorService (serverAlias, false); | AESIT aesit = findAdminExecutorService (serverAlias, false); |
if (aesit == AdminExecutorServices.end()) | if (aesit == AdminExecutorServices.end()) |
{ | { |
StartAllServices = false; | messageToClient (1, "don't find the server"); |
nlwarning("don't find the server"); | nlwarning("don't find the server"); |
| StartAllServices = false; |
return; | return; |
} | } |
| |
| |
} | } |
catch(EUnknownVar&) | catch(EUnknownVar&) |
{ | { |
| messageToClient (1, "'Services' variable is not found"); |
nlwarning ("'Services' variable is not found"); | nlwarning ("'Services' variable is not found"); |
StartAllServices = false; | StartAllServices = false; |
return; | return; |
| |
{ | { |
if (StartAllServices) | if (StartAllServices) |
{ | { |
| messageToClient (1, "already running a script, reset it"); |
nlwarning("already running a script, reset it"); | nlwarning("already running a script, reset it"); |
StartAllServices = false; | StartAllServices = false; |
} | } |
| |
AESIT aesit = findAdminExecutorService (serverAlias, false); | AESIT aesit = findAdminExecutorService (serverAlias, false); |
if (aesit == AdminExecutorServices.end()) | if (aesit == AdminExecutorServices.end()) |
{ | { |
nlwarning("aes '%s' not running, can't run the script", serverAlias.c_str()); | messageToClient (1, "an aes is not running, can't run the script"); |
| nlwarning("aes '%s' isn't running, can't run the script", serverAlias.c_str()); |
return; | return; |
} | } |
} | } |
} | } |
catch(EConfigFile &) | catch(EConfigFile &) |
{ | { |
| messageToClient (1, "bad config file"); |
nlwarning ("bad config file"); | nlwarning ("bad config file"); |
return; | return; |
} | } |
| |
nlinfo("end of command result"); | nlinfo("end of command result"); |
} | } |
| |
| // get the service list from the admin exec and send the list to all admin client |
static void cbServiceList (CMessage& msgin, TSockId from, CCallbackNetBase &netbase) | static void cbServiceList (CMessage& msgin, TSockId from, CCallbackNetBase &netbase) |
{ | { |
/* // get the service list from the admin exec and send the list to all admin client | |
CAdminExecutorService *aes = (CAdminExecutorService*) from->appId(); | CAdminExecutorService *aes = (CAdminExecutorService*) from->appId(); |
aes->Services.clear(); | |
| |
CMessage msgout (CNetManager::getSIDA ("AS"), "SL"); | |
| |
uint32 nbaes = 1; | // |
msgout.serial (nbaes); | // Get the list of service from aes |
msgout.serial (aes->Id); | // |
| |
uint32 nbs; | uint32 nbs; |
msgin.serial (nbs); | msgin.serial (nbs); |
msgout.serial (nbs); | |
| |
for (uint32 i = 0; i < nbs; i++) | for (uint32 i = 0; i < nbs; i++) |
{ | { |
uint32 sid; | // find the service |
msgin.serial(sid); | CService s; |
| |
aes->Services.push_back (CService(sid)); | |
CService *s = &(aes->Services.back()); | |
| |
msgin.serial(s->ShortName, s->LongName, s->Ready); | msgin.serial (s.Id, s.AliasName, s.ShortName, s.LongName, s.Ready); |
| msgin.serialCont (s.Commands); |
| s.Connected = true; |
| |
msgout.serial (s->Id, s->ShortName, s->LongName, s->Ready); | if (!s.AliasName.empty()) |
| { |
| SIT sit = aes->findService (s.AliasName, false); |
| if (sit == aes->Services.end ()) |
| { |
| aes->Services.push_back (s); |
| } |
| else |
| { |
| nlassert ("the service already exists with alias, update it"); |
| (*sit).setValues (s); |
| } |
| } |
| else |
| { |
| SIT sit = aes->findService (s.Id, false); |
| if (sit == aes->Services.end ()) |
| { |
| aes->Services.push_back (s); |
| } |
| else |
| { |
| nlassert ("the service already exists with id, update it"); |
| (*sit).setValues (s); |
| } |
| } |
} | } |
CNetManager::send ("AS", msgout, 0); | |
| |
displayServices (); | displayServices (); |
*/} | |
| // |
| // Send the new list to all admin |
| // |
| |
| CMessage msgout (CNetManager::getSIDA ("AS"), "SERVICE_LIST"); |
| uint32 nbaes = 1; |
| msgout.serial (nbaes); |
| msgout.serial (aes->Id); |
| uint32 ss = aes->Services.size(); |
| msgout.serial (ss); |
| |
| for (SIT sit = aes->Services.begin(); sit != aes->Services.end(); sit++) |
| { |
| msgout.serial ((*sit).Id, (*sit).AliasName, (*sit).ShortName, (*sit).LongName); |
| msgout.serial ((*sit).Ready, (*sit).Connected, (*sit).InConfig); |
| msgout.serialCont ((*sit).Commands); |
| } |
| CNetManager::send ("AS", msgout, 0); |
| } |
| |
static void cbServiceAliasList (CMessage& msgin, TSockId from, CCallbackNetBase &netbase) | static void cbServiceAliasList (CMessage& msgin, TSockId from, CCallbackNetBase &netbase) |
{ | { |
| |
aes->ServiceAliasList.clear (); | aes->ServiceAliasList.clear (); |
msgin.serialCont (aes->ServiceAliasList); | msgin.serialCont (aes->ServiceAliasList); |
| |
| nlinfo("send SAL to admin callback from aes"); |
| |
CMessage msgout (CNetManager::getSIDA ("AS"), "SAL"); | CMessage msgout (CNetManager::getSIDA ("AS"), "SAL"); |
msgout.serial (aes->Id); | msgout.serial (aes->Id); |
msgout.serialCont (aes->ServiceAliasList); | msgout.serialCont (aes->ServiceAliasList); |
| |
if (sit == aes->Services.end ()) | if (sit == aes->Services.end ()) |
{ | { |
// normal case for unknown services | // normal case for unknown services |
nlwarning ("new service with alias (%s) but not in my list", alias.c_str()); | nlwarning ("new service without alias and not in my list, add it"); |
} | } |
else | else |
{ | { |
nlwarning ("new service without alias is already in my list with id %d", sid); | nlwarning ("new service without alias is already in my list with id %d, add it", sid); |
} | } |
aes->Services.push_back (CService ()); | aes->Services.push_back (CService ()); |
sit = aes->Services.end(); | sit = aes->Services.end(); |
| |
(*sit).AliasName = alias; | (*sit).AliasName = alias; |
(*sit).Connected = true; | (*sit).Connected = true; |
msgin.serial ((*sit).ShortName, (*sit).LongName); | msgin.serial ((*sit).ShortName, (*sit).LongName); |
| msgin.serialCont ((*sit).Commands); |
| |
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()); | 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).AliasName, (*sit).ShortName, (*sit).LongName); | msgout.serial (aes->Id, sid, (*sit).AliasName, (*sit).ShortName, (*sit).LongName); |
| msgout.serialCont ((*sit).Commands); |
| |
CNetManager::send ("AS", msgout, 0); | CNetManager::send ("AS", msgout, 0); |
} | } |
| |
| |
// erase only if it's not a service in the config | // erase only if it's not a service in the config |
aes->Services.erase (sit); | aes->Services.erase (sit); |
} | } |
| |
| displayServices (); |
} | } |
| |
// i'm connected to a new admin executor service | // i'm connected to a new admin executor service |
| |
aes->Connected = false; | aes->Connected = false; |
| |
SIT sit; | SIT sit; |
for (sit = aes->Services.begin(); sit != aes->Services.end(); sit++) | for (sit = aes->Services.begin(); sit != aes->Services.end();) |
| { |
| // keep only inconfig services |
| if ((*sit).InConfig) |
{ | { |
(*sit).Id = 0xFFFFFFFF; | (*sit).Id = 0xFFFFFFFF; |
(*sit).ShortName = (*sit).LongName = ""; | (*sit).ShortName = (*sit).LongName = ""; |
(*sit).Ready = (*sit).Connected = false; | (*sit).Ready = (*sit).Connected = false; |
| sit++; |
| } |
| else |
| { |
| // erase only if it's not a service in the config |
| sit = aes->Services.erase (sit); |
| } |
} | } |
| |
nlinfo ("*:%d:* disconnected", aes->Id); | nlinfo ("*:%d:* disconnected", aes->Id); |
| |
CNetManager::send ("AS", msgout, 0); | CNetManager::send ("AS", msgout, 0); |
*/ | */ |
| |
| displayServices (); |
| |
// broadcast the new state of this AES | // broadcast the new state of this AES |
CMessage msgout (CNetManager::getSIDA ("AS"), "AES_LIST"); | CMessage msgout (CNetManager::getSIDA ("AS"), "AES_LIST"); |
uint32 nbaes = 1; | uint32 nbaes = 1; |
| |
//////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////// |
//////////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////////// |
| |
void errorMessage(string message, TSockId from, CCallbackNetBase &netbase) | |
{ | |
CMessage msgout (netbase.getSIDA (), "ERR"); | |
msgout.serial (message); | |
netbase.send (msgout, from); | |
} | |
| |
// | // |
// A new admin client is connected. | // A new admin client is connected. |
// | // |
| |
| |
msgout.serial ((*sit).Id, (*sit).AliasName, (*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); |
| msgout.serialCont ((*sit).Commands); |
} | } |
} | } |
CNetManager::send ("AS", msgout, from); | CNetManager::send ("AS", msgout, from); |
| |
| displayServices (); |
| |
// | // |
// send service alias list | // send service alias list |
// | // |
| |
| nlinfo("send SAL to admin startup"); |
| |
for (aesit = AdminExecutorServices.begin(); aesit != AdminExecutorServices.end(); aesit++) | for (aesit = AdminExecutorServices.begin(); aesit != AdminExecutorServices.end(); aesit++) |
{ | { |
CMessage msgout2 (CNetManager::getSIDA ("AS"), "SAL"); | CMessage msgout2 (CNetManager::getSIDA ("AS"), "SAL"); |
| |
if (aesit == AdminExecutorServices.end()) | if (aesit == AdminExecutorServices.end()) |
{ | { |
// don't find the aes, send an error message | // don't find the aes, send an error message |
errorMessage ("couldn't execute command, as didn't find the aes", from, netbase); | messageToClient (0, "couldn't execute command, as didn't find the aes", from); |
return; | return; |
} | } |
| |
| |
if (aesit == AdminExecutorServices.end()) | if (aesit == AdminExecutorServices.end()) |
{ | { |
// don't find the aes, send an error message | // don't find the aes, send an error message |
errorMessage ("couldn't start service, as didn't find the aes", from, netbase); | messageToClient (0, "couldn't start service, as didn't find the aes", from); |
return; | return; |
} | } |
| |
| |
AESIT aesit = findAdminExecutorService (aesid, false); | AESIT aesit = findAdminExecutorService (aesid, false); |
if (aesit == AdminExecutorServices.end()) | if (aesit == AdminExecutorServices.end()) |
{ | { |
errorMessage ("couldn't stop service, as didn't find the aes", from, netbase); | messageToClient (0, "couldn't stop service, as didn't find the aes", from); |
// don't find the aes, send an error message | // don't find the aes, send an error message |
return; | return; |
} | } |
| |
if (sit == (*aesit).Services.end()) | if (sit == (*aesit).Services.end()) |
{ | { |
// don't find the s, send an error message | // don't find the s, send an error message |
errorMessage ("couldn't stop service, as didn't find the service", from, netbase); | messageToClient (0, "couldn't stop service, as didn't find the service", from); |
return; | return; |
} | } |
| |
| |
AESIT aesit = findAdminExecutorService (aesid, false); | AESIT aesit = findAdminExecutorService (aesid, false); |
if (aesit == AdminExecutorServices.end()) | if (aesit == AdminExecutorServices.end()) |
{ | { |
errorMessage ("couldn't stop service, as didn't find the aes", from, netbase); | messageToClient (0, "couldn't stop service, as didn't find the aes", from); |
// don't find the aes, send an error message | // don't find the aes, send an error message |
return; | return; |
} | } |
| |
if (sit == (*aesit).Services.end()) | if (sit == (*aesit).Services.end()) |
{ | { |
// don't find the s, send an error message | // don't find the s, send an error message |
errorMessage ("couldn't stop service, as didn't find the service", from, netbase); | messageToClient (0, "couldn't stop service, as didn't find the service", from); |
return; | return; |
} | } |
| |
| |
s.InConfig = true; | s.InConfig = true; |
(*aesit).Services.push_back (s); | (*aesit).Services.push_back (s); |
} | } |
| displayServices (); |
} | } |
| |
bool update () | bool update () |