[omniORB] The Simple example not working :0)

yashik@veon.com yashik@veon.com
Sun Oct 13 10:27:01 2002


Hi there,

     My guess is that the problem occurs in the servant when you make an
assignment
(*seq)[i] = itemList[i]._this();

When working with sequences you should:
1. allocate enough memory of all items
2. set the correct size of the sequence

The line
     ItemSeq* seq = new ItemSeq(len);
only tells the sequence to allocate memory for 'len' elements, but the size
of the sequence remains 0.
you should call seq->length(len) to be able to access the elements of the
sequence.


HTH,
Yakov



                                                                                                                                 
                    "Bjorn R. Jensen"                                                                                            
                    <bjensen@fastmail.fm>              To:     "Laurent JOIGNY" <ljoigny@houston.westerngeco.slb.com>,           
                    Sent by:                            omniorb-list@omniorb-support.com                                         
                    omniorb-list-admin@omniorb-s       cc:                                                                       
                    upport.com                         Subject:     Re: [omniORB] The Simple example not working :0)             
                                                                                                                                 
                                                                                                                                 
                    11/10/2002 09:50                                                                                             
                                                                                                                                 
                                                                                                                                 




Hi there,

 There is a problem in your implementation of the Item servant,
where you return a char * to the orb runtime. The orb runtime
expects a char * to memory allocated using CORBA::string_alloc.
The orb runtime also assumes ownership of the string handed to
it, and will free it using CORBA::string_free, when it is done
marshalling it. In your case it would be easiest, if you used
return CORBA::string_dup(d_name). You are basically corrupting
the heap.

Yours sincerely,

Bjorn

On Thu, 10 Oct 2002 16:19:07 -0500, "Laurent JOIGNY"
<ljoigny@houston.westerngeco.slb.com> said:
> Hi,
>
> I am a new user of omniORB and I tried to run a simple example
> of a time server. All goes well until I decide to add some spicy
> stuff like sequence.
>
> First of all my problem was at the compilation stage, when I try to
> assign an element of a vector to an element of my sequence.
> It seems that the _this() operation was enough to solve the problem,
> but at the execution stage my server stop in this portion of code.
>
> If somebody has an idea, I would be glad to hear it.
>
> I read some of other issues on the list archive but I didn't find my
> answer. Any way I thing that a bigger example of omniORB use, with
> sequence,
> should be present in the product archive.
>
> Server Execution:
> -----------------
> Get ORB reference
> Get the POA reference
> Create and activate the TimeImpl object
> Start the POA manager
> Stringify the TimeImpl reference
> Running ORB...
>
> Begin get_items
> itemList size = 3
> New sequence created
> Copy an item
>
> Client Execution:
> ------------------
> Starting the server
> Get ORB reference
> Destringify the Object reference
> Get a Time object from the reference
> Use the time service
> Time in GreenWich is 21:13:17
> Get a list of item and display it
> ERROR IN THE CLIENT
>
>
> IDL:
> -----
> module TIDL {
>          interface Item {
>                    attribute string name;
>          };
>          typedef sequence<Item> ItemSeq;
>          struct TimeOfDay {
>                    short hour;
>                    short minute;
>                    short second;
>          };
>          interface Time {
>                    TimeOfDay get_gmt();
>                    ItemSeq get_items();
>          };
> };
>
> Servant code: timeImpl.cc
> -------------------------
> using namespace TIDL;
>
> class ItemImpl : public POA_TIDL::Item,
>          public PortableServer::RefCountServantBase
> {
> public :
>          ItemImpl(char *n) { strcpy(d_name, n); };
>          virtual char *name() { return d_name; };
>          virtual void name(const char *n) { strcpy(d_name, n); };
>
>          char d_name[50];
> };
>
> class TimeImpl : public POA_TIDL::Time,
>          public PortableServer::RefCountServantBase
> {
> public :
>          virtual TimeOfDay get_gmt();
>          virtual ItemSeq*  get_items();
>
>          vector<ItemImpl> itemList;
> };
>
> TimeOfDay TimeImpl::get_gmt()
> {
>      TimeOfDay tod;
>      ... etc ..
>      return tod;
> }
>
> ItemSeq*  TimeImpl::get_items()
> {
>          cerr<<"Begin get_items"<<endl;
>          int len = itemList.size();
>          cerr<<"itemList size = "<<len<<endl;
>          ItemSeq* seq = new ItemSeq(len);
>          cerr<<"New sequence created"<<endl;
>
>          for (int i=0; i<len; i++)
>          {
>                    cerr<<"Copy an item"<<endl;
>                    (*seq)[i] = itemList[i]._this();   // FIXE ME !!
>          }
>
>          cerr<<"End get_items"<<endl;
>          return seq;
> }
>
> Server code: timeImpl.cc
> ------------------------
> int main(int argc, char * argv[])
> {
>          ... etc...
>          TimeImpl *mytime = new TimeImpl();
>
>          ItemImpl item = ItemImpl("A");
>          mytime->itemList.push_back( item );
>          item.name("simple");
>          mytime->itemList.push_back( item );
>          item.name("test");
>          mytime->itemList.push_back( item );
>
>          PortableServer::ObjectId_var mytimeid =
poa->activate_object(mytime);
>
>          Time_var mytimeref = mytime->_this();
>          mytime->_remove_ref();
>
>          ... etc ...
> }
>
> Client code:
> ------------
> int main(int argc, char * argv[])
> {
>          ... etc ...
>          cerr<<"Get a Time object from the reference"<<endl;
>          Time_var tm = Time::_narrow(obj);
>          if (CORBA::is_nil(tm)) {
>                    cerr<<"Argument is not a Time reference"<<endl;
>                    throw 0;
>          }
>
>          // Get time
>          cerr<<"Use the time service"<<endl;
>          TimeOfDay tod = tm->get_gmt();
>          ... etc ...
>
>          cout<<"Get a list of item and display it "<<endl;
>          ItemSeq *seq = tm->get_items();
>          cout<<"List taken"<<endl;
>          int len2 = seq->length();
>          for (int i=0; i<len2; i++)
>          {
>                    cout<<(*seq)[i]<<" ";
>          }
>
>          ... etc ...
> }
>
>
> --
> Laurent JOIGNY
> WesternGeco / Schlumberger / Houston
> phone : (+1) 713 689 6646
>
> _______________________________________________
> omniORB-list mailing list
> omniORB-list@omniorb-support.com
> http://www.omniorb-support.com/mailman/listinfo/omniorb-list
>
_______________________________________________
omniORB-list mailing list
omniORB-list@omniorb-support.com
http://www.omniorb-support.com/mailman/listinfo/omniorb-list