[Avida-SVN] r2847 - in development: Avida.xcodeproj source/cpu source/drivers source/platform

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Tue Oct 14 13:02:47 PDT 2008


Author: brysonda
Date: 2008-10-14 16:02:47 -0400 (Tue, 14 Oct 2008)
New Revision: 2847

Added:
   development/source/drivers/cDriverStatusConduit.cc
   development/source/drivers/cDriverStatusConduit.h
   development/source/platform/tThreadSpecific.h
Modified:
   development/Avida.xcodeproj/project.pbxproj
   development/source/cpu/cHardwareManager.cc
   development/source/drivers/cDriverManager.cc
   development/source/drivers/cDriverManager.h
Log:
Lay some groundwork for a more universally accessible error reporting facility.  Rather than require the driver object to be passed around, functions and methods will contact the status conduit via the globally reachable driver manager.

Modified: development/Avida.xcodeproj/project.pbxproj
===================================================================
--- development/Avida.xcodeproj/project.pbxproj	2008-10-14 12:57:57 UTC (rev 2846)
+++ development/Avida.xcodeproj/project.pbxproj	2008-10-14 20:02:47 UTC (rev 2847)
@@ -201,6 +201,7 @@
 		70B6514F0BEA6FCC002472ED /* main.cc in Sources */ = {isa = PBXBuildFile; fileRef = 701EF27E0BEA5D2300DAE168 /* main.cc */; };
 		70B651B70BEA9AEC002472ED /* unit-tests in CopyFiles */ = {isa = PBXBuildFile; fileRef = 70B6514C0BEA6FAD002472ED /* unit-tests */; };
 		70BB2A2B0E9FA12F008269D2 /* ASAvidaLib.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70BB2A2A0E9FA12F008269D2 /* ASAvidaLib.cc */; };
+		70BB2AE20EA5303F008269D2 /* cDriverStatusConduit.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70BB2AC60EA52BD9008269D2 /* cDriverStatusConduit.cc */; };
 		70DCAC9C097AF7C0002F8733 /* primitive.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70DCAC9B097AF7C0002F8733 /* primitive.cc */; };
 		70EFD6600D975B6E00FAD32A /* cConstBurstSchedule.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70EFD65F0D975B5E00FAD32A /* cConstBurstSchedule.cc */; };
 		B4FA258A0C5EB65E0086D4B5 /* cPlasticPhenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = B4FA25810C5EB6510086D4B5 /* cPlasticPhenotype.cc */; };
@@ -741,6 +742,9 @@
 		70B6514C0BEA6FAD002472ED /* unit-tests */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "unit-tests"; sourceTree = BUILT_PRODUCTS_DIR; };
 		70BB2A290E9FA12F008269D2 /* ASAvidaLib.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASAvidaLib.h; sourceTree = "<group>"; };
 		70BB2A2A0E9FA12F008269D2 /* ASAvidaLib.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ASAvidaLib.cc; sourceTree = "<group>"; };
+		70BB2ABF0EA4F896008269D2 /* tThreadSpecific.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tThreadSpecific.h; sourceTree = "<group>"; };
+		70BB2AC20EA4FF25008269D2 /* cDriverStatusConduit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cDriverStatusConduit.h; sourceTree = "<group>"; };
+		70BB2AC60EA52BD9008269D2 /* cDriverStatusConduit.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cDriverStatusConduit.cc; sourceTree = "<group>"; };
 		70BCB21B0AB7ADA6003FF331 /* cArgContainer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cArgContainer.h; sourceTree = "<group>"; };
 		70BCB21C0AB7ADA6003FF331 /* cArgContainer.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cArgContainer.cc; sourceTree = "<group>"; };
 		70BCB2470AB7B634003FF331 /* cArgSchema.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cArgSchema.h; sourceTree = "<group>"; };
@@ -963,6 +967,7 @@
 		701D9115094B770B008B845F /* drivers */ = {
 			isa = PBXGroup;
 			children = (
+				70BB2AC60EA52BD9008269D2 /* cDriverStatusConduit.cc */,
 				701D9382094CBA69008B845F /* cDriverManager.cc */,
 				701D9116094B773E008B845F /* cWorldDriver.h */,
 				701D912B094B7AC1008B845F /* cAvidaDriver.h */,
@@ -973,6 +978,7 @@
 				701D930C094CAD6B008B845F /* cDefaultRunDriver.cc */,
 				701D93E6094CBF71008B845F /* cDefaultAnalyzeDriver.h */,
 				701D93E7094CBF71008B845F /* cDefaultAnalyzeDriver.cc */,
+				70BB2AC20EA4FF25008269D2 /* cDriverStatusConduit.h */,
 			);
 			path = drivers;
 			sourceTree = "<group>";
@@ -1273,6 +1279,7 @@
 				70436B250C36C64000A05ABA /* platform.h */,
 				70436B260C36C64000A05ABA /* PlatformExpert.cc */,
 				70436B270C36C64000A05ABA /* PlatformExpert.h */,
+				70BB2ABF0EA4F896008269D2 /* tThreadSpecific.h */,
 			);
 			path = platform;
 			sourceTree = "<group>";
