-
Notifications
You must be signed in to change notification settings - Fork 410
Expand file tree
/
Copy pathmain.cc
More file actions
60 lines (49 loc) · 1.73 KB
/
main.cc
File metadata and controls
60 lines (49 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "../build/dora-node-api.h"
#include <iostream>
#include <vector>
int main()
{
std::cout << "HELLO FROM C++" << std::endl;
unsigned char counter = 0;
auto dora_node = init_dora_node();
for (int i = 0; i < 20; i++)
{
auto event = dora_node.events->next();
auto ty = event_type(event);
if (ty == DoraEventType::AllInputsClosed)
{
break;
}
else if (ty == DoraEventType::Input)
{
auto input = event_as_input(std::move(event));
counter += 1;
std::cout << "Received input " << std::string(input.id) << " (counter: " << (unsigned int)counter << ")" << std::endl;
std::vector<unsigned char> out_vec{counter};
rust::Slice<const uint8_t> out_slice{out_vec.data(), out_vec.size()};
auto result = send_output(dora_node.send_output, "counter", out_slice);
auto error = std::string(result.error);
if (!error.empty())
{
std::cerr << "Error: " << error << std::endl;
return -1;
}
}
else if (ty == DoraEventType::NodeFailed)
{
auto failed = event_as_node_failed(std::move(event));
std::cerr << "Node failed: source=" << std::string(failed.source_node_id)
<< " error=" << std::string(failed.error) << std::endl;
}
else if (ty == DoraEventType::Reload)
{
std::cout << "Reload event received" << std::endl;
}
else
{
std::cerr << "Unknown event type " << static_cast<int>(ty) << std::endl;
}
}
std::cout << "GOODBYE FROM C++ node (using Rust API)" << std::endl;
return 0;
}