| 44 | //////////////////////////////////////////////////////////////////////////////// |
| 45 | |
| 46 | erpc_client_t erpc_client_init(erpc_transport_t transport, erpc_mbf_t message_buffer_factory) |
| 47 | { |
| 48 | erpc_assert(transport != NULL); |
| 49 | erpc_assert(message_buffer_factory != NULL); |
| 50 | |
| 51 | Transport *castedTransport; |
| 52 | BasicCodecFactory *codecFactory; |
| 53 | Crc16 *crc16; |
| 54 | ClientManager *client; |
| 55 | |
| 56 | #if ERPC_ALLOCATION_POLICY == ERPC_ALLOCATION_POLICY_STATIC |
| 57 | if (s_codecFactory.isUsed() || s_crc16.isUsed() || s_client.isUsed()) |
| 58 | { |
| 59 | client = NULL; |
| 60 | } |
| 61 | else |
| 62 | { |
| 63 | // Init factories. |
| 64 | s_codecFactory.construct(); |
| 65 | codecFactory = s_codecFactory.get(); |
| 66 | |
| 67 | s_crc16.construct(); |
| 68 | crc16 = s_crc16.get(); |
| 69 | |
| 70 | // Init the client manager. |
| 71 | s_client.construct(); |
| 72 | client = s_client.get(); |
| 73 | } |
| 74 | #elif ERPC_ALLOCATION_POLICY == ERPC_ALLOCATION_POLICY_DYNAMIC |
| 75 | // Init factories. |
| 76 | codecFactory = new BasicCodecFactory(); |
| 77 | |
| 78 | crc16 = new Crc16(); |
| 79 | |
| 80 | // Init the client manager. |
| 81 | client = new ClientManager(); |
| 82 | |
| 83 | if ((codecFactory == NULL) || (crc16 == NULL) || (client == NULL)) |
| 84 | { |
| 85 | if (codecFactory != NULL) |
| 86 | { |
| 87 | delete codecFactory; |
| 88 | } |
| 89 | if (crc16 != NULL) |
| 90 | { |
| 91 | delete crc16; |
| 92 | } |
| 93 | if (client != NULL) |
| 94 | { |
| 95 | delete client; |
| 96 | } |
| 97 | client = NULL; |
| 98 | } |
| 99 | #else |
| 100 | #error "Unknown eRPC allocation policy!" |
| 101 | #endif |
| 102 | |
| 103 | if (client != NULL) |