By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,954 Members | 1,133 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,954 IT Pros & Developers. It's quick & easy.

HELP C++ and Corba?

P: n/a
Hello all,
I am having a very difficult time getting something to work. This
involves CORBA, hopefully someone here will be able to answer it, and if not
maybe someone can point me in the right direction to where I can get it
answered. Using ACE/TAO.... Redhat 7.3 using Kdevelop.
OK really I just want to copy a CORBA octet sequence to and array where I
can get a pointer to point to it. The first 0-3 octets in the sequence are
stored in the first int and so forth... so the array of ints would be one
quarter of the size of the octet sequence.

This is what I have and doesn't work:

//corba object already declared.

CORBA::Octet* ptempBuffer;
ptempBuffer =payLoad_var->getBuffer();
char* working_data =(char*)ptempBuffer;

byte_index =0;
for(analog_index = 0; analog_index <16; analog_index++)
{

working_data[byteIndex]=char(analog_data[analog_index]>>8);
working_data[byteIndex+1]=char(analog_data[analog_index]& 0xFF);
working_data[byteIndex+2]=char(0x00);
working_data[byteIndex+3]=char(0x00);
byte_index +=4;
}

This is what i have and it seems to crash!
Can someone be kind and help a poor soul?
thanks


Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Bob Smith" <la******@yahoo.com> wrote in message news:<q5*******************@twister.nyroc.rr.com>. ..
I am having a very difficult time getting something to work. This
involves CORBA, hopefully someone here will be able to answer it, and if not
maybe someone can point me in the right direction to where I can get it
answered. Using ACE/TAO.... Redhat 7.3 using Kdevelop.
This is an ISO C++ newsgroup, which means (a) this is (mostly)
off-topic, and (b) it's a crapshoot whether anyone here speaks CORBA.
In the future, you should probably post to comp.object.corba, or else
comp.soft-sys.ace (yes, they talk TAO) or one of the mailing lists for
which it acts as a gateway:

http://www.cs.wustl.edu/~schmidt/TAO-mail.html
This is what i have and it seems to crash!


Looking at this code, I can only guess that the crash is due to
accessing memory that isn't yours to access. analog_data ought to have
at least 16 elements, and working_data ought to have 64 (4 bytes for
each of analog_data's 16 elements). That's about all I can tell you
from looking at this code. Except...

<off-topic>
CORBA sequences like payLoad_var (that's what it is, no?) seem to act
a lot like C++ std::vector objects. As such, you have to resize them
before you start using them. Also, they have an overloaded operator[],
so you don't need to mess with pointers.

(For future reference, even when using a pointer, you should be able
to use CORBA::Octet without casting. That is, working_data should have
been a pointer to CORBA::Octet and not a pointer to char, since that's
what getBuffer() returns. And if you must cast, prefer C++-style casts
[like static_cast] to C-style ones whenever possible [which it almost
always is].)

Putting everything together, something like this ought to do it:

// allocate 64 octets (must be done before getBuffer!)
payLoad_var->length(64);

byte_index = 0;

for(analog_index = 0; analog_index <16; analog_index++)
{
typedef CORBA::Octet octet;
payLoad_var[byteIndex]=octet(analog_data[analog_index]>>8);
payLoad_var[byteIndex+1]=octet(analog_data[analog_index]& 0xFF);
payLoad_var[byteIndex+2]=octet(0x00);
payLoad_var[byteIndex+3]=octet(0x00);
byte_index +=4;
}
</off-topic>

If that doesn't do the trick, a CORBA or ACE/TAO forum would be much
better equipped to help you. Try there next.

- Shane
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.