Pteros  2.0
Molecular modeling library for human beings!
task_driver.h
1 /*
2  *
3  * This source code is part of
4  * ******************
5  * *** Pteros ***
6  * ******************
7  * molecular modeling library
8  *
9  * Copyright (c) 2009-2017, Semen Yesylevskyy
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of Artistic License:
13  *
14  * Please note, that Artistic License is slightly more restrictive
15  * then GPL license in terms of distributing the modified versions
16  * of this software (they should be approved first).
17  * Read http://www.opensource.org/licenses/artistic-license-2.0.php
18  * for details. Such license fits scientific software better then
19  * GPL because it prevents the distribution of bugged derivatives.
20  *
21 */
22 
23 
24 #include "pteros/analysis/task_base.h"
25 #include <thread>
26 #include "message_channel.h"
27 #include "pteros/core/pteros_error.h"
28 #include "data_container.h"
29 
30 namespace pteros {
31 
32 using DataChannel = MessageChannel<std::shared_ptr<pteros::DataContainer> > ;
33 using DataChannel_ptr = std::shared_ptr<DataChannel> ;
34 
35 class TaskDriver {
36 public:
37  TaskDriver(TaskBase* _task);
38  virtual ~TaskDriver();
39  void set_data_channel_and_system(const DataChannel_ptr& ch, const System &sys);
40  void process_until_end();
41  void process_until_end_in_thread ();
42  void join_thread();
43 private:
44  DataChannel_ptr channel;
45  TaskBase* task;
46  std::shared_ptr<DataContainer> data;
47  std::thread t;
48  bool stop_now; // Emergency stop flag for thread
49  bool pre_process_done;
50 };
51 
52 
53 }