 | > > 1. Issue with C++NPv2 streams example > --------------------------------------- > > My earlier postings originated from an example test > I had written based on the Streams example from > p302 of C++NPv2. > > The problem is that for member variable tasks, > such as the one shown on p303 in the LogRec_Module > template definition, when you call any member > functions of the task related to being part of a > module (that should have been setup when > the task was inserted into the stream) the > functions are not setup! ...
I may have an explanation for the problem.
From display_logfile.cpp:
template class Logrec_Module : public ACE_Module { public: Logrec_Module (const ACE_TCHAR *name) : ACE_Module (name, &task_, // Initialize writer-side task. 0, // Ignore reader-side task. 0, ACE_Module::M_DELETE_READER) {} private: TASK task_; };
The task_ member of the module is passed as an argument to the base-class constructor of the module. However, the constructor of the task_ object has not been called yet, so task_ is probably bogus.
When the constructor for task does get called, it takes on the default values for the module variables, i.e., none are set.
If you move the base-class constructor out of the member initialization list in the Logrec_Module template, letting the default destructor get triggered there, and then use the base class open() call in Logrec_Module, then by that time the task_ member is initialized, and the module properties of the task are now correct.
i.e., template class Logrec_Module : public ACE_Module { public: Logrec_Module (const ACE_TCHAR *name) { ACE_Module::open (name, &task_, // Initialize writer-side task. 0, // Ignore reader-side task. 0, ACE_Module::M_DELETE_READER); } private: TASK task_; };
and the same for the Logrec_Reader_Module class a little further down in the file.
With this modification, the debug statements in the Logrec_Reader task, eg.
virtual int open (void *) {
ACE_DEBUG((LM_DEBUG, "Logrec_Reader: open\n")); if (module()) { ACE_DEBUG((LM_DEBUG, "Logrec_Reader: module is set\n")); } else { ACE_DEBUG((LM_DEBUG, "Logrec_Reader: module is NOT set\n")); } ACE_FILE_Addr name (filename_.c_str ()); ACE_FILE_Connector connector; if (connector.connect (logfile_, name) == -1) return -1; return activate (); }
Go from saying that module is NOT set, to being set.
If this is the correct solution to the problem, then it should be listed in the book Errata. I just took a look at
http://www.cs.wustl.edu/~schmidt/ACE/book2/Errata.txt
and there is no mention of it there.
A single file example that exhibits this problem can be found at:
http://www.ovro.caltech.edu/~dwh/ace/simple_stream_member_task.cpp compile with -DCONSTRUCTOR_LIST and it'll show that none of the task module member functions return useful values, recompile without the define and the task member calls work as expected.
Whew! Now, I was sure I came to work today to get something useful done ....
Dave
|
|