Index: Evidence/Evidence.cc
===================================================================
--- Evidence/Evidence.cc	(revision 231)
+++ Evidence/Evidence.cc	(revision 232)
@@ -17,5 +17,5 @@
     These signals will then cause pause() to return which can be used
 	by the application to terminate gracefully.
-  - The static method ToString() converts the contents of a DIMInfo service into text
+  - The static method ToString() converts the contents of a DIM service into text
   - A terminate-handler is installed for catching unhandled C++ exceptions.
 
@@ -27,10 +27,7 @@
 using namespace std;
 
-EvidenceServer *ThisServer;
-
 //
 // Internal configuration class of EvidenceServer
 //
-// Data that might be accessed by two threads are protected by mutex
 
 // Constructor
@@ -38,12 +35,6 @@
 
   // Initialise
-  int Ret;
-  if ((Ret = pthread_mutex_init(&Mutex, NULL)) != 0) {
-    ThisServer->Message(ThisServer->FATAL, "pthread_mutex_init() failed in Config constructor (%s)", strerror(Ret));
-  }
   CurrentItem = string();
   ConfigTimeStamp = 0;
-  
-  // Signal delivered to this thread if configuration file changes 
   ThreadID = pthread_self();
 
@@ -56,9 +47,4 @@
   
   delete Service;
-
-  int Ret;
-  if ((Ret = pthread_mutex_destroy(&Mutex)) != 0) {
-	ThisServer->Message(ThisServer->ERROR, "pthread_mutex_destroy() failed in Config destructor (%s)", strerror(Ret));
-  }
 }
 
@@ -66,10 +52,10 @@
 void EvidenceServer::Config::infoHandler() {
 
-  Lock();
+  This->Lock();
   ConfigTimeStamp = getInfo()->getInt();
-  Unlock();
-
-  if (pthread_kill(ThreadID, ThisServer->ConfigSignal) != 0) {
-	ThisServer->Message(ThisServer->WARN, "Could not send signal to main thread");
+  This->Unlock();
+
+  if (pthread_kill(ThreadID, This->ConfigSignal) != 0) {
+	This->Message(WARN, "Could not send signal to main thread");
   }
 }
@@ -78,5 +64,5 @@
 void EvidenceServer::Config::rpcInfoHandler(){
 
-  Lock();
+  This->Lock();
   // Update map
   List[CurrentItem].Value = string(getString(), getSize()-1);
@@ -84,5 +70,5 @@
   // Clear to allow new rpc call
   CurrentItem.clear(); 
-  Unlock();
+  This->Unlock();
 }
 
@@ -93,7 +79,7 @@
 
   // If up-to-date data in configuration list available, return this
-  Lock();
+  This->Lock();
   if ((List.count(Item) > 0) && (List[Item].Time >= ConfigTimeStamp)) Result = List[Item].Value;
-  Unlock();
+  This->Unlock();
   if (!Result.empty()) return Result;
 
@@ -106,5 +92,5 @@
 	if (!EvidenceServer::ServiceOK(&Config)) {
       if (Default.empty()) {
-		ThisServer->Message(ThisServer->FATAL, "Configuration server unreachable, can't retrieve '%s'", Item.c_str());
+		This->Message(FATAL, "Configuration server unreachable, can't retrieve '%s'", Item.c_str());
 	  }
 	  else Result = Default;
@@ -117,14 +103,14 @@
 	// Update configuration map	
 	if (!Result.empty()) {
-	  Lock();
+	  This->Lock();
 	  List[Item].Value = Result;
 	  List[Item].Time = ConfigTimeStamp;
-	  Unlock();
+	  This->Unlock();
 	}	
   }
 
-  // Non-blocking configuration request fro other threads
+  // Non-blocking configuration request from other threads
   if (pthread_self() != ThreadID) {
- 	Lock();
+ 	This->Lock();
 	if (List.count(Item) > 0) {
 	  // New request possible only when answer to previous request received
@@ -136,45 +122,9 @@
 	  // Return current value
 	  Result = List[Item].Value;
-	  Unlock();
+	  This->Unlock();
 	}
   }
 
   return Result;
-}
-
-// Locking and unlocking for list access
-// Signal blocked before locking to avaoid dead-lock by calling GetConfig() from ConfigChanged().
-void EvidenceServer::Config::Lock() {
-
-  int Ret = 0;
-  sigset_t Set;
-
-  if (ThisServer->ConfigSignal != 0) {
-	Ret += abs(sigemptyset(&Set));
-	Ret += abs(sigaddset(&Set, ThisServer->ConfigSignal));
-	Ret += abs(pthread_sigmask(SIG_BLOCK, &Set, NULL));
-  }
-  Ret += abs(pthread_mutex_lock(&Mutex));
-  
-  if (Ret != 0) {
-	ThisServer->Message(ThisServer->FATAL, "Thread related call failed in Config::Lock()");
-  }
-}
-
-void EvidenceServer::Config::Unlock() {
-
-  int Ret = 0;
-  sigset_t Set;
-
-  Ret += abs(pthread_mutex_unlock(&Mutex));
-  if (ThisServer->ConfigSignal != 0) {
-	Ret += abs(sigemptyset(&Set));
-	Ret += abs(sigaddset(&Set, ThisServer->ConfigSignal));
-	Ret += abs(pthread_sigmask(SIG_UNBLOCK, &Set, NULL));
-  }
-
-  if (Ret != 0) {
-	ThisServer->Message(ThisServer->FATAL, "Thread related call failed in Config::Unlock()");
-  }
 }
 
