- Main Page
- Related Pages
- Classes
- Files

- File List
- File Members

# scopedparallelexecutor.h

    00001 // Copyright (C) 2008,2009,2010 by Philipp Münzel. All rights reserved.
    00002 // Released under the terms of the license described in license.txt
    00003
    00004 #ifndef SCOPEDPARALLELEXECUTOR_H
    00005 #define SCOPEDPARALLELEXECUTOR_H
    00006
    00007 #include "dllexport.h"
    00008
    00009 #include <boost/thread.hpp>
    00010 #include <boost/function.hpp>
    00011 #include <boost/asio.hpp>
    00012
    00013 namespace SCS {
    00014
    00027 class DLL_PUBLIC ScopedParallelExecutor
    00028 {
    00029 public:
    00030     ScopedParallelExecutor();
    00031
    00036     ScopedParallelExecutor(boost::function<void()> run_function, long run_interval_ms);
    00037
    00041     ~ScopedParallelExecutor();
    00042
    00046     void setCallback(boost::function<void()> run_function);
    00047
    00051     void setRunInterval(long milliseconds);
    00052
    00057     static void delay(int seconds);
    00058
    00059 private:
    00060     void runFunction();
    00061     void runIOService();
    00062
    00063 private:
    00064     boost::function<void()> m_run_function;
    00065     long m_run_interval_ms;
    00066     boost::asio::io_service m_io_service;
    00067     std::auto_ptr<boost::asio::io_service::work> m_work;
    00068     boost::thread m_thread;
    00069     boost::asio::deadline_timer m_timer;
    00070     bool m_stop;
    00071 };
    00072 }
    00073 #endif // SCOPEDPARALLELEXECUTOR_H