Using the MetaEdit+ API from C and C++ with gSOAP
The MetaEdit+ API is accessed as a WebService with SOAP calls. Almost all programming languages have a SOAP library, which enables you to call MetaEdit+ API functions in the same way as native functions. The free gSOAP library provides this funtionality for C and C++.
The instructions and ancillary files below are for the latest version of gSOAP at the time of writing. Some details may change with newer versions, so for first time use it is recommended to start with exactly the version specified below.
- Download the 2.7.9l version of gSOAP with win32 binaries from the Download tab on
http://sourceforge.net/projects/gsoap2 and expand it into the
root of C: to form c:\gsoap-win32-2.7
- Copy the enclosed MetaEditAPI-animate.wsdl file to "C:\gsoap-win32-2.7\bin".
This is just the animate command from the full WSDL: having just one
operation at this stage will make learning gSOAP easier.
- In that directory, run the following two commands: the first produces
the file used as argument for the second:
wsdl2h -c MetaEditAPI-animate.wsdl
-c means for C rather than C++.
soapcpp2 -C MetaEditAPI-animate.h
-C means only generate for the client-side, not the server side.
- As a result you should get the following files in this directory:
(There will also be some other generated files which you don't need).
- Copy these files to your own directory for C programs
- Also copy stdsoap2.* there from C:\gsoap-win32-2.7 — these are the
generic gSOAP library files
- Add the attached helper files from MetaCase for easier calling of the
animate API function:
Add soapApi.c, .h, .o to your Makefile, and you can use "struct meoop" rather than the generated "struct ns2__MEOop" from soapStub.h, which seemed to give us problems when compiling.
- Make a C program that calls the soap_animate function from soapApi.c
with meoop structs whose values correspond to an object and a graph in your
repository. The attached "C animation.rep" generator, run on any MetaEdit+
graph, should produce something that works: Metamodel | Generator Editor;
Generator | Change Graph Type | Graph; Generator | Read from File... | C
Animation.rep; Generator | Save; Generator | Generate | (choose any graph,
and save the results to a C file, e.g. animate.c).
- Open the MetaEdit+ API tool (Repository | API Tool) and press the Start
- Compile and run your generated animate.c file along with the other files in that directory (a win32 console app will suffice). If it does not open the chosen graph and highlight the objects, use the Update Log and View Entry XML buttons to see what MetaEdit+ received. If there is nothing, check your firewall settings on your local machine: they must allow the C program to communicate with MetaEdit+ on port 6390 (or whatever port you specifiied in the WSDL file and API Tool).
The gSOAP documentation in the doc directory of the download should help you proceed, e.g. to improve the animate program by initializing and closing gSOAP once rather than as part of each animate call, or to switch from C to C++ (rerun step 3 without the -c parameter in wsdl2h).
To use any API calls other than animate(), you must replace the WSDL file in step 2 with the full WSDL file saved from the API Tool in MetaEdit+, and repeat steps 3-5.