interreality.org [VOS]
[Home] [About]
[Screenshots]
[Download]
[News]
[Community]
[Documentation] [Manual]
[Bugs & Requests] [Wiki]

/home/tetron/hack/vos/apps/tutorials/vostut7client.cc

Go to the documentation of this file.
00001 /* Seventh VOS tutorial.  Creating your own MetaObjects
00002 
00003    This tutorial covers:
00004    - Accessing our hello object remotely
00005 
00006    This file (vostut7client.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 #include "vostut7hello.hh"
00012 
00013 using namespace VUtil;
00014 using namespace VOS;
00015 
00016 int main(int argc, char** argv)
00017 {
00018     Site site;
00019     site.addSiteExtension(new LocalVipSiteExtension());
00020     site.setDefaultPolicy("core:accept-all");
00021 
00022     try {
00023         /* Use a path from the command line (or the default). */
00024         std::string siteurl;
00025         if(argc > 1) siteurl = argv[1];
00026         else siteurl = "vip://localhost:4231";
00027 
00028         LOG("helloclient", 1, "Acquiring remote object at " << siteurl);
00029 
00030         vRef<Vobject> v = Vobject::findObjectFromRoot(siteurl + "/hello");
00031 
00032         vRef<Hello> h = meta_cast<Hello>(v);
00033 
00034          LOG("helloclient", 1, "Saying 'Good day to you sir.'");
00035 
00036          // Call the hello method.  From the application's point of
00037          // view, it doesn't matter that it's a remote object.
00038          // Everything happens behind the scenes.
00039 
00040          std::string s = h->hello("Good day to you sir.");
00041 
00042          LOG("helloclient", 1, "Got back: '" << s << "'");
00043 
00044     } catch(NoSuchObjectError x){
00045         LOG("helloclient", 1, "NoSuchObjectError " << x.what());
00046     } catch(NoSuchSiteError x){
00047         LOG("helloclient", 1, "NoSuchSiteError " << x.what());
00048     } catch(AccessControlError x){
00049         LOG("helloclient", 1, "AccessControlError " << x.what());
00050     } catch(RemoteError x){
00051         LOG("helloclient", 1, "RemoteError " << x.what());
00052     } catch(BadURLError x){
00053         LOG("helloclient", 1, "BadURLError " << x.what());
00054     }
00055     return 0;
00056 }
00057