Skip to content

Commit

Permalink
Hierachical Modes + variables in the condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Rima_a authored and Rima_a committed Aug 20, 2014
1 parent d73612d commit 351dd7c
Show file tree
Hide file tree
Showing 21 changed files with 1,098 additions and 213 deletions.
3 changes: 2 additions & 1 deletion jdeeco-core/model/RuntimeModel.ecore
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
<eStructuralFeatures xsi:type="ecore:EReference" name="triggers" upperBound="-1"
eType="#//Trigger" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="state" lowerBound="1" eType="#//ModeState"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="parent" eType="#//ComponentProcess"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="children" upperBound="-1"
eType="#//ComponentProcess"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EEnum" name="ParameterDirection">
<eLiterals name="IN"/>
Expand Down
2 changes: 1 addition & 1 deletion jdeeco-core/model/RuntimeModel.ecorediag
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@
</children>
<styles xmi:type="notation:ConnectorStyle" xmi:id="_H4bKUSE4EeS9C8M9BxJk1g" lineColor="4210752"/>
<styles xmi:type="notation:FontStyle" xmi:id="_H4bKUiE4EeS9C8M9BxJk1g" fontColor="4210752" fontName="Segoe UI" fontHeight="10"/>
<element xmi:type="ecore:EReference" href="RuntimeModel.ecore#//ComponentProcess/parent"/>
<element xmi:type="ecore:EReference" href="RuntimeModel.ecore#//ComponentProcess/children"/>
<bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_H4bKUyE4EeS9C8M9BxJk1g" points="[22, 3, 21, 48]$[84, 3, 83, 48]$[102, 3, 101, 48]$[102, -45, 101, 0]$[22, -45, 21, 0]"/>
<sourceAnchor xmi:type="notation:IdentityAnchor" xmi:id="_H4whgCE4EeS9C8M9BxJk1g" id="(0.8641975308641975,0.736)"/>
<targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="_H47goCE4EeS9C8M9BxJk1g" id="(0.8703703703703703,0.368)"/>
Expand Down
2 changes: 1 addition & 1 deletion jdeeco-core/model/RuntimeModel.genmodel
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute RuntimeModel.ecore#//ComponentProcess/isActive"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference RuntimeModel.ecore#//ComponentProcess/triggers"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute RuntimeModel.ecore#//ComponentProcess/state"/>
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference RuntimeModel.ecore#//ComponentProcess/parent"/>
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference RuntimeModel.ecore#//ComponentProcess/children"/>
</genClasses>
<genClasses ecoreClass="RuntimeModel.ecore#//Parameter">
<genFeatures notify="false" createChild="false" propertySortChoices="true" ecoreFeature="ecore:EReference RuntimeModel.ecore#//Parameter/knowledgePath"/>
Expand Down
4 changes: 2 additions & 2 deletions jdeeco-core/src/cz/cuni/mff/d3s/deeco/annotations/Mode.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Mode {
boolean init() default false;
String parent() default "";
// boolean init() default false;
String parent();
}
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ ComponentInstance createComponentInstance(Object obj) throws AnnotationProcessor

for (Method m : methods) {
createTriggerTransition(componentInstance,m);
createChildren(componentInstance, methods);
}


Expand Down Expand Up @@ -628,7 +629,7 @@ void createTriggerTransition(ComponentInstance componentInstance, Method method)
Type[] parameterTypes = method.getParameterTypes();
Annotation[][] allAnnotations = method.getParameterAnnotations();
ComponentProcess toProcess = getProcess(componentInstance, method.getName(), null);

