ACE主动对象问题
#include "ace/OS.h"
#include "ace/Task.h"
#include "ace/Method_Object.h"
#include "ace/Activation_Queue.h"
#include "ace/Auto_Ptr.h"
#include "ace/Future.h"
#include <string>
#include <iostream>
using namespace std;
class Logger: public ACE_Task<ACE_MT_SYNCH>
{
public:
Logger()
{
this->activate();
}
int svc();
string LogMsg(const string& msg);
void LogMsgActive (const string& msg,ACE_Future<string> *result);
private:
ACE_Activation_Queue cmdQueue; //命令队列
};
class LogMsgCmd: public ACE_Method_Object
{
public:
LogMsgCmd(Logger *plog,const string& msg,ACE_Future<string> *result)
{
this->log=plog;
this->msg=msg;
this->result=result;
}
int call()
{
string reply = this->log->LogMsg(msg);
result->set(reply);
return 0;
}
private:
ACE_Future<string> *result;
Logger *log;
string msg;
};
string Logger::LogMsg(const string& msg)
{
ACE_OS::sleep(2);
cout<<endl<<msg<<endl;
return msg;
}
//以主动的方式记录日志
void Logger::LogMsgActive(const string& msg,ACE_Future<string> *result)
{
//生成命令对象,插入到命令队列中
cmdQueue.enqueue(new LogMsgCmd(this,msg,result));
}
int Logger::svc()
{
while(true)
{
//遍历命令队列,执行命令
auto_ptr<ACE_Method_Object> mo
(this->cmdQueue.dequeue ());
if (mo->call () == -1)
break;
}
return 0;
}
void get_info(ACE_Future<string> &fu)
{
string state = fu.ready()?"ready":"not ready";
cout<<endl<<state<<endl;
if(fu.ready())
{
string value;
fu.get(value);
cout<<"value:\t"<<value<<endl;
}
}
int main (int argc, ACE_TCHAR *argv[])
{
ACE_Future<string> result;
Logger log;
log.LogMsgActive ("hello",&result);
while(true)
{
get_info(result);
if(result.ready())
break;
ACE_OS::sleep(1);
}
cout<<endl<<"cmd end"<<endl;
while(true)
ACE_OS::sleep(1);
return 0;
}
对于这段代码 我的怎么找不到os头文件和ace/Method_Object.h头文件,还有ACE_Method_Object 这个类
[解决办法]
ACE没用过 虽然有配置过环境 不过刚刚在库里面找了下的确没有os.h和method_Object.h这两个文件在ACE库里面。 建议LZ看看此代码的出处详细说明
[解决办法]
我倒是接触过ACE,最近下载过ACE最新的源码,可以肯定的说OS.h的头文件一定是有的,其他的应该也都有。
[解决办法]
楼主装错了吧!!!