Open3D (C++ API)  0.18.0+252c867
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 
14 #include "open3d/utility/Logging.h"
15 
16 namespace zmq {
17 class message_t;
18 class socket_t;
19 class context_t;
20 } // namespace zmq
21 
22 namespace open3d {
23 namespace io {
24 namespace rpc {
25 
26 class MessageProcessorBase;
27 
28 namespace messages {
29 struct Request;
30 struct SetMeshData;
31 struct GetMeshData;
32 struct SetCameraData;
33 struct SetProperties;
34 struct SetActiveCamera;
35 struct SetTime;
36 } // namespace messages
37 
39 class ZMQReceiver {
40 public:
44  ZMQReceiver(const std::string& address = "tcp://127.0.0.1:51454",
45  int timeout = 10000);
46 
47  ZMQReceiver(const ZMQReceiver&) = delete;
48  ZMQReceiver& operator=(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 
66 private:
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
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
ZMQReceiver & operator=(const ZMQReceiver &)=delete
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