forked from seanavery/viam-csi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
77 lines (62 loc) · 2.35 KB
/
main.cpp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include <gst/gst.h>
#include <viam/sdk/module/module.hpp>
#include <viam/sdk/module/service.hpp>
#include <viam/sdk/resource/resource.hpp>
#include <viam/sdk/registry/registry.hpp>
#include <viam/sdk/components/camera/server.hpp>
#include "constraints.h"
#include "csi_camera.cpp"
using namespace viam::sdk;
int serve(const std::string& socket_path) {
// Signal handlers
sigset_t sigset;
sigemptyset(&sigset);
sigaddset(&sigset, SIGINT);
sigaddset(&sigset, SIGTERM);
pthread_sigmask(SIG_BLOCK, &sigset, NULL);
// Model regsitration
auto module_registration = std::make_shared<ModelRegistration>(
ResourceType{RESOURCE_TYPE},
Camera::static_api(),
Model{API_NAMESPACE, API_TYPE, API_SUBTYPE},
[](Dependencies, ResourceConfig resource_config) -> std::shared_ptr<Resource> {
return std::make_shared<CSICamera>(resource_config.name(), resource_config.attributes());
},
[](ResourceConfig resource_config) -> std::vector<std::string> { return {}; });
try {
Registry::register_model(module_registration);
std::cout << "registered model: " << API_NAMESPACE << ":" << API_TYPE << ":" << API_SUBTYPE << std::endl;
} catch (const std::runtime_error& e) {
std::cerr << "error registering model: " << e.what() << std::endl;
return EXIT_FAILURE;
}
// Socket
auto module_service = std::make_shared<ModuleService_>(socket_path);
// GRPC Server
auto server = std::make_shared<Server>();
module_service->add_model_from_registry(
server,
module_registration->api(),
module_registration->model());
module_service->start(server);
// Start server thread
std::thread server_thread([&server, &sigset]() {
server->start();
int sig = 0;
auto result = sigwait(&sigset, &sig);
server->shutdown();
});
server->wait();
server_thread.join();
return EXIT_SUCCESS;
}
int main(int argc, char *argv[]) {
std::cout << "### STARTING VIAM CSI CAMERA MODULE" << std::endl;
// Gstreamer initialization
gst_init(&argc, &argv);
std::string sock_path = (argc < 2) ? DEFAULT_SOCKET_PATH : argv[1];
std::cout << "binary:" << argv[0] << std::endl;
std::cout << "socket: " << sock_path << std::endl;
return serve(sock_path);
}