|
34 | 34 |
|
35 | 35 | begin |
36 | 36 |
|
| 37 | + RFLX_Result := |
| 38 | + (Message_Class => RFLX.CoAP.Server_Error, |
| 39 | + Success_Code => RFLX.CoAP.Success_Response'Last, |
| 40 | + Client_Error_Code => RFLX.CoAP.Client_Error_Response'Last, |
| 41 | + Server_Error_Code => RFLX.CoAP.Internal_Server_Error, |
| 42 | + Padding => 0, |
| 43 | + Options_And_Payload_Options_And_Payload => [others => 0], |
| 44 | + Options_And_Payload_Length => 0); |
| 45 | + |
37 | 46 | RFLX.CoAP.CoAP_Message.Initialize |
38 | 47 | (Ctx => Context, |
39 | 48 | Buffer => Buffer, |
|
74 | 83 | RFLX.CoAP.Client_Error_Response'Last; |
75 | 84 | RFLX_Result.Server_Error_Code := |
76 | 85 | RFLX.CoAP.Server_Error_Response'Last; |
77 | | - RFLX_Result.Padding := 0; |
78 | 86 | RFLX_Result.Message_Class := Response_Codes.Code_Class; |
79 | 87 |
|
80 | 88 | case CoAP_SPARK.Messages.Response_Code (Response_Codes.Code_Class) |
|
97 | 105 | end if; |
98 | 106 | end if; |
99 | 107 |
|
| 108 | + RFLX.CoAP.CoAP_Message.Take_Buffer |
| 109 | + (Ctx => Context, |
| 110 | + Buffer => Buffer); |
| 111 | + pragma Assert (not RFLX.CoAP.CoAP_Message.Has_Buffer (Context)); |
| 112 | + |
| 113 | + RFLX.RFLX_Types.Free (Buffer); |
100 | 114 | end Get_Response; |
101 | 115 |
|
102 | 116 | procedure Get_Error_Options_And_Payload |
103 | 117 | (State : in out RFLX.CoAP_Server.Main_Loop_Environment.State; |
104 | | - RFLX_Result : out RFLX.CoAP_Server.Options_And_Payload_Data.Structure) is |
| 118 | + RFLX_Result : out RFLX.CoAP_Server.Options_And_Payload_Data.Structure) |
| 119 | + is |
| 120 | + use type CoAP_SPARK.Status_Type; |
| 121 | + |
| 122 | + Status_Image : constant String := |
| 123 | + CoAP_SPARK.Status_Type'Image (State.Current_Status); |
| 124 | + Buffer : RFLX_Types.Bytes_Ptr := |
| 125 | + new RFLX_Types.Bytes'([1 .. RFLX_Result.Options_And_Payload'Length => 0]); |
| 126 | + Context : RFLX.CoAP.CoAP_Message.Context; |
| 127 | + |
| 128 | + Response_Content : CoAP_SPARK.Messages.Content; |
| 129 | + |
105 | 130 | begin |
106 | | - null; |
| 131 | + RFLX.CoAP.CoAP_Message.Initialize |
| 132 | + (Ctx => Context, |
| 133 | + Buffer => Buffer); |
| 134 | + |
| 135 | + -- This procedure is only called when there is an error in the |
| 136 | + -- main loop state machine, so if we haven't set an error status yet, |
| 137 | + -- we have to set it to Unexpected_Case, since the cause is unknown. |
| 138 | + if State.Current_Status = CoAP_SPARK.OK or else |
| 139 | + Status_Image'Length > CoAP_SPARK.Max_Payload_Length |
| 140 | + then |
| 141 | + CoAP_SPARK.Messages.Initialize_With_Text_Payload |
| 142 | + (Text => "Unexpected case in main loop", |
| 143 | + Item => Response_Content); |
| 144 | + else |
| 145 | + CoAP_SPARK.Messages.Initialize_With_Text_Payload |
| 146 | + (Text => Status_Image, |
| 147 | + Item => Response_Content); |
| 148 | + end if; |
| 149 | + |
| 150 | + CoAP_SPARK.Messages.Encoding.Encode_Options_And_Payload |
| 151 | + (Options_And_Payload => Response_Content, |
| 152 | + Status => State.Current_Status, |
| 153 | + Encoded_Data => RFLX_Result.Options_And_Payload, |
| 154 | + Encoded_Length => RFLX.CoAP.Length_16 |
| 155 | + (RFLX_Result.Length)); |
| 156 | + |
| 157 | + CoAP_SPARK.Messages.Finalize (Response_Content); |
| 158 | + pragma Assert (CoAP_SPARK.Messages.Is_Empty (Response_Content)); |
| 159 | + |
| 160 | + RFLX.CoAP.CoAP_Message.Take_Buffer |
| 161 | + (Ctx => Context, |
| 162 | + Buffer => Buffer); |
| 163 | + pragma Assert (not RFLX.CoAP.CoAP_Message.Has_Buffer (Context)); |
| 164 | + |
| 165 | + RFLX.RFLX_Types.Free (Buffer); |
107 | 166 | end Get_Error_Options_And_Payload; |
108 | 167 |
|
109 | 168 | end RFLX.CoAP_Server.Main_Loop; |
0 commit comments