libzypp  17.16.0
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 #include "zypp/UserData.h"
17 
19 namespace zypp
20 {
21 
23  namespace HACK {
24  class Callback
25  {
26  };
27  } // namespace HACK
28 
30 
145  namespace callback
146  {
147 
149  struct ReportBase
150  {
153 
155  virtual void report( const UserData & userData_r = UserData() )
156  {}
157 
158  virtual ~ReportBase()
159  {}
160  };
161 
163  template<class TReport>
165 
167  template<class TReport>
168  struct ReceiveReport : public TReport
169  {
173 
174  virtual ~ReceiveReport()
175  { disconnect(); }
176 
178  { return Distributor::instance().getReceiver(); }
179 
180  bool connected() const
181  { return whoIsConnected() == this; }
182 
183  void connect()
184  { Distributor::instance().setReceiver( *this ); }
185 
186  void disconnect()
187  { Distributor::instance().unsetReceiver( *this ); }
188 
189  virtual void reportbegin()
190  {}
191  virtual void reportend()
192  {}
193  };
194 
196  template<class TReport>
197  struct DistributeReport
198  {
199  public:
203 
205  {
206  static DistributeReport _self;
207  return _self;
208  }
209 
211  { return _receiver == &_noReceiver ? 0 : _receiver; }
212 
213  void setReceiver( Receiver & rec_r )
214  { _receiver = &rec_r; }
215 
216  void unsetReceiver( Receiver & rec_r )
217  { if ( _receiver == &rec_r ) noReceiver(); }
218 
219  void noReceiver()
220  { _receiver = &_noReceiver; }
221 
222  public:
224  { return _receiver; }
225 
226  private:
228  : _receiver( &_noReceiver )
229  {}
232  };
233 
235  template<class TReport>
237  {
241 
243  { Distributor::instance()->reportbegin(); }
244 
246  { Distributor::instance()->reportend(); }
247 
249  { return Distributor::instance().getReceiver(); }
250 
251  static bool connected()
252  { return whoIsConnected(); }
253 
255  { return Distributor::instance(); }
256  };
257 
283  template<class TReport>
284  struct TempConnect
285  {
289 
291  : _oldRec( Distributor::instance().getReceiver() )
292  {
294  }
295 
297  : _oldRec( Distributor::instance().getReceiver() )
298  {
299  rec_r.connect();
300  }
301 
303  {
304  if ( _oldRec )
306  else
308  }
309  private:
311  };
312 
314  } // namespace callback
317 } // namespace zypp
319 #endif // ZYPP_CALLBACK_H
ReceiveReport< TReport > Receiver
Definition: Callback.h:239
void setReceiver(Receiver &rec_r)
Definition: Callback.h:213
ReceiveReport< TReport > Receiver
Definition: Callback.h:287
DistributeReport< TReport > Distributor
Definition: Callback.h:202
DistributeReport< TReport > Distributor
Definition: Callback.h:288
TempConnect(Receiver &rec_r)
Definition: Callback.h:296
DistributeReport< TReport > Distributor
Definition: Callback.h:240
ReceiveReport< TReport > Receiver
Definition: Callback.h:171
callback::UserData UserData
Definition: Callback.h:151
ReceiveReport< TReport > Receiver
Definition: Callback.h:201
Temporarily connect a ReceiveReport then restore the previous one.
Definition: Callback.h:284
Distributor & operator->()
Definition: Callback.h:254
virtual void report(const UserData &userData_r=UserData())
The most generic way of sending/receiving data.
Definition: Callback.h:155
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
static DistributeReport & instance()
Definition: Callback.h:204
virtual void reportend()
Definition: Callback.h:191
Receiver * getReceiver() const
Definition: Callback.h:210
void unsetReceiver(Receiver &rec_r)
Definition: Callback.h:216
static Receiver * whoIsConnected()
Definition: Callback.h:248
Typesafe passing of user data via callbacks.
Definition: UserData.h:38
virtual void reportbegin()
Definition: Callback.h:189
DistributeReport< TReport > Distributor
Definition: Callback.h:172
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
ReceiveReport * whoIsConnected() const
Definition: Callback.h:177
static bool connected()
Definition: Callback.h:251
UserData::ContentType ContentType
Definition: Callback.h:152
Mime type like 'type/subtype' classification of content.
Definition: ContentType.h:29