1 #include "ace/Log_Msg.h"
2 #include "ace/OS_Memory.h"
3 #include "CommandStream.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")),
24 // Listing 02 code/ch18
25 CommandModule
*answerCallModule
;
26 ACE_NEW_RETURN (answerCallModule
,
27 AnswerCallModule (this->peer_
),
30 CommandModule
*retrieveCallerIdModule
;
31 ACE_NEW_RETURN (retrieveCallerIdModule
,
32 RetrieveCallerIdModule (this->peer_
),
35 CommandModule
*playMessageModule
;
36 ACE_NEW_RETURN (playMessageModule
,
37 PlayMessageModule (this->peer_
),
40 CommandModule
*recordMessageModule
;
41 ACE_NEW_RETURN (recordMessageModule
,
42 RecordMessageModule (this->peer_
),
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()),
53 if (this->push (retrieveCallerIdModule
) == -1)
54 ACE_ERROR_RETURN ((LM_ERROR
,
55 ACE_TEXT ("Failed to push %p\n"),
56 retrieveCallerIdModule
->name()),
59 if (this->push (playMessageModule
) == -1)
60 ACE_ERROR_RETURN ((LM_ERROR
,
61 ACE_TEXT ("Failed to push %p\n"),
62 playMessageModule
->name()),
65 if (this->push (recordMessageModule
) == -1)
66 ACE_ERROR_RETURN ((LM_ERROR
,
67 ACE_TEXT ("Failed to push %p\n"),
68 recordMessageModule
->name()),
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"),
87 command
= (Command
*)mb
->data_block ();
89 ACE_TEXT ("Command (%d) returns (%d)\n"),
91 command
->numeric_result_
));