~l3on/ubuntu/precise/rkward/rebuild1

« back to all changes in this revision

Viewing changes to rkward/rbackend/rinterface.h

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Friedrichsmeier
  • Date: 2008-04-20 21:30:00 UTC
  • mfrom: (1.2.2 upstream) (3.1.9 hardy)
  • Revision ID: james.westby@ubuntu.com-20080420213000-fs4i8efmfc793bnn
new upstream release
closes: #475175
closes: #463348
closes: #475982

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
                          rinterface.h  -  description
3
3
                             -------------------
4
4
    begin                : Fri Nov 1 2002
5
 
    copyright            : (C) 2002 by Thomas Friedrichsmeier
 
5
    copyright            : (C) 2002, 2004, 2005, 2006, 2007 by Thomas Friedrichsmeier
6
6
    email                : tfry@users.sourceforge.net
7
7
 ***************************************************************************/
8
8
 
32
32
#define MUTEX_UNLOCK RInterface::mutex.unlock ();
33
33
#endif
34
34
 
35
 
class RKwatch;
36
35
class RCommand;
37
 
class RKwardApp;
 
36
class RKWardMainWindow;
38
37
struct RCallbackArgs;
39
38
class QTimer;
40
39
class RThread;
41
40
class RCommandReceiver;
42
41
struct REvalRequest;
 
42
struct RKWardStartupOptions;
43
43
 
44
44
/** This class provides the main interface to the R-processor.
45
45
 
86
86
 
87
87
/** returns the command currently running in the thread. Be careful when using the returned pointer! */
88
88
        RCommand *runningCommand ();
 
89
 
 
90
        bool backendIsDead ();
 
91
        bool backendIsIdle ();
89
92
public slots:
90
93
/** called periodically to flush output buffer in RThread */
91
94
        void flushOutput ();
94
97
        RThread *r_thread;
95
98
/** Timer to trigger flushing output */
96
99
        QTimer *flush_timer;
97
 
/** cancelling the command that is (or seems to be) currently running is tricky: In order to do so, we need to signal an interrupt to the RThread. We need this pointer to find out, when the command has actually been interrupted, and we can resume processing. */
 
100
/** canceling the command that is (or seems to be) currently running is tricky: In order to do so, we need to signal an interrupt to the RThread. We need this pointer to find out, when the command has actually been interrupted, and we can resume processing. */
98
101
        RCommand *running_command_canceled;
99
102
 
100
103
/** See \ref RThread::doSubstack (). Does the actual job. */
102
105
//      void processRGetValueRequest (RGetValueRequest);
103
106
/** See \ref RThread::doStandardCallback (). Does the actual job. */
104
107
        void processRCallbackRequest (RCallbackArgs *args);
105
 
friend class RKwardApp;
 
108
friend class RKWardMainWindow;
106
109
friend class RCommand;
107
 
/** pointer to the RKwatch. TODO: (re-)move this pointer */
108
 
        RKwatch *watch;
109
110
/** Used (once!) to start the RThread. Need to make this separate to avoid race conditions */
110
111
        void startThread ();
111
112
protected:
137
138
\endcode
138
139
 
139
140
You will note, that actually there are two RInterface::issueCommand functions, this one is obviously the one taking a QString and several further
140
 
parameters as argument. It is actually quite similar to the other RInterface::issueCommand function which takes an RCommand as a paramter. This convenience class basically just creates an RCommand with the same parameters as the constructor of RCommand (RCommand::RCommand), and then submits this RCommand. We'll discuss what an RCommand really is further down below. For now a good enough explanations is, that it's simply a container for a command.
 
141
parameters as argument. It is actually quite similar to the other RInterface::issueCommand function which takes an RCommand as a parameter. This convenience class basically just creates an RCommand with the same parameters as the constructor of RCommand (RCommand::RCommand), and then submits this RCommand. We'll discuss what an RCommand really is further down below. For now a good enough explanations is, that it's simply a container for a command.
141
142
 
142
143
The first parameter here is fairly obvious, the command-string the R backend should evaluate.
143
144
 
147
148
 
148
149
\section UsingTheInterfaceToRHandlingReturns A slightly more realistic example: Handling the result of an RCommand
149
150
 
150
 
Most of the time you don't just want to run a command, but you also want to know the result. Now, this is a tad bit more difficult than one might expect at first glance. The reason for this is that the R backend runs in a separate thread. Hence, whenever you submit a command, it generally does not get executed right away - or at least you just don't know, when exactly it gets executed, and when the result is available. This is neccessary, so (expensive) commands running in the backend do not block operations in the GUI/frontend.
 
151
Most of the time you don't just want to run a command, but you also want to know the result. Now, this is a tad bit more difficult than one might expect at first glance. The reason for this is that the R backend runs in a separate thread. Hence, whenever you submit a command, it generally does not get executed right away - or at least you just don't know, when exactly it gets executed, and when the result is available. This is necessary, so (expensive) commands running in the backend do not block operations in the GUI/frontend.
151
152
 
152
153
Ok, so how do you get informed, when your command was completed? Using RCommandReceiver. What you will want to do is inherit the class you
153
154
want to handle the results of RCommands from RCommandReceiver. When finished, the RCommand will be submitted to the (pure virtual) RCommandReceiver::rCommandDone function, which of course you'll have to implement in a meaningful way in your derived class.
332
333
This one tells the backend, that the command does not really need to be executed, and does not contain anything. You'll rarely need this flag, but sometimes it is useful to submit an empty command simply to find out when it is finished.
333
334
 
334
335
- RCommand::DirectToOutput
335
 
This is typically used in plugins: When you specify this modifier, the plain text result of this command (i.e. whatever R prints out when evaluating the command) will be added to the HTML output file. Remember to call RKwardApp::newOutput in order to refresh the output-window once the command has finished.
 
336
This is typically used in plugins: When you specify this modifier, the plain text result of this command (i.e. whatever R prints out when evaluating the command) will be added to the HTML output file. Remember to call RKWardMainWindow::newOutput in order to refresh the output-window once the command has finished.
336
337
 
337
338
- RCommand::GetIntVector, RCommand::GetStringVector, RCommand::GetRealVector
338
339
These are special modifiers helpful when transferring data from R to RKWard (used primarily in the editor classes and in conjunction with RCommand::Sync): They tell the backend to try to fetch the result as an array of int, char*, or double, respectively. For instance, if you know object "myobject" is an integer vector, you may get the data using