Open3D (C++ API)  0.16.0
ZMQReceiver.h
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// The MIT License (MIT)
5//
6// Copyright (c) 2018-2021 www.open3d.org
7//
8// Permission is hereby granted, free of charge, to any person obtaining a copy
9// of this software and associated documentation files (the "Software"), to deal
10// in the Software without restriction, including without limitation the rights
11// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12// copies of the Software, and to permit persons to whom the Software is
13// furnished to do so, subject to the following conditions:
14//
15// The above copyright notice and this permission notice shall be included in
16// all copies or substantial portions of the Software.
17//
18// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24// IN THE SOFTWARE.
25// ----------------------------------------------------------------------------
26
27#pragma once
28
29#include <atomic>
30#include <mutex>
31#include <thread>
32
34
35namespace zmq {
36class message_t;
37class socket_t;
38class context_t;
39} // namespace zmq
40
41namespace open3d {
42namespace io {
43namespace rpc {
44
45class MessageProcessorBase;
46
47namespace messages {
48struct Request;
49struct SetMeshData;
50struct GetMeshData;
51struct SetCameraData;
52struct SetProperties;
53struct SetActiveCamera;
54struct SetTime;
55} // namespace messages
56
59public:
63 ZMQReceiver(const std::string& address = "tcp://127.0.0.1:51454",
64 int timeout = 10000);
65
66 ZMQReceiver(const ZMQReceiver&) = delete;
68
69 virtual ~ZMQReceiver();
70
72 void Start();
73
77 void Stop();
78
80 std::runtime_error GetLastError();
81
83 void SetMessageProcessor(std::shared_ptr<MessageProcessorBase> processor);
84
85private:
86 void Mainloop();
87
88 const std::string address_;
89 const int timeout_;
90 std::shared_ptr<zmq::context_t> context_;
91 std::unique_ptr<zmq::socket_t> socket_;
92 std::thread thread_;
93 std::mutex mutex_;
94 bool keep_running_;
95 std::atomic<bool> loop_running_;
96 std::atomic<int> mainloop_error_code_;
97 std::runtime_error mainloop_exception_;
98 std::shared_ptr<MessageProcessorBase> processor_;
99};
100
101} // namespace rpc
102} // namespace io
103} // namespace open3d
Class for the server side receiving requests from a client.
Definition: ZMQReceiver.h:58
virtual ~ZMQReceiver()
Definition: ZMQReceiver.cpp:63
void Start()
Starts the receiver mainloop in a new thread.
Definition: ZMQReceiver.cpp:65
ZMQReceiver(const std::string &address="tcp://127.0.0.1:51454", int timeout=10000)
Definition: ZMQReceiver.cpp:55
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:232
std::runtime_error GetLastError()
Returns the last error from the mainloop thread.
Definition: ZMQReceiver.cpp:106
void Stop()
Definition: ZMQReceiver.cpp:89
ZMQReceiver(const ZMQReceiver &)=delete
bool SetTime(int time, std::shared_ptr< ConnectionBase > connection)
Definition: RemoteFunctions.cpp:414
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:206
bool SetActiveCamera(const std::string &path, std::shared_ptr< ConnectionBase > connection)
Definition: RemoteFunctions.cpp:431
Definition: PinholeCameraIntrinsic.cpp:35
Definition: ConnectionBase.h:31