Changeset 209 for Evidence/Evidence.cc


Ignore:
Timestamp:
05/19/10 09:08:40 (14 years ago)
Author:
ogrimm
Message:
Service histories now available via DimRpc from DColl
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Evidence/Evidence.cc

    r199 r209  
    3838  // Initialize
    3939  Status = NULL;
     40  StdOutText = NULL;
    4041  ExitRequest = false;
    4142  ThisServer = this;
     
    6061 
    6162  Status = new DimService((ServerName+"/Status").c_str(), (char *) "C", InitMsg, strlen(InitMsg)+1);
     63  StdOut = new DimService((ServerName+"/Textout").c_str(), (char *) "");
    6264
    6365  start(Name);
     
    7476  }
    7577  delete ModifyInfo;
     78 
     79  delete Status;
     80  delete StdOut;
    7681}
    7782
     
    126131  // Terminate if message type is fatal
    127132  if (Severity == FATAL) exit(EXIT_FAILURE);
     133}
     134
     135// Set text of StdOut service
     136void EvidenceServer::SetStdOut(char *Text) {
     137
     138  // Copy text to permanent buffer
     139  char *Tmp = new char[strlen(Text)+1];
     140  strcpy(Tmp, Text);
     141  StdOut->updateService(Tmp);
     142
     143  // Delete old buffer and save new buffer pointer
     144  delete[] StdOutText;
     145  StdOutText = Tmp;   
    128146}
    129147
     
    148166        break;
    149167  }
    150  
     168
    151169  // Make configuration request
    152   DimRpcInfo Config((char *) "ConfigRequest", (char *) "");
     170  DimRpcInfo Config((char *) "ConfigRequest", NO_LINK);
    153171  Config.setData((char *) (ServerName + " " + Item).c_str());
    154172  char *Result = Config.getString();
    155  
     173
    156174  // Terminate if not successful
     175  if (!EvidenceServer::ServiceOK(&Config)) {
     176    State(FATAL, "Configuration server unreachable, can't get '%s'", Item.c_str());
     177  }
     178
    157179  if (strlen(Result) == 0) {
    158180    if (Default == NULL) State(FATAL, "Missing configuration data '%s'", Item.c_str());
     
    172194  strcpy(ConfigList[ItemNo].Value, Result);
    173195  ConfigList[ItemNo].Time = ModifyInfo->LastModifyTime;
    174    
     196
    175197  // Return address to configuration value 
    176198  return ConfigList[ItemNo].Value;
     
    314336  return !((Item->getSize() == strlen(NO_LINK)+1) && 
    315337          (memcmp(Item->getData(), NO_LINK, Item->getSize()) == 0));
    316 
    317 }
    318 
     338}
     339
     340bool EvidenceServer::ServiceOK(DimRpcInfo *Item) {
     341
     342  return !((Item->getSize() == strlen(NO_LINK)+1) && 
     343          (memcmp(Item->getData(), NO_LINK, Item->getSize()) == 0));
     344}
    319345
    320346///////////////////////////
     
    333359
    334360// Constructor
    335 EvidenceHistory::EvidenceHistory(std::string Name, int Delay):
    336         Name(Name+".hist"),
    337         Delay(Delay) {
     361EvidenceHistory::EvidenceHistory(std::string Name):     Name(Name) {
    338362
    339363  Buffer = NULL;
    340   LastUpdate = 0;
    341364}
    342365
     
    350373bool EvidenceHistory::GetHistory() {
    351374
    352   // Check if last buffer update less than minimum delay in the past
    353   if ((Buffer != NULL) && (time(NULL)-LastUpdate < Delay)) {
    354         Offset = *(int *) Buffer;
    355         return true;
    356   }
    357   LastUpdate = time(NULL);
    358  
    359   // Check if service available
    360   DimCurrentInfo Info(Name.c_str(), NO_LINK);
    361   if (((Info.getSize() == strlen(NO_LINK)+1) && 
    362           (memcmp(Info.getData(), NO_LINK, Info.getSize()) == 0))) return false;
     375  DimRpcInfo R((char *) "ServiceHistory", NO_LINK);
     376  R.setData((char *) Name.c_str());
     377  if (!EvidenceServer::ServiceOK(&R)) return false;
    363378
    364379  delete[] Buffer;
    365   BufferSize = Info.getSize();
     380  BufferSize = R.getSize();
    366381  Buffer = new char [BufferSize];
    367382
    368   memcpy(Buffer, Info.getData(), BufferSize);
     383  memcpy(Buffer, R.getData(), BufferSize);
    369384  Offset = *(int *) Buffer;
    370385 
Note: See TracChangeset for help on using the changeset viewer.