libzypp  11.13.5
Callback.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_CALLBACK_H
13 #define ZYPP_CALLBACK_H
14 
15 #include "zypp/base/NonCopyable.h"
16 
18 namespace zypp
19 {
20 
22  namespace HACK {
23  class Callback
24  {
25  };
26  } // namespace HACK
27 
29 
129  namespace callback
130  {
131 
133  struct ReportBase
134  {
135  virtual ~ReportBase()
136  {}
137  };
138 
140  template<class _Report>
141  class DistributeReport;
142 
144  template<class _Report>
145  struct ReceiveReport : public _Report
146  {
150 
151  virtual ~ReceiveReport()
152  { disconnect(); }
153 
155  { return Distributor::instance().getReceiver(); }
156 
157  bool connected() const
158  { return whoIsConnected() == this; }
159 
160  void connect()
161  { Distributor::instance().setReceiver( *this ); }
162 
163  void disconnect()
164  { Distributor::instance().unsetReceiver( *this ); }
165 
166  virtual void reportbegin()
167  {}
168  virtual void reportend()
169  {}
170  };
171 
173  template<class _Report>
175  {
176  public:
180 
182  {
183  static DistributeReport _self;
184  return _self;
185  }
186 
188  { return _receiver == &_noReceiver ? 0 : _receiver; }
189 
190  void setReceiver( Receiver & rec_r )
191  { _receiver = &rec_r; }
192 
193  void unsetReceiver( Receiver & rec_r )
194  { if ( _receiver == &rec_r ) noReceiver(); }
195 
196  void noReceiver()
197  { _receiver = &_noReceiver; }
198 
199  public:
201  { return _receiver; }
202 
203  private:
205  : _receiver( &_noReceiver )
206  {}
209  };
210 
212  template<class _Report>
214  {
218 
220  { Distributor::instance()->reportbegin(); }
221 
223  { Distributor::instance()->reportend(); }
224 
226  { return Distributor::instance(); }
227  };
228 
254  template<class _Report>
255  struct TempConnect
256  {
260 
262  : _oldRec( Distributor::instance().getReceiver() )
263  {
265  }
266 
268  : _oldRec( Distributor::instance().getReceiver() )
269  {
270  rec_r.connect();
271  }
272 
274  {
275  if ( _oldRec )
277  else
279  }
280  private:
282  };
283 
285  } // namespace callback
288 } // namespace zypp
290 #endif // ZYPP_CALLBACK_H