@@ -185,4 +135,5 @@
 
 int EvidenceServer::ConfigSignal = 0;
+EvidenceServer *EvidenceServer::This = NULL;
 
 // Constructor starts server with given name
@@ -193,5 +144,16 @@
   MessageData = NULL;
   ExitRequest = false;
-  ThisServer = this;
+  This = this;
+
+  // Initialise mutex
+  int Ret;
+  pthread_mutexattr_t Attr;
+
+  if ((Ret = pthread_mutexattr_settype(&Attr, PTHREAD_MUTEX_ERRORCHECK)) != 0) {
+    Message(FATAL, "pthread_mutex_settype() failed (%s)", strerror(Ret));
+  }
+  if ((Ret = pthread_mutex_init(&Mutex, &Attr)) != 0) {
+    Message(FATAL, "pthread_mutex_init() failed (%s)", strerror(Ret));
+  }
 
   // Catch some signals
@@ -225,5 +187,10 @@
   delete ConfClass;
   delete MessageService;
-  delete MessageData;
+  delete[] MessageData;
+  
+  int Ret;
+  if ((Ret = pthread_mutex_destroy(&Mutex)) != 0) {
+	Message(ERROR, "pthread_mutex_destroy() failed (%s)", strerror(Ret));
+  }
 }
 
@@ -270,5 +237,5 @@
 	MessageService->updateService(NewMsg, sizeof(struct Message)+strlen(NewMsg->Text)+1);
   }
-  delete MessageData;
+  delete[] MessageData;
   MessageData = NewMsg;
 
@@ -311,5 +278,6 @@
 }
 
-// Signal emitted when configuraton file changes, signal handler calls ConfigChanged()
+
+// Set signal emitted when configuraton file changes, signal handler calls ConfigChanged()
 void EvidenceServer::ActivateSignal(int Signal) {
 
@@ -323,4 +291,43 @@
 
 
+// Locking and unlocking for list access
+// Signal blocked before locking to avoid dead-lock by calling GetConfig() from ConfigChanged().
+void EvidenceServer::Lock() {
+
+  int Ret;
+  sigset_t Set;
+
+  if (ConfigSignal != 0) {
+	Ret = abs(sigemptyset(&Set));
+	Ret += abs(sigaddset(&Set, ConfigSignal));
+	Ret += abs(pthread_sigmask(SIG_BLOCK, &Set, NULL));
+
+	if (Ret != 0) Message(FATAL, "Signal masking failed in Lock()");
+  }
+
+  if ((Ret = pthread_mutex_lock(&Mutex)) != 0) {
+	Message(FATAL, "pthread_mutex_lock() failed in Lock() (%s)", strerror(Ret));
+  }
+}
+
+void EvidenceServer::Unlock() {
+
+  int Ret;
+  sigset_t Set;
+
+  if ((Ret = pthread_mutex_unlock(&Mutex)) != 0) {
+	Message(FATAL, "pthread_mutex_unlock() failed in Unlock() (%s)", strerror(Ret));
+  }
+  
+  if (ConfigSignal != 0) {
+	Ret = abs(sigemptyset(&Set));
+	Ret += abs(sigaddset(&Set, ConfigSignal));
+	Ret += abs(pthread_sigmask(SIG_UNBLOCK, &Set, NULL));
+
+	if (Ret != 0) Message(FATAL, "Signal unmasking failed in Unlock()");
+  }
+}
+
+
 // ====== Static methods ======
 
@@ -332,5 +339,5 @@
   // If signal indicates configuration change, invoke call-back
   if (Signal == EvidenceServer::ConfigSignal) {
-    ThisServer->ConfigChanged();
+    This->ConfigChanged();
 	return;
   }
@@ -339,10 +346,10 @@
   if (!Called) {
 	Called = true;
-	ThisServer->ExitRequest = true;
+	This->ExitRequest = true;
 	return;
   }
 
   // If invoked twice, call exit()
-  ThisServer->Message(ThisServer->WARN, "Signal handler called again, invoking exit() (signal %d)", Signal);
+  This->Message(WARN, "Signal handler called again, invoking exit() (signal %d)", Signal);
   exit(EXIT_FAILURE);
 }
