Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / APG / Streams / CommandStream.cpp
blob6e46b134e415249d3a46efdaf0664c4ed5ca0736
1 #include "ace/Log_Msg.h"
2 #include "ace/OS_Memory.h"
3 #include "CommandStream.h"
4 #include "Command.h"
5 #include "CommandModule.h"
6 #include "CommandTasks.h"
8 // Gotcha: superclass' open() won't open head/tail modules
9 // Gotcha!! Must open the stream before pushing modules!
11 // Listing 01 code/ch18
12 int CommandStream::open (void *arg,
13 ACE_Module<ACE_MT_SYNCH> *head,
14 ACE_Module<ACE_MT_SYNCH> *tail)
16 ACE_TRACE ("CommandStream::open(peer)");
18 if (this->inherited::open (arg, head, tail) == -1)
19 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"),
20 ACE_TEXT ("Failed to open superclass")),
21 -1);
22 // Listing 01
24 // Listing 02 code/ch18
25 CommandModule *answerCallModule;
26 ACE_NEW_RETURN (answerCallModule,
27 AnswerCallModule (this->peer_),
28 -1);
30 CommandModule *retrieveCallerIdModule;
31 ACE_NEW_RETURN (retrieveCallerIdModule,
32 RetrieveCallerIdModule (this->peer_),
33 -1);
35 CommandModule *playMessageModule;
36 ACE_NEW_RETURN (playMessageModule,
37 PlayMessageModule (this->peer_),
38 -1);
40 CommandModule *recordMessageModule;
41 ACE_NEW_RETURN (recordMessageModule,
42 RecordMessageModule (this->peer_),
43 -1);
44 // Listing 02
46 // Listing 03 code/ch18
47 if (this->push (answerCallModule) == -1)
48 ACE_ERROR_RETURN ((LM_ERROR,
49 ACE_TEXT ("Failed to push %p\n"),
50 answerCallModule->name()),
51 -1);
53 if (this->push (retrieveCallerIdModule) == -1)
54 ACE_ERROR_RETURN ((LM_ERROR,
55 ACE_TEXT ("Failed to push %p\n"),
56 retrieveCallerIdModule->name()),
57 -1);
59 if (this->push (playMessageModule) == -1)
60 ACE_ERROR_RETURN ((LM_ERROR,
61 ACE_TEXT ("Failed to push %p\n"),
62 playMessageModule->name()),
63 -1);
65 if (this->push (recordMessageModule) == -1)
66 ACE_ERROR_RETURN ((LM_ERROR,
67 ACE_TEXT ("Failed to push %p\n"),
68 recordMessageModule->name()),
69 -1);
70 // Listing 03
71 return 0;
74 // Listing 04 code/ch18
75 Command *CommandStream::execute (Command *command)
77 ACE_Message_Block *mb = 0;
78 ACE_NEW_RETURN (mb, ACE_Message_Block (command), 0);
79 if (this->put (mb) == -1)
80 ACE_ERROR_RETURN ((LM_ERROR,
81 ACE_TEXT ("Fail on put command %d: %p\n"),
82 command->command_,
83 ACE_TEXT ("")),
84 0);
86 this->get (mb);
87 command = (Command *)mb->data_block ();
88 ACE_DEBUG ((LM_DEBUG,
89 ACE_TEXT ("Command (%d) returns (%d)\n"),
90 command->command_,
91 command->numeric_result_));
93 return command;
95 // Listing 04