#  Fifth VOS tutorial.  Introduction to Metaobjects.
#
#    This tutorial file covers:
#    - Accessing remote metaobjects
#    - Using meta_cast
#
#    This file (vostut5client.py) is released into the public domain.  No
#    restrictions are placed on its use, distribution or inclusion into
#    other works.


# You must run this program after running vostut5server.

from vos import *
import sys
import traceback

def listTypes(vob):
    print "Types for " + vob.getURLstr() + ": "
    types = vob.getTypes()
    for type in types:
        print types
    print ""

print "VOS Tutorial 5 Client\n"

localsite = Site()
lvse = LocalVipSiteExtension()
localsite.addSiteExtension(lvse)
localsite.setDefaultPolicy("core:accept-all")

siteurl = ""
if( len( sys.argv ) > 1):
   siteurl = sys.argv[1]
else:
   siteurl = "vip://localhost:4231"

#  The purpose of this client part of vostut5 is simply to
#  demonstrate that the use of meta_cast<> and show that API for
#  Property are the same whether you accessing local or remote
#  vobjects.

try:
    position = Vobject.findObjectFromRoot(siteurl + "/planet/position")
    listTypes(position)

# To extract the Property class interface from the position
# vobject, we use the method meta_cast.

    positionproperty = meta_cast_Property(position)

    print "vostut5client: The property value of " + positionproperty.getURLstr()
    print " is now " + positionproperty.read()

except:
    print "exception :-/"
    print traceback.print_exc(file=sys.stdout)
