Simple setup for loading models

107 views
Skip to first unread message

Pavel K

unread,
Oct 13, 2015, 2:33:26 PM10/13/15
to Franca
Hello everybody,

I am working on tools for Common API C [1] that should enable
translating Franca IDL into C code.  The generated code would enable,
for example, invoking a method defined by a Franca interface via an
IPC mechanism while hiding the protocol details from the application.
Different IPC mechanisms such as D-Bus can be supported by independent
backends.

So far I have created a set of Maven/Tycho projects that create a
Eclipse UI plugin and a standalone binary to invoke the generator
functionality.  They currently accept one Franca file as their input
and are capable of producing several output files.  I also created a
test generator based on Franca Runtime, Xtend and integrated via JUnit
(as described in Franca User Manual).

Now I need to integrate the generator with 'real' Eclipse plugins (no
JUnit, etc.) that feed it with input files and store the generated
code in output files.  In order to load the Franca model, I currently
adopted (actually copied) the method loadModel() as implemented by
org.franca.connectors.idl.
tests.IdlTestBase:

protected FModel loadModel(String filename) {
    FrancaIDLStandaloneSetup.doSetup();
    ResourceSet resourceSet = new ResourceSetImpl();
    Resource res = resourceSet.getResource(URI.createFileURI(filename), true);
    FModel root = (FModel)res.getContents().get(0);
    return root;
}

I pass it the result of IFile.getLocation().toString() as filename and
it seems to work in my environment so far, but I wonder if this is the
intended way to implement model loading.

Any hints would be highly appreciated.


Regards,
--Pavel Konopelko

[1] http://git.projects.genivi.org/?p=common-api/c-poc.git;a=summary

Klaus Birken

unread,
Oct 14, 2015, 4:20:20 AM10/14/15
to Franca
Hi Pavel,

your code for model loading is the minimal way of loading an EMF model, which properly works for one-file models. However, if your Franca model uses imports and references to other Franca files, this will not work properly, as you are loading only one file and will get unresolved references.

Franca offers the FrancaPersistenceManager class, which supports loading and saving multi-file Franca models. It is important to use this (and most of the other Franca infrastructure) in the Google-Guice style, i.e., using injection. You might want to read my recent conversation with Sanjay in this group. 

For running your generator from inside an Eclipse IDE, you might want to look at the handler implementation of the Franca-to-D-Bus transformation, which does a quite similar task. It implements a context menu item detecting fidl-files and calling the transformation properly. It also executes the validation of input models. You should also look into plugin.xml of the same plug-in to find out how the handler is tied into the UI.

For running your generator standalone, you should use the example code I posted in the previous thread with Sanjay. It initializes the Franca infrastructure and creates an injector, which is then used to properly initialize the generator.

Hope this helps, regards,
Klaus

Reply all
Reply to author
Forward
0 new messages