osate / osate2

Open Source AADL2 Tool Environment
http://osate.org
Eclipse Public License 2.0
39 stars 8 forks source link

Checking properties for connection instances #252

Closed backesj closed 11 years ago

backesj commented 11 years ago

Currently the code for getting the properties from the declarative model of a given connection instance is commented out. The commented code starting at line 741 of "org.osate.aadl2/src/org/osate/aadl2/instance/impl/ConnectionInstanceImpl.java" is shown below. How can I currently access the values of properties applied to connection instances?

// XXX: [AADL 1 -> AADL 2] Added to make property lookup work.
//  protected void getPropertyValueFromDeclarativeModel(final Property property,
//          final AadlPropertyValue apv) throws InvalidModelException {
//      /*
//       * If there is more than one declarative spec that influences this
//       * instance object, then we pick the first one that has the property we
//       * are looking for. Semantic checks at the time the instance model is
//       * generated guarantee that it deosn't matter which of the declarative
//       * objects with the property value we look at. Right now this
//       * multiple-spec case only applies to semantic connections.
//       */
//      /*
//       * Sanity check: if there are no declarative connections then we have
//       * nothing to do! If the number of connections does not match the number
//       * of connection contexts then the model is ill-formed and we should not
//       * proceed.
//       */
//      final List<Connection> connections = getConnections();
//      final List<ComponentInstance> contexts = getConnectionContexts();
//      if ((connections.size() > 0) && (connections.size() == contexts.size())) {
//          /*
//           * This is sleazy: because using getPropertyValueInternal mutates
//           * the pva, we can't use it repeatedly until we find the particular
//           * declarative element that gives us the property value. If we do,
//           * we will corrupt the pva. But we cannot directly use
//           * getPropertyValue() either because it will trigger a cyclic
//           * dependency error. So we have to create a new PVA for each lookup;
//           * in this case we know that we always want a DeclarativeMPVA
//           * because the whole point is that we now have delcarative model
//           * elements.
//           * 
//           * If all of them are "not present", then the value is not present,
//           * so we can pick an arbitrary declarative element to do the real
//           * work with a "normal" call to getPropertyValueInternal. If some of
//           * the values are present, then we can also pick an arbitrary one to
//           * use for getPropertyValueInternal.
//           */
//          Connection definingConnection = null;
//          ComponentInstance definingConnectionContext = null;
//          final Iterator<Connection> connIter = connections.iterator();
//          final Iterator<ComponentInstance> ctxtIter = contexts.iterator();
//          while ((definingConnection == null) && connIter.hasNext()) {
//              final Connection conn = connIter.next();
//              final ComponentInstance ctxt = ctxtIter.next();
//              final AadlPropertyValue apv1 = new AadlPropertyValue(property);
//              conn.getPropertyValueInternal(property, apv1, true);
////                apv.addDefaultValue(property.getDefaultAadlValue());
//
//              /*
//               * If the value exists for this connection, then we choose it.
//               * If the value is modal then make sure it exists for at least
//               * one mode.
//               */
//              if (apv1.isModal()) {
//                  final Collection<ReflectiveAadlPropertyValue> vals = apv1.getAllValues();
//                  for (final Iterator<ReflectiveAadlPropertyValue> valIter = vals.iterator(); valIter.hasNext();) {
//                      final AadlPropertyValue apv = valIter.next();
//                      if (!apv.isNotPresent() && apv.exists()) {
//                          definingConnection = conn;
//                          definingConnectionContext = ctxt;
//                          break;
//                      }
//                  }
//              } else if (!apv1.getValue().isNotPresent()) {
//                  definingConnection = conn;
//                  definingConnectionContext = ctxt;
//              }
//          }
//          /*
//           * If definingConnection == null then all the values are not
//           * present, so we arbitrarily use the first component to compute the
//           * property value.
//           */
//          if (definingConnection == null) {
//              definingConnection = connections.get(0);
//              definingConnectionContext = contexts.get(0);
//          }
////            apv.pushCurrentComponent(definingConnectionContext);
//          try {
//              definingConnection.getPropertyValueInternal(property, apv, true);
//          } finally {
////                pva.popCurrentComponent();
//          }
//      }
//  }
juli1 commented 11 years ago

Hello, In fact, the ConnectionInstance object contains connection reference. Then, the properties are then taken from the ConnectionReference and their related connection object from the declarative model. If you have some problems for accessing the properties of your model, lease send a model example so that we can reproduce the issue. Thanks.

backesj commented 11 years ago

I'm still unclear on what function to use to grab this information from a ConnectionReference (Something in "org.osate.xtext.aadl2.properties.util.PropertyUtils.java")? Could you point me to somewhere in the osate source or in a plugin where a ConnectionReference is queried for the value of one of it's properties?

On Mon, Jul 1, 2013 at 3:17 PM, Julien notifications@github.com wrote:

Hello, In fact, the ConnectionInstance object contains connection reference. Then, the properties are then taken from the ConnectionReference and their related connection object from the declarative model. If you have some problems for accessing the properties of your model, lease send a model example so that we can reproduce the issue. Thanks.

