[omniORB] The Simple example not working :0)
Laurent JOIGNY
ljoigny@houston.westerngeco.slb.com
Thu Oct 10 22:22:01 2002
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