5 #include "ace/Task_T.h"
6 #include "ace/ace_wchar.h"
8 // Listing 100 code/ch18
9 class BasicTask
: public ACE_Task
<ACE_MT_SYNCH
>
12 typedef ACE_Task
<ACE_MT_SYNCH
> inherited
;
14 BasicTask () : inherited()
17 virtual int open (void * = 0)
20 ACE_TEXT ("BasicTask::open() starting ")
21 ACE_TEXT ("%d threads\n"),
22 this->desired_threads ()));
24 return this->activate (THR_NEW_LWP
| THR_JOINABLE
,
25 this->desired_threads ());
29 // Listing 101 code/ch18
30 int put (ACE_Message_Block
*message
,
31 ACE_Time_Value
*timeout
)
33 return this->putq (message
, timeout
);
37 // Listing 1020 code/ch18
40 for (ACE_Message_Block
*message
= 0; ; )
43 ACE_TEXT ("BasicTask::svc() - ")
44 ACE_TEXT ("waiting for work\n" )));
46 if (this->getq (message
) == -1)
47 ACE_ERROR_RETURN ((LM_ERROR
, ACE_TEXT ("%p\n"),
52 // Listing 1021 code/ch18
53 if (message
->msg_type () == ACE_Message_Block::MB_HANGUP
)
55 if (this->putq (message
) == -1)
59 ACE_TEXT ("Task::svc() putq")));
66 // Listing 1022 code/ch18
67 Message
*recordedMessage
=
68 (Message
*)message
->rd_ptr ();
70 if (this->process (recordedMessage
) == -1)
73 ACE_ERROR_RETURN ((LM_ERROR
,
75 ACE_TEXT ("process")),
80 // Listing 1023 code/ch18
82 ACE_TEXT ("BasicTask::svc() - ")
83 ACE_TEXT ("Continue to next stage\n" )));
84 if (this->next_step (message
) < 0)
88 ACE_TEXT ("put_next failed")));
98 // Listing 103 code/ch18
99 virtual int close (u_long flags
)
105 ACE_Message_Block
*hangup
= new ACE_Message_Block ();
106 hangup
->msg_type (ACE_Message_Block::MB_HANGUP
);
107 if (this->putq (hangup
) == -1)
110 ACE_ERROR_RETURN ((LM_ERROR
,
112 ACE_TEXT ("Task::close() putq")),
116 rval
= this->wait ();
123 // Listing 105 code/ch18
125 virtual int next_step (ACE_Message_Block
*message_block
)
127 return this->put_next (message_block
);
131 // Listing 104 code/ch18
132 virtual int process (Message
*message
) = 0;
134 virtual int desired_threads ()
141 #endif /* BASIC_TASK_H */