我正在使用corba應用程序,在create_servant()方法中,我們正在創建新servant並將其返回給被調用者。爲了簡化內存管理,我將PortableServer :: RefCountServantBase類繼承到實現類。
我收到下面的編譯錯誤。繼承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
}
您使用的是什麼ORB? – 2010-07-04 14:50:05
這是我們正在使用的TUX ORB。 – Jagannath 2010-07-05 08:43:56