1 #include "CommandTask.h"
3 // Listing 01 code/ch18
4 CommandTask::CommandTask (int command
)
5 : inherited (), command_(command
)
9 // Listing 02 code/ch18
10 int CommandTask::open (void *)
12 return this->activate ();
16 // Listing 03 code/ch18
17 int CommandTask::put (ACE_Message_Block
*message
,
18 ACE_Time_Value
*timeout
)
20 return this->putq (message
, timeout
);
24 // Listing 04 code/ch18
25 int CommandTask::process (Command
*)
27 ACE_TRACE ("CommandTask::process()");
28 return Command::RESULT_FAILURE
;
32 // Listing 05 code/ch18
33 int CommandTask::close (u_long flags
)
38 ACE_Message_Block
*hangup
= new ACE_Message_Block
;
39 hangup
->msg_type (ACE_Message_Block::MB_HANGUP
);
40 if (this->putq (hangup
->duplicate ()) == -1)
42 ACE_ERROR_RETURN ((LM_ERROR
,
44 ACE_TEXT ("Task::close() putq")),
56 // Listing 06 code/ch18
57 // Listing 061 code/ch18
58 int CommandTask::svc ()
60 ACE_Message_Block
*message
;
65 ACE_TEXT ("CommandTask::svc() - ")
66 ACE_TEXT ("%s waiting for work\n"),
67 this->module ()->name ()));
69 if (this->getq (message
) == -1)
70 ACE_ERROR_RETURN ((LM_ERROR
,
75 if (message
->msg_type () == ACE_Message_Block::MB_HANGUP
)
77 if (this->putq (message
->duplicate ()) == -1)
79 ACE_ERROR_RETURN ((LM_ERROR
,
81 ACE_TEXT ("Task::svc() putq")),
90 // Listing 062 code/ch18
91 Command
*command
= (Command
*)message
->data_block ();
94 ACE_TEXT ("CommandTask::svc() - ")
95 ACE_TEXT ("%s got work request %d\n"),
96 this->module ()->name (),
99 if (command
->command_
!= this->command_
)
101 this->put_next (message
->duplicate ());
104 // Listing 063 code/ch18
107 int result
= this->process (command
);
108 ACE_DEBUG ((LM_DEBUG
,
109 ACE_TEXT ("CommandTask::svc() - ")
110 ACE_TEXT ("%s work request %d result is %d\n"),
111 this->module ()->name (),
115 if (result
== Command::RESULT_FAILURE
)
117 command
->numeric_result_
= -1;
120 // Listing 064 code/ch18
121 else if (result
== Command::RESULT_PASS
)
123 this->put_next (message
->duplicate ());
126 // Listing 065 code/ch18
127 else // result == Command::RESULT_SUCCESS
129 if (this->is_writer ())
131 this->sibling ()->putq
132 (message
->duplicate ());
135 // Listing 066 code/ch18
136 else // this->is_reader ()
138 this->put_next (message
->duplicate ());
142 } // command->command_ ? = this->command_
144 // Listing 067 code/ch18