gphoto2pp
A C++ Wrapper for libgphoto2
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
camera_wrapper.hpp
Go to the documentation of this file.
1 
25 #ifndef CAMERA_HPP
26 #define CAMERA_HPP
27 
28 #include "observer.hpp"
29 
30 #include <string>
31 #include <iosfwd>
32 #include <future>
33 #include <mutex>
34 #include <memory>
35 
36 namespace gphoto2
37 {
38  struct _Camera;
39  struct _GPContext;
40 }
41 
42 namespace gphoto2pp
43 {
44  //Forward Declarations
45  enum class CameraEventTypeWrapper : int;
46  enum class CameraFileTypeWrapper : int;
47  enum class CameraCaptureTypeWrapper : int;
48 
49  struct CameraFilePathWrapper;
50 
51  class CameraFileWrapper;
52  class CameraWidgetWrapper;
53  class WindowWidget;
54  class CameraListWrapper;
55 
57  {
58  public:
62  CameraWrapper();
63 
67  CameraWrapper(std::string const & model, std::string const & port);
68 
69  ~CameraWrapper();
70 
71  // Move constructor and move assignment are allowed.
73  CameraWrapper& operator=(CameraWrapper&& other);
74 
75  // This is not copyable. the t_Camera object is sort of a singleton. We don't want multiple commands being issued to one t_Camera resource.
76  CameraWrapper(const CameraWrapper& other) = delete;
77  CameraWrapper& operator=(CameraWrapper const & other) = delete;
78 
86  std::string getSummary() const;
87 
92  std::string getModel() const;
93 
98  std::string getPort() const;
99 
108 
117 
124  void triggerCapture();
125 
132  WindowWidget getConfig() const;
133 
142  void setConfig(CameraWidgetWrapper const & cameraWidget);
143 
144  //Filesystem Operations
152  CameraListWrapper folderListFiles(std::string const & folder) const;
153 
161  CameraListWrapper folderListFolders(std::string const & folder) const;
162 
169  void folderDeleteAll(std::string const & folder);
170 
180  void folderPutFile(std::string const & folder, std::string const & fileName, CameraFileTypeWrapper const & fileType, CameraFileWrapper cameraFile);
181 
189  void folderMakeDir(std::string const & folder, std::string const & name);
190 
198  void folderRemoveDir(std::string const & folder, std::string const & name);
199 
209  CameraFileWrapper fileGet(std::string const & folder, std::string const & fileName, CameraFileTypeWrapper const & fileType) const;
210 
218  void fileDelete(std::string const & folder, std::string const & fileName) const;
219 
235  observer::Registration subscribeToCameraEvent(CameraEventTypeWrapper const & event, std::function<void(const CameraFilePathWrapper&, const std::string&)> func);
236 
242  bool startListeningForEvents();
243 
248  void stopListeningForEvents();
249 
250  private:
254  void initialize();
255 
261  void initialize(std::string const & model, std::string const & port);
262 
263  gphoto2::_Camera* m_camera = nullptr;
264 
265  std::shared_ptr<gphoto2::_GPContext> m_context;
266 
267  std::string m_model;
268  std::string m_port;
269 
270  observer::SubjectEvent<CameraEventTypeWrapper, void(const CameraFilePathWrapper&, const std::string&)> m_cameraEvents;
271 
272  std::atomic<bool> m_listenForEvents;
273  std::future<bool> m_listenForEventSignalFuture;
274 
275  mutable std::mutex m_cameraIOMutex;
276  };
277 
278 }
279 
280 #endif // CAMERA_HPP