Franca model API's

383 views
Skip to first unread message

Sanjay Bharadwaj

unread,
Sep 29, 2015, 12:34:58 PM9/29/15
to Franca
Hi team,

I have been working on a project which converts a User-defined IDL (UDL) to Franca. 
Some of the questions I have are below - 

1. Can I use Franca libraries API's to create Franca model?
Example - As I parse the UDL and find a corresponding keyword, I need to create a Franca interface and in UDL if I have certain operations, I need to create Franca methods and  finally I need add these methods to the previously created Franca interface.  
Similarly all the properties must be set using API's. (I ask about all the properties because setter functions for all the attributes are not present in the existing code)
I use Franca 0.9.1, in this version, there are no set methods for every Franca model elements.

2. I have the Franca library function

FDModelHelper.instance().loadmodel(inputfile);

this functions loads already existing Franca model, is there any other function that can generate the *.fidl and *.fdepl files based on fmodel? This way I can generate the interface files from the models.

Please let me know,
Thanks in anticipation of your response,
Sanjay Bharadwaj


kbi...@itemis.de

unread,
Sep 30, 2015, 2:20:41 AM9/30/15
to Franca
Hi Sanjay,

ad 1) I suggest to look at some existing code as an example of how to create a Franca IDL model. You may check out the D-Bus-to-Franca transformation in the standard repository [1]. It uses Xtend "create" methods, which provide a built-in hash ensuring that input model elements which already have been transformed will not be transformed again, but just the result from the first transformation will be returned. If you build a transformation in Java, you probably end up with manually coded hashes.

Regarding the actual creation of model objects, you have to use the factory class, e.g.:

FrancaFactory::eINSTANCE.createFMethod

for creating a Franca method. There even should be setters for all the attributes, in Java e.g.:

FMethod m = FrancaFactory.eINSTANCE.createFMethod();
m.setName("foo");

There is also a chapter in the User's Guide (latest release is 0.9.2.0) describing the model API and how to create objects.

ad 2) A model can be saved to file with FrancaPersistenceManager.saveModel().

Regards,
Klaus


[1] https://github.com/franca/franca/blob/master/plugins/org.franca.connectors.dbus/src/org/franca/connectors/dbus/DBus2FrancaTransformation.xtend

Sanjay Bharadwaj

unread,
Oct 7, 2015, 9:08:23 AM10/7/15
to Franca
Hi Klaus,

Good day!
thank you for the inputs. 
I tried using the FrancaPersistenceManager.saveModel(), but it has a lot of dependencies, I guess it uses google Guice package.
I am unable to save a model, could you please provide me an example to save the model?

thanks,
Sanjay

Klaus Birken

unread,
Oct 13, 2015, 7:08:45 AM10/13/15
to Franca
Hi Sanjay,

please have a look at line 99ff in the source file of the DBus-to-Franca's UI: see here. You will need Guice anyway for any project built on top of Xtext. You can also build a plain Java class which runs a Franca trafo on the command line, see example code below.

Regards,
Klaus


private static Injector injector;
	
public static void main(String[] args) throws Exception {
	injector = new FrancaIDLStandaloneSetup().createInjectorAndDoEMFRegistration();
	int retval = injector.getInstance(FrancaStandaloneGen.class).run(args);
	if (retval != 0)
		System.exit(retval);
}

// injected fragments
@Inject	FrancaPersistenceManager fidlLoader;
@Inject	MyGenerator generator;

public int run(String[] args) throws Exception {
	Options options = getOptions();
	// put loading of the model(s) and your transformation here
}

Sanjay Bharadwaj

unread,
Oct 13, 2015, 12:47:42 PM10/13/15
to Franca

Hi Klaus,


Thank you for the reply but even the basic code like this throws error. 

I am trying to generate a very simple model.


I did look into the dbus code you have provided, but even there you call the same method.

I just run the below code as Java application


I also have doubt on the way I build the model, please let me know if the below way of creation of model is correct?




please let me know if you know the reason behind the error,

I hope its not something to do with the eclipse installation because I used the latest eclipse release.


Thank you in anticipation of your response,


Best regards,

Sanjay


Sanjay Bharadwaj

unread,
Oct 13, 2015, 12:59:29 PM10/13/15
to Franca
I even tried this, with the injecters

Klaus Birken

unread,
Oct 14, 2015, 4:06:57 AM10/14/15
to Franca
Hi Sanjay,

the version with the @Inject is a little better than the previous one, but it won't work either. Guice injectors work like this: From somewhere you have to get a fully configured injector. In order to create any object in your system, you have to use the injector instead of using "new" and the constructor. Creating objects that way will allow the injector to find all @Inject annotations and insert real object references there.

In your example. an instance of FModel_Generate is created using "new", which doesn't involve any injector. Thus, the class member Mgr annotated with @Inject will not be initialized (this would be the job of an injector).

In my example posted above, I used 

injector = new FrancaIDLStandaloneSetup().createInjectorAndDoEMFRegistration();

in order to create a proper injector (and initialize the language infrastructure for Franca, which is also missing in your code example). Afterwards, I use the injector to create the instance of the FrancaStandaloneGen class. The injector will then fill in all the proper attributes in the newly created object.

int retval = injector.getInstance(FrancaStandaloneGen.class).run(args);

In all code which follows (the run() method and all methods called from there), you also have to ensure that new objects are created using the injector.

Hope this helps,
Klaus
Reply all
Reply to author
Forward
0 new messages