In the previous blog posts I showed you how the basic features of Eclipse and Artop can be used to perform basic searches and navigation on AUTOSAR models. However, there are also often cases, where a user wants to perform more complex queries on AUTOSAR models.
E.g. we might want to find PDUs with specific characteristis (number of signals, certain ID range). In the example for this blog post, we want to find all SenderReceiverInterfaces in our model, that actually don't have any data element.
With Sphinx we can create complex scripts in a running Artop, written in Java or (even better) in Xtend. Xtend in especially suited for the job, since it has nice concepts for complex model queries. The required steps are:
To execute dynamic code from the workspace, Sphinx will look for implementations of WorkspaceWorkflow classes in the project, so we need a small implementation:
public class Query extends WorkspaceWorkflow {
new() {
children += new QueryComponent
}
}
The actual action happens in the Query component:
class QueryComponent extends AbstractModelWorkflowComponent {
override protected invokeInternal(WorkflowContext arg0, ProgressMonitor arg1, Issues arg2) {
val m = arg0.get(IModelWorkflowSlots.MODEL_SLOT_NAME) as List<EObject>
val c = m.get(0).eResource.resourceSet.allContents.filter(SenderReceiverInterface).
filter[it.dataElements.empty].toList
showResults(c)
}
}
The code for this example is actually very simple:
def protected showResults(Collection<? extends EObject> coll) {
Display.^default.syncExec([
NewSearchUI.activateSearchResultView();
val view = NewSearchUI.getSearchResultView();
])
val query = new ModelSearchQuery(null) {
override getResultLabel(int nMatches) {
"Script query"
}
};
val searchResult = new ModelSearchResult(query);
coll.forEach[searchResult.addMatch(new ModelSearchMatch(it))]
Display.^default.syncExec([
(NewSearchUI.getSearchResultView() as SearchView).showSearchResult(searchResult)
])
}
Using run configurations to run the queries
A workflow can be run either through the context menu of a element in the model explorer or through Eclipse run configurations. The context menu approach however does not support passing of arguments through an UI. So we will be using run configurations, even if we do not use workflow parameters right now (that will be shown in a later blog post). So we create a new "Sphinx workflow" and set the path to our Workflow class:
If we click the "Run" button, we will get the results in the search window. In our case, we are using the "Blueprint" model that is provided with Artop / AUTOSAR and find the following interfaces that have no data elements:
In the short series of three blog posts, we have shown how Eclipse and Artop can be used to configure a powerful tool for examining AUTOSAR models at no cost. In addition to the normal navigations and model searches, you can interactively use any Java-based language to write custom model queries - we recommend Xtend because of its powerful language features that support model navigation. The example above is quite simple, but it is very easy to write much more powerful queries.
In addition, you can use any Java-based libraries and frameworks to help you do the job. In a customer setting, we need to group PDUs according to various criteria and we make use of the JGraphT library.