From 639c835bc2730a4fbffd915f5b2028a68375ee7a Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Wed, 28 Jul 2010 14:30:32 -0700 Subject: add new cstore library --- perl_dmod/.gitignore | 2 + perl_dmod/Cstore/.gitignore | 5 + perl_dmod/Cstore/Changes | 6 + perl_dmod/Cstore/Cstore.xs | 299 +++++++++++++++++++++++++++++++++++++++++ perl_dmod/Cstore/MANIFEST | 7 + perl_dmod/Cstore/Makefile.PL | 88 ++++++++++++ perl_dmod/Cstore/README | 33 +++++ perl_dmod/Cstore/lib/Cstore.pm | 96 +++++++++++++ perl_dmod/Cstore/t/Cstore.t | 15 +++ perl_dmod/Cstore/typemap | 68 ++++++++++ perl_dmod/Makefile.am | 25 ++++ 11 files changed, 644 insertions(+) create mode 100644 perl_dmod/.gitignore create mode 100644 perl_dmod/Cstore/.gitignore create mode 100644 perl_dmod/Cstore/Changes create mode 100644 perl_dmod/Cstore/Cstore.xs create mode 100644 perl_dmod/Cstore/MANIFEST create mode 100644 perl_dmod/Cstore/Makefile.PL create mode 100644 perl_dmod/Cstore/README create mode 100644 perl_dmod/Cstore/lib/Cstore.pm create mode 100644 perl_dmod/Cstore/t/Cstore.t create mode 100644 perl_dmod/Cstore/typemap create mode 100644 perl_dmod/Makefile.am (limited to 'perl_dmod') diff --git a/perl_dmod/.gitignore b/perl_dmod/.gitignore new file mode 100644 index 0000000..b336cc7 --- /dev/null +++ b/perl_dmod/.gitignore @@ -0,0 +1,2 @@ +/Makefile +/Makefile.in diff --git a/perl_dmod/Cstore/.gitignore b/perl_dmod/Cstore/.gitignore new file mode 100644 index 0000000..7082d2a --- /dev/null +++ b/perl_dmod/Cstore/.gitignore @@ -0,0 +1,5 @@ +/Makefile +/Cstore.bs +/Cstore.cpp +/blib +/pm_to_blib diff --git a/perl_dmod/Cstore/Changes b/perl_dmod/Cstore/Changes new file mode 100644 index 0000000..15e5188 --- /dev/null +++ b/perl_dmod/Cstore/Changes @@ -0,0 +1,6 @@ +Revision history for Perl extension Cstore. + +0.01 Tue Jun 15 12:03:35 2010 + - original version; created by h2xs 1.23 with options + -c --skip-ppport -n Cstore + diff --git a/perl_dmod/Cstore/Cstore.xs b/perl_dmod/Cstore/Cstore.xs new file mode 100644 index 0000000..5dd105e --- /dev/null +++ b/perl_dmod/Cstore/Cstore.xs @@ -0,0 +1,299 @@ +/* + * Copyright (C) 2010 Vyatta, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "EXTERN.h" +#include "perl.h" +#include "XSUB.h" + +/* these macros are defined in perl headers but conflict with C++ headers */ +#undef do_open +#undef do_close + +#include +#include +#include +#include + +/* currently use the UnionfsCstore implementation */ +#include + +typedef SV STRVEC; +typedef SV STRSTRMAP; + +MODULE = Cstore PACKAGE = Cstore + + +Cstore * +Cstore::new() +CODE: + RETVAL = new UnionfsCstore(); +OUTPUT: + RETVAL + + +bool +Cstore::cfgPathExists(STRVEC *vref, bool active_cfg) +PREINIT: + vector arg_strvec; +CODE: + RETVAL = THIS->cfgPathExists(arg_strvec, active_cfg); +OUTPUT: + RETVAL + + +STRVEC * +Cstore::cfgPathGetChildNodes(STRVEC *vref, bool active_cfg) +PREINIT: + vector arg_strvec; +CODE: + vector ret_strvec; + THIS->cfgPathGetChildNodes(arg_strvec, ret_strvec, active_cfg); +OUTPUT: + RETVAL + + +SV * +Cstore::cfgPathGetValue(STRVEC *vref, bool active_cfg) +PREINIT: + vector arg_strvec; +CODE: + string value; + if (THIS->cfgPathGetValue(arg_strvec, value, active_cfg)) { + RETVAL = newSVpv(value.c_str(), 0); + } else { + XSRETURN_UNDEF; + } +OUTPUT: + RETVAL + + +STRVEC * +Cstore::cfgPathGetValues(STRVEC *vref, bool active_cfg) +PREINIT: + vector arg_strvec; +CODE: + vector ret_strvec; + THIS->cfgPathGetValues(arg_strvec, ret_strvec, active_cfg); +OUTPUT: + RETVAL + + +bool +Cstore::cfgPathEffective(STRVEC *vref) +PREINIT: + vector arg_strvec; +CODE: + RETVAL = THIS->cfgPathEffective(arg_strvec); +OUTPUT: + RETVAL + + +STRVEC * +Cstore::cfgPathGetEffectiveChildNodes(STRVEC *vref) +PREINIT: + vector arg_strvec; +CODE: + vector ret_strvec; + THIS->cfgPathGetEffectiveChildNodes(arg_strvec, ret_strvec); +OUTPUT: + RETVAL + + +SV * +Cstore::cfgPathGetEffectiveValue(STRVEC *vref) +PREINIT: + vector arg_strvec; +CODE: + string value; + if (THIS->cfgPathGetEffectiveValue(arg_strvec, value)) { + RETVAL = newSVpv(value.c_str(), 0); + } else { + XSRETURN_UNDEF; + } +OUTPUT: + RETVAL + + +STRVEC * +Cstore::cfgPathGetEffectiveValues(STRVEC *vref) +PREINIT: + vector arg_strvec; +CODE: + vector ret_strvec; + THIS->cfgPathGetEffectiveValues(arg_strvec, ret_strvec); +OUTPUT: + RETVAL + + +bool +Cstore::cfgPathDeleted(STRVEC *vref) +PREINIT: + vector arg_strvec; +CODE: + RETVAL = THIS->cfgPathDeleted(arg_strvec); +OUTPUT: + RETVAL + + +bool +Cstore::cfgPathAdded(STRVEC *vref) +PREINIT: + vector arg_strvec; +CODE: + RETVAL = THIS->cfgPathAdded(arg_strvec); +OUTPUT: + RETVAL + + +bool +Cstore::cfgPathChanged(STRVEC *vref) +PREINIT: + vector arg_strvec; +CODE: + RETVAL = THIS->cfgPathChanged(arg_strvec); +OUTPUT: + RETVAL + + +STRVEC * +Cstore::cfgPathGetDeletedChildNodes(STRVEC *vref) +PREINIT: + vector arg_strvec; +CODE: + vector ret_strvec; + THIS->cfgPathGetDeletedChildNodes(arg_strvec, ret_strvec); +OUTPUT: + RETVAL + + +STRSTRMAP * +Cstore::cfgPathGetChildNodesStatus(STRVEC *vref) +PREINIT: + vector arg_strvec; +CODE: + map ret_strstrmap; + THIS->cfgPathGetChildNodesStatus(arg_strvec, ret_strstrmap); +OUTPUT: + RETVAL + + +STRVEC * +Cstore::cfgPathGetValuesDA(STRVEC *vref, bool active_cfg) +PREINIT: + vector arg_strvec; +CODE: + vector ret_strvec; + THIS->cfgPathGetValuesDA(arg_strvec, ret_strvec, active_cfg); +OUTPUT: + RETVAL + + +SV * +Cstore::cfgPathGetValueDA(STRVEC *vref, bool active_cfg) +PREINIT: + vector arg_strvec; +CODE: + string value; + if (THIS->cfgPathGetValueDA(arg_strvec, value, active_cfg)) { + RETVAL = newSVpv(value.c_str(), 0); + } else { + XSRETURN_UNDEF; + } +OUTPUT: + RETVAL + + +STRVEC * +Cstore::cfgPathGetChildNodesDA(STRVEC *vref, bool active_cfg) +PREINIT: + vector arg_strvec; +CODE: + vector ret_strvec; + THIS->cfgPathGetChildNodesDA(arg_strvec, ret_strvec, active_cfg); +OUTPUT: + RETVAL + + +bool +Cstore::cfgPathDeactivated(STRVEC *vref, bool active_cfg) +PREINIT: + vector arg_strvec; +CODE: + RETVAL = THIS->cfgPathDeactivated(arg_strvec, active_cfg); +OUTPUT: + RETVAL + + +STRSTRMAP * +Cstore::cfgPathGetChildNodesStatusDA(STRVEC *vref) +PREINIT: + vector arg_strvec; +CODE: + map ret_strstrmap; + THIS->cfgPathGetChildNodesStatusDA(arg_strvec, ret_strstrmap); +OUTPUT: + RETVAL + + +STRVEC * +Cstore::tmplGetChildNodes(STRVEC *vref) +PREINIT: + vector arg_strvec; +CODE: + vector ret_strvec; + THIS->tmplGetChildNodes(arg_strvec, ret_strvec); +OUTPUT: + RETVAL + + +bool +Cstore::validateTmplPath(STRVEC *vref, bool validate_vals) +PREINIT: + vector arg_strvec; +CODE: + RETVAL = THIS->validateTmplPath(arg_strvec, validate_vals); +OUTPUT: + RETVAL + + +STRSTRMAP * +Cstore::getParsedTmpl(STRVEC *vref, bool allow_val) +PREINIT: + vector arg_strvec; +CODE: + map ret_strstrmap; + if (!THIS->getParsedTmpl(arg_strvec, ret_strstrmap, allow_val)) { + XSRETURN_UNDEF; + } +OUTPUT: + RETVAL + + +SV * +Cstore::cfgPathGetComment(STRVEC *vref, bool active_cfg) +PREINIT: + vector arg_strvec; +CODE: + string comment; + if (THIS->cfgPathGetComment(arg_strvec, comment, active_cfg)) { + RETVAL = newSVpv(comment.c_str(), 0); + } else { + XSRETURN_UNDEF; + } +OUTPUT: + RETVAL + + diff --git a/perl_dmod/Cstore/MANIFEST b/perl_dmod/Cstore/MANIFEST new file mode 100644 index 0000000..3f4f007 --- /dev/null +++ b/perl_dmod/Cstore/MANIFEST @@ -0,0 +1,7 @@ +Changes +Makefile.PL +MANIFEST +README +Cstore.xs +t/Cstore.t +lib/Cstore.pm diff --git a/perl_dmod/Cstore/Makefile.PL b/perl_dmod/Cstore/Makefile.PL new file mode 100644 index 0000000..d3968f7 --- /dev/null +++ b/perl_dmod/Cstore/Makefile.PL @@ -0,0 +1,88 @@ +# Copyright (C) 2010 Vyatta, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +package MY; + +use 5.010000; +use ExtUtils::MakeMaker; + +my $PMOD_DIR = '$(SITEPREFIX)/share/perl5'; + +sub constants{ + my $self = shift; + my $orig_txt = $self->SUPER::constants(@_); + $orig_txt =~ s#= \$\(SITEPREFIX\)/(lib|share)/.*#= $PMOD_DIR#g; + return $orig_txt; +} + +sub c_o { + my $self = shift; + my $orig_txt = $self->SUPER::c_o(@_); + $orig_txt =~ s/\.c(\s)/.cpp$1/g; + return $orig_txt; +} + +sub xs_c { + my $self = shift; + my $orig_txt = $self->SUPER::xs_c(@_); + $orig_txt =~ s/\.c(\s)/.cpp$1/g; + return $orig_txt; +} + +sub xs_o { + my $self = shift; + my $orig_txt = $self->SUPER::xs_o(@_); + $orig_txt =~ s/\.c(\s)/.cpp$1/g; + return $orig_txt; +} + +sub install { + my $self = shift; + my $orig_txt = $self->SUPER::install(@_); + $orig_txt =~ s/pure_install doc_install/pure_install/g; + $orig_txt =~ s/\$\(INST_MAN3DIR\) .*/undef undef/g; + return $orig_txt; +} + +sub clean { + my $self = shift; + my $orig_txt = $self->SUPER::clean(@_); + $orig_txt =~ s/Cstore\.c\s/Cstore.cpp /g; + return $orig_txt; +} + +sub dynamic_lib { + my $self = shift; + my $orig_txt = $self->SUPER::dynamic_lib(@_); + $orig_txt =~ s/(\s)LD_RUN_PATH=\S+\s+/$1/g; + return $orig_txt; +} + +WriteMakefile( + NAME => 'Cstore', + VERSION_FROM => 'lib/Cstore.pm', + PREREQ_PM => {}, + ($] >= 5.005 ? + (ABSTRACT_FROM => 'lib/Cstore.pm', + AUTHOR => 'Vyatta ') : ()), + # note: MM will convert LIBS to absolute path in Makefile. + # => regenerate Makefile every time + LIBS => ['-L../../src/.libs -lvyatta-cfg'], + DEFINE => '', + INC => '-I../../src', + CC => 'g++', + PREFIX => '/opt/vyatta', + INSTALLDIRS => 'site', +); + diff --git a/perl_dmod/Cstore/README b/perl_dmod/Cstore/README new file mode 100644 index 0000000..84870fc --- /dev/null +++ b/perl_dmod/Cstore/README @@ -0,0 +1,33 @@ +Cstore version 0.01 +========================== + +This module provides Perl bindings to the Vyatta Cstore library. + + +INSTALLATION + +This module is installed as part of the vyatta-cfg package. + + +DEPENDENCIES + +This module requires the Vyatta Cstore library. + + +COPYRIGHT AND LICENCE + +Copyright (C) 2010 Vyatta, Inc. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License version 2 as +published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + + diff --git a/perl_dmod/Cstore/lib/Cstore.pm b/perl_dmod/Cstore/lib/Cstore.pm new file mode 100644 index 0000000..7cf2169 --- /dev/null +++ b/perl_dmod/Cstore/lib/Cstore.pm @@ -0,0 +1,96 @@ +# Copyright (C) 2010 Vyatta, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +package Cstore; + +use 5.010000; +use strict; +use warnings; + +require Exporter; +use AutoLoader qw(AUTOLOAD); + +our @ISA = qw(Exporter); + +# Items to export into callers namespace by default. Note: do not export +# names by default without a very good reason. Use EXPORT_OK instead. +# Do not simply export all your public functions/methods/constants. + +# This allows declaration use Cstore ':all'; +# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK +# will save memory. +our %EXPORT_TAGS = ( 'all' => [ qw( + +) ] ); + +our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); + +our @EXPORT = qw( + +); + +our $VERSION = '0.01'; + +require XSLoader; +XSLoader::load('Cstore', $VERSION); + +# Preloaded methods go here. + +# Autoload methods go after =cut, and are processed by the autosplit program. + +1; +__END__ +=head1 NAME + +Cstore - Perl binding for the Vyatta Cstore library + +=head1 SYNOPSIS + + use Cstore; + my $cstore = new Cstore; + +=head1 DESCRIPTION + +This module provides the Perl binding for the Vyatta Cstore library. + +=head2 EXPORT + +None by default. + +=head1 SEE ALSO + +For more information on the Cstore library, see the documentation and +source code for the main library. + +=head1 AUTHOR + +Vyatta, Inc. Eeng@vyatta.comE + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2010 Vyatta, Inc. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License version 2 as +published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +=cut diff --git a/perl_dmod/Cstore/t/Cstore.t b/perl_dmod/Cstore/t/Cstore.t new file mode 100644 index 0000000..51d23ac --- /dev/null +++ b/perl_dmod/Cstore/t/Cstore.t @@ -0,0 +1,15 @@ +# Before `make install' is performed this script should be runnable with +# `make test'. After `make install' it should work as `perl Cstore.t' + +######################### + +# change 'tests => 1' to 'tests => last_test_to_print'; + +use Test::More tests => 1; +BEGIN { use_ok('Cstore') }; + +######################### + +# Insert your test code below, the Test::More module is use()ed here so read +# its man page ( perldoc Test::More ) for help writing this test script. + diff --git a/perl_dmod/Cstore/typemap b/perl_dmod/Cstore/typemap new file mode 100644 index 0000000..f1f6a82 --- /dev/null +++ b/perl_dmod/Cstore/typemap @@ -0,0 +1,68 @@ +# Copyright (C) 2010 Vyatta, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +Cstore * O_CPPOBJ +STRVEC * T_STRVEC_REF +STRSTRMAP * T_STRSTRMAP_REF + + +############################################################ +OUTPUT +O_CPPOBJ + sv_setref_pv($arg, CLASS, (void *) $var); + +T_STRVEC_REF + AV *results; + results = (AV *) sv_2mortal((SV *) newAV()); + for (unsigned int i = 0; i < ret_strvec.size(); i++) { + av_push(results, newSVpv(ret_strvec[i].c_str(), 0)); + } + $arg = newRV((SV *) results); + +T_STRSTRMAP_REF + HV *href = (HV *) sv_2mortal((SV *) newHV()); + map::iterator it = ret_strstrmap.begin(); + for (; it != ret_strstrmap.end(); ++it) { + const char *key = (*it).first.c_str(); + const char *val = (*it).second.c_str(); + hv_store(href, key, strlen(key), newSVpv(val, 0), 0); + } + $arg = newRV((SV *) href); + + +############################################################ +INPUT +O_CPPOBJ + if (sv_isobject($arg) && (SvTYPE(SvRV($arg)) == SVt_PVMG)) { + $var = ($type) SvIV((SV *) SvRV($arg)); + } else { + warn(\"${Package}::$func_name(): $var is not a blessed SV reference\"); + XSRETURN_UNDEF; + } + +T_STRVEC_REF + { + int i = 0; + I32 num = 0; + if (!SvROK($arg) || SvTYPE(SvRV($arg)) != SVt_PVAV) { + XSRETURN_UNDEF; + } + num = av_len((AV *) SvRV($arg)); + /* if input array is empty, vector will be empty as well. */ + for (i = 0; i <= num; i++) { + string str = SvPV_nolen(*av_fetch((AV *) SvRV($arg), i, 0)); + arg_strvec.push_back(str); + } + } + diff --git a/perl_dmod/Makefile.am b/perl_dmod/Makefile.am new file mode 100644 index 0000000..6c12b35 --- /dev/null +++ b/perl_dmod/Makefile.am @@ -0,0 +1,25 @@ +PERL_MODS = Cstore + +# nop for all-local. make install will do a build anyway, so don't repeat +# the build here. +all-local: ; + +install-exec-local: + for pm in $(PERL_MODS); do \ + (cd $$pm; \ + perl Makefile.PL; \ + $(MAKE) $(AM_MAKEFLAGS) install); \ + done + +clean-local: + for pm in $(PERL_MODS); do \ + (cd $$pm; \ + perl Makefile.PL; \ + $(MAKE) $(AM_MAKEFLAGS) realclean); \ + done + +# nops +check-local: ; +install-data-local: ; +uninstall-local: ; + -- cgit v1.2.3 From dc4bd2c05375cece9d1c1281cbebbef40a09c4e4 Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Fri, 30 Jul 2010 09:53:00 -0700 Subject: add default status observers --- lib/Vyatta/Config.pm | 23 +++++++++++++++++++++-- lib/Vyatta/ConfigLoad.pm | 4 ++-- perl_dmod/Cstore/Cstore.xs | 10 ++++++++++ src/cstore/cstore.cpp | 16 +++++++++++++++- src/cstore/cstore.hpp | 4 +++- src/cstore/unionfs/cstore-unionfs.cpp | 5 +++-- src/cstore/unionfs/cstore-unionfs.hpp | 2 +- 7 files changed, 55 insertions(+), 9 deletions(-) (limited to 'perl_dmod') diff --git a/lib/Vyatta/Config.pm b/lib/Vyatta/Config.pm index 8067e05..371fe32 100755 --- a/lib/Vyatta/Config.pm +++ b/lib/Vyatta/Config.pm @@ -53,8 +53,9 @@ sub get_path_comps { } ############################################################ -# low-level API functions that have been converted to use -# the cstore library. +# low-level API functions that use the cstore library directly. +# they are either new functions or old ones that have been +# converted to use cstore. ############################################################ ###### @@ -94,6 +95,24 @@ sub existsOrig { return; # note: this return is needed. } +## isDefault("path to node") +# Returns true if specified node is "default" in working config. +sub isDefault { + my ($self, $path) = @_; + return 1 + if ($self->{_cstore}->cfgPathDefault($self->get_path_comps($path), undef)); + return; # note: this return is needed. +} + +## isDefaultOrig("path to node") +# Returns true if specified node is "default" in active config. +sub isDefaultOrig { + my ($self, $path) = @_; + return 1 + if ($self->{_cstore}->cfgPathDefault($self->get_path_comps($path), 1)); + return; # note: this return is needed. +} + ## listNodes("level") # return array of all child nodes at "level" in working config. sub listNodes { diff --git a/lib/Vyatta/ConfigLoad.pm b/lib/Vyatta/ConfigLoad.pm index d3d7dbb..55ba76b 100755 --- a/lib/Vyatta/ConfigLoad.pm +++ b/lib/Vyatta/ConfigLoad.pm @@ -401,8 +401,8 @@ sub getConfigDiff { $file; } @{${$del}[0]}; - my ($is_multi, $is_text, $default) - = $active_cfg->parseTmpl(join ' ', @comps); + $active_cfg->setLevel(join ' ', @comps); + my ($is_multi, $is_text, $default) = $active_cfg->parseTmpl(); if (!defined($default)) { push @new_delete_list, $del; } diff --git a/perl_dmod/Cstore/Cstore.xs b/perl_dmod/Cstore/Cstore.xs index 5dd105e..f72a124 100644 --- a/perl_dmod/Cstore/Cstore.xs +++ b/perl_dmod/Cstore/Cstore.xs @@ -54,6 +54,16 @@ OUTPUT: RETVAL +bool +Cstore::cfgPathDefault(STRVEC *vref, bool active_cfg) +PREINIT: + vector arg_strvec; +CODE: + RETVAL = THIS->cfgPathDefault(arg_strvec, active_cfg); +OUTPUT: + RETVAL + + STRVEC * Cstore::cfgPathGetChildNodes(STRVEC *vref, bool active_cfg) PREINIT: diff --git a/src/cstore/cstore.cpp b/src/cstore/cstore.cpp index e97ea2c..c829f6e 100644 --- a/src/cstore/cstore.cpp +++ b/src/cstore/cstore.cpp @@ -853,7 +853,7 @@ Cstore::setCfgPath(const vector& path_comps) append_cfg_path(path_comps); pop_cfg_path(); // only do it if it's previously marked default - if (marked_display_default()) { + if (marked_display_default(false)) { ret = unmark_display_default(); /* XXX work around current commit's unionfs implementation problem. @@ -1448,6 +1448,20 @@ Cstore::cfgPathGetComment(const vector& path_comps, string& comment, return ret; } +/* return whether specified path is "default". if a node is "default", it + * is currently not shown by the "show" command unless "-all" is specified. + * active_cfg: whether to observe active config. + */ +bool +Cstore::cfgPathDefault(const vector& path_comps, bool active_cfg) +{ + SAVE_PATHS; + append_cfg_path(path_comps); + bool ret = marked_display_default(active_cfg); + RESTORE_PATHS; + return ret; +} + /* the following functions are observers of the "effective" config. * they can be used * (1) outside a config session (e.g., op mode, daemons, callbacks, etc.). diff --git a/src/cstore/cstore.hpp b/src/cstore/cstore.hpp index 1d4ffe2..1d8a295 100644 --- a/src/cstore/cstore.hpp +++ b/src/cstore/cstore.hpp @@ -172,6 +172,8 @@ public: vector& values, bool active_cfg = false); bool cfgPathGetComment(const vector& path_comps, string& comment, bool active_cfg = false); + bool cfgPathDefault(const vector& path_comps, + bool active_cfg = false); /* observers for working AND active configs (at the same time). * MUST ONLY be used during config session. */ @@ -304,13 +306,13 @@ private: // observers for current work path virtual bool marked_changed() = 0; - virtual bool marked_display_default() = 0; // observers for current work path or active path virtual bool read_value_vec(vector& vvec, bool active_cfg) = 0; virtual bool cfg_node_exists(bool active_cfg) = 0; virtual bool marked_deactivated(bool active_cfg) = 0; virtual bool get_comment(string& comment, bool active_cfg) = 0; + virtual bool marked_display_default(bool active_cfg) = 0; // observers during commit operation virtual bool marked_committed(const vtw_def& def, bool is_set) = 0; diff --git a/src/cstore/unionfs/cstore-unionfs.cpp b/src/cstore/unionfs/cstore-unionfs.cpp index 6e6e5de..3e94778 100644 --- a/src/cstore/unionfs/cstore-unionfs.cpp +++ b/src/cstore/unionfs/cstore-unionfs.cpp @@ -662,9 +662,10 @@ UnionfsCstore::unmark_display_default() } bool -UnionfsCstore::marked_display_default() +UnionfsCstore::marked_display_default(bool active_cfg) { - b_fs::path marker = get_work_path() / C_MARKER_DEF_VALUE; + b_fs::path marker = (active_cfg ? get_active_path() : get_work_path()) + / C_MARKER_DEF_VALUE; return b_fs::exists(marker); } diff --git a/src/cstore/unionfs/cstore-unionfs.hpp b/src/cstore/unionfs/cstore-unionfs.hpp index dd44d9a..8bec974 100644 --- a/src/cstore/unionfs/cstore-unionfs.hpp +++ b/src/cstore/unionfs/cstore-unionfs.hpp @@ -165,13 +165,13 @@ private: // observers for work path bool marked_changed(); - bool marked_display_default(); // observers for work path or active path bool cfg_node_exists(bool active_cfg); bool read_value_vec(vector& vvec, bool active_cfg); bool marked_deactivated(bool active_cfg); bool get_comment(string& comment, bool active_cfg); + bool marked_display_default(bool active_cfg); // observers during commit operation bool marked_committed(const vtw_def& def, bool is_set); -- cgit v1.2.3 From 31f5a0c0245604b891aac418b3b787556b9f6b5b Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Fri, 13 Aug 2010 11:18:33 -0700 Subject: add API function for retrieving deleted values of a multi node. --- lib/Vyatta/Config.pm | 9 +++++++++ perl_dmod/Cstore/Cstore.xs | 11 +++++++++++ src/cstore/cstore.cpp | 29 +++++++++++++++++++++++++++++ src/cstore/cstore.hpp | 2 ++ 4 files changed, 51 insertions(+) (limited to 'perl_dmod') diff --git a/lib/Vyatta/Config.pm b/lib/Vyatta/Config.pm index 371fe32..a02ee18 100755 --- a/lib/Vyatta/Config.pm +++ b/lib/Vyatta/Config.pm @@ -356,6 +356,15 @@ sub listDeleted { return @{$ref}; } +## returnDeletedValues("level") +# return array of deleted values of specified "multi node" +sub returnDeletedValues { + my ($self, $path) = @_; + my $ref = $self->{_cstore}->cfgPathGetDeletedValues( + $self->get_path_comps($path)); + return @{$ref}; +} + ## isAdded("node") # whether specified node has been added in working config sub isAdded { diff --git a/perl_dmod/Cstore/Cstore.xs b/perl_dmod/Cstore/Cstore.xs index f72a124..4a726e7 100644 --- a/perl_dmod/Cstore/Cstore.xs +++ b/perl_dmod/Cstore/Cstore.xs @@ -189,6 +189,17 @@ OUTPUT: RETVAL +STRVEC * +Cstore::cfgPathGetDeletedValues(STRVEC *vref) +PREINIT: + vector arg_strvec; +CODE: + vector ret_strvec; + THIS->cfgPathGetDeletedValues(arg_strvec, ret_strvec); +OUTPUT: + RETVAL + + STRSTRMAP * Cstore::cfgPathGetChildNodesStatus(STRVEC *vref) PREINIT: diff --git a/src/cstore/cstore.cpp b/src/cstore/cstore.cpp index 04e8b27..3cd0649 100644 --- a/src/cstore/cstore.cpp +++ b/src/cstore/cstore.cpp @@ -1085,6 +1085,35 @@ Cstore::cfgPathGetDeletedChildNodesDA(const vector& path_comps, } } +/* get "deleted" values of specified "multi node" during commit + * operation. values are returned in dvals. if specified path is not + * a "multi node", it's a nop. + * + * NOTE: this function does not consider the "value ordering". the "deleted" + * status is purely based on the presence/absence of a value. + */ +void +Cstore::cfgPathGetDeletedValues(const vector& path_comps, + vector& dvals) +{ + vector ovals; + vector nvals; + if (!cfgPathGetValues(path_comps, ovals, true) + || !cfgPathGetValues(path_comps, nvals, false)) { + return; + } + map dmap; + for (size_t i = 0; i < nvals.size(); i++) { + dmap[nvals[i]] = true; + } + for (size_t i = 0; i < ovals.size(); i++) { + if (dmap.find(ovals[i]) == dmap.end()) { + // in active but not in working + dvals.push_back(ovals[i]); + } + } +} + /* this is the equivalent of the listNodeStatus() from the original * perl API. it provides the "status" ("deleted", "added", "changed", * or "static") of each child node of specified path. diff --git a/src/cstore/cstore.hpp b/src/cstore/cstore.hpp index caf845b..492462e 100644 --- a/src/cstore/cstore.hpp +++ b/src/cstore/cstore.hpp @@ -183,6 +183,8 @@ public: bool cfgPathChanged(const vector& path_comps); void cfgPathGetDeletedChildNodes(const vector& path_comps, vector& cnodes); + void cfgPathGetDeletedValues(const vector& path_comps, + vector& dvals); void cfgPathGetChildNodesStatus(const vector& path_comps, map& cmap); -- cgit v1.2.3