[Fawkes Git] branch/bschaepers/asp-aspect: ASP Aspect: Use Fawkes logging for Clingo.

Bjoern Schaepers bjoern.schaepers at rwth-aachen.de
Thu Oct 27 15:47:12 CEST 2016


Changes have been pushed for the project "Fawkes Robotics Software Framework".

Gitweb: http://git.fawkesrobotics.org/fawkes.git
Trac:   http://trac.fawkesrobotics.org

The branch, bschaepers/asp-aspect has been updated
        to  10dd8ee45c19379b016a50499e7683cdb0590fde (commit)
      from  0e73c34d51d17f9d12d04168bba2100f9057c1ef (commit)

http://git.fawkesrobotics.org/fawkes.git/bschaepers/asp-aspect

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- *Log* ---------------------------------------------------------------
commit 10dd8ee45c19379b016a50499e7683cdb0590fde
Author:     Bjoern Schaepers <bjoern.schaepers at rwth-aachen.de>
AuthorDate: Thu Oct 20 23:19:33 2016 +0200
Commit:     Bjoern Schaepers <bjoern.schaepers at rwth-aachen.de>
CommitDate: Thu Oct 27 15:44:01 2016 +0200

    ASP Aspect: Use Fawkes logging for Clingo.

http://git.fawkesrobotics.org/fawkes.git/commit/10dd8ee
http://trac.fawkesrobotics.org/changeset/10dd8ee

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


- *Summary* -----------------------------------------------------------
 src/plugins/asp/asp_thread.cpp        |    1 +
 src/plugins/asp/asp_thread.h          |    2 +
 src/plugins/asp/aspect/asp_inifin.cpp |   38 ++++++++++++++++++++++++++++++--
 src/plugins/asp/aspect/asp_inifin.h   |    7 ++++++
 4 files changed, 45 insertions(+), 3 deletions(-)


- *Diffs* -------------------------------------------------------------

- *commit* 10dd8ee45c19379b016a50499e7683cdb0590fde - - - - - - - - - -
Author:  Bjoern Schaepers <bjoern.schaepers at rwth-aachen.de>
Date:    Thu Oct 20 23:19:33 2016 +0200
Subject: ASP Aspect: Use Fawkes logging for Clingo.

 src/plugins/asp/asp_thread.cpp        |    1 +
 src/plugins/asp/asp_thread.h          |    2 +
 src/plugins/asp/aspect/asp_inifin.cpp |   38 ++++++++++++++++++++++++++++++--
 src/plugins/asp/aspect/asp_inifin.h   |    7 ++++++
 4 files changed, 45 insertions(+), 3 deletions(-)

_Diff for modified files_:
diff --git a/src/plugins/asp/asp_thread.cpp b/src/plugins/asp/asp_thread.cpp
index 285ece6..99b5805 100644
--- a/src/plugins/asp/asp_thread.cpp
+++ b/src/plugins/asp/asp_thread.cpp
@@ -42,6 +42,7 @@ ASPThread::ASPThread(void)
 void
 ASPThread::init(void)
 {
+	ASPIniFin.setLogger(logger);
 	return;
 }
 
diff --git a/src/plugins/asp/asp_thread.h b/src/plugins/asp/asp_thread.h
index 590d390..92ac825 100644
--- a/src/plugins/asp/asp_thread.h
+++ b/src/plugins/asp/asp_thread.h
@@ -25,6 +25,7 @@
 
 #include <aspect/aspect_provider.h>
 #include "aspect/asp_inifin.h"
+#include <aspect/logging.h>
 #include <core/threading/thread.h>
 
 namespace fawkes {
@@ -33,6 +34,7 @@ namespace fawkes {
 
 class ASPThread
 : public fawkes::Thread,
+  public fawkes::LoggingAspect,
   public fawkes::AspectProviderAspect
 {
 	private:
diff --git a/src/plugins/asp/aspect/asp_inifin.cpp b/src/plugins/asp/aspect/asp_inifin.cpp
index 0dbeb8d..2a39bf7 100644
--- a/src/plugins/asp/aspect/asp_inifin.cpp
+++ b/src/plugins/asp/aspect/asp_inifin.cpp
@@ -25,6 +25,7 @@
 #include "asp_inifin.h"
 #include <clingo.hh>
 #include <core/threading/thread_finalizer.h>
+#include <logging/logger.h>
 
 namespace fawkes {
 #if 0 /* just to make Emacs auto-indent happy */
@@ -35,10 +36,14 @@ namespace fawkes {
  * ASPAspect initializer/finalizer.
  * This initializer/finalizer will provide the ASP node handle to threads with the ASPAspect.
  * @author Björn Schäpers
+ *
+ * @property ASPAspectIniFin::Log
+ * @brief The logger used for Clingo Output.
  */
 
-/** Constructor. */
-ASPAspectIniFin::ASPAspectIniFin(void) : AspectIniFin("ASPAspect")
+/** Constructor.
+ */
+ASPAspectIniFin::ASPAspectIniFin(void) : AspectIniFin("ASPAspect"), Log(nullptr)
 {
 	return;
 }
@@ -53,7 +58,23 @@ ASPAspectIniFin::init(Thread *thread)
 		thread->name());
 	} //if ( asp_thread == nullptr )
 
-	asp_thread->init_ASPAspect(LockPtr<Clingo::Control>(new Clingo::Control));
+	auto clingoLogger = [this](const Clingo::WarningCode code, char const *msg)
+		{
+			fawkes::Logger::LogLevel level = fawkes::Logger::LL_NONE;
+			switch ( code )
+			{
+				case Clingo::WarningCode::AtomUndefined      :
+				case Clingo::WarningCode::OperationUndefined :
+				case Clingo::WarningCode::RuntimeError       : level = fawkes::Logger::LL_ERROR; break;
+				case Clingo::WarningCode::Other              :
+				case Clingo::WarningCode::VariableUnbounded  : level = fawkes::Logger::LL_WARN;
+				case Clingo::WarningCode::FileIncluded       :
+				case Clingo::WarningCode::GlobalVariable     : level = fawkes::Logger::LL_INFO; break;
+			} //switch ( code )
+			Log->log(level, "Clingo", msg);
+			return;
+		};
+	asp_thread->init_ASPAspect(LockPtr<Clingo::Control>(new Clingo::Control({}, clingoLogger, 100)));
 	return;
 }
 
@@ -71,4 +92,15 @@ ASPAspectIniFin::finalize(Thread *thread)
 	return;
 }
 
+/**
+ * @brief Sets the logger to use for Clingo messages.
+ * @param[in] logger The new logger.
+ */
+void
+ASPAspectIniFin::setLogger(Logger *logger)
+{
+	Log = logger;
+	return;
+}
+
 } // end namespace fawkes
diff --git a/src/plugins/asp/aspect/asp_inifin.h b/src/plugins/asp/aspect/asp_inifin.h
index f62ef73..d112084 100644
--- a/src/plugins/asp/aspect/asp_inifin.h
+++ b/src/plugins/asp/aspect/asp_inifin.h
@@ -32,13 +32,20 @@ namespace fawkes {
 }
 #endif
 
+class Logger;
+
 class ASPAspectIniFin : public AspectIniFin
 {
+	private:
+	Logger *Log;
+
 	public:
 	ASPAspectIniFin(void);
 
 	void init(Thread *thread) override;
 	void finalize(Thread *thread) override;
+
+	void setLogger(Logger *logger);
 };
 
 } // end namespace fawkes




-- 
Fawkes Robotics Framework                 http://www.fawkesrobotics.org


More information about the fawkes-commits mailing list