Open3D (C++ API)  0.17.0
ZMQReceiver.h
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// Copyright (c) 2018-2023 www.open3d.org
5// SPDX-License-Identifier: MIT
6// ----------------------------------------------------------------------------
7
8#pragma once
9
10#include <atomic>
11#include <mutex>
12#include <thread>
13
15
16namespace zmq {
17class message_t;
18class socket_t;
19class context_t;
20} // namespace zmq
21
22namespace open3d {
23namespace io {
24namespace rpc {
25
26class MessageProcessorBase;
27
28namespace messages {
29struct Request;
30struct SetMeshData;
31struct GetMeshData;
32struct SetCameraData;
33struct SetProperties;
34struct SetActiveCamera;
35struct SetTime;
36} // namespace messages
37
40public:
44 ZMQReceiver(const std::string& address = "tcp://127.0.0.1:51454",
45 int timeout = 10000);
46
47 ZMQReceiver(const ZMQReceiver&) = delete;
49
50 virtual ~ZMQReceiver();
51
53 void Start();
54
58 void Stop();
59
61 std::runtime_error GetLastError();
62
64 void SetMessageProcessor(std::shared_ptr<MessageProcessorBase> processor);
65
66private:
67 void Mainloop();
68
69 const std::string address_;
70 const int timeout_;
71 std::shared_ptr<zmq::context_t> context_;
72 std::unique_ptr<zmq::socket_t> socket_;
73 std::thread thread_;
74 std::mutex mutex_;
75 bool keep_running_;
76 std::atomic<bool> loop_running_;
77 std::atomic<int> mainloop_error_code_;
78 std::runtime_error mainloop_exception_;
79 std::shared_ptr<MessageProcessorBase> processor_;
80};
81
82} // namespace rpc
83} // namespace io
84} // namespace open3d
Class for the server side receiving requests from a client.
Definition: ZMQReceiver.h:39
virtual ~ZMQReceiver()
Definition: ZMQReceiver.cpp:44
void Start()
Starts the receiver mainloop in a new thread.
Definition: ZMQReceiver.cpp:46
ZMQReceiver(const std::string &address="tcp://127.0.0.1:51454", int timeout=10000)
Definition: ZMQReceiver.cpp:36
ZMQReceiver & operator=(const ZMQReceiver &)=delete
void SetMessageProcessor(std::shared_ptr< MessageProcessorBase > processor)
Sets the message processor object which will process incoming messages.
Definition: ZMQReceiver.cpp:213
std::runtime_error GetLastError()
Returns the last error from the mainloop thread.
Definition: ZMQReceiver.cpp:87
void Stop()
Definition: ZMQReceiver.cpp:70
ZMQReceiver(const ZMQReceiver &)=delete
bool SetTime(int time, std::shared_ptr< ConnectionBase > connection)
Definition: RemoteFunctions.cpp:395
bool SetMeshData(const std::string &path, int time, const std::string &layer, const core::Tensor &vertices, const std::map< std::string, core::Tensor > &vertex_attributes, const core::Tensor &faces, const std::map< std::string, core::Tensor > &face_attributes, const core::Tensor &lines, const std::map< std::string, core::Tensor > &line_attributes, const std::string &material, const std::map< std::string, float > &material_scalar_attributes, const std::map< std::string, std::array< float, 4 > > &material_vector_attributes, const std::map< std::string, t::geometry::Image > &texture_maps, const std::string &o3d_type, std::shared_ptr< ConnectionBase > connection)
Definition: RemoteFunctions.cpp:187
bool SetActiveCamera(const std::string &path, std::shared_ptr< ConnectionBase > connection)
Definition: RemoteFunctions.cpp:412
Definition: PinholeCameraIntrinsic.cpp:16
Definition: ConnectionBase.h:12