Commit 5c972459 authored by yoogx's avatar yoogx

* getPropertyValueByName: new function, return a property

          value from a string
parent a2a02dc2
...@@ -92,7 +92,14 @@ def generate (generator): ...@@ -92,7 +92,14 @@ def generate (generator):
################################################################################ ################################################################################
def getPropertyValue (nodeId,nameId): def getPropertyValue (nodeId,propertyId):
'''Get the value of the property '''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)
...@@ -30,6 +30,7 @@ args = sys.argv[1:] ...@@ -30,6 +30,7 @@ args = sys.argv[1:]
################################### ###################################
import ocarina import ocarina
import lmp
def visitor (component, level): def visitor (component, level):
""" """
...@@ -42,25 +43,26 @@ 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]; features=ocarina.AIN.Features(component)[0];
if features is not None : if features is not None :
print ' ' * level,' -> features:',features print ' ' * level,' -> features:',features
for feature in 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]; properties = ocarina.AIN.Properties(component)[0];
if properties is not None : if properties is not None :
print ' ' * level,' -> properties:' print ' ' * level,' -> properties:'
for property in properties: for property in properties:
print ' ' * level,' ',ocarina.getPropertyValue(component,property)[0] print ' ' * level,' ',ocarina.getPropertyValue(component,property)[0]
print '[looking for priority] ' * level,' ',ocarina.getPropertyValueByName(component,u'priority')[0]
subcomponents=ocarina.AIN.Subcomponents(component)[0]; subcomponents=ocarina.AIN.Subcomponents(component)[0];
if subcomponents is not None : if subcomponents is not None :
print ' ' * level,' -> subcomponents:',subcomponents print ' ' * level,' -> subcomponents:',subcomponents
for subcomponent in 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) visitor(str(ocarina.AIN.Corresponding_Instance(subcomponent)[0]),level+3)
print ' ' * level,'end of visit of ',component print ' ' * level,'end of visit of ',component
...@@ -81,7 +83,7 @@ def main (): ...@@ -81,7 +83,7 @@ def main ():
print 'Visit AADL Instance tree' print 'Visit AADL Instance tree'
print '----------------------------------------------------' print '----------------------------------------------------'
root=ocarina.getRoot()[0] root=lmp.getRoot()[0]
visitor(root,0) visitor(root,0)
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -157,6 +157,15 @@ package body Ocarina.Backends.Properties.Utils is ...@@ -157,6 +157,15 @@ package body Ocarina.Backends.Properties.Utils is
is is
Prop_Name : constant Name_Id Prop_Name : constant Name_Id
:= Standard.Utils.To_Lower (Display_Name (Identifier (Property))); := 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 A : constant String_Access
:= new String'(Get_Name_String (Prop_Name)); := new String'(Get_Name_String (Prop_Name));
AADL_Property_Value : Node_Id; AADL_Property_Value : Node_Id;
......
...@@ -47,6 +47,11 @@ package Ocarina.Backends.Properties.Utils is ...@@ -47,6 +47,11 @@ package Ocarina.Backends.Properties.Utils is
-- ("Period", "500 Ms") -- ("Period", "500 Ms")
-- ("Dispatch_Protocol", "Periodic") -- ("Dispatch_Protocol", "Periodic")
function Check_And_Get_Property
(E : Node_Id;
Prop_Name : Name_Id)
return String_List;
function Check_And_Get_Property function Check_And_Get_Property
(E : Node_Id; (E : Node_Id;
Property : Node_Id) Property : Node_Id)
......
...@@ -465,6 +465,18 @@ package body Ocarina.Python_Cmd is ...@@ -465,6 +465,18 @@ package body Ocarina.Python_Cmd is
Nth_Arg (Data, 2, "")); Nth_Arg (Data, 2, ""));
end On_Get_Property_Value; 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 -- -- On_Get_Instances --
---------------------- ----------------------
...@@ -673,6 +685,11 @@ package body Ocarina.Python_Cmd is ...@@ -673,6 +685,11 @@ package body Ocarina.Python_Cmd is
(Repo, "getPropertyValue", 2, 2, (Repo, "getPropertyValue", 2, 2,
Handler => On_Get_Property_Value'Unrestricted_Access); 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 -- getPropertyConstants() function
Register_Command Register_Command
(Repo, "getPropertyConstants", 1, 1, (Repo, "getPropertyConstants", 1, 1,
......
...@@ -280,6 +280,25 @@ package body Ocarina.Utils is ...@@ -280,6 +280,25 @@ package body Ocarina.Utils is
end loop; end loop;
end Get_Property_Value; 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 -- -- Get_Node_Id --
----------------- -----------------
......
...@@ -60,8 +60,11 @@ package Ocarina.Utils is ...@@ -60,8 +60,11 @@ package Ocarina.Utils is
function Get_List_Id_From_String (Name : String) return List_Id; function Get_List_Id_From_String (Name : String) return List_Id;
function Get_Int_From_String (Name : String) return Int; function Get_Int_From_String (Name : String) return Int;
function Get_Value_Id_From_String (Name : String) return Value_Id; 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_Node_Id (Data : in out Callback_Data'Class; N : String);
procedure Get_Property_Value (Data : in out Callback_Data'Class; procedure Get_Property_Value (Data : in out Callback_Data'Class;
PropId : String; PropName : String); PropId : String; PropName : String);
procedure Get_Property_Value_By_Name (Data : in out Callback_Data'Class;
PropId : String; PropName : String);
end Ocarina.Utils; end Ocarina.Utils;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment