added empty ParameterKey to make SetParameterValues work
[perl-cwmp.git] / lib / CWMP / Methods.pm
index ab77c99..3a2aa68 100644 (file)
@@ -51,17 +51,16 @@ sub xml {
        confess "no state?" unless ($state);
        confess "no body closure" unless ( $closure );
 
-       confess "no ID in state ", dump( $state ) unless ( $state->{ID} );
-
        #warn "state used to generate xml = ", dump( $state ) if $self->debug;
 
        my $X = XML::Generator->new(':pretty');
 
+       my @header;
+       push( @header, $X->ID( $cwmp, { mustUnderstand => 1 }, $state->{ID} )) if $state->{ID};
+       push( @header, $X->NoMoreRequests( $cwmp, $state->{NoMoreRequests} || 0 ));
+
        return $X->Envelope( $soap, { 'soap:encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/" },
-               $X->Header( $soap,
-                       $X->ID( $cwmp, { mustUnderstand => 1 }, $state->{ID} ),
-                       $X->NoMoreRequests( $cwmp, $state->{NoMoreRequests} || 0 ),
-               ),
+               $X->Header( $soap, @header ),
                $X->Body( $soap, $closure->( $X, $state ) ),
        );
 }
@@ -78,17 +77,17 @@ sub GetRPCMethods {
        my ( $self, $state ) = @_;
        $self->xml( $state, sub {
                my ( $X, $state ) = @_;
-               $X->GetRPCMethods();
+               $X->GetRPCMethods( $cwmp, '' );
        });
 };
 
 =head2 SetParameterValues
 
-  $method->SetParameterValues( $state,
+  $method->SetParameterValues( $state, {
        param1 => 'value1',
        param2 => 'value2',
        ...
-  );
+  });
 
 It doesn't support base64 encoding of values yet.
 
@@ -103,33 +102,23 @@ sub SetParameterValues {
 
        confess "SetParameterValues needs parameters" unless @_;
 
-       my @params = @_;
-
-       my ( @names, @values );
-
-       while ( @_ ) {
-               push @names, shift @_;
-               push @values, shift @_;
-       }
-
-       confess "can't convert params ", dump( @params ), " to name/value pairs" unless $#names == $#values;
+       my $params = shift || return;
 
-       warn "# SetParameterValues", dump( @params ), "\n" if $self->debug;
+       warn "# SetParameterValues = ", dump( $params ), "\n" if $self->debug;
 
        $self->xml( $state, sub {
                my ( $X, $state ) = @_;
 
                $X->SetParameterValues( $cwmp,
-                       $X->ParameterList( $cwmp,
-                               $X->ParameterNames( $cwmp,
-                                       map {
-                                               $X->ParameterValueStruct( $cwmp,
-                                                       $X->Name( $cwmp, $_ ),
-                                                       $X->Value( $cwmp, shift @values )
-                                               )
-                                       } @names
-                               )
-                       )
+                       $X->ParameterList( [],
+                               map {
+                                       $X->ParameterValueStruct( [],
+                                               $X->Name( [], $_ ),
+                                               $X->Value( [], $params->{$_} )
+                                       )
+                               } sort keys %$params
+                       ),
+                       $X->ParameterKey( '' ),
                );
        });
 }
@@ -137,15 +126,20 @@ sub SetParameterValues {
 
 =head2 GetParameterValues
 
-  $method->GetParameterValues( $state, $ParameterNames );
+  $method->GetParameterValues( $state, [ 'ParameterName', ... ] );
 
 =cut
 
+sub _array_param {
+       my $v = shift;
+       confess "array_mandatory(",dump($v),") isn't ARRAY" unless ref($v) eq 'ARRAY';
+       return @$v;
+}
+
 sub GetParameterValues {
        my $self = shift;
        my $state = shift;
-       my @ParameterNames = @_;
-       confess "GetParameterValues need ParameterNames" unless @ParameterNames;
+       my @ParameterNames = _array_param(shift);
        warn "# GetParameterValues", dump( @ParameterNames ), "\n" if $self->debug;
 
        $self->xml( $state, sub {
@@ -163,14 +157,16 @@ sub GetParameterValues {
 
 =head2 GetParameterNames
 
-  $method->GetParameterNames( $state, $ParameterPath, $NextLevel );
+  $method->GetParameterNames( $state, [ $ParameterPath, $NextLevel ] );
 
 =cut
 
 sub GetParameterNames {
-       my ( $self, $state, $ParameterPath, $NextLevel ) = @_;
-       $ParameterPath ||= '';  # all
-       $NextLevel ||= 0;               # all
+       my ( $self, $state, $param ) = @_;
+       # default: all, all
+       my ( $ParameterPath, $NextLevel ) = _array_param( $param );
+       $ParameterPath ||= '';
+       $NextLevel ||= 0;
        warn "# GetParameterNames( '$ParameterPath', $NextLevel )\n" if $self->debug;
        $self->xml( $state, sub {
                my ( $X, $state ) = @_;
@@ -182,6 +178,31 @@ sub GetParameterNames {
        });
 }
 
+=head2 GetParameterAttributes
+
+       $method->GetParameterAttributes( $state, [ $ParametarNames, ... ] );
+
+=cut
+
+sub GetParameterAttributes {
+       my ( $self, $state, $param ) = @_;
+       my @ParameterNames = _array_param($param);
+
+       warn "# GetParameterAttributes", dump( @ParameterNames ), "\n" if $self->debug;
+
+       $self->xml( $state, sub {
+               my ( $X, $state ) = @_;
+
+               $X->GetParameterAttributes( $cwmp,
+                       $X->ParameterNames( $cwmp,
+                               map {
+                                       $X->string( $xsd, $_ )
+                               } @ParameterNames
+                       )
+               );
+       });
+}
+
 =head2 Reboot
 
   $method->Reboot( $state );
@@ -196,6 +217,20 @@ sub Reboot {
        });
 }
 
+=head2 FactoryReset
+
+  $method->FactoryReset( $state );
+
+=cut
+
+sub FactoryReset {
+       my ( $self, $state ) = @_;
+       $self->xml( $state, sub {
+               my ( $X, $state ) = @_;
+               $X->FactoryReset();
+       });
+}
+
 
 =head1 Server methods