Reuse RStudio environment with RInside - c++

Background/what I've tried:
My end goal is to be able to dispatch some C++ code (a rather large physics-simulation application) from RStudio and while that C++ code is running have it repeatedly talk to an embedded R instance in order to make decisions. Once complete the C++ code would return results back to R
What is working is both parts separately. Using Rcpp I can launch the physics simulation from RStudio and have the C++ code return information back to RStudio assuming the C++ code doesn't talk to an embedded R instance. With RInside/Rcpp I was also able to get the C++ program to run and query an embedded R instance as it goes about its business.
When I try to combine the two, I get an error that an R instance is already initialized - which of course makes sense, this is the RStudio instance. I tried looking at RInside::InstancePtr(), but it doesn't look like RInside::instance_m is set by RStudio
Question: Is it possible to re-use an existing RStudio R instance as an embedded instance for use with RInside?
It seems likely that this is just not possible, that the one R instance can't be accepting input from the running C++ program while at the same time waiting for that same C++ program to return.
The reason for the above structure is that I would like R be able to dispatch many physics simulations with different parameters and aggregate those results. I would also like certain decision-making logic (the embedded R files) be able to be written in R rather than in C++ to make it easier for users. Those are what guided me to the above idea for a solution

Related

Is there a way to send C/C++ commands using Johnny-Five?

Currently running a number of ESP8266s flashed with StandardFirmataWiFi using a central linux machine running J5. So instead setting up a bunch of micro-controllers to run autonomously, they are all WiFi enabled and under the command of a single machine.
So far this has been working very well. I'm very familiar with JS, not super familiar with C/C+
But occasionally I find example code in C/C+ for which I can't find a J5 equivalent.
Question:
Is it possible to issue C/C+ (or even Python) commands from Johnny-Five? So in other words instead of the central machine issuing J5-only commands to the micro-controllers, is there way to have J5 send C/C+ snippets? If so, that would make it easier to work directly with demo/community-shared code while also making it easier for JS-fluent developers to transition toward C.
C and C++ are compiled languages. That means you need a compiler in order to translate C or C++ code into something that can be run on a processor. Because of that there's no eval() in C or C++, no function which can text a chunk of text and process it as C or C++ code.
So there cannot be a way for Johnny-Five or anything else to send C or C++ code to an ESP8266 - the ESP8266 is not capable of running a C or C++ compiler and cannot translate C code into something it can execute. You could potentially transfer compiled ESP8266 code but there are so many difficulties with that approach that you shouldn't waste time considering it.
Like Javascript, Python is an interpreted language. It has an eval() function that you can execute a string as Python code. If you can arrange to have a handler on the ESP8266 receive a string and then eval it, you could send Python commands from a remote program.
Beware that there are huge gaping security issues with doing something like that - you're literally allowing a remote program to execute whatever it feels like on the ESP8266.

Creating a Launcher and sending info to second program

I have created a program that extracts data from a racing game and sends it to a speed gauge cluster. I call it the transfer program.
I need a simple user-friendly User Interface to start the transfer program, set some variables and choose a COM Port. At the moment I'm trying to do it with a C++ Windows Forms Application in a CLR Project on Microsoft Visual Studio 2015. When I tried to do it directly (creating the UI in the same project as the transfer program) I just get too many errors that I have no idea where they come from or why they are there.
So I've decided maybe I could try creating some sort of launcher, i.e. a completely different program that is only the UI to start the transfer program and send a few user-set variables to it on startup as well as choose a COM Port to communicate on.
Any idea on how to start on this? How do I execute the transfer program from the Launcher? How do I send variables and data to it?
Thank you very much!
There are basically two ways to pass information to your transfer program.
For simple use cases, just pass the values along on the command line. If you're still using the CLR, this is done using System.Diagnostics.Process. A nice example can be found in this answer: https://stackoverflow.com/a/33633148/127826
Use a shared configuration file. So the user interface loads the values from the config and also saves the file before executing the transfer program. The transfer program then reads the same configuration file to get the values it needs.
The second approach is far more flexible and is what I would use.

is there a way to clone a run-time program to another server

Suppose I'm running a small program on the server. for example, a random number generator and sending the result to a client every second. I know that my server is about to be turned off. Is there a way to clone the program to another server so that the client doesn't notice it?
ideally i would want to save the dynamic object of the small program, send it to another server and re-link it with another server using dynamic linking. If that is possible then the question is how to save/hibernate that small program.
another obvious solution is to serialize the all states of the project and send it to another server but that would involve changing the small program, which is not desirable.
I'm not even sure what keywords to search for.
(i would like to avoid system calls, if possible. if not then it's fine.)
update (1)
the defult platform is linux but i'm also interested in embedded systems and nacl

Need guidance in non C/C++ based graphics interface

I have prepared a program launcher in C++ (the only language I know), which accepts strings as program trigger.
But however hard I try I'm unable to give it a GUI like look; using graphics.h's graph functions creates graphics but in cmd like window.
All I need is a small widget/window like thing that sits on the desktop where a user can type the command string (and error messages can be displayed as usual).
Can I get a code snippet for such a widget/window?
The input string may be copied to a .txt file and my prog will read it from there.
P.S.- I'm a beginner & rookie so please avoid complex alternatives.
Well, one of the easiest options in my opinion is to use .NET Framework:
http://10rem.net/blog/2010/03/04/my-first-windows-cplusplus-application-in-ages-hello-world-in-win32-with-visual-cplusplus-2010
http://msdn.microsoft.com/en-us/library/bb384845.aspx

How to read 3rd party application's variables from memory?

I'm trying to read variables from memory. Variables, that doesn't belong to my own program. For instance, let's say I have this Adobe Shockwave (.dcr) application running in browser and I want to read different variables from it. How it's being done? Do I need to hook the process? But it's running under virtual machine, so I don't know how to do it.
This task is pretty much trivial in normal w32 applications (as it is mainly just
CBT-hooking / subclassing), but as I mentioned before, I've got no idea how it's being
done with flash / shockwave.
I'm using C++ (VS9) as my development-environment, in case you wish to know.
Any hints would be highly appreciated, so thank you in advance.
Best regards,
nhaa123
If you're trying to do it manually just for one or two experiments, it's easy.
Try a tool like Cheat engine which is like a free and quick and simple process peeker. Basically it scans the process's memory space for given key values. You can then filter those initial search hits later as well. You can also change those values you do find, live. The link above shows a quick example of using it to find a score or money value in a game, and editing it live as the game runs.
without having debug Binaries/DLLs of the Apps, your only chance is asking some hackers.
Normally you can connect to a process with a debugger, but without the debugging symbols of the binaries you don't see any variable names - just memory addresses.
Further the Flash/Shockwave code runs inside a sandbox inside the browser to prevent security holes by manipulated Flash code. So you don't have a real chance to get access to the running Flash code / to the plugin executing the Flash code - except you have a manipulated version of such a plugin.
So your task is quite hard to solve without using less legal methods. The next hard thing is the virtual machine - this could be solved by implementing your app as a client/server solution, where the "inspector" / watchdog runs as server inside the virtual machine and the client requesting the variable status/content running on your normal host. The communication could be done as simple socket connection.
If you have the chance to write your own Flash/Shockwave plugin, you maybe could be able to see contents of variables.
Sorry, that I cannot help you any further.
ciao,
3DH