ifm3d
frame_grabber.h
1 /*
2  * Copyright 2022-present ifm electronic, gmbh
3 
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef IFM3D_FG_FRAMEGRABBER_H
8 #define IFM3D_FG_FRAMEGRABBER_H
9 #pragma once
10 
11 #include <cstdint>
12 #include <future>
13 #include <ifm3d/device/device.h>
14 #include <ifm3d/device/err.h>
15 #include <ifm3d/device/pcic_command.h>
16 #include <ifm3d/fg/buffer.h>
17 #include <ifm3d/fg/frame.h>
18 #include <ifm3d/fg/module_frame_grabber.h>
19 #include <ifm3d/fg/organizer.h>
20 #include <memory>
21 #include <optional>
22 #include <variant>
23 #include <vector>
24 
25 namespace ifm3d
26 {
31  class IFM3D_EXPORT FrameGrabber
32  {
33  public:
34  using Ptr = std::shared_ptr<FrameGrabber>;
35  using NewFrameCallback = std::function<void(Frame::Ptr)>;
36  using AsyncErrorCallback = std::function<void(int, const std::string&)>;
37  using AsyncNotificationCallback =
38  std::function<void(const std::string&, const std::string&)>;
39  using ErrorCallback = std::function<void(const ifm3d::Error&)>;
40  using BufferList =
41  std::vector<std::variant<std::uint64_t, int, ifm3d::buffer_id>>;
42  using PCICCommandResponse =
43  std::variant<std::monostate, std::string, std::vector<std::uint8_t>>;
44 
51  FrameGrabber(ifm3d::Device::Ptr cam,
52  std::optional<std::uint16_t> pcic_port = std::nullopt);
53 
58  virtual ~FrameGrabber();
59 
60  // disable copy/move semantics
61  FrameGrabber(FrameGrabber&&) = delete;
62  FrameGrabber& operator=(FrameGrabber&&) = delete;
63  FrameGrabber(FrameGrabber&) = delete;
64  FrameGrabber& operator=(const FrameGrabber&) = delete;
65 
81  std::shared_future<void> SWTrigger();
82 
87  void OnNewFrame(NewFrameCallback callback = nullptr);
88 
110  std::shared_future<void> Start(
111  const BufferList& buffers,
112  const std::optional<json>& schema = std::nullopt);
113 
119  std::shared_future<void> Stop();
120 
124  bool IsRunning();
125 
129  std::shared_future<Frame::Ptr> WaitForFrame();
130 
137  void SetOrganizer(std::unique_ptr<Organizer> organizer);
138 
145  void OnAsyncError(AsyncErrorCallback callback = nullptr);
146 
152  void OnAsyncNotification(AsyncNotificationCallback callback = nullptr);
153 
158  void OnError(ErrorCallback callback = nullptr);
159 
166  void SetMasking(bool mask);
167 
171  bool IsMasking();
172 
185  std::shared_future<PCICCommandResponse> SendCommand(
186  const PCICCommand& command);
187 
188  private:
189  class Impl;
190  std::unique_ptr<Impl> _impl;
191 
192  }; // end: class FrameGrabber
193 
194 } // end: namespace ifm3d
195 
196 #endif // IFM3D_FG_FRAMEGRABBER_H
ifm3d::FrameGrabber
Definition: frame_grabber.h:31
ifm3d::Error
Definition: err.h:114
ifm3d::PCICCommand
Definition: pcic_command.h:10