libpsynth 0.2.1
/home/raskolnikov/dev/psynth/trunk/src/psynth/io/thread_async.hpp
Go to the documentation of this file.
00001 
00011 /*
00012  *  Copyright (C) 2011 Juan Pedro BolĂ­var Puente
00013  *
00014  *  This file is part of Psychosynth.
00015  *   
00016  *  Psychosynth is free software: you can redistribute it and/or modify
00017  *  it under the terms of the GNU General Public License as published by
00018  *  the Free Software Foundation, either version 3 of the License, or
00019  *  (at your option) any later version.
00020  *
00021  *  Psychosynth is distributed in the hope that it will be useful,
00022  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024  *  GNU General Public License for more details.
00025  *
00026  *  You should have received a copy of the GNU General Public License
00027  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00028  *
00029  */
00030 
00031 #ifndef PSYNTH_IO_THREAD_ASYNC_H_
00032 #define PSYNTH_IO_THREAD_ASYNC_H_
00033 
00034 #include <thread>
00035 #include <psynth/io/async_base.hpp>
00036 
00037 namespace psynth
00038 {
00039 namespace io
00040 {
00041 
00042 class thread_async : public detail::async_base_impl
00043 {
00044 public:
00045     typedef detail::async_base_impl::callback_type callback_type;
00046     
00047     thread_async (callback_type cb, bool realtime = false)
00048         : detail::async_base_impl (cb)
00049         , _realtime (realtime)
00050     {}
00051     
00052     ~thread_async () { soft_stop (); }
00053     
00054     void start ();
00055     void stop ();
00056 
00057 protected:
00058     virtual void run ();
00059     virtual void iterate () {}
00060     
00061 private:
00062     void _request_rt ();
00063 
00064     bool        _realtime;
00065     std::thread _thread;
00066 };
00067 
00068 } /* namespace io */
00069 } /* namespace psynth */
00070 
00071 #endif /* PSYNTH_IO_THREAD_ASYNC_H_ */