Download Part II: An Open-Source Environment with C++

Transcript
T h e S e c o n d Te s t : A d d i n g C h a n n e l s a n d R a n d o m P a r a m e t e r s
Remember, we are discussing channels here because that’s how we
wanted to implement the agent layer. This could have easily been a more
generic producer/consumer model, or an event-driven method, but implement what feels correct for you. (All the examples in this handbook use
channels.)
Here are the classes for the driver and checker and the inherited classes
for their agents:
namespace my_interface {
class driver {
public:
void send_data(const my_data&);
}
typedef channel_get <my_data> input;
class driver_agent : public driver,
public truss::thread {
public:
driver_agent(input* drain) : drain_(drain) {}
//must have a start to drain the channel
void start_() {
for (;;) {
send_data(drain_—>get());
}
}
private:
input* drain_;
};
class checker {
public:
check_data(const my_data&, const results&);
};
typedef channel_get <results> checker_in;
class checker_agent : public checker,
public truss::thread {
public:
checker_agent(generated_channel* generated,
checker_in* actual) :
generated_ (generated), actual_(actual) {}
A P r a c t i t io n e r ’ s H a n d b o o k
131