Changeset 154 for Evidence


Ignore:
Timestamp:
01/29/10 14:27:34 (15 years ago)
Author:
ogrimm
Message:
Updates to status service
Location:
Evidence
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • Evidence/Alarm.cc

    r152 r154  
    112112                strcmp(getInfo()->getString(), NO_LINK)==0) State[i] = 4;
    113113        else {
    114           State[i] = *(getInfo()->getString()+getInfo()->getSize());
     114          State[i] = *(getInfo()->getString()+getInfo()->getSize()-1);
    115115
     116  printf("*** String length: %d  Message length: %d    Last number: %d\n",strlen(getInfo()->getString()),getInfo()->getSize(),State[i]);
    116117          // Print message
    117118          time_t RawTime = getInfo()->getTimestamp();
     
    156157
    157158  // Check periodically if servers are up
    158   while(!EvidenceServer::ExitRequest) {
     159  while(!Alarm.ExitRequest) {
    159160    for (int i=0; i<Alarm.NumServers; i++) {
    160161      Exists = false;
  • Evidence/Config.cc

    r151 r154  
    158158          Notify = -1;
    159159  }
    160 
     160 
    161161  // Sleep until file changes or signal caught
    162   while (!EvidenceServer::ExitRequest) {
     162  while (!Config.ExitRequest) {
    163163    if (Notify != -1) {
    164164          read(Notify, &Event, sizeof(Event));
  • Evidence/Edd/Edd.cc

    r152 r154  
    6969    // If this is a status indicator, adapt background colour
    7070    if (Data.size() == Text.size()+2) {
    71       switch (Data[Text.size() + 2]) {
     71      switch (Data[Text.size() + 1]) {
    7272        case 0:  Pal.setColor(QPalette::Base, Qt::white); break;
    73         case 1:  Pal.setColor(QPalette::Base, Qt::cyan); break;
     73        case 1:  Pal.setColor(QPalette::Base, Qt::yellow); break;
    7474        case 2:  Pal.setColor(QPalette::Base, Qt::red); break;
    7575        case 3:  Pal.setColor(QPalette::Base, Qt::red); break;
     
    623623  MainLayout->addWidget(Textout, 1, 0, 1, 2);
    624624
     625  QFrame *Val = new QFrame();
     626  Val->setFrameStyle(QFrame::HLine);
     627  Val->setLineWidth(10);
     628  //Value->setMaximumWidth(200);
     629  MainLayout->addWidget(Val, 2, 0, 2, 1);     
     630
    625631  Value = new Edd_Indicator("DColl/Status");
    626632  Value->setMaximumWidth(200);
     
    702708  // Tab widget
    703709  TabWidget = new QTabWidget(Central);
    704   TabWidget->addTab(MainWidget, "&Main");
    705710  TabWidget->addTab(BiasWidget, "&Bias");
    706711  TabWidget->addTab(EnvironmentWidget, "&Environment");
     712  TabWidget->addTab(MainWidget, "Evidence");
    707713
    708714  // Menu bar
  • Evidence/Evidence.cc

    r152 r154  
    2525#include "Evidence.h"
    2626
    27 bool EvidenceServer::ExitRequest = false;
    28 string __StatusName;
     27EvidenceServer *ThisServer;
    2928
    3029// Constructor starts server with given name
     
    3332  // Initialize
    3433  Status = NULL;
    35   ConfigList = NULL;
    36   ConfigNum = 0;
    37   __StatusName = string(Name) + "/Status";
     34  ExitRequest = false;
     35  ThisServer = this;
    3836 
    3937  // Catch some signals
     
    4745 
    4846  // Start server
    49   Status = new DimService(__StatusName.c_str(), (char *) "Server started");
     47  static char Init[] = "Server started";
     48  Status = new DimService((string(Name) + "/Status").c_str(), (char *) "C", Init, sizeof(Init));
    5049
    5150  start(Name);
    5251  addExitHandler(this);
     52
    5353}
    5454
     
    5656EvidenceServer::~EvidenceServer() {
    5757
    58   for (unsigned int i=0; i<ConfigNum; i++) {
     58  for (unsigned int i=0; i<ConfigList.size(); i++) {
    5959        delete[] ConfigList[i].Name;
    6060        delete[] ConfigList[i].Value;
    6161  }
    62   free(ConfigList);
    6362}
    6463
     
    9392  va_end(ArgumentPointer);
    9493
    95   snprintf(TBuf, sizeof(TBuf), "%s (%s): %s", __StatusName.c_str(), StateString[Severity], Tmp); // Normal string
    96   snprintf(SBuf, sizeof(SBuf), "%s*%c", Tmp, (char) Severity);
    97   *(strrchr(SBuf, '*')) = '\0';  // String with severity encoding
     94  // Create normal string
     95  snprintf(TBuf, sizeof(TBuf), "%s (%s): %s", Status->getName(), StateString[Severity], Tmp);
     96
     97  // Create string with severity encoding
     98  snprintf(SBuf, sizeof(SBuf), "%s**", Tmp);
     99  SBuf[strlen(SBuf)-2] = '\0';
     100  SBuf[strlen(SBuf)+1] = Severity;
     101
    98102  if (Tmp != ErrorString) free(Tmp);
    99103 
     
    120124 
    121125  // Check if configuration request already in list
    122   for (unsigned int i=0; i<ConfigNum; i++) {
     126  for (unsigned int i=0; i<ConfigList.size(); i++) {
    123127    if (strcmp(ConfigList[i].Name, Item) == 0) {
    124128          // Return original value if still up to date
     
    144148  }
    145149
    146   // Enlarge memory to hold new pointer if necessary
     150  // Enlarge list if necessary
    147151  if (ItemNo == -1) {
    148         void *N = realloc(ConfigList, sizeof(struct ConfigItem)*(++ConfigNum));
    149         if (N == NULL) {
    150           State(WARN, "Could not realloc() memory for configuration, will lose memory (%s)", strerror(errno));
    151           ConfigNum--; 
    152         }
    153         else ConfigList = (struct ConfigItem *) N;
    154        
    155         ItemNo = ConfigNum-1;
    156   }
    157  
    158   // Allocate memory for strings, and copy data to this memory
     152    struct ConfigItem New;
     153    ConfigList.push_back(New);
     154        ItemNo = ConfigList.size()-1;
     155  }
     156
     157  // Create new entry in item list, allocate memory and copy data to this memory
    159158  ConfigList[ItemNo].Value = new char [strlen(Result)+1];
    160159  ConfigList[ItemNo].Name = new char [strlen(Item)+1];
    161160  strcpy(ConfigList[ItemNo].Name, Item);
    162161  strcpy(ConfigList[ItemNo].Value, Result);
    163 
    164162  ConfigList[ItemNo].Time = Time;
    165  
     163   
    166164  // Return address to configuration value 
    167165  return ConfigList[ItemNo].Value;
     
    174172void EvidenceServer::SignalHandler(int) {
    175173
    176   EvidenceServer::ExitRequest = true;
     174  ThisServer->ExitRequest = true;
    177175}
    178176
     
    180178void EvidenceServer::Terminate() {
    181179
    182   string Msg = __StatusName + ": Caught unhandled exception";
     180  string Msg = string(ThisServer->Status->getName()) + ": Caught unhandled exception";
     181
    183182  printf("%s\n", Msg.c_str());
    184183  DimClient::sendCommand("DColl/Log", Msg.c_str());
     
    187186}
    188187
     188
    189189// Translates DIMInfo to string (memory has to be freed by caller)
    190190// No DIM structures are supported (only a single number or string is converted)
     191// For string conversion, a terminating \0 is enforced.
    191192char *EvidenceServer::ToString(DimInfo *Item) {
    192193
     
    198199  switch (*(Item->getFormat())) {
    199200    case 'I':  R = asprintf(&Text, "%d", Item->getInt());   break;
    200     case 'C':  R = asprintf(&Text, "%s", Item->getString());   break;
    201201    case 'S':  R = asprintf(&Text, "%hd", Item->getShort());   break;
    202202    case 'F':  R = asprintf(&Text, "%.5f", Item->getFloat());   break;
    203203    case 'D':  R = asprintf(&Text, "%.5f", Item->getDouble());   break;
    204204    case 'X':  R = asprintf(&Text, "%lld", Item->getLonglong());   break;
     205    case 'C':  *(Item->getString() + Item->getSize()) = '\0';
     206                           R = asprintf(&Text, "%s", Item->getString());
     207                           break;
    205208    default: return NULL;
    206209  }
  • Evidence/Evidence.h

    r152 r154  
    77#include <errno.h>
    88#include <exception>
     9#include <vector>
    910
    1011#include "dis.hxx"
     
    3031          char *Value;
    3132          int Time;
    32         } *ConfigList;
    33         unsigned int ConfigNum;
     33        };
     34        vector<struct ConfigItem> ConfigList;
    3435
    3536    DimService *Status;
     
    5051        static char* ToString(DimInfo *);
    5152
    52     static bool ExitRequest;
     53    bool ExitRequest;
    5354};
    5455
Note: See TracChangeset for help on using the changeset viewer.