libzypp 17.31.6
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
19namespace zypp
20{
21
23 namespace HACK {
25 {
26 };
27 } // namespace HACK
28
30
145 namespace callback
146 {
147
150 {
153
155 virtual void report( const UserData & userData_r = UserData() )
156 {}
157
158 virtual ~ReportBase()
159 {}
160 };
161
163 template<class TReport>
164 struct DistributeReport;
165
167 template<class TReport>
168 struct ReceiveReport : public TReport
169 {
173
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
188
189 virtual void reportbegin()
190 {}
191 virtual void reportend()
192 {}
193 };
194
196 template<class TReport>
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
220 { _receiver = &_noReceiver; }
221
222 public:
224 { return _receiver; }
225
226 private:
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>
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
Mime type like 'type/subtype' classification of content.
Definition: ContentType.h:30
Typesafe passing of user data via callbacks.
Definition: UserData.h:39
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
ReceiveReport< TReport > Receiver
Definition: Callback.h:201
Receiver * getReceiver() const
Definition: Callback.h:210
static DistributeReport & instance()
Definition: Callback.h:204
DistributeReport< TReport > Distributor
Definition: Callback.h:202
void unsetReceiver(Receiver &rec_r)
Definition: Callback.h:216
void setReceiver(Receiver &rec_r)
Definition: Callback.h:213
virtual void reportend()
Definition: Callback.h:191
ReceiveReport * whoIsConnected() const
Definition: Callback.h:177
virtual void reportbegin()
Definition: Callback.h:189
DistributeReport< TReport > Distributor
Definition: Callback.h:172
ReceiveReport< TReport > Receiver
Definition: Callback.h:171
UserData::ContentType ContentType
Definition: Callback.h:152
virtual void report(const UserData &userData_r=UserData())
The most generic way of sending/receiving data.
Definition: Callback.h:155
callback::UserData UserData
Definition: Callback.h:151
static bool connected()
Definition: Callback.h:251
DistributeReport< TReport > Distributor
Definition: Callback.h:240
Distributor & operator->()
Definition: Callback.h:254
static Receiver * whoIsConnected()
Definition: Callback.h:248
ReceiveReport< TReport > Receiver
Definition: Callback.h:239
Temporarily connect a ReceiveReport then restore the previous one.
Definition: Callback.h:285
DistributeReport< TReport > Distributor
Definition: Callback.h:288
ReceiveReport< TReport > Receiver
Definition: Callback.h:287
TempConnect(Receiver &rec_r)
Definition: Callback.h:296