我有一个非常简单的CORBA代码。它有一个简单的例程可以将消息写入文件。如果我手动启动服务器,代码运行正常。 输出文件将按预期创建。如果我添加服务器 到IMR并让IMR负责启动,代码不会写出out文件。有人能告诉我发生了什么以及如何解决它吗?
void
Hello_impl::say_hello() throw (CORBA::SystemException)
{
cout << "Hello World" << endl;
char* msg = strdup ("Hello from this world to the next");
ofstream out;
out.open ("./mydata2.txt", std::ios::out);
out << msg;
out.close();
}
这是服务器代码。
run (CORBA::ORB_ptr orb)
{
CORBA::Object_var poaObj =
orb->resolve_initial_references("RootPOA");
PortableServer::POA_var rootPoa =
PortableServer::POA::_narrow(poaObj);
PortableServer::POAManager_var manager =
rootPoa->the_POAManager();
CORBA::PolicyList policyList(2);
policyList.length(2);
policyList[0] = rootPoa->create_lifespan_policy(
PortableServer::PERSISTENT);
policyList[1] = rootPoa->create_id_assignment_policy(
PortableServer::USER_ID);
PortableServer::POA_var helloPOA =
rootPoa->create_POA ("hello", manager, policyList);
CORBA::PolicyList policyList;
PortableServer::POA_var helloPOA =
rootPoa->create_POA ("hello", manager, policyList);
Hello_impl* helloImpl = new Hello_impl(helloPOA);
PortableServer::ServantBase_var servant = helloImpl;
PortableServer::ObjectId_var oid =
PortableServer::string_to_ObjectId("hello");
helloPOA->activate_object_with_id (oid, servant);
Hello_var hello = helloImpl->_this();
CORBA::String_var s = orb->object_to_string(hello);
const char* refFile = "/tmp/Hello.ref";
ofstream out (refFile);
out << s << endl;
out.close();
}