yast2-storage

OutputProcessor.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) [2004-2009] Novell, Inc.
00003  *
00004  * All Rights Reserved.
00005  *
00006  * This program is free software; you can redistribute it and/or modify it
00007  * under the terms of version 2 of the GNU General Public License as published
00008  * by the Free Software Foundation.
00009  *
00010  * This program is distributed in the hope that it will be useful, but WITHOUT
00011  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
00013  * more details.
00014  *
00015  * You should have received a copy of the GNU General Public License along
00016  * with this program; if not, contact Novell, Inc.
00017  *
00018  * To contact Novell about this file by physical or electronic mail, you may
00019  * find current contact information at www.novell.com.
00020  */
00021 
00022 
00023 #ifndef OUTPUT_PROCESSOR_H
00024 #define OUTPUT_PROCESSOR_H
00025 
00026 
00027 #include "storage/StorageInterface.h"
00028 
00029 
00030 namespace storage
00031 {
00032 
00033     class OutputProcessor
00034     {
00035     public:
00036         OutputProcessor() {}
00037         virtual ~OutputProcessor() {}
00038         virtual void reset() = 0;
00039         virtual void finish() = 0;
00040         virtual void process(const string& txt, bool stderr) = 0;
00041     };
00042 
00043 
00044     class ProgressBar : public OutputProcessor
00045     {
00046     public:
00047         ProgressBar(const string& id, CallbackProgressBar callback)
00048             : id(id), callback(callback), first(true), max(100), cur(0)
00049         {}
00050 
00051         virtual ~ProgressBar() {}
00052 
00053         virtual void reset() { first = true; cur = 0; }
00054         virtual void finish() { setCurValue(max); }
00055         virtual void process(const string& txt, bool stderr) {}
00056 
00057         void setMaxValue(unsigned val) { max = val; }
00058         unsigned getMaxValue() const { return max; }
00059         void setCurValue(unsigned val);
00060         unsigned getCurValue() const { return cur; }
00061 
00062     protected:
00063         const string id;
00064         const CallbackProgressBar callback;
00065 
00066         bool first;
00067 
00068     private:
00069         unsigned long max;
00070         unsigned long cur;
00071     };
00072 
00073 
00074     class Mke2fsProgressBar : public ProgressBar
00075     {
00076     public:
00077         Mke2fsProgressBar(CallbackProgressBar callback)
00078             : ProgressBar("format", callback)
00079         {
00080             setMaxValue(100);
00081             done = false;
00082         }
00083 
00084         virtual void process(const string& txt, bool stderr);
00085 
00086     protected:
00087         string seen;
00088         bool done;
00089     };
00090 
00091 
00092     class ReiserProgressBar : public ProgressBar
00093     {
00094     public:
00095         ReiserProgressBar(CallbackProgressBar callback)
00096             : ProgressBar("format", callback)
00097         {
00098             setMaxValue(100);
00099         }
00100 
00101         virtual void process(const string& txt, bool stderr);
00102 
00103     protected:
00104         string seen;
00105     };
00106 
00107 
00108     class DasdfmtProgressBar : public ProgressBar
00109     {
00110     public:
00111         DasdfmtProgressBar(CallbackProgressBar callback)
00112             : ProgressBar("dasdfmt", callback)
00113         {
00114             setMaxValue(100);
00115             max_cyl = cur_cyl = 0;
00116         }
00117 
00118         virtual void process(const string& txt, bool stderr);
00119 
00120     protected:
00121         string seen;
00122         unsigned long max_cyl;
00123         unsigned long cur_cyl;
00124     };
00125 
00126 }
00127 
00128 
00129 #endif