From: Michael Andres Date: Wed, 1 Feb 2006 21:35:48 +0000 (+0000) Subject: - added struct callback::TempConnect X-Git-Tag: BASE-SuSE-SLE-10-SP2-Branch~2781 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=33a94ab5ef9327c8cacb08a1116d0f5fb88f08a7;p=platform%2Fupstream%2Flibzypp.git - added struct callback::TempConnect Temporarily connect a ReceiveReport then restore the previous one. --- diff --git a/zypp/Callback.h b/zypp/Callback.h index 819f108..08abe76 100644 --- a/zypp/Callback.h +++ b/zypp/Callback.h @@ -220,6 +220,53 @@ namespace zypp { return Distributor::instance(); } }; + /** Temporarily connect a ReceiveReport then restore the previous one. + * + * Pass the ReceiveReport you want to connect temporarily + * to the ctor. The ReceiveReport is connected, a previously + * connected ReceiveReport is remembered and re-connected in + * the dtor. + * \code + * struct FooReceive : public callback::ReceiveReport + * {..}; + * struct FooReceive2 : public callback::ReceiveReport + * {..}; + * + * FooReceive r; + * FooReceive2 r2; + * + * r.connect(); + * ... // r receiving the report + * { + * callback::TempConnect temp( r2 ); + * ...// r2 receiving the report + * } + * ...// r receiving the report + * \endcode + */ + template + struct TempConnect + { + typedef ReceiveReport<_Report> Receiver; + typedef DistributeReport<_Report> Distributor; + + TempConnect( Receiver & rec_r ) + : _oldRec( Distributor::instance().getReceiver() ) + { + rec_r.connect(); + } + + ~TempConnect() + { + if ( _oldRec ) + Distributor::instance().setReceiver( *_oldRec ); + else + Distributor::instance().noReceiver(); + } + private: + Receiver * _oldRec; + }; + ///////////////////////////////////////////////////////////////// } // namespace callback ///////////////////////////////////////////////////////////////////