]> granicus.if.org Git - icinga2/commitdiff
Cleaned up AsyncTask class.
authorGunnar Beutner <gunnar.beutner@netways.de>
Sat, 14 Jul 2012 11:57:20 +0000 (13:57 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Sat, 14 Jul 2012 11:57:50 +0000 (13:57 +0200)
12 files changed:
base/Makefile.am
base/asynctask.cpp [new file with mode: 0644]
base/asynctask.h
base/base.vcxproj
base/base.vcxproj.filters
base/i2-base.h
base/process.cpp
base/process.h
cib/checktask.cpp
cib/checktask.h
components/checker/checkercomponent.cpp
components/checker/checkercomponent.h

index 24d60168da370b9bf7792cbaaf0780aa260fead5..dbf52b8fcbed27becb60baef5364509fed8e7775 100644 (file)
@@ -7,6 +7,7 @@ pkglib_LTLIBRARIES =  \
 libbase_la_SOURCES =  \
        application.cpp \
        application.h \
+       asynctask.cpp \
        asynctask.h \
        component.cpp \
        component.h \
diff --git a/base/asynctask.cpp b/base/asynctask.cpp
new file mode 100644 (file)
index 0000000..7b09f83
--- /dev/null
@@ -0,0 +1,50 @@
+/******************************************************************************
+ * Icinga 2                                                                   *
+ * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/)        *
+ *                                                                            *
+ * 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; either version 2             *
+ * of the License, or (at your option) any later version.                     *
+ *                                                                            *
+ * 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 St, Fifth Floor, Boston, MA 02110-1301, USA.             *
+ ******************************************************************************/
+
+#include "i2-base.h"
+
+using namespace icinga;
+
+AsyncTask::AsyncTask(const AsyncTask::CompletionCallback& completionCallback)
+       : m_Finished(false), m_CompletionCallback(completionCallback)
+{ }
+
+AsyncTask::~AsyncTask(void)
+{
+       assert(m_Finished);
+}
+
+void AsyncTask::Start(void)
+{
+       assert(Application::IsMainThread());
+
+       Run();
+}
+
+void AsyncTask::Finish(void)
+{
+       Event::Post(boost::bind(&AsyncTask::ForwardCallback, static_cast<AsyncTask::Ptr>(GetSelf())));
+}
+
+void AsyncTask::ForwardCallback(void)
+{
+       m_CompletionCallback(GetSelf());
+       m_CompletionCallback = CompletionCallback();
+       m_Finished = true;
+}
\ No newline at end of file
index 9e25e7f327b5918298077984ff7ed4f0f84acb51..d98dfd012c32e54119b6c8c4ae91003c44e4fe4d 100644 (file)
 namespace icinga
 {
 
-template<typename T>
-class AsyncTask : public Object
+class I2_BASE_API AsyncTask : public Object
 {
 public:
-       typedef shared_ptr<AsyncTask<T> > Ptr;
-       typedef weak_ptr<AsyncTask<T> > WeakPtr;
+       typedef shared_ptr<AsyncTask> Ptr;
+       typedef weak_ptr<AsyncTask> WeakPtr;
 
-       typedef function<void (const shared_ptr<T>&)> CompletionCallback;
+       typedef function<void (const AsyncTask::Ptr&)> CompletionCallback;
 
-       AsyncTask(const CompletionCallback& completionCallback)
-               : m_Finished(false), m_CompletionCallback(completionCallback)
-       { }
+       AsyncTask(const CompletionCallback& completionCallback);
+       ~AsyncTask(void);
 
-       ~AsyncTask(void)
-       {
-               assert(m_Finished);
-       }
-
-       void Start(void)
-       {
-               assert(Application::IsMainThread());
-
-               Run();
-       }
+       void Start(void);
 
 protected:
        virtual void Run(void) = 0;
 
-       void Finish(void)
-       {
-               Event::Post(boost::bind(&T::ForwardCallback, static_cast<shared_ptr<T> >(GetSelf())));
-       }
+       void Finish(void);
 
 private:
-       void ForwardCallback(void)
-       {
-               m_CompletionCallback(GetSelf());
-               m_CompletionCallback = CompletionCallback();
-               m_Finished = true;
-       }
+       void ForwardCallback(void);
 
        bool m_Finished;
        CompletionCallback m_CompletionCallback;
index ad0ca617683fabfe8fb34c300a398673187298c2..3365e7e913ec0ec4c7c51392140c012d94e95a59 100644 (file)
@@ -12,6 +12,7 @@
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="application.cpp" />
+    <ClCompile Include="asynctask.cpp" />
     <ClCompile Include="component.cpp" />
     <ClCompile Include="configobject.cpp" />
     <ClCompile Include="dictionary.cpp" />
index 58d2e0a6ab068e98929d67e23cf3f9929834dfdb..9e59fd00ed6b926d9277d8039c0fecfa6fa2b31a 100644 (file)
@@ -79,6 +79,9 @@
     <ClCompile Include="process.cpp">
       <Filter>Quelldateien</Filter>
     </ClCompile>
+    <ClCompile Include="asynctask.cpp">
+      <Filter>Quelldateien</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="application.h">
index a0b1663fabd8c1ecd18cd55d939c98394df3e555..edc81aab029ef9a6557a1bd71d2f8d7260b03ab5 100644 (file)
@@ -55,6 +55,7 @@
 #ifdef _MSC_VER
 #      pragma warning(disable:4251)
 #      pragma warning(disable:4275)
+#      pragma warning(disable:4345)
 #      define _CRT_SECURE_NO_DEPRECATE
 #      define _CRT_SECURE_NO_WARNINGS
 #else /* _MSC_VER */
index 50c4feabea14d790fdc8e697faee8bfa500eaa38..23bde9c518519d1a8c0442f9dcb50f31b31dcb0b 100644 (file)
@@ -31,7 +31,7 @@ deque<Process::Ptr> Process::m_Tasks;
 condition_variable Process::m_TasksCV;
 
 Process::Process(const string& command, const CompletionCallback& completionCallback)
-       : AsyncTask<Process>(completionCallback), m_Command(command), m_UsePopen(false)
+       : AsyncTask(completionCallback), m_Command(command), m_UsePopen(false)
 {
        if (!m_ThreadCreated) {
                thread t(&Process::WorkerThreadProc);
index a5d11b85ab63c42f8458b9440bb2b71d2bbf1af9..ec9bde5b9209edfda23e7cc5692149024561928f 100644 (file)
@@ -23,7 +23,7 @@
 namespace icinga
 {
 
-class I2_BASE_API Process : public AsyncTask<Process>
+class I2_BASE_API Process : public AsyncTask
 {
 public:
        typedef shared_ptr<Process> Ptr;
index e75f3799dc453b19b7692968eac10baecada7c8b..cab5ebeffc714998054e80b82c52c8ddd945d54a 100644 (file)
@@ -24,7 +24,7 @@ using namespace icinga;
 map<string, CheckTaskType> CheckTask::m_Types;
 
 CheckTask::CheckTask(const Service& service, const CompletionCallback& completionCallback)
-       : AsyncTask<CheckTask>(completionCallback), m_Service(service)
+       : AsyncTask(completionCallback), m_Service(service)
 { }
 
 Service& CheckTask::GetService(void)
index db20668c70c1445479068a8569f98ad695360fbc..a7c43c5a79e6ad2e3469279da5f57dfad2ed9803 100644 (file)
@@ -25,7 +25,7 @@ namespace icinga
 
 struct CheckTaskType;
 
-class I2_CIB_API CheckTask : public AsyncTask<CheckTask>
+class I2_CIB_API CheckTask : public AsyncTask
 {
 public:
        typedef shared_ptr<CheckTask> Ptr;
index 6c7d5416ed664768bf2bb678b759de568ca20162..b24fedba96620798943b55f102554383a8f3097f 100644 (file)
@@ -93,8 +93,9 @@ void CheckerComponent::CheckTimerHandler(void)
        Logger::Write(LogInformation, "checker", msgbuf.str());
 }
 
-void CheckerComponent::CheckCompletedHandler(const CheckTask::Ptr& task)
+void CheckerComponent::CheckCompletedHandler(const AsyncTask::Ptr& atask)
 {
+       CheckTask::Ptr task = static_pointer_cast<CheckTask>(atask);
        Service service = task->GetService();
 
        service.RemoveTag("current_task");
index b3e6b7ff13093ae4fbd0028eb29e3d3a9d914971..3700d4e3160c628dffb210a877ca50ae086a96df 100644 (file)
@@ -60,7 +60,7 @@ private:
        void CheckTimerHandler(void);
        void ResultTimerHandler(void);
 
-       void CheckCompletedHandler(const CheckTask::Ptr& task);
+       void CheckCompletedHandler(const AsyncTask::Ptr& task);
 
        void AdjustCheckTimer(void);