@@ -2033,6 +2040,7 @@
 				70A778390D69D5CA00735F1E /* cDemeProbSchedule.cc in Sources */,
 				2A57A3FF0D6B954D00FC54C7 /* cProbDemeProbSchedule.cc in Sources */,
 				70EFD6600D975B6E00FAD32A /* cConstBurstSchedule.cc in Sources */,
+				70BB2AE20EA5303F008269D2 /* cDriverStatusConduit.cc in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: development/source/cpu/cHardwareManager.cc
===================================================================
--- development/source/cpu/cHardwareManager.cc	2008-10-14 12:57:57 UTC (rev 2846)
+++ development/source/cpu/cHardwareManager.cc	2008-10-14 20:02:47 UTC (rev 2847)
@@ -33,7 +33,8 @@
 #include "cInitFile.h"
 #include "cInstSet.h"
 #include "cWorld.h"
-#include "cWorldDriver.h"
+#include "cDriverManager.h"
+#include "cDriverStatusConduit.h"
 #include "tDictionary.h"
 
 cHardwareManager::cHardwareManager(cWorld* world)
@@ -66,12 +67,12 @@
 			default_filename = cHardwareGX::GetDefaultInstFilename();
 			break;      
 		default:
-      m_world->GetDriver().RaiseFatalException(1, "Unknown/Unsupported HARDWARE_TYPE specified");
+      cDriverManager::Status().SignalFatalError(1, "Unknown/Unsupported HARDWARE_TYPE specified");
   }
 
   if (filename == "" || filename == "-") {
     filename = default_filename;
-    m_world->GetDriver().NotifyComment(cString("Using default instruction set: ") + filename);
+    cDriverManager::Status().NotifyComment(cString("Using default instruction set: ") + filename);
   }
   
   if (m_world->GetConfig().INST_SET_FORMAT.Get()) {
@@ -105,7 +106,7 @@
       hw = new cHardwareGX(m_world, in_org, m_inst_set);
       break;
     default:
-      m_world->GetDriver().RaiseFatalException(-1, "Unrecognized hardware type.");
+      cDriverManager::Status().SignalFatalError(1, "Unknown/Unsupported HARDWARE_TYPE specified");
       break;
   }
   

Modified: development/source/drivers/cDriverManager.cc
===================================================================
--- development/source/drivers/cDriverManager.cc	2008-10-14 12:57:57 UTC (rev 2846)
+++ development/source/drivers/cDriverManager.cc	2008-10-14 20:02:47 UTC (rev 2847)
@@ -26,6 +26,7 @@
 
 #include "cActionLibrary.h"
 #include "cAvidaDriver.h"
+#include "cDriverStatusConduit.h"
 #include "cWorldDriver.h"
 
 #include <cassert>
@@ -102,6 +103,22 @@
   m_dm->m_mutex.Unlock();
 }
 
+cDriverStatusConduit& cDriverManager::Status()
+{
+  cDriverStatusConduit* conduit = m_dm->m_conduit.Get();
+  if (!conduit) {
+    conduit = new cDriverStatusConduit;
+    m_dm->m_conduit.Set(conduit);
+  }
+  return *conduit;
+}
+
+void cDriverManager::SetConduit(cDriverStatusConduit* conduit)
+{
+  m_dm->m_conduit.Set(conduit);
+}
+
+
 cActionLibrary* cDriverManager::GetActionLibrary()
 {
   assert(m_dm);

Modified: development/source/drivers/cDriverManager.h
===================================================================
--- development/source/drivers/cDriverManager.h	2008-10-14 12:57:57 UTC (rev 2846)
+++ development/source/drivers/cDriverManager.h	2008-10-14 20:02:47 UTC (rev 2847)
@@ -31,9 +31,13 @@
 #ifndef cMutex_h
 #include "cMutex.h"
 #endif
+#ifndef tThreadSpecific_h
+#include "tThreadSpecific.h"
+#endif
 
 class cActionLibrary;
 class cAvidaDriver;
+class cDriverStatusConduit;
 class cWorldDriver;
 
 
@@ -48,6 +52,8 @@
   cMutex m_mutex;
   cActionLibrary* m_actlib;
   
+  tThreadSpecific<cDriverStatusConduit> m_conduit;
+  
   cDriverManager();
   ~cDriverManager();
 
@@ -65,6 +71,9 @@
   static void Unregister(cAvidaDriver* drv);
   static void Unregister(cWorldDriver* drv);
   
+  static cDriverStatusConduit& Status();
+  static void SetConduit(cDriverStatusConduit* conduit);
+    
   static cActionLibrary* GetActionLibrary();
 };
 

Added: development/source/drivers/cDriverStatusConduit.cc
===================================================================
--- development/source/drivers/cDriverStatusConduit.cc	                        (rev 0)
+++ development/source/drivers/cDriverStatusConduit.cc	2008-10-14 20:02:47 UTC (rev 2847)
@@ -0,0 +1,56 @@
+/*
+ *  cDriverStatusConduit.cc
+ *  Avida
+ *
+ *  Created by David on 10/14/08.
+ *  Copyright 2008 Michigan State University. All rights reserved.
+ *
+ *
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License
+ *  as published by the Free Software Foundation; version 2
+ *  of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#include "cDriverStatusConduit.h"
+
+#include "avida.h"
+
+#include "cString.h"
+
+#include <iostream>
+
+using namespace std;
+
+
+void cDriverStatusConduit::SignalError(const cString& msg)
+{
+  cerr << "error: " << msg << endl;
+}
+
+void cDriverStatusConduit::SignalFatalError(int exit_code, const cString& msg)
+{
+  cerr << "error: " << msg << endl << "exiting..." << endl;
+  Avida::Exit(exit_code);
+}
+
+void cDriverStatusConduit::NotifyWarning(const cString& msg)
+{
+  cout << "warning: " << msg << endl;
+}
+
+void cDriverStatusConduit::NotifyComment(const cString& msg)
+{
+  cout << msg << endl;
+}
+

Added: development/source/drivers/cDriverStatusConduit.h
===================================================================
--- development/source/drivers/cDriverStatusConduit.h	                        (rev 0)
+++ development/source/drivers/cDriverStatusConduit.h	2008-10-14 20:02:47 UTC (rev 2847)
@@ -0,0 +1,50 @@
+/*
+ *  cDriverStatusConduit.h
+ *  Avida
+ *
+ *  Created by David on 10/14/08.
+ *  Copyright 2008 Michigan State University. All rights reserved.
+ *
+ *
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License
+ *  as published by the Free Software Foundation; version 2
+ *  of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#ifndef cDriverStatusConduit_h
+#define cDriverStatusConduit_h
+
+
+class cString;
+
+class cDriverStatusConduit
+{
+private:
+  cDriverStatusConduit(const cDriverStatusConduit&); // @not_implemented
+  cDriverStatusConduit& operator=(const cDriverStatusConduit&); // @not_implemented
+  
+public:
+  cDriverStatusConduit() { ; }
+  virtual ~cDriverStatusConduit() { ; }
+  
+  // Signals
+  virtual void SignalError(const cString& msg);
+  virtual void SignalFatalError(int exit_code, const cString& msg);
+  
+  // Notifications
+  virtual void NotifyWarning(const cString& msg);
+  virtual void NotifyComment(const cString& msg);
+};
+
+#endif

Added: development/source/platform/tThreadSpecific.h
===================================================================
--- development/source/platform/tThreadSpecific.h	                        (rev 0)
+++ development/source/platform/tThreadSpecific.h	2008-10-14 20:02:47 UTC (rev 2847)
@@ -0,0 +1,78 @@
+/*
+ *  tThreadSpecific.h
+ *  Avida
+ *
+ *  Created by David on 10/14/08.
+ *  Copyright 2008 Michigan State University. All rights reserved.
+ *
+ *
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License
+ *  as published by the Free Software Foundation; version 2
+ *  of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#ifndef tThreadSpecific_h
+#define tThreadSpecific_h
+
+
+#if AVIDA_PLATFORM(THREADS) && AVIDA_PLATFORM(UNIX)
+
+// Use POSIX Threads
+#include <pthread.h>
+
+template<typename T>
+class tThreadSpecific
+{
+private:
+  pthread_key_t m_key;
+  static void destroySpecific(void* data) { delete (T*)data; }
+  
+public:
+  tThreadSpecific() { pthread_key_create(&m_key, &destroySpecific); }
+  ~tThreadSpecific() { destroySpecific(pthread_getspecific(m_key)); pthread_key_delete(m_key); }
+  
+  T* Get() { return (T*)pthread_getspecific(m_key); }
+  void Set(T* value) { destroySpecific(pthread_getspecific(m_key)); pthread_setspecific(m_key, (void*)value); }
+};
+
+
+#elif AVIDA_PLATFORM(THREADS) && AVIDA_PLATFORM(WINDOWS)
+
+// Use Windows Threading
+#include <windows.h>
+
+#error Windows tThreadSpecific not currently implemented
+
+#else
+
+// Disable Threading
+template<typename T>
+class tThreadSpecific
+{
+private:
+  T* m_value;
+  
+public:
+  tThreadSpecific() : m_value(NULL) { ; }
+  ~tThreadSpecific() { delete m_value; }
+  
+  T* Get() { return m_value; }
+  T* Set(T* value) { T* oldvalue = m_value; m_value = value; return oldvalue; }
+  void Set(T* value) { delete m_value; m_value = value; }
+};
+
+#endif
+
+
+#endif




More information about the Avida-cvs mailing list