@@ -355,7 +362,7 @@
 
   if (Terminating) {
-	Msg << ThisServer->Name << ": Terminate() called recursively, calling abort()";
+	Msg << This->Name << ": Terminate() called recursively, calling abort()";
 	printf("%s\n", Msg.str().c_str());
-	ThisServer->SendToLog(Msg.str().c_str());
+	This->SendToLog(Msg.str().c_str());
 	abort();
   }
@@ -383,22 +390,18 @@
   else Msg << "Terminate() called without an active exception";
 
-  ThisServer->Message(FATAL, Msg.str().c_str());
-}
-
-
-// Translates DIMInfo safely to string (assures no inivalid memory accesses are made)
-string EvidenceServer::ToString(DimInfo *I) {
+  This->Message(FATAL, Msg.str().c_str());
+}
+
+
+// Translates DIM data safely to string (assures no invalid memory accesses are made)
+string EvidenceServer::ToString(char *Format, void *Data, int Size) {
 
   ostringstream Text;
   
-  // Safety check
-  if (I->getSize() < 1) return string();
-
   // 'Message' service format handled here
-  if (strcmp(I->getFormat(), "I:1;C") == 0 && I->getSize()>=(int) sizeof(struct Message)) {
-	struct Message *Msg = (struct Message *) I->getData();
+  if (strcmp(Format, "I:1;C") == 0 && Size >= (int) sizeof(struct Message)) {
+	struct Message *Msg = (struct Message *) Data;
 	// Safely extract string and limit to length of C string (padding might make it longer)
-	string MsgText(Msg->Text, I->getSize()-sizeof(struct Message));
-    //MsgText.erase(strlen(MsgText.c_str()));
+	string MsgText(Msg->Text, Size-sizeof(struct Message));
 	Text << Msg->Severity << " " << MsgText.erase(strlen(MsgText.c_str()));
 
@@ -407,7 +410,7 @@
   
   // Structure: print hex representation 
-  if (strlen(I->getFormat()) != 1) {
-	for (int i=0; i<I->getSize(); i++) {
-	  Text << setw(2) << hex << *((char *) I->getData() + i) << " ";
+  if (strlen(Format) != 1) {
+	for (int i=0; i<Size; i++) {
+	  Text << setw(2) << hex << *((char *) Data + i) << " ";
 	} 
 	return Text.str();
@@ -415,41 +418,34 @@
 
   // String if format "C" and terminated with \0
-  if (strcmp(I->getFormat(),"C")==0 && *((char *) I->getData()+I->getSize()-1)=='\0') {  
-    Text << I->getString(); 
-	return Text.str();
+  if (strcmp(Format, "C") == 0 && Size > 0 && *((char *) Data+Size-1)=='\0') {
+	return string((char *) Data);
   }
 
   // Number array
-  int Size;
-  switch (*(I->getFormat())) {
-    case 'C': Size = sizeof(char);		break;
+  int ElementSize;
+  switch (*Format) {
+    case 'C': ElementSize = sizeof(char);		break;
     case 'I':
-    case 'L': Size = sizeof(int);		break;
-    case 'S': Size = sizeof(short);		break;
-    case 'F': Size = sizeof(float);		break;
-    case 'D': Size = sizeof(double);	break;
-    case 'X': Size = sizeof(long long);	break;
+    case 'L': ElementSize = sizeof(int);		break;
+    case 'S': ElementSize = sizeof(short);		break;
+    case 'F': ElementSize = sizeof(float);		break;
+    case 'D': ElementSize = sizeof(double);		break;
+    case 'X': ElementSize = sizeof(long long);	break;
     default: return string();
   }
 
-  for (int i=0; i<I->getSize()/Size; i++) {
+  for (int i=0; i<Size/ElementSize; i++) {
 	// Space between entries
     if (i != 0) Text << " ";
 
 	// Translate data
-	switch (*(I->getFormat())) {
-      case 'C': Text << *((char *) I->getData() + i);
-				break;
+	switch (*Format) {
+      case 'C': Text << *((char *) Data + i);		break;
       case 'I':
-      case 'L': Text << *((int *) I->getData() + i);
-				break;
-      case 'S': Text << *((short *) I->getData() + i);
-				break;
-      case 'F': Text << *((float *) I->getData() + i);
-				break;
-      case 'D': Text << *((double *) I->getData() + i);
-				break;
-      case 'X': Text << *((long long *) I->getData() + i);
-				break;
+      case 'L': Text << *((int *) Data + i);		break;
+      case 'S': Text << *((short *) Data + i);		break;
+      case 'F': Text << *((float *) Data + i);		break;
+      case 'D': Text << *((double *) Data + i);		break;
+      case 'X': Text << *((long long *) Data + i);	break;
 	}
   }
