Open3D (C++ API)  0.11.0
ReceiverBase.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2020 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 
33 #include "open3d/utility/Console.h"
34 
35 namespace zmq {
36 class message_t;
37 class socket_t;
38 } // namespace zmq
39 
40 namespace open3d {
41 namespace io {
42 namespace rpc {
43 
44 namespace messages {
45 struct Request;
46 struct SetMeshData;
47 struct GetMeshData;
48 struct SetCameraData;
49 struct SetProperties;
50 struct SetActiveCamera;
51 struct SetTime;
52 } // namespace messages
53 
57 class ReceiverBase {
58 public:
62  ReceiverBase(const std::string& address = "tcp://127.0.0.1:51454",
63  int timeout = 10000);
64 
65  ReceiverBase(const ReceiverBase&) = delete;
66  ReceiverBase& operator=(const ReceiverBase&) = delete;
67 
68  ~ReceiverBase();
69 
71  void Start();
72 
76  void Stop();
77 
78 protected:
79  // Opaque type for providing the original msgpack::object to the
80  // ProcessMessage functions
81  struct MsgpackObject;
82 
90  virtual std::shared_ptr<zmq::message_t> ProcessMessage(
91  const messages::Request& req,
92  const messages::SetMeshData& msg,
93  const MsgpackObject& obj);
94  virtual std::shared_ptr<zmq::message_t> ProcessMessage(
95  const messages::Request& req,
96  const messages::GetMeshData& msg,
97  const MsgpackObject& obj);
98  virtual std::shared_ptr<zmq::message_t> ProcessMessage(
99  const messages::Request& req,
100  const messages::SetCameraData& msg,
101  const MsgpackObject& obj);
102  virtual std::shared_ptr<zmq::message_t> ProcessMessage(
103  const messages::Request& req,
104  const messages::SetProperties& msg,
105  const MsgpackObject& obj);
106  virtual std::shared_ptr<zmq::message_t> ProcessMessage(
107  const messages::Request& req,
108  const messages::SetActiveCamera& msg,
109  const MsgpackObject& obj);
110  virtual std::shared_ptr<zmq::message_t> ProcessMessage(
111  const messages::Request& req,
112  const messages::SetTime& msg,
113  const MsgpackObject& obj);
114 
115 private:
116  void Mainloop();
117 
118  const std::string address_;
119  const int timeout_;
120  std::unique_ptr<zmq::socket_t> socket_;
121  std::thread thread_;
122  std::mutex mutex_;
123  bool keep_running_;
124  std::atomic<bool> loop_running_;
125 };
126 
127 } // namespace rpc
128 } // namespace io
129 } // namespace open3d
Definition: ReceiverBase.cpp:54
Definition: Messages.h:190
Definition: Messages.h:307
Definition: Messages.h:277
Definition: PinholeCameraIntrinsic.cpp:35
struct for defining a "get_mesh_data" message, which requests mesh data.
Definition: Messages.h:209
bool SetMeshData(const core::Tensor &vertices, const std::string &path, int time, const std::string &layer, 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::map< std::string, core::Tensor > &textures, std::shared_ptr< ConnectionBase > connection)
Definition: RemoteFunctions.cpp:163
Definition: ConnectionBase.h:31
Definition: ReceiverBase.h:57
bool SetTime(int time, std::shared_ptr< ConnectionBase > connection)
Definition: RemoteFunctions.cpp:377
bool SetActiveCamera(const std::string &path, std::shared_ptr< ConnectionBase > connection)
Definition: RemoteFunctions.cpp:394