+# The _add DS_ handler
+#
+{
+my $add_ds_done;
+sub handle_line_add_ds
+{
+ my $line = shift;
+ my $index = shift;
+
+ my $post = sub { for (@_) { post_line ($_, $index + 1); } };
+
+ if (!@$NewDSes)
+ {
+ $post->($line);
+ return;
+ }
+
+ if (!$add_ds_done && ($line =~ m#<rra>#i))
+ {
+ for (my $i = 0; $i < @$NewDSes; $i++)
+ {
+ my $ds = $NewDSes->[$i];
+ my $temp;
+
+ my $min;
+ my $max;
+
+ if ($Debug)
+ {
+ print STDOUT "Adding DS: name = $ds->{'name'}, type = $ds->{'type'}, heartbeat = $ds->{'heartbeat'}, min = $ds->{'min'}, max = $ds->{'max'}\n";
+ }
+
+ $min = 'NaN';
+ if (defined ($ds->{'min'}) && ($ds->{'min'} ne 'U'))
+ {
+ $min = sprintf ('%.10e', $ds->{'min'});
+ }
+
+ $max = 'NaN';
+ if (defined ($ds->{'max'}) && ($ds->{'max'} ne 'U'))
+ {
+ $max = sprintf ('%.10e', $ds->{'max'});
+ }
+
+
+ $post->("\t<ds>\n",
+ "\t\t<name> $ds->{'name'} </name>\n",
+ "\t\t<type> $ds->{'type'} </type>\n",
+ "\t\t<minimal_heartbeat> $ds->{'heartbeat'} </minimal_heartbeat>\n",
+ "\t\t<min> $min </min>\n",
+ "\t\t<max> $max </max>\n",
+ "\n",
+ "\t\t<!-- PDP Status -->\n",
+ "\t\t<last_ds> UNKN </last_ds>\n",
+ "\t\t<value> NaN </value>\n",
+ "\t\t<unknown_sec> 0 </unknown_sec>\n",
+ "\t</ds>\n",
+ "\n");
+ }
+
+ $add_ds_done = 1;
+ }
+ elsif ($add_ds_done && ($line =~ m#</ds>#i)) # inside a cdp_prep block
+ {
+ $post->("\t\t\t</ds>\n",
+ "\t\t\t<ds>\n",
+ "\t\t\t<primary_value> NaN </primary_value>\n",
+ "\t\t\t<secondary_value> NaN </secondary_value>\n",
+ "\t\t\t<value> NaN </value>\n",
+ "\t\t\t<unknown_datapoints> 0 </unknown_datapoints>\n");
+ }
+ elsif ($line =~ m#<row>#i)
+ {
+ my $insert = '<v> NaN </v>' x (0 + @$NewDSes);
+ $line =~ s#</row>#$insert</row>#i;
+ }
+
+ $post->($line);
+}} # handle_line_add_ds
+
+#