[niepce] [niepce] Gphoto utils. Now depends on libgphoto2.
- From: Hubert Figuière <hub src gnome org>
- To: svn-commits-list gnome org
- Subject: [niepce] [niepce] Gphoto utils. Now depends on libgphoto2.
- Date: Sat, 23 May 2009 03:30:35 -0400 (EDT)
commit 9986351693abe4d2e25a8adfc6154eadbae15eca
Author: Hubert Figuiere <hub figuiere net>
Date: Fri May 22 03:03:49 2009 -0400
[niepce] Gphoto utils. Now depends on libgphoto2.
[niepce] Singleton class.
---
ChangeLog | 11 ++++
README | 1 +
configure.ac | 2 +
src/fwk/Makefile.am | 1 +
src/fwk/base/singleton.hpp | 44 ++++++++++++++++++
src/fwk/utils/Makefile.am | 3 +-
src/fwk/utils/gphoto.cpp | 109 ++++++++++++++++++++++++++++++++++++++++++++
src/fwk/utils/gphoto.hpp | 85 ++++++++++++++++++++++++++++++++++
8 files changed, 255 insertions(+), 1 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 216d02f..29e0ed3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2009-05-22 Hubert Figuiere <hub figuiere net>
+
+ * src/fwk/utils/gphoto.{hpp,cpp}:
+ * src/fwk/utils/Makefile.am:
+ * configure.ac
+ * README
+ Gphoto utils. Now depends on libgphoto2.
+
+ * src/fwk/base/singleton.hpp
+ Singleton class.
+
2009-05-21 Hubert Figuiere <hub figuiere net>
* src/fwk/toolkit/frame.{hpp,cpp}
diff --git a/README b/README
index 539157c..480249e 100644
--- a/README
+++ b/README
@@ -37,6 +37,7 @@ libopenraw >= 0.0.5
geglmm >= 0.0.22
gegl >= 0.0.22
babl
+libgphoto2
Niepce is being developed on Linux. It should build and work on other
UNIX systems.
diff --git a/configure.ac b/configure.ac
index ec39be3..ad3ba09 100644
--- a/configure.ac
+++ b/configure.ac
@@ -28,6 +28,7 @@ SQLITE_VERSION=3.0
GEGL_VERSION=0.0.22
GEGLMM_VERSION=0.0.22
LIBOPENRAW_VERSION=0.0.5
+LIBGPHOTO_VERSION=2.4
dnl need at least 2.5.0 because of xmlTextReader
LIBXML2_VERSION=2.5.0
BOOST_VERSION=1.34
@@ -71,6 +72,7 @@ PKG_CHECK_MODULES(SQLITE3, [sqlite3 >= $SQLITE_VERSION])
PKG_CHECK_MODULES(EXEMPI, [exempi-2.0 >= $EXEMPI_VERSION])
PKG_CHECK_MODULES(LIBXML2, [libxml-2.0 >= $LIBXML2_VERSION])
PKG_CHECK_MODULES(BABL, babl)
+PKG_CHECK_MODULES(GPHOTO, [libgphoto2 >= $LIBGPHOTO_VERSION libgphoto2_port])
PKG_CHECK_MODULES(OPENRAW, libopenraw-gnome-1.0 >= $LIBOPENRAW_VERSION)
AC_SUBST(OPENRAW_CFLAGS)
diff --git a/src/fwk/Makefile.am b/src/fwk/Makefile.am
index 077b96d..4dfe978 100644
--- a/src/fwk/Makefile.am
+++ b/src/fwk/Makefile.am
@@ -25,4 +25,5 @@ libfwk_a_SOURCES = base/color.hpp base/color.cpp \
base/fractions.hpp base/fractions.cpp \
base/moniker.hpp base/moniker.cpp \
base/geometry.hpp base/geometry.cpp \
+ base/singleton.hpp
$(NULL)
\ No newline at end of file
diff --git a/src/fwk/base/singleton.hpp b/src/fwk/base/singleton.hpp
new file mode 100644
index 0000000..4120f24
--- /dev/null
+++ b/src/fwk/base/singleton.hpp
@@ -0,0 +1,44 @@
+/*
+ * niepce - fwk/base/singleton.hpp
+ *
+ * Copyright (C) 2009 Hubert Figuiere
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __BASE_SINGLETON_HPP__
+#define __BASE_SINGLETON_HPP__
+
+
+namespace fwk {
+
+
+ template <class _Type>
+ class Singleton
+ {
+ public:
+ static _Type & obj()
+ {
+ // TODO make this thread safe;
+ static _Type * instance = new _Type();
+ return *instance;
+ }
+
+ };
+
+}
+
+
+#endif
diff --git a/src/fwk/utils/Makefile.am b/src/fwk/utils/Makefile.am
index 48f8b12..5224513 100644
--- a/src/fwk/utils/Makefile.am
+++ b/src/fwk/utils/Makefile.am
@@ -2,7 +2,7 @@
DIST_SUBDIRS = db
INCLUDES = -I$(top_srcdir)/src/ @LIBGLIBMM_CFLAGS@ \
- @EXEMPI_CFLAGS@ @LIBXML2_CFLAGS@
+ @EXEMPI_CFLAGS@ @LIBXML2_CFLAGS@ @GPHOTO_CFLAGS@
TESTS = testfiles testxmp \
testpathutils \
@@ -77,6 +77,7 @@ libniepceutils_a_SOURCES = \
buffer.hpp logstreamutils.hpp \
boost.hpp \
files.hpp files.cpp \
+ gphoto.hpp gphoto.cpp \
thread.hpp thread.cpp worker.hpp \
pathutils.hpp pathutils.cpp \
databinder.hpp databinder.cpp \
diff --git a/src/fwk/utils/gphoto.cpp b/src/fwk/utils/gphoto.cpp
new file mode 100644
index 0000000..8164173
--- /dev/null
+++ b/src/fwk/utils/gphoto.cpp
@@ -0,0 +1,109 @@
+/*
+ * niepce - fwk/utils/gphoto.cpp
+ *
+ * Copyright (C) 2009 Hubert Figuiere
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <string.h>
+
+extern "C" {
+#include <gphoto2-port-result.h>
+}
+
+#include "fwk/base/debug.hpp"
+#include "gphoto.hpp"
+
+
+namespace fwk {
+
+
+#define GP_CHECK(x,op) if (x < GP_OK) { \
+ DBG_OUT("%s failed with %d",#op,x); }
+
+
+GpDeviceList::GpDeviceList()
+ : m_abilities(NULL)
+ , m_ports(NULL)
+{
+ reload();
+}
+
+GpDeviceList::~GpDeviceList()
+{
+ _gp_cleanup();
+}
+
+
+void GpDeviceList::_gp_cleanup()
+{
+ if (m_abilities) {
+ ::gp_abilities_list_free(m_abilities);
+ m_abilities = NULL;
+ }
+ if (m_ports) {
+ ::gp_port_info_list_free(m_ports);
+ m_ports = NULL;
+ }
+}
+
+void GpDeviceList::reload()
+{
+ _gp_cleanup();
+
+ int ret;
+ ret = ::gp_port_info_list_new(&m_ports);
+ GP_CHECK(ret, gp_port_info_list_new);
+ ret = ::gp_port_info_list_load(m_ports);
+ GP_CHECK(ret, gp_port_list_load);
+ ret = ::gp_abilities_list_new(&m_abilities);
+ GP_CHECK(ret, gp_abilities_list_new);
+ ret = ::gp_abilities_list_load(m_abilities, NULL);
+ GP_CHECK(ret, gp_abilities_list_load);
+}
+
+
+void GpDeviceList::detect()
+{
+ if((!m_ports) || (!m_abilities)) {
+ reload();
+ }
+ ::CameraList *cameraList;
+ int ret;
+
+ ret = ::gp_list_new(&cameraList);
+ GP_CHECK(ret, gp_list_new);
+ ret = ::gp_abilities_list_detect(m_abilities, m_ports, cameraList, NULL);
+ GP_CHECK(ret, gp_abilities_list_detect);
+
+ int count = ::gp_list_count(cameraList);
+ for (int i = 0; i < count; i++) {
+ const char * name;
+ const char * value;
+ ret = ::gp_list_get_name(cameraList, i, &name);
+ GP_CHECK(ret, gp_list_get_name);
+ ret = ::gp_list_get_value(cameraList, i, &value);
+ GP_CHECK(ret, gp_list_get_value);
+ if ((count > 1) && (strcmp(value, "usb:") == 0)) {
+ continue;
+ }
+ DBG_OUT("found %s %s", name, value);
+ push_back(GpDevice::Ptr(new GpDevice(name,value)));
+ }
+ ::gp_list_free(cameraList);
+}
+
+
+}
diff --git a/src/fwk/utils/gphoto.hpp b/src/fwk/utils/gphoto.hpp
new file mode 100644
index 0000000..d199d14
--- /dev/null
+++ b/src/fwk/utils/gphoto.hpp
@@ -0,0 +1,85 @@
+/*
+ * niepce - fwk/utils/gphoto.cpp
+ *
+ * Copyright (C) 2009 Hubert Figuiere
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __FWK_GPHOTO_HPP_
+#define __FWK_GPHOTO_HPP_
+
+#include <list>
+#include <string>
+#include <tr1/memory>
+
+#include <boost/noncopyable.hpp>
+
+extern "C" {
+#include <gphoto2-port-info-list.h>
+#include <gphoto2-abilities-list.h>
+}
+
+#include "fwk/base/singleton.hpp"
+
+namespace fwk {
+
+class GpDevice
+ : public boost::noncopyable
+{
+public:
+ typedef std::tr1::shared_ptr<GpDevice> Ptr;
+
+ GpDevice(const std::string & m_model, const std::string & m_path);
+
+private:
+ std::string m_model;
+ std::string m_path;
+};
+
+
+
+class GpDeviceList
+ : public fwk::Singleton<GpDeviceList>
+ , private std::list<GpDevice::Ptr>
+{
+public:
+ ~GpDeviceList();
+
+ void reload();
+ void detect();
+private:
+ GpDeviceList();
+
+ void _gp_cleanup();
+ ::CameraAbilitiesList *m_abilities;
+ ::GPPortInfoList *m_ports;
+};
+
+
+
+class GpCamera
+{
+public:
+ GpCamera(const GpDevice::Ptr & device);
+
+private:
+ GpDevice::Ptr m_device;
+};
+
+}
+
+
+#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]