— Reply to this email directly or view it on GitHubhttps://github.com/osate/osate2-core/issues/252#issuecomment-20307375 .

reteprelief commented 11 years ago

You just use the helper methods to retrieve properties found in GetProperties. These helper methods are for many predeclared properties. They make use of lower level methods defined in PropertyUtils. For example, the flow latency analysis retrieves the latency value on a connection instance by calling res = GetProperties.getLatencyinMicroSec(connInstance);

This method is defined as public static double getLatencyinMicroSec(final NamedElement ne) { Property Latency = lookupPropertyDefinition(ne,CommunicationProperties._NAME, CommunicationProperties.LATENCY); UnitLiteral microSecond = PropertiesLinkingService.findUnitLiteral(Latency, AadlProject.US_LITERAL); return PropertyUtils.getScaledRangeMaximum(ne, Latency, microSecond,0.0); }

From: backesj [mailto:notifications@github.com] Sent: Wednesday, July 03, 2013 11:01 AM To: osate/osate2-core Subject: Re: [osate2-core] Checking properties for connection instances (#252)

I'm still unclear on what function to use to grab this information from a ConnectionReference (Something in "org.osate.xtext.aadl2.properties.util.PropertyUtils.java")? Could you point me to somewhere in the osate source or in a plugin where a ConnectionReference is queried for the value of one of it's properties?

On Mon, Jul 1, 2013 at 3:17 PM, Julien notifications@github.com<mailto:notifications@github.com> wrote:

Hello, In fact, the ConnectionInstance object contains connection reference. Then, the properties are then taken from the ConnectionReference and their related connection object from the declarative model. If you have some problems for accessing the properties of your model, lease send a model example so that we can reproduce the issue. Thanks.

— Reply to this email directly or view it on GitHubhttps://github.com/osate/osate2-core/issues/252#issuecomment-20307375 .

— Reply to this email directly or view it on GitHubhttps://github.com/osate/osate2-core/issues/252#issuecomment-20421177.

backesj commented 11 years ago

So I'm using the "PropertyUtils.getSimplePropertyValue(final NamedElement ph, final Property pd)" method, which works fine for component instances (and is called by the "PropertyUtils.getScaledRangeMaximum()") you suggested above. However, this method relies on the "getPropertyValueFromDeclarativeModel(final Property property, final PropertyAcc pas)" method implemented in "InstanceObjectImpl.java". It seems that the "getPropertyValueFromDeclarativeModel(final Property property, final PropertyAcc pas)" used to be overridden in "ConnectionInstanceImpl.java" but this is now longer the case (as stated my original post). I will try to develop a simple model where this method fails to return the correct results and post again.

backesj commented 11 years ago

After generating an instance model for the following model, I call the following method:

PropertyUtils.getSimplePropertyValue(el, prop);

where "el" is the ConnectionInstanceImpl corresponding to the "TA.data_out -> TB.data_in" connection in the instantiated process "P", and "prop" is the PropertyImpl corresponding to "TEST_PROPS::Test_Prop" property. The method throws a PropertyNotPresentException exception.

TEST_PROP.aadl

property set TEST_PROPS is
     Test_Prop: aadlboolean applies to (port, connection);
end TEST_PROPS;

TEST.aadl

package TEST
public
with TEST_PROPS;

system test
end test;

system implementation test.Impl
    subcomponents
        P : process test_proc.Impl;

end test.Impl;

process test_proc
end test_proc;

process implementation test_proc.impl
    subcomponents
        TA: thread tA;
        TB: thread Tb;

    connections
        port TA.data_out -> TB.data_in;
end test_proc.Impl;

thread tA

    features
    data_out: out data port;

    properties
    TEST_PROPS::Test_Prop => true applies to data_out;

end tA;

thread tB
features
    data_in: in data port;

    properties
    TEST_PROPS::Test_Prop => true applies to data_in;
end tB;

end TEST;
backesj commented 11 years ago

I should also note that the following code throws the same exception:

for(ConnectionReference ref : el.getConnectionReferences())
    PropertyUtils.getSimplePropertyValue(ref, prop);
juli1 commented 11 years ago

Hello,

Do you still experience issues ? If yes, is it possible to explain the issue because I am not able to reproduce this issue. Thanks in advance for letting us know.

Regards.

agacek commented 11 years ago

John, in your provided example the property is attached the port, not the connection. In this case, you should be able to get the property with

PropertyUtils.getSimplePropertyValue(el.getSource(), prop)

Similarly you can use el.getDestination() for the other side of the connection. If you want to attach the property to the connection you can do either:

process implementation test_proc.impl
    subcomponents
        TA: thread tA;
        TB: thread Tb;

    connections
        c1 : port TA.data_out -> TB.data_in;

    properties
        TEST_PROPS::Test_Prop => true applies to c1;
end test_proc.Impl;

or

process implementation test_proc.impl
    subcomponents
        TA: thread tA;
        TB: thread Tb;

    connections
        port TA.data_out -> TB.data_in {
            TEST_PROPS::Test_Prop => true;
        };
end test_proc.Impl;

In either case, you can then look up the property in the instance model using

PropertyUtils.getSimplePropertyValue(el, prop)