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):
################################################################################
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)
......@@ -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__":
......
......@@ -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;
......
......@@ -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)
......
......@@ -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,
......
......@@ -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 --
-----------------
......
......@@ -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;
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