more callbacks and add commit
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 8 Sep 2006 10:33:30 +0000 (10:33 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 8 Sep 2006 10:33:30 +0000 (10:33 +0000)
tools/zmart/zmart-media-callbacks.h [new file with mode: 0644]

diff --git a/tools/zmart/zmart-media-callbacks.h b/tools/zmart/zmart-media-callbacks.h
new file mode 100644 (file)
index 0000000..c67d351
--- /dev/null
@@ -0,0 +1,78 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+
+#ifndef ZMART_MEDIA_CALLBACKS_H
+#define ZMART_MEDIA_CALLBACKS_H
+
+#include <stdlib.h>
+#include <iostream>
+
+#include <zypp/base/Logger.h>
+#include <zypp/ZYppCallbacks.h>
+#include <zypp/Pathname.h>
+#include <zypp/KeyRing.h>
+#include <zypp/Digest.h>
+#include <zypp/Url.h>
+#include <zypp/Source.h>
+
+#include "AliveCursor.h"
+
+using zypp::media::MediaChangeReport;
+using zypp::media::DownloadProgressReport;
+
+///////////////////////////////////////////////////////////////////
+namespace ZmartRecipients
+{
+
+  struct MediaChangeReportReceiver : public zypp::callback::ReceiveReport<MediaChangeReport>
+  {
+    virtual MediaChangeReport::Action requestMedia( const zypp::Source_Ref source, unsigned mediumNr, MediaChangeReport::Error error, std::string description )
+    { return MediaChangeReport::ABORT; }
+  };
+
+    // progress for downloading a file
+  struct DownloadProgressReportReceiver : public zypp::callback::ReceiveReport<zypp::media::DownloadProgressReport>
+  {
+    virtual void start( const zypp::Url &file, zypp::Pathname localfile )
+    {}
+
+    virtual bool progress(int value, const zypp::Url &file)
+    { return true; }
+
+    virtual DownloadProgressReport::Action problem( const zypp::Url &file, DownloadProgressReport::Error error, std::string description )
+    { return DownloadProgressReport::ABORT; }
+
+    virtual void finish( const zypp::Url &file, Error error, std::string reason )
+    {}
+  };
+  
+    ///////////////////////////////////////////////////////////////////
+}; // namespace ZmartRecipients
+///////////////////////////////////////////////////////////////////
+
+class MediaCallbacks {
+
+  private:
+    ZmartRecipients::MediaChangeReportReceiver _mediaChangeReport;
+    ZmartRecipients::DownloadProgressReportReceiver _mediaDownloadReport;
+  public:
+    MediaCallbacks()
+    {
+      _mediaChangeReport.connect();
+      _mediaDownloadReport.connect();
+    }
+
+    ~MediaCallbacks()
+    {
+      _mediaChangeReport.disconnect();
+      _mediaDownloadReport.disconnect();
+    }
+};
+
+#endif