Skip to content

Commit

Permalink
Merge pull request #3734 from sletteland/onvif_events
Browse files Browse the repository at this point in the history
Onvif events
  • Loading branch information
connortechnology authored Jul 25, 2023
2 parents 5a497a7 + 8c754fb commit 4c69781
Show file tree
Hide file tree
Showing 9 changed files with 913 additions and 93 deletions.
654 changes: 654 additions & 0 deletions onvif/proxy/lib/ONVIF/PTZ/PTZ.pm

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions onvif/proxy/lib/ONVIF/PTZ/Types/PTZNode.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use base qw(SOAP::WSDL::XSD::Typelib::ComplexType);
Class::Std::initialize();

{ # BLOCK to scope variables

my %token_of :ATTR(:get<token>);
my %Name_of :ATTR(:get<Name>);
my %SupportedPTZSpaces_of :ATTR(:get<SupportedPTZSpaces>);
my %MaximumNumberOfPresets_of :ATTR(:get<MaximumNumberOfPresets>);
Expand All @@ -31,7 +31,8 @@ my %AuxiliaryCommands_of :ATTR(:get<AuxiliaryCommands>);
my %Extension_of :ATTR(:get<Extension>);

__PACKAGE__->_factory(
[ qw( Name
[ qw( token
Name
SupportedPTZSpaces
MaximumNumberOfPresets
HomeSupported
Expand All @@ -40,6 +41,7 @@ __PACKAGE__->_factory(
) ],
{
'token'=> \%token_of,
'Name' => \%Name_of,
'SupportedPTZSpaces' => \%SupportedPTZSpaces_of,
'MaximumNumberOfPresets' => \%MaximumNumberOfPresets_of,
Expand All @@ -48,6 +50,7 @@ __PACKAGE__->_factory(
'Extension' => \%Extension_of,
},
{
'token' => 'ONVIF::PTZ::Types::ReferenceToken',
'Name' => 'ONVIF::PTZ::Types::Name',
'SupportedPTZSpaces' => 'ONVIF::PTZ::Types::PTZSpaces',
'MaximumNumberOfPresets' => 'SOAP::WSDL::XSD::Typelib::Builtin::int',
Expand All @@ -57,6 +60,7 @@ __PACKAGE__->_factory(
},
{

'token' => 'token',
'Name' => 'Name',
'SupportedPTZSpaces' => 'SupportedPTZSpaces',
'MaximumNumberOfPresets' => 'MaximumNumberOfPresets',
Expand All @@ -76,17 +80,19 @@ use base qw(SOAP::WSDL::XSD::Typelib::AttributeSet);

{ # BLOCK to scope variables

my %token_of :ATTR(:get<token>);
my %FixedHomePosition_of :ATTR(:get<FixedHomePosition>);

__PACKAGE__->_factory(
[ qw(
[ qw( token
FixedHomePosition
) ],
{

token=> \%token_of,
FixedHomePosition => \%FixedHomePosition_of,
},
{
token => 'ONVIF::PTZ::Types::ReferenceToken',
FixedHomePosition => 'SOAP::WSDL::XSD::Typelib::Builtin::boolean',
}
);
Expand Down
55 changes: 55 additions & 0 deletions onvif/proxy/lib/WSNotification/Elements/Header.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

package WSNotification::Elements::Header;
use strict;
use warnings;


__PACKAGE__->_set_element_form_qualified(0);

sub get_xmlns { 'http://schemas.xmlsoap.org/soap/envelope/' };

our $XML_ATTRIBUTE_CLASS;
undef $XML_ATTRIBUTE_CLASS;

sub __get_attr_class {
return $XML_ATTRIBUTE_CLASS;
}

use Class::Std::Fast::Storable constructor => 'none';
use base qw(SOAP::WSDL::XSD::Typelib::ComplexType);
use Data::Dumper;

Class::Std::initialize();

{ # BLOCK to scope variables

my %Action_of :ATTR(:get<Action>);
my %MessageID_of :ATTR(:get<MessageID>);
my %ReplyTo_of :ATTR(:get<ReplyTo>);
my %To_of :ATTR(:get<To>);
__PACKAGE__->_factory(
[ qw( Action MessageID ReplyTo To ) ],
{
'Action' => \%Action_of,
'MessageID' => \%MessageID_of,
'ReplyTo' => \%ReplyTo_of,
'To' => \%To_of,
},
{
'Action' => 'WSNotification::Elements::Action',
'MessageID' => 'WSNotification::Elements::MessageID',
'ReplyTo' => 'WSNotification::Elements::ReplyTo',
'To' => 'WSNotification::Elements::To',
},
{
'Action' => '',
'MessageID' => '',
'ReplyTo' => '',
'To' => '',
}
);

} # end BLOCK


1;
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use warnings;
use Class::Std::Fast::Storable;
use Scalar::Util qw(blessed);
use base qw(SOAP::WSDL::Client::Base);
use Data::Dumper;

# only load if it hasn't been loaded before
require WSNotification::Typemaps::WSBaseNotificationSender
Expand All @@ -20,7 +21,7 @@ sub START {
sub Renew {
my ($self, $body, $header) = @_;
die "Renew must be called as object method (\$self is <$self>)" if not blessed($self);
return $self->SUPER::call({
return $self->SUPER::call({
operation => 'Renew',
soap_action => 'http://docs.oasis-open.org/wsn/bw-2/Renew',
style => 'document',
Expand All @@ -34,7 +35,10 @@ sub Renew {

},
header => {

'use' => 'literal',
namespace => 'http://schemas.xmlsoap.org/ws/2004/08/addressing',
encodingStyle => '',
parts => [qw( WSNotification::Elements::Header )],
},
headerfault => {

Expand Down
42 changes: 27 additions & 15 deletions scripts/zmonvif-trigger.pl.in
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ use Time::HiRes qw( usleep );

use SOAP::Lite; # +trace;
use SOAP::Transport::HTTP;

use Data::UUID;
use ZoneMinder;

require ONVIF::Client;
require WSNotification::Elements::Header;

require WSNotification::Interfaces::WSBaseNotificationSender::NotificationProducerPort;
require WSNotification::Interfaces::WSBaseNotificationSender::SubscriptionManagerPort;
Expand All @@ -74,6 +75,7 @@ my $daemon_pid;

my $monitor_reload_time = 0;


# this does not work on all architectures
my @EXTRA_SOCK_OPTS = (
'ReuseAddr' => '1',
Expand All @@ -87,9 +89,16 @@ my @EXTRA_SOCK_OPTS = (

sub handler { # 1st argument is signal name
my ($sig) = @_;
Error("Caught a SIG$sig -- shutting down");
confess();
kill($daemon_pid) if defined $daemon_pid;
# Error("Caught a SIG$sig --daemon_pid = $daemon_pid shutting down");
Info("Caught a SIG$sig ;;; daemon_pid = $daemon_pid");
if ( $daemon_pid != 0 ) {
Info( "killing child $daemon_pid \n") ;
kill(15 ,$daemon_pid) ;
Info(" sent kill signal to child , now waitpid...") ;
waitpid($daemon_pid, 0);
confess();
}
Info("Exiting ..") ;
exit(0);
}

Expand Down Expand Up @@ -215,6 +224,7 @@ sub xs_duration {
}

Info('Monitor URL: '.$monitor->{ONVIF_URL});
Info("In parent process ;;; child PID = $daemon_pid");

## set up ONVIF client for monitor
next if ! $monitor->{ONVIF_URL};
Expand Down Expand Up @@ -428,7 +438,6 @@ sub start_daemon {
$daemon_pid = fork();
die "fork() failed: $!" unless defined $daemon_pid;
if ( $daemon_pid ) {

# this is a new process --> use new name and log file
$0 = $0.' [http-daemon]';
logInit(id => 'zmonvif-trigger-httpd');
Expand Down Expand Up @@ -485,36 +494,39 @@ sub subscribe {
# },
},,
);

die $result if not $result;
# print $result . "\n";

### build Subscription Manager
my $submgr_addr = $result->get_SubscriptionReference()->get_Address()->get_value();
Info("Subscription Manager at $submgr_addr");

my $serializer = $client->service('device', 'ep')->get_serializer();

my $submgr_svc = WSNotification::Interfaces::WSBaseNotificationSender::SubscriptionManagerPort->new({
serializer => $serializer,
proxy => $submgr_addr,
});

},
);
return $submgr_svc;
} # end sub subscribe

sub unsubscribe {
my ($submgr_svc) = @_;

$submgr_svc->Unsubscribe( { },, );
}


sub renew {
my ($submgr_svc, $duration) = @_;

my $endpoint=$submgr_svc->get_endpoint();
my $uuid_gen = Data::UUID->new();
my $uuid = $uuid_gen->create_str();
my $result = $submgr_svc->Renew( {
TerminationTime => xs_duration($duration), # AbsoluteOrRelativeTimeType
},,
},
WSNotification::Elements::Header->new({
Action => { value => 'http://docs.oasis-open.org/wsn/bw-2/SubscriptionManager/RenewRequest' },
MessageID => { value => "urn:uuid:$uuid" },
To => { value => "$endpoint" },
# ReplyTo => { Address => { value => "http://www.w3.org/2005/08/addressing/anonymous" }},
})
);
die $result if not $result;
}
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ if(GSOAP_FOUND)
#COMMAND ${GSOAP_WSDL2H} -d -P -O2 -o ${CMAKE_BINARY_DIR}/generated/bindings.h http://www.onvif.org/onvif/ver10/events/wsdl/event.wsdl
#COMMAND echo '\#import \"wsse.h\"' >> ${CMAKE_BINARY_DIR}/generated/bindings.h
#COMMAND echo '\#import \"struct_timeval.h\"' >> ${CMAKE_BINARY_DIR}/generated/bindings.h
COMMAND ${GSOAP_SOAPCPP2} -n -2 -C -I ${GSOAP_PLUGIN_DIR}/.. -I ${GSOAP_PLUGIN_DIR}/../import/ -I ${GSOAP_PLUGIN_DIR}/../custom/ -d ${CMAKE_BINARY_DIR}/generated -j -x ${CMAKE_CURRENT_SOURCE_DIR}/bindings.h
COMMAND ${GSOAP_SOAPCPP2} -a -n -2 -C -I ${GSOAP_PLUGIN_DIR}/.. -I ${GSOAP_PLUGIN_DIR}/../import/ -I ${GSOAP_PLUGIN_DIR}/../custom/ -d ${CMAKE_BINARY_DIR}/generated -j -x ${CMAKE_CURRENT_SOURCE_DIR}/bindings.h
COMMENT "CREATING STUBS AND GLUE CODE"
)

Expand Down
1 change: 1 addition & 0 deletions src/bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -7747,3 +7747,4 @@ generated .h file in your code.
/* End of /home/jbennett/src/zoneminder/build/generated/bindings.h */
#import "wsse.h"
#import "struct_timeval.h"
#import "wsa5.h"
Loading

0 comments on commit 4c69781

Please sign in to comment.