继承PortableServer::RefCountServantBase时出现编译错误

发布于 2024-09-07 03:44:39 字数 3330 浏览 4 评论 0原文

我正在开发一个 corba 应用程序,在 create_servant() 方法中我们创建新的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
}

I am working on a corba application where in create_servant() method we are creating new servant and returning it to the callee. To make the memory management easier, I am inheriting PortableServer::RefCountServantBase class to the implementation class.
I get the below compilation errors.

"simples.cpp", line 108: Error: Cannot create a variable for abstract class Simple_i.
"simples.cpp", line 108: Error: PortableServer::ServantBase::invoke(CORBA::ServerRequest*) has not been overridden.
"simples.cpp", line 108: Error: PortableServer::ServantBase::_primary_interface(const PortableServer::ObjectId&, PortableServer::POA*) has not been overridden.
3 Error(s) detected.

If I don't inherit RefCountServantBase I don't get any compilation errors. In samples.cpp, which is not shown here we are creating an instance of sample_i and returning it.

Here is the sample code:

// 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

Update:
I changed the inheritance and did not inherit PortableServer::RefCountServantBase, since RefCountServantBase itself is getting inherited by Tobj_ServantBase.
Now, I have the code as below. Is this fine? Do I need to care about memory management
here ? Or am I missing something?

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
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

好多鱼好多余 2024-09-14 03:44:39

在较新版本的 CORBA 中,不推荐使用 RefCountServantBase。您不再需要继承它,因为自动生成的 C++ 仆人现在提供相同的功能。您应该验证您正在使用的 ORB 是否已实现此更改。

至于您关于 create_servant() 函数的问题部分。从创造仆人的角度来看应该没问题。然而,您可以将多个内容分配给您的servant 变量,这看起来很奇怪。如果发生这种情况,你就会泄漏。

我也不能说 _tc_SimpleFactory->id()_tc_Simple->id() 因为我不熟悉这些函数。如果它们返回 CORBA 字符串,那么您就会泄漏内存。

In newer versions of CORBA, RefCountServantBase is deprecated. You no longer need to inherit from it because the auto-generated C++ servants now provide the same functionality. You should verify that the ORB you are using has implemented this change.

As to the part of your question about your create_servant() function. It should be fine from the servant creation aspect. However it looks strange that you can assign multiple things to your servant variable. If this happened you would leak.

I also can't say about _tc_SimpleFactory->id() or _tc_Simple->id() because I'm not familiar with those functions. If they return CORBA strings then you are leaking memory.

无妨# 2024-09-14 03:44:39

PortableServer::RefCountServantBase 是抽象类吗?你能发布它的声明吗?

第一个编译错误表明 Simple_i 没有实现基类中声明的所有抽象方法。
另外两个编译错误涉及 PortableServer::ServantBase 中未在 Simple_i 中实现的方法。我猜它们是抽象方法。我还注意到其中一个称为调用,并且 POA_Simple 声明了一个调用方法。也就是说,Simple_i 继承了两个不同基类调用的调用方法。我不确定这是否会导致进一步的问题。

Is PortableServer::RefCountServantBase an abstract class? Could you post its declaration?

First compilation error says Simple_i is not implementing all the abstract methods declared in the base classes.
The other two compilation errors refer to methods in PortableServer::ServantBase that are not being implemented in Simple_i. I guess they are abstract methods. I note also that one of them is called invoke, and that POA_Simple declares an invoke method. That is, Simple_i is inheriting a method called invoke by two different base classes. I am not sure if this can lead to further issues.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文