[vlmc-devel] [PATCH 2/3] Added libcurlpp dependency.

Paweł Wegner pawel.wegner95 at gmail.com
Wed May 4 22:25:11 CEST 2016


---
 configure.ac          |  4 +++-
 src/GoogleDrive.cpp   | 27 +++++++++++++++++++++++++++
 src/GoogleDrive.h     | 18 ++++++++++++++++++
 src/ICloudStorage.cpp | 14 +++++++++++++-
 src/ICloudStorage.h   | 14 +++++++++++++-
 src/Makefile.am       |  9 ++++++++-
 test/Makefile.am      |  2 +-
 test/main.cpp         |  4 ++--
 8 files changed, 85 insertions(+), 7 deletions(-)
 create mode 100644 src/GoogleDrive.cpp
 create mode 100644 src/GoogleDrive.h

diff --git a/configure.ac b/configure.ac
index 7c07e14..b152a82 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4,9 +4,11 @@ AC_CONFIG_MACRO_DIRS([m4])
 LT_INIT
 
 AC_PROG_CXX
-
 AX_CXX_COMPILE_STDCXX_11
 
+PKG_CHECK_MODULES([libcurlpp], [curlpp], [have_libcurlpp=yes], [have_libcurlpp=no])
+AM_CONDITIONAL([libcurlpp], [test "$have_libcurlpp" = "yes"])
+
 AC_CONFIG_FILES([
   Makefile
   src/Makefile
diff --git a/src/GoogleDrive.cpp b/src/GoogleDrive.cpp
new file mode 100644
index 0000000..f2ac437
--- /dev/null
+++ b/src/GoogleDrive.cpp
@@ -0,0 +1,27 @@
+#include "GoogleDrive.h"
+
+#include <curlpp/Easy.hpp>
+#include <curlpp/Options.hpp>
+#include <sstream>
+
+using namespace curlpp::options;
+
+namespace cloudstorage {
+
+GoogleDrive::GoogleDrive() {
+  curlpp::Easy request;
+  std::stringstream stream;
+  curlpp::options::WriteStream ws(&stream);
+  request.setOpt<Url>("https://www.googleapis.com/auth/drive");
+  request.setOpt(ws);
+  request.perform();
+  assert(stream.str() == "drive");
+}
+
+// TODO
+std::vector<ICloudStorage::File> GoogleDrive::listDirectory(
+    const std::string& path) const {
+  return {};
+}
+
+}  // namespace cloudstorage
diff --git a/src/GoogleDrive.h b/src/GoogleDrive.h
new file mode 100644
index 0000000..255f4e6
--- /dev/null
+++ b/src/GoogleDrive.h
@@ -0,0 +1,18 @@
+#ifndef GOOGLEDRIVE_H
+#define GOOGLEDRIVE_H
+
+#include "ICloudStorage.h"
+
+namespace cloudstorage {
+
+class GoogleDrive : public ICloudStorage {
+ public:
+  GoogleDrive();
+
+  std::vector<File> listDirectory(const std::string& path) const;
+ private:
+};
+
+}  // namespace cloudstorage
+
+#endif
diff --git a/src/ICloudStorage.cpp b/src/ICloudStorage.cpp
index 4296881..cd1cd6b 100644
--- a/src/ICloudStorage.cpp
+++ b/src/ICloudStorage.cpp
@@ -1,7 +1,19 @@
 #include "ICloudStorage.h"
 
+#include <curlpp/cURLpp.hpp>
+
 namespace cloudstorage {
 
-ICloudStorage::ICloudStorage() {}
+int ICloudStorage::storage_count_;
+
+ICloudStorage::ICloudStorage() {
+  if (storage_count_ == 0) curlpp::initialize();
+  storage_count_++;
+}
+
+ICloudStorage::~ICloudStorage() {
+  storage_count_--;
+  if (storage_count_ == 0) curlpp::terminate();
+}
 
 };  //  namespace cloudstorage
diff --git a/src/ICloudStorage.h b/src/ICloudStorage.h
index 19a537b..d4407fe 100644
--- a/src/ICloudStorage.h
+++ b/src/ICloudStorage.h
@@ -1,14 +1,26 @@
 #ifndef ICLOUDSTORAGE_H
 #define ICLOUDSTORAGE_H
 
+#include <string>
+#include <vector>
+
 namespace cloudstorage {
 
 class ICloudStorage {
  public:
+  struct File {
+    std::string filename_;
+    bool is_directory_;
+  };
+
   ICloudStorage();
-  virtual ~ICloudStorage() = default;
+  virtual ~ICloudStorage();
+
+  virtual std::vector<File> listDirectory(const std::string& path) const = 0;
 
  private:
+
+  static int storage_count_;
 };
 
 }  //  namespace cloudstorage
diff --git a/src/Makefile.am b/src/Makefile.am
index 6c59c77..7b7b8aa 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,11 @@
 ACLOCAL_AMFLAGS = -I m4
 
+AM_CXXFLAGS = $(libcurlpp_CXXFLAGS)
+
 lib_LTLIBRARIES = libcloudstorage.la
-libcloudstorage_la_SOURCES = ICloudStorage.cpp
+libcloudstorage_la_SOURCES = \
+	ICloudStorage.cpp ICloudStorage.h \
+	GoogleDrive.cpp GoogleDrive.h
+
+libcloudstorage_la_LIBADD = $(libcurlpp_LIBS)
+
diff --git a/test/Makefile.am b/test/Makefile.am
index 12980db..be324ef 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,6 +1,6 @@
 ACLOCAL_AMFLAGS = -I m4
 
-AM_LDFLAGS = $(top_srcdir)/src/libcloudstorage.la
+AM_LDFLAGS =  $(top_srcdir)/src/libcloudstorage.la
 AM_CXXFLAGS = -I$(top_srcdir)/src
 
 check_PROGRAMS = main
diff --git a/test/main.cpp b/test/main.cpp
index e75b175..c31ac52 100644
--- a/test/main.cpp
+++ b/test/main.cpp
@@ -1,6 +1,6 @@
-#include <ICloudStorage.h>
+#include <GoogleDrive.h>
 
 int main() {
-  cloudstorage::ICloudStorage obj;
+  cloudstorage::GoogleDrive gdrive;
   return 0;
 }
-- 
2.7.4



More information about the Vlmc-devel mailing list