Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef TIMEBOMB_HPP_
- #define TIMEBOMB_HPP_
- #include <boost/thread.hpp>
- #include <boost/python.hpp>
- using namespace boost;
- using namespace boost::python;
- // The interface to implement in Python. This will get
- // called from a thread in the C++ runtime.
- class ITimeBombCallback
- {
- public:
- virtual ~ITimeBombCallback() { }
- virtual void ReceiveExplosion() = 0;
- };
- // To properly call interfaces implemented in Python, we actually use a specific wrapper.
- // Calls to/from Python objects will actually take a trip through this.
- class ITimeBombCallbackWrapper : public ITimeBombCallback, public boost::python::wrapper<ITimeBombCallback>
- {
- void ReceiveExplosion();
- };
- // Usage:
- // 1. Construct with an implementation of ITimeBombCallback (from Python).
- // 2. Call Go() to start background thread.
- // 3. Wait around 5 seconds for the bomb to go off.
- // 4. Call Join() if you're still alive.
- class TimeBomb
- {
- protected:
- boost::thread* backgroundThread;
- ITimeBombCallback* luckyWinner;
- void InnerBody();
- public:
- TimeBomb(ITimeBombCallback* luckyWinner);
- void Go();
- void Join();
- };
- #endif // TIMEBOMB_HPP_
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement