-
Notifications
You must be signed in to change notification settings - Fork 141
RCloud RPC internals
oc.init.authenticate
(in ocaps.R) is the only exposed OCAP: function(v, mode="IDE")
which is attempting RC.authenticate(v)
followed by RC.auth.anonymous(v)
if unsuccessful. Those are the only functions to expose initial RCloud API to JS.
JavaScript functions are represented as structure("<random-string>", class="javascript_function")
. rserve.js converts any JS function by generating a random string, registering it in its internal hash (captured_functions
in rserve.js) and returning the above structure.
The JS functions are invoked via OOB_MSG
with list("<reference-string>", ...)
.
The OCAP setup_js_installer -> rcloud.setup.js.installer
has to be called to register installation JS code with the R side. This happens in setup_*authenticated_ocaps()
in rcloud.js and given the R side necessary JS function references to register new JS code.
R functions are registered via make.oc
(creating an OCref
object) which guarantees termination when the function is called and will return an R object of class OCAP-eval-error
on error. Alternatively, it is possible to use Rserve:::ocap(f, name)
directly, but that doesn't guarantee termination and thus use RESP_ERR
with error code -1 (encoded as 127). All OCref
objects are transformed into JS functions which require a continuation of the form function(err, v)
.
Note that rserve-js doesn't treat OCAP-eval-error
in any special way, so OCAPs created with make.oc
only signal err
on communication errors, not on R evaluation errors.