added stdurl session option
(Boeing r1839)
This commit is contained in:
parent
57022b7ca6
commit
7bc3fa99a0
2 changed files with 32 additions and 11 deletions
|
@ -13,6 +13,7 @@ from core.constants import *
|
||||||
from core.api import coreapi
|
from core.api import coreapi
|
||||||
from coreobj import PyCoreNet, PyCoreObj
|
from coreobj import PyCoreNet, PyCoreObj
|
||||||
from core.netns import nodes
|
from core.netns import nodes
|
||||||
|
from urlparse import urlparse
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
class Sdt(object):
|
class Sdt(object):
|
||||||
|
@ -20,7 +21,7 @@ class Sdt(object):
|
||||||
The connect() method initializes the display, and can be invoked
|
The connect() method initializes the display, and can be invoked
|
||||||
when a node position or link has changed.
|
when a node position or link has changed.
|
||||||
'''
|
'''
|
||||||
DEFAULT_SDT_PORT = 5000
|
DEFAULT_SDT_URL = "tcp://127.0.0.1:50000/"
|
||||||
# default altitude (in meters) for flyto view
|
# default altitude (in meters) for flyto view
|
||||||
DEFAULT_ALT = 2500
|
DEFAULT_ALT = 2500
|
||||||
# TODO: read in user's nodes.conf here; below are default node types
|
# TODO: read in user's nodes.conf here; below are default node types
|
||||||
|
@ -45,7 +46,7 @@ class Sdt(object):
|
||||||
self.connected = False
|
self.connected = False
|
||||||
self.showerror = True
|
self.showerror = True
|
||||||
self.verbose = self.session.getcfgitembool('verbose', False)
|
self.verbose = self.session.getcfgitembool('verbose', False)
|
||||||
self.address = ("127.0.0.1", self.DEFAULT_SDT_PORT)
|
self.url = self.DEFAULT_SDT_URL
|
||||||
# node information for remote nodes not in session._objs
|
# node information for remote nodes not in session._objs
|
||||||
# local nodes also appear here since their obj may not exist yet
|
# local nodes also appear here since their obj may not exist yet
|
||||||
self.remotes = {}
|
self.remotes = {}
|
||||||
|
@ -59,7 +60,7 @@ class Sdt(object):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def connect(self, flags=0):
|
def connect(self, flags=0):
|
||||||
''' Connect to the SDT UDP port if enabled.
|
''' Connect to the SDT address/port if enabled.
|
||||||
'''
|
'''
|
||||||
if not self.is_enabled():
|
if not self.is_enabled():
|
||||||
return False
|
return False
|
||||||
|
@ -67,15 +68,32 @@ class Sdt(object):
|
||||||
return True
|
return True
|
||||||
if self.session.getstate() == coreapi.CORE_EVENT_SHUTDOWN_STATE:
|
if self.session.getstate() == coreapi.CORE_EVENT_SHUTDOWN_STATE:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if hasattr(self.session.options,'sdturl'):
|
||||||
|
self.url = urlparse(self.session.options.sdturl)
|
||||||
|
if self.session.options.sdturl == "":
|
||||||
|
self.url = urlparse(self.DEFAULT_SDT_URL)
|
||||||
|
if self.showerror:
|
||||||
|
self.session.info("sdturl: %s invalid. Using default sdturl %s" % \
|
||||||
|
(self.session.options.sdturl, \
|
||||||
|
self.DEFAULT_SDT_URL))
|
||||||
|
|
||||||
|
self.address = (self.url.hostname,self.url.port)
|
||||||
|
self.protocol = self.url.scheme
|
||||||
if self.showerror:
|
if self.showerror:
|
||||||
self.session.info("connecting to SDT at %s:%s" % self.address)
|
self.session.info("connecting to SDT at %s://%s" \
|
||||||
|
% (self.protocol, self.address))
|
||||||
if self.sock is None:
|
if self.sock is None:
|
||||||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
try:
|
||||||
try:
|
if (self.protocol.lower() == 'udp'):
|
||||||
self.sock.connect(self.address)
|
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
except Exception, e:
|
self.sock.connect(self.address)
|
||||||
self.session.warn("SDT socket connect error: %s" % e)
|
else:
|
||||||
return False
|
# Default to tcp
|
||||||
|
self.sock = socket.create_connection(self.address,5)
|
||||||
|
except Exception, e:
|
||||||
|
self.session.warn("SDT socket connect error: %s" % e)
|
||||||
|
return False
|
||||||
if not self.initialize():
|
if not self.initialize():
|
||||||
return False
|
return False
|
||||||
self.connected = True
|
self.connected = True
|
||||||
|
@ -129,6 +147,7 @@ class Sdt(object):
|
||||||
if self.showerror:
|
if self.showerror:
|
||||||
self.session.warn("SDT connection error: %s" % e)
|
self.session.warn("SDT connection error: %s" % e)
|
||||||
self.showerror = False
|
self.showerror = False
|
||||||
|
self.sock = None
|
||||||
self.connected = False
|
self.connected = False
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
@ -999,6 +999,8 @@ class SessionConfig(ConfigurableManager, Configurable):
|
||||||
'Preserve session dir'),
|
'Preserve session dir'),
|
||||||
("enablesdt", coreapi.CONF_DATA_TYPE_BOOL, '0', 'On,Off',
|
("enablesdt", coreapi.CONF_DATA_TYPE_BOOL, '0', 'On,Off',
|
||||||
'Enable SDT3D output'),
|
'Enable SDT3D output'),
|
||||||
|
("sdturl", coreapi.CONF_DATA_TYPE_STRING, '', '',
|
||||||
|
'SDT3D URL'),
|
||||||
]
|
]
|
||||||
_confgroups = "Options:1-%d" % len(_confmatrix)
|
_confgroups = "Options:1-%d" % len(_confmatrix)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue