Skip to content

Commit

Permalink
Add validation error event and remove clutter from helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jbsco committed Aug 7, 2024
1 parent 08f052b commit 1e5756b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
43 changes: 15 additions & 28 deletions src/components/parameters/component-parameters-implementation.adb
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,15 @@ package body Component.Parameters.Implementation is
-- Send the parameter fetch request to the appropriate component:
Self.Parameter_Update_T_Provide (Idx, Param_Validate);

-- Make sure the status is successful. If it is not, then produce an event.
if Param_Validate.Status /= Success then
Self.Event_T_Send_If_Connected (Self.Events.Parameter_Validation_Failed (Self.Sys_Time_T_Get, (
Operation => Param_Validate.Operation,
Status => Param_Validate.Status,
Id => Param_Validate.Param.Header.Id)
));
end if;

return Param_Validate.Status;
end Validate_Parameters;

Expand Down Expand Up @@ -345,16 +354,6 @@ package body Component.Parameters.Implementation is
Memory_Region_Ptr : constant Byte_Array_Pointer.Instance := Byte_Array_Pointer.Packed.Unpack (Region);
Parameter_Data_Ptr : constant Byte_Array_Pointer.Instance
:= Byte_Array_Pointer.Slice (Memory_Region_Ptr, Start_Index => Parameter_Table_Header.Size_In_Bytes);

-- If the status returned is not success then set our status to return to a parameter error.
procedure Set_Status (Stat : in Parameter_Enums.Parameter_Update_Status.E) is
begin
-- Check the return status. Even if it is bad, we still continue to try to stage
-- the rest of the parameters.
if Stat /= Success then
Status_To_Return := Parameter_Error;
end if;
end Set_Status;
begin
-- Go through all our entries linearly, extracting data from the incoming memory region, and
-- using the values stored there as values to stage our parameters.
Expand All @@ -377,7 +376,9 @@ package body Component.Parameters.Implementation is
Value (Value'First .. Value'First + Param_Length - 1) := To_Byte_Array (Ptr);

-- Stage the parameter:
Set_Status (Self.Stage_Parameter (Param_Entry => Param_Entry, Value => Value));
if Self.Stage_Parameter (Param_Entry => Param_Entry, Value => Value) /= Success then
Status_To_Return := Parameter_Error;
end if;
end;
end loop;
return Status_To_Return;
Expand All @@ -388,33 +389,19 @@ package body Component.Parameters.Implementation is
use Parameter_Enums.Parameter_Update_Status;
use Parameter_Enums.Parameter_Table_Update_Status;
Status_To_Return : Parameter_Enums.Parameter_Table_Update_Status.E := Success;

-- If the status returned is not success then set our status to return to a parameter error.
procedure Set_Status (Stat : in Parameter_Enums.Parameter_Update_Status.E) is
begin
-- Check the return status. Even if it is bad, we still continue to try to stage
-- the rest of the parameters.
if Stat /= Success then
Status_To_Return := Parameter_Error;
end if;
end Set_Status;
begin
-- Stage all of the parameters:
Status_To_Return := Self.Stage_Parameter_Table (Region);

-- OK, now we need to validate all the parameters.
for Idx in Self.Connector_Parameter_Update_T_Provide'Range loop
if Self.Is_Parameter_Update_T_Provide_Connected (Idx) then
Set_Status (Self.Validate_Parameters (Component_Id => Idx));
if Self.Validate_Parameters (Component_Id => Idx) /= Success then
Status_To_Return := Parameter_Error;
end if;
end if;
end loop;

-- Send out a new parameter's packet if configured to do so:
if Self.Dump_Parameters_On_Change then
-- Send the packet:
Set_Status (Self.Send_Parameters_Packet);
end if;

