// product.cc // Kenneth J. Goldman 12/26/94 // T. Paul McCartney 12/30/96 (converted) // // This module has three integer presentation entries. // i1 and i2: input integer values // out: an output value that is the product of i1 and i2 // The module is reactive. It terminates when either input value is negative. #include #include "PG.hh" static int done = 0; PGint i1 = 0; PGint i2 = 0; PGint out = 0; class productReactor : public PGreactor { public: virtual void react(PGvariable&) { if ((i1 < 0) || (i2 < 0)) done = 1; else { cout << "multiplying " << i1 << " by " << i2 << endl; out = i1 * i2; } }; }; int main() { PG::initialize("PRODUCT"); out.publish("out", PG::READ); i1.publish("i1", PG::WRITE); i2.publish("i2", PG::WRITE); productReactor r; i1.setReactor(&r); i2.setReactor(&r); while (!done) PG::sleep(0, 200); PG::terminate(); }