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 <memory>
14 #include <optional>
15 #include <vector>
16 #include <variant>
17 #include <ifm3d/device/device.h>
18 #include <ifm3d/device/err.h>
19 #include <ifm3d/fg/buffer.h>
20 #include <ifm3d/fg/organizer.h>
21 #include <ifm3d/fg/frame.h>
22 #include <ifm3d/fg/module_frame_grabber.h>
23 
24 namespace ifm3d
25 {
30  class IFM3D_EXPORT FrameGrabber
31  {
32  public:
33  using Ptr = std::shared_ptr<FrameGrabber>;
34  using NewFrameCallback = std::function<void(Frame::Ptr)>;
35  using AsyncErrorCallback = std::function<void(int, const std::string&)>;
36  using AsyncNotificationCallback =
37  std::function<void(const std::string&, const std::string&)>;
38  using BufferList =
39  std::vector<std::variant<std::uint64_t, int, ifm3d::buffer_id>>;
40  using ErrorCallback = std::function<void(const ifm3d::Error&)>;
41 
48  FrameGrabber(ifm3d::Device::Ptr cam,
49  std::optional<std::uint16_t> pcic_port = std::nullopt);
50 
55  virtual ~FrameGrabber();
56 
57  // disable copy/move semantics
58  FrameGrabber(FrameGrabber&&) = delete;
59  FrameGrabber& operator=(FrameGrabber&&) = delete;
60  FrameGrabber(FrameGrabber&) = delete;
61  FrameGrabber& operator=(const FrameGrabber&) = delete;
62 
78  std::shared_future<void> SWTrigger();
79 
84  void OnNewFrame(NewFrameCallback callback = nullptr);
85 
107  std::shared_future<void> Start(
108  const BufferList& buffers,
109  const std::optional<json>& schema = std::nullopt);
110 
116  std::shared_future<void> Stop();
117 
121  bool IsRunning();
122 
126  std::shared_future<Frame::Ptr> WaitForFrame();
127 
134  void SetOrganizer(std::unique_ptr<Organizer> organizer);
135 
142  void OnAsyncError(AsyncErrorCallback callback = nullptr);
143 
149  void OnAsyncNotification(AsyncNotificationCallback callback = nullptr);
150 
155  void OnError(ErrorCallback callback = nullptr);
156 
163  void SetMasking(const bool mask);
164 
168  bool IsMasking();
169 
170  private:
171  class Impl;
172  std::unique_ptr<Impl> pImpl;
173 
174  }; // end: class FrameGrabber
175 
176 } // end: namespace ifm3d
177 
178 #endif // IFM3D_FG_FRAMEGRABBER_H
ifm3d::FrameGrabber
Definition: frame_grabber.h:30
ifm3d::Error
Definition: err.h:114