TProcessor Demo 如下:
#include <iostream>
#include <boost/shared_ptr.hpp>
class TProcessorEventHandler {
public:
virtual ~TProcessorEventHandler() {}
virtual void processingEvent(void *event_ctx) {}
};
class TProcessor {
public:
virtual ~TProcessor() {}
virtual bool process(void *process_ctx) = 0;
boost::shared_ptr<TProcessorEventHandler> getEventHandler() {
return eventHandler_;
}
void setEventHandler(boost::shared_ptr<TProcessorEventHandler> eventHandler) {
eventHandler_ = eventHandler;
}
protected:
TProcessor() {}
boost::shared_ptr<TProcessorEventHandler> eventHandler_;
};
class MyPro : public TProcessor {
public:
bool process(void *process_ctx) {
std::cout << "MyPro::process" << std::endl;
eventHandler_->processingEvent(NULL);
}
};
class MyProEvent : public TProcessorEventHandler {
public:
void processingEvent(void *event_ctx) {
std::cout << "MyProEvent::processingEvent" << std::endl;
}
};
int main() {
boost::shared_ptr<MyPro> pro(new MyPro());
boost::shared_ptr<MyProEvent> event(new MyProEvent()) ;
pro->setEventHandler(event);
pro->process(NULL);
}