my testcase for testing aria reports
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Tue, 3 Mar 2009 10:34:29 +0000 (11:34 +0100)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Tue, 3 Mar 2009 10:34:29 +0000 (11:34 +0100)
devel/devel.dmacvicar/CMakeLists.txt
devel/devel.dmacvicar/getfile.cc [new file with mode: 0644]

index f9efa10..88607e6 100644 (file)
@@ -6,6 +6,9 @@ TARGET_LINK_LIBRARIES(rpmbuilder  zypp )
 ADD_EXECUTABLE(testbed testbed.cc)
 TARGET_LINK_LIBRARIES(testbed  zypp )
 
+ADD_EXECUTABLE(getfile getfile.cc)
+TARGET_LINK_LIBRARIES(getfile  zypp )
+
 FIND_PACKAGE(Zsync)
 IF(ZSYNC_FOUND)
   ADD_EXECUTABLE(zsync zsync.cc)
diff --git a/devel/devel.dmacvicar/getfile.cc b/devel/devel.dmacvicar/getfile.cc
new file mode 100644 (file)
index 0000000..0eeb37f
--- /dev/null
@@ -0,0 +1,106 @@
+#include <sys/time.h>
+
+#include <iostream>
+#include <fstream>
+
+#include <zypp/base/Logger.h>
+#include <zypp/ZYpp.h>
+#include <zypp/ZYppFactory.h>
+
+#include "zypp/Product.h"
+#include "zypp/Package.h"
+#include "zypp/Fetcher.h"
+#include "zypp/TmpPath.h"
+#include "zypp/ProgressData.h"
+
+#include "zypp/sat/Pool.h"
+
+#include "zypp/ZYppCallbacks.h"
+
+using namespace std;
+using namespace zypp;
+using namespace zypp::repo;
+using zypp::media::MediaChangeReport;
+using zypp::media::DownloadProgressReport;
+
+
+bool result_cb( const ResObject::Ptr &r )
+{
+  cout << r << endl;
+}
+
+struct MediaChangeReportReceiver : public zypp::callback::ReceiveReport<MediaChangeReport>
+  {
+    virtual MediaChangeReport::Action
+    requestMedia(zypp::Url & url,
+                 unsigned                         mediumNr,
+                 const std::string &              label,
+                 MediaChangeReport::Error         error,
+                 const std::string &              description,
+                 const std::vector<std::string> & devices,
+                 unsigned int &                   index)
+    {
+      cout << std::endl;
+      MIL << "media problem, url: " << url.asString() << std::endl;
+      return MediaChangeReport::IGNORE;
+    }
+  };
+
+struct DownloadProgressReportReceiver : public zypp::callback::ReceiveReport<DownloadProgressReport>
+{
+
+    virtual void start( const Url &/*file*/, Pathname /*localfile*/ )
+    {
+    }
+    
+    virtual bool progress(int value, const Url &file,
+                          double dbps_avg,
+                          double dbps_current)
+    { 
+        cout << file << " " << value << "% speed:" << dbps_current << " avg:" << dbps_avg << endl;
+        return true; 
+    }
+    
+    virtual Action problem( const Url &/*file*/
+                            , Error /*error*/
+                            , const std::string &/*description*/ ) { return ABORT; }
+    
+    virtual void finish(
+        const Url &/*file*/
+        , Error /*error*/
+        , const std::string &/*reason*/
+        ) {}
+};
+
+int main(int argc, char **argv)
+{
+    try
+    {
+      ZYpp::Ptr z = getZYpp();
+    
+      MediaChangeReportReceiver change_report;
+      DownloadProgressReportReceiver progress_report;
+      change_report.connect();
+      progress_report.connect();
+      
+      MediaSetAccess access(Url("http://download.opensuse.org/update/11.1/rpm/x86_64"));
+      OnMediaLocation loc;
+      loc.setLocation("java-1_5_0-sun-1.5.0_update17-1.1.x86_64.rpm");
+      //loc.setOptional(true);
+
+      Fetcher fetcher;
+      fetcher.enqueue(loc);
+      fetcher.start("./", access);
+      
+    }
+    catch ( const Exception &e )
+    {
+      ZYPP_CAUGHT(e);
+      cout << e.msg() << endl;
+    }
+    
+    return 0;
+}
+
+
+