Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

apps/tutorials/vostut5client.cc

Go to the documentation of this file.
00001 /* Fifth VOS tutorial.  Introduction to Metaobjects.
00002 
00003    This tutorial file covers:
00004    - Accessing remote metaobjects
00005 
00006    This file (vostut5client.cc) is released into the public domain.  No
00007    restrictions are placed on its use, distribution or inclusion into
00008    other works.
00009 */
00010 
00011 // You must run this program after running vostut5server.
00012 
00013 #include <vos/corelibs/vos/vos.hh>
00014 #include <vos/metaobjects/property/property.hh>
00015 
00016 void listTypes(Vobject* vob);
00017 
00018 int main(int argc, char** argv)
00019 {
00020     cout << "VOS Tutorial 5 Client\n\n";
00021 
00022     LocalSocketSite localsite(&NoAccessControl::static_);
00023     localsite.setTimeoutOnSelect(-1);
00024 
00025     string siteurl;
00026     if(argc > 1) siteurl = argv[1];
00027     else siteurl = "vop://localhost:4231";
00028 
00029     Property::registerExtenders();
00030 
00031     // The purpose of this client part of vostut5 is simply to
00032     // demonstrate that the usage of meta_cast<> and the API for
00033     // Property are the same whether you accessing local or remote
00034     // vobjects.
00035 
00036     try {
00037         vRef<Vobject> position = Vobject::findObjectFromRoot(siteurl + "/planet/position");
00038 
00039         listTypes(&position);
00040 
00041         Property* positionproperty = MetaObject::meta_cast<Property*>(&position);
00042 
00043         cout << "vostut5client: The property value of " << positionproperty->getURL().getString()
00044              << " is now " << positionproperty->read() << endl;
00045 
00046     } catch(runtime_error& e) {
00047         cout << "Error!  " << e.what() << "\n";
00048     }
00049 }
00050 
00051 void listTypes(Vobject* vob)
00052 {
00053     // The type set is returned as an STL set<string>.  Simply use
00054     // standard iterators to iterate over the set.
00055 
00056     const Vobject::TypeSet& types = vob->getTypes();
00057 
00058     cout << "Types for " << vob->getURL().getString() << ": ";
00059     for(Vobject::TypeSet::const_iterator i = types.begin(); i != types.end(); i++)
00060     {
00061         if(i != types.begin()) cout << ", ";
00062         cout << (*i);
00063     }
00064     cout << "\n";
00065 }
00066 

Generated on Tue Aug 12 03:55:36 2003 for Interreality Project - VOS by doxygen 1.3.2