From 5c972459a352c4d462b2bc4ed39ec17156fa467a Mon Sep 17 00:00:00 2001 From: yoogx Date: Mon, 20 Jul 2015 23:38:50 +0200 Subject: [PATCH] * getPropertyValueByName: new function, return a property value from a string --- resources/runtime/python/ocarina/ocarina.py | 11 +++++++++-- resources/runtime/python/test/visitor.py | 10 ++++++---- .../ocarina-backends-properties-utils.adb | 9 +++++++++ .../ocarina-backends-properties-utils.ads | 5 +++++ src/python/ocarina-python_cmd.adb | 17 +++++++++++++++++ src/python/ocarina-utils.adb | 19 +++++++++++++++++++ src/python/ocarina-utils.ads | 3 +++ 7 files changed, 68 insertions(+), 6 deletions(-) diff --git a/resources/runtime/python/ocarina/ocarina.py b/resources/runtime/python/ocarina/ocarina.py index 116d76f2..093d8987 100755 --- a/resources/runtime/python/ocarina/ocarina.py +++ b/resources/runtime/python/ocarina/ocarina.py @@ -92,7 +92,14 @@ def generate (generator): ################################################################################ -def getPropertyValue (nodeId,nameId): +def getPropertyValue (nodeId,propertyId): '''Get the value of the property ''' - return runOcarinaFunction (libocarina_python.getPropertyValue, nodeId,nameId) + return runOcarinaFunction (libocarina_python.getPropertyValue, nodeId,propertyId) + +################################################################################ + +def getPropertyValueByName (nodeId,propertyString): + '''Get the value of the property + ''' + return runOcarinaFunction (libocarina_python.getPropertyValueByName, nodeId, propertyString) diff --git a/resources/runtime/python/test/visitor.py b/resources/runtime/python/test/visitor.py index d689b5f6..10bbb0c3 100755 --- a/resources/runtime/python/test/visitor.py +++ b/resources/runtime/python/test/visitor.py @@ -30,6 +30,7 @@ args = sys.argv[1:] ################################### import ocarina +import lmp def visitor (component, level): """ @@ -42,25 +43,26 @@ def visitor (component, level): """ - print ' ' * level,'Visiting ',ocarina.getInstanceName(component)[0] + print ' ' * level,'Visiting ',lmp.getInstanceName(component)[0] features=ocarina.AIN.Features(component)[0]; if features is not None : print ' ' * level,' -> features:',features for feature in features : - print ' ' * level,' -> ',feature,",",ocarina.getInstanceName(feature)[0] + print ' ' * level,' -> ',feature,",",lmp.getInstanceName(feature)[0] properties = ocarina.AIN.Properties(component)[0]; if properties is not None : print ' ' * level,' -> properties:' for property in properties: print ' ' * level,' ',ocarina.getPropertyValue(component,property)[0] + print '[looking for priority] ' * level,' ',ocarina.getPropertyValueByName(component,u'priority')[0] subcomponents=ocarina.AIN.Subcomponents(component)[0]; if subcomponents is not None : print ' ' * level,' -> subcomponents:',subcomponents for subcomponent in subcomponents : - print ' ' * level,' -> ',subcomponent,",",ocarina.getInstanceName(subcomponent)[0] + print ' ' * level,' -> ',subcomponent,",",lmp.getInstanceName(subcomponent)[0] visitor(str(ocarina.AIN.Corresponding_Instance(subcomponent)[0]),level+3) print ' ' * level,'end of visit of ',component @@ -81,7 +83,7 @@ def main (): print 'Visit AADL Instance tree' print '----------------------------------------------------' - root=ocarina.getRoot()[0] + root=lmp.getRoot()[0] visitor(root,0) if __name__ == "__main__": diff --git a/src/backends/ocarina-backends-properties-utils.adb b/src/backends/ocarina-backends-properties-utils.adb index faaf725e..7a9be109 100644 --- a/src/backends/ocarina-backends-properties-utils.adb +++ b/src/backends/ocarina-backends-properties-utils.adb @@ -157,6 +157,15 @@ package body Ocarina.Backends.Properties.Utils is is Prop_Name : constant Name_Id := Standard.Utils.To_Lower (Display_Name (Identifier (Property))); + begin + return Check_And_Get_Property (E, Prop_Name); + end Check_And_Get_Property; + + function Check_And_Get_Property + (E : Node_Id; + Prop_Name : Name_Id) + return String_List + is A : constant String_Access := new String'(Get_Name_String (Prop_Name)); AADL_Property_Value : Node_Id; diff --git a/src/backends/ocarina-backends-properties-utils.ads b/src/backends/ocarina-backends-properties-utils.ads index fe6f4cd5..0dfc3da2 100644 --- a/src/backends/ocarina-backends-properties-utils.ads +++ b/src/backends/ocarina-backends-properties-utils.ads @@ -47,6 +47,11 @@ package Ocarina.Backends.Properties.Utils is -- ("Period", "500 Ms") -- ("Dispatch_Protocol", "Periodic") + function Check_And_Get_Property + (E : Node_Id; + Prop_Name : Name_Id) + return String_List; + function Check_And_Get_Property (E : Node_Id; Property : Node_Id) diff --git a/src/python/ocarina-python_cmd.adb b/src/python/ocarina-python_cmd.adb index 56cb618b..a5f5fe1a 100644 --- a/src/python/ocarina-python_cmd.adb +++ b/src/python/ocarina-python_cmd.adb @@ -465,6 +465,18 @@ package body Ocarina.Python_Cmd is Nth_Arg (Data, 2, "")); end On_Get_Property_Value; + procedure On_Get_Property_Value_By_Name + (Data : in out Callback_Data'Class; Command : String); + + procedure On_Get_Property_Value_By_Name + (Data : in out Callback_Data'Class; Command : String) is + pragma Unreferenced (Command); + begin + Get_Property_Value_By_Name + (Data, Nth_Arg (Data, 1, ""), + Nth_Arg (Data, 2, "")); + end On_Get_Property_Value_By_Name; + ---------------------- -- On_Get_Instances -- ---------------------- @@ -673,6 +685,11 @@ package body Ocarina.Python_Cmd is (Repo, "getPropertyValue", 2, 2, Handler => On_Get_Property_Value'Unrestricted_Access); + -- getPropertyValueByName() function + Register_Command + (Repo, "getPropertyValueByName", 2, 2, + Handler => On_Get_Property_Value_By_Name'Unrestricted_Access); + -- getPropertyConstants() function Register_Command (Repo, "getPropertyConstants", 1, 1, diff --git a/src/python/ocarina-utils.adb b/src/python/ocarina-utils.adb index 61e7ea28..64c1f6e0 100644 --- a/src/python/ocarina-utils.adb +++ b/src/python/ocarina-utils.adb @@ -280,6 +280,25 @@ package body Ocarina.Utils is end loop; end Get_Property_Value; + -------------------------------- + -- Get_Property_Value_By_Name -- + -------------------------------- + + procedure Get_Property_Value_By_Name (Data : in out Callback_Data'Class; + PropId : String; PropName : String) + is + Result : constant String_List := + Ocarina.Backends.Properties.Utils.Check_And_Get_Property + (Get_Node_Id_From_String (PropId), + Get_String_Name (PropName)); + begin + Set_Return_Value_As_List (Data); + + for Elt of Result loop + Set_Return_Value (Data, Elt.all); + end loop; + end Get_Property_Value_By_Name; + ----------------- -- Get_Node_Id -- ----------------- diff --git a/src/python/ocarina-utils.ads b/src/python/ocarina-utils.ads index 98947b87..e2dcb433 100644 --- a/src/python/ocarina-utils.ads +++ b/src/python/ocarina-utils.ads @@ -60,8 +60,11 @@ package Ocarina.Utils is function Get_List_Id_From_String (Name : String) return List_Id; function Get_Int_From_String (Name : String) return Int; function Get_Value_Id_From_String (Name : String) return Value_Id; + procedure Get_Node_Id (Data : in out Callback_Data'Class; N : String); procedure Get_Property_Value (Data : in out Callback_Data'Class; PropId : String; PropName : String); + procedure Get_Property_Value_By_Name (Data : in out Callback_Data'Class; + PropId : String; PropName : String); end Ocarina.Utils; -- GitLab