Revision: 40596
http://brlcad.svn.sourceforge.net/brlcad/?rev=40596&view=rev
Author: davidloman
Date: 2010-09-17 13:06:40 +0000 (Fri, 17 Sep 2010)
Log Message:
-----------
Exposed ControlledThread header file. Made user hooks non-virtual, implemented
default stubs. Added multilayered run stack logic for ease of extensibility.
Modified Paths:
--------------
rt^3/trunk/src/utility/ControlledThread.cxx
Added Paths:
-----------
rt^3/trunk/include/ControlledThread.h
Removed Paths:
-------------
rt^3/trunk/src/utility/ControlledThread.h
Copied: rt^3/trunk/include/ControlledThread.h (from rev 40595,
rt^3/trunk/src/utility/ControlledThread.h)
===================================================================
--- rt^3/trunk/include/ControlledThread.h (rev 0)
+++ rt^3/trunk/include/ControlledThread.h 2010-09-17 13:06:40 UTC (rev
40596)
@@ -0,0 +1,71 @@
+/* C O N T R O L L E D T H R E A D . H
+ * BRLCAD
+ *
+ * Copyright (c) 2010 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ */
+/** @file ControlledThread.h
+ *
+ */
+
+#ifndef __CONTROLLEDTHREAD_H__
+#define __CONTROLLEDTHREAD_H__
+
+#include <Qt>
+#include "GSThread.h"
+
+class ControlledThread
+{
+public:
+ ControlledThread(QString threadname = "");
+ virtual ~ControlledThread();
+
+ bool startup();
+ bool shutdown();
+
+protected:
+ virtual bool preStartupHook();
+ virtual bool postStartupHook();
+
+ virtual bool preRunHook();
+ void run();
+ virtual void _run();
+ virtual void _runLoopPass();
+ virtual bool postRunHook();
+
+ virtual bool preShutdownHook();
+ virtual bool postShutdownHook();
+
+private:
+ /* fields */
+ QString threadName;
+ bool runCmd;
+ bool runStatus;
+
+ GSThread* internalThread;
+};
+
+#endif /* __CONTROLLEDTHREAD_H__ */
+
+/*
+ * Local Variables:
+ * tab-width: 8
+ * mode: C
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */
Modified: rt^3/trunk/src/utility/ControlledThread.cxx
===================================================================
--- rt^3/trunk/src/utility/ControlledThread.cxx 2010-09-17 04:59:34 UTC (rev
40595)
+++ rt^3/trunk/src/utility/ControlledThread.cxx 2010-09-17 13:06:40 UTC (rev
40596)
@@ -23,24 +23,113 @@
#include "ControlledThread.h"
-ControlledThread::ControlledThread()
+ControlledThread::ControlledThread(QString threadName)
{
- this->threadName = "DEFAULT_THREAD_NAME";
+ if (threadName.length() <= 0)
+ {
+ this->threadName = "DEFAULT_THREAD_NAME";
+ }
+ else
+ {
+ this->threadName = threadName;
+ }
this->runCmd = false;
this->runStatus = false;
+ this->internalThread = new GSThread();
}
ControlledThread::~ControlledThread()
{
+ delete this->internalThread;
}
-bool ControlledThread::startup(){
+bool
+ControlledThread::startup()
+{
bool preRetVal = this->preStartupHook();
+ this->runCmd = true;
+ bool postRetVal = this->preStartupHook();
+}
+bool
+ControlledThread::shutdown()
+{
+ bool preRetVal = this->preShutdownHook();
+ this->runCmd = false;
+ bool postRetVal = this->preShutdownHook();
+}
- bool postRetVal = this->preStartupHook();
+void
+ControlledThread::run()
+{
+ this->preRunHook();
+ this->runStatus = true;
+
+ this->_run();
+
+ this->postRunHook();
+ this->runStatus = true;
}
+void
+ControlledThread::_run()
+{
+ while (this->runCmd)
+ {
+ this->_runLoopPass();
+ }
+}
+
+void
+ControlledThread::_runLoopPass()
+{
+ //DOES NOTHING BY DEFAULT
+ GSThread::msleep(123);
+}
+
+/**
+ * User hook. Called immediately after ControlledThread::startup() is called
but prior to 'runCmd' being set to true;
+ */
+bool
+ControlledThread::preStartupHook()
+{
+ return true;
+}
+
+/**
+ * User hook. Called immediately after 'runCmd' is set to true;
+ */
+bool
+ControlledThread::postStartupHook()
+{
+ return true;
+}
+
+bool
+ControlledThread::preRunHook()
+{
+ return true;
+}
+
+bool
+ControlledThread::postRunHook()
+{
+ return true;
+}
+
+bool
+ControlledThread::preShutdownHook()
+{
+ return true;
+}
+
+bool
+ControlledThread::postShutdownHook()
+{
+ return true;
+}
+
+
// Local Variables:
// tab-width: 8
// mode: C++
Deleted: rt^3/trunk/src/utility/ControlledThread.h
===================================================================
--- rt^3/trunk/src/utility/ControlledThread.h 2010-09-17 04:59:34 UTC (rev
40595)
+++ rt^3/trunk/src/utility/ControlledThread.h 2010-09-17 13:06:40 UTC (rev
40596)
@@ -1,61 +0,0 @@
-/* C O N T R O L L E D T H R E A D . H
- * BRLCAD
- *
- * Copyright (c) 2010 United States Government as represented by
- * the U.S. Army Research Laboratory.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * version 2.1 as published by the Free Software Foundation.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this file; see the file named COPYING for more
- * information.
- */
-/** @file ControlledThread.h
- *
- */
-
-#ifndef __CONTROLLEDTHREAD_H__
-#define __CONTROLLEDTHREAD_H__
-
-class ControlledThread
-{
-public:
- ControlledThread(QString threadname = "");
- virtual ~ControlledThread();
-
- bool startup();
- bool shutdown();
-
-protected:
- virtual boolean preStartupHook() = 0;
- virtual boolean postStartupHook() = 0;
-
- virtual boolean preShutdownHook() = 0;
- virtual boolean postShutdownHook() = 0;
-
-private:
- /* fields */
- QString threadName;
- bool runCmd;
- bool runStatus;
-
-};
-
-#endif /* __CONTROLLEDTHREAD_H__ */
-
-/*
- * Local Variables:
- * tab-width: 8
- * mode: C
- * indent-tabs-mode: t
- * c-file-style: "stroustrup"
- * End:
- * ex: shiftwidth=4 tabstop=8
- */
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits