Discussion:
[omniORB] Changing lenght of CORBA::String_var type and setting new value.
janarbek
2007-10-09 15:28:31 UTC
Permalink
Hi all,

Sorry for sending basic questions,..may be u guys see I am doing progress in CORBA with c++. Ok my question is,...

I want to change lenght of CORB::String_var data variable in a loop and set new const string to my data variable.

What I did was in the below.

My IDL

interface stringTestServer {
void setSize(inout short size);
string returnType();
};

Server code:
data = ( char*) "A";

void stringTestServer_i::setSize(CORBA::Short& size)
{
const char *str ="";
std::string s ="";

for(int i=0;i<size;i++)
{
s+="a";
}
str = s.c_str();
cout<<"Str="<<str<<endl; str varaible changes as loop

data = CORBA::string_dup(str); --> Here is the problem data always prints A
cout<<"Data="<<*data<<endl;
}

char* stringTestServer_i::returnType()
{
return CORBA::string_dup(data);
}

I hope I made myself understand, basically I want to change lenght of data and set new string each time.





==================================================================================================================================================================
Janarbek, Researcher.
Software Robot Research Team, ETRI(Electronics and Telecommunications Research Institute)
161 Kajong-Dong, Yusong-Gu, TAEJON, 305-350, KOREA
Email : ***@etri.re.kr
Phone : 82-42-860-1838
Fax : 82-42-860-6790
Cell Phone: 82-10-8692-8103
===================================================================================================================================================================


---------------------------------
Looking for a deal? Find great prices on flights and hotels with Yahoo! FareChase.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20071009/e9eec34e/attachment.htm
Jason Etheridge
2007-10-09 15:45:48 UTC
Permalink
Post by janarbek
I want to change lenght of CORB::String_var data variable in a loop and
set new const string to my data variable.
...
Post by janarbek
data = ( char*) "A";
Firstly, you should never initialise a CORBA::String_var (assuming
that's the type of 'data') to a non-const string. In other words, this
should be:

data = (const char *)"A";
Post by janarbek
void stringTestServer_i::setSize(CORBA::Short& size)
{
const char *str ="";
std::string s ="";
for(int i=0;i<size;i++)
{
s+="a";
}
str = s.c_str();
cout<<"Str="<<str<<endl; str varaible changes as loop
data = CORBA::string_dup(str); --> Here is the problem data always prints A
cout<<"Data="<<*data<<endl;
}
There's nothing obviously wrong with what you're doing. If you're
still having trouble, I'd suggest pasting the entire source file for
your implementation; it's possible there's something else wrong that's
in the missing code.

Cheers,
Jason.
--
Jason Etheridge mailto:***@etheridge.org
Loading...