Skip to content

Commit c9e2ffe

Browse files
committed
Fix compilation
1 parent 88769c0 commit c9e2ffe

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

examples/main.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
#include <internal_client.h>
2+
#include <memory_management.h>
23
#include <iostream>
34
#include <modules/CarAccessoryModule.pb.h>
45

56

67
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};
819
void *context {};
920
int rc = init_connection(&context, "127.0.0.1", 8888, device);
21+
deallocate(&deviceRoleBuffer);
22+
deallocate(&deviceNameBuffer);
1023
if(rc != OK ) {
11-
destroy_connection(&context);
24+
if(context != nullptr) {
25+
destroy_connection(&context);
26+
}
1227
return rc;
1328
}
1429

0 commit comments

Comments
 (0)