for (int i = 0; i < parameterTypes.length; i++) {
TriggerOnValueUnchange t = getAnnotation(allAnnotations[i], TriggerOnValueUnchange.class);
if (t != null) {
Expand Down Expand Up @@ -677,6 +678,25 @@ void createTriggerTransition(ComponentInstance componentInstance, Method method)



private void createChildren(ComponentInstance componentInstance, List<Method> methods) {

List<ComponentProcess> children = new ArrayList<ComponentProcess>();
for (Method m : methods) {
Annotation[] anns = m.getDeclaredAnnotations();
ComponentProcess child = getProcess(componentInstance, m.getName(), null);
for (Annotation annotation : anns) {
if(annotation instanceof Mode){
for (ComponentProcess process : componentInstance.getComponentProcesses()) {
if(((Mode)annotation).parent().equals(process.getName())){
process.getChildren().add(child);
}
}
}
}
}
}


private ComponentProcess getProcess(ComponentInstance componentInstance,
String name, ComponentProcess toProcess) {
for (ComponentProcess process : componentInstance.getComponentProcesses()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@
import java.util.List;
import java.util.Map;

import cz.cuni.mff.d3s.deeco.model.runtime.api.ComponentProcess;
import cz.cuni.mff.d3s.deeco.model.runtime.api.KnowledgeChangeTrigger;
import cz.cuni.mff.d3s.deeco.model.runtime.api.KnowledgePath;
import cz.cuni.mff.d3s.deeco.model.runtime.api.KnowledgeValueChangeTrigger;
import cz.cuni.mff.d3s.deeco.model.runtime.api.KnowledgeValueUnchangeTrigger;
import cz.cuni.mff.d3s.deeco.model.runtime.api.ModeState;
import cz.cuni.mff.d3s.deeco.model.runtime.api.PathNode;
import cz.cuni.mff.d3s.deeco.model.runtime.api.PathNodeComponentId;
import cz.cuni.mff.d3s.deeco.model.runtime.api.PathNodeField;
import cz.cuni.mff.d3s.deeco.model.runtime.api.Trigger;
import cz.cuni.mff.d3s.deeco.model.runtime.stateflow.ConditionType;
import cz.cuni.mff.d3s.deeco.model.runtime.stateflow.InaccuracyParamHolder;
import cz.cuni.mff.d3s.deeco.model.runtime.stateflow.TriggerConditionParser;

/**
Expand All @@ -36,7 +32,6 @@ public class BaseKnowledgeManager implements KnowledgeManager {

private final Map<KnowledgePath, Object> knowledge;
private final Map<KnowledgeChangeTrigger, List<TriggerListener>> knowledgeChangeListeners;
private Object value = null;
private final String id;

@Override
Expand Down Expand Up @@ -592,7 +587,7 @@ private void notifyKnowledgeValueChangeListeners(
// notify its listeners about the change
for (final TriggerListener listener : knowledgeChangeListeners
.get(kvct)) {
if(TriggerConditionParser.checkCondition(kvct, value)){
if(TriggerConditionParser.checkCondition(knowledge, kvct, value)){
listener.triggered(kvct);
}
}
Expand Down Expand Up @@ -624,7 +619,7 @@ private void notifyKnowledgeValueUnchangeListeners(
// notify its listeners about the change
for (final TriggerListener listener : knowledgeChangeListeners
.get(kvct)) {
if(TriggerConditionParser.checkCondition(kvct, value)){
if(TriggerConditionParser.checkCondition(knowledge, kvct, value)){
listener.triggered(kvct);
}
}
Expand All @@ -633,25 +628,6 @@ private void notifyKnowledgeValueUnchangeListeners(
}
}


// private boolean checkTriggerEquality(KnowledgeValueUnchangeTrigger t1, KnowledgeValueUnchangeTrigger t2,Object value){
// if(t1.getConstraints().equals(t2.getConstraints()) && t1.getKnowledgePath().equals(t2.getKnowledgePath())){
// if(TriggerConditionParser.checkCondition(t1, value))
// return true;
// }
// return false;
// }
//
//
// private boolean checkTriggerEquality(KnowledgeValueChangeTrigger t1, KnowledgeValueChangeTrigger t2,Object value){
// if(t1.getConstraints().equals(t2.getConstraints()) && t1.getKnowledgePath().equals(t2.getKnowledgePath())){
// if(TriggerConditionParser.checkCondition(t1, value))
// return true;
// }
// return false;
// }


/**
* Checks whether the shorter list is contained in the longer one, keeping
* the order. It returns the containment end index.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* <li>{@link cz.cuni.mff.d3s.deeco.model.runtime.api.ComponentProcess#isIsActive <em>Is Active</em>}</li>
* <li>{@link cz.cuni.mff.d3s.deeco.model.runtime.api.ComponentProcess#getTriggers <em>Triggers</em>}</li>
* <li>{@link cz.cuni.mff.d3s.deeco.model.runtime.api.ComponentProcess#getState <em>State</em>}</li>
* <li>{@link cz.cuni.mff.d3s.deeco.model.runtime.api.ComponentProcess#getParent <em>Parent</em>}</li>
* <li>{@link cz.cuni.mff.d3s.deeco.model.runtime.api.ComponentProcess#getChildren <em>Children</em>}</li>
* </ul>
* </p>
*
Expand Down Expand Up @@ -153,29 +153,19 @@ public interface ComponentProcess extends Invocable {
void setState(ModeState value);

/**
* Returns the value of the '<em><b>Parent</b></em>' reference.
* Returns the value of the '<em><b>Children</b></em>' reference list.
* The list contents are of type {@link cz.cuni.mff.d3s.deeco.model.runtime.api.ComponentProcess}.
* <!-- begin-user-doc -->
* <p>
* If the meaning of the '<em>Parent</em>' reference isn't clear,
* If the meaning of the '<em>Children</em>' reference list isn't clear,
* there really should be more of a description here...
* </p>
* <!-- end-user-doc -->
* @return the value of the '<em>Parent</em>' reference.
* @see #setParent(ComponentProcess)
* @see cz.cuni.mff.d3s.deeco.model.runtime.meta.RuntimeMetadataPackage#getComponentProcess_Parent()
* @return the value of the '<em>Children</em>' reference list.
* @see cz.cuni.mff.d3s.deeco.model.runtime.meta.RuntimeMetadataPackage#getComponentProcess_Children()
* @model
* @generated
*/
ComponentProcess getParent();

/**
* Sets the value of the '{@link cz.cuni.mff.d3s.deeco.model.runtime.api.ComponentProcess#getParent <em>Parent</em>}' reference.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @param value the new value of the '<em>Parent</em>' reference.
* @see #getParent()
* @generated
*/
void setParent(ComponentProcess value);
EList<ComponentProcess> getChildren();

} // ComponentProcess
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.EObjectResolvingEList;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.InternalEList;

Expand All @@ -38,7 +39,7 @@
* <li>{@link cz.cuni.mff.d3s.deeco.model.runtime.impl.ComponentProcessImpl#isIsActive <em>Is Active</em>}</li>
* <li>{@link cz.cuni.mff.d3s.deeco.model.runtime.impl.ComponentProcessImpl#getTriggers <em>Triggers</em>}</li>
* <li>{@link cz.cuni.mff.d3s.deeco.model.runtime.impl.ComponentProcessImpl#getState <em>State</em>}</li>
* <li>{@link cz.cuni.mff.d3s.deeco.model.runtime.impl.ComponentProcessImpl#getParent <em>Parent</em>}</li>
* <li>{@link cz.cuni.mff.d3s.deeco.model.runtime.impl.ComponentProcessImpl#getChildren <em>Children</em>}</li>
* </ul>
* </p>
*
Expand Down Expand Up @@ -116,14 +117,14 @@ public class ComponentProcessImpl extends InvocableImpl implements ComponentProc
protected ModeState state = STATE_EDEFAULT;

/**
* The cached value of the '{@link #getParent() <em>Parent</em>}' reference.
* The cached value of the '{@link #getChildren() <em>Children</em>}' reference list.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getParent()
* @see #getChildren()
* @generated
* @ordered
*/
protected ComponentProcess parent;
protected EList<ComponentProcess> children;

/**
* <!-- begin-user-doc -->
Expand Down Expand Up @@ -265,37 +266,11 @@ public void setState(ModeState newState) {
* <!-- end-user-doc -->
* @generated
*/
public ComponentProcess getParent() {
if (parent != null && parent.eIsProxy()) {
InternalEObject oldParent = (InternalEObject)parent;
parent = (ComponentProcess)eResolveProxy(oldParent);
if (parent != oldParent) {
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.RESOLVE, RuntimeMetadataPackage.COMPONENT_PROCESS__PARENT, oldParent, parent));
}
public EList<ComponentProcess> getChildren() {
if (children == null) {
children = new EObjectResolvingEList<ComponentProcess>(ComponentProcess.class, this, RuntimeMetadataPackage.COMPONENT_PROCESS__CHILDREN);
}
return parent;
}

/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public ComponentProcess basicGetParent() {
return parent;
}

/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setParent(ComponentProcess newParent) {
ComponentProcess oldParent = parent;
parent = newParent;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, RuntimeMetadataPackage.COMPONENT_PROCESS__PARENT, oldParent, parent));
return children;
}

/**
Expand Down Expand Up @@ -362,9 +337,8 @@ public Object eGet(int featureID, boolean resolve, boolean coreType) {
return getTriggers();
case RuntimeMetadataPackage.COMPONENT_PROCESS__STATE:
return getState();
case RuntimeMetadataPackage.COMPONENT_PROCESS__PARENT:
if (resolve) return getParent();
return basicGetParent();
case RuntimeMetadataPackage.COMPONENT_PROCESS__CHILDREN:
return getChildren();
}
return super.eGet(featureID, resolve, coreType);
}
Expand Down Expand Up @@ -394,8 +368,9 @@ public void eSet(int featureID, Object newValue) {
case RuntimeMetadataPackage.COMPONENT_PROCESS__STATE:
setState((ModeState)newValue);
return;
case RuntimeMetadataPackage.COMPONENT_PROCESS__PARENT:
setParent((ComponentProcess)newValue);
case RuntimeMetadataPackage.COMPONENT_PROCESS__CHILDREN:
getChildren().clear();
getChildren().addAll((Collection<? extends ComponentProcess>)newValue);
return;
}
super.eSet(featureID, newValue);
Expand Down Expand Up @@ -424,8 +399,8 @@ public void eUnset(int featureID) {
case RuntimeMetadataPackage.COMPONENT_PROCESS__STATE:
setState(STATE_EDEFAULT);
return;
case RuntimeMetadataPackage.COMPONENT_PROCESS__PARENT:
setParent((ComponentProcess)null);
case RuntimeMetadataPackage.COMPONENT_PROCESS__CHILDREN:
getChildren().clear();
return;
}
super.eUnset(featureID);
Expand All @@ -449,8 +424,8 @@ public boolean eIsSet(int featureID) {
return triggers != null && !triggers.isEmpty();
case RuntimeMetadataPackage.COMPONENT_PROCESS__STATE:
return state != STATE_EDEFAULT;
case RuntimeMetadataPackage.COMPONENT_PROCESS__PARENT:
return parent != null;
case RuntimeMetadataPackage.COMPONENT_PROCESS__CHILDREN:
return children != null && !children.isEmpty();
}
return super.eIsSet(featureID);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ public EAttribute getComponentProcess_State() {
* <!-- end-user-doc -->
* @generated
*/
public EReference getComponentProcess_Parent() {
public EReference getComponentProcess_Children() {
return (EReference)componentProcessEClass.getEStructuralFeatures().get(5);
}

Expand Down Expand Up @@ -1153,7 +1153,7 @@ public void createPackageContents() {
createEAttribute(componentProcessEClass, COMPONENT_PROCESS__IS_ACTIVE);
createEReference(componentProcessEClass, COMPONENT_PROCESS__TRIGGERS);
createEAttribute(componentProcessEClass, COMPONENT_PROCESS__STATE);
createEReference(componentProcessEClass, COMPONENT_PROCESS__PARENT);
createEReference(componentProcessEClass, COMPONENT_PROCESS__CHILDREN);

parameterEClass = createEClass(PARAMETER);
createEReference(parameterEClass, PARAMETER__KNOWLEDGE_PATH);
Expand Down Expand Up @@ -1303,7 +1303,7 @@ public void initializePackageContents() {
initEAttribute(getComponentProcess_IsActive(), ecorePackage.getEBoolean(), "isActive", "true", 1, 1, ComponentProcess.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEReference(getComponentProcess_Triggers(), this.getTrigger(), null, "triggers", null, 0, -1, ComponentProcess.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEAttribute(getComponentProcess_State(), this.getModeState(), "state", null, 1, 1, ComponentProcess.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEReference(getComponentProcess_Parent(), this.getComponentProcess(), null, "parent", null, 0, 1, ComponentProcess.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEReference(getComponentProcess_Children(), this.getComponentProcess(), null, "children", null, 0, -1, ComponentProcess.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);

initEClass(parameterEClass, Parameter.class, "Parameter", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
initEReference(getParameter_KnowledgePath(), this.getKnowledgePath(), null, "knowledgePath", null, 0, 1, Parameter.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -791,13 +791,13 @@ public interface RuntimeMetadataPackage extends EPackage {
int COMPONENT_PROCESS__STATE = INVOCABLE_FEATURE_COUNT + 4;

/**
* The feature id for the '<em><b>Parent</b></em>' reference.
* The feature id for the '<em><b>Children</b></em>' reference list.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
* @ordered
*/
int COMPONENT_PROCESS__PARENT = INVOCABLE_FEATURE_COUNT + 5;
int COMPONENT_PROCESS__CHILDREN = INVOCABLE_FEATURE_COUNT + 5;

/**
* The number of structural features of the '<em>Component Process</em>' class.
Expand Down Expand Up @@ -1673,15 +1673,15 @@ public interface RuntimeMetadataPackage extends EPackage {
EAttribute getComponentProcess_State();

/**
* Returns the meta object for the reference '{@link cz.cuni.mff.d3s.deeco.model.runtime.api.ComponentProcess#getParent <em>Parent</em>}'.
* Returns the meta object for the reference list '{@link cz.cuni.mff.d3s.deeco.model.runtime.api.ComponentProcess#getChildren <em>Children</em>}'.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return the meta object for the reference '<em>Parent</em>'.
* @see cz.cuni.mff.d3s.deeco.model.runtime.api.ComponentProcess#getParent()
* @return the meta object for the reference list '<em>Children</em>'.
* @see cz.cuni.mff.d3s.deeco.model.runtime.api.ComponentProcess#getChildren()
* @see #getComponentProcess()
* @generated
*/
EReference getComponentProcess_Parent();
EReference getComponentProcess_Children();

/**
* Returns the meta object for class '{@link cz.cuni.mff.d3s.deeco.model.runtime.api.Parameter <em>Parameter</em>}'.
Expand Down Expand Up @@ -2482,12 +2482,12 @@ interface Literals {
EAttribute COMPONENT_PROCESS__STATE = eINSTANCE.getComponentProcess_State();

/**
* The meta object literal for the '<em><b>Parent</b></em>' reference feature.
* The meta object literal for the '<em><b>Children</b></em>' reference list feature.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
EReference COMPONENT_PROCESS__PARENT = eINSTANCE.getComponentProcess_Parent();
EReference COMPONENT_PROCESS__CHILDREN = eINSTANCE.getComponentProcess_Children();

/**
* The meta object literal for the '{@link cz.cuni.mff.d3s.deeco.model.runtime.impl.ParameterImpl <em>Parameter</em>}' class.
Expand Down
Loading

0 comments on commit 351dd7c

Please sign in to comment.