2010-06-22 88 views
0

我正在使用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 
} 
+0

您使用的是什麼ORB? – 2010-07-04 14:50:05

+0

這是我們正在使用的TUX ORB。 – Jagannath 2010-07-05 08:43:56

回答

0

在較新版本的CORBA中,RefCountServantBase已棄用。您不再需要繼承它,因爲自動生成的C++ servant現在提供相同的功能。您應該驗證您正在使用的ORB是否實施了此更改。

至於你的問題關於你的create_servant()函數的部分。從僕人的創作方面來看應該沒問題。不過,看起來很奇怪,您可以將多個事物分配給您的變量servant。如果發生這種情況,你會泄漏。

我也不能說_tc_SimpleFactory->id()_tc_Simple->id()因爲我不熟悉這些功能。如果他們返回CORBA字符串,那麼你正在泄漏內存。

+0

得到你。條件應該是其他如果不是ifs。是你在說什麼內存泄漏?不管怎麼說,我會看看ORB,如果它已經進行了更改。 – Jagannath 2010-07-10 22:59:47

+0

是的,如果這兩個ifs被執行了,你將會泄漏,還要注意調用'_tc_SimpleFactory-> id()'和' _tc_Simple-> id()'。他們是否返回字符串,你必須釋放自己?如果是這樣,那些也是泄漏。 – 2010-07-11 01:20:42

0

PortableServer :: RefCountServantBase是一個抽象類嗎?你能發表它的聲明嗎?

第一次編譯錯誤說Simple_i沒有實現在基類中聲明的所有抽象方法。 另外兩個編譯錯誤引用了SimpleServer中未實現的PortableServer :: ServantBase中的方法。我猜他們是抽象的方法。我還注意到其中一個被稱爲invoke,並且POA_Simple聲明瞭一個invoke方法。也就是說,Simple_i繼承了兩個不同基類的調用方法。我不確定這是否會導致更多問題。

+0

我Binged /谷歌搜索它,並沒有找到類聲明RefCountServantBase :-(。 – Jagannath 2010-06-22 23:05:08

+0

你應該有它的來源。 – 2010-07-05 18:27:44