-- Return the memory pointer with the status for deallocation.
return (Region => Region, Status => Status_To_Return);
end Validate_Parameter_Table;
Expand Down
3 changes: 3 additions & 0 deletions src/components/parameters/parameters.events.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ events:
- name: Parameter_Update_Failed
description: A parameter value could not be updated.
param_type: Parameter_Operation_Status.T
- name: Parameter_Validation_Failed
description: A parameter value could not be validated.
param_type: Parameter_Operation_Status.T
- name: Parameter_Fetch_Failed
description: A parameter value could not be updated.
param_type: Parameter_Operation_Status.T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ package body Component.Parameters.Implementation.Tester is
Self.Parameter_Update_Id_Not_Recognized_History.Init (Depth => 20);
Self.Parameter_Stage_Failed_History.Init (Depth => 20);
Self.Parameter_Update_Failed_History.Init (Depth => 20);
Self.Parameter_Validation_Failed_History.Init (Depth => 20);
Self.Parameter_Fetch_Failed_History.Init (Depth => 20);
Self.Parameter_Fetch_Length_Mismatch_History.Init (Depth => 20);
Self.Parameter_Update_Length_Mismatch_History.Init (Depth => 20);
Expand Down Expand Up @@ -65,6 +66,7 @@ package body Component.Parameters.Implementation.Tester is
Self.Parameter_Update_Id_Not_Recognized_History.Destroy;
Self.Parameter_Stage_Failed_History.Destroy;
Self.Parameter_Update_Failed_History.Destroy;
Self.Parameter_Validation_Failed_History.Destroy;
Self.Parameter_Fetch_Failed_History.Destroy;
Self.Parameter_Fetch_Length_Mismatch_History.Destroy;
Self.Parameter_Update_Length_Mismatch_History.Destroy;
Expand Down Expand Up @@ -218,6 +220,13 @@ package body Component.Parameters.Implementation.Tester is
Self.Parameter_Update_Failed_History.Push (Arg);
end Parameter_Update_Failed;

-- A parameter value could not be validated.
overriding procedure Parameter_Validation_Failed (Self : in out Instance; Arg : in Parameter_Operation_Status.T) is
begin
-- Push the argument onto the test history for looking at later:
Self.Parameter_Validation_Failed_History.Push (Arg);
end Parameter_Validation_Failed;

-- A parameter value could not be updated.
overriding procedure Parameter_Fetch_Failed (Self : in out Instance; Arg : in Parameter_Operation_Status.T) is
begin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ package Component.Parameters.Implementation.Tester is
package Parameter_Update_Id_Not_Recognized_History_Package is new Printable_History (Parameter_Id.T, Parameter_Id.Representation.Image);
package Parameter_Stage_Failed_History_Package is new Printable_History (Parameter_Operation_Status.T, Parameter_Operation_Status.Representation.Image);
package Parameter_Update_Failed_History_Package is new Printable_History (Parameter_Operation_Status.T, Parameter_Operation_Status.Representation.Image);
package Parameter_Validation_Failed_History_Package is new Printable_History (Parameter_Operation_Status.T, Parameter_Operation_Status.Representation.Image);
package Parameter_Fetch_Failed_History_Package is new Printable_History (Parameter_Operation_Status.T, Parameter_Operation_Status.Representation.Image);
package Parameter_Fetch_Length_Mismatch_History_Package is new Printable_History (Invalid_Parameter_Length.T, Invalid_Parameter_Length.Representation.Image);
package Parameter_Update_Length_Mismatch_History_Package is new Printable_History (Invalid_Parameter_Length.T, Invalid_Parameter_Length.Representation.Image);
Expand Down Expand Up @@ -75,6 +76,7 @@ package Component.Parameters.Implementation.Tester is
Parameter_Update_Id_Not_Recognized_History : Parameter_Update_Id_Not_Recognized_History_Package.Instance;
Parameter_Stage_Failed_History : Parameter_Stage_Failed_History_Package.Instance;
Parameter_Update_Failed_History : Parameter_Update_Failed_History_Package.Instance;
Parameter_Validation_Failed_History : Parameter_Validation_Failed_History_Package.Instance;
Parameter_Fetch_Failed_History : Parameter_Fetch_Failed_History_Package.Instance;
Parameter_Fetch_Length_Mismatch_History : Parameter_Fetch_Length_Mismatch_History_Package.Instance;
Parameter_Update_Length_Mismatch_History : Parameter_Update_Length_Mismatch_History_Package.Instance;
Expand Down Expand Up @@ -155,6 +157,8 @@ package Component.Parameters.Implementation.Tester is
overriding procedure Parameter_Stage_Failed (Self : in out Instance; Arg : in Parameter_Operation_Status.T);
-- A parameter value could not be updated.
overriding procedure Parameter_Update_Failed (Self : in out Instance; Arg : in Parameter_Operation_Status.T);
-- A parameter value could not be validated.
overriding procedure Parameter_Validation_Failed (Self : in out Instance; Arg : in Parameter_Operation_Status.T);
-- A parameter value could not be updated.
overriding procedure Parameter_Fetch_Failed (Self : in out Instance; Arg : in Parameter_Operation_Status.T);
-- A parameter was fetched but contained an unexpected length.
Expand Down

0 comments on commit 1e5756b

Please sign in to comment.