|
1 | 1 | #include <internal_client.h> |
| 2 | +#include <memory_management.h> |
2 | 3 | #include <iostream> |
3 | 4 | #include <modules/CarAccessoryModule.pb.h> |
4 | 5 |
|
5 | 6 |
|
6 | 7 | int main() { |
7 | | - struct device_identification device {2, 0, "button", "example_button", 0}; |
| 8 | + |
| 9 | + std::string deviceRole = "example_button"; |
| 10 | + std::string deviceName = "button"; |
| 11 | + buffer deviceRoleBuffer {}; |
| 12 | + allocate(&deviceRoleBuffer, deviceRole.length()); |
| 13 | + std::memcpy(deviceRoleBuffer.data, deviceRole.c_str(), deviceRoleBuffer.size_in_bytes); |
| 14 | + buffer deviceNameBuffer {}; |
| 15 | + allocate(&deviceNameBuffer, deviceName.length()); |
| 16 | + std::memcpy(deviceNameBuffer.data, deviceName.c_str(), deviceNameBuffer.size_in_bytes); |
| 17 | + |
| 18 | + struct device_identification device {2, 0, deviceNameBuffer, deviceRoleBuffer, 0}; |
8 | 19 | void *context {}; |
9 | 20 | int rc = init_connection(&context, "127.0.0.1", 8888, device); |
| 21 | + deallocate(&deviceRoleBuffer); |
| 22 | + deallocate(&deviceNameBuffer); |
10 | 23 | if(rc != OK ) { |
11 | | - destroy_connection(&context); |
| 24 | + if(context != nullptr) { |
| 25 | + destroy_connection(&context); |
| 26 | + } |
12 | 27 | return rc; |
13 | 28 | } |
14 | 29 |
|
|
0 commit comments