Is there any way to develop a c++ backend service?
We want to migrate our project to theia. Our project is written in C++. I have seen some extensions that can be developed by java like GLSP have a java version and a node version. But I have never seen an extension written by c++, only the logic code in c++ is OK. I know one way is to spawn a child c++ process and forward JSON-RPC messages between the frontend and the c++ process, but implementing this from zero is time-consuming for us, Could anyone give some idea or a simple demo is a big help?
what is the current way you are interacting with your C++ service? Theia doesn’t necessarily require you to use JSON-RPC to communicate with your service. The usual approach would be to interact with the Theia backend via JSON-RPC (using the proxy method), and then let the backend do whatever it likes with the information that it receives.
Forwarding via JSON-RPC is one solution, but there are other ways to accomplish communication to another process as well. We have been recently doing something similar in the elk-libavoid router algorithm, where we just communicate using a custom stdio “protocol”.
Note that it’s possible to make Node native extensions:
You’d need to expose the relevant functions from C++ to JS and then hook everything up using Inversify in the backend like any other component.
I don’t know if this method is the most efficient for what you have, but it’s an option. It also would only work on the Node/Electron backend, the components wouldn’t be able to be directly loaded in the frontend/browser.
We have not used any way to interact with c++ currently. We found theia is a better cross-platform for us, but our backend program was written in c++ before, and we want to build our UI throw theia, We dot have any experience in combining c++ and theia , so want to get some help
Thank you very much for your reply, I read the link, and It is indeed useful, Is there any project used this way in GitHub? A demo project will save us a lot of time if possible.
There is no Theia extension written in C++ that I know of, but since you can create JS functions and even objects you would just implement things in such a way that it follows Theia’s extension model and contributions and bind those using Inversify just as you would do with any other JS class.
I found the following examples for generic functionality written in C++:
Note that Theia implements a simple C addon to interface with Electron’s
I try your method, but get some errors when building. My steps as follow
- create a theia extension named “cppaddon” to theia blueprint template project
- Run “yarn build” and everything is ok
- add a binding.gyp file to appaddon extension,file content is
- add a hello_world.cc file
- build c++ addon by script in package.json
- My project tree
- Finally I run “yarn build” and get the error
8.I do not know how to solve this,It seems that the project can not load addon.node file. Could you give me some help?
@wss are you trying to load the node.js native module into the browser code of your application? Only the node (backend) part of your application is capable of loading
*.node files. This is why webpack complains, as it tries to bundle the
.node file into the browser build.