|
楼主 |
发表于 2010-1-7 15:38:27
|
显示全部楼层
还有,我想说的是svc.conf中这样加载估计是不行的, 至少于CCM_App这个例子没有做完整,因为在Stream这个章节中调度消息是要我们手工写基类调度的, 例如我们需要自己去调用put() 与get()消息,如Stream中这段代码,当然是放在基类中的,这个不是ACE基类,而是要我们自己封装的:
下面就是单向流中:作为Module之上的Task基类写法:(它的目的是调度Module间的message)
#pragma once
#include "ace/Task_T.h"
#include "ace/ace_wchar.h"
#include "Message.h"
class CBasicTask :
public ACE_Task<ACE_MT_SYNCH>
{
public:
CBasicTask(void);
~CBasicTask(void);
typedef ACE_Task<ACE_MT_SYNCH> inherited;
public:
// open (void * = 0)
int open(void* = 0 );
// Listing 101 code/ch18
int put (ACE_Message_Block *message,
ACE_Time_Value *timeout)
{
return this->putq (message, timeout);
}
// Listing 101
// Listing 1020 code/ch18
virtual int svc (void)
{
for (ACE_Message_Block *message = 0; ; )
{
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("BasicTask::svc() - ")
ACE_TEXT ("waiting for work\n" )));
if (this->getq (message) == -1)
ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"),
ACE_TEXT ("getq")),
-1);
// Listing 1020
// Listing 1021 code/ch18
if (message->msg_type () == ACE_Message_Block::MB_HANGUP)
{
if (this->putq (message) == -1)
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("Task::svc() putq")));
message->release ();
}
break;
}
// Listing 1021
// Listing 1022 code/ch18
CMessage *recordedMessage =
(CMessage *)message->rd_ptr ();
if (this->process (recordedMessage) == -1)
{
message->release ();
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("process")),
-1);
}
// Listing 1022
// Listing 1023 code/ch18
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("BasicTask::svc() - ")
ACE_TEXT ("Continue to next stage\n" )));
if (this->next_step (message) < 0)
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("put_next failed")));
message->release ();
break;
}
// Listing 1023
}
return 0;
}
// Listing 103 code/ch18
virtual int close (u_long flags)
{
int rval = 0;
if (flags == 1)
{
ACE_Message_Block *hangup = new ACE_Message_Block ();
hangup->msg_type (ACE_Message_Block::MB_HANGUP);
if (this->putq (hangup) == -1)
{
hangup->release ();
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("Task::close() putq")),
-1);
}
rval = this->wait ();
}
return rval;
}
// Listing 103
// Listing 105 code/ch18
protected:
virtual int next_step (ACE_Message_Block *message_block)
{
return this->put_next (message_block);
}
// Listing 105
// Listing 104 code/ch18
virtual int process (CMessage *message) = 0;
public:
virtual int desired_threads(void);
}; |
|