Skip to content

Commit c5e8ded

Browse files
committed
Merge pull request #23 from mpromonet/master
add pullpoint access
2 parents 07b1126 + edff553 commit c5e8ded

File tree

7 files changed

+583
-20
lines changed

7 files changed

+583
-20
lines changed

examples/events.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
# -*- coding: utf-8 -*-
2-
import os.path
32
from onvif import ONVIFCamera
43
__author__ = 'vahid'
54

65

7-
this_dir = os.path.abspath(os.path.dirname(__file__))
8-
wsdl_dir = os.path.abspath(os.path.join(this_dir, '../wsdl'))
9-
10-
def get_event_srv():
11-
mycam = ONVIFCamera('192.168.1.10', 8899, 'admin', 'admin', wsdl_dir) #, no_cache=True)
12-
#print mycam.devicemgmt.GetServices()
13-
event_service = mycam.create_events_service()
14-
return event_service
15-
16-
176
if __name__ == '__main__':
18-
e_service = get_event_srv()
19-
pp = e_service.GetEventProperties()
7+
mycam = ONVIFCamera('192.168.1.10', 8899, 'admin', 'admin') #, no_cache=True)
8+
event_service = mycam.create_events_service()
9+
print(event_service.GetEventProperties())
10+
11+
pullpoint = mycam.create_pullpoint_service()
12+
req = pullpoint.create_type('PullMessages')
13+
req.MessageLimit=100
14+
print(pullpoint.PullMessages(req))

onvif/client.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class ONVIFService(object):
6666
@safe_func
6767
def __init__(self, xaddr, user, passwd, url,
6868
cache_location='/tmp/suds', cache_duration=None,
69-
encrypt=True, daemon=False, ws_client=None, no_cache=False):
69+
encrypt=True, daemon=False, ws_client=None, no_cache=False, portType=None):
7070

7171
if not os.path.isfile(url):
7272
raise ONVIFError('%s doesn`t exist!' % url)
@@ -91,6 +91,7 @@ def __init__(self, xaddr, user, passwd, url,
9191
self.ws_client = Client(url=self.url,
9292
location=self.xaddr,
9393
cache=cache,
94+
port=portType,
9495
headers={'Content-Type': 'application/soap+xml'})
9596
else:
9697
self.ws_client = ws_client
@@ -240,6 +241,14 @@ def update_xaddrs(self):
240241
except Exception:
241242
logger.exception('Unexcept service type')
242243

244+
with self.services_lock:
245+
try:
246+
self.event = self.create_events_service()
247+
self.xaddrs['http://www.onvif.org/ver10/events/wsdl/PullPointSubscription'] = self.event.CreatePullPointSubscription().SubscriptionReference.Address
248+
except:
249+
pass
250+
251+
243252
def update_url(self, host=None, port=None):
244253
changed = False
245254
if host and self.host != host:
@@ -295,7 +304,7 @@ def get_definition(self, name):
295304
if not os.path.isfile(wsdlpath):
296305
raise ONVIFError('No such file: %s' % wsdlpath)
297306

298-
# XAddr for devicemgmt is fixd:
307+
# XAddr for devicemgmt is fixed:
299308
if name == 'devicemgmt':
300309
xaddr = 'http://%s:%s/onvif/device_service' % (self.host, self.port)
301310
return xaddr, wsdlpath
@@ -307,7 +316,7 @@ def get_definition(self, name):
307316

308317
return xaddr, wsdlpath
309318

310-
def create_onvif_service(self, name, from_template=True):
319+
def create_onvif_service(self, name, from_template=True, portType=None):
311320
'''Create ONVIF service client'''
312321

313322
name = name.lower()
@@ -323,14 +332,14 @@ def create_onvif_service(self, name, from_template=True):
323332
self.cache_duration,
324333
self.encrypt,
325334
self.daemon,
326-
no_cache=self.no_cache)
335+
no_cache=self.no_cache, portType=portType)
327336
# No template, create new service from wsdl document.
328337
# A little time-comsuming
329338
else:
330339
service = ONVIFService(xaddr, self.user, self.passwd,
331340
wsdl_file, self.cache_location,
332341
self.cache_duration, self.encrypt,
333-
self.daemon, no_cache=self.no_cache)
342+
self.daemon, no_cache=self.no_cache, portType=portType)
334343

335344
self.services[name] = service
336345

@@ -369,4 +378,7 @@ def create_search_service(self, from_template=True):
369378
return self.create_onvif_service('search', from_template)
370379

371380
def create_replay_service(self, from_template=True):
372-
return self.create_onvif_service('search', from_template)
381+
return self.create_onvif_service('replay', from_template)
382+
383+
def create_pullpoint_service(self, from_template=True):
384+
return self.create_onvif_service('pullpoint', from_template, portType='PullPointSubscription')

onvif/definition.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
'imaging' : {'ns': 'http://www.onvif.org/ver20/imaging/wsdl', 'wsdl': 'imaging.wsdl'},
77
'deviceio' : {'ns': 'http://www.onvif.org/ver10/deviceIO/wsdl', 'wsdl': 'deviceio.wsdl'},
88
'events' : {'ns': 'http://www.onvif.org/ver10/events/wsdl', 'wsdl': 'events.wsdl'},
9+
'pullpoint' : {'ns': 'http://www.onvif.org/ver10/events/wsdl/PullPointSubscription', 'wsdl': 'events.wsdl'},
910
'analytics' : {'ns': 'http://www.onvif.org/ver20/analytics/wsdl', 'wsdl': 'analytics.wsdl'},
1011
'recording' : {'ns': 'http://www.onvif.org/ver10/recording/wsdl', 'wsdl': 'recording.wsdl'},
1112
'search' : {'ns': 'http://www.onvif.org/ver10/search/wsdl', 'wsdl': 'search.wsdl'},

0 commit comments

Comments
 (0)