Connecting a C++ Process to the Web

End of last year me and my colleagues had the chance to submit a paper to the 19th “Methods and Description Languages for Modelling and Verification of Circuits and Systems” workshop (in German “Methoden und Beschreibungssprachen zur Modellierung und Verifikation von Schaltungen und Systemen” – in short MBMV). This year the conference took place at the University of Freiburg.

Our paper with the title “Connecting a C++ based Structural Verification Tool to the Web” describes an approach of how a C++ application can easily be connected to the web. In short – a web server and an interpreter (in our case a PHP interpreter) are integrated into the C++ process (dynamically linked at runtime) to allow direct access to the data structures and functions of the C++ process from the browser. The web front-end is developed using standard web technologies (PHP, JavaScript, CSS, …). This allows the usage of well known frameworks to develop the front-end.

In principle we avoid exporting any data from the C++ process to a database since archiving data in this context is not important. Instead we need direct insight into certain data of the process while the C++ application is still running. In our case we use data from the C++ application to present an electrical circuit to the user directly in the browser (using SVG). The rendering of the circuit itself is done by the C++ application. The generated SVG is then returned to the browser (see figure).

One important idea behind the concept is that the interface between PHP and the C++ process is automatically generated using SWIG – the so called “Simple Wrapper and Interface Generator”. SWIG is an open source tool which currently supports the mapping from C/C++ to about 24 different scripting languages (c.f. www.swig.org). Therefore, in principle the usage of PHP could be replaced by any other supported scripting language like Python or Perl.

In the end, the only thing left to the developer is writing the SWIG interface file which lists the classes and functions which should be available from the scripting language. The syntax of this file is very close to the C++ syntax. The concept allows a web developer to write common PHP/Python code to model the front-end. If data or functionality from the C++ process is required the developer simply uses the generated PHP interface.

Note that SWIG supports access to most STL containers out of the box (depending on the scripting language). Hence, it is for example very simple to iterate over an STL vector in PHP and the further process the content in the scripting language – for example returning it in JSON format.

Download paper

Last updated: June 16, 2022 at 14:17 pm

Leave a Reply

Your email address will not be published.