f0ebf040fdeefea2bc54c89e5f62cbd4b8083de9
[platform/upstream/libzypp.git] / devel / devel.dmacvicar / testbed.cc
1 #include <sys/time.h>
2
3 #include <iostream>
4 #include <fstream>
5
6 #include <zypp/base/Logger.h>
7 #include <zypp/ZYpp.h>
8 #include <zypp/ZYppFactory.h>
9
10 #include "zypp/Product.h"
11 #include "zypp/Package.h"
12 #include "zypp/Fetcher.h"
13 #include "zypp/TmpPath.h"
14 #include "zypp/ProgressData.h"
15
16 #include "zypp/sat/Pool.h"
17
18 #include "zypp/ZYppCallbacks.h"
19
20 using namespace std;
21 using namespace zypp;
22 using namespace zypp::repo;
23 using zypp::media::MediaChangeReport;
24
25
26 bool result_cb( const ResObject::Ptr &r )
27 {
28   cout << r << endl;
29 }
30
31 struct MediaChangeReportReceiver : public zypp::callback::ReceiveReport<MediaChangeReport>
32   {
33     virtual MediaChangeReport::Action
34     requestMedia(zypp::Url & url,
35                  unsigned                         mediumNr,
36                  const std::string &              label,
37                  MediaChangeReport::Error         error,
38                  const std::string &              description,
39                  const std::vector<std::string> & devices,
40                  unsigned int &                   index)
41     {
42       cout << std::endl;
43       MIL << "media problem, url: " << url.asString() << std::endl;
44       return MediaChangeReport::IGNORE;
45     }
46   };
47
48
49 int main(int argc, char **argv)
50 {
51     try
52     {
53       ZYpp::Ptr z = getZYpp();
54     
55       MediaChangeReportReceiver report;
56       report.connect();
57       
58
59       Fetcher fetcher;
60       MediaSetAccess access(Url("http://ftp.kernel.org/pub"));
61       filesystem::TmpDir tmp;
62       
63       OnMediaLocation loc;
64       loc.setLocation("/README2");
65       loc.setOptional(true);
66       
67       fetcher.enqueue(loc);
68       fetcher.start(tmp.path(), access);
69       
70     }
71     catch ( const Exception &e )
72     {
73       ZYPP_CAUGHT(e);
74       cout << e.msg() << endl;
75     }
76     
77     return 0;
78 }
79
80
81