1 /*
2  * SessionRmdNotebook.hpp
3  *
4  * Copyright (C) 2021 by RStudio, PBC
5  *
6  * Unless you have received this program directly from RStudio pursuant
7  * to the terms of a commercial license agreement with RStudio, then
8  * this program is licensed to you under the terms of version 3 of the
9  * GNU Affero General Public License. This program is distributed WITHOUT
10  * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
11  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
12  * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
13  *
14  */
15 
16 
17 #ifndef SESSION_RMARKDOWN_NOTEBOOK_HPP
18 #define SESSION_RMARKDOWN_NOTEBOOK_HPP
19 
20 #include <ctime>
21 
22 #include <core/BoostSignals.hpp>
23 #include <shared_core/json/Json.hpp>
24 
25 #define kChunkLibDir "lib"
26 #define kNotebookExt ".nb.html"
27 
28 namespace rstudio {
29 namespace core {
30    class Error;
31    class FilePath;
32 }
33 }
34 
35 namespace rstudio {
36 namespace session {
37 namespace modules {
38 namespace rmarkdown {
39 namespace notebook {
40 
41 enum ExecMode
42 {
43    // a single chunk is being executed interactively
44    ExecModeSingle = 0,
45    // multiple chunks are being executed in a batch
46    ExecModeBatch  = 1
47 };
48 
49 enum ExecScope
50 {
51    // an entire chunk is being executed
52    ExecScopeChunk   = 0,
53    // a section of a chunk is being executed (e.g. via Ctrl+Enter)
54    ExecScopePartial = 1,
55    // an inline R chunk is being executed
56    ExecScopeInline  = 2
57 };
58 
59 enum CommitMode
60 {
61    // changes should be committed to the cache immediately
62    ModeCommitted   = 0,
63    // changes should held for commit until save
64    ModeUncommitted = 1
65 };
66 
67 enum Condition
68 {
69    ConditionMessage = 0,
70    ConditionWarning = 1
71 };
72 
73 core::Error initialize();
74 
75 std::string notebookCtxId();
76 
77 struct Events : boost::noncopyable
78 {
79    // Document {0}, chunk {1} from context id, {2} from code, {3} label, {4} execution completed
80    RSTUDIO_BOOST_SIGNAL<void(const std::string&, const std::string&,
81                              const std::string&, const std::string&, const std::string&)>
82                 onChunkExecCompleted;
83 
84    // Document {0}, chunk {1} had console output of type {2} and text {3}
85    RSTUDIO_BOOST_SIGNAL<void(const std::string&, const std::string&, int,
86                 const std::string&)>
87                 onChunkConsoleOutput;
88 
89    RSTUDIO_BOOST_SIGNAL<void(const core::FilePath&, const core::FilePath&,
90                       const core::json::Value& metadata, unsigned ordinal)>
91                          onPlotOutput;
92    RSTUDIO_BOOST_SIGNAL<void(const core::FilePath&, const core::FilePath&,
93                       const core::json::Value& metadata)> onHtmlOutput;
94    RSTUDIO_BOOST_SIGNAL<void(const core::json::Object&)> onErrorOutput;
95    RSTUDIO_BOOST_SIGNAL<void(const core::FilePath&, const core::FilePath&,
96                       const core::json::Value& metadata)> onDataOutput;
97    RSTUDIO_BOOST_SIGNAL<void(Condition condition, const std::string& message)>
98                          onCondition;
99 };
100 
101 Events& events();
102 
103 } // namespace notebook
104 } // namespace rmarkdown
105 } // namespace modules
106 } // namespace session
107 } // namespace rstudio
108 
109 #endif // SESSION_RMARKDOWN_NOTEBOOK_HPP
110