hrpPrep.py
Go to the documentation of this file.
00001 #
00002 # Prepare Scripting Environment Parameters
00003 #
00004 # This module can do with a little tidying up.
00005 # ... perhaps with a Meta-class
00006 #
00007 
00008 import time, string
00009 
00010 ####################################################################
00011 #
00012 # Functions for Jython
00013 #
00014 def doNarrow4Jython(corbaClass, corbaObject):
00015     return corbaClass.narrow(corbaObject)
00016 
00017 
00018 def getORBJython(argv):
00019     props = System.getProperties()
00020     s = System.getenv("NS_OPT")
00021     if(not s):
00022         s = System.getenv("NS_OPT")
00023         
00024     if(s == ''):
00025         args = argv
00026     else:
00027         args = string.split(s)
00028     #
00029     return CORBA.ORB.init(args, props)
00030 
00031 
00032 def getPluginObject2NarrowJython(name):
00033     #print 'getPluginObject2NarrowJython'
00034     try:
00035         exec('import Simulator.'+name+'Helper as localImport')
00036         return localImport
00037     except ImportError:
00038         return None
00039 
00040 #def importJavaPlugins():
00041 #    pluginList = dir(Simulator)
00042 #    for p in pluginList:
00043 #        if p[-6:] == 'Helper':
00044 #            print 'import Simulator.'+p+' as '+p[:-6]
00045 #            #exec('import Simulator.'+p+' as '+p[:-6])
00046 #
00047 ####################################################################
00048 
00049 
00050 ####################################################################
00051 #
00052 # Functions for Python+omniORB
00053 #
00054 def doNarrow4Python(corbaClass, corbaObject):
00055     #print 'corbaClass = ', corbaClass
00056     #print 'corbaObject = ', corbaObject
00057     try:
00058         tmp = corbaObject._narrow(corbaClass)
00059         #print 'narrowed result is', tmp
00060         return tmp
00061     except:
00062         print 'narrow exception:', corbaObject, 'to', corbaClass
00063 
00064     return None
00065 
00066 
00067 def getORBPython(argv):
00068     return CORBA.ORB_init(argv, CORBA.ORB_ID)
00069 
00070 
00071 def getPluginObject2NarrowPython(name):
00072     print name
00073     print 'getPluginObject2NarrowPython('+name+')'
00074     try:
00075         exec('from _GlobalIDL import '+name+' as localImport')
00076         return localImport
00077     except ImportError:
00078         return None
00079 #
00080 ####################################################################
00081 
00082 global doNarrow
00083 doNarrow = None
00084 
00085 try: # platform is Jython
00086     import java.lang.System as System
00087     print 'platform is probably Jython'
00088     import org.omg.CORBA as CORBA
00089     
00090     from org.omg.CosNaming import NameComponent
00091     from org.omg.CosNaming.NamingContextPackage import NotFound
00092     from jp.go.aist.hrp import simulator as IDLBase
00093     
00094     Platform = 'J'
00095     
00096     # Naming Context
00097     from org.omg.CosNaming import NamingContextHelper as NamingContext
00098     # Plugin Manager (fails here...)
00099     #from IDLBase import PluginManagerHelper as PluginManager
00100     #import IDLBase.PluginManagerHelper as PluginManager
00101     PluginManager = IDLBase.PluginManagerHelper
00102     # Command Receiver
00103     #from IDLBase import CommandReceiverHelper as CommandReceiver
00104     CommandReceiver = IDLBase.CommandReceiverHelper
00105     # Plugin
00106     #from IDLBase import PluginHelper as Plugin
00107     Plugin = IDLBase.PluginHelper
00108     # Logger Plugin
00109     #from IDLBase import LoggerPluginHelper as LoggerPlugin
00110     LoggerPlugin = IDLBase.LoggerPluginHelper
00111     # Sequence Player
00112     #from IDLBase import SequencePlayerHelper as SequencePlayer
00113     SequencePlayer = IDLBase.SequencePlayerHelper
00114 
00115     stateProvider = IDLBase.stateProviderHelper
00116     IoControPlugin = IDLBase.IoControlPluginHelper
00117     # set specialised function
00118     doNarrow = doNarrow4Jython
00119     getORB = getORBJython
00120     getPluginObject2Narrow = getPluginObject2NarrowJython
00121 
00122 except ImportError: # platform is not Jython
00123     print 'platform is probably CPython'
00124     import omniORB.CORBA as CORBA
00125     import CosNaming
00126     import _GlobalIDL as IDLBase
00127     
00128     NameComponent = CosNaming.NameComponent
00129     NotFound = CosNaming.NamingContext.NotFound
00130     
00131     Platform = 'C'
00132 
00133     # Naming Context
00134     NamingContext = CosNaming.NamingContext
00135     # Plugin Manager
00136     #from IDLBase import PluginManager
00137     PluginManager = IDLBase.PluginManager
00138     # Command Receiver
00139     #from IDLBase import CommandReceiver
00140     CommandReceiver = IDLBase.CommandReceiver
00141     # Plugin
00142     #from IDLBase import Plugin
00143     Plugin = IDLBase.Plugin
00144     # Logger Plugin
00145     #from IDLBase import LoggerPlugin
00146     LoggerPlugin = IDLBase.LoggerPlugin
00147     # Sequence Player
00148     #from IDLBase import SequencePlayer
00149     SequencePlayer = IDLBase.SequencePlayer
00150     # set specialised functions
00151     stateProvider = IDLBase.stateProvider
00152     IoControPlugin = IDLBase.IoControlPlugin
00153 
00154     doNarrow = doNarrow4Python
00155     getORB = getORBPython
00156     getPluginObject2Narrow = getPluginObject2NarrowPython
00157 
00158 #---------------------------------------------------#
00159 
00160 def getCORBAObjects():
00161     return NotFound, NamingContext, NameComponent, \
00162            IDLBase, \
00163            PluginManager, \
00164            Plugin, \
00165            CommandReceiver, \
00166            stateProvider, \
00167            IoControPlugin, \
00168            LoggerPlugin, \
00169            SequencePlayer


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sun Apr 2 2017 03:43:54