├── .gitignore ├── tests ├── unit_test_sample_input.jpg ├── CMakeLists.txt ├── Helpers_widgets_Generic.h ├── Helpers_gphoto2_Generic.h ├── Helpers_camera_wrapper_Generic.h ├── Helpers_gphoto2_NoDevice.h ├── CameraWidgetWrapper_Generic.h ├── CameraWrapper_Generic.h └── CameraListWrapper_NoDevice.h ├── gphoto2pp.pc.in ├── cmake_debug.sh ├── cmake_release.sh ├── examples ├── CMakeLists.txt ├── example1.cpp ├── example2.cpp ├── example7.cpp ├── example3.cpp ├── example9.cpp ├── example11.cpp ├── example10.cpp ├── example4.cpp └── example5.cpp ├── cmake_uninstall.cmake.in ├── update_doc.sh ├── include └── gphoto2pp │ ├── button_widget.hpp │ ├── range_widget_range.hpp │ ├── camera_capture_type_wrapper.hpp │ ├── camera_file_path_wrapper.hpp │ ├── section_widget.hpp │ ├── text_widget.hpp │ ├── menu_widget.hpp │ ├── toggle_widget.hpp │ ├── radio_widget.hpp │ ├── window_widget.hpp │ ├── camera_event_type_wrapper.hpp │ ├── camera_file_type_wrapper.hpp │ ├── helper_context.hpp │ ├── camera_widget_type_wrapper.hpp │ ├── range_widget.hpp │ ├── int_widget.hpp │ ├── float_widget.hpp │ ├── date_widget.hpp │ ├── value_widget_base.hpp │ ├── string_widget.hpp │ ├── helper_debugging.hpp │ ├── gp_port_info_list_wrapper.hpp │ ├── helper_widgets.hpp │ ├── helper_gphoto2.hpp │ ├── camera_abilities_list_wrapper.hpp │ ├── choices_widget.hpp │ ├── exceptions.hpp │ ├── log.h │ ├── camera_list_wrapper.hpp │ ├── non_value_widget.hpp │ └── camera_widget_wrapper.hpp ├── src ├── text_widget.cpp ├── menu_widget.cpp ├── radio_widget.cpp ├── toggle_widget.cpp ├── window_widget.cpp ├── section_widget.cpp ├── helper_context.cpp ├── int_widget.cpp ├── float_widget.cpp ├── string_widget.cpp ├── date_widget.cpp ├── range_widget.cpp ├── gp_port_info_list_wrapper.cpp ├── non_value_widget.cpp ├── helper_widgets.cpp ├── choices_widget.cpp ├── camera_abilities_list_wrapper.cpp ├── helper_gphoto2.cpp ├── helper_debugging.cpp ├── helper_camera_wrapper.cpp ├── camera_list_wrapper.cpp └── camera_widget_wrapper.cpp ├── DEV-TEST.md ├── cmake └── modules │ └── FindGphoto2.cmake ├── README.md ├── INSTALL.md └── CMakeLists.txt /.gitignore: -------------------------------------------------------------------------------- 1 | gh-pages/ 2 | build/ 3 | doxygen/ 4 | -------------------------------------------------------------------------------- /tests/unit_test_sample_input.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maldworth/gphoto2pp/HEAD/tests/unit_test_sample_input.jpg -------------------------------------------------------------------------------- /gphoto2pp.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=@CMAKE_INSTALL_PREFIX@ 3 | libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@ 4 | includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ 5 | 6 | Name: @PROJECT_NAME@ 7 | Description: @PROJECT_DESCRIPTION@ 8 | Version: @MYLIB_VERSION_STRING@ 9 | 10 | Requires: 11 | Libs: -L${libdir} -lgphoto2pp -lgphoto2 12 | Cflags: -I${includedir} 13 | -------------------------------------------------------------------------------- /cmake_debug.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # builds the cmake files into the build directory 4 | 5 | set -e 6 | 7 | if [ -d "./build/debug/" ]; then 8 | echo "Debug build found, cleaning up..." 9 | cd ./build/ 10 | rm -rf -- debug/ 11 | mkdir debug 12 | cd debug 13 | cmake -DCMAKE_BUILD_TYPE=DEBUG ../../ 14 | else 15 | echo "Debug build not found, making directory..." 16 | mkdir -p ./build/debug/ 17 | cd ./build/debug/ 18 | cmake -DCMAKE_BUILD_TYPE=DEBUG ../../ 19 | fi 20 | -------------------------------------------------------------------------------- /cmake_release.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # builds the cmake files into the build directory 4 | 5 | set -e 6 | 7 | if [ -d "./build/release/" ]; then 8 | echo "Release build found, cleaning up..." 9 | cd ./build/ 10 | rm -rf -- release/ 11 | mkdir release 12 | cd release 13 | cmake -DCMAKE_BUILD_TYPE=RELEASE ../../ 14 | else 15 | echo "Release build not found, making directory..." 16 | mkdir -p ./build/release/ 17 | cd ./build/release/ 18 | cmake -DCMAKE_BUILD_TYPE=RELEASE ../../ 19 | fi 20 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(EXECUTABLE_OUTPUT_PATH ${EXECUTABLE_OUTPUT_PATH}/examples) 2 | 3 | add_custom_target( examples ) 4 | 5 | FILE(GLOB EXAMPLES_SOURCE_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp") 6 | foreach( examplesourcefile ${EXAMPLES_SOURCE_FILES} ) 7 | # I used a simple string replace, to cut off .cpp. 8 | string( REPLACE ".cpp" "" examplename ${examplesourcefile} ) 9 | add_executable( ${examplename} EXCLUDE_FROM_ALL ${examplesourcefile} ) 10 | # Make sure YourLib is linked to each app 11 | target_link_libraries( ${examplename} gphoto2pp ${LIBS} ) 12 | # Adds this example to the `make examples` custom target 13 | add_dependencies( examples ${examplename} ) 14 | endforeach( examplesourcefile ${EXAMPLES_SOURCE_FILES} ) 15 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(CxxTest) 2 | if(CXXTEST_FOUND) 3 | enable_testing() 4 | set(EXECUTABLE_OUTPUT_PATH ${EXECUTABLE_OUTPUT_PATH}/cxxtests) 5 | 6 | #include_directories(${GPHOTO2PP_SOURCE_DIR}/gphoto2pp/include) 7 | include_directories(${CXXTEST_INCLUDE_DIR}) 8 | 9 | #First copies the testing png to the ../build/tests folder where all the test runners (*.cc) files are generated. That's where ctest executes it's tests from 10 | file(COPY unit_test_sample_input.jpg DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) 11 | FILE(GLOB TESTS_SOURCE_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.h") 12 | foreach( testssourcefile ${TESTS_SOURCE_FILES} ) 13 | # I used a simple string replace, to cut off .h. 14 | string( REPLACE ".h" "" testname ${testssourcefile} ) 15 | CXXTEST_ADD_TEST( ${testname} "${testname}.cc" "${CMAKE_CURRENT_SOURCE_DIR}/${testssourcefile}" ) 16 | # Make sure YourLib is linked to each app 17 | target_link_libraries( ${testname} gphoto2pp ${LIBS} ) 18 | endforeach( testssourcefile ${TESTS_SOURCE_FILES} ) 19 | endif(CXXTEST_FOUND) 20 | -------------------------------------------------------------------------------- /cmake_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | if (NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 2 | message(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"") 3 | endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 4 | 5 | file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) 6 | string(REGEX REPLACE "\n" ";" files "${files}") 7 | list(REVERSE files) 8 | foreach (file ${files}) 9 | message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"") 10 | if (EXISTS "$ENV{DESTDIR}${file}") 11 | execute_process( 12 | COMMAND @CMAKE_COMMAND@ -E remove "$ENV{DESTDIR}${file}" 13 | OUTPUT_VARIABLE rm_out 14 | RESULT_VARIABLE rm_retval 15 | ) 16 | if(NOT ${rm_retval} EQUAL 0) 17 | message(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"") 18 | endif (NOT ${rm_retval} EQUAL 0) 19 | else (EXISTS "$ENV{DESTDIR}${file}") 20 | message(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.") 21 | endif (EXISTS "$ENV{DESTDIR}${file}") 22 | endforeach(file) 23 | -------------------------------------------------------------------------------- /update_doc.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Updates the doxygen documentation, and copies it into the appropriate place 4 | # in the gh-pages branch. 5 | 6 | set -e 7 | 8 | if [ -d "./build/debug/" ]; then 9 | echo "Debug build found, making documentation..." 10 | cd ./build/debug 11 | make doc 12 | cd ../../ 13 | tempdir=`mktemp -d` 14 | cp -r ./doxygen/* ${tempdir} 15 | if [ -d "./gh-pages/" ]; then 16 | echo "gh-pages already exists, removing it" 17 | rm -rf -- gh-pages/ 18 | fi 19 | mkdir gh-pages 20 | cd gh-pages 21 | git init 22 | git remote add -t gh-pages -f origin https://github.com/maldworth/gphoto2pp.git 23 | git checkout gh-pages 24 | cp -rf ${tempdir}/* ./ 25 | rm -rf -- ${tempdir} 26 | echo "###############" 27 | echo "Successfully updated doxygen in gh-pages branch. you will need to run 'git status' and see what changes are there" 28 | echo "depending on the changes, you might have to add or remove files before commiting to staging" 29 | echo "the easiest command is to use 'git add -A', then you commit changes and push to the remote repo" 30 | else 31 | echo "Must build in Debug mode in order to generate docs" 32 | fi 33 | -------------------------------------------------------------------------------- /include/gphoto2pp/button_widget.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef BUTTONWIDGET_HPP 26 | #define BUTTONWIDGET_HPP 27 | 28 | namespace gphoto2pp 29 | { 30 | 31 | // My D90 doesn't have button widget, so I'm not quite sure how to implement this widget 32 | 33 | } 34 | 35 | #endif // BUTTONWIDGET_HPP 36 | -------------------------------------------------------------------------------- /include/gphoto2pp/range_widget_range.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef RANGEWIDGETRANGE_HPP 26 | #define RANGEWIDGETRANGE_HPP 27 | 28 | #include 29 | 30 | namespace gphoto2pp 31 | { 32 | /** struct RangeWidgetRange 33 | * Provides a POD for the RangeWidget's getRange method. 34 | */ 35 | struct RangeWidgetRange 36 | { 37 | float Min; 38 | float Max; 39 | float Step; 40 | }; 41 | } 42 | 43 | #endif // RANGEWIDGETRANGE_HPP 44 | -------------------------------------------------------------------------------- /src/text_widget.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | namespace gphoto2pp 31 | { 32 | 33 | TextWidget::TextWidget(gphoto2::_CameraWidget* cameraWidget) 34 | : StringWidget{cameraWidget} 35 | { 36 | if(getType() != CameraWidgetTypeWrapper::Text) 37 | { 38 | throw exceptions::InvalidWidgetType("The widget type must be a Text Widget"); 39 | } 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /src/menu_widget.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | namespace gphoto2pp 31 | { 32 | 33 | MenuWidget::MenuWidget(gphoto2::_CameraWidget* cameraWidget) 34 | : ChoicesWidget{cameraWidget} 35 | { 36 | if(this->getType() != CameraWidgetTypeWrapper::Menu) 37 | { 38 | throw exceptions::InvalidWidgetType("The widget type must be a Menu Widget"); 39 | } 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /src/radio_widget.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | namespace gphoto2pp 31 | { 32 | 33 | RadioWidget::RadioWidget(gphoto2::_CameraWidget* cameraWidget) 34 | : ChoicesWidget{cameraWidget} 35 | { 36 | if(this->getType() != CameraWidgetTypeWrapper::Radio) 37 | { 38 | throw exceptions::InvalidWidgetType("The widget type must be a Radio Widget"); 39 | } 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /src/toggle_widget.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | namespace gphoto2pp 31 | { 32 | 33 | ToggleWidget::ToggleWidget(gphoto2::_CameraWidget* cameraWidget) 34 | : IntWidget{cameraWidget} 35 | { 36 | if(this->getType() != CameraWidgetTypeWrapper::Toggle) 37 | { 38 | throw exceptions::InvalidWidgetType("The widget type must be a Toggle Widget"); 39 | } 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /src/window_widget.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | namespace gphoto2pp 31 | { 32 | 33 | WindowWidget::WindowWidget(gphoto2::_CameraWidget* cameraWidget) 34 | : NonValueWidget{cameraWidget} 35 | { 36 | if(this->getType() != CameraWidgetTypeWrapper::Window) 37 | { 38 | throw exceptions::InvalidWidgetType("The widget type must be a Window Widget"); 39 | } 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /src/section_widget.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | namespace gphoto2pp 31 | { 32 | 33 | SectionWidget::SectionWidget(gphoto2::_CameraWidget* cameraWidget) 34 | : NonValueWidget{cameraWidget} 35 | { 36 | if(this->getType() != CameraWidgetTypeWrapper::Section) 37 | { 38 | throw exceptions::InvalidWidgetType("The widget type must be a Section Widget"); 39 | } 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /include/gphoto2pp/camera_capture_type_wrapper.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef CAMERACAPTURETYPEWRAPPER_HPP 26 | #define CAMERACAPTURETYPEWRAPPER_HPP 27 | 28 | namespace gphoto2pp 29 | { 30 | /** 31 | * Provides a C++ enum for the gphoto2 CameraCaptureType enum 32 | */ 33 | enum class CameraCaptureTypeWrapper : int 34 | { 35 | Image = 0, ///< Maps to GP_CAPTURE_IMAGE 36 | Movie = 1, ///< Maps to GP_CAPTURE_MOVIE 37 | Sound = 2, ///< Maps to GP_CAPTURE_SOUND 38 | }; 39 | } 40 | 41 | #endif // CAMERACAPTURETYPEWRAPPER_HPP 42 | -------------------------------------------------------------------------------- /include/gphoto2pp/camera_file_path_wrapper.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef CAMERAFILEPATHWRAPPER_HPP 26 | #define CAMERAFILEPATHWRAPPER_HPP 27 | 28 | #include 29 | 30 | namespace gphoto2pp 31 | { 32 | /** struct CameraFilePathWrapper 33 | * Provides a POD for the camerafilepath. This doesn't actually wrap the gphoto2 CameraFilePath struct because the structure was so simple 34 | */ 35 | struct CameraFilePathWrapper 36 | { 37 | std::string Name; 38 | std::string Folder; 39 | }; 40 | } 41 | 42 | #endif // CAMERAFILEPATHWRAPPER_HPP 43 | -------------------------------------------------------------------------------- /include/gphoto2pp/section_widget.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef SECTIONWIDGET_HPP 26 | #define SECTIONWIDGET_HPP 27 | 28 | #include 29 | 30 | namespace gphoto2pp 31 | { 32 | /** 33 | * \class SectionWidget 34 | * A class representing gphoto2 widgets which are of the widget type GPhoto2pp::CameraWidgetTypeWrapper::Section 35 | */ 36 | class SectionWidget: public NonValueWidget 37 | { 38 | protected: 39 | SectionWidget(gphoto2::_CameraWidget* cameraWidget); 40 | }; 41 | 42 | } 43 | 44 | #endif // SECTIONWIDGET_HPP 45 | -------------------------------------------------------------------------------- /include/gphoto2pp/text_widget.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef TEXTWIDGET_HPP 26 | #define TEXTWIDGET_HPP 27 | 28 | #include 29 | 30 | namespace gphoto2pp 31 | { 32 | /** 33 | * \class TextWidget 34 | * A class representing gphoto2 widgets which are of the widget type GPhoto2pp::CameraWidgetTypeWrapper::Text 35 | */ 36 | class TextWidget: public StringWidget 37 | { 38 | friend class NonValueWidget; 39 | 40 | protected: 41 | TextWidget(gphoto2::_CameraWidget* cameraWidget); 42 | }; 43 | 44 | } 45 | 46 | #endif // TEXTWIDGET_HPP 47 | -------------------------------------------------------------------------------- /include/gphoto2pp/menu_widget.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef MENUWIDGET_HPP 26 | #define MENUWIDGET_HPP 27 | 28 | #include 29 | 30 | namespace gphoto2pp 31 | { 32 | /** 33 | * \class MenuWidget 34 | * A class representing gphoto2 widgets which are of the widget type GPhoto2pp::CameraWidgetTypeWrapper::Menu 35 | */ 36 | class MenuWidget: public ChoicesWidget 37 | { 38 | friend class NonValueWidget; 39 | 40 | protected: 41 | MenuWidget(gphoto2::_CameraWidget* cameraWidget); 42 | }; 43 | 44 | } 45 | 46 | #endif // MENUWIDGET_HPP 47 | -------------------------------------------------------------------------------- /include/gphoto2pp/toggle_widget.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef TOGGLEWIDGET_HPP 26 | #define TOGGLEWIDGET_HPP 27 | 28 | #include 29 | 30 | namespace gphoto2pp 31 | { 32 | /** 33 | * \class ToggleWidget 34 | * A class representing gphoto2 widgets which are of the widget type GPhoto2pp::CameraWidgetTypeWrapper::Toggle 35 | */ 36 | class ToggleWidget: public IntWidget 37 | { 38 | friend class NonValueWidget; 39 | 40 | protected: 41 | ToggleWidget(gphoto2::_CameraWidget* cameraWidget); 42 | }; 43 | } 44 | 45 | #endif // TOGGLEWIDGET_HPP 46 | -------------------------------------------------------------------------------- /include/gphoto2pp/radio_widget.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef RADIOWIDGET_HPP 26 | #define RADIOWIDGET_HPP 27 | 28 | #include 29 | 30 | namespace gphoto2pp 31 | { 32 | /** 33 | * \class RadioWidget 34 | * A class representing gphoto2 widgets which are of the widget type GPhoto2pp::CameraWidgetTypeWrapper::Radio 35 | */ 36 | class RadioWidget: public ChoicesWidget 37 | { 38 | friend class NonValueWidget; 39 | 40 | protected: 41 | RadioWidget(gphoto2::_CameraWidget* cameraWidget); 42 | }; 43 | 44 | } 45 | 46 | #endif // RADIOWIDGET_HPP 47 | -------------------------------------------------------------------------------- /include/gphoto2pp/window_widget.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef WINDOWWIDGET_HPP 26 | #define WINDOWWIDGET_HPP 27 | 28 | #include 29 | 30 | namespace gphoto2pp 31 | { 32 | /** 33 | * \class WindowWidget 34 | * A class representing gphoto2 widgets which are of the widget type GPhoto2pp::CameraWidgetTypeWrapper::Window 35 | */ 36 | class WindowWidget : public NonValueWidget 37 | { 38 | friend class CameraWrapper; 39 | 40 | protected: 41 | WindowWidget(gphoto2::_CameraWidget* cameraWidget); 42 | }; 43 | } 44 | 45 | #endif // WINDOWWIDGET_HPP 46 | -------------------------------------------------------------------------------- /include/gphoto2pp/camera_event_type_wrapper.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef CAMERAEVENTTYPEWRAPPER_HPP 26 | #define CAMERAEVENTTYPEWRAPPER_HPP 27 | 28 | namespace gphoto2pp 29 | { 30 | /** 31 | * Provides a C++ enum for the gphoto2 CameraEventType enum 32 | */ 33 | enum class CameraEventTypeWrapper : int 34 | { 35 | Unknown = 0, ///< Maps to GP_EVENT_UNKNOWN 36 | Timeout = 1, ///< Maps to GP_EVENT_TIMEOUT 37 | FileAdded = 2, ///< Maps to GP_EVENT_FILE_ADDED 38 | FolderAdded = 3, ///< Maps to GP_EVENT_FOLDER_ADDED 39 | CaptureComplete = 4, ///< Maps to GP_EVENT_CAPTURE_COMPLETE 40 | }; 41 | } 42 | 43 | #endif // CAMERAEVENTTYPEWRAPPER_HPP 44 | -------------------------------------------------------------------------------- /src/helper_context.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | namespace gphoto2 28 | { 29 | #include 30 | } 31 | 32 | namespace gphoto2pp 33 | { 34 | std::shared_ptr getContext() 35 | { 36 | auto deleter = [](gphoto2::_GPContext* p){gphoto2::gp_context_unref(p);}; 37 | 38 | gphoto2::_GPContext* gpContext = gphoto2::gp_context_new(); 39 | 40 | return std::shared_ptr(gpContext, deleter); 41 | } 42 | 43 | // These are additional helper methods which are for more advanced users of libgphoto2 44 | namespace context 45 | { 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /tests/Helpers_widgets_Generic.h: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | class Helpers_gphoto2_Generic : public CxxTest::TestSuite 34 | { 35 | gphoto2pp::CameraWrapper _camera; 36 | 37 | public: 38 | void setUp() 39 | { 40 | FILELog::ReportingLevel() = logCRITICAL; 41 | } 42 | 43 | void testGetAllWidgets() 44 | { 45 | TS_ASSERT_THROWS_NOTHING(gphoto2pp::helper::getAllWidgetsNames(_camera.getConfig())); 46 | } 47 | }; 48 | -------------------------------------------------------------------------------- /include/gphoto2pp/camera_file_type_wrapper.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef CAMERAFILETYPEWRAPPER_HPP 26 | #define CAMERAFILETYPEWRAPPER_HPP 27 | 28 | namespace gphoto2pp 29 | { 30 | /** 31 | * Provides a C++ enum for the gphoto2 CameraFileType enum 32 | */ 33 | enum class CameraFileTypeWrapper : int 34 | { 35 | Preview = 0, ///< Maps to GP_FILE_TYPE_PREVIEW 36 | Normal = 1, ///< Maps to GP_FILE_TYPE_NORMAL 37 | Raw = 2, ///< Maps to GP_FILE_TYPE_RAW 38 | Audio = 3, ///< Maps to GP_FILE_TYPE_AUDIO 39 | Exif = 4, ///< Maps to GP_FILE_TYPE_EXIF 40 | MetaData = 5 ///< Maps to GP_FILE_TYPE_METADATA 41 | }; 42 | 43 | } 44 | 45 | 46 | #endif // CAMERAFILETYPEWRAPPER_HPP 47 | -------------------------------------------------------------------------------- /include/gphoto2pp/helper_context.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef HELPERCONTEXT_HPP 26 | #define HELPERCONTEXT_HPP 27 | 28 | #include 29 | 30 | namespace gphoto2 31 | { 32 | struct _GPContext; 33 | } 34 | 35 | 36 | namespace gphoto2pp 37 | { 38 | /** 39 | * \brief Creates a shared pointer of GPContext to be used anywhere in the program. Passes in a deleter method which will free the context on destruction. 40 | * \return the new context ready for usage 41 | * \throw GPhoto2pp::exceptions::NoCameraFoundError if it didn't find any cameras 42 | */ 43 | std::shared_ptr getContext(); 44 | 45 | namespace helper 46 | { 47 | // TODO 48 | } 49 | } 50 | 51 | #endif // HELPERGPHOTO2_HPP 52 | -------------------------------------------------------------------------------- /examples/example1.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | 29 | int main(int argc, char* argv[]) { 30 | auto version = gphoto2pp::LibraryVersion(); 31 | std::cout << "#############################" << std::endl; 32 | std::cout << "# Short Version - " << std::endl; 33 | std::cout << "#############################" << std::endl; 34 | std::cout << version << std::endl << std::endl; 35 | 36 | version = gphoto2pp::LibraryVersion(true); 37 | std::cout << "#############################" << std::endl; 38 | std::cout << "# Verbose Version - " << std::endl; 39 | std::cout << "#############################" << std::endl; 40 | std::cout << version << std::endl << std::endl; 41 | } 42 | -------------------------------------------------------------------------------- /include/gphoto2pp/camera_widget_type_wrapper.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef WIDGETTYPE_HPP 26 | #define WIDGETTYPE_HPP 27 | 28 | namespace gphoto2pp 29 | { 30 | /** 31 | * Provides a C++ enum for the gphoto2 CameraWidgetType enum 32 | */ 33 | enum class CameraWidgetTypeWrapper : int 34 | { 35 | Window = 0, ///< Maps to GP_WIDGET_WINDOW 36 | Section = 1, ///< Maps to GP_WIDGET_SECTION 37 | Text = 2, ///< Maps to GP_WIDGET_TEXT 38 | Range = 3, ///< Maps to GP_WIDGET_RANGE 39 | Toggle = 4, ///< Maps to GP_WIDGET_TOGGLE 40 | Radio = 5, ///< Maps to GP_WIDGET_RADIO 41 | Menu = 6, ///< Maps to GP_WIDGET_MENU 42 | Button = 7, ///< Maps to GP_WIDGET_BUTTON 43 | Date = 8, ///< Maps to GP_WIDGET_DATE 44 | }; 45 | } 46 | 47 | 48 | #endif // WIDGETTYPE_HPP 49 | -------------------------------------------------------------------------------- /src/int_widget.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | namespace gphoto2 34 | { 35 | #include 36 | } 37 | 38 | namespace gphoto2pp 39 | { 40 | 41 | IntWidget::IntWidget(gphoto2::_CameraWidget* cameraWidget) 42 | : ValueWidgetBase{cameraWidget} 43 | { 44 | } 45 | 46 | int IntWidget::getValue() const 47 | { 48 | int temp = 0; 49 | 50 | gphoto2pp::checkResponse(gphoto2::gp_widget_get_value(m_cameraWidget, &temp),"gp_widget_get_value"); 51 | 52 | return temp; 53 | } 54 | void IntWidget::setValue(int const & value) 55 | { 56 | gphoto2pp::checkResponse(gphoto2::gp_widget_set_value(m_cameraWidget, &value),"gp_widget_set_value"); 57 | } 58 | 59 | } 60 | 61 | -------------------------------------------------------------------------------- /src/float_widget.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | namespace gphoto2 34 | { 35 | #include 36 | } 37 | 38 | namespace gphoto2pp 39 | { 40 | 41 | FloatWidget::FloatWidget(gphoto2::_CameraWidget* cameraWidget) 42 | : ValueWidgetBase{cameraWidget} 43 | { 44 | } 45 | 46 | float FloatWidget::getValue() const 47 | { 48 | float temp = 0; 49 | 50 | gphoto2pp::checkResponse(gphoto2::gp_widget_get_value(m_cameraWidget, &temp),"gp_widget_get_value"); 51 | 52 | return temp; 53 | } 54 | void FloatWidget::setValue(float const & value) 55 | { 56 | gphoto2pp::checkResponse(gphoto2::gp_widget_set_value(m_cameraWidget, &value),"gp_widget_set_value"); 57 | } 58 | } 59 | 60 | -------------------------------------------------------------------------------- /src/string_widget.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | namespace gphoto2 33 | { 34 | #include 35 | } 36 | 37 | namespace gphoto2pp 38 | { 39 | 40 | StringWidget::StringWidget(gphoto2::_CameraWidget* cameraWidget) 41 | : ValueWidgetBase{cameraWidget} 42 | { 43 | } 44 | 45 | std::string StringWidget::getValue() const 46 | { 47 | char* temp = nullptr; 48 | 49 | gphoto2pp::checkResponse(gphoto2::gp_widget_get_value(m_cameraWidget, &temp),"gp_widget_get_value"); 50 | 51 | return std::string(temp); 52 | } 53 | 54 | void StringWidget::setValue(std::string const & value) 55 | { 56 | gphoto2pp::checkResponse(gphoto2::gp_widget_set_value(m_cameraWidget, value.c_str()),"gp_widget_set_value"); 57 | } 58 | 59 | } 60 | 61 | -------------------------------------------------------------------------------- /examples/example2.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | int main(int argc, char* argv[]) { 32 | // runs autodetect method and returns all cameras connected to the computer 33 | std::cout << "#############################" << std::endl; 34 | std::cout << "# autoDetect - multiple #" << std::endl; 35 | std::cout << "#############################" << std::endl; 36 | try 37 | { 38 | auto cameraList = gphoto2pp::autoDetectAll(); 39 | 40 | for(int i = 0; i < cameraList.count(); ++i) 41 | { 42 | std::cout << "model: " << cameraList.getName(i) << std::endl; 43 | } 44 | } 45 | catch (const gphoto2pp::exceptions::NoCameraFoundError &e) 46 | { 47 | std::cout << "GPhoto couldn't detect any cameras connected to the computer" << std::endl; 48 | std::cout << "Exception Message: " << e.what() << std::endl; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/date_widget.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | namespace gphoto2 33 | { 34 | #include 35 | } 36 | 37 | namespace gphoto2pp 38 | { 39 | 40 | DateWidget::DateWidget(gphoto2::_CameraWidget* cameraWidget) 41 | : ValueWidgetBase{cameraWidget} 42 | { 43 | if(this->getType() != CameraWidgetTypeWrapper::Date) 44 | { 45 | throw exceptions::InvalidWidgetType("The widget type must be a Date Widget"); 46 | } 47 | } 48 | 49 | std::time_t DateWidget::getValue() const 50 | { 51 | int temp = 0; 52 | 53 | gphoto2pp::checkResponse(gphoto2::gp_widget_get_value(m_cameraWidget, &temp),"gp_widget_get_value"); 54 | 55 | return static_cast(temp); 56 | } 57 | 58 | void DateWidget::setValue(std::time_t const & datetime) 59 | { 60 | int temp = static_cast(datetime); 61 | 62 | gphoto2pp::checkResponse(gphoto2::gp_widget_set_value(m_cameraWidget, &temp),"gp_widget_set_value"); 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /include/gphoto2pp/range_widget.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef RANGEWIDGET_HPP 26 | #define RANGEWIDGET_HPP 27 | 28 | #include 29 | 30 | namespace gphoto2pp 31 | { 32 | struct RangeWidgetRange; 33 | 34 | /** 35 | * \class RangeWidget 36 | * A class representing gphoto2 widgets which are of the widget type GPhoto2pp::CameraWidgetTypeWrapper::Range 37 | */ 38 | class RangeWidget: public FloatWidget 39 | { 40 | friend class NonValueWidget; 41 | 42 | public: 43 | /** 44 | * \brief Gets the widget's range. 45 | * \return the widget's range 46 | * \note Direct wrapper for gp_widget_get_range(...) 47 | * \throw GPhoto2pp::exceptions::gphoto2_exception 48 | */ 49 | RangeWidgetRange getRange() const; 50 | 51 | /** 52 | * \brief Gets the widget's range and returns their values in a user friendly string. 53 | * \return the widget's range 54 | * \throw GPhoto2pp::exceptions::gphoto2_exception 55 | */ 56 | std::string ToString() const; 57 | 58 | protected: 59 | RangeWidget(gphoto2::_CameraWidget* cameraWidget); 60 | }; 61 | 62 | } 63 | 64 | #endif // RANGEWIDGET_HPP 65 | -------------------------------------------------------------------------------- /include/gphoto2pp/int_widget.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef INTWIDGET_HPP 26 | #define INTWIDGET_HPP 27 | 28 | #include 29 | 30 | namespace gphoto2pp 31 | { 32 | /** 33 | * \class IntWidget 34 | * A class representing gphoto2 widgets which have a value that is meaningfully represented by an int 35 | */ 36 | class IntWidget: public ValueWidgetBase 37 | { 38 | friend class NonValueWidget; 39 | 40 | public: 41 | /** 42 | * \brief Gets the widget's value in terms of int 43 | * \return the widget's int value 44 | * \note Direct wrapper for gp_widget_get_value(...) 45 | * \throw GPhoto2pp::exceptions::gphoto2_exception 46 | */ 47 | int getValue() const override; 48 | 49 | /** 50 | * \brief Sets the widget's value in terms of int 51 | * \param[in] value to set the widget to 52 | * \note Direct wrapper for gp_widget_set_value(...) 53 | * \throw GPhoto2pp::exceptions::gphoto2_exception 54 | */ 55 | void setValue(int const & value) override; 56 | 57 | protected: 58 | IntWidget(gphoto2::_CameraWidget* cameraWidget); 59 | }; 60 | 61 | } 62 | 63 | #endif // INTWIDGET_HPP 64 | -------------------------------------------------------------------------------- /include/gphoto2pp/float_widget.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef FLOATWIDGET_HPP 26 | #define FLOATWIDGET_HPP 27 | 28 | #include 29 | 30 | namespace gphoto2pp 31 | { 32 | /** 33 | * \class FloatWidget 34 | * A class representing gphoto2 widgets which have a value that is meaningfully represented by a float 35 | */ 36 | class FloatWidget: public ValueWidgetBase 37 | { 38 | friend class NonValueWidget; 39 | 40 | public: 41 | /** 42 | * \brief Gets the widget's value in terms of float 43 | * \return the widget's float value 44 | * \note Direct wrapper for gp_widget_get_value(...) 45 | * \throw GPhoto2pp::exceptions::gphoto2_exception 46 | */ 47 | float getValue() const override; 48 | 49 | /** 50 | * \brief Sets the widget's value in terms of float 51 | * \param[in] value to set for widget 52 | * \note Direct wrapper for gp_widget_set_value(...) 53 | * \throw GPhoto2pp::exceptions::gphoto2_exception 54 | */ 55 | void setValue(float const & value) override; 56 | 57 | protected: 58 | FloatWidget(gphoto2::_CameraWidget* cameraWidget); 59 | }; 60 | 61 | } 62 | 63 | #endif // FLOATWIDGET_HPP 64 | -------------------------------------------------------------------------------- /include/gphoto2pp/date_widget.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef DATEWIDGET_HPP 26 | #define DATEWIDGET_HPP 27 | 28 | #include 29 | 30 | #include 31 | 32 | namespace gphoto2pp 33 | { 34 | /** 35 | * \class DateWidget 36 | * A class representing gphoto2 widgets which are of the widget type GPhoto2pp::CameraWidgetTypeWrapper::Date 37 | */ 38 | class DateWidget: public ValueWidgetBase 39 | { 40 | friend class NonValueWidget; 41 | 42 | public: 43 | /** 44 | * \brief Gets the widget's value in terms of std::time_t 45 | * \return the widget's std::time_t value 46 | * \note Direct wrapper for gp_widget_get_value(...) 47 | * \throw GPhoto2pp::exceptions::gphoto2_exception 48 | */ 49 | std::time_t getValue() const override; 50 | 51 | /** 52 | * \brief Sets the widget's value in terms of std::time_t 53 | * \param[in] date to set for the widget 54 | * \note Direct wrapper for gp_widget_set_value(...) 55 | * \throw GPhoto2pp::exceptions::gphoto2_exception 56 | */ 57 | void setValue(std::time_t const & date) override; 58 | 59 | protected: 60 | DateWidget(gphoto2::_CameraWidget* cameraWidget); 61 | }; 62 | } 63 | 64 | #endif // DATEWIDGET_HPP 65 | -------------------------------------------------------------------------------- /include/gphoto2pp/value_widget_base.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef VALUEWIDGETBASE_HPP 26 | #define VALUEWIDGETBASE_HPP 27 | 28 | #include 29 | 30 | namespace gphoto2pp 31 | { 32 | /** 33 | * \class ValueWidgetBase 34 | * A templated class which must be inherited by any leaf widget type. That means any widget type that is not a Section or a Widget. That way their specific widget implementations can define meaningful Get and Set methods. 35 | * \tparam the meaningful value type for the widget 36 | */ 37 | template 38 | class ValueWidgetBase : public CameraWidgetWrapper 39 | { 40 | 41 | public: 42 | /** 43 | * \brief Gets the widget's value in terms of T 44 | * \return the widget's value 45 | */ 46 | virtual T getValue() const = 0; 47 | 48 | /** 49 | * \brief Sets the widget's value in terms of T 50 | * \param[in] value to set for the widget 51 | * \return the widget's T value 52 | */ 53 | virtual void setValue(T const & value) = 0; 54 | 55 | protected: 56 | ValueWidgetBase(gphoto2::_CameraWidget* cameraWidget) 57 | : CameraWidgetWrapper{cameraWidget} 58 | { 59 | // Empty Constructor 60 | } 61 | }; 62 | 63 | } 64 | 65 | #endif // VALUEWIDGETBASE_HPP 66 | -------------------------------------------------------------------------------- /include/gphoto2pp/string_widget.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef STRINGWIDGET_HPP 26 | #define STRINGWIDGET_HPP 27 | 28 | #include 29 | 30 | #include 31 | 32 | namespace gphoto2pp 33 | { 34 | /** 35 | * \class StringWidget 36 | * A class representing gphoto2 widgets which have a value that is meaningfully represented by a string 37 | */ 38 | class StringWidget : public ValueWidgetBase 39 | { 40 | friend class NonValueWidget; 41 | 42 | public: 43 | /** 44 | * \brief Gets the widget's value in terms of std::string 45 | * \return the widget's std::string value 46 | * \note Direct wrapper for gp_widget_get_value(...) 47 | * \throw GPhoto2pp::exceptions::gphoto2_exception 48 | */ 49 | std::string getValue() const override; 50 | 51 | /** 52 | * \brief Sets the widget's value in terms of std::string 53 | * \param[in] value to set for the widget 54 | * \note Direct wrapper for gp_widget_set_value(...) 55 | * \throw GPhoto2pp::exceptions::gphoto2_exception 56 | */ 57 | void setValue(std::string const & value) override; 58 | 59 | protected: 60 | StringWidget(gphoto2::_CameraWidget* cameraWidget); 61 | }; 62 | 63 | } 64 | 65 | #endif // STRINGWIDGET_HPP 66 | -------------------------------------------------------------------------------- /src/range_widget.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | namespace gphoto2 33 | { 34 | #include 35 | } 36 | 37 | #include 38 | 39 | namespace gphoto2pp 40 | { 41 | 42 | RangeWidget::RangeWidget(gphoto2::_CameraWidget* cameraWidget) 43 | : FloatWidget{cameraWidget} 44 | { 45 | if(this->getType() != CameraWidgetTypeWrapper::Range) 46 | { 47 | throw exceptions::InvalidWidgetType("The widget type must be a Range Widget"); 48 | } 49 | } 50 | 51 | RangeWidgetRange RangeWidget::getRange() const 52 | { 53 | auto range = RangeWidgetRange{0,0,0}; 54 | gphoto2pp::checkResponse(gphoto2::gp_widget_get_range(m_cameraWidget, &range.Min, &range.Max, &range.Step),"gp_widget_get_range"); 55 | return range; 56 | } 57 | 58 | std::string RangeWidget::ToString() const 59 | { 60 | float m_min = 0, m_max = 0, m_step = 0; 61 | gphoto2pp::checkResponse(gphoto2::gp_widget_get_range(m_cameraWidget, &m_min, &m_max, &m_step),"gp_widget_get_range"); 62 | 63 | std::stringstream temp; 64 | temp << "[min: " << m_min << " max: " << m_max << " step: " << m_step << "]"; 65 | return temp.str(); 66 | } 67 | 68 | } 69 | 70 | -------------------------------------------------------------------------------- /include/gphoto2pp/helper_debugging.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef HELPERDEBUGGING_HPP 26 | #define HELPERDEBUGGING_HPP 27 | 28 | #include 29 | 30 | namespace gphoto2pp 31 | { 32 | namespace helper 33 | { 34 | namespace debugging 35 | { 36 | enum class LogLevelWrapper : int 37 | { 38 | Error = 0, // Log message is an error infomation 39 | Verbose = 1, // Log message is an verbose debug infomation 40 | Debug = 2, // Log message is an debug infomation 41 | Data = 3 // Log message is a data hex dump 42 | }; 43 | 44 | namespace detail 45 | { 46 | struct PortLoggingEventsManager : observer::SubjectEvent 47 | { 48 | public: 49 | PortLoggingEventsManager() = default; 50 | ~PortLoggingEventsManager(); 51 | void startPortLogging(const LogLevelWrapper& level); 52 | void stopPortLogging(); 53 | private: 54 | int id = 0; 55 | }; 56 | } 57 | 58 | void startPortLogging(const LogLevelWrapper& level); 59 | void stopPortLogging(); 60 | 61 | observer::Registration subscribeToPortLogEvents(const LogLevelWrapper& event, std::function func); 62 | } 63 | } 64 | } 65 | 66 | #endif // HELPERDEBUGGING_HPP 67 | -------------------------------------------------------------------------------- /tests/Helpers_gphoto2_Generic.h: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | class Helpers_gphoto2_Generic : public CxxTest::TestSuite 33 | { 34 | std::pair _cameraDetails; 35 | 36 | public: 37 | void setUp() 38 | { 39 | FILELog::ReportingLevel() = logCRITICAL; 40 | } 41 | 42 | void testCameraAutodetectSingle() 43 | { 44 | try 45 | { 46 | _cameraDetails = gphoto2pp::autoDetect(); 47 | } 48 | catch(const gphoto2pp::exceptions::NoCameraFoundError& e) 49 | { 50 | TS_FAIL("No Camera detected, please make sure your camera is on and plugged in"); 51 | } 52 | catch(const std::exception& e) 53 | { 54 | TS_FAIL(e.what()); 55 | } 56 | } 57 | 58 | void testCameraAutodetectMultiple() 59 | { 60 | std::vector models; 61 | std::vector ports; 62 | try 63 | { 64 | auto cameraList = gphoto2pp::autoDetectAll(); 65 | 66 | if(cameraList.count() <= 1) 67 | { 68 | // No TS_SKIP available :( 69 | //TS_SKIP("Only 1 Camera Found, cannot complete this test, skipping..."); 70 | } 71 | } 72 | catch(const gphoto2pp::exceptions::NoCameraFoundError& e) 73 | { 74 | TS_FAIL("No Camera detected, please make sure your camera is on and plugged in"); 75 | } 76 | catch(const std::exception& e) 77 | { 78 | TS_FAIL(e.what()); 79 | } 80 | } 81 | 82 | 83 | }; 84 | -------------------------------------------------------------------------------- /include/gphoto2pp/gp_port_info_list_wrapper.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef GPPORTINFOLISTWRAPPER_HPP 26 | #define GPPORTINFOLISTWRAPPER_HPP 27 | 28 | #include 29 | 30 | namespace gphoto2 31 | { 32 | struct _GPPortInfoList; 33 | } 34 | 35 | namespace gphoto2pp 36 | { 37 | 38 | /** 39 | * \class GPPortInfoListWrapper 40 | * A wrapper around the gphoto2 GPPortInfoList struct. 41 | */ 42 | class GPPortInfoListWrapper 43 | { 44 | public: 45 | GPPortInfoListWrapper(); 46 | ~GPPortInfoListWrapper(); 47 | 48 | gphoto2::_GPPortInfoList* getPtr() const; 49 | 50 | /** 51 | * \brief Finds the list index of the specified port path 52 | * \return the port index 53 | * \note Direct wrapper for gp_port_info_list_lookup_path(...) 54 | * \throw GPhoto2pp::exceptions::gphoto2_exception 55 | */ 56 | int lookupPath(std::string const & path) const; 57 | 58 | /** 59 | * \brief Finds the list index of the specified model name 60 | * \return the port index 61 | * \note Direct wrapper for gp_port_info_list_lookup_name(...) 62 | * \throw GPhoto2pp::exceptions::gphoto2_exception 63 | */ 64 | int lookupName(std::string const & name) const; 65 | 66 | /** 67 | * \brief Gets the number of items in the list 68 | * \return the count of items 69 | * \note Direct wrapper for gp_port_info_list_count(...) 70 | * \throw GPhoto2pp::exceptions::gphoto2_exception 71 | */ 72 | int count() const; 73 | 74 | private: 75 | gphoto2::_GPPortInfoList* m_portInfoList; 76 | }; 77 | } 78 | 79 | #endif // GPPORTINFOLISTWRAPPER_HPP 80 | -------------------------------------------------------------------------------- /src/gp_port_info_list_wrapper.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | 29 | namespace gphoto2 30 | { 31 | #include 32 | } 33 | 34 | namespace gphoto2pp 35 | { 36 | 37 | GPPortInfoListWrapper::GPPortInfoListWrapper() 38 | { 39 | gphoto2pp::checkResponse(gphoto2::gp_port_info_list_new(&m_portInfoList),"gp_port_info_list_new"); 40 | 41 | gphoto2pp::checkResponse(gphoto2::gp_port_info_list_load(m_portInfoList),"gp_port_info_list_load"); 42 | } 43 | 44 | GPPortInfoListWrapper::~GPPortInfoListWrapper() 45 | { 46 | // Destructors should never throw exceptions. Hence the silent response 47 | gphoto2pp::checkResponseSilent(gphoto2::gp_port_info_list_free(m_portInfoList),"gp_port_info_list_free"); 48 | } 49 | 50 | gphoto2::_GPPortInfoList* GPPortInfoListWrapper::getPtr() const 51 | { 52 | return m_portInfoList; 53 | } 54 | 55 | int GPPortInfoListWrapper::lookupPath(std::string const & path) const 56 | { 57 | return gphoto2pp::checkResponse(gphoto2::gp_port_info_list_lookup_path(m_portInfoList, path.c_str()),"gp_port_info_list_lookup_path"); 58 | } 59 | 60 | int GPPortInfoListWrapper::lookupName(std::string const & name) const 61 | { 62 | return gphoto2pp::checkResponse(gphoto2::gp_port_info_list_lookup_name(m_portInfoList, name.c_str()),"gp_port_info_list_lookup_name"); 63 | } 64 | 65 | int GPPortInfoListWrapper::count() const 66 | { 67 | return gphoto2pp::checkResponse(gphoto2::gp_port_info_list_count(m_portInfoList),"gp_port_info_list_count"); 68 | } 69 | 70 | } 71 | 72 | -------------------------------------------------------------------------------- /examples/example7.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | int main(int argc, char* argv[]) { 33 | 34 | try 35 | { 36 | gphoto2pp::CameraWrapper cameraWrapper; 37 | 38 | std::cout << "#############################" << std::endl; 39 | std::cout << "# Capture Preview #" << std::endl; 40 | std::cout << "#############################" << std::endl; 41 | 42 | std::cout << "How Many preview pictures would you like to take [1..100]? "; 43 | std::string input = ""; 44 | int pictureQty = 0; 45 | std::getline(std::cin, input); 46 | 47 | std::stringstream tempStream(input); 48 | 49 | if(tempStream >> pictureQty) 50 | { 51 | if(pictureQty < 0 || pictureQty > 100) 52 | { 53 | std::cout << "That number is not between 1 and 100 (inclusive)" << std::endl; 54 | return 0; 55 | } 56 | else 57 | { 58 | for (int i = 0; i < pictureQty; i++) 59 | { 60 | gphoto2pp::helper::capturePreview(cameraWrapper,"example7_preview"+std::to_string(i)+".jpg"); 61 | } 62 | std::cout << "Done! check the directory which example7 executed in, the pictures were saved there" << std::endl; 63 | } 64 | } 65 | else 66 | { 67 | std::cout << "That was not a number" << std::endl; 68 | return 0; 69 | } 70 | } 71 | catch (gphoto2pp::exceptions::gphoto2_exception& e) 72 | { 73 | std::cout << "GPhoto Exception Code: " << e.getResultCode() << std::endl; 74 | std::cout << "Exception Message: " << e.what() << std::endl; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /examples/example3.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | int main(int argc, char* argv[]) { 32 | std::string model; 33 | std::string port; 34 | 35 | // runs the autodetect method and returns the first camera we find (if any) 36 | std::cout << "#############################" << std::endl; 37 | std::cout << "# autoDetect - first camera #" << std::endl; 38 | std::cout << "#############################" << std::endl; 39 | try 40 | { 41 | auto cameraPair = gphoto2pp::autoDetect(); 42 | std::cout << "model: " << cameraPair.first << " port: " << cameraPair.second << std::endl; 43 | 44 | model = cameraPair.first; 45 | port = cameraPair.second; 46 | } 47 | catch (gphoto2pp::exceptions::NoCameraFoundError &e) 48 | { 49 | std::cout << "GPhoto couldn't detect any cameras connected to the computer" << std::endl; 50 | std::cout << "Exception Message: " << e.what() << std::endl; 51 | } 52 | 53 | try 54 | { 55 | std::cout << "connecting to the first camera (model and port above)..." << std::endl; 56 | auto cameraWrapper = gphoto2pp::CameraWrapper(model, port); 57 | 58 | std::cout << "#############################" << std::endl; 59 | std::cout << "# print camera summary #" << std::endl; 60 | std::cout << "#############################" << std::endl; 61 | std::cout << cameraWrapper.getSummary() << std::endl; 62 | } 63 | catch (gphoto2pp::exceptions::gphoto2_exception& e) 64 | { 65 | std::cout << "GPhoto Exception Code: " << e.getResultCode() << std::endl; 66 | std::cout << "Exception Message: " << e.what() << std::endl; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /DEV-TEST.md: -------------------------------------------------------------------------------- 1 | Development and Testing 2 | ======================= 3 | 4 | Table Of Contents 5 | ----------------- 6 | * todo - Naming Scheme with libgphoto2 7 | * [Running Unit Tests](#running-unit-tests) 8 | * todo - Explain each test and what it does 9 | * todo - Building doxygen documentation and committing to gh-pages 10 | * [Debugging gphoto2pp](#debugging-gphoto2pp) 11 | * [Debugging libgphoto2](#debugging-libgphoto2) 12 | 13 | Running Unit Tests 14 | ------------------ 15 | After running the ./cmake_debug.sh, you then must navigate to the build/debug folder and run **make**. Then run ``ctest -VV``. 16 | 17 | Debugging gphoto2pp 18 | ------------------- 19 | This will show the various debugging mechanisms in place in order to help triage any bugs that may be happening with the library (and gphoto2). 20 | 21 | ### Logging 22 | The log mechanism we have implemented was taken from a dr.dobbs article which is completely contained in a header file. The default log level is Error and will log to stdout. You can optionally set it to log to a file instead. 23 | Log Levels: 24 | * logEMERGENCY 25 | * logALERT 26 | * logCRITICAL 27 | * logERROR 28 | * logWARN 29 | * logWARN1 30 | * logWARN2 31 | * logWARN3 32 | * logINFO 33 | * logDEBUG 34 | 35 | ### Setting Log Level 36 | To set the logging level you can input this line anywhere in your code ``gphoto2pp::FILELog::ReportingLevel() = gphoto2pp::logDEBUG`` and you may also need to include log.h ``#include ``. 37 | 38 | ### Setting Log Output To File 39 | Put the following two lines in your program (typically the entry point). 40 | ```cpp 41 | ... 42 | FILE* log_fd = fopen( "mygphpto2pplog.txt", "w" ); 43 | Output2FILE::Stream() = log_fd; 44 | ... 45 | ``` 46 | If you wish to stop logging, you can do nullptr?? 47 | 48 | ### Using The Logger for your Application 49 | Using this header only logger for your application is also quite acceptable, simply include the log file with ``#include `` and then use this line with the appropriate log level ``FILE_LOG(logDEBUG) << "Some debug message";`` 50 | 51 | Debugging libgphoto2 52 | ----------------- 53 | Libgphoto2 also has included some callbacks for debugging. These are separate from gphoto2pp logging, but you can log them to the same output (as seen in Example 11). 54 | 55 | If the camera is having unexpected behavior, it most likely lies in libgphoto2. Help for debugging these issues can be found on (gphoto nabble)[http://gphoto-software.10949.n7.nabble.com/]. 56 | What I recommend is: 57 | * Try to reproduce the error with the command line tool gphoto2 and the --debug flag. This way you can post that log output right to nabble and get some assistance. 58 | * If you don't want to use or don't have the command line tool, the output from that is identical to what we output in the debugging callback. You will just need to capture it to a log file and post it. 59 | -------------------------------------------------------------------------------- /tests/Helpers_camera_wrapper_Generic.h: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | 37 | class Helpers_gphoto2_Generic : public CxxTest::TestSuite 38 | { 39 | gphoto2pp::CameraWrapper _camera; 40 | 41 | public: 42 | void setUp() 43 | { 44 | FILELog::ReportingLevel() = logCRITICAL; 45 | } 46 | 47 | void testCaptureAutoDelete() 48 | { 49 | gphoto2pp::CameraFileWrapper cameraFile; 50 | TS_ASSERT_THROWS_NOTHING(gphoto2pp::helper::capture(_camera, cameraFile, true)); 51 | 52 | // gphoto2 < 2.5 stores temp files here 53 | auto files_loc1 = _camera.folderListFiles("/store_00010001"); 54 | 55 | // gphoto2 >= 2.5 stores temp files here 56 | auto files_loc2 = _camera.folderListFiles("/"); 57 | 58 | TS_ASSERT_EQUALS(files_loc1.count(), 0); 59 | TS_ASSERT_EQUALS(files_loc2.count(), 0); 60 | 61 | //TODO, save the file to hard disk and check for it's presence 62 | } 63 | 64 | void testCaptureNoAutoDelete() 65 | { 66 | // I updated libgphoto to 2.5.8.1 and then this test started failing with 67 | // error -110 (I/O in progress), and I suspect it's because the previous test might 68 | // not have been finished with the card, or I have a slow SD card, 69 | // so I just added in a sleep and it's working again. 70 | std::this_thread::sleep_for(std::chrono::seconds(2)); 71 | 72 | gphoto2pp::CameraFileWrapper cameraFile; 73 | TS_ASSERT_THROWS_NOTHING(gphoto2pp::helper::capture(_camera, cameraFile, false)); 74 | 75 | // gphoto2 < 2.5 stores temp files here 76 | auto files_loc1 = _camera.folderListFiles("/store_00010001"); 77 | 78 | // gphoto2 >= 2.5 stores temp files here 79 | auto files_loc2 = _camera.folderListFiles("/"); 80 | 81 | TS_ASSERT(files_loc1.count() == 1 || files_loc2.count() == 1); 82 | } 83 | }; 84 | -------------------------------------------------------------------------------- /include/gphoto2pp/helper_widgets.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef HELPERWIDGETS_HPP 26 | #define HELPERWIDGETS_HPP 27 | 28 | #include 29 | #include 30 | 31 | //g++ -std=c++11 main.cpp -o main -I. -I/usr/include/boost -I../Library ../Library/logog/liblogog.a ./Debug/libGPhoto2pp.a -lgphoto2 32 | //g++ -std=c++11 main.cpp -o main -I. -I/usr/include/boost -I../Library ../Library/logog/liblogog.a ./Debug/libGPhoto2pp.a -lgphoto2 -DLOGOG_LEVEL=0 33 | //g++ -std=c++11 main.cpp -o main -I. -I/usr/include/boost -I../Library ./Debug/libGPhoto2pp.a -lgphoto2 34 | 35 | namespace gphoto2pp 36 | { 37 | class NonValueWidget; 38 | enum class CameraWidgetTypeWrapper : int; 39 | 40 | namespace helper 41 | { 42 | /** 43 | * \brief Traverses the widget tree (depth first pre-order) and returns all widgets 44 | * \param[in] parentWidget is the starting node, and this will only traverse children of this node (it will not visit ancestors, if present) 45 | * \param[in] showFullName indicates whether to show the full widget path (eg... true = /main/imgsettings/iso vs. false = iso) 46 | * \return the compiled list of all widgets found 47 | */ 48 | std::vector getAllWidgetsNames(NonValueWidget const & parentWidget, bool showFullName = false); // Need to ask Marcus if these names are unique? So far they appear to be (I've not encountered two leaf nodes with the same name 49 | 50 | /** 51 | * \brief Traverses the widget tree (depth first pre-order) and returns all widgets matching the provided type 52 | * \param[in] parentWidget is the starting node, and this will only traverse children of this node (it will not visit ancestors, if present) 53 | * \param[in] filterByWidgetType will only show results that match this widget type 54 | * \param[in] showFullName indicates whether to show the full widget path (eg... true = /main/imgsettings/iso vs. false = iso) 55 | */ 56 | std::vector getAllWidgetsNamesOfType(NonValueWidget const & parentWidget, CameraWidgetTypeWrapper const & filterByWidgetType, bool showFullName = false); 57 | } 58 | } 59 | 60 | #endif // HELPERWIDGETS_HPP 61 | -------------------------------------------------------------------------------- /src/non_value_widget.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | namespace gphoto2 31 | { 32 | #include 33 | } 34 | 35 | namespace gphoto2pp 36 | { 37 | 38 | NonValueWidget::NonValueWidget(gphoto2::_CameraWidget* cameraWidget) 39 | : CameraWidgetWrapper{cameraWidget} 40 | { 41 | } 42 | 43 | int NonValueWidget::countChildren() const 44 | { 45 | return gphoto2pp::checkResponse(gphoto2::gp_widget_count_children(m_cameraWidget),"gp_widget_count_children"); 46 | } 47 | 48 | // Protected Methods, this call is done here so we don't have to put any gphoto includes in the header hpp files. 49 | gphoto2::_CameraWidget* NonValueWidget::getChildByNameWrapper(std::string const & name) const 50 | { 51 | gphoto2::_CameraWidget* childWidget; 52 | gphoto2pp::checkResponse(gphoto2::gp_widget_get_child_by_name(m_cameraWidget, name.c_str(), &childWidget),"gp_widget_get_child_by_name"); 53 | return childWidget; 54 | } 55 | 56 | gphoto2::_CameraWidget* NonValueWidget::getChildByLabelWrapper(std::string const & label) const 57 | { 58 | gphoto2::_CameraWidget* childWidget; 59 | gphoto2pp::checkResponse(gphoto2::gp_widget_get_child_by_label(m_cameraWidget, label.c_str(), &childWidget),"gp_widget_get_child_by_label"); 60 | return childWidget; 61 | } 62 | 63 | gphoto2::_CameraWidget* NonValueWidget::getChildWrapper(int index) const 64 | { 65 | if( index >= countChildren()) 66 | { 67 | throw exceptions::IndexOutOfRange("You are trying to get a child widget at an index which is greater than the maximum index."); 68 | } 69 | 70 | gphoto2::_CameraWidget* childWidget; 71 | gphoto2pp::checkResponse(gphoto2::gp_widget_get_child(m_cameraWidget, index, &childWidget),"gp_widget_get_child"); 72 | return childWidget; 73 | } 74 | 75 | gphoto2::_CameraWidget* NonValueWidget::getChildByIdWrapper(int id) const 76 | { 77 | gphoto2::_CameraWidget* childWidget; 78 | gphoto2pp::checkResponse(gphoto2::gp_widget_get_child_by_id(m_cameraWidget, id, &childWidget),"gp_widget_get_child_by_id"); 79 | return childWidget; 80 | } 81 | } 82 | 83 | -------------------------------------------------------------------------------- /tests/Helpers_gphoto2_NoDevice.h: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | class Helpers_gphoto2_NoDevice : public CxxTest::TestSuite 33 | { 34 | public: 35 | void setUp() 36 | { 37 | FILELog::ReportingLevel() = logCRITICAL; 38 | } 39 | 40 | void testCheckResponseOk() 41 | { 42 | TS_ASSERT_EQUALS(gphoto2pp::checkResponse(0,"ok_method"), 0); 43 | } 44 | 45 | void testCheckResponseInvalid() 46 | { 47 | TS_ASSERT_THROWS(gphoto2pp::checkResponse(-1,"invalid_method"), gphoto2pp::exceptions::gphoto2_exception); 48 | } 49 | 50 | void testCheckResponseSilentOk() 51 | { 52 | TS_ASSERT_EQUALS(gphoto2pp::checkResponseSilent(0,"ok_method"), 0); 53 | } 54 | 55 | void testCheckResponseSilentInvalid() 56 | { 57 | TS_ASSERT_EQUALS(gphoto2pp::checkResponseSilent(-1,"invalid_method"), -1); 58 | } 59 | 60 | void testLibraryVersion() 61 | { 62 | auto version = gphoto2pp::LibraryVersion(); 63 | 64 | TS_ASSERT(!version.empty()); 65 | } 66 | 67 | void testCameraAutodetectSingle() 68 | { 69 | try 70 | { 71 | auto cameraDetails = gphoto2pp::autoDetect(); 72 | 73 | // Frusterating, I must have an old version of cxxtest, as TS_SKIP is not declared 74 | //TS_SKIP("Camera was found, cannot complete this test"); 75 | } 76 | catch(const gphoto2pp::exceptions::NoCameraFoundError& e) 77 | { 78 | TS_ASSERT(true); 79 | } 80 | catch(const std::exception& e) 81 | { 82 | TS_FAIL(e.what()); 83 | } 84 | } 85 | 86 | void testCameraAutodetectMultiple() 87 | { 88 | try 89 | { 90 | auto cameraList = gphoto2pp::autoDetectAll(); 91 | 92 | // Frusterating, I must have an old version of cxxtest, as TS_SKIP is not declared 93 | //TS_SKIP("Camera was found, cannot complete this test"); 94 | } 95 | catch(const gphoto2pp::exceptions::NoCameraFoundError& e) 96 | { 97 | TS_ASSERT(true); 98 | } 99 | catch(const std::exception& e) 100 | { 101 | TS_FAIL(e.what()); 102 | } 103 | } 104 | }; 105 | -------------------------------------------------------------------------------- /cmake/modules/FindGphoto2.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # This module defines 3 | # GPHOTO2_INCLUDE_DIR, where to find libgphoto2 header files 4 | # GPHOTO2_LIBRARIES, the libraries to link against to use libgphoto2 5 | # GPHOTO2_FOUND, If false, do not try to use libgphoto2. 6 | # GPHOTO2_VERSION_STRING, e.g. 2.4.14 7 | # GPHOTO2_VERSION_MAJOR, e.g. 2 8 | # GPHOTO2_VERSION_MINOR, e.g. 4 9 | # GPHOTO2_VERSION_PATCH, e.g. 14 10 | # 11 | # also defined, but not for general use are 12 | # GPHOTO2_LIBRARY, where to find the sqlite3 library. 13 | 14 | 15 | #============================================================================= 16 | # Copyright 2010 henrik andersson 17 | #============================================================================= 18 | 19 | SET(GPHOTO2_FIND_REQUIRED ${Gphoto2_FIND_REQUIRED}) 20 | 21 | find_path(GPHOTO2_INCLUDE_DIR gphoto2/gphoto2.h) 22 | mark_as_advanced(GPHOTO2_INCLUDE_DIR) 23 | 24 | set(GPHOTO2_NAMES ${GPHOTO2_NAMES} gphoto2 libgphoto2) 25 | set(GPHOTO2_PORT_NAMES ${GPHOTO2_PORT_NAMES} gphoto2_port libgphoto2_port) 26 | find_library(GPHOTO2_LIBRARY NAMES ${GPHOTO2_NAMES} ) 27 | find_library(GPHOTO2_PORT_LIBRARY NAMES ${GPHOTO2_PORT_NAMES} ) 28 | mark_as_advanced(GPHOTO2_LIBRARY) 29 | mark_as_advanced(GPHOTO2_PORT_LIBRARY) 30 | 31 | # Detect libgphoto2 version 32 | FIND_PROGRAM(GPHOTO2CONFIG_EXECUTABLE NAMES gphoto2-config) 33 | IF(GPHOTO2CONFIG_EXECUTABLE) 34 | EXEC_PROGRAM(${GPHOTO2CONFIG_EXECUTABLE} ARGS --version RETURN_VALUE _return_VALUE OUTPUT_VARIABLE GPHOTO2_VERSION) 35 | string(REGEX REPLACE "^.*libgphoto2 ([0-9]+).*$" "\\1" GPHOTO2_VERSION_MAJOR "${GPHOTO2_VERSION}") 36 | string(REGEX REPLACE "^.*libgphoto2 [0-9]+\\.([0-9]+).*$" "\\1" GPHOTO2_VERSION_MINOR "${GPHOTO2_VERSION}") 37 | string(REGEX REPLACE "^.*libgphoto2 [0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" GPHOTO2_VERSION_PATCH "${GPHOTO2_VERSION}") 38 | 39 | set(GPHOTO2_VERSION_STRING "${GPHOTO2_VERSION_MAJOR}.${GPHOTO2_VERSION_MINOR}.${GPHOTO2_VERSION_PATCH}") 40 | ENDIF(GPHOTO2CONFIG_EXECUTABLE) 41 | 42 | # handle the QUIETLY and REQUIRED arguments and set GPHOTO2_FOUND to TRUE if 43 | # all listed variables are TRUE 44 | include(FindPackageHandleStandardArgs) 45 | find_package_handle_standard_args(GPHOTO2 DEFAULT_MSG GPHOTO2_LIBRARY GPHOTO2_INCLUDE_DIR) 46 | 47 | IF(GPHOTO2_FOUND) 48 | SET(Gphoto2_LIBRARIES ${GPHOTO2_LIBRARY} ${GPHOTO2_PORT_LIBRARY}) 49 | SET(Gphoto2_INCLUDE_DIRS ${GPHOTO2_INCLUDE_DIR}) 50 | 51 | # libgphoto2 dynamically loads and unloads usb library 52 | # without calling any cleanup functions (since they are absent from libusb-0.1). 53 | # This leaves usb event handling threads running with invalid callback and return addresses, 54 | # which causes a crash after any usb event is generated, at least in Mac OS X. 55 | # libusb1 backend does correctly call exit function, but ATM it crashes anyway. 56 | # Workaround is to link against libusb so that it wouldn't get unloaded. 57 | IF(APPLE) 58 | find_library(USB_LIBRARY NAMES usb-1.0 libusb-1.0) 59 | mark_as_advanced(USB_LIBRARY) 60 | IF(USB_LIBRARY) 61 | SET(Gphoto2_LIBRARIES ${Gphoto2_LIBRARIES} ${USB_LIBRARY}) 62 | ENDIF(USB_LIBRARY) 63 | ENDIF(APPLE) 64 | 65 | ENDIF(GPHOTO2_FOUND) 66 | -------------------------------------------------------------------------------- /examples/example9.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | #include 32 | 33 | /* 34 | * Example 9 35 | */ 36 | 37 | int main(int argc, char* argv[]) { 38 | 39 | try 40 | { 41 | std::cout << std::endl << "#############################" << std::endl; 42 | std::cout << "listing all files and folders may take quite some time if your memory card has a lot of pictures on it (I've had it take upwards of 30 seconds)" << std::endl; 43 | std::cout << "Please be patient...." << std::endl << std::endl; 44 | std::cout << "#############################" << std::endl; 45 | 46 | std::cout << "#############################" << std::endl; 47 | std::cout << "# List all folders #" << std::endl; 48 | std::cout << "#############################" << std::endl; 49 | 50 | gphoto2pp::CameraWrapper cameraWrapper; 51 | 52 | auto folders = gphoto2pp::helper::getAllFolders(cameraWrapper); 53 | 54 | for(auto i : folders) 55 | { 56 | std::cout << i << std::endl; 57 | } 58 | 59 | std::cout << std::endl << "#############################" << std::endl; 60 | std::cout << "# List all files #" << std::endl; 61 | std::cout << "#############################" << std::endl; 62 | 63 | auto files = gphoto2pp::helper::getAllFiles(cameraWrapper); 64 | 65 | for(auto i : files) 66 | { 67 | std::cout << i << std::endl; 68 | } 69 | 70 | std::cout << std::endl << "#############################" << std::endl; 71 | std::cout << "# List individual folder #" << std::endl; 72 | std::cout << "#############################" << std::endl; 73 | 74 | // The two helpers used above access this method, as well as folderListFiles 75 | // They are convienence methods, use this directly if you please 76 | auto clw = cameraWrapper.folderListFolders("/"); 77 | 78 | if(clw.count() > 0) 79 | { 80 | std::cout << "'" << clw.getName(0) << "' and '" << clw.getValue(0) << "'" << std::endl; 81 | } 82 | } 83 | catch (gphoto2pp::exceptions::gphoto2_exception& e) 84 | { 85 | std::cout << "GPhoto Exception Code: " << e.getResultCode() << std::endl; 86 | std::cout << "Exception Message: " << e.what() << std::endl; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /include/gphoto2pp/helper_gphoto2.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef HELPERGPHOTO2_HPP 26 | #define HELPERGPHOTO2_HPP 27 | 28 | #include 29 | #include 30 | 31 | namespace gphoto2 32 | { 33 | struct _GPContext; 34 | } 35 | 36 | 37 | namespace gphoto2pp 38 | { 39 | class CameraListWrapper; 40 | 41 | /** 42 | * \brief Finds the first available and recognized camera type connected to the computer 43 | * \return the model and port of the first camera found 44 | * \throw GPhoto2pp::exceptions::NoCameraFoundError if it didn't find any cameras 45 | */ 46 | std::pair autoDetect(); 47 | 48 | /** 49 | * \brief Finds all attached and recognized camera types connected to the computer 50 | * \return a list of all cameras found 51 | * \throw GPhoto2pp::exceptions::NoCameraFoundError if it didn't find any cameras 52 | */ 53 | CameraListWrapper autoDetectAll(); 54 | 55 | /** 56 | * \brief Helper used to validate the response of gphoto2 methods. when GP_ error codes are < 0, this method will create a gphoto2_exception 57 | * \param[in] result of the gphoto2 method 58 | * \param[in] methodName of the gphoto2 method that was called 59 | * \return the integer result returned from all gphoto2 methods. All results < 0 will be caught and thrown in the exception type. Some gphoto2 methods return the count of items, and so values > 0 can be returned and unrelated to error codes 60 | * \throw GPhoto2pp::exceptions::gphoto2_exception 61 | */ 62 | int checkResponse(int result, std::string&& methodName); 63 | 64 | /** 65 | * \brief Helper used to validate the response of gphoto2 methods, but does not throw an exception (logs the error instead) 66 | * \param[in] result of the gphoto2 method 67 | * \param[in] methodName of the gphoto2 method that was called 68 | * \return the integer result returned from all gphoto2 methods. This is usually <= 0 (gphoto2 error codes), but some methods return the count of items, and so values > 0 can be returned and unrelated to error codes 69 | */ 70 | int checkResponseSilent(int result, std::string&& methodName); 71 | 72 | /** 73 | * \brief Returns the version of gphoto library currently linked in the system 74 | * \param[in] verbose response, set to true, otherwise set to false 75 | * \note Direct wrapper for gp_library_version(...) 76 | */ 77 | std::string LibraryVersion(bool verbose = false); 78 | } 79 | 80 | #endif // HELPERGPHOTO2_HPP 81 | -------------------------------------------------------------------------------- /src/helper_widgets.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | namespace gphoto2pp 33 | { 34 | namespace helper 35 | { 36 | void getWidgetSummary(NonValueWidget const & currentWidget, std::string const & parentWidgetPath, std::vector& allWidgetNames, bool showFullName, bool onlySpecificWidgetType, CameraWidgetTypeWrapper const & filterByWidgetType) 37 | { 38 | std::string currentWidgetName{currentWidget.getName()}; 39 | 40 | if(showFullName) 41 | { 42 | currentWidgetName = parentWidgetPath + "/" + currentWidgetName; 43 | } 44 | 45 | // This means we are logging all widget types, and so we can ignore the filterByWidgetType argument 46 | if(onlySpecificWidgetType == false) 47 | { 48 | allWidgetNames.push_back(currentWidgetName); 49 | } 50 | else if(filterByWidgetType == currentWidget.getType()) 51 | { 52 | allWidgetNames.push_back(currentWidgetName); 53 | } 54 | 55 | int numOfChildren = currentWidget.countChildren(); 56 | 57 | for(int i = 0; i < numOfChildren; ++i) 58 | { 59 | auto childWidget = currentWidget.getChild(i); 60 | getWidgetSummary(childWidget, currentWidgetName, allWidgetNames, showFullName, onlySpecificWidgetType, filterByWidgetType); 61 | } 62 | } 63 | 64 | std::vector getAllWidgetsNames(NonValueWidget const & parentWidget, bool showFullName /* = false */) 65 | { 66 | std::vector allWidgetNames{}; 67 | 68 | getWidgetSummary(parentWidget, std::string{""}, allWidgetNames, showFullName, false, CameraWidgetTypeWrapper::Window); // we could have passed in anything for the widget type because it will be ignored, we just chose Window 69 | 70 | return std::move(allWidgetNames); 71 | 72 | //~ return getAllWidgetsNamesOfType(parentWidget, CameraWidgetTypeWrapper::Unassigned, showFullName); 73 | } 74 | 75 | std::vector getAllWidgetsNamesOfType(NonValueWidget const & parentWidget, CameraWidgetTypeWrapper const & filterByWidgetType, bool showFullName /* = false */) 76 | { 77 | std::vector allWidgetNames{}; 78 | 79 | getWidgetSummary(parentWidget, std::string{""}, allWidgetNames, showFullName, true, filterByWidgetType); 80 | 81 | return std::move(allWidgetNames); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /include/gphoto2pp/camera_abilities_list_wrapper.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef CAMERAABILITIESLISTWRAPPER_H 26 | #define CAMERAABILITIESLISTWRAPPER_H 27 | 28 | #include 29 | 30 | namespace gphoto2 31 | { 32 | // Forward Declaration 33 | struct _CameraAbilitiesList; 34 | } 35 | 36 | namespace gphoto2pp 37 | { 38 | class GPPortInfoListWrapper; 39 | class CameraListWrapper; 40 | 41 | /** 42 | * \class CameraAbilitiesListWrapper 43 | * A wrapper around the gphoto2 CameraAbilitiesList struct. 44 | */ 45 | class CameraAbilitiesListWrapper 46 | { 47 | public: 48 | CameraAbilitiesListWrapper(); 49 | ~CameraAbilitiesListWrapper(); 50 | 51 | // Move constructor and move assignment are allowed 52 | CameraAbilitiesListWrapper(CameraAbilitiesListWrapper&& other); 53 | CameraAbilitiesListWrapper& operator=(CameraAbilitiesListWrapper&& other); 54 | 55 | // We cannot support copy constructor or assignment at this time 56 | CameraAbilitiesListWrapper(CameraAbilitiesListWrapper const & other) = delete; 57 | CameraAbilitiesListWrapper& operator=(CameraAbilitiesListWrapper const & other) = delete; 58 | 59 | gphoto2::_CameraAbilitiesList* getPtr() const; 60 | 61 | /** 62 | * \brief Tries to detect any cameras connected to the computer using the list of ports provided 63 | * \param[in] portInfoList of ports to scan for camera models 64 | * \note Direct wrapper for gp_abilities_list_detect(...) 65 | * \throw GPhoto2pp::exceptions::gphoto2_exception 66 | */ 67 | CameraListWrapper listDetect(GPPortInfoListWrapper const & portInfoList); 68 | 69 | /** 70 | * \brief Resets the abilities list 71 | * \note Direct wrapper for gp_abilities_list_reset(...) 72 | * \throw GPhoto2pp::exceptions::gphoto2_exception 73 | */ 74 | void reset(); 75 | 76 | /** 77 | * \brief Counts the entries in the abilities list 78 | * \return he number of items in the list 79 | * \note Direct wrapper for gp_abilities_list_count(...) 80 | * \throw GPhoto2pp::exceptions::gphoto2_exception 81 | */ 82 | int count() const; 83 | 84 | /** 85 | * \brief Scans the list for the given model 86 | * \param[in] model of camera to search for 87 | * \return the index of the item (if found) 88 | * \note Direct wrapper for gp_abilities_list_count(...) 89 | * \throw GPhoto2pp::exceptions::gphoto2_exception 90 | */ 91 | int lookupModel(std::string const & model) const; 92 | 93 | private: 94 | gphoto2::_CameraAbilitiesList* m_cameraAbilitiesList; 95 | }; 96 | } 97 | 98 | #endif // CAMERAABILITIESLISTWRAPPER_H 99 | -------------------------------------------------------------------------------- /examples/example11.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | /* 35 | * Example 11 - Getting debugging logs from gphoto2 36 | */ 37 | 38 | int main(int argc, char* argv[]) { 39 | try 40 | { 41 | std::cout << "#############################" << std::endl; 42 | std::cout << "# Debugger Usage #" << std::endl; 43 | std::cout << "#############################" << std::endl; 44 | 45 | // Enable the GPhoto2pp logging, which by default goes to the stdout 46 | FILELog::ReportingLevel() = logDEBUG; 47 | auto pair = gphoto2pp::autoDetect(); 48 | 49 | // Now we set it to error so it won't interfere with our example below 50 | FILELog::ReportingLevel() = logERROR; 51 | 52 | // Hook the debugger up at any time, first we need a functor to send the logger for events 53 | auto mylogger = [](gphoto2pp::helper::debugging::LogLevelWrapper level, const std::string& domain, const std::string& str, void* data) 54 | { 55 | auto now = std::chrono::high_resolution_clock::now(); 56 | auto us = std::chrono::duration_cast(now.time_since_epoch()); 57 | auto s = std::chrono::duration_cast(us); 58 | std::cout << (s.count() % 60) << "." << (us.count() % 1000000) << ": "; 59 | 60 | // This line is really the only important one, the chrono stuff is so it mimics the gphoto2 debugger output 61 | std::cout << str << std::endl; 62 | 63 | // If you want to log it using the same mechanism as gphoto2pp, use this line instead of cout 64 | // FILE_LOG(logDEBUG) << (s.count() % 60) << "." << (us.count() % 1000000) << ": " << str; 65 | }; 66 | 67 | // This registration variable should be kept in scope for as long as you want it to log. 68 | // Once the registration variable falls out of scope (and is cleaned up), the handler loses registration. 69 | auto registration = gphoto2pp::helper::debugging::subscribeToPortLogEvents(gphoto2pp::helper::debugging::LogLevelWrapper::Debug, mylogger); 70 | 71 | // Don't start actual listening until this is triggered 72 | gphoto2pp::helper::debugging::startPortLogging(gphoto2pp::helper::debugging::LogLevelWrapper::Debug); 73 | 74 | // Calling any method should generate log messages, but I just happened to choose autoDetect :) 75 | pair = gphoto2pp::autoDetect(); 76 | } 77 | catch (gphoto2pp::exceptions::gphoto2_exception& e) 78 | { 79 | std::cout << "GPhoto Exception Code: " << e.getResultCode() << std::endl; 80 | std::cout << "Exception Message: " << e.what() << std::endl; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /tests/CameraWidgetWrapper_Generic.h: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | class CameraWidgetWrapper_Generic : public CxxTest::TestSuite 34 | { 35 | gphoto2pp::CameraWrapper _camera; 36 | 37 | public: 38 | void setUp() 39 | { 40 | FILELog::ReportingLevel() = logCRITICAL; 41 | } 42 | 43 | void testGetName() 44 | { 45 | auto windowWidget = _camera.getConfig(); 46 | 47 | TS_ASSERT(!windowWidget.getName().empty()); 48 | } 49 | 50 | void testMoveAssignment() 51 | { 52 | auto windowWidget = _camera.getConfig(); 53 | auto originalName = windowWidget.getName(); 54 | 55 | // Move Assignment 56 | auto moveassignment = std::move(windowWidget); 57 | 58 | TS_ASSERT_EQUALS(moveassignment.getName(), originalName); 59 | 60 | TS_ASSERT_THROWS(windowWidget.getName(), gphoto2pp::exceptions::gphoto2_exception); 61 | } 62 | 63 | void testMoveConstructor() 64 | { 65 | auto windowWidget = _camera.getConfig(); 66 | auto originalName = windowWidget.getName(); 67 | 68 | // Move Constructor 69 | auto moveconstructor(std::move(windowWidget)); 70 | 71 | TS_ASSERT_EQUALS(moveconstructor.getName(), originalName); 72 | 73 | TS_ASSERT_THROWS(windowWidget.getName(), gphoto2pp::exceptions::gphoto2_exception); // The old value is no longer valid again 74 | } 75 | 76 | void testCopyAssignment() 77 | { 78 | auto windowWidget = _camera.getConfig(); 79 | auto originalName = windowWidget.getName(); 80 | 81 | // Copy Assignment 82 | { 83 | auto copyassignment = windowWidget; 84 | 85 | TS_ASSERT_EQUALS(copyassignment.getName(), originalName); 86 | TS_ASSERT_EQUALS(windowWidget.getName(), originalName); 87 | } 88 | 89 | // Now out of scope, the original file should still exist and work 90 | TS_ASSERT_EQUALS(windowWidget.getName(), originalName); 91 | } 92 | 93 | void testCopyConstructor() 94 | { 95 | auto windowWidget = _camera.getConfig(); 96 | auto originalName = windowWidget.getName(); 97 | 98 | // Copy Constructor 99 | { 100 | auto copyconstructor(windowWidget); 101 | 102 | TS_ASSERT_EQUALS(copyconstructor.getName(), originalName); 103 | TS_ASSERT_EQUALS(windowWidget.getName(), originalName); 104 | } 105 | 106 | TS_ASSERT_EQUALS(windowWidget.getName(), originalName); 107 | } 108 | 109 | void testGetType() 110 | { 111 | auto windowWidget = _camera.getConfig(); 112 | 113 | TS_ASSERT_EQUALS(windowWidget.getType(), gphoto2pp::CameraWidgetTypeWrapper::Window); 114 | } 115 | 116 | 117 | }; 118 | -------------------------------------------------------------------------------- /include/gphoto2pp/choices_widget.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef CHOICESWIDGET_HPP 26 | #define CHOICESWIDGET_HPP 27 | 28 | #include 29 | 30 | #include 31 | 32 | namespace gphoto2pp 33 | { 34 | /** 35 | * \class ChoicesWidget 36 | * A class representing gphoto2 widgets which are of the widget type GPhoto2pp::CameraWidgetTypeWrapper::Menu or GPhoto2pp::CameraWidgetTypeWrapper::Radio 37 | */ 38 | class ChoicesWidget : public StringWidget 39 | { 40 | friend class NonValueWidget; 41 | 42 | public: 43 | /** 44 | * \brief Counts the number of choices/options to set for this widget 45 | * \return the number of choices 46 | * \note Direct wrapper for gp_widget_count_choices(...) 47 | * \throw GPhoto2pp::exceptions::gphoto2_exception 48 | */ 49 | int countChoices() const; 50 | 51 | /** 52 | * \brief Gets the currently set choice at the specified index 53 | * \return the choices index 54 | * \note Direct wrapper for gp_widget_get_choice(...) 55 | * \throw GPhoto2pp::exceptions::IndexOutOfRange if the index is greater than countChoices of choices 56 | * \throw GPhoto2pp::exceptions::gphoto2_exception 57 | */ 58 | int getChoice() const; 59 | 60 | /** 61 | * \brief Sets the choice at the specified index 62 | * \param[in] index of the choice to set 63 | * \note Helper which calls getChoice with the provided index and then setValue with the response 64 | * \throw GPhoto2pp::exceptions::IndexOutOfRange if the index is greater than countChoices 65 | * \throw GPhoto2pp::exceptions::gphoto2_exception 66 | */ 67 | void setChoice(int index); 68 | 69 | /** 70 | * \brief Gets all the possible choices 71 | * \return the choices 72 | * \note Helper which iterates through all choices compiling them into a vector 73 | * \throw GPhoto2pp::exceptions::gphoto2_exception 74 | */ 75 | std::vector getChoices() const; 76 | 77 | /** 78 | * \brief Gets the string representation of the choice at the specified index 79 | * \param[in] index of the choice to get 80 | * \return the choices value 81 | * \note Direct wrapper for gp_widget_get_choice(...) 82 | * \throw GPhoto2pp::exceptions::IndexOutOfRange if the index is greater than countChoices of choices 83 | * \throw GPhoto2pp::exceptions::gphoto2_exception 84 | */ 85 | std::string choiceToString(int index) const; 86 | 87 | /** 88 | * \brief Formats the choices into a string with optional separator 89 | * \param[in] separator used to insert inbetween all the choices for concatenation 90 | * \return the string of choices 91 | * \throw GPhoto2pp::exceptions::gphoto2_exception 92 | */ 93 | std::string choicesToString(std::string&& separator = " ") const; 94 | 95 | protected: 96 | ChoicesWidget(gphoto2::_CameraWidget* cameraWidget); 97 | }; 98 | } 99 | 100 | #endif // CHOICESWIDGET_HPP 101 | -------------------------------------------------------------------------------- /examples/example10.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include // For the subscribeToCameraEvent(...) method 30 | 31 | #include 32 | 33 | #include 34 | 35 | #include 36 | 37 | #include 38 | #include 39 | 40 | /* 41 | * Example 10 Tethered 42 | */ 43 | 44 | // Only used for the registration2 part, just to show how you can also bind to a class method 45 | struct MyTestHandlerClass 46 | { 47 | void mySuperSpecialHandler(const gphoto2pp::CameraFilePathWrapper& cameraFilePath, const std::string& data) const 48 | { 49 | std::cout << "My Super Special Handler was Triggered with file: " << cameraFilePath.Name << std::endl; 50 | } 51 | }; 52 | 53 | int main(int argc, char* argv[]) { 54 | using namespace std::placeholders; // for _1, _2, see http://en.cppreference.com/w/cpp/utility/functional/bind for more details 55 | try 56 | { 57 | std::cout << "#############################" << std::endl; 58 | std::cout << "# Tethered listener #" << std::endl; 59 | std::cout << "#############################" << std::endl; 60 | 61 | gphoto2pp::CameraWrapper cameraWrapper; 62 | 63 | // Create our event handler 64 | auto myhandler = [&cameraWrapper](const gphoto2pp::CameraFilePathWrapper& cameraFilePath, const std::string& data) 65 | { 66 | std::cout << "File Added: " << cameraFilePath.Name << std::endl; 67 | std::cout << "Downloading... " << std::endl; 68 | auto cameraFile = cameraWrapper.fileGet( cameraFilePath.Folder, cameraFilePath.Name, gphoto2pp::CameraFileTypeWrapper::Normal); 69 | cameraFile.save("example10_"+cameraFilePath.Name); 70 | std::cout << "Done!" << std::endl; 71 | }; 72 | 73 | // Subscribe to the event we want with our handler 74 | auto registration = cameraWrapper.subscribeToCameraEvent(gphoto2pp::CameraEventTypeWrapper::FileAdded, myhandler); 75 | 76 | // An alternate way to show handler registration with an object method 77 | MyTestHandlerClass mthc; 78 | auto registration2 = cameraWrapper.subscribeToCameraEvent(gphoto2pp::CameraEventTypeWrapper::FileAdded, std::bind(&MyTestHandlerClass::mySuperSpecialHandler, std::cref(mthc), _1, _2)); 79 | 80 | // Start listening for events from the camera. 81 | cameraWrapper.startListeningForEvents(); 82 | 83 | std::string input = ""; 84 | std::cout << "Press to quit at any time." << std::endl; 85 | std::cout << "Now pick up your camera and take some pictures as you normally would!" << std::endl; 86 | std::getline(std::cin, input); 87 | 88 | } 89 | catch (gphoto2pp::exceptions::gphoto2_exception& e) 90 | { 91 | std::cout << "GPhoto Exception Code: " << e.getResultCode() << std::endl; 92 | std::cout << "Exception Message: " << e.what() << std::endl; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /include/gphoto2pp/exceptions.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef EXCEPTIONS_HPP 26 | #define EXCEPTIONS_HPP 27 | 28 | #include 29 | 30 | namespace gphoto2pp 31 | { 32 | namespace exceptions 33 | { 34 | /** 35 | * \class GPhoto2ppException 36 | * Base class for all exceptions in this library 37 | */ 38 | class GPhoto2ppException : public std::runtime_error 39 | { 40 | public: 41 | GPhoto2ppException(std::string&& message) : std::runtime_error(message) { } 42 | }; 43 | 44 | /** 45 | * \class gphoto2_exception 46 | * Represents any error received from a gphoto2 method call with a value < 0 47 | */ 48 | class gphoto2_exception : public GPhoto2ppException 49 | { 50 | public: 51 | gphoto2_exception(int result, std::string&& gp_result_string) : GPhoto2ppException(std::move(gp_result_string)),m_resultCode(result) { } 52 | 53 | /** 54 | * \brief The error code received from the gphoto2 method 55 | */ 56 | int getResultCode() const 57 | { 58 | return m_resultCode; 59 | } 60 | private: 61 | const int m_resultCode; 62 | 63 | }; 64 | 65 | class InvalidLinkedVersionException : public GPhoto2ppException 66 | { 67 | public: 68 | InvalidLinkedVersionException(std::string&& message) : GPhoto2ppException(std::move(message)) { } 69 | }; 70 | 71 | class CameraWrapperException : public GPhoto2ppException 72 | { 73 | public: 74 | CameraWrapperException(std::string&& message) : GPhoto2ppException(std::move(message)) { } 75 | }; 76 | 77 | class HelperException : public GPhoto2ppException 78 | { 79 | public: 80 | HelperException(std::string&& message) : GPhoto2ppException(std::move(message)) { } 81 | }; 82 | 83 | class NoCameraFoundError : public GPhoto2ppException 84 | { 85 | public: 86 | NoCameraFoundError(std::string&& message) : GPhoto2ppException(std::move(message)) { } 87 | }; 88 | 89 | class ArgumentException : public GPhoto2ppException 90 | { 91 | public: 92 | ArgumentException(std::string&& message) : GPhoto2ppException(std::move(message)) { } 93 | }; 94 | 95 | // Widget Exceptions 96 | class InvalidWidgetType : public GPhoto2ppException 97 | { 98 | public: 99 | InvalidWidgetType(std::string&& message) : GPhoto2ppException(std::move(message)) { } 100 | }; 101 | 102 | class NullWidget : public GPhoto2ppException 103 | { 104 | public: 105 | NullWidget(std::string&& message) : GPhoto2ppException(std::move(message)) { } 106 | }; 107 | 108 | class IndexOutOfRange : public GPhoto2ppException 109 | { 110 | public: 111 | IndexOutOfRange(std::string&& message) : GPhoto2ppException(std::move(message)) { } 112 | }; 113 | 114 | class ValueOutOfLimits : public GPhoto2ppException 115 | { 116 | public: 117 | ValueOutOfLimits(std::string&& message) : GPhoto2ppException(std::move(message)) { } 118 | }; 119 | 120 | 121 | } 122 | } 123 | 124 | #endif // EXCEPTIONS_HPP 125 | -------------------------------------------------------------------------------- /src/choices_widget.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | namespace gphoto2 35 | { 36 | #include 37 | } 38 | 39 | namespace gphoto2pp 40 | { 41 | 42 | ChoicesWidget::ChoicesWidget(gphoto2::_CameraWidget* cameraWidget) 43 | : StringWidget{cameraWidget} 44 | { 45 | switch(this->getType()) 46 | { 47 | case CameraWidgetTypeWrapper::Menu: 48 | case CameraWidgetTypeWrapper::Radio: 49 | break; 50 | default: 51 | throw exceptions::InvalidWidgetType("A Choice Widget can only be of type Menu or Radio"); 52 | break; 53 | } 54 | } 55 | 56 | int ChoicesWidget::countChoices() const 57 | { 58 | return gphoto2pp::checkResponse(gphoto2::gp_widget_count_choices(m_cameraWidget),"gp_widget_count_choices"); 59 | } 60 | 61 | std::vector ChoicesWidget::getChoices() const 62 | { 63 | int choiceCount = countChoices(); 64 | 65 | std::vector choices(choiceCount); 66 | for(int i = 0; i < choiceCount; ++i) 67 | { 68 | choices[i] = choiceToString(i); 69 | } 70 | 71 | return choices; 72 | } 73 | 74 | int ChoicesWidget::getChoice() const 75 | { 76 | // Gets all the choices in the structure 77 | auto choices = getChoices(); 78 | 79 | // Finds the iterator over the choice that matches the currently set one 80 | auto const item = std::find(std::begin(choices), std::end(choices), this->getValue()); 81 | 82 | // If the index is at the end 83 | if(item == std::end(choices)) 84 | { 85 | throw exceptions::ValueOutOfLimits("For some strange reason, the current value set on the camera didn't match to a value from the choices"); 86 | } 87 | 88 | return std::distance(std::begin(choices), item); 89 | } 90 | 91 | void ChoicesWidget::setChoice(int index) 92 | { 93 | if (index >= countChoices()) 94 | { 95 | throw exceptions::IndexOutOfRange("You are trying to set a choice index which is greater than the maximum choice index."); 96 | } 97 | 98 | this->setValue(choiceToString(index)); 99 | } 100 | 101 | std::string ChoicesWidget::choiceToString(int index) const 102 | { 103 | if (index >= countChoices()) 104 | { 105 | throw exceptions::IndexOutOfRange("You are trying to get a choice index which is greater than the maximum choice index."); 106 | } 107 | 108 | char const * temp = nullptr; 109 | 110 | gphoto2pp::checkResponse(gphoto2::gp_widget_get_choice(m_cameraWidget, index, &temp),"gp_widget_get_choice"); 111 | 112 | return std::string(temp); 113 | } 114 | 115 | std::string ChoicesWidget::choicesToString(std::string&& separator /* = " " */) const 116 | { 117 | // We don't allow an empty separator 118 | if(separator.empty()) 119 | { 120 | throw exceptions::ArgumentException("You are not allowed to have an empty separator"); 121 | } 122 | std::stringstream temp; 123 | for(auto choice : getChoices()) 124 | { 125 | temp << "\"" << choice << "\"" << separator; 126 | } 127 | 128 | return temp.str().substr(0, temp.str().length() - separator.length()); // erases the last separator 129 | } 130 | 131 | } 132 | 133 | -------------------------------------------------------------------------------- /tests/CameraWrapper_Generic.h: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | class CameraWrapper_Generic : public CxxTest::TestSuite 38 | { 39 | gphoto2pp::CameraWrapper _camera; 40 | gphoto2pp::CameraFilePathWrapper _captureFilePath; 41 | 42 | public: 43 | void setUp() 44 | { 45 | FILELog::ReportingLevel() = logCRITICAL; 46 | } 47 | 48 | void testSummary() 49 | { 50 | TS_ASSERT(!_camera.getSummary().empty()); 51 | } 52 | 53 | void testMoveAssignment() 54 | { 55 | // Move Assignment 56 | auto moveassignment = std::move(_camera); 57 | 58 | TS_ASSERT(!moveassignment.getSummary().empty()); 59 | TS_ASSERT_THROWS(_camera.getSummary(), gphoto2pp::exceptions::gphoto2_exception); 60 | 61 | _camera = std::move(moveassignment); // now assign it back 62 | 63 | TS_ASSERT(!_camera.getSummary().empty()); 64 | } 65 | 66 | void testMoveConstructor() 67 | { 68 | // Move Constructor 69 | auto moveconstructor(std::move(_camera)); 70 | 71 | TS_ASSERT(!moveconstructor.getSummary().empty()); 72 | TS_ASSERT_THROWS(_camera.getSummary(), gphoto2pp::exceptions::gphoto2_exception); // The old value is no longer valid again 73 | 74 | _camera = std::move(moveconstructor); // now assign it back, ironically using move assignment which we previously checked that it was working 75 | 76 | TS_ASSERT(!_camera.getSummary().empty()); 77 | } 78 | 79 | void testCapture() 80 | { 81 | _captureFilePath = _camera.capture(gphoto2pp::CameraCaptureTypeWrapper::Image); 82 | } 83 | 84 | void testSDCardAccessingAndDeletingFiles() 85 | { 86 | // The previous test should have taken a picture and put the temporary image in the root folder "/" 87 | 88 | auto files = _camera.folderListFiles(_captureFilePath.Folder); 89 | 90 | // Makes sure we have files 91 | TS_ASSERT_LESS_THAN(0, files.count()); 92 | 93 | TS_ASSERT(files.getName(0).find(_captureFilePath.Name) != std::string::npos); 94 | 95 | _camera.fileDelete(_captureFilePath.Folder,_captureFilePath.Name); 96 | 97 | //Now lets delete the file when it's not there, this should throw an exception 98 | TS_ASSERT_THROWS(_camera.fileDelete(_captureFilePath.Folder,_captureFilePath.Name);, gphoto2pp::exceptions::gphoto2_exception); 99 | 100 | //Now we know there will be no files 101 | files = _camera.folderListFiles(_captureFilePath.Folder); 102 | 103 | TS_ASSERT_EQUALS(files.count(),0); 104 | } 105 | 106 | void testSDCardAccessingFolders() 107 | { 108 | auto folders = _camera.folderListFolders("/"); 109 | 110 | // Makes sure we have at least one sub folder, which we should at the root of the camera filesystem 111 | TS_ASSERT_LESS_THAN(0, folders.count()); 112 | 113 | auto rootFolder = "/"+folders.getName(0)+"/"; 114 | 115 | TS_ASSERT(!rootFolder.empty()); 116 | } 117 | 118 | void testGetAndSetConfig() 119 | { 120 | auto config = _camera.getConfig(); 121 | 122 | TS_ASSERT(!config.getName().empty()); 123 | 124 | _camera.setConfig(config); 125 | } 126 | }; 127 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | gphoto2pp 2 | ========= 3 | 4 | gphoto2pp is a C++11 wrapper for libgphoto2. 5 | 6 | Table Of Contents 7 | ----------------- 8 | * [Prerequisites](#prerequisites) 9 | * [2 Minute Tutorial](#2-minute-tutorial) 10 | * [Installation](INSTALL.md#installation) 11 | * [User Prerequisites](INSTALL.md#user-prerequisites) 12 | * [Dev/Test/Contributor Prerequisites](INSTALL.md#devtestcontributor-prerequisites) 13 | * [Libgphoto2 (Simple)](INSTALL.md#installing-libgphoto2-simple) 14 | * [Libgphoto2 (Advanced)](INSTALL.md#installing-libgphoto2-advanced) 15 | * [CMake](INSTALL.md#installing-cmake) 16 | * [Dev/Test/Contributor Only](INSTALL.md#installing-devtestcontributor-only) 17 | * [gphoto2pp](INSTALL.md#installing-gphoto2pp) 18 | * [Examples](#examples) 19 | * [Example 1](EXAMPLES.md#example-1) 20 | * [Example 2](EXAMPLES.md#example-2) 21 | * [Example 3](EXAMPLES.md#example-3) 22 | * [Example 4](EXAMPLES.md#example-4) 23 | * [Example 5](EXAMPLES.md#example-5) 24 | * [Example 6](EXAMPLES.md#example-6) 25 | * [Example 7](EXAMPLES.md#example-7) 26 | * [Example 8](EXAMPLES.md#example-8) 27 | * [Example 9](EXAMPLES.md#example-9) 28 | * [Example 10](EXAMPLES.md#example-10) 29 | * [Example 11](EXAMPLES.md#example-11) 30 | * [Dev/Test/Contributor](#devtest) 31 | * [FAQ](#faq) 32 | * [Doxygen Documentation](#doxygen-documentation) 33 | * [Other Useful Links](#other-useful-links) 34 | * [Version History](#version-history) 35 | 36 | Prerequisites 37 | ------------ 38 | * A C++11 compiler (I've only tested g++, but others should work) 39 | * libgphoto2 (2.4.14 or greater) 40 | * cmake (2.8.3 or greater), *only needed to build the library once to generate libgphoto2pp.so* 41 | 42 | 2 Minute Tutorial 43 | ----------------- 44 | The following snip will show you a quick demo of how easy it is to interact with your camera using gphoto2pp. Don't forget you will need to follow the [installation instructions](#installation) before you can compile this 2 minute tutorial on your computer. 45 | Make a source file eg. ``touch testgphoto2pp.cpp`` 46 | Now put this in the source file 47 | ```cpp 48 | #include // Header for CameraWrapper 49 | #include // Header for CameraFileWrapper 50 | #include // Used for helper::capture(...) method 51 | 52 | #include 53 | 54 | int main() 55 | { 56 | // Connects to the first camera found and initializes 57 | gphoto2pp::CameraWrapper camera; 58 | 59 | // Prints out the summary of your camera's abilities 60 | std::cout << camera.getSummary() << std::endl; 61 | 62 | // Creates empty instance of a cameraFile, which will be populated in our helper method 63 | gphoto2pp::CameraFileWrapper cameraFile; 64 | 65 | // Takes a picture with the camera and does all of the behind the scenes fetching 66 | gphoto2pp::helper::capture(camera, cameraFile); 67 | 68 | // Lastly saves the picture to your hard drive 69 | // Your camera might take files in different formats (bmp, raw) 70 | // so this extension might be wrong and you should rename your file appropriately 71 | cameraFile.save("my-gphoto2pp-test.jpg"); 72 | 73 | return 1; 74 | } 75 | ``` 76 | 77 | Now compile with the command: 78 | ```sh 79 | g++ -std=c++11 testgphoto2pp.cpp -lgphoto2 -lgphoto2pp 80 | ``` 81 | and then execute it 82 | ```sh 83 | ./a.out 84 | ``` 85 | 86 | That's it! The library is certainly capable of more, which you can view at [examples](EXAMPLES.md). 87 | 88 | Installation 89 | ------------ 90 | Please see the [Installation document](INSTALL.md) for details. 91 | 92 | Examples 93 | -------- 94 | Please see the [Examples document](EXAMPLES.md) for details about all examples provided. 95 | 96 | Dev/Test 97 | -------- 98 | If you would like to contribute/develop/test gphoto2pp, please see the [Dev-Test doc](DEV-TEST.md). 99 | 100 | FAQ 101 | --- 102 | Please see the [FAQ document](FAQ.md) 103 | 104 | Doxygen Documentation 105 | ----------------------- 106 | Please see this [projects github pages](http://maldworth.github.io/gphoto2pp/) for the auto generated Doxygen Page. 107 | 108 | Other Useful Links 109 | --------------- 110 | If you are new to gphoto2pp (and perhaps gphoto), then please view some of these resources: 111 | * This library wraps [gphoto](http://www.gphoto.org/) 112 | 113 | Version History 114 | --------------- 115 | Placeholder 116 | -------------------------------------------------------------------------------- /INSTALL.md: -------------------------------------------------------------------------------- 1 | Installation 2 | ============ 3 | Don't be overwhelmed with all the installation steps listed below here. Most distros can install both **libgphoto** and **cmake** through their package manger, and then all you need to do is follow the instructions in the [gphoto2pp section](#installing-gphoto2pp). 4 | 5 | Table Of Contents 6 | ----------------- 7 | * [User Prerequisites](#user-prerequisites) 8 | * [Dev/Test/Contributor Prerequisites](#devtestcontributor-prerequisites) 9 | * [Libgphoto2 (Simple)](#installing-libgphoto2-simple) 10 | * [Libgphoto2 (Advanced)](#installing-libgphoto2-advanced) 11 | * [CMake](#installing-cmake) 12 | * [Dev/Test/Contributor Only](#installing-devtestcontributor-only) 13 | * [gphoto2pp](#installing-gphoto2pp) 14 | 15 | User Prerequisites 16 | ------------------ 17 | * A C++11 compiler (I've only tested g++, but others should work) 18 | * libgphoto2 (2.4.14 or greater) 19 | * cmake (2.8.3 or greater) 20 | 21 | Dev/Test/Contributor Prerequisites 22 | ---------------------------------- 23 | Everything mentioned in *User Prerequisites* plus: 24 | * cxxtest 25 | * *(optional)* doxygen and graphviz 26 | Once complete the installation, please also view the [Dev-Test document](DEV-TEST.md) for more information. 27 | 28 | Installing libgphoto2 (Simple) 29 | ------------------------------ 30 | ``apt-get install libgphoto2-2-dev`` or ``brew install libgphoto2`` or yum, or whatever package management system your OS uses 31 | 32 | Installing libgphoto2 (Advanced) 33 | -------------------------------- 34 | You only need to do this if you explicitly want the latest and greatest libgphoto2 to work with. But most distros have 2.4.14 or greater in their package management system, in which case you should probably use the simple way. 35 | * download libgphoto from http://www.sourceforge.net/projects/gphoto/files 36 | * If you are using this method I'm going to assume you are a more proficient and can follow the INSTALL instructions 37 | * If you need some references, check out: http://github.com/gonzalo/gphoto2-updater http://www.ohmypi.com/2013/06/07/compiling-gphoto2-dependencies-how-to/ or http://www.yannock.be/computer/compiling-gphoto2-on-the-raspberry-pi (note: some of these guide download and compile/install the libusbx-1.X... beforehand, which I didn't have to do on my distro, I just did **apt-get install libusb-1.0.0-dev) 38 | 39 | Installing CMake 40 | ---------------- 41 | Again, most distros have this, so install it through your package manager *brew, apt-get, yum, etc...* 42 | 43 | Installing Dev/Test/Contributor Only 44 | ------------------------------------ 45 | Install ``cxxtest`` using package manager. 46 | Also, if you'd like to generate the documentation, install ``doxygen`` and ``graphviz`` the same way. You can make the documentation by typing ``make doc``. 47 | 48 | Installing gphoto2pp 49 | -------------------- 50 | We are almost there. 51 | * Download gphoto2pp from here (of course), and extract it to any directory of your choosing (or clone with **git clone**) 52 | * Open a terminal (if not done already), and run ``./cmake_release.sh`` or ``./cmake_debug.sh``. I recommend release, unless you plan on debugging and perhaps contributing code back to the repo. 53 | * This shell script will simply run the cmake commands and appropriate build flag. CMake will scan and make sure gphoto2 is linked in the system before continuing, and then it will create all the Makefile's which will be used to compile and install gphoto2pp 54 | * Pay attention to the output, if there's an error saying *Could NOT find CxxTest...* that's okay if you aren't going to run any unit tests 55 | * Now browse into the appropriate folder ``cd ./build/debug/`` or ``cd ./build/release/`` and enter the command ``make``, and it will build the library. 56 | * **Optional** to build examples, run command ``make examples`` or ``make example[0-9]+``. 57 | * Lastly, you most likely want to install, which will copy the library and headers to your system lib paths. Run the command ``make install`` and let it do it's magic. (will probably require sudo, and the install will not be present if compiled in DEBUG mode) 58 | * You might have to use the command ``ldconfig`` to update your PATH with the new library (this is the command my OS, it might vary, and you might need to use *sudo* as well) 59 | * Optional, if you want to uninstall at any time, you can run ``make uninstall`` from this same directory. You will need to have the *install_manifest.txt* preserved so the uninstall know's what files to uninstall. (again, will probably require sudo) 60 | -------------------------------------------------------------------------------- /src/camera_abilities_list_wrapper.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | 34 | namespace gphoto2 35 | { 36 | #include 37 | } 38 | 39 | namespace gphoto2pp 40 | { 41 | 42 | CameraAbilitiesListWrapper::CameraAbilitiesListWrapper() 43 | : m_cameraAbilitiesList{nullptr} 44 | { 45 | FILE_LOG(logINFO) << "CameraAbilitiesListWrapper Constructor"; 46 | 47 | gphoto2pp::checkResponse(gphoto2::gp_abilities_list_new(&m_cameraAbilitiesList),"gp_abilities_list_new"); 48 | 49 | auto spContext = gphoto2pp::getContext(); 50 | 51 | gphoto2pp::checkResponse(gphoto2::gp_abilities_list_load(m_cameraAbilitiesList, spContext.get()),"gp_abilities_list_load"); 52 | } 53 | 54 | CameraAbilitiesListWrapper::~CameraAbilitiesListWrapper() 55 | { 56 | FILE_LOG(logINFO) << "~CameraAbilitiesListWrapper Destructor"; 57 | 58 | if(m_cameraAbilitiesList != nullptr) 59 | { 60 | gphoto2pp::checkResponseSilent(gphoto2::gp_abilities_list_free(m_cameraAbilitiesList),"gp_abilities_list_free"); 61 | m_cameraAbilitiesList = nullptr; 62 | } 63 | } 64 | 65 | CameraAbilitiesListWrapper::CameraAbilitiesListWrapper(CameraAbilitiesListWrapper&& other) 66 | : m_cameraAbilitiesList{other.m_cameraAbilitiesList} 67 | { 68 | FILE_LOG(logINFO) << "CameraAbilitiesListWrapper move Constructor"; 69 | 70 | other.m_cameraAbilitiesList = nullptr; 71 | } 72 | 73 | CameraAbilitiesListWrapper& CameraAbilitiesListWrapper::operator=(CameraAbilitiesListWrapper&& other) 74 | { 75 | FILE_LOG(logINFO) << "CameraAbilitiesListWrapper move assignment operator"; 76 | 77 | if(this != &other) 78 | { 79 | // Release current objects resource 80 | if(m_cameraAbilitiesList != nullptr) 81 | { 82 | FILE_LOG(logINFO) << "CameraAbilitiesListWrapper move assignment - current abilities is not null"; 83 | gphoto2pp::checkResponse(gphoto2::gp_abilities_list_free(m_cameraAbilitiesList),"gp_abilities_list_free"); 84 | } 85 | 86 | // Steal or "move" the other objects resource 87 | m_cameraAbilitiesList = other.m_cameraAbilitiesList; 88 | 89 | // Unreference the other objects resource, so it's destructor doesn't unreference it 90 | other.m_cameraAbilitiesList = nullptr; 91 | } 92 | return *this; 93 | } 94 | 95 | gphoto2::_CameraAbilitiesList* CameraAbilitiesListWrapper::getPtr() const 96 | { 97 | return m_cameraAbilitiesList; 98 | } 99 | 100 | CameraListWrapper CameraAbilitiesListWrapper::listDetect(GPPortInfoListWrapper const & portInfoList) 101 | { 102 | auto spContext = gphoto2pp::getContext(); 103 | CameraListWrapper cameraList; 104 | 105 | gphoto2pp::checkResponse(gphoto2::gp_abilities_list_detect(m_cameraAbilitiesList, portInfoList.getPtr(), cameraList.getPtr(), spContext.get()),"gp_abilities_list_detect"); 106 | 107 | return cameraList; // Compiler should do RVO here 108 | } 109 | 110 | void CameraAbilitiesListWrapper::reset() 111 | { 112 | gphoto2pp::checkResponse(gphoto2::gp_abilities_list_reset(m_cameraAbilitiesList),"gp_abilities_list_reset"); 113 | } 114 | 115 | int CameraAbilitiesListWrapper::count() const 116 | { 117 | FILE_LOG(logDEBUG) << "CameraAbilitiesListWrapper count"; 118 | 119 | return gphoto2pp::checkResponse(gphoto2::gp_abilities_list_count(m_cameraAbilitiesList),"gp_abilities_list_count"); 120 | } 121 | 122 | // Meant to return the index of the specified model, or gphoto error code 123 | int CameraAbilitiesListWrapper::lookupModel(std::string const & model) const 124 | { 125 | FILE_LOG(logDEBUG) << "CameraAbilitiesListWrapper lookupModel - model"; 126 | 127 | return gphoto2pp::checkResponse(gphoto2::gp_abilities_list_lookup_model(m_cameraAbilitiesList, model.c_str()),"gp_abilities_list_lookup_model"); 128 | } 129 | 130 | } 131 | 132 | -------------------------------------------------------------------------------- /src/helper_gphoto2.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | #ifdef GPHOTO_LESS_25 33 | #include 34 | #include 35 | #else 36 | #include 37 | #endif 38 | 39 | namespace gphoto2 40 | { 41 | #ifndef GPHOTO_LESS_25 42 | #include // Needed for gp_camera_autodetect, but only used if gphoto is 2.5 or greater 43 | #else 44 | #include // used for gp_result_as_string 45 | #include 46 | #endif 47 | #include 48 | } 49 | 50 | #include 51 | 52 | namespace gphoto2pp 53 | { 54 | std::pair autoDetect() 55 | { 56 | auto cameraList = autoDetectAll(); 57 | 58 | return cameraList.getPair(0); 59 | } 60 | 61 | CameraListWrapper autoDetectAll() 62 | { 63 | CameraListWrapper cameraListWrapper; 64 | #ifdef GPHOTO_LESS_25 65 | //All this logic was added to the gp_camera_autodetect method in 2.5 or greater. 66 | 67 | // Constructor for this class will load all port drivers 68 | GPPortInfoListWrapper portInfoListWrapper; 69 | 70 | // Loads all the camera drivers we have 71 | CameraAbilitiesListWrapper cameraAbilitiesListWrapper; 72 | 73 | auto tempListWrapper = cameraAbilitiesListWrapper.listDetect(portInfoListWrapper); 74 | 75 | //Now we need to filter out the usb: 76 | for (int i = 0; i < tempListWrapper.count(); i++) 77 | { 78 | auto name = tempListWrapper.getName(i); 79 | auto value = tempListWrapper.getValue(i); 80 | 81 | if(!std::string("usb:").compare(value)) 82 | { 83 | // We don't want to capture items with usb: 84 | continue; 85 | } 86 | cameraListWrapper.append(name, value); 87 | } 88 | #else 89 | auto spContext = gphoto2pp::getContext(); 90 | gphoto2pp::checkResponse(gphoto2::gp_camera_autodetect(cameraListWrapper.getPtr(), spContext.get()), "gp_camera_autodetect"); 91 | #endif 92 | int count = cameraListWrapper.count(); 93 | 94 | if(count == 0) 95 | { 96 | throw exceptions::NoCameraFoundError("autoDetect(multiple)"); 97 | } 98 | 99 | return std::move(cameraListWrapper); 100 | } 101 | 102 | int checkResponse(int result, std::string&& methodName) 103 | { 104 | if(result < 0) 105 | { 106 | std::stringstream errorMessage; 107 | errorMessage << methodName << ": failed with return code '" << result << "' and the reason is: '" << gphoto2::gp_result_as_string(result) << "'"; 108 | FILE_LOG(logERROR) << "Exception Message - '"<< errorMessage.str().c_str() << "'"; 109 | throw exceptions::gphoto2_exception(result, errorMessage.str()); 110 | } 111 | return result; 112 | } 113 | 114 | int checkResponseSilent(int result, std::string&& methodName) 115 | { 116 | try 117 | { 118 | gphoto2pp::checkResponse(result, std::move(methodName)); 119 | } 120 | catch(const exceptions::gphoto2_exception& e) 121 | { 122 | FILE_LOG(logERROR) << "Suppressed gphoto2_exception[" << e.what() <<"]"; 123 | } 124 | catch(const std::runtime_error& e) 125 | { 126 | FILE_LOG(logCRITICAL) << "Suppressed runtime_error[" << e.what() <<"]"; 127 | } 128 | catch(const std::exception& e) 129 | { 130 | FILE_LOG(logEMERGENCY) << "Suppressed std::exception"; 131 | } 132 | return result; 133 | } 134 | 135 | std::string LibraryVersion(bool verbose) 136 | { 137 | gphoto2::GPVersionVerbosity verbosity = gphoto2::GP_VERSION_SHORT; 138 | if(verbose) 139 | { 140 | verbosity = gphoto2::GP_VERSION_VERBOSE; 141 | } 142 | 143 | // array of char pointers. Remember const char** is equivalent to char const** 144 | char const** resp = gphoto2::gp_library_version(verbosity); 145 | 146 | std::stringstream version; 147 | 148 | char const** iter = resp; 149 | 150 | for(iter = resp; *iter; iter++) 151 | { 152 | version << *iter << std::endl; 153 | } 154 | 155 | return version.str(); 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /include/gphoto2pp/log.h: -------------------------------------------------------------------------------- 1 | #ifndef __LOG_H__ 2 | #define __LOG_H__ 3 | 4 | // from here http://stackoverflow.com/questions/5028302/small-logger-class 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | inline std::string NowTime(); 11 | 12 | enum TLogLevel {logEMERGENCY, logALERT, logCRITICAL, logERROR, logWARN, logWARN1, logWARN2, logWARN3, logINFO, logDEBUG}; 13 | 14 | template 15 | class Log 16 | { 17 | public: 18 | Log(); 19 | virtual ~Log(); 20 | std::ostringstream& Get(TLogLevel level = logINFO); 21 | public: 22 | static TLogLevel& ReportingLevel(); 23 | static std::string ToString(TLogLevel level); 24 | static TLogLevel FromString(const std::string& level); 25 | protected: 26 | std::ostringstream os; 27 | private: 28 | Log(const Log&); 29 | Log& operator =(const Log&); 30 | }; 31 | 32 | template 33 | Log::Log() 34 | { 35 | } 36 | 37 | template 38 | std::ostringstream& Log::Get(TLogLevel level) 39 | { 40 | os << "- " << NowTime(); 41 | os << " " << ToString(level) << ": "; 42 | os << std::string(level > logWARN && level <= logWARN3 ? level - logWARN : 0, '\t'); 43 | return os; 44 | } 45 | 46 | template 47 | Log::~Log() 48 | { 49 | os << std::endl; 50 | T::Output(os.str()); 51 | } 52 | 53 | template 54 | TLogLevel& Log::ReportingLevel() 55 | { 56 | static TLogLevel reportingLevel = logERROR; 57 | return reportingLevel; 58 | } 59 | 60 | template 61 | std::string Log::ToString(TLogLevel level) 62 | { 63 | static const char* const buffer[] = {"EMERGENCY", "ALERT", "CRITICAL", "ERROR", "WARN", "WARN1", "WARN2", "WARN3", "INFO", "DEBUG"}; 64 | return buffer[level]; 65 | } 66 | 67 | template 68 | TLogLevel Log::FromString(const std::string& level) 69 | { 70 | if (level == "DEBUG") 71 | return logDEBUG; 72 | if (level == "INFO") 73 | return logINFO; 74 | if (level == "WARN3") 75 | return logWARN3; 76 | if (level == "WARN2") 77 | return logWARN2; 78 | if (level == "WARN1") 79 | return logWARN1; 80 | if (level == "WARN") 81 | return logWARN; 82 | if (level == "ERROR") 83 | return logERROR; 84 | if (level == "CRITICAL") 85 | return logCRITICAL; 86 | if (level == "ALERT") 87 | return logALERT; 88 | if (level == "EMERGENCY") 89 | return logEMERGENCY; 90 | Log().Get(logWARN) << "Unknown logging level '" << level << "'. Using INFO level as default."; 91 | return logINFO; 92 | } 93 | 94 | class Output2FILE 95 | { 96 | public: 97 | static FILE*& Stream(); 98 | static void Output(const std::string& msg); 99 | }; 100 | 101 | inline FILE*& Output2FILE::Stream() 102 | { 103 | static FILE* pStream = stderr; 104 | return pStream; 105 | } 106 | 107 | inline void Output2FILE::Output(const std::string& msg) 108 | { 109 | FILE* pStream = Stream(); 110 | if (!pStream) 111 | return; 112 | fprintf(pStream, "%s", msg.c_str()); 113 | fflush(pStream); 114 | } 115 | 116 | #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) 117 | # if defined (BUILDING_FILELOG_DLL) 118 | # define FILELOG_DECLSPEC __declspec (dllexport) 119 | # elif defined (USING_FILELOG_DLL) 120 | # define FILELOG_DECLSPEC __declspec (dllimport) 121 | # else 122 | # define FILELOG_DECLSPEC 123 | # endif // BUILDING_DBSIMPLE_DLL 124 | #else 125 | # define FILELOG_DECLSPEC 126 | #endif // _WIN32 127 | 128 | class FILELOG_DECLSPEC FILELog : public Log {}; 129 | //typedef Log FILELog; 130 | 131 | #ifndef FILELOG_MAX_LEVEL 132 | #define FILELOG_MAX_LEVEL logDEBUG 133 | #endif 134 | 135 | #define FILE_LOG(level) \ 136 | if (level > FILELOG_MAX_LEVEL) ;\ 137 | else if (level > FILELog::ReportingLevel() || !Output2FILE::Stream()) ; \ 138 | else FILELog().Get(level) 139 | 140 | #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) 141 | 142 | #include 143 | 144 | inline std::string NowTime() 145 | { 146 | const int MAX_LEN = 200; 147 | char buffer[MAX_LEN]; 148 | if (GetTimeFormatA(LOCALE_USER_DEFAULT, 0, 0, 149 | "HH':'mm':'ss", buffer, MAX_LEN) == 0) 150 | return "Error in NowTime()"; 151 | 152 | char result[100] = {0}; 153 | static DWORD first = GetTickCount(); 154 | std::sprintf(result, "%s.%03ld", buffer, (long)(GetTickCount() - first) % 1000); 155 | return result; 156 | } 157 | 158 | #else 159 | 160 | #include 161 | 162 | inline std::string NowTime() 163 | { 164 | char buffer[11]; 165 | time_t t; 166 | time(&t); 167 | tm r = {0}; 168 | strftime(buffer, sizeof(buffer), "%X", localtime_r(&t, &r)); 169 | struct timeval tv; 170 | gettimeofday(&tv, 0); 171 | char result[100] = {0}; 172 | std::sprintf(result, "%s.%03ld", buffer, (long)tv.tv_usec / 1000); 173 | return result; 174 | } 175 | 176 | #endif //WIN32 177 | 178 | #endif //__LOG_H__ 179 | -------------------------------------------------------------------------------- /tests/CameraListWrapper_NoDevice.h: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | class CameraListWrapper_NoDevice : public CxxTest::TestSuite 33 | { 34 | public: 35 | void setUp() 36 | { 37 | FILELog::ReportingLevel() = logCRITICAL; 38 | } 39 | 40 | void testConstructionAndAssignmentWithReset() 41 | { 42 | gphoto2pp::CameraListWrapper cameraList; 43 | 44 | cameraList.append("First Model","Some Port1"); 45 | cameraList.append("Second Model","Some Port2"); 46 | 47 | TS_ASSERT_EQUALS(cameraList.getName(0),"First Model"); 48 | TS_ASSERT_EQUALS(cameraList.getName(1),"Second Model"); 49 | TS_ASSERT_EQUALS(cameraList.getValue(0),"Some Port1"); 50 | TS_ASSERT_EQUALS(cameraList.getValue(1),"Some Port2"); 51 | 52 | cameraList.reset(); 53 | 54 | TS_ASSERT_EQUALS(cameraList.count(),0); 55 | } 56 | 57 | void testConstructionAndReAssignmentWithSort() 58 | { 59 | gphoto2pp::CameraListWrapper cameraList; 60 | 61 | cameraList.append("First Model","Some Port1"); 62 | cameraList.append("Second Model","Some Port2"); 63 | cameraList.setName(0,"z First Model Modified"); 64 | cameraList.setValue(1,"Some Port2 Modified"); 65 | 66 | cameraList.sort(); 67 | 68 | TS_ASSERT_EQUALS(cameraList.getName(0),"Second Model"); 69 | TS_ASSERT_EQUALS(cameraList.getValue(0),"Some Port2 Modified"); 70 | 71 | TS_ASSERT_EQUALS(cameraList.getName(1),"z First Model Modified"); 72 | TS_ASSERT_EQUALS(cameraList.getValue(1),"Some Port1"); 73 | 74 | TS_ASSERT_THROWS(cameraList.getName(10), gphoto2pp::exceptions::gphoto2_exception); // out of bounds 75 | } 76 | 77 | void testFindByName() 78 | { 79 | gphoto2pp::CameraListWrapper cameraList; 80 | 81 | cameraList.append("First Model","Some Port1"); 82 | cameraList.append("Second Model","Some Port2"); 83 | 84 | TS_ASSERT_THROWS(cameraList.findByName("First"), gphoto2pp::exceptions::gphoto2_exception); 85 | 86 | auto index = cameraList.findByName("First Model"); 87 | 88 | TS_ASSERT_EQUALS(index,0); 89 | } 90 | 91 | void testDuplicatesWithFindByName() 92 | { 93 | gphoto2pp::CameraListWrapper cameraList; 94 | 95 | cameraList.append("First Model","Some Port1"); 96 | cameraList.append("First Model","Some Port1"); // Should I make the append method throw an error if the model aleady exists on the port? Best to ask Marcus 97 | 98 | //TS_ASSERT_EQUALS(cameraList.count(),1); 99 | } 100 | 101 | void testCopyAndAssignmentOperators() 102 | { 103 | gphoto2pp::CameraListWrapper cameraList; 104 | 105 | cameraList.append("First Model","Some Port1"); 106 | cameraList.append("Second Model","Some Port2"); 107 | 108 | { 109 | // Copy Constructor 110 | auto copy(cameraList); 111 | 112 | TS_ASSERT_EQUALS(cameraList.getName(0),"First Model"); 113 | TS_ASSERT_EQUALS(copy.getName(0),"First Model"); 114 | } 115 | 116 | { 117 | // Copy Assignment 118 | auto assignment = cameraList; 119 | 120 | TS_ASSERT_EQUALS(cameraList.getName(0),"First Model"); 121 | TS_ASSERT_EQUALS(assignment.getName(0),"First Model"); 122 | } 123 | 124 | { 125 | // Move Assignment 126 | auto moveassignment = std::move(cameraList); 127 | 128 | TS_ASSERT_EQUALS(moveassignment.getName(0),"First Model"); 129 | TS_ASSERT_THROWS(cameraList.count(), gphoto2pp::exceptions::gphoto2_exception); // The old value is no longer valid 130 | 131 | cameraList = moveassignment; // now copy it back 132 | 133 | TS_ASSERT_EQUALS(cameraList.getName(0),"First Model"); 134 | } 135 | 136 | { 137 | // Move Constructor 138 | auto moveconstructor(std::move(cameraList)); 139 | 140 | TS_ASSERT_EQUALS(moveconstructor.getName(0),"First Model"); 141 | TS_ASSERT_THROWS(cameraList.count(), gphoto2pp::exceptions::gphoto2_exception); // The old value is no longer valid again 142 | 143 | cameraList = moveconstructor; // now copy it back 144 | 145 | TS_ASSERT_EQUALS(cameraList.getName(0),"First Model"); 146 | } 147 | } 148 | }; 149 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 2.8.3) 2 | project (GPHOTO2PP DESCRIPTION "A C++ wrapper for libgphoto2") 3 | 4 | if(CMAKE_BUILD_TYPE) 5 | message("Building ${CMAKE_BUILD_TYPE} build.") 6 | elseif(NOT CMAKE_BUILD_TYPE) 7 | message(FATAL_ERROR "No build type specified. Use -DCMAKE_BUILD_TYPE=[DEBUG|RELEASE] to specify.") 8 | endif(CMAKE_BUILD_TYPE) 9 | 10 | #set the version of our library 11 | # MAJOR, is significant breaking changes, MINOR, is when we might have changed signatures of existing functions, PATCH, is just bug fixes and no breaking changes 12 | set(MYLIB_VERSION_MAJOR 1) 13 | set(MYLIB_VERSION_MINOR 0) 14 | set(MYLIB_VERSION_PATCH 0) 15 | set(MYLIB_VERSION_STRING ${MYLIB_VERSION_MAJOR}.${MYLIB_VERSION_MINOR}.${MYLIB_VERSION_PATCH}) 16 | 17 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/modules/) 18 | 19 | # finds the current version of libgphoto2 installed 20 | find_package( Gphoto2 REQUIRED ) 21 | if(GPHOTO2_FOUND) 22 | include_directories(${Gphoto2_INCLUDE_DIRS}) 23 | list(APPEND LIBS ${Gphoto2_LIBRARIES}) 24 | 25 | # Gphoto 2.5 had breaking api changes that weren't compatable with older versions. 26 | # Although I'm developing with the latest in mind, there's no reason this wrapper 27 | # shouldn't work for versions less than 2.5 (as most linux distros still use 2.4.14) 28 | if(${GPHOTO2_VERSION_STRING} VERSION_LESS "2.5") 29 | add_definitions("-DGPHOTO_LESS_25") 30 | endif() 31 | endif() 32 | 33 | include(GNUInstallDirs) 34 | 35 | if(UNIX) 36 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11") 37 | if(CMAKE_BUILD_TYPE MATCHES "RELEASE") 38 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") 39 | elseif(CMAKE_BUILD_TYPE MATCHES "DEBUG") 40 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g") 41 | endif(CMAKE_BUILD_TYPE MATCHES "RELEASE") 42 | else() 43 | # I have never tried it on any other OS. I suspect apple will work. 44 | message( FATAL_ERROR "I have never tried this on a non Linux machine, please try at your own risk") 45 | endif() 46 | 47 | # base path of where binaries should be built 48 | set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) 49 | 50 | # where the library will be built to 51 | set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/libs) 52 | 53 | ############ 54 | # gphoto2pp 55 | ############ 56 | FILE(GLOB GPHOTO2PP_SOURCE_FILES "src/*.cpp") 57 | FILE(GLOB GPHOTO2PP_HPPHEADER_FILES "include/gphoto2pp/*.hpp") 58 | FILE(GLOB GPHOTO2PP_HEADER_FILES "include/gphoto2pp/*.h") 59 | 60 | set(GPHOTO2PP_SOURCES ${GPHOTO2PP_SOURCE_FILES}) 61 | set(GPHOTO2PP_HEADERS ${GPHOTO2PP_HPPHEADER_FILES} ${GPHOTO2PP_HEADER_FILES}) 62 | 63 | add_library( gphoto2pp SHARED ${GPHOTO2PP_SOURCES}) 64 | target_link_libraries(gphoto2pp pthread) 65 | 66 | include_directories("include") 67 | 68 | # sets the shared library version 69 | # http://cmake.3232098.n2.nabble.com/Version-in-name-of-shared-library-td7581530.html 70 | set_target_properties( gphoto2pp PROPERTIES VERSION ${MYLIB_VERSION_STRING} SOVERSION ${MYLIB_VERSION_MAJOR} ) 71 | 72 | # create pkg-config files for configuration in non-cmake projects 73 | configure_file(gphoto2pp.pc.in gphoto2pp.pc @ONLY) 74 | 75 | # only offer install option if they compiled with release mode 76 | if(CMAKE_BUILD_TYPE MATCHES "RELEASE") 77 | # adds the 'make install' targets to copy the shared library to /usr/local/lib/ directory 78 | install( TARGETS gphoto2pp DESTINATION ${CMAKE_INSTALL_LIBDIR} ) 79 | # adds all the relevant headers to /usr/local/include/gphoto2pp when ``make install`` is executed 80 | install( FILES ${GPHOTO2PP_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/gphoto2pp ) 81 | 82 | # install the pkg-config config to system folder 83 | install(FILES ${CMAKE_BINARY_DIR}/gphoto2pp.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig) 84 | endif(CMAKE_BUILD_TYPE MATCHES "RELEASE") 85 | 86 | ########### 87 | # Examples 88 | ########### 89 | add_subdirectory( examples ) 90 | 91 | ############# 92 | # Unit Tests 93 | ############# 94 | # for now only add unit tests in dev mode 95 | if(CMAKE_BUILD_TYPE MATCHES "DEBUG") 96 | enable_testing() 97 | add_subdirectory( tests ) 98 | endif(CMAKE_BUILD_TYPE MATCHES "DEBUG") 99 | 100 | ############################### 101 | # Docs generation with Doxygen 102 | ############################### 103 | if(CMAKE_BUILD_TYPE MATCHES "DEBUG") 104 | find_package( Doxygen ) 105 | if( DOXYGEN_FOUND ) 106 | add_custom_target (doc ${DOXYGEN_EXECUTABLE} ${CMAKE_SOURCE_DIR}/Doxyfile 107 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 108 | COMMENT "Generating source code documentation with Doxygen." VERBATIM) 109 | endif() # DOXYGEN_FOUND 110 | endif(CMAKE_BUILD_TYPE MATCHES "DEBUG") 111 | 112 | ################### 113 | # uninstall target 114 | ################### 115 | if(CMAKE_BUILD_TYPE MATCHES "RELEASE") 116 | configure_file( 117 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" 118 | "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" 119 | IMMEDIATE @ONLY) 120 | 121 | add_custom_target(uninstall 122 | COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) 123 | endif(CMAKE_BUILD_TYPE MATCHES "RELEASE") 124 | -------------------------------------------------------------------------------- /src/helper_debugging.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | 29 | namespace gphoto2 30 | { 31 | #include 32 | } 33 | 34 | namespace gphoto2pp 35 | { 36 | namespace helper 37 | { 38 | namespace debugging 39 | { 40 | namespace detail 41 | { 42 | static PortLoggingEventsManager PortLogEventHandler; 43 | 44 | // From Here http://stackoverflow.com/questions/2342162/stdstring-formatting-like-sprintf 45 | inline std::string strformat(char const * fmt, va_list vl){ 46 | int size = 512; 47 | char* buffer = 0; 48 | buffer = new char[size]; 49 | //va_list vl; 50 | //va_start(vl, fmt); 51 | int nsize = vsnprintf(buffer, size, fmt, vl); 52 | if(size<=nsize){ //fail delete buffer and try again 53 | delete[] buffer; 54 | buffer = 0; 55 | buffer = new char[nsize+1]; //+1 for /0 56 | nsize = vsnprintf(buffer, size, fmt, vl); 57 | } 58 | std::string ret(buffer); 59 | va_end(vl); 60 | delete[] buffer; 61 | return ret; 62 | } 63 | 64 | inline std::string strformat(char const * fmt, ...){ 65 | va_list vl; 66 | va_start(vl, fmt); 67 | return strformat(fmt, vl); 68 | } 69 | 70 | #ifdef GPHOTO_LESS_25 71 | static void errordumper(gphoto2::GPLogLevel level, const char *domain, const char *format, va_list args, void *data) 72 | { 73 | std::string str = strformat(format, args); 74 | #else 75 | static void errordumper(gphoto2::GPLogLevel level, const char *domain, const char *str, void *data) 76 | { 77 | #endif 78 | 79 | switch(level) 80 | { 81 | case gphoto2::GP_LOG_ERROR: 82 | { 83 | PortLogEventHandler(LogLevelWrapper::Error, static_cast(level), std::string(domain), std::string(str), data); 84 | } 85 | case gphoto2::GP_LOG_VERBOSE: 86 | { 87 | PortLogEventHandler(LogLevelWrapper::Verbose, static_cast(level), std::string(domain), std::string(str), data); 88 | } 89 | case gphoto2::GP_LOG_DEBUG: 90 | { 91 | PortLogEventHandler(LogLevelWrapper::Debug, static_cast(level), std::string(domain), std::string(str), data); 92 | } 93 | case gphoto2::GP_LOG_DATA: 94 | { 95 | PortLogEventHandler(LogLevelWrapper::Data, static_cast(level), std::string(domain), std::string(str), data); 96 | } 97 | default: 98 | { 99 | break; 100 | } 101 | } 102 | 103 | //~ // Not sure if this is necessary, as they can log their own messages... 104 | //~ auto now = std::chrono::high_resolution_clock::now(); 105 | //~ auto us = std::chrono::duration_cast(now.time_since_epoch()); 106 | //~ auto s = std::chrono::duration_cast(us); 107 | //~ FILE_LOG(logERROR) << (s.count() % 60) << "." << (us.count() % 1000000) << ": " << str; 108 | } 109 | 110 | PortLoggingEventsManager::~PortLoggingEventsManager() 111 | { 112 | stopPortLogging(); 113 | } 114 | 115 | void PortLoggingEventsManager::startPortLogging(LogLevelWrapper const & level) 116 | { 117 | if(id == 0) 118 | { 119 | id = checkResponse(gphoto2::gp_log_add_func(static_cast(level), errordumper, nullptr), "gp_log_add_func"); 120 | } 121 | } 122 | 123 | void PortLoggingEventsManager::stopPortLogging() 124 | { 125 | if(id != 0) 126 | { 127 | checkResponse(gphoto2::gp_log_remove_func(id), "gp_log_remove_func"); 128 | id = 0; 129 | } 130 | } 131 | } 132 | 133 | void startPortLogging(LogLevelWrapper const & level) 134 | { 135 | detail::PortLogEventHandler.startPortLogging(level); 136 | } 137 | 138 | void stopPortLogging() 139 | { 140 | detail::PortLogEventHandler.stopPortLogging(); 141 | } 142 | 143 | observer::Registration subscribeToPortLogEvents(LogLevelWrapper const & event, std::function func) 144 | { 145 | return detail::PortLogEventHandler.registerObserver(event, std::move(func)); 146 | } 147 | } 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /include/gphoto2pp/camera_list_wrapper.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef CAMERALISTWRAPPER_HPP 26 | #define CAMERALISTWRAPPER_HPP 27 | 28 | #include 29 | 30 | namespace gphoto2 31 | { 32 | struct _CameraList; 33 | } 34 | 35 | namespace gphoto2pp 36 | { 37 | /** 38 | * \class CameraFileWrapper 39 | * A wrapper around the gphoto2 CameraFile struct. 40 | */ 41 | class CameraListWrapper 42 | { 43 | public: 44 | CameraListWrapper(); 45 | ~CameraListWrapper(); 46 | 47 | // Move constructor and move assignment are allowed 48 | CameraListWrapper(CameraListWrapper&& other); 49 | CameraListWrapper& operator=(CameraListWrapper&& other); 50 | 51 | CameraListWrapper(CameraListWrapper const & other); 52 | CameraListWrapper& operator=(CameraListWrapper const & other); 53 | 54 | gphoto2::_CameraList* getPtr() const; 55 | 56 | /** 57 | * \brief Gets the number of cameras contained in the list 58 | * \return the number of cameras 59 | * \note Direct wrapper for gp_list_count(...) 60 | * \throw GPhoto2pp::exceptions::gphoto2_exception 61 | */ 62 | int count() const; 63 | 64 | /** 65 | * \brief Gets the model name of the camera at the index 66 | * \param[in] index of the model name to get 67 | * \return the camera model name 68 | * \note Direct wrapper for gp_list_get_name(...) 69 | * \throw GPhoto2pp::exceptions::gphoto2_exception 70 | */ 71 | std::string getName(int index) const; 72 | 73 | /** 74 | * \brief Gets the port of the camera at the index 75 | * \param[in] index of the port value to get 76 | * \return the port which the camera is connected to 77 | * \note Direct wrapper for gp_list_get_value(...) 78 | * \throw GPhoto2pp::exceptions::gphoto2_exception 79 | */ 80 | std::string getValue(int index) const; 81 | 82 | /** 83 | * \brief Sets the camera model name at the specified index 84 | * \param[in] index of the name to set 85 | * \param[in] name of the model to set 86 | * \note Direct wrapper for gp_list_set_name(...) 87 | * \throw GPhoto2pp::exceptions::gphoto2_exception 88 | */ 89 | void setName(int index, std::string const & name); 90 | 91 | /** 92 | * \brief Sets the camera port at the specified index 93 | * \param[in] index of the port to set 94 | * \param[in] value of the port name to set 95 | * \note Direct wrapper for gp_list_set_value(...) 96 | * \throw GPhoto2pp::exceptions::gphoto2_exception 97 | */ 98 | void setValue(int index, std::string const & value); 99 | 100 | /** 101 | * \brief Adds a new camera model and port pair 102 | * \param[in] name of the camera model 103 | * \param[in] value of the port connected to the camera 104 | * \note Direct wrapper for gp_list_append(...) 105 | * \throw GPhoto2pp::exceptions::gphoto2_exception 106 | */ 107 | void append(std::string const & name, std::string const & value); 108 | 109 | /** 110 | * \brief Erases all model and port pairs in the current list. 111 | * \note Direct wrapper for gp_list_reset(...) 112 | * \throw GPhoto2pp::exceptions::gphoto2_exception 113 | */ 114 | void reset(); 115 | 116 | /** 117 | * \brief Sorts the list based on the name (camera model) 118 | * \note Direct wrapper for gp_list_sort(...) 119 | * \throw GPhoto2pp::exceptions::gphoto2_exception 120 | */ 121 | void sort(); 122 | 123 | /** 124 | * \brief Sorts the list based on the name (camera model) 125 | * \param[in] name of the model to search for 126 | * \note Direct wrapper for gp_list_sort(...) 127 | * \throw GPhoto2pp::exceptions::gphoto2_exception 128 | */ 129 | int findByName(std::string const & name) const; 130 | 131 | /** 132 | * \brief Gets the name (model) and value (port) pair 133 | * \param[in] index of the model/port pair to get 134 | * \return the model/port pair 135 | * \throw GPhoto2pp::exceptions::gphoto2_exception 136 | */ 137 | std::pair getPair(int index) const; 138 | 139 | /** 140 | * \brief Gets the name (model) and value (port) pair by searching the name 141 | * \param[in] name of the model to search for 142 | * \return the model\port pair 143 | * \throw GPhoto2pp::exceptions::gphoto2_exception 144 | */ 145 | std::pair getPairByName(std::string const & name) const; 146 | 147 | private: 148 | gphoto2::_CameraList* m_cameraList; 149 | }; 150 | } 151 | 152 | #endif // CAMERALISTWRAPPER_HPP 153 | -------------------------------------------------------------------------------- /include/gphoto2pp/non_value_widget.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef NONVALUEWIDGET_HPP 26 | #define NONVALUEWIDGET_HPP 27 | 28 | #include 29 | 30 | namespace gphoto2pp 31 | { 32 | /** 33 | * \class NonValueWidget 34 | * A class representing gphoto2 widgets which are not leaf nodes (have children), which is a Window or Section widget 35 | */ 36 | class NonValueWidget : public CameraWidgetWrapper 37 | { 38 | public: 39 | /** 40 | * \brief Gets the number of children to this current widget 41 | * \return the number of children 42 | * \note Direct wrapper for gp_widget_count_children(...) 43 | * \throw GPhoto2pp::exceptions::gphoto2_exception 44 | */ 45 | int countChildren() const; 46 | 47 | /** 48 | * \brief Gets the child widget that matches the name. 49 | * \tparam T type that inherits from CameraWidgetWrapper 50 | * \param[in] name of the child widget to get 51 | * \return the widget 52 | * \throw GPhoto2pp::exceptions::gphoto2_exception 53 | */ 54 | template 55 | T getChildByName(std::string const & name) const 56 | { 57 | auto cameraWidget = getChildByNameWrapper(name); 58 | return T(cameraWidget); 59 | } 60 | 61 | /** 62 | * \brief Gets the child widget that matches the label. 63 | * \tparam T type that inherits from CameraWidgetWrapper 64 | * \param[in] label of the child widget to get 65 | * \return the widget 66 | * \throw GPhoto2pp::exceptions::gphoto2_exception 67 | */ 68 | template 69 | T getChildByLabel(std::string const & label) const 70 | { 71 | auto cameraWidget = getChildByLabelWrapper(label); 72 | return T(cameraWidget); 73 | } 74 | 75 | /** 76 | * \brief Gets the child widget at the specified index. 77 | * \tparam a type that inherits from CameraWidgetWrapper 78 | * \param[in] index of the child widget to get 79 | * \return the widget 80 | * \throw GPhoto2pp::exceptions::gphoto2_exception 81 | */ 82 | template 83 | T getChild(int index) const 84 | { 85 | auto cameraWidget = getChildWrapper(index); 86 | return T(cameraWidget); 87 | } 88 | 89 | /** 90 | * \brief Gets the child widget that matches the unique id. 91 | * \tparam a type that inherits from CameraWidgetWrapper 92 | * \param[in] id of the child widget to get 93 | * \return the widget 94 | * \throw GPhoto2pp::exceptions::gphoto2_exception 95 | */ 96 | template 97 | T getChildById(int id) const 98 | { 99 | auto cameraWidget = getChildByIdWrapper(id); 100 | return T(cameraWidget); 101 | } 102 | 103 | protected: 104 | NonValueWidget(gphoto2::_CameraWidget* cameraWidget); 105 | 106 | /** 107 | * \brief Gets the child widget by the name passed in and returns the widget type that the user expects. 108 | * \tparam a type that inherits from CameraWidgetWrapper 109 | * \param[in] name of the child widget to get 110 | * \return the widget 111 | * \note Direct wrapper for gp_widget_get_child_by_name(...) 112 | * \throw GPhoto2pp::exceptions::gphoto2_exception 113 | */ 114 | gphoto2::_CameraWidget* getChildByNameWrapper(std::string const & name) const; 115 | 116 | /** 117 | * \brief Gets the child widget by the label passed in and returns the widget type that the user expects. 118 | * \tparam a type that inherits from CameraWidgetWrapper 119 | * \param[in] label of the child widget to get 120 | * \return the widget 121 | * \note Direct wrapper for gp_widget_get_child_by_label(...) 122 | * \throw GPhoto2pp::exceptions::gphoto2_exception 123 | */ 124 | gphoto2::_CameraWidget* getChildByLabelWrapper(std::string const & label) const; 125 | 126 | /** 127 | * \brief Gets the child widget at the specified index and returns the widget type that the user expects. 128 | * \tparam a type that inherits from CameraWidgetWrapper 129 | * \param[in] index of the child widget to get 130 | * \return the widget 131 | * \note Direct wrapper for gp_widget_get_child(...) 132 | * \throw GPhoto2pp::exceptions::IndexOutOfRange 133 | * \throw GPhoto2pp::exceptions::gphoto2_exception 134 | */ 135 | gphoto2::_CameraWidget* getChildWrapper(int index) const; 136 | 137 | /** 138 | * \brief Gets the child widget that matches the unique id. 139 | * \tparam a type that inherits from CameraWidgetWrapper 140 | * \param[in] id of the child widget to get 141 | * \return the widget 142 | * \note Direct wrapper for gp_widget_get_child_by_id(...) 143 | * \throw GPhoto2pp::exceptions::gphoto2_exception 144 | */ 145 | gphoto2::_CameraWidget* getChildByIdWrapper(int id) const; 146 | }; 147 | 148 | } 149 | 150 | #endif // NONVALUEWIDGET_HPP 151 | -------------------------------------------------------------------------------- /src/helper_camera_wrapper.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | 36 | namespace gphoto2pp 37 | { 38 | namespace helper 39 | { 40 | void capturePreview(CameraWrapper& cameraWrapper, std::string const & outputFilename) 41 | { 42 | CameraFileWrapper cameraFile = cameraWrapper.capturePreview(); // No point in duplicating code, call overloaded method 43 | 44 | cameraFile.save(outputFilename); 45 | } 46 | 47 | void capturePreview(CameraWrapper& cameraWrapper, std::ostream& outputStream) 48 | { 49 | CameraFileWrapper cameraFile = cameraWrapper.capturePreview(); // No point in duplicating code, call overloaded method 50 | 51 | auto buffer = cameraFile.getDataAndSize(); 52 | 53 | outputStream.write(buffer.data(), buffer.size()); 54 | 55 | outputStream.flush(); 56 | // Not sure if I should close the file in here, or let the user do it. I'll let the user do it for now. 57 | } 58 | 59 | void capture(CameraWrapper& cameraWrapper, CameraFileWrapper& cameraFile, bool autoDeleteImageFromSrc /* = false */, CameraCaptureTypeWrapper const & captureType /* = Image */, CameraFileTypeWrapper const & fileType /* = Normal */) 60 | { 61 | auto cameraFilePath = cameraWrapper.capture(captureType); 62 | 63 | // This should be the move assignment operator 64 | cameraFile = cameraWrapper.fileGet(cameraFilePath.Folder, cameraFilePath.Name, fileType); 65 | 66 | if(autoDeleteImageFromSrc) 67 | { 68 | cameraWrapper.fileDelete(cameraFilePath.Folder, cameraFilePath.Name); 69 | } 70 | } 71 | 72 | void capture(CameraWrapper& cameraWrapper, std::string const & outputFilename, bool autoDeleteImageFromSrc /* = false */, CameraCaptureTypeWrapper const & captureType /* = Image */, CameraFileTypeWrapper const & fileType /* = Normal */) 73 | { 74 | auto cameraFilePath = cameraWrapper.capture(captureType); 75 | 76 | auto cameraFile = cameraWrapper.fileGet(cameraFilePath.Folder, cameraFilePath.Name, fileType); 77 | 78 | cameraFile.save(outputFilename); 79 | 80 | if(autoDeleteImageFromSrc) 81 | { 82 | cameraWrapper.fileDelete(cameraFilePath.Folder, cameraFilePath.Name); 83 | } 84 | } 85 | 86 | void capture(CameraWrapper& cameraWrapper, std::ostream& outputStream, bool autoDeleteImageFromSrc /* = false */, CameraCaptureTypeWrapper const & captureType /* = Image */, CameraFileTypeWrapper const & fileType /* = Normal */) 87 | { 88 | auto cameraFilePath = cameraWrapper.capture(captureType); 89 | 90 | auto cameraFile = cameraWrapper.fileGet(cameraFilePath.Folder, cameraFilePath.Name, fileType); 91 | 92 | auto temp = cameraFile.getDataAndSize(); 93 | 94 | outputStream.write(temp.data(),temp.size()); 95 | 96 | outputStream.flush(); // If we don't flush, I found strange things might happen to the jpg, for one thing the thumbnail wouldn't show up. Makes sense, as once we leave this scope some items are disposed, so we want to make sure that the stream is flushed. 97 | // Not sure if I should close the file in here as well, or let the user do it. I'll let the user do it for now. 98 | 99 | if(autoDeleteImageFromSrc) 100 | { 101 | cameraWrapper.fileDelete(cameraFilePath.Folder, cameraFilePath.Name); 102 | } 103 | } 104 | 105 | //Private Method 106 | void getChildrenItems(CameraWrapper& cameraWrapper, std::string const & folder, std::vector& allItems, bool getFiles) 107 | { 108 | if(getFiles == false) 109 | { 110 | allItems.push_back(folder); 111 | } 112 | else 113 | { 114 | auto cameraListFiles = cameraWrapper.folderListFiles(folder); 115 | 116 | for(int i = 0; i < cameraListFiles.count(); ++i) 117 | { 118 | allItems.push_back(folder + cameraListFiles.getName(i)); 119 | } 120 | } 121 | 122 | auto cameraListFolders = cameraWrapper.folderListFolders(folder); 123 | 124 | for(int i = 0; i < cameraListFolders.count(); ++i) 125 | { 126 | getChildrenItems(cameraWrapper, folder + cameraListFolders.getName(i) + "/", allItems, getFiles); 127 | } 128 | } 129 | 130 | std::vector getAllFolders(CameraWrapper& cameraWrapper) 131 | { 132 | std::vector allFolders; 133 | 134 | getChildrenItems(cameraWrapper, "/", allFolders, false); 135 | 136 | return allFolders; 137 | } 138 | 139 | std::vector getAllFiles(CameraWrapper& cameraWrapper) 140 | { 141 | std::vector allFiles; 142 | 143 | getChildrenItems(cameraWrapper, "/", allFiles, true); 144 | 145 | return allFiles; 146 | } 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /src/camera_list_wrapper.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | 29 | namespace gphoto2 30 | { 31 | #include 32 | } 33 | 34 | namespace gphoto2pp 35 | { 36 | 37 | CameraListWrapper::CameraListWrapper() 38 | : m_cameraList{nullptr} 39 | { 40 | gphoto2pp::checkResponse(gphoto2::gp_list_new(&m_cameraList),"gp_list_new"); 41 | } 42 | 43 | CameraListWrapper::~CameraListWrapper() 44 | { 45 | if(m_cameraList != nullptr) // Added this line so the move constructor wouldn't dispose of the object if it was reassigned 46 | { 47 | gphoto2pp::checkResponseSilent(gphoto2::gp_list_unref(m_cameraList),"gp_list_unref"); 48 | m_cameraList = nullptr; 49 | } 50 | } 51 | 52 | CameraListWrapper::CameraListWrapper(CameraListWrapper&& other) 53 | : m_cameraList{other.m_cameraList} 54 | { 55 | other.m_cameraList = nullptr; 56 | } 57 | 58 | CameraListWrapper& CameraListWrapper::operator=(CameraListWrapper&& other) 59 | { 60 | if(this != &other) 61 | { 62 | // Release current objects resource 63 | if(m_cameraList != nullptr) 64 | { 65 | gphoto2pp::checkResponse(gphoto2::gp_list_unref(m_cameraList),"gp_list_unref"); 66 | } 67 | 68 | // Steal or "move" the other objects resource 69 | m_cameraList = other.m_cameraList; 70 | 71 | // Unreference the other objects resource, so it's destructor doesn't unreference it 72 | other.m_cameraList = nullptr; 73 | } 74 | return *this; 75 | } 76 | 77 | CameraListWrapper::CameraListWrapper(CameraListWrapper const & other) 78 | : m_cameraList{other.m_cameraList} 79 | { 80 | // Because we now refer to the same cameralist as "other", we need to add to it's reference count 81 | if(m_cameraList != nullptr) 82 | { 83 | gphoto2::gp_list_ref(m_cameraList); 84 | } 85 | } 86 | 87 | CameraListWrapper& CameraListWrapper::operator=(CameraListWrapper const & other) 88 | { 89 | if(this != &other) 90 | { 91 | // Release current objects resource 92 | if(m_cameraList != nullptr) 93 | { 94 | gphoto2pp::checkResponse(gphoto2::gp_list_unref(m_cameraList),"gp_list_unref"); 95 | } 96 | 97 | // copy the other objects pointer 98 | m_cameraList = other.m_cameraList; 99 | 100 | // Add reference count to the copied cameraList 101 | if(m_cameraList != nullptr) 102 | { 103 | gphoto2pp::checkResponse(gphoto2::gp_list_ref(m_cameraList),"gp_list_ref"); 104 | } 105 | } 106 | return *this; 107 | } 108 | 109 | gphoto2::_CameraList* CameraListWrapper::getPtr() const 110 | { 111 | return m_cameraList; 112 | } 113 | 114 | int CameraListWrapper::count() const 115 | { 116 | return gphoto2pp::checkResponse(gphoto2::gp_list_count(m_cameraList),"gp_list_count"); 117 | } 118 | 119 | std::string CameraListWrapper::getName(int index) const 120 | { 121 | const char* temp = nullptr; 122 | 123 | gphoto2pp::checkResponse(gphoto2::gp_list_get_name(m_cameraList, index, &temp),"gp_list_get_name"); 124 | 125 | if(temp == nullptr) 126 | { 127 | return std::string{}; 128 | } 129 | else 130 | { 131 | return std::string{temp}; 132 | } 133 | } 134 | 135 | std::string CameraListWrapper::getValue(int index) const 136 | { 137 | char const * temp = nullptr; 138 | 139 | gphoto2pp::checkResponse(gphoto2::gp_list_get_value(m_cameraList, index, &temp),"gp_list_get_value"); 140 | 141 | if(temp == nullptr) // sometimes it returns null, so we will just consider that an empty string 142 | { 143 | return std::string{}; 144 | } 145 | else 146 | { 147 | return std::string{temp}; 148 | } 149 | } 150 | 151 | void CameraListWrapper::append(std::string const & name, std::string const & value) 152 | { 153 | gphoto2pp::checkResponse(gphoto2::gp_list_append(m_cameraList, name.c_str(), value.c_str()),"gp_list_append"); 154 | } 155 | 156 | void CameraListWrapper::reset() 157 | { 158 | gphoto2pp::checkResponse(gphoto2::gp_list_reset(m_cameraList),"gp_list_reset"); 159 | } 160 | 161 | void CameraListWrapper::sort() 162 | { 163 | gphoto2pp::checkResponse(gphoto2::gp_list_sort(m_cameraList),"gp_list_sort"); 164 | } 165 | 166 | int CameraListWrapper::findByName(std::string const & name) const 167 | { 168 | int index; 169 | 170 | gphoto2pp::checkResponse(gphoto2::gp_list_find_by_name(m_cameraList, &index, name.c_str()),"gp_list_find_by_name"); 171 | 172 | return index; 173 | } 174 | 175 | void CameraListWrapper::setName(int index, std::string const & name) 176 | { 177 | gphoto2pp::checkResponse(gphoto2::gp_list_set_name(m_cameraList, index, name.c_str()),"gp_list_set_name"); 178 | } 179 | 180 | void CameraListWrapper::setValue(int index, std::string const & value) 181 | { 182 | gphoto2pp::checkResponse(gphoto2::gp_list_set_value(m_cameraList, index, value.c_str()),"gp_list_set_value"); 183 | } 184 | 185 | std::pair CameraListWrapper::getPair(int index) const 186 | { 187 | return std::make_pair(getName(index), getValue(index)); 188 | } 189 | 190 | std::pair CameraListWrapper::getPairByName(std::string const & name) const 191 | { 192 | auto index = findByName(name); 193 | 194 | return std::make_pair(getName(index), getValue(index)); 195 | } 196 | } 197 | 198 | -------------------------------------------------------------------------------- /src/camera_widget_wrapper.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | namespace gphoto2 31 | { 32 | #include 33 | } 34 | 35 | namespace gphoto2pp 36 | { 37 | CameraWidgetWrapper::CameraWidgetWrapper(gphoto2::_CameraWidget* cameraWidget) 38 | : m_cameraWidget{cameraWidget} 39 | { 40 | // This call to increment the reference is correct 99% of the time when this constructor is called 41 | // because it is likely being called for a child widget. However the one scenario when we call this 42 | // constructor from the CameraWrapper.getConfig, it is the parent, and so we have now just incremented 43 | // the reference to == 2. This is wrong, and so we unref right after in CameraWrapper::getConfig 44 | ref(); 45 | } 46 | 47 | CameraWidgetWrapper::~CameraWidgetWrapper() 48 | { 49 | if(m_cameraWidget != nullptr) 50 | { 51 | unref(); 52 | 53 | m_cameraWidget = nullptr; 54 | } 55 | } 56 | 57 | CameraWidgetWrapper::CameraWidgetWrapper(CameraWidgetWrapper&& other) 58 | : m_cameraWidget{other.m_cameraWidget} 59 | { 60 | other.m_cameraWidget = nullptr; // So when the 'other' instance calls it's destructor, it won't try to unreference. 61 | } 62 | 63 | CameraWidgetWrapper& CameraWidgetWrapper::operator=(CameraWidgetWrapper&& other) 64 | { 65 | // Check for self assignment 66 | if(this != &other) 67 | { 68 | // Release current objects resource 69 | if(m_cameraWidget != nullptr) 70 | { 71 | unref(); 72 | } 73 | 74 | // Steal or "move" the other objects resource 75 | m_cameraWidget = other.m_cameraWidget; 76 | 77 | // Unreference the other objects resource, so it's destructor doesn't unreference it 78 | other.m_cameraWidget = nullptr; 79 | } 80 | 81 | return *this; 82 | } 83 | 84 | CameraWidgetWrapper::CameraWidgetWrapper(CameraWidgetWrapper const & other) 85 | : m_cameraWidget{other.m_cameraWidget} 86 | { 87 | ref(); 88 | } 89 | 90 | CameraWidgetWrapper& CameraWidgetWrapper::operator=(CameraWidgetWrapper const & other) 91 | { 92 | // Check for self assignment 93 | if(this != &other) 94 | { 95 | // Release current objects resource 96 | if(m_cameraWidget != nullptr) 97 | { 98 | unref(); 99 | } 100 | 101 | // copy the other objects pointer 102 | m_cameraWidget = other.m_cameraWidget; 103 | 104 | // Now we add reference to thew new one we just copied 105 | if(m_cameraWidget != nullptr) 106 | { 107 | ref(); 108 | } 109 | } 110 | return *this; 111 | } 112 | 113 | gphoto2::_CameraWidget* CameraWidgetWrapper::getPtr() const 114 | { 115 | return m_cameraWidget; 116 | } 117 | 118 | std::string CameraWidgetWrapper::getName() const 119 | { 120 | const char* temp = nullptr; 121 | 122 | gphoto2pp::checkResponse(gphoto2::gp_widget_get_name(m_cameraWidget, &temp),"gp_widget_get_name"); 123 | 124 | return std::string(temp); 125 | } 126 | 127 | CameraWidgetTypeWrapper CameraWidgetWrapper::getType() const 128 | { 129 | gphoto2::CameraWidgetType temp; 130 | 131 | gphoto2pp::checkResponse(gphoto2::gp_widget_get_type(m_cameraWidget, &temp),"gp_widget_get_type"); 132 | 133 | return static_cast(temp); 134 | } 135 | 136 | std::string CameraWidgetWrapper::getLabel() const 137 | { 138 | const char* temp = nullptr; 139 | 140 | gphoto2pp::checkResponse(gphoto2::gp_widget_get_label(m_cameraWidget, &temp),"gp_widget_get_label"); 141 | 142 | return std::string(temp); 143 | } 144 | 145 | std::string CameraWidgetWrapper::getInfo() const 146 | { 147 | const char* temp = nullptr; 148 | 149 | gphoto2pp::checkResponse(gphoto2::gp_widget_get_info(m_cameraWidget, &temp),"gp_widget_get_info"); 150 | 151 | return std::string(temp); 152 | } 153 | 154 | int CameraWidgetWrapper::getId() const 155 | { 156 | int id = 0; 157 | 158 | gphoto2pp::checkResponse(gphoto2::gp_widget_get_id(m_cameraWidget, &id),"gp_widget_get_id"); 159 | 160 | return id; 161 | } 162 | 163 | CameraWidgetWrapper CameraWidgetWrapper::getRoot() const 164 | { 165 | return CameraWidgetWrapper(getRootDefault()); 166 | } 167 | 168 | CameraWidgetWrapper CameraWidgetWrapper::getParent() const 169 | { 170 | return CameraWidgetWrapper(getParentDefault()); 171 | } 172 | 173 | gphoto2::_CameraWidget* CameraWidgetWrapper::getRootDefault() const 174 | { 175 | gphoto2::_CameraWidget* rootWidget = nullptr; 176 | 177 | gphoto2pp::checkResponse(gphoto2::gp_widget_get_root(m_cameraWidget, &rootWidget),"gp_widget_get_root"); 178 | 179 | return rootWidget; 180 | } 181 | 182 | void CameraWidgetWrapper::ref() 183 | { 184 | gphoto2::_CameraWidget* rootWidget = getRootDefault(); 185 | 186 | gphoto2pp::checkResponse(gphoto2::gp_widget_ref(rootWidget),"gp_widget_ref"); 187 | } 188 | 189 | void CameraWidgetWrapper::unref() 190 | { 191 | gphoto2::_CameraWidget* rootWidget = getRootDefault(); 192 | 193 | gphoto2pp::checkResponse(gphoto2::gp_widget_unref(rootWidget),"gp_widget_unref"); 194 | } 195 | 196 | gphoto2::_CameraWidget* CameraWidgetWrapper::getParentDefault() const 197 | { 198 | gphoto2::_CameraWidget* parentWidget = nullptr; 199 | 200 | gphoto2pp::checkResponse(gphoto2::gp_widget_get_parent(m_cameraWidget, &parentWidget),"gp_widget_get_parent"); 201 | 202 | return parentWidget; 203 | } 204 | } 205 | 206 | -------------------------------------------------------------------------------- /examples/example4.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | #include // only for capture method 3 36 | 37 | // This method is only needed for certain canon cameras. I had tested this on a Canon EOS Rebel T2i (shows as Canon EOS 550D) with the boolean set to true and false, and I noticed no difference. So you might need it or you might not depending on what camera you use. 38 | void setCanonCapture(gphoto2pp::CameraWrapper& cameraWrapper, bool capture) 39 | { 40 | try 41 | { 42 | auto captureWidget = cameraWrapper.getConfig().getChildByName("capture"); 43 | captureWidget.setValue(capture ? 1 : 0); 44 | cameraWrapper.setConfig(captureWidget); 45 | } 46 | catch(const std::runtime_error& e) 47 | { 48 | // Swallow the exception 49 | std::cout << "Tried to set canon capture, failed. The camera is probably not a canon" << std::endl; 50 | } 51 | } 52 | 53 | int main(int argc, char* argv[]) { 54 | try 55 | { 56 | std::cout << "#############################" << std::endl; 57 | std::cout << "# connect to camera #" << std::endl; 58 | std::cout << "#############################" << std::endl; 59 | gphoto2pp::CameraWrapper cameraWrapper; // Not passing in model and port will connect to the first available camera. 60 | 61 | setCanonCapture(cameraWrapper, true); 62 | 63 | std::cout << "#############################" << std::endl; 64 | std::cout << "# Capture Method 1 #" << std::endl; 65 | std::cout << "#############################" << std::endl; 66 | std::cout << "Taking first picture..." << std::endl << std::endl; 67 | // Clean and quick capture and save to disk, but this assumes you are taking images, and in jpeg foramt. Adjust type and extension as appropriate. 68 | gphoto2pp::helper::capture(cameraWrapper, "example4_capture_method_2.jpg", true); 69 | 70 | std::cout << "#############################" << std::endl; 71 | std::cout << "# Capture Method 2 #" << std::endl; 72 | std::cout << "#############################" << std::endl; 73 | 74 | 75 | std::cout << "Taking second picture..." << std::endl << std::endl; 76 | gphoto2pp::CameraFileWrapper cameraFileWrapper; 77 | gphoto2pp::helper::capture(cameraWrapper, cameraFileWrapper, true); 78 | 79 | // This is only really needed if your camera is set to take pictures in RAW. 80 | // Because by default the mime type for those is 'application/unknown' 81 | cameraFileWrapper.detectMimeType(); 82 | 83 | std::cout << "FileName (empty by default): "<< cameraFileWrapper.getFileName() << std::endl; 84 | 85 | std::cout << "MimeType: "<< cameraFileWrapper.getMimeType() << std::endl; 86 | 87 | // This will only set the extension for known mime types (application/unknown is not understood, and you should perform detectMimeType before this method) 88 | cameraFileWrapper.adjustNameForMimeType(); 89 | std::cout << "FileName (still empty if the mime type is still unknown): "<< cameraFileWrapper.getFileName() << std::endl; 90 | 91 | // I choose a filename 92 | std::string fileName("example4_capture_method_1a." + cameraFileWrapper.getFileName()); 93 | 94 | // Just for the purpose of demonstration, we will set the extension to something random 95 | // Again, the release notes say that the setFileName and getFileName will be going away, which I understand, 96 | // because it's not until we call the .save(fileName) method, that it's saved to the place with the directory. 97 | cameraFileWrapper.setFileName("TestRandom0293.odf"); 98 | 99 | std::cout << "Delibrately incorrect filename and extension: "<< cameraFileWrapper.getFileName() << std::endl; 100 | 101 | // Should Fix the extension 102 | cameraFileWrapper.adjustNameForMimeType(); 103 | 104 | std::cout << "FileName (proper extension): "<< cameraFileWrapper.getFileName() << std::endl; 105 | 106 | // Now after all that fiddling with filenames, we save the file and use our own filename (haha) 107 | std::cout << "FileName we will save with: "<< fileName << std::endl; 108 | cameraFileWrapper.save(fileName); 109 | 110 | // Now lets take another picture but ignore all of that messing around we did above and just use 4 lines of code instead :) 111 | std::cout << std::endl << "Taking third picture..." << std::endl << std::endl; 112 | //cameraFileWrapper = cameraWrapper.capture(); 113 | gphoto2pp::helper::capture(cameraWrapper, cameraFileWrapper, true); 114 | cameraFileWrapper.detectMimeType(); 115 | cameraFileWrapper.adjustNameForMimeType(); 116 | cameraFileWrapper.save("example4_capture_method_1b."+cameraFileWrapper.getFileName()); 117 | 118 | std::cout << "#############################" << std::endl; 119 | std::cout << "# Capture Method 3 #" << std::endl; 120 | std::cout << "#############################" << std::endl; 121 | std::cout << "Taking fourth picture..." << std::endl << std::endl; 122 | std::fstream f1("example4_capture_method_3.jpg",std::fstream::out|std::fstream::binary|std::fstream::trunc); 123 | gphoto2pp::helper::capture(cameraWrapper,f1, true); 124 | f1.close(); 125 | 126 | } 127 | catch (gphoto2pp::exceptions::gphoto2_exception& e) 128 | { 129 | std::cout << "GPhoto Exception Code: " << e.getResultCode() << std::endl; 130 | std::cout << "Exception Message: " << e.what() << std::endl; 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /include/gphoto2pp/camera_widget_wrapper.hpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #ifndef CAMERAWIDGETWRAPPER_HPP 26 | #define CAMERAWIDGETWRAPPER_HPP 27 | 28 | #include 29 | 30 | namespace gphoto2 31 | { 32 | // Forward declare the gphoto2 struct 33 | struct _CameraWidget; 34 | } 35 | 36 | namespace gphoto2pp 37 | { 38 | enum class CameraWidgetTypeWrapper : int; 39 | 40 | /** 41 | * \class CameraWidgetWrapper 42 | * This class provides a RAII wrapper around the gphoto2 CameraWidget struct. In the gphoto2 the camera's abilities are represented by an N-ary tree. 43 | * 44 | * Gphoto2 has 9 node types. 7 of them compose the leaf nodes of the tree and contian read, or read/write values. 2 of them (window and section) are non value widgets, and represent the internal nodes with 1 or more children. 45 | * 46 | * Every camera abilities tree has Only 1 root node, which is always of type *Window*. Then this can have n children, typically they are *Section* widgets. 47 | * 48 | * Please review the above graphical tree to look at the inheritance hierarchy of the widget types to understand the underlying value they each represent. 49 | * 50 | * | Type | Value | Node Type | 51 | * | ------- |:------:| --------- | 52 | * | Window | N/A | Root | 53 | * | Section | N/A | Non Leaf | 54 | * | Text | string | Leaf | 55 | * | Range | float | Leaf | 56 | * | Toggle | int | Leaf | 57 | * | Radio | string | Leaf | 58 | * | Menu | string | Leaf | 59 | * | Button | N/A | Leaf | 60 | * | Date | time_t | Leaf | 61 | * 62 | */ 63 | class CameraWidgetWrapper 64 | { 65 | public: 66 | virtual ~CameraWidgetWrapper(); 67 | 68 | // Move constructor and move assignment 69 | CameraWidgetWrapper(CameraWidgetWrapper&& other); 70 | CameraWidgetWrapper& operator=(CameraWidgetWrapper&& other); 71 | 72 | // Copy constructor and copy assignment 73 | CameraWidgetWrapper(CameraWidgetWrapper const & other); 74 | CameraWidgetWrapper& operator=(CameraWidgetWrapper const & other); 75 | 76 | /** 77 | * \brief Gets the raw resource 78 | * RAII indicates we still should allow our users access to the RAW Resource and it is applicable. 79 | * \return the gphoto2 CameraWidget struct 80 | */ 81 | gphoto2::_CameraWidget* getPtr() const; 82 | 83 | /** 84 | * \brief Gets the widget's name 85 | * \return the widget name 86 | * \note Direct wrapper for gp_widget_get_name(...) 87 | * \throw GPhoto2pp::exceptions::gphoto2_exception 88 | */ 89 | std::string getName() const; 90 | 91 | /** 92 | * \brief Gets the widget's type 93 | * \return the widget type 94 | * \note Direct wrapper for gp_widget_get_type(...) 95 | * \throw GPhoto2pp::exceptions::gphoto2_exception 96 | */ 97 | CameraWidgetTypeWrapper getType() const; 98 | 99 | /** 100 | * \brief Gets the widget's label 101 | * \return the widget label 102 | * \note Direct wrapper for gp_widget_get_label(...) 103 | * \throw GPhoto2pp::exceptions::gphoto2_exception 104 | */ 105 | std::string getLabel() const; 106 | 107 | /** 108 | * \brief Gets the widget's info 109 | * \return the widget info 110 | * \note Direct wrapper for gp_widget_get_info(...) 111 | * \throw GPhoto2pp::exceptions::gphoto2_exception 112 | */ 113 | std::string getInfo() const; 114 | 115 | /** 116 | * \brief Gets the widget's unique id 117 | * \return the widget's id 118 | * \note Direct wrapper for gp_widget_get_id(...) 119 | * \throw GPhoto2pp::exceptions::gphoto2_exception 120 | */ 121 | int getId() const; 122 | 123 | /** 124 | * \brief Gets the widget's Root. 125 | * This is likely going to be the Window Widget (same widget from ICameraWrapper::getConfig()). 126 | * \return the root widget 127 | * \note Direct wrapper for gp_widget_get_root(...) 128 | * \throw GPhoto2pp::exceptions::gphoto2_exception 129 | */ 130 | CameraWidgetWrapper getRoot() const; 131 | 132 | /** 133 | * \brief Gets the widget's parent. 134 | * This is the immediate parent of the widget. If the current widget is a leaf node, then this is likely a Section Widget, but could also be a Window Widget. 135 | * \return the parent widget 136 | * \note Direct wrapper for gp_widget_get_parent(...) 137 | * \throw GPhoto2pp::exceptions::gphoto2_exception 138 | */ 139 | CameraWidgetWrapper getParent() const; 140 | 141 | protected: 142 | CameraWidgetWrapper(gphoto2::_CameraWidget* cameraWidget); 143 | 144 | /** 145 | * \brief Adds a reference count to the internal gphoto2::CameraWidget struct 146 | * \note Direct wrapper for gp_widget_ref(...) 147 | * \throw GPhoto2pp::exceptions::gphoto2_exception 148 | */ 149 | void ref(); 150 | 151 | /** 152 | * \brief Subtracts a reference count to the internal gphoto2::CameraWidget struct 153 | * \note Direct wrapper for gp_widget_unref(...) 154 | * \throw GPhoto2pp::exceptions::gphoto2_exception 155 | */ 156 | void unref(); 157 | 158 | /** 159 | * \brief Gets the unwrapped CameraWidget struct pointer of the root 160 | * \note Direct wrapper for gp_widget_get_root(...) 161 | * \throw GPhoto2pp::exceptions::gphoto2_exception 162 | */ 163 | gphoto2::_CameraWidget* getRootDefault() const; 164 | 165 | /** 166 | * \brief Gets the unwrapped CameraWidget struct pointer of the parent 167 | * \note Direct wrapper for gp_widget_get_root(...) 168 | * \throw GPhoto2pp::exceptions::gphoto2_exception 169 | */ 170 | gphoto2::_CameraWidget* getParentDefault() const; 171 | 172 | gphoto2::_CameraWidget* m_cameraWidget = nullptr; 173 | }; 174 | 175 | } 176 | 177 | #endif // CAMERAWIDGETWRAPPER_HPP 178 | -------------------------------------------------------------------------------- /examples/example5.cpp: -------------------------------------------------------------------------------- 1 | /** \file 2 | * \author Copyright (c) 2013 maldworth 3 | * 4 | * \note 5 | * This file is part of gphoto2pp 6 | * 7 | * \note 8 | * gphoto2pp is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 3 of the License, or (at your option) any later version. 12 | * 13 | * \note 14 | * gphoto2pp is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * \note 20 | * You should have received a copy of the GNU Lesser General Public 21 | * License along with gphoto2pp. 22 | * If not, see http://www.gnu.org/licenses 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | #include 33 | 34 | // I Recommend you go read my synopsis on widgets first, found here: http://maldworth.github.io/gphoto2pp/classgphoto2pp_1_1_camera_widget_wrapper.html#details 35 | 36 | int main(int argc, char* argv[]) { 37 | try 38 | { 39 | // I've made this example more complicated than it needs to be, but the purpose is to show 40 | // that there are many types of widgets that control the cameras, but for simplicity sake, there 41 | // are really just two methods being used here: 42 | // 1. getAllWidgetsNames(...) 43 | // 2. getAllWidgetsOfType(...) 44 | 45 | gphoto2pp::CameraWrapper cameraWrapper{}; // Not passing in model and port will connect to the first available camera. 46 | auto rootWidget = cameraWrapper.getConfig(); 47 | bool showFullName = false; 48 | 49 | // Good ol lambda expressions 50 | auto getWidgetsOfType = [&](gphoto2pp::CameraWidgetTypeWrapper widgetType) 51 | { 52 | auto allWidgetsOfType = gphoto2pp::helper::getAllWidgetsNamesOfType(rootWidget, widgetType, showFullName); 53 | for(auto it = allWidgetsOfType.begin(); it != allWidgetsOfType.end(); ++it) 54 | { 55 | std::cout << *it << std::endl; 56 | } 57 | }; 58 | 59 | std::string input = ""; 60 | int menuNumber = 0; 61 | do 62 | { 63 | std::cout << std::endl << "#############################" << std::endl; 64 | std::cout << "# Scan Camera Widget Types #" << std::endl; 65 | std::cout << "#############################" << std::endl; 66 | std::cout << "1. Date Widgets" << std::endl; 67 | std::cout << "2. Toggle Widgets" << std::endl; 68 | std::cout << "3. Button Widgets" << std::endl; 69 | std::cout << "4. Range Widgets" << std::endl; 70 | std::cout << "5. Menu Widgets" << std::endl; 71 | std::cout << "6. Radio Widgets" << std::endl; 72 | std::cout << "7. Text Widgets" << std::endl; 73 | std::cout << "8. Section Widgets" << std::endl; 74 | std::cout << "9. All Widgets" << std::endl; 75 | std::cout << "10. Toggle show full widget name (currently = " << std::boolalpha << showFullName << ")" << std::endl; 76 | std::cout << "11. Quit" << std::endl; 77 | std::cout << "Please press a number then hit : "; 78 | std::getline(std::cin, input); 79 | 80 | // Converts from string to number safely 81 | std::stringstream tempStream(input); 82 | if(tempStream >> menuNumber) 83 | { 84 | switch(menuNumber) 85 | { 86 | case 1: // Date Widget 87 | { 88 | std::cout << std::endl << "## Date Widgets ##" << std::endl << std::endl; 89 | getWidgetsOfType(gphoto2pp::CameraWidgetTypeWrapper::Date); 90 | break; 91 | } 92 | case 2: // Toggle Widget 93 | { 94 | std::cout << std::endl << "## Toggle Widgets ##" << std::endl << std::endl; 95 | getWidgetsOfType(gphoto2pp::CameraWidgetTypeWrapper::Toggle); 96 | break; 97 | } 98 | case 3: // Button Widget 99 | { 100 | std::cout << std::endl << "## Button Widgets ##" << std::endl << std::endl; 101 | getWidgetsOfType(gphoto2pp::CameraWidgetTypeWrapper::Button); 102 | break; 103 | } 104 | case 4: // Range Widget 105 | { 106 | std::cout << std::endl << "## Range Widgets ##" << std::endl << std::endl; 107 | getWidgetsOfType(gphoto2pp::CameraWidgetTypeWrapper::Range); 108 | break; 109 | } 110 | case 5: // Menu Widget 111 | { 112 | std::cout << std::endl << "## Menu Widgets ##" << std::endl << std::endl; 113 | getWidgetsOfType(gphoto2pp::CameraWidgetTypeWrapper::Menu); 114 | break; 115 | } 116 | case 6: // Radio Widget 117 | { 118 | std::cout << std::endl << "## Radio Widgets ##" << std::endl << std::endl; 119 | getWidgetsOfType(gphoto2pp::CameraWidgetTypeWrapper::Radio); 120 | break; 121 | } 122 | case 7: // Text Widget 123 | { 124 | std::cout << std::endl << "## Text Widgets ##" << std::endl << std::endl; 125 | getWidgetsOfType(gphoto2pp::CameraWidgetTypeWrapper::Text); 126 | break; 127 | } 128 | case 8: // Section Widget 129 | { 130 | std::cout << std::endl << "## Section Widgets ##" << std::endl << std::endl; 131 | getWidgetsOfType(gphoto2pp::CameraWidgetTypeWrapper::Section); 132 | break; 133 | } 134 | case 9: // All Widgets 135 | { 136 | auto allWidgets = gphoto2pp::helper::getAllWidgetsNames(rootWidget, showFullName); 137 | for(auto widget : allWidgets) 138 | { 139 | std::cout << widget << std::endl; 140 | } 141 | break; 142 | } 143 | case 10: // Toggle showing full name 144 | { 145 | showFullName = !showFullName; 146 | std::cout << std::endl << "Full widget name " << (showFullName ? "WILL" : "will NOT") << " be visible" << std::endl << std::endl; 147 | break; 148 | } 149 | default: 150 | case 11: // Quit 151 | { 152 | std::cout << std::endl << "Exiting" << std::endl; 153 | break; 154 | } 155 | } 156 | } 157 | else 158 | { 159 | // They didn't input a number 160 | std::cout << std::endl << "Invalid entry, please input a number" << std::endl; 161 | menuNumber = -1; 162 | } 163 | }while(menuNumber != 11); 164 | } 165 | catch (gphoto2pp::exceptions::gphoto2_exception& e) 166 | { 167 | std::cout << "GPhoto Exception Code: " << e.getResultCode() << std::endl; 168 | std::cout << "Exception Message: " << e.what() << std::endl; 169 | } 170 | } 171 | --------------------------------------------------------------------------------