Summer Qin | 153f3df | 2022-11-17 15:51:02 +0800 | [diff] [blame] | 1 | /* |
Kevin Peng | 0eca5ea | 2023-07-21 17:32:31 +0800 | [diff] [blame] | 2 | * Copyright (c) 2023, Arm Limited. All rights reserved. |
Summer Qin | 153f3df | 2022-11-17 15:51:02 +0800 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | /* |
Kevin Peng | 0eca5ea | 2023-07-21 17:32:31 +0800 | [diff] [blame] | 9 | * Generated by erpcgen 1.9.1 on Fri Jul 21 17:28:31 2023. |
Summer Qin | 153f3df | 2022-11-17 15:51:02 +0800 | [diff] [blame] | 10 | * |
| 11 | * AUTOGENERATED - DO NOT EDIT |
| 12 | */ |
| 13 | |
| 14 | |
Kevin Peng | 0eca5ea | 2023-07-21 17:32:31 +0800 | [diff] [blame] | 15 | #include "tfm_erpc_server.h" |
Summer Qin | 153f3df | 2022-11-17 15:51:02 +0800 | [diff] [blame] | 16 | #if ERPC_ALLOCATION_POLICY == ERPC_ALLOCATION_POLICY_DYNAMIC |
| 17 | #include <new> |
| 18 | #include "erpc_port.h" |
| 19 | #endif |
| 20 | #include "erpc_manually_constructed.h" |
| 21 | |
| 22 | #if 10901 != ERPC_VERSION_NUMBER |
| 23 | #error "The generated shim code version is different to the rest of eRPC code." |
| 24 | #endif |
| 25 | |
| 26 | using namespace erpc; |
| 27 | using namespace std; |
| 28 | |
| 29 | #if ERPC_NESTED_CALLS_DETECTION |
| 30 | extern bool nestingDetection; |
| 31 | #endif |
| 32 | |
| 33 | ERPC_MANUALLY_CONSTRUCTED_STATIC(psa_client_api_service, s_psa_client_api_service); |
| 34 | |
| 35 | |
| 36 | //! @brief Function to read struct binary_t |
| 37 | static void read_binary_t_struct(erpc::Codec * codec, binary_t * data); |
| 38 | |
| 39 | //! @brief Function to read struct list_binary_1_t |
| 40 | static void read_list_binary_1_t_struct(erpc::Codec * codec, list_binary_1_t * data); |
| 41 | |
| 42 | |
| 43 | // Read struct binary_t function implementation |
| 44 | static void read_binary_t_struct(erpc::Codec * codec, binary_t * data) |
| 45 | { |
| 46 | if(NULL == data) |
| 47 | { |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | uint8_t * data_local; |
| 52 | codec->readBinary(&data->dataLength, &data_local); |
| 53 | data->data = (uint8_t *) erpc_malloc(data->dataLength * sizeof(uint8_t)); |
| 54 | if ((data->data == NULL) && (data->dataLength > 0)) |
| 55 | { |
| 56 | codec->updateStatus(kErpcStatus_MemoryError); |
| 57 | } |
| 58 | else |
| 59 | { |
| 60 | memcpy(data->data, data_local, data->dataLength); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | // Read struct list_binary_1_t function implementation |
| 65 | static void read_list_binary_1_t_struct(erpc::Codec * codec, list_binary_1_t * data) |
| 66 | { |
| 67 | if(NULL == data) |
| 68 | { |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | codec->startReadList(&data->elementsCount); |
| 73 | data->elements = (binary_t *) erpc_malloc(data->elementsCount * sizeof(binary_t)); |
| 74 | if ((data->elements == NULL) && (data->elementsCount > 0)) |
| 75 | { |
| 76 | codec->updateStatus(kErpcStatus_MemoryError); |
| 77 | } |
| 78 | for (uint32_t listCount = 0U; listCount < data->elementsCount; ++listCount) |
| 79 | { |
| 80 | read_binary_t_struct(codec, &(data->elements[listCount])); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | |
| 85 | //! @brief Function to write struct binary_t |
| 86 | static void write_binary_t_struct(erpc::Codec * codec, const binary_t * data); |
| 87 | |
| 88 | //! @brief Function to write struct list_binary_1_t |
| 89 | static void write_list_binary_1_t_struct(erpc::Codec * codec, const list_binary_1_t * data); |
| 90 | |
| 91 | |
| 92 | // Write struct binary_t function implementation |
| 93 | static void write_binary_t_struct(erpc::Codec * codec, const binary_t * data) |
| 94 | { |
| 95 | if(NULL == data) |
| 96 | { |
| 97 | return; |
| 98 | } |
| 99 | |
| 100 | codec->writeBinary(data->dataLength, data->data); |
| 101 | } |
| 102 | |
| 103 | // Write struct list_binary_1_t function implementation |
| 104 | static void write_list_binary_1_t_struct(erpc::Codec * codec, const list_binary_1_t * data) |
| 105 | { |
| 106 | if(NULL == data) |
| 107 | { |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | codec->startWriteList(data->elementsCount); |
| 112 | for (uint32_t listCount = 0U; listCount < data->elementsCount; ++listCount) |
| 113 | { |
| 114 | write_binary_t_struct(codec, &(data->elements[listCount])); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | |
| 119 | //! @brief Function to free space allocated inside struct binary_t |
| 120 | static void free_binary_t_struct(binary_t * data); |
| 121 | |
| 122 | //! @brief Function to free space allocated inside struct list_binary_1_t |
| 123 | static void free_list_binary_1_t_struct(list_binary_1_t * data); |
| 124 | |
| 125 | |
| 126 | // Free space allocated inside struct binary_t function implementation |
| 127 | static void free_binary_t_struct(binary_t * data) |
| 128 | { |
Kevin Peng | 0eca5ea | 2023-07-21 17:32:31 +0800 | [diff] [blame] | 129 | if (data->data) |
| 130 | { |
| 131 | erpc_free(data->data); |
| 132 | } |
Summer Qin | 153f3df | 2022-11-17 15:51:02 +0800 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | // Free space allocated inside struct list_binary_1_t function implementation |
| 136 | static void free_list_binary_1_t_struct(list_binary_1_t * data) |
| 137 | { |
| 138 | for (uint32_t listCount = 0; listCount < data->elementsCount; ++listCount) |
| 139 | { |
| 140 | free_binary_t_struct(&data->elements[listCount]); |
| 141 | } |
| 142 | |
Kevin Peng | 0eca5ea | 2023-07-21 17:32:31 +0800 | [diff] [blame] | 143 | if (data->elements) |
| 144 | { |
| 145 | erpc_free(data->elements); |
| 146 | } |
Summer Qin | 153f3df | 2022-11-17 15:51:02 +0800 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | |
| 150 | |
| 151 | // Call the correct server shim based on method unique ID. |
| 152 | erpc_status_t psa_client_api_service::handleInvocation(uint32_t methodId, uint32_t sequence, Codec * codec, MessageBufferFactory *messageFactory) |
| 153 | { |
| 154 | erpc_status_t erpcStatus; |
| 155 | switch (methodId) |
| 156 | { |
| 157 | case kpsa_client_api_psa_framework_version_id: |
| 158 | { |
| 159 | erpcStatus = psa_framework_version_shim(codec, messageFactory, sequence); |
| 160 | break; |
| 161 | } |
| 162 | |
| 163 | case kpsa_client_api_psa_version_id: |
| 164 | { |
| 165 | erpcStatus = psa_version_shim(codec, messageFactory, sequence); |
| 166 | break; |
| 167 | } |
| 168 | |
| 169 | case kpsa_client_api_erpc_psa_call_id: |
| 170 | { |
| 171 | erpcStatus = erpc_psa_call_shim(codec, messageFactory, sequence); |
| 172 | break; |
| 173 | } |
| 174 | |
Kevin Peng | 0eca5ea | 2023-07-21 17:32:31 +0800 | [diff] [blame] | 175 | case kpsa_client_api_psa_connect_id: |
| 176 | { |
| 177 | erpcStatus = psa_connect_shim(codec, messageFactory, sequence); |
| 178 | break; |
| 179 | } |
| 180 | |
| 181 | case kpsa_client_api_psa_close_id: |
| 182 | { |
| 183 | erpcStatus = psa_close_shim(codec, messageFactory, sequence); |
| 184 | break; |
| 185 | } |
| 186 | |
Summer Qin | 153f3df | 2022-11-17 15:51:02 +0800 | [diff] [blame] | 187 | default: |
| 188 | { |
| 189 | erpcStatus = kErpcStatus_InvalidArgument; |
| 190 | break; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | return erpcStatus; |
| 195 | } |
| 196 | |
| 197 | // Server shim for psa_framework_version of psa_client_api interface. |
| 198 | erpc_status_t psa_client_api_service::psa_framework_version_shim(Codec * codec, MessageBufferFactory *messageFactory, uint32_t sequence) |
| 199 | { |
| 200 | erpc_status_t err = kErpcStatus_Success; |
| 201 | |
| 202 | uint32_t result; |
| 203 | |
| 204 | // startReadMessage() was already called before this shim was invoked. |
| 205 | |
| 206 | err = codec->getStatus(); |
| 207 | if (err == kErpcStatus_Success) |
| 208 | { |
| 209 | // Invoke the actual served function. |
| 210 | #if ERPC_NESTED_CALLS_DETECTION |
| 211 | nestingDetection = true; |
| 212 | #endif |
| 213 | result = psa_framework_version(); |
| 214 | #if ERPC_NESTED_CALLS_DETECTION |
| 215 | nestingDetection = false; |
| 216 | #endif |
| 217 | |
| 218 | // preparing MessageBuffer for serializing data |
| 219 | err = messageFactory->prepareServerBufferForSend(codec->getBuffer()); |
| 220 | } |
| 221 | |
| 222 | if (err == kErpcStatus_Success) |
| 223 | { |
| 224 | // preparing codec for serializing data |
| 225 | codec->reset(); |
| 226 | |
| 227 | // Build response message. |
| 228 | codec->startWriteMessage(kReplyMessage, kpsa_client_api_service_id, kpsa_client_api_psa_framework_version_id, sequence); |
| 229 | |
| 230 | codec->write(result); |
| 231 | |
| 232 | err = codec->getStatus(); |
| 233 | } |
| 234 | |
| 235 | return err; |
| 236 | } |
| 237 | |
| 238 | // Server shim for psa_version of psa_client_api interface. |
| 239 | erpc_status_t psa_client_api_service::psa_version_shim(Codec * codec, MessageBufferFactory *messageFactory, uint32_t sequence) |
| 240 | { |
| 241 | erpc_status_t err = kErpcStatus_Success; |
| 242 | |
| 243 | uint32_t sid; |
| 244 | uint32_t result; |
| 245 | |
| 246 | // startReadMessage() was already called before this shim was invoked. |
| 247 | |
| 248 | codec->read(&sid); |
| 249 | |
| 250 | err = codec->getStatus(); |
| 251 | if (err == kErpcStatus_Success) |
| 252 | { |
| 253 | // Invoke the actual served function. |
| 254 | #if ERPC_NESTED_CALLS_DETECTION |
| 255 | nestingDetection = true; |
| 256 | #endif |
| 257 | result = psa_version(sid); |
| 258 | #if ERPC_NESTED_CALLS_DETECTION |
| 259 | nestingDetection = false; |
| 260 | #endif |
| 261 | |
| 262 | // preparing MessageBuffer for serializing data |
| 263 | err = messageFactory->prepareServerBufferForSend(codec->getBuffer()); |
| 264 | } |
| 265 | |
| 266 | if (err == kErpcStatus_Success) |
| 267 | { |
| 268 | // preparing codec for serializing data |
| 269 | codec->reset(); |
| 270 | |
| 271 | // Build response message. |
| 272 | codec->startWriteMessage(kReplyMessage, kpsa_client_api_service_id, kpsa_client_api_psa_version_id, sequence); |
| 273 | |
| 274 | codec->write(result); |
| 275 | |
| 276 | err = codec->getStatus(); |
| 277 | } |
| 278 | |
| 279 | return err; |
| 280 | } |
| 281 | |
| 282 | // Server shim for erpc_psa_call of psa_client_api interface. |
| 283 | erpc_status_t psa_client_api_service::erpc_psa_call_shim(Codec * codec, MessageBufferFactory *messageFactory, uint32_t sequence) |
| 284 | { |
| 285 | erpc_status_t err = kErpcStatus_Success; |
| 286 | |
| 287 | psa_handle_t handle; |
| 288 | int32_t t; |
| 289 | list_binary_1_t *erpc_in_vec = NULL; |
| 290 | erpc_in_vec = (list_binary_1_t *) erpc_malloc(sizeof(list_binary_1_t)); |
| 291 | if (erpc_in_vec == NULL) |
| 292 | { |
| 293 | codec->updateStatus(kErpcStatus_MemoryError); |
| 294 | } |
| 295 | list_binary_1_t *erpc_out_vec = NULL; |
| 296 | erpc_out_vec = (list_binary_1_t *) erpc_malloc(sizeof(list_binary_1_t)); |
| 297 | if (erpc_out_vec == NULL) |
| 298 | { |
| 299 | codec->updateStatus(kErpcStatus_MemoryError); |
| 300 | } |
| 301 | psa_status_t result; |
| 302 | |
| 303 | // startReadMessage() was already called before this shim was invoked. |
| 304 | |
| 305 | codec->read(&handle); |
| 306 | |
| 307 | codec->read(&t); |
| 308 | |
| 309 | read_list_binary_1_t_struct(codec, erpc_in_vec); |
| 310 | |
| 311 | read_list_binary_1_t_struct(codec, erpc_out_vec); |
| 312 | |
| 313 | err = codec->getStatus(); |
| 314 | if (err == kErpcStatus_Success) |
| 315 | { |
| 316 | // Invoke the actual served function. |
| 317 | #if ERPC_NESTED_CALLS_DETECTION |
| 318 | nestingDetection = true; |
| 319 | #endif |
| 320 | result = erpc_psa_call(handle, t, erpc_in_vec, erpc_out_vec); |
| 321 | #if ERPC_NESTED_CALLS_DETECTION |
| 322 | nestingDetection = false; |
| 323 | #endif |
| 324 | |
| 325 | // preparing MessageBuffer for serializing data |
| 326 | err = messageFactory->prepareServerBufferForSend(codec->getBuffer()); |
| 327 | } |
| 328 | |
| 329 | if (err == kErpcStatus_Success) |
| 330 | { |
| 331 | // preparing codec for serializing data |
| 332 | codec->reset(); |
| 333 | |
| 334 | // Build response message. |
| 335 | codec->startWriteMessage(kReplyMessage, kpsa_client_api_service_id, kpsa_client_api_erpc_psa_call_id, sequence); |
| 336 | |
| 337 | write_list_binary_1_t_struct(codec, erpc_out_vec); |
| 338 | |
| 339 | codec->write(result); |
| 340 | |
| 341 | err = codec->getStatus(); |
| 342 | } |
| 343 | |
| 344 | if (erpc_in_vec) |
| 345 | { |
| 346 | free_list_binary_1_t_struct(erpc_in_vec); |
| 347 | } |
Kevin Peng | 0eca5ea | 2023-07-21 17:32:31 +0800 | [diff] [blame] | 348 | if (erpc_in_vec) |
| 349 | { |
| 350 | erpc_free(erpc_in_vec); |
| 351 | } |
Summer Qin | 153f3df | 2022-11-17 15:51:02 +0800 | [diff] [blame] | 352 | |
| 353 | if (erpc_out_vec) |
| 354 | { |
| 355 | free_list_binary_1_t_struct(erpc_out_vec); |
| 356 | } |
Kevin Peng | 0eca5ea | 2023-07-21 17:32:31 +0800 | [diff] [blame] | 357 | if (erpc_out_vec) |
| 358 | { |
| 359 | erpc_free(erpc_out_vec); |
| 360 | } |
| 361 | |
| 362 | return err; |
| 363 | } |
| 364 | |
| 365 | // Server shim for psa_connect of psa_client_api interface. |
| 366 | erpc_status_t psa_client_api_service::psa_connect_shim(Codec * codec, MessageBufferFactory *messageFactory, uint32_t sequence) |
| 367 | { |
| 368 | erpc_status_t err = kErpcStatus_Success; |
| 369 | |
| 370 | uint32_t sid; |
| 371 | uint32_t ver; |
| 372 | psa_handle_t result; |
| 373 | |
| 374 | // startReadMessage() was already called before this shim was invoked. |
| 375 | |
| 376 | codec->read(&sid); |
| 377 | |
| 378 | codec->read(&ver); |
| 379 | |
| 380 | err = codec->getStatus(); |
| 381 | if (err == kErpcStatus_Success) |
| 382 | { |
| 383 | // Invoke the actual served function. |
| 384 | #if ERPC_NESTED_CALLS_DETECTION |
| 385 | nestingDetection = true; |
| 386 | #endif |
| 387 | result = psa_connect(sid, ver); |
| 388 | #if ERPC_NESTED_CALLS_DETECTION |
| 389 | nestingDetection = false; |
| 390 | #endif |
| 391 | |
| 392 | // preparing MessageBuffer for serializing data |
| 393 | err = messageFactory->prepareServerBufferForSend(codec->getBuffer()); |
| 394 | } |
| 395 | |
| 396 | if (err == kErpcStatus_Success) |
| 397 | { |
| 398 | // preparing codec for serializing data |
| 399 | codec->reset(); |
| 400 | |
| 401 | // Build response message. |
| 402 | codec->startWriteMessage(kReplyMessage, kpsa_client_api_service_id, kpsa_client_api_psa_connect_id, sequence); |
| 403 | |
| 404 | codec->write(result); |
| 405 | |
| 406 | err = codec->getStatus(); |
| 407 | } |
| 408 | |
| 409 | return err; |
| 410 | } |
| 411 | |
| 412 | // Server shim for psa_close of psa_client_api interface. |
| 413 | erpc_status_t psa_client_api_service::psa_close_shim(Codec * codec, MessageBufferFactory *messageFactory, uint32_t sequence) |
| 414 | { |
| 415 | erpc_status_t err = kErpcStatus_Success; |
| 416 | |
| 417 | psa_handle_t handle; |
| 418 | |
| 419 | // startReadMessage() was already called before this shim was invoked. |
| 420 | |
| 421 | codec->read(&handle); |
| 422 | |
| 423 | err = codec->getStatus(); |
| 424 | if (err == kErpcStatus_Success) |
| 425 | { |
| 426 | // Invoke the actual served function. |
| 427 | #if ERPC_NESTED_CALLS_DETECTION |
| 428 | nestingDetection = true; |
| 429 | #endif |
| 430 | psa_close(handle); |
| 431 | #if ERPC_NESTED_CALLS_DETECTION |
| 432 | nestingDetection = false; |
| 433 | #endif |
| 434 | |
| 435 | // preparing MessageBuffer for serializing data |
| 436 | err = messageFactory->prepareServerBufferForSend(codec->getBuffer()); |
| 437 | } |
| 438 | |
| 439 | if (err == kErpcStatus_Success) |
| 440 | { |
| 441 | // preparing codec for serializing data |
| 442 | codec->reset(); |
| 443 | |
| 444 | // Build response message. |
| 445 | codec->startWriteMessage(kReplyMessage, kpsa_client_api_service_id, kpsa_client_api_psa_close_id, sequence); |
| 446 | |
| 447 | err = codec->getStatus(); |
| 448 | } |
Summer Qin | 153f3df | 2022-11-17 15:51:02 +0800 | [diff] [blame] | 449 | |
| 450 | return err; |
| 451 | } |
| 452 | |
| 453 | #if ERPC_ALLOCATION_POLICY == ERPC_ALLOCATION_POLICY_DYNAMIC |
| 454 | erpc_service_t create_psa_client_api_service() |
| 455 | { |
| 456 | return new (nothrow) psa_client_api_service(); |
| 457 | } |
| 458 | |
| 459 | void destroy_psa_client_api_service(erpc_service_t service) |
| 460 | { |
| 461 | if (service) |
| 462 | { |
| 463 | delete (psa_client_api_service *)service; |
| 464 | } |
| 465 | } |
| 466 | #elif ERPC_ALLOCATION_POLICY == ERPC_ALLOCATION_POLICY_STATIC |
| 467 | erpc_service_t create_psa_client_api_service() |
| 468 | { |
| 469 | s_psa_client_api_service.construct(); |
| 470 | return s_psa_client_api_service.get(); |
| 471 | } |
| 472 | |
| 473 | void destroy_psa_client_api_service() |
| 474 | { |
| 475 | s_psa_client_api_service.destroy(); |
| 476 | } |
| 477 | #else |
| 478 | #warning "Unknown eRPC allocation policy!" |
| 479 | #endif |