From: Duncan Mac-Vicar P Date: Tue, 3 Mar 2009 10:34:29 +0000 (+0100) Subject: my testcase for testing aria reports X-Git-Tag: 6.6.0~40^2~44 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fupstream%2Flibzypp.git;a=commitdiff_plain;h=adc20a8d22f6beb59a63ba0063c95f9d49aecb5e my testcase for testing aria reports --- diff --git a/devel/devel.dmacvicar/CMakeLists.txt b/devel/devel.dmacvicar/CMakeLists.txt index f9efa10..88607e6 100644 --- a/devel/devel.dmacvicar/CMakeLists.txt +++ b/devel/devel.dmacvicar/CMakeLists.txt @@ -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 index 0000000..0eeb37f --- /dev/null +++ b/devel/devel.dmacvicar/getfile.cc @@ -0,0 +1,106 @@ +#include + +#include +#include + +#include +#include +#include + +#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 + { + virtual MediaChangeReport::Action + requestMedia(zypp::Url & url, + unsigned mediumNr, + const std::string & label, + MediaChangeReport::Error error, + const std::string & description, + const std::vector & devices, + unsigned int & index) + { + cout << std::endl; + MIL << "media problem, url: " << url.asString() << std::endl; + return MediaChangeReport::IGNORE; + } + }; + +struct DownloadProgressReportReceiver : public zypp::callback::ReceiveReport +{ + + 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; +} + + +