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

Diff for /code/nelns/admin_executor_service/admin_executor_service.cpp between version 1.3 and 1.4

version 1.3, 2001/05/03 13:19:13 version 1.4, 2001/05/10 08:20:06
Line 46 
Line 46 
  
 struct CService struct CService
 { {
         CService(TSockId s) : ServiceSockId(s), ServiceId(NextServiceId++) { }         CService(TSockId s) : SockId(s), Id(NextId++), Ready(false) { }
  
         TSockId        ServiceSockId;        // socket number to communicate with         TSockId        SockId;                        /// connection to the service
         uint32        ServiceId;                // id to identify it         uint32        Id;                                /// uint32 to identify the service
         string        ShortName;         string        ShortName;                /// name of the service in short format ("NS" for example)
         string        LongName;         string        LongName;                /// name of the service in long format ("naming_service")
          bool        Ready;                        /// true if the service is ready
  
 private: private:
          static        uint32 NextId;
         static        uint32 NextServiceId; 
 }; };
  
 uint32 CService::NextServiceId = 0; uint32 CService::NextId = 1;
  
 list<CService> Services; list<CService> Services;
 typedef list<CService>::iterator sit; typedef list<CService>::iterator SIT;
  
 sit find (TSockId sid) SIT find (TSockId sid)
 { {
         sit it;         SIT sit;
         for (it = Services.begin(); it != Services.end(); it++)         for (sit = Services.begin(); sit != Services.end(); sit++)
         {         {
                 if ((*it).ServiceSockId == sid) break;                 if ((*sit).SockId == sid) break;
         }         }
         return it;         return sit;
 } }
  
 sit find (uint32 sid) SIT findService (uint32 sid)
 { {
         sit it;         SIT sit;
         for (it = Services.begin(); it != Services.end(); it++)         for (sit = Services.begin(); sit != Services.end(); sit++)
         {         {
                 if ((*it).ServiceId == sid) break;                 if ((*sit).Id == sid) break;
         }         }
         return it;         return sit;
 } }
  
  
Line 197 
Line 197 
  
 static void cbServiceIdentification (CMessage& msgin, TSockId from, CCallbackNetBase &netbase) static void cbServiceIdentification (CMessage& msgin, TSockId from, CCallbackNetBase &netbase)
 { {
         CService *c = (CService*) from->appId();         CService *s = (CService*) from->appId();
  
         msgin.serial (c->ShortName);         msgin.serial (s->ShortName, s->LongName);
         msgin.serial (c->LongName); 
  
         nlinfo ("%s %s %s is identified", from->asString().c_str(), c->ShortName.c_str(), c->LongName.c_str());         nlinfo ("*:*:%d is identified to be '%s' '%s'", s->Id, s->ShortName.c_str(), s->LongName.c_str());
  
          // broadcast the message to the admin service
         CMessage msgout (CNetManager::getSIDA ("AESAS"), "SID");         CMessage msgout (CNetManager::getSIDA ("AESAS"), "SID");
         msgout.serial (c->ShortName);         msgout.serial (s->Id, s->ShortName, s->LongName);
         msgout.serial (c->LongName); 
         CNetManager::send ("AESAS", msgout);         CNetManager::send ("AESAS", msgout);
 } }
  
 static void cbServiceReady (CMessage& msgin, TSockId from, CCallbackNetBase &netbase) static void cbServiceReady (CMessage& msgin, TSockId from, CCallbackNetBase &netbase)
 { {
         CService *c = (CService*) from->appId();         CService *s = (CService*) from->appId();
  
         nlinfo ("%s %s %s is ready", from->asString().c_str(), c->ShortName.c_str(), c->LongName.c_str());         nlinfo ("*:*:%d is ready", s->Id);
          s->Ready = true;
  
          // broadcast the message to the admin service
         CMessage msgout (CNetManager::getSIDA ("AESAS"), "SR");         CMessage msgout (CNetManager::getSIDA ("AESAS"), "SR");
         msgout.serial (c->ShortName);         msgout.serial (s->Id);
         msgout.serial (c->LongName); 
         CNetManager::send ("AESAS", msgout);         CNetManager::send ("AESAS", msgout);
 } }
  
 void serviceConnection (const string &serviceName, TSockId from, void *arg) void serviceConnection (const string &serviceName, TSockId from, void *arg)
 { {
         Services.push_back (CService(from));         Services.push_back (CService(from));
         CService *c = &(Services.back());         CService *s = &(Services.back());
         from->setAppId ((uint64)c);         from->setAppId ((uint64)s);
  
         nlinfo ("%s is connected", from->asString().c_str());         nlinfo ("*:*:%d connected", s->Id);
                  
          // broadcast the message to the admin service
         CMessage msgout (CNetManager::getSIDA ("AESAS"), "SC");         CMessage msgout (CNetManager::getSIDA ("AESAS"), "SC");
          msgout.serial (s->Id);
         CNetManager::send ("AESAS", msgout);         CNetManager::send ("AESAS", msgout);
 } }
  
 void serviceDisconnection (const string &serviceName, TSockId from, void *arg) void serviceDisconnection (const string &serviceName, TSockId from, void *arg)
 { {
         CService *c = (CService*) from->appId();         CService *s = (CService*) from->appId();
  
         nlinfo ("%s %s %s is disconnected", from->asString().c_str(), c->ShortName.c_str(), c->LongName.c_str());         nlinfo ("*:*:%d disconnected", s->Id);
  
          // broadcast the message to the admin service
         CMessage msgout (CNetManager::getSIDA ("AESAS"), "SD");         CMessage msgout (CNetManager::getSIDA ("AESAS"), "SD");
         msgout.serial (c->ShortName);         msgout.serial (s->Id);
         msgout.serial (c->LongName); 
         CNetManager::send ("AESAS", msgout);         CNetManager::send ("AESAS", msgout);
  
          // remove the service from the list
          Services.erase (findService(s->Id));
 } }
  
  
Line 281 
Line 286 
  
 } }
  
  void cbASServiceConnection (const string &serviceName, TSockId from, void *arg)
  {
          // new admin service, send him all out info about services
  
          nlinfo ("AS %s is connected", from->asString().c_str());
          
          CMessage msgout (CNetManager::getSIDA ("AESAS"), "SL");
          uint32 nbs = (uint32)Services.size();
          msgout.serial (nbs);
          for (SIT sit = Services.begin(); sit != Services.end(); sit++)
          {
                  msgout.serial ((*sit).Id);
                  msgout.serial ((*sit).ShortName);
                  msgout.serial ((*sit).LongName);
                  msgout.serial ((*sit).Ready);
          }
          CNetManager::send ("AESAS", msgout, from);
  }
  
 TCallbackItem AESASCallbackArray[] = TCallbackItem AESASCallbackArray[] =
 { {
Line 305 
Line 328 
                 CNetManager::setDisconnectionCallback ("AES", serviceDisconnection, NULL);                 CNetManager::setDisconnectionCallback ("AES", serviceDisconnection, NULL);
  
                 // install the server for AS                 // install the server for AS
                  CNetManager::setConnectionCallback ("AESAS", cbASServiceConnection, NULL);
                 CNetManager::addServer ("AESAS", 49996);                 CNetManager::addServer ("AESAS", 49996);
                 CNetManager::addCallbackArray ("AESAS", AESASCallbackArray, sizeof(AESASCallbackArray)/sizeof(AESASCallbackArray[0]));                 CNetManager::addCallbackArray ("AESAS", AESASCallbackArray, sizeof(AESASCallbackArray)/sizeof(AESASCallbackArray[0]));
         }         }


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