1 /*
2  * REmbedded.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 #ifndef R_EMBEDDED_HPP
17 #define R_EMBEDDED_HPP
18 
19 #include <string>
20 
21 typedef struct SEXPREC *SEXP;
22 
23 #include <R_ext/Boolean.h>
24 #include <R_ext/RStartup.h>
25 
26 #ifdef _WIN32
27 typedef char CONSOLE_BUFFER_CHAR;
28 #else
29 typedef unsigned char CONSOLE_BUFFER_CHAR;
30 #endif
31 
32 namespace rstudio {
33 namespace core {
34    class Error;
35    class FilePath;
36 }
37 }
38 
39 namespace rstudio {
40 namespace r {
41 namespace session {
42 
43 struct Callbacks
44 {
45    void (*showMessage)(const char*);
46    int (*readConsole)(const char *, CONSOLE_BUFFER_CHAR*, int, int);
47    void (*writeConsoleEx)(const char *, int, int);
48    int (*editFile)(const char*);
49    void (*busy)(int);
50    int (*chooseFile)(int, char *, int);
51    int (*showFiles)(int, const char **, const char **, const char *,
52                     Rboolean, const char *);
53    void (*loadhistory)(SEXP, SEXP, SEXP, SEXP);
54    void (*savehistory)(SEXP, SEXP, SEXP, SEXP);
55    void (*addhistory)(SEXP, SEXP, SEXP, SEXP);
56    void (*suicide)(const char*);
57    void (*cleanUp)(SA_TYPE, int, int);
58 };
59 
60 struct InternalCallbacks
61 {
InternalCallbacksrstudio::r::session::InternalCallbacks62    InternalCallbacks() : suicide(nullptr), cleanUp(nullptr) {}
63    void (*suicide)(const char*);
64    void (*cleanUp)(SA_TYPE, int, int);
65 };
66 
67 void runEmbeddedR(const core::FilePath& rHome,
68                   const core::FilePath& userHome,
69                   bool quiet,
70                   bool loadInitFile,
71                   SA_TYPE defaultSaveAction,
72                   const Callbacks& callbacks,
73                   InternalCallbacks* pInternal);
74 
75 core::Error completeEmbeddedRInitialization(bool useInternet2);
76 
77 } // namespace session
78 } // namespace r
79 } // namespace rstudio
80 
81 
82 #endif // R_EMBEDDED_HPP
83 
84