summaryrefslogtreecommitdiff
path: root/perl_dmod
diff options
context:
space:
mode:
authorAn-Cheng Huang <ancheng@vyatta.com>2010-07-28 14:30:32 -0700
committerAn-Cheng Huang <ancheng@vyatta.com>2010-07-28 14:30:32 -0700
commit639c835bc2730a4fbffd915f5b2028a68375ee7a (patch)
tree203d61e1d5e8ef422d6aba3851d2f83a1f838b6b /perl_dmod
parent0247864ef578ac05bbac8dc5175e674ce7b82714 (diff)
downloadvyatta-cfg-639c835bc2730a4fbffd915f5b2028a68375ee7a.tar.gz
vyatta-cfg-639c835bc2730a4fbffd915f5b2028a68375ee7a.zip
add new cstore library
Diffstat (limited to 'perl_dmod')
-rw-r--r--perl_dmod/.gitignore2
-rw-r--r--perl_dmod/Cstore/.gitignore5
-rw-r--r--perl_dmod/Cstore/Changes6
-rw-r--r--perl_dmod/Cstore/Cstore.xs299
-rw-r--r--perl_dmod/Cstore/MANIFEST7
-rw-r--r--perl_dmod/Cstore/Makefile.PL88
-rw-r--r--perl_dmod/Cstore/README33
-rw-r--r--perl_dmod/Cstore/lib/Cstore.pm96
-rw-r--r--perl_dmod/Cstore/t/Cstore.t15
-rw-r--r--perl_dmod/Cstore/typemap68
-rw-r--r--perl_dmod/Makefile.am25
11 files changed, 644 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>.
+ */
+
+#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 <cstring>
+#include <vector>
+#include <string>
+#include <map>
+
+/* currently use the UnionfsCstore implementation */
+#include <cstore/unionfs/cstore-unionfs.hpp>
+
+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<string> arg_strvec;
+CODE:
+ RETVAL = THIS->cfgPathExists(arg_strvec, active_cfg);
+OUTPUT:
+ RETVAL
+
+
+STRVEC *
+Cstore::cfgPathGetChildNodes(STRVEC *vref, bool active_cfg)
+PREINIT:
+ vector<string> arg_strvec;
+CODE:
+ vector<string> ret_strvec;
+ THIS->cfgPathGetChildNodes(arg_strvec, ret_strvec, active_cfg);
+OUTPUT:
+ RETVAL
+
+
+SV *
+Cstore::cfgPathGetValue(STRVEC *vref, bool active_cfg)
+PREINIT:
+ vector<string> 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<string> arg_strvec;
+CODE:
+ vector<string> ret_strvec;
+ THIS->cfgPathGetValues(arg_strvec, ret_strvec, active_cfg);
+OUTPUT:
+ RETVAL
+
+
+bool
+Cstore::cfgPathEffective(STRVEC *vref)
+PREINIT:
+ vector<string> arg_strvec;
+CODE:
+ RETVAL = THIS->cfgPathEffective(arg_strvec);
+OUTPUT:
+ RETVAL
+
+
+STRVEC *
+Cstore::cfgPathGetEffectiveChildNodes(STRVEC *vref)
+PREINIT:
+ vector<string> arg_strvec;
+CODE:
+ vector<string> ret_strvec;
+ THIS->cfgPathGetEffectiveChildNodes(arg_strvec, ret_strvec);
+OUTPUT:
+ RETVAL
+
+
+SV *
+Cstore::cfgPathGetEffectiveValue(STRVEC *vref)
+PREINIT:
+ vector<string> 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<string> arg_strvec;
+CODE:
+ vector<string> ret_strvec;
+ THIS->cfgPathGetEffectiveValues(arg_strvec, ret_strvec);
+OUTPUT:
+ RETVAL
+
+
+bool
+Cstore::cfgPathDeleted(STRVEC *vref)
+PREINIT:
+ vector<string> arg_strvec;
+CODE:
+ RETVAL = THIS->cfgPathDeleted(arg_strvec);
+OUTPUT:
+ RETVAL
+
+
+bool
+Cstore::cfgPathAdded(STRVEC *vref)
+PREINIT:
+ vector<string> arg_strvec;
+CODE:
+ RETVAL = THIS->cfgPathAdded(arg_strvec);
+OUTPUT:
+ RETVAL
+
+
+bool
+Cstore::cfgPathChanged(STRVEC *vref)
+PREINIT:
+ vector<string> arg_strvec;
+CODE:
+ RETVAL = THIS->cfgPathChanged(arg_strvec);
+OUTPUT:
+ RETVAL
+
+
+STRVEC *
+Cstore::cfgPathGetDeletedChildNodes(STRVEC *vref)
+PREINIT:
+ vector<string> arg_strvec;
+CODE:
+ vector<string> ret_strvec;
+ THIS->cfgPathGetDeletedChildNodes(arg_strvec, ret_strvec);
+OUTPUT:
+ RETVAL
+
+
+STRSTRMAP *
+Cstore::cfgPathGetChildNodesStatus(STRVEC *vref)
+PREINIT:
+ vector<string> arg_strvec;
+CODE:
+ map<string, string> ret_strstrmap;
+ THIS->cfgPathGetChildNodesStatus(arg_strvec, ret_strstrmap);
+OUTPUT:
+ RETVAL
+
+
+STRVEC *
+Cstore::cfgPathGetValuesDA(STRVEC *vref, bool active_cfg)
+PREINIT:
+ vector<string> arg_strvec;
+CODE:
+ vector<string> ret_strvec;
+ THIS->cfgPathGetValuesDA(arg_strvec, ret_strvec, active_cfg);
+OUTPUT:
+ RETVAL
+
+
+SV *
+Cstore::cfgPathGetValueDA(STRVEC *vref, bool active_cfg)
+PREINIT:
+ vector<string> 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<string> arg_strvec;
+CODE:
+ vector<string> ret_strvec;
+ THIS->cfgPathGetChildNodesDA(arg_strvec, ret_strvec, active_cfg);
+OUTPUT:
+ RETVAL
+
+
+bool
+Cstore::cfgPathDeactivated(STRVEC *vref, bool active_cfg)
+PREINIT:
+ vector<string> arg_strvec;
+CODE:
+ RETVAL = THIS->cfgPathDeactivated(arg_strvec, active_cfg);
+OUTPUT:
+ RETVAL
+
+
+STRSTRMAP *
+Cstore::cfgPathGetChildNodesStatusDA(STRVEC *vref)
+PREINIT:
+ vector<string> arg_strvec;
+CODE:
+ map<string, string> ret_strstrmap;
+ THIS->cfgPathGetChildNodesStatusDA(arg_strvec, ret_strstrmap);
+OUTPUT:
+ RETVAL
+
+
+STRVEC *
+Cstore::tmplGetChildNodes(STRVEC *vref)
+PREINIT:
+ vector<string> arg_strvec;
+CODE:
+ vector<string> ret_strvec;
+ THIS->tmplGetChildNodes(arg_strvec, ret_strvec);
+OUTPUT:
+ RETVAL
+
+
+bool
+Cstore::validateTmplPath(STRVEC *vref, bool validate_vals)
+PREINIT:
+ vector<string> arg_strvec;
+CODE:
+ RETVAL = THIS->validateTmplPath(arg_strvec, validate_vals);
+OUTPUT:
+ RETVAL
+
+
+STRSTRMAP *
+Cstore::getParsedTmpl(STRVEC *vref, bool allow_val)
+PREINIT:
+ vector<string> arg_strvec;
+CODE:
+ map<string, string> 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<string> 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 <http://www.gnu.org/licenses/>.
+
+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 <eng@vyatta.com>') : ()),
+ # 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 <http://www.gnu.org/licenses/>.
+
+
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 <http://www.gnu.org/licenses/>.
+
+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. E<lt>eng@vyatta.comE<gt>
+
+=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 <http://www.gnu.org/licenses/>.
+
+=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 <http://www.gnu.org/licenses/>.
+
+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<string, string>::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: ;
+