Skip to content

Commit 18a311f

Browse files
author
Douglas Pew
committed
Returned to caching of domain object - added tests that add/remove waveforms outside pyrest and confirm sync
1 parent 749521d commit 18a311f

10 files changed

Lines changed: 454 additions & 72 deletions

File tree

model/domain.py

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import logging
2525
from ossie.utils import redhawk
2626
from ossie.utils.redhawk.channels import ODMListener
27+
import traceback
2728

2829

2930
def scan_domains():
@@ -64,6 +65,7 @@ class Domain:
6465
name = None
6566

6667
def __init__(self, domainname):
68+
logging.trace("Estasblishing domain %s", domainname, exc_info=True)
6769
self.name = domainname
6870
try:
6971
self._establish_domain()
@@ -76,6 +78,7 @@ def _odm_response(self, event):
7678
eventH.event_queue.put(event)
7779

7880
def _connect_odm_listener(self):
81+
7982
self.odmListener = ODMListener()
8083
self.odmListener.connect(self.domMgr_ptr)
8184
self.odmListener.deviceManagerAdded.addListener(self._odm_response)
@@ -86,6 +89,7 @@ def _connect_odm_listener(self):
8689
def _establish_domain(self):
8790
redhawk.setTrackApps(False)
8891
self.domMgr_ptr = redhawk.attach(str(self.name))
92+
self.domMgr_ptr.__odmListener = None
8993
self._connect_odm_listener()
9094

9195
def properties(self):
@@ -216,29 +220,3 @@ def services(self, dev_mgr_id):
216220
ret_dict.append({'name': svc._instanceName, 'id': svc._refid})
217221
return ret_dict
218222

219-
@staticmethod
220-
def locate_by_path(path, path_type):
221-
'''
222-
Locates a redhawk object with the given path, and path type.
223-
Returns the object + remaining path:
224-
225-
comp, opath = locate(ipath, 'component')
226-
227-
228-
Valid path types are:
229-
'application' - [ domain id, application-id ]
230-
'component' - [ domain id, application-id, component-id ]
231-
'device-mgr' - [ domain id, device-manager-id ]
232-
'device' - [ domain id, device-manager-id, device-id ]
233-
'''
234-
domain = Domain(path[0])
235-
if path_type == 'application':
236-
return domain.find_app(path[1]), path[2:]
237-
elif path_type == 'component':
238-
return domain.find_component(path[1], path[2]), path[3:]
239-
elif path_type == 'device-mgr':
240-
return domain.find_device_manager(path[1]), path[2:]
241-
elif path_type == 'device':
242-
return domain.find_device(path[1], path[2]), path[3:]
243-
raise ValueError("Bad path type %s. Must be one of application, component, device-mgr or device" % path_type)
244-

model/redhawk.py

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,19 @@
2626

2727
from _utils.tasking import background_task
2828

29-
from domain import Domain, scan_domains
29+
from domain import Domain, scan_domains, ResourceNotFound
3030

3131

3232
class Redhawk(object):
3333
__domains = {}
3434

3535
def _get_domain(self, domain_name):
3636
name = str(domain_name)
37-
# if not name in self.__domains:
38-
# self.__domains[name] = Domain(domain_name)
39-
#
40-
# return self.__domains[name]
41-
return Domain(domain_name)
42-
37+
if not name in self.__domains:
38+
self.__domains[name] = Domain(domain_name)
39+
40+
return self.__domains[name]
41+
4342
##############################
4443
# DOMAIN
4544

@@ -144,3 +143,33 @@ def get_device(self, domain_name, device_manager_id, device_id):
144143
def get_service_list(self, domain_name, device_manager_id):
145144
dom = self._get_domain(domain_name)
146145
return dom.services(device_manager_id)
146+
147+
##############################
148+
# GENERIC
149+
150+
@background_task
151+
def get_object_by_path(self, path, path_type):
152+
'''
153+
Locates a redhawk object with the given path, and path type.
154+
Returns the object + remaining path:
155+
156+
comp, opath = locate(ipath, 'component')
157+
158+
159+
Valid path types are:
160+
'application' - [ domain id, application-id ]
161+
'component' - [ domain id, application-id, component-id ]
162+
'device-mgr' - [ domain id, device-manager-id ]
163+
'device' - [ domain id, device-manager-id, device-id ]
164+
'''
165+
domain = self._get_domain(path[0])
166+
if path_type == 'application':
167+
return domain.find_app(path[1]), path[2:]
168+
elif path_type == 'component':
169+
return domain.find_component(path[1], path[2]), path[3:]
170+
elif path_type == 'device-mgr':
171+
return domain.find_device_manager(path[1]), path[2:]
172+
elif path_type == 'device':
173+
return domain.find_device(path[1], path[2]), path[3:]
174+
raise ValueError("Bad path type %s. Must be one of application, component, device-mgr or device" % path_type)
175+

pyrest.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,34 @@ def __init__(self, *args, **kwargs):
6969
# Domains
7070
(_DOMAIN_PATH + _LIST, DomainInfo, dict(redhawk=redhawk)),
7171
(_DOMAIN_PATH + _ID, DomainInfo, dict(redhawk=redhawk)),
72-
(_DOMAIN_PATH + _ID + _PROPERTIES_PATH + _LIST, DomainProperties, dict(redhawk=redhawk)),
73-
(_DOMAIN_PATH + _ID + _PROPERTIES_PATH + _ID, DomainProperties, dict(redhawk=redhawk)),
72+
(_DOMAIN_PATH + _ID + _PROPERTIES_PATH + _LIST, DomainProperties,
73+
dict(redhawk=redhawk)),
74+
(_DOMAIN_PATH + _ID + _PROPERTIES_PATH + _ID, DomainProperties,
75+
dict(redhawk=redhawk)),
7476

7577
# Applications
7678
(_APPLICATION_PATH + _LIST, Applications, dict(redhawk=redhawk)),
7779
(_APPLICATION_PATH + _ID, Applications, dict(redhawk=redhawk)),
78-
(_APPLICATION_PATH + _ID + _PORT_PATH + _LIST, PortHandler, dict(kind='application')),
79-
(_APPLICATION_PATH + _ID + _PORT_PATH + _ID, PortHandler, dict(kind='application')),
80-
(_APPLICATION_PATH + _ID + _BULKIO_PATH, BulkIOWebsocketHandler, dict(kind='application', _ioloop=_ioloop)),
80+
(_APPLICATION_PATH + _ID + _PORT_PATH + _LIST, PortHandler,
81+
dict(redhawk=redhawk, kind='application')),
82+
(_APPLICATION_PATH + _ID + _PORT_PATH + _ID, PortHandler,
83+
dict(redhawk=redhawk, kind='application')),
84+
(_APPLICATION_PATH + _ID + _BULKIO_PATH, BulkIOWebsocketHandler,
85+
dict(redhawk=redhawk, kind='application', _ioloop=_ioloop)),
8186

8287
# Components
8388
(_COMPONENT_PATH + _LIST, Component, dict(redhawk=redhawk)),
8489
(_COMPONENT_PATH + _ID, Component, dict(redhawk=redhawk)),
85-
(_COMPONENT_PATH + _ID + _PROPERTIES_PATH + _LIST, ComponentProperties, dict(redhawk=redhawk)),
86-
(_COMPONENT_PATH + _ID + _PROPERTIES_PATH + _ID, ComponentProperties, dict(redhawk=redhawk)),
87-
(_COMPONENT_PATH + _ID + _PORT_PATH + _LIST, PortHandler, dict(kind='component')),
88-
(_COMPONENT_PATH + _ID + _PORT_PATH + _ID, PortHandler, dict(kind='component')),
89-
(_COMPONENT_PATH + _ID + _BULKIO_PATH, BulkIOWebsocketHandler, dict(kind='component', _ioloop=_ioloop)),
90+
(_COMPONENT_PATH + _ID + _PROPERTIES_PATH + _LIST, ComponentProperties,
91+
dict(redhawk=redhawk)),
92+
(_COMPONENT_PATH + _ID + _PROPERTIES_PATH + _ID, ComponentProperties,
93+
dict(redhawk=redhawk)),
94+
(_COMPONENT_PATH + _ID + _PORT_PATH + _LIST, PortHandler,
95+
dict(redhawk=redhawk, kind='component')),
96+
(_COMPONENT_PATH + _ID + _PORT_PATH + _ID, PortHandler,
97+
dict(redhawk=redhawk, kind='component')),
98+
(_COMPONENT_PATH + _ID + _BULKIO_PATH, BulkIOWebsocketHandler,
99+
dict(redhawk=redhawk, kind='component', _ioloop=_ioloop)),
90100

91101
# Device Managers
92102
(_DEVICE_MGR_PATH + _LIST, DeviceManagers, dict(redhawk=redhawk)),
@@ -95,11 +105,16 @@ def __init__(self, *args, **kwargs):
95105
# Devices
96106
(_DEVICE_PATH + _LIST, Devices, dict(redhawk=redhawk)),
97107
(_DEVICE_PATH + _ID, Devices, dict(redhawk=redhawk)),
98-
(_DEVICE_PATH + _ID + _PROPERTIES_PATH + _LIST, DeviceProperties, dict(redhawk=redhawk)),
99-
(_DEVICE_PATH + _ID + _PROPERTIES_PATH + _ID, DeviceProperties, dict(redhawk=redhawk)),
100-
(_DEVICE_PATH + _ID + _PORT_PATH + _LIST, PortHandler, dict(kind='device')),
101-
(_DEVICE_PATH + _ID + _PORT_PATH + _ID, PortHandler, dict(kind='device')),
102-
(_DEVICE_PATH + _ID + _BULKIO_PATH, BulkIOWebsocketHandler, dict(kind='device', _ioloop=_ioloop)),
108+
(_DEVICE_PATH + _ID + _PROPERTIES_PATH + _LIST, DeviceProperties,
109+
dict(redhawk=redhawk)),
110+
(_DEVICE_PATH + _ID + _PROPERTIES_PATH + _ID, DeviceProperties,
111+
dict(redhawk=redhawk)),
112+
(_DEVICE_PATH + _ID + _PORT_PATH + _LIST, PortHandler,
113+
dict(redhawk=redhawk, kind='device')),
114+
(_DEVICE_PATH + _ID + _PORT_PATH + _ID, PortHandler,
115+
dict(redhawk=redhawk, kind='device')),
116+
(_DEVICE_PATH + _ID + _BULKIO_PATH, BulkIOWebsocketHandler,
117+
dict(redhawk=redhawk, kind='device', _ioloop=_ioloop)),
103118
]
104119
tornado.web.Application.__init__(self, handlers, *args, **kwargs)
105120

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
tornado==4.0.1
1+
tornado==4.0.2
22
futures==2.1.6

rest/bulkio_handler.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from bulkio.bulkioInterfaces import BULKIO__POA
2424

2525
# third party imports
26-
from tornado import ioloop
26+
from tornado import ioloop, gen
2727
from tornado import websocket
2828

2929
import numpy
@@ -61,16 +61,18 @@ class BulkIOWebsocketHandler(websocket.WebSocketHandler):
6161
'dataShort': _pass_through
6262
}
6363

64-
def initialize(self, kind, _ioloop=None):
64+
def initialize(self, kind, redhawk=None, _ioloop=None):
6565
self.kind = kind
66+
self.redhawk = redhawk
6667
if not _ioloop:
6768
_ioloop = ioloop.IOLoop.current()
6869
self._ioloop = _ioloop
6970

71+
@gen.coroutine
7072
def open(self, *args):
7173
try:
7274
logging.debug("BulkIOWebsocketHandler open kind=%s, path=%s", self.kind, args)
73-
obj, path = Domain.locate_by_path(args, path_type=self.kind)
75+
obj, path = yield self.redhawk.get_object_by_path(args, path_type=self.kind)
7476
logging.debug("Found object %s", dir(obj))
7577

7678
for p in obj.ports:

rest/port.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,28 @@
2424
import logging
2525
from tornado import web, ioloop
2626
from helper import PortHelper
27-
from model.domain import Domain, ResourceNotFound
27+
from model.domain import ResourceNotFound
28+
from tornado import gen
29+
2830
import json
2931

32+
from handler import JsonHandler
33+
from helper import PropertyHelper
3034

31-
class PortHandler(web.RequestHandler, PortHelper):
35+
class PortHandler(JsonHandler, PropertyHelper, PortHelper):
3236

33-
def initialize(self, kind, _ioloop=None):
37+
def initialize(self, kind, redhawk=None, _ioloop=None):
38+
super(PortHandler, self).initialize(redhawk)
3439
self.kind = kind
3540
if not _ioloop:
3641
_ioloop = ioloop.IOLoop.current()
3742
self._ioloop = _ioloop
3843

44+
@gen.coroutine
3945
def get(self, *args):
4046
try:
4147
logging.debug("port kind=%s, path=%s", self.kind, args)
42-
obj, path = Domain.locate_by_path(args, path_type=self.kind)
48+
obj, path = yield self.redhawk.get_object_by_path(args, path_type=self.kind)
4349
logging.debug("Found object %s", dir(obj))
4450
if path:
4551
name = path[0]

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@
3838
from component import ComponentTests
3939
from bulkio import BulkIOTests
4040
from port import PortTests
41+
from concurrent import ConcurrencyTests

0 commit comments

Comments
 (0)