Discussion:
[omniORB] String sequence
Hamilton Temple
2008-08-14 23:05:08 UTC
Permalink
Hello there,

I'm trying to implement a server method that returns a char **,
I'm defining the IDL file in that way:

module MyModule{
interface MyClass{
typedef sequence<string> SeqStr;
SeqStr listContents(in string locator);
};
};

I have been googling without success. omniidl
generates the definition of a class SeqStr in
the hh file. Where could I find a full example
providing the implementation of a class like
this?

My second post today, sorry :)

Thank you,

Hamilton
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20080814/e7e44add/attachment.htm
Hamilton Temple
2008-08-15 01:24:49 UTC
Permalink
Martin, thank you for your answer.

I know that CORBA cannot deal with pointers. Sorry, it was my way to express
what
I want. As you pointed, my intention is to return a sequence of strings.

I have been only able to find incomplete examples describing the process of
mapping
a sequence of string to C++. Silly me, I thought that doing this was much
more
straightforward. This kind of return type must be quite frequent in CORBA.

I will try to obtain a copy of the books you recommend me.

Just in case, any CORBA guru over there has done this before? :)
Could you provide me detailed source code?

Thank you,

Hamilton
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20080814/aac5d6bd/attachment-0001.htm
Michael
2008-08-15 01:38:56 UTC
Permalink
No guru questions, trivial. Until you get the book, you can download the
c++ mapping spec for free from www.omg.org.

class MyClass_impl: virtual public POA_MyModule::MyClass
{
public:
MyModule::MyClass::SeqStr* listContents(const char* locator)
{
std::cout << "Locator is " << locator << std::endl;
std::auto_ptr<MyModule::MyClass::SeqStr> ret(new
MyModule::MyClass::SeqStr);

ret->length(5);
(*ret)[0] = "Please";
(*ret)[1] = "buy";
(*ret)[2] = "a book";
(*ret)[3] = "about";
(*ret)[4] = "CORBA!";
return ret.release();
}
};

As we discussd on this list before, you can also use the CORBA inbuild
memory management instead of auto_ptr (which would be
MyModule::MyClass::SeqStr_var). Using std::auto_ptr is just my personal
preference.

cheers
michael
Post by Hamilton Temple
Martin, thank you for your answer.
I know that CORBA cannot deal with pointers. Sorry, it was my way to express
what
I want. As you pointed, my intention is to return a sequence of strings.
I have been only able to find incomplete examples describing the process of
mapping
a sequence of string to C++. Silly me, I thought that doing this was much
more
straightforward. This kind of return type must be quite frequent in CORBA.
I will try to obtain a copy of the books you recommend me.
Just in case, any CORBA guru over there has done this before? :)
Could you provide me detailed source code?
Thank you,
Hamilton
------------------------------------------------------------------------
_______________________________________________
omniORB-list mailing list
http://www.omniorb-support.com/mailman/listinfo/omniorb-list
Matej Kenda
2008-08-22 23:15:48 UTC
Permalink
Hi,

I usually use the features of _var helper classes to help with memory
management.

The function would look like this:

MyModule::MyClass::SeqStr* listContents(const char* locator)
{
std::cout << "Locator is " << locator << std::endl;

MyModule::MyClass::SeqStr_var ret(new MyModule::MyClass::SeqStr);

ret->length(5);
ret[0] = "Please";
ret[1] = "buy";
ret[2] = "a book";
ret[3] = "about";
ret[4] = "CORBA!";
return ret._retn();
}

HTH,

Matej
Post by Michael
No guru questions, trivial. Until you get the book, you can download the
c++ mapping spec for free from www.omg.org.
Loading...