tclsci plugged
[scilab.git] / scilab / modules / core / includes / runner.hxx
1 /*
2  *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  *  Copyright (C) 2010-2010 - DIGITEO - Bruno JOFRET
4  *  Copyright (C) 2014-2015 - Scilab Enterprises - Cedric Delamarre
5  *
6  *  This file must be used under the terms of the CeCILL.
7  *  This source file is licensed as described in the file COPYING, which
8  *  you should have received as part of this distribution.  The terms
9  *  are also available at
10  *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
11  *
12  */
13
14 #ifndef __RUNNER_HXX__
15 #define __RUNNER_HXX__
16
17 #include <atomic>
18 #include <memory>
19
20 #include "exp.hxx"
21 #include "runvisitor.hxx"
22
23 extern "C"
24 {
25 #include "dynlib_core.h"
26 #include "storeCommand.h" // command_origin_t
27 }
28
29 class CORE_IMPEXP Runner
30 {
31 public :
32     Runner(ast::Exp* _theProgram, ast::RunVisitor *_visitor) : m_theProgram(_theProgram), m_visitor(_visitor), m_iCommandOrigin(NONE), m_isInterruptible(true)
33     { }
34
35     Runner(ast::Exp* _theProgram, ast::RunVisitor *_visitor, command_origin_t _iCommandOrigin, bool _isInterruptible) : m_theProgram(_theProgram), m_visitor(_visitor), m_iCommandOrigin(_iCommandOrigin), m_isInterruptible(_isInterruptible)
36     { }
37
38     ~Runner()
39     {
40         delete m_theProgram;
41     }
42
43     ast::RunVisitor *getVisitor()
44     {
45         return m_visitor.get();
46     }
47
48     ast::Exp* getProgram()
49     {
50         return m_theProgram;
51     }
52
53     command_origin_t getCommandOrigin()
54     {
55         return m_iCommandOrigin;
56     }
57
58     bool isInterruptible()
59     {
60         return m_isInterruptible;
61     }
62
63 private :
64     ast::Exp* m_theProgram;
65     std::unique_ptr<ast::RunVisitor> m_visitor;
66     command_origin_t m_iCommandOrigin;
67     bool m_isInterruptible;
68 };
69
70 // static members to manage execution
71 class StaticRunner
72 {
73 public:
74     static void launch(void);
75     static void setRunner(Runner* _RunMe);
76     static Runner* getRunner(void);
77     static bool isRunnerAvailable(void);
78     static bool isInterruptibleCommand(void);
79     static void setInterruptibleCommand(bool _isInterruptible);
80     static command_origin_t getCommandOrigin();
81     static void execAndWait(ast::Exp* _theProgram, ast::RunVisitor *_visitor,
82                             bool _isInterruptible, bool _isPrioritary, command_origin_t _iCommandOrigin);
83     static void exec(ast::Exp* _theProgram, ast::RunVisitor *_visitor);
84
85 private:
86     static std::atomic<Runner*> m_RunMe;
87     static std::atomic<bool> m_bInterruptibleCommand;
88 };
89
90 extern "C"
91 {
92     void StaticRunner_launch(void);
93     int StaticRunner_isRunnerAvailable(void);
94     int StaticRunner_isInterruptibleCommand(void);
95     void StaticRunner_setInterruptibleCommand(int val);
96     command_origin_t StaticRunner_getCommandOrigin(void);
97 }
98
99 #endif /* !__RUNNER_HXX__ */