【发布时间】:2010-06-22 22:35:59
【问题描述】:
我正在开发一个 corba 应用程序,我们在 create_servant() 方法中创建新的服务方并将其返回给被调用方。为了使内存管理更容易,我将 PortableServer::RefCountServantBase 类继承到实现类。
我收到以下编译错误。
“simples.cpp”,第 108 行:错误:无法为抽象类 Simple_i 创建变量。
“simples.cpp”,第 108 行:错误:PortableServer::ServantBase::invoke(CORBA::ServerRequest*) 尚未被覆盖。
“simples.cpp”,第 108 行:错误:PortableServer::ServantBase::_primary_interface(const PortableServer::ObjectId&, PortableServer::POA*) 尚未被覆盖。
3 检测到错误。
如果我不继承 RefCountServantBase,我不会收到任何编译错误。在此处未显示的 samples.cpp 中,我们正在创建 sample_i 的实例并返回它。
这里是示例代码:
// sample_i.h
#include "simple_s.h"
extern char* generate_unique_id(); // Generate unique uuids
class Simple_i : public virtual POA_Simple
, virtual public PortableServer::RefCountServantBase
{
public:
virtual char* to_lower(const char* val);
virtual void to_upper(char*& val);
virtual char* to_print(const char* val);
};
class SimpleFactory_i : public virtual POA_SimpleFactory
// , virtual public PortableServer::RefCountServantBase
{
public:
virtual Simple_ptr find_simple();
// To make simpapp scalable have the SimpleFactory use the user
// supplied identifier in the Simple object reference it creates.
};
================================================ ================================== // sample_s.h
#include <string.h>
#include "orbminor.h"
#include <Tobj_ServantBase.h>
#include "simple_c.h"
class POA_Simple : public Tobj_ServantBase
{
public:
virtual ::CORBA::Char * to_lower (
const char * str) = 0;
virtual void to_upper (
::CORBA::Char *& str) = 0;
virtual ::CORBA::Char * to_print (
const char * str) = 0;
::Simple_ptr _this();
void invoke (::CORBA::ServerRequest_ptr _nasreq);
::CORBA::RepositoryId _primary_interface (
const PortableServer::ObjectId &,
PortableServer::POA_ptr);
protected:
virtual ~POA_Simple(){ }
private:
OBBArgument *getparams (::CORBA::Short, OBB::ServerRequest * SrvReq, ::CORBA::ULong & ArgCnt);
};
class POA_SimpleFactory : public Tobj_ServantBase
{
public:
virtual ::Simple_ptr find_simple () = 0;
::SimpleFactory_ptr _this();
void invoke (::CORBA::ServerRequest_ptr _nasreq);
::CORBA::RepositoryId _primary_interface (
const PortableServer::ObjectId &,
PortableServer::POA_ptr);
protected:
virtual ~POA_SimpleFactory(){ }
private:
OBBArgument *getparams (::CORBA::Short, OBB::ServerRequest * SrvReq, ::CORBA::ULong & ArgCnt);
};
#endif
更新:
我更改了继承并没有继承 PortableServer::RefCountServantBase,因为 RefCountServantBase 本身正在被 Tobj_ServantBase 继承。
现在,我有如下代码。这样好吗?我需要关心内存管理吗
这里 ?还是我错过了什么?
Tobj_Servant Server::create_servant(const char* intf_repos_id)
{
Tobj_Servant servant = NULL;
if (!strcmp(intf_repos_id, _tc_SimpleFactory->id())) {
servant = new SimpleFactory_i();
}
if (!strcmp(intf_repos_id, _tc_Simple->id())) {
servant = new Simple_i();
}
servant->_add_ref();
return servant; // unknown interface
}
【问题讨论】:
-
这是我们使用的 TUX ORB。