moving ui_browser.php & ui_handler.php to htmlUi

This commit is contained in:
naomiaro 2010-10-01 17:29:25 -04:00
parent dab1af1577
commit eb1678f961
171 changed files with 8 additions and 32773 deletions

View File

@ -1,10 +0,0 @@
<?php
if (strpos($_SERVER['PHP_SELF'], '~') !== false) {
list(, $user, ) = explode('/', $_SERVER['PHP_SELF']);
$base = "/$user/campcaster";
} else {
$base = "/campcaster";
}
header("LOCATION: $base/htmlUI/var/html/ui_browser.php");
?>

View File

@ -6,22 +6,22 @@
<title>Campcaster</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="styles_campcaster.css" rel="stylesheet" type="text/css" />
<link href="assets/plupload/plupload.queue.css" rel="stylesheet" type="text/css" />
<link href="css/playlist.css" rel="stylesheet" type="text/css" />
<link href="htmlUI/html/styles_campcaster.css" rel="stylesheet" type="text/css" />
<link href="htmlUI/html/assets/plupload/plupload.queue.css" rel="stylesheet" type="text/css" />
<link href="htmlUI/html/css/playlist.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="assets/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="assets/jquery-ui-1.8.5.custom.min.js"></script>
<script type="text/javascript" src="htmlUI/html/assets/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="htmlUI/html/assets/jquery-ui-1.8.5.custom.min.js"></script>
<script type="text/javascript" src="assets/plupload/plupload.full.min.js"></script>
<script type="text/javascript" src="assets/plupload/jquery.plupload.queue.min.js"></script>
<script type="text/javascript" src="htmlUI/html/assets/plupload/plupload.full.min.js"></script>
<script type="text/javascript" src="htmlUI/html/assets/plupload/jquery.plupload.queue.min.js"></script>
{include file="script/basics.js.tpl"}
{include file="script/contextmenu.js.tpl"}
{include file="script/collector.js.tpl"}
{include file="script/alttext.js.tpl"}
<script type="text/javascript" src="js/playlist.js"></script>
<script type="text/javascript" src="htmlUI/html/js/playlist.js"></script>
</head>

View File

@ -1,90 +0,0 @@
#!/bin/bash
#-------------------------------------------------------------------------------
# Copyright (c) 2010 Sourcefabric O.P.S.
#
# This file is part of the Campcaster project.
# http://campcaster.sourcefabric.org/
#
# Campcaster is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Campcaster 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 Campcaster; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Run this to set up the build system: configure, makefiles, etc.
# (based on the version in enlightenment's cvs)
#-------------------------------------------------------------------------------
package="Core"
# assume we're in $basedir/bin
reldir=`dirname $0`/..
basedir=`cd $reldir; pwd;`
test -z "$basedir" && basedir=.
usrdir=`cd $basedir/../../../usr; pwd;`
bindir=$basedir/bin
etcdir=$basedir/etc
tmpdir=$basedir/tmp
cd "$tmpdir"
DIE=0
(autoheader --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "You must have autoconf installed to compile $package."
echo "Download the appropriate package for your distribution,"
echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/"
DIE=1
}
(autoconf --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "You must have autoconf installed to compile $package."
echo "Download the appropriate package for your distribution,"
echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/"
DIE=1
}
if test "$DIE" -eq 1; then
exit 1
fi
if test -z "$*"; then
echo "I am going to run ./configure with no arguments - if you wish "
echo "to pass any to it, please specify them on the $0 command line."
fi
echo "Generating configuration files for $package, please wait...."
configure_ac=${etcdir}/configure.ac
configure=${tmpdir}/configure
aclocal_m4=${tmpdir}/aclocal.m4
# copy over configure.ac and acinlclude.m4 from etc to tmp,
# as aclocal >= 1.8 is sooo unbelivably stupid that it will simply try to
# look for configure.ac in the current directory, and include acinclude.m4
# in aclocal.m4 it without a directory path in front
ACLOCAL_FLAGS="-I ${tmpdir} --acdir=${tmpdir} --output=${aclocal_m4}"
echo " aclocal $ACLOCAL_FLAGS"
cp -f ${configure_ac} ${tmpdir}
cp -f ${etcdir}/acinclude.m4 ${tmpdir}
aclocal $ACLOCAL_FLAGS
echo " autoheader ${configure_ac}"
autoheader ${configure_ac}
echo " autoconf -I ${tmpdir} -o ${configure} ${configure_ac}"
autoconf -I ${tmpdir} -o ${configure} ${configure_ac}

View File

@ -1,75 +0,0 @@
#!/bin/bash
#-------------------------------------------------------------------------------
# Copyright (c) 2010 Sourcefabric O.P.S.
#
# This file is part of the Campcaster project.
# http://campcaster.sourcefabric.org/
#
# Campcaster is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Campcaster 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 Campcaster; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# This script generates code coverage data for the module
#-------------------------------------------------------------------------------
module="Campcaster Core"
reldir=`dirname $0`/..
basedir=`cd $reldir; pwd;`
bindir=$basedir/bin
docdir=$basedir/doc
tmpdir=$basedir/tmp
usrdir=`cd $basedir/../../../usr; pwd;`
coverage_report_dir=$docdir/coverage
raw_coverage_file=$tmpdir/raw_coverage.info
coverage_file=$tmpdir/coverage.info
lcov=$usrdir/bin/lcov
genhtml=$usrdir/bin/genhtml
cd $basedir
#-------------------------------------------------------------------------------
# Re-configure with covarege collection enabled, compile and run the tests
#-------------------------------------------------------------------------------
$bindir/autogen.sh --enable-coverage
make clean
make check
#-------------------------------------------------------------------------------
# Generate some symlinks so that the sources are visible from tmpdir
#-------------------------------------------------------------------------------
ln -s $basedir/include $tmpdir/include
ln -s $basedir/src $tmpdir/src
#-------------------------------------------------------------------------------
# Use lcov to generate an HTML report on the coverage data
#-------------------------------------------------------------------------------
$lcov -d $tmpdir -c > $raw_coverage_file
$lcov -e $raw_coverage_file "$tmpdir/*" > $coverage_file
rm -rf $coverage_report_dir
mkdir -p $coverage_report_dir
$genhtml -t "$module" -o $coverage_report_dir $coverage_file
#-------------------------------------------------------------------------------
# Clean up
#-------------------------------------------------------------------------------
rm -f $tmpdir/include
rm -f $tmpdir/src

View File

@ -1,47 +0,0 @@
#!/bin/sh
#-------------------------------------------------------------------------------
# Copyright (c) 2010 Sourcefabric O.P.S.
#
# This file is part of the Campcaster project.
# http://campcaster.campware.org/
#
# Campcaster is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Campcaster 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 Campcaster; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Run this script to configure the environment.
#
# This script in effect calls the real automake / autoconf configure script
#-------------------------------------------------------------------------------
# assume we're in $basedir
reldir=`dirname $0`
basedir=`cd $reldir; pwd;`
test -z "$basedir" && basedir=.
bindir=$basedir/bin
tmpdir=$basedir/tmp
autogen=$bindir/autogen.sh
configure=$tmpdir/configure
if [ ! -x $configure ]; then
(cd $basedir && $autogen "$@")
fi
(cd $tmpdir && $configure "$@")

View File

@ -1 +0,0 @@
keep me

View File

@ -1 +0,0 @@
keep me

View File

@ -1,245 +0,0 @@
#-------------------------------------------------------------------------------
# Copyright (c) 2010 Sourcefabric O.P.S.
#
# This file is part of the Campcaster project.
# http://campcaster.sourcefabric.org/
#
# Campcaster is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Campcaster 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 Campcaster; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# @configure_input@
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# General command definitions
#-------------------------------------------------------------------------------
MKDIR = mkdir -p
RM = rm -f
RMDIR = rm -rf
DOXYGEN = doxygen
CP = cp -f
#-------------------------------------------------------------------------------
# Basic directory and file definitions
#-------------------------------------------------------------------------------
PACKAGE_NAME = @PACKAGE_NAME@
BASE_DIR = @builddir@
DOC_DIR = ${BASE_DIR}/doc
DOXYGEN_DIR = ${DOC_DIR}/doxygen
COVERAGE_DIR = ${DOC_DIR}/coverage
ETC_DIR = ${BASE_DIR}/etc
INCLUDE_DIR = ${BASE_DIR}/include
LIB_DIR = ${BASE_DIR}/lib
SRC_DIR = ${BASE_DIR}/src
TMP_DIR = ${BASE_DIR}/tmp
VAR_DIR = ${BASE_DIR}/var
prefix = @prefix@
USR_DIR = ${prefix}
USR_INCLUDE_DIR = ${USR_DIR}/include
USR_BIN_DIR = ${USR_DIR}/bin
USR_LIB_DIR = ${USR_DIR}/lib
GENRB = @GENRB@
TMP_LOCALIZATION_DIR = ${TMP_DIR}/${PACKAGE_NAME}
GENRBOPTS = --destdir ${TMP_LOCALIZATION_DIR} \
--encoding utf-8 \
--strict
VPATH = ${SRC_DIR}
BOOST_CFLAGS=@BOOST_CPPFLAGS@
BOOST_LIBS=@BOOST_LDFLAGS@
BOOST_DATE_TIME_LIB=@BOOST_DATE_TIME_LIB@
LIBXMLPP_CFLAGS=@LIBXMLPP_CFLAGS@
LIBXMLPP_LIBS=@LIBXMLPP_LIBS@
CURL_CFLAGS=@CURL_CFLAGS@
CURL_LIBS=@CURL_LIBS@
ICU_CFLAGS=@ICU_CFLAGS@
ICU_CXXFLAGS=@ICU_CXXFLAGS@
ICU_LIBS=@ICU_LIBS@
TAGLIB_CFLAGS=@TAGLIB_CFLAGS@
TAGLIB_LIBS=@TAGLIB_LIBS@
TEST_RESULTS = ${DOC_DIR}/testResults.xml
# the text result XSLT has to be relative to the test result file, e.g. TMP_DIR
TEST_XSLT = ../etc/testResultToHtml.xsl
CORE_LIB = livesupport_core
CORE_LIB_FILE = ${LIB_DIR}/lib${CORE_LIB}.a
TEST_RUNNER = ${TMP_DIR}/testRunner
DOXYGEN_CONFIG = ${ETC_DIR}/doxygen.config
export LD_LIBRARY_PATH:=${USR_LIB_DIR}:${LD_LIBRARY_PATH}
#-------------------------------------------------------------------------------
# Configuration parameters
#-------------------------------------------------------------------------------
CPPFLAGS = @CPPFLAGS@
CXXFLAGS = @CXXFLAGS@ @DEFS@ @COVERAGE_CXXFLAGS@ -pthread \
-pedantic -Wall -Wno-long-long \
${BOOST_CFLAGS} \
${TAGLIB_CFLAGS} \
${LIBXMLPP_CFLAGS} \
-I${USR_INCLUDE_DIR} \
-I${INCLUDE_DIR} -I${TMP_DIR}
LDFLAGS = @LDFLAGS@ -pthread \
${BOOST_LIBS} \
${CURL_LIBS} \
${ICU_LIBS} \
${TAGLIB_LIBS} \
${LIBXMLPP_LIBS} \
-L${USR_LIB_DIR} \
-L${LIB_DIR}
#-------------------------------------------------------------------------------
# Dependencies
#-------------------------------------------------------------------------------
CORE_LIB_OBJS = ${TMP_DIR}/UniqueId.o \
${TMP_DIR}/Uuid.o \
${TMP_DIR}/Playable.o \
${TMP_DIR}/AudioClip.o \
${TMP_DIR}/FadeInfo.o \
${TMP_DIR}/ScheduleEntry.o \
${TMP_DIR}/PlaylistElement.o \
${TMP_DIR}/Playlist.o \
${TMP_DIR}/TimeConversion.o \
${TMP_DIR}/Thread.o \
${TMP_DIR}/LocalizedObject.o \
${TMP_DIR}/LocalizedConfigurable.o \
${TMP_DIR}/Md5.o \
${TMP_DIR}/XmlRpcTools.o \
${TMP_DIR}/XmlRpcException.o \
${TMP_DIR}/BaseTestMethod.o \
${TMP_DIR}/SearchCriteria.o \
${TMP_DIR}/MetadataType.o \
${TMP_DIR}/MetadataTypeContainer.o \
${TMP_DIR}/OptionsContainer.o \
${TMP_DIR}/FileTools.o \
${TMP_DIR}/AsyncState.o \
${TMP_DIR}/MetadataConstraint.o \
${TMP_DIR}/NumericConstraint.o \
${TMP_DIR}/NumericRangeConstraint.o \
${TMP_DIR}/EnumerationConstraint.o \
${TMP_DIR}/RdsItem.o \
${TMP_DIR}/RdsContainer.o \
${TMP_DIR}/NumericTools.o
TEST_RUNNER_OBJS = ${TMP_DIR}/TestRunner.o \
${TMP_DIR}/FileToolsTest.o \
${TMP_DIR}/UuidTest.o \
${TMP_DIR}/UniqueIdTest.o \
${TMP_DIR}/AudioClipTest.o \
${TMP_DIR}/ScheduleEntryTest.o \
${TMP_DIR}/FadeInfoTest.o \
${TMP_DIR}/PlaylistElementTest.o \
${TMP_DIR}/PlaylistTest.o \
${TMP_DIR}/TimeConversionTest.o \
${TMP_DIR}/TestRunnable.o \
${TMP_DIR}/ThreadTest.o \
${TMP_DIR}/LocalizedObjectTest.o \
${TMP_DIR}/LocalizedConfigurableTest.o \
${TMP_DIR}/Md5Test.o \
${TMP_DIR}/XmlRpcToolsTest.o \
${TMP_DIR}/SearchCriteriaTest.o \
${TMP_DIR}/MetadataTypeContainerTest.o \
${TMP_DIR}/AsyncStateTest.o \
${TMP_DIR}/RdsContainerTest.o \
${TMP_DIR}/NumericToolsTest.o
TEST_RUNNER_RES = ${TMP_LOCALIZATION_DIR}/root.res \
${TMP_LOCALIZATION_DIR}/en.res \
${TMP_LOCALIZATION_DIR}/hu.res \
${TMP_LOCALIZATION_DIR}/jp.res
TEST_RUNNER_LIBS = -l${CORE_LIB} ${ICU_LIBS} ${BOOST_DATE_TIME_LIB} \
-lcppunit -ldl -lxmlrpc++ -ltar
#-------------------------------------------------------------------------------
# Targets
#-------------------------------------------------------------------------------
.PHONY: all dir_setup doc clean docclean depclean distclean check install
all: dir_setup ${CORE_LIB_FILE}
dir_setup: ${TMP_DIR} ${TMP_LOCALIZATION_DIR} ${DOXYGEN_DIR}
doc:
${DOXYGEN} ${DOXYGEN_CONFIG}
clean:
${RM} ${CORE_LIB_OBJS} ${CORE_LIB_FILE}
${RM} ${TEST_RUNNER_OBJS} ${TEST_RUNNER_RES} ${TEST_RUNNER}
${RM} ${TMP_DIR}/*.bb ${TMP_DIR}/*.bbg ${TMP_DIR}/*.da ${TMP_DIR}/*.info
${RMDIR} ${TMP_LOCALIZATION_DIR}
docclean:
${RMDIR} ${DOXYGEN_DIR}/html
${RMDIR} ${COVERAGE_DIR}/*
${RM} ${TEST_RESULTS}
depclean: clean
distclean: clean docclean
${RMDIR} ${TMP_DIR}/config* ${TMP_DIR}/autom4te* ${TMP_DIR}/ac*.m4
check: ${TEST_RUNNER} ${TEST_RUNNER_RES}
${TEST_RUNNER} -o ${TEST_RESULTS} -s ${TEST_XSLT}
install: all
${MKDIR} ${USR_INCLUDE_DIR}/LiveSupport/Core
${CP} ${INCLUDE_DIR}/LiveSupport/Core/*.h \
${USR_INCLUDE_DIR}/LiveSupport/Core
${CP} ${CORE_LIB_FILE} ${USR_LIB_DIR}
#-------------------------------------------------------------------------------
# Specific targets
#-------------------------------------------------------------------------------
${CORE_LIB_FILE}: ${CORE_LIB_OBJS}
${AR} crus $@ $^
${TMP_DIR}:
${MKDIR} ${TMP_DIR}
${TMP_LOCALIZATION_DIR}:
${MKDIR} ${TMP_LOCALIZATION_DIR}
${DOXYGEN_DIR}:
${MKDIR} ${DOXYGEN_DIR}
${TEST_RUNNER}: ${TEST_RUNNER_OBJS} ${CORE_LIB_FILE}
${CXX} ${LDFLAGS} -o $@ ${TEST_RUNNER_OBJS} ${TEST_RUNNER_LIBS}
#-------------------------------------------------------------------------------
# Pattern rules
#-------------------------------------------------------------------------------
${TMP_DIR}/%.o : ${SRC_DIR}/%.cxx
${CXX} ${CPPFLAGS} ${CXXFLAGS} -c -o $@ $<
${TMP_LOCALIZATION_DIR}/%.res : ${VAR_DIR}/%.txt
${GENRB} ${GENRBOPTS} $^

View File

@ -1,576 +0,0 @@
dnl-----------------------------------------------------------------------------
dnl Copyright (c) 2010 Sourcefabric O.P.S.
dnl
dnl This file is part of the Campcaster project.
dnl http://campcaster.sourcefabric.org/
dnl
dnl Campcaster is free software; you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
dnl the Free Software Foundation; either version 2 of the License, or
dnl (at your option) any later version.
dnl
dnl Campcaster is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dnl GNU General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License
dnl along with Campcaster; if not, write to the Free Software
dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
dnl
dnl-----------------------------------------------------------------------------
dnl-----------------------------------------------------------------------------
dnl Macro to check for available modules using pkg-conf
dnl
dnl usage:
dnl PKG_CHECK_MODULES(GSTUFF,[gtk+-2.0 >= 1.3], action-if, action-not)
dnl
dnl defines GSTUFF_LIBS, GSTUFF_CFLAGS, see pkg-config man page
dnl also defines GSTUFF_PKG_ERRORS on error
dnl
dnl This function was taken from the glade-- project
dnl-----------------------------------------------------------------------------
AC_DEFUN([PKG_CHECK_MODULES], [
succeeded=no
if test -z "$PKG_CONFIG"; then
AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
fi
if test "$PKG_CONFIG" = "no" ; then
echo "*** The pkg-config script could not be found. Make sure it is"
echo "*** in your path, or set the PKG_CONFIG environment variable"
echo "*** to the full path to pkg-config."
echo "*** Or see http://www.freedesktop.org/software/pkgconfig to get pkg-config."
else
PKG_CONFIG_MIN_VERSION=0.9.0
if $PKG_CONFIG --atleast-pkgconfig-version $PKG_CONFIG_MIN_VERSION; then
AC_MSG_CHECKING(for $2)
if $PKG_CONFIG --exists "$2" ; then
AC_MSG_RESULT(yes)
succeeded=yes
AC_MSG_CHECKING($1_CFLAGS)
$1_CFLAGS=`$PKG_CONFIG --cflags "$2"`
AC_MSG_RESULT($$1_CFLAGS)
AC_MSG_CHECKING($1_LIBS)
$1_LIBS=`$PKG_CONFIG --libs "$2"`
AC_MSG_RESULT($$1_LIBS)
else
$1_CFLAGS=""
$1_LIBS=""
## If we have a custom action on failure, don't print errors, but
## do set a variable so people can do so.
$1_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "$2"`
ifelse([$4], ,echo $$1_PKG_ERRORS,)
fi
AC_SUBST($1_CFLAGS)
AC_SUBST($1_LIBS)
else
echo "*** Your version of pkg-config is too old. You need version $PKG_CONFIG_MIN_VERSION or newer."
echo "*** See http://www.freedesktop.org/software/pkgconfig"
fi
fi
if test $succeeded = yes; then
ifelse([$3], , :, [$3])
else
ifelse([$4], , AC_MSG_ERROR([Library requirements ($2) not met; consider adjusting the PKG_CONFIG_PATH environment variable if your libraries are in a nonstandard prefix so pkg-config can find them.]), [$4])
fi
])
dnl-----------------------------------------------------------------------------
dnl Macro to check for taglib of sufficient version by looking at taglib-config
dnl
dnl usage:
dnl AC_CHECK_TAGLIB(version, action-if, action-not)
dnl
dnl defines TAGLIB_LIBS, TAGLIB_CFLAGS, see taglib-config man page
dnl-----------------------------------------------------------------------------
AC_DEFUN([AC_CHECK_TAGLIB], [
succeeded=no
if test -z "$TAGLIB_CONFIG"; then
AC_PATH_PROG(TAGLIB_CONFIG, taglib-config, no)
fi
if test "$TAGLIB_CONFIG" = "no" ; then
echo "*** The taglib-config script could not be found. Make sure it is"
echo "*** in your path, and that taglib is properly installed."
echo "*** Or see http://developer.kde.org/~wheeler/taglib.html"
else
TAGLIB_VERSION=`$TAGLIB_CONFIG --version`
AC_MSG_CHECKING(for taglib >= $1)
VERSION_CHECK=`expr $TAGLIB_VERSION \>\= $1`
if test "$VERSION_CHECK" = "1" ; then
AC_MSG_RESULT(yes)
succeeded=yes
AC_MSG_CHECKING(TAGLIB_CFLAGS)
TAGLIB_CFLAGS=`$TAGLIB_CONFIG --cflags`
AC_MSG_RESULT($TAGLIB_CFLAGS)
AC_MSG_CHECKING(TAGLIB_LIBS)
TAGLIB_LIBS=`$TAGLIB_CONFIG --libs`
AC_MSG_RESULT($TAGLIB_LIBS)
else
TAGLIB_CFLAGS=""
TAGLIB_LIBS=""
## If we have a custom action on failure, don't print errors, but
## do set a variable so people can do so.
ifelse([$3], ,echo "can't find taglib >= $1",)
fi
AC_SUBST(TAGLIB_CFLAGS)
AC_SUBST(TAGLIB_LIBS)
fi
if test $succeeded = yes; then
ifelse([$2], , :, [$2])
else
ifelse([$3], , AC_MSG_ERROR([Library requirements (taglib) not met.]), [$3])
fi
])
dnl-----------------------------------------------------------------------------
dnl Macro to check for ICU of sufficient version by looking at icu-config
dnl
dnl usage:
dnl AC_CHECK_ICU(version, action-if, action-not)
dnl
dnl defines ICU_LIBS, ICU_CFLAGS, ICU_CXXFLAGS, see icu-config man page
dnl-----------------------------------------------------------------------------
AC_DEFUN([AC_CHECK_ICU], [
succeeded=no
if test -z "$ICU_CONFIG"; then
AC_PATH_PROG(ICU_CONFIG, icu-config, no)
fi
if test "$ICU_CONFIG" = "no" ; then
echo "*** The icu-config script could not be found. Make sure it is"
echo "*** in your path, and that taglib is properly installed."
echo "*** Or see http://ibm.com/software/globalization/icu/"
else
ICU_VERSION=`$ICU_CONFIG --version`
AC_MSG_CHECKING(for ICU >= $1)
VERSION_CHECK=`expr $ICU_VERSION \>\= $1`
if test "$VERSION_CHECK" = "1" ; then
AC_MSG_RESULT(yes)
succeeded=yes
AC_MSG_CHECKING(ICU_CFLAGS)
ICU_CFLAGS=`$ICU_CONFIG --cflags`
AC_MSG_RESULT($ICU_CFLAGS)
AC_MSG_CHECKING(ICU_CXXFLAGS)
ICU_CXXFLAGS=`$ICU_CONFIG --cxxflags`
AC_MSG_RESULT($ICU_CXXFLAGS)
AC_MSG_CHECKING(ICU_LIBS)
ICU_LIBS=`$ICU_CONFIG --ldflags`
AC_MSG_RESULT($ICU_LIBS)
else
ICU_CFLAGS=""
ICU_CXXFLAGS=""
ICU_LIBS=""
## If we have a custom action on failure, don't print errors, but
## do set a variable so people can do so.
ifelse([$3], ,echo "can't find ICU >= $1",)
fi
AC_SUBST(ICU_CFLAGS)
AC_SUBST(ICU_CXXFLAGS)
AC_SUBST(ICU_LIBS)
fi
if test $succeeded = yes; then
ifelse([$2], , :, [$2])
else
ifelse([$3], , AC_MSG_ERROR([Library requirements (ICU) not met.]), [$3])
fi
])
dnl-----------------------------------------------------------------------------
dnl Macro to check for C++ namespaces
dnl for more information on this macro, see
dnl http://autoconf-archive.cryp.to/ac_cxx_namespaces.html
dnl
dnl usage:
dnl If the compiler can prevent names clashes using namespaces,
dnl define HAVE_NAMESPACES.
dnl-----------------------------------------------------------------------------
AC_DEFUN([AC_CXX_NAMESPACES],
[AC_CACHE_CHECK(whether the compiler implements namespaces,
ac_cv_cxx_namespaces,
[AC_LANG_SAVE
AC_LANG_CPLUSPLUS
AC_TRY_COMPILE([namespace Outer { namespace Inner { int i = 0; }}],
[using namespace Outer::Inner; return i;],
ac_cv_cxx_namespaces=yes, ac_cv_cxx_namespaces=no)
AC_LANG_RESTORE
])
if test "$ac_cv_cxx_namespaces" = yes; then
AC_DEFINE(HAVE_NAMESPACES,,[define if the compiler implements namespaces])
fi
])
dnl-----------------------------------------------------------------------------
dnl Test for the Boost C++ libraries of a particular version (or newer).
dnl for more information on boost, see http://www.boost.org/
dnl for more information on this macro, see
dnl http://autoconf-archive.cryp.to/ax_boost_base.html
dnl
dnl usage:
dnl If no path to the installed boost library is given the macro searches
dnl under ${prefix}, /usr, /usr/local, and /opt, and evaluates the $BOOST_ROOT
dnl environment variable. Further documentation is available at
dnl http://randspringer.de/boost/index.html
dnl
dnl This macro calls: AC_SUBST(BOOST_CPPFLAGS) and AC_SUBST(BOOST_LDFLAGS)
dnl and sets: HAVE_BOOST
dnl
dnl Modified for Campcaster:
dnl * --with-boost default changed to Yes;
dnl * if the library is not found, it does not die, just prints "no", leaves
dnl HAVE_BOOST undefined, and sets the BOOST_CPPFLAGS and BOOST_LDFLAGS
dnl variables to "";
dnl * ${prefix} is prepended to the search path.
dnl
dnl Author: Thomas Porschberg <thomas@randspringer.de>
dnl
dnl License:
dnl Copyright © 2006 Thomas Porschberg <thomas@randspringer.de>
dnl Copying and distribution of this file, with or without modification,
dnl are permitted in any medium without royalty provided the copyright notice
dnl and this notice are preserved.
dnl-----------------------------------------------------------------------------
AC_DEFUN([AX_BOOST_BASE],
[
AC_ARG_WITH([boost],
AS_HELP_STRING([--with-boost@<:@=DIR@:>@], [use boost (default is Yes) - it is possible to specify the root directory for boost (optional)]),
[
if test "$withval" = "no"; then
want_boost="no"
elif test "$withval" = "yes"; then
want_boost="yes"
ac_boost_path=""
else
want_boost="yes"
ac_boost_path="$withval"
fi
],
[want_boost="yes"])
if test "x$want_boost" = "xyes"; then
boost_lib_version_req=ifelse([$1], ,1.20.0,$1)
boost_lib_version_req_shorten=`expr $boost_lib_version_req : '\([[0-9]]*\.[[0-9]]*\)'`
boost_lib_version_req_major=`expr $boost_lib_version_req : '\([[0-9]]*\)'`
boost_lib_version_req_minor=`expr $boost_lib_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
boost_lib_version_req_sub_minor=`expr $boost_lib_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
if test "x$boost_lib_version_req_sub_minor" = "x" ; then
boost_lib_version_req_sub_minor="0"
fi
WANT_BOOST_VERSION=`expr $boost_lib_version_req_major \* 100000 \+ $boost_lib_version_req_minor \* 100 \+ $boost_lib_version_req_sub_minor`
AC_MSG_CHECKING(for boostlib >= $boost_lib_version_req)
succeeded=no
dnl first we check the system location for boost libraries
dnl this location ist chosen if boost libraries are installed with the --layout=system option
dnl or if you install boost with RPM
if test "$ac_boost_path" != ""; then
BOOST_LDFLAGS="-L$ac_boost_path/lib"
BOOST_CPPFLAGS="-I$ac_boost_path/include"
else
for ac_boost_path_tmp in ${prefix} /usr /usr/local /opt ; do
if test -d "$ac_boost_path_tmp/include/boost" && test -r "$ac_boost_path_tmp/include/boost"; then
BOOST_LDFLAGS="-L$ac_boost_path_tmp/lib"
BOOST_CPPFLAGS="-I$ac_boost_path_tmp/include"
break;
fi
done
fi
CPPFLAGS_SAVED="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
export CPPFLAGS
LDFLAGS_SAVED="$LDFLAGS"
LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
export LDFLAGS
AC_LANG_PUSH(C++)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
@%:@include <boost/version.hpp>
]], [[
#if BOOST_VERSION >= $WANT_BOOST_VERSION
// Everything is okay
#else
# error Boost version is too old
#endif
]])],[
AC_MSG_RESULT(yes)
succeeded=yes
found_system=yes
],[
])
AC_LANG_POP([C++])
dnl if we found no boost with system layout we search for boost libraries
dnl built and installed without the --layout=system option or for a staged(not installed) version
if test "x$succeeded" != "xyes"; then
_version=0
if test "$ac_boost_path" != ""; then
BOOST_LDFLAGS="-L$ac_boost_path/lib"
if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
_version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
V_CHECK=`expr $_version_tmp \> $_version`
if test "$V_CHECK" = "1" ; then
_version=$_version_tmp
fi
VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
BOOST_CPPFLAGS="-I$ac_boost_path/include/boost-$VERSION_UNDERSCORE"
done
fi
else
for ac_boost_path in /usr /usr/local /opt ; do
if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
_version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
V_CHECK=`expr $_version_tmp \> $_version`
if test "$V_CHECK" = "1" ; then
_version=$_version_tmp
best_path=$ac_boost_path
fi
done
fi
done
VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE"
BOOST_LDFLAGS="-L$best_path/lib"
if test "x$BOOST_ROOT" != "x"; then
if test -d "$BOOST_ROOT" && test -r "$BOOST_ROOT" && test -d "$BOOST_ROOT/stage/lib" && test -r "$BOOST_ROOT/stage/lib"; then
version_dir=`expr //$BOOST_ROOT : '.*/\(.*\)'`
stage_version=`echo $version_dir | sed 's/boost_//' | sed 's/_/./g'`
stage_version_shorten=`expr $stage_version : '\([[0-9]]*\.[[0-9]]*\)'`
V_CHECK=`expr $stage_version_shorten \>\= $_version`
if test "$V_CHECK" = "1" ; then
AC_MSG_NOTICE(We will use a staged boost library from $BOOST_ROOT)
BOOST_CPPFLAGS="-I$BOOST_ROOT"
BOOST_LDFLAGS="-L$BOOST_ROOT/stage/lib"
fi
fi
fi
fi
CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
export CPPFLAGS
LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
export LDFLAGS
AC_LANG_PUSH(C++)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
@%:@include <boost/version.hpp>
]], [[
#if BOOST_VERSION >= $WANT_BOOST_VERSION
// Everything is okay
#else
# error Boost version is too old
#endif
]])],[
AC_MSG_RESULT(yes)
succeeded=yes
found_system=yes
],[
])
AC_LANG_POP([C++])
fi
if test "$succeeded" != "yes" ; then
BOOST_CPPFLAGS=""
BOOST_LDFLAGS=""
AC_MSG_RESULT(no)
else
AC_SUBST(BOOST_CPPFLAGS)
AC_SUBST(BOOST_LDFLAGS)
AC_DEFINE(HAVE_BOOST,,[define if the Boost library is available])
fi
CPPFLAGS="$CPPFLAGS_SAVED"
LDFLAGS="$LDFLAGS_SAVED"
fi
])
dnl-----------------------------------------------------------------------------
dnl Test for Date_Time library from the Boost C++ libraries.
dnl for more information on boost, see http://www.boost.org/
dnl for more information on this macro, see
dnl http://autoconf-archive.cryp.to/ax_boost_date_time.html
dnl
dnl usage:
dnl The macro requires a preceding call to AX_BOOST_BASE.
dnl Further documentation is available at
dnl <http://randspringer.de/boost/index.html>.
dnl
dnl This macro calls: AC_SUBST(BOOST_DATE_TIME_LIB)
dnl and sets: HAVE_BOOST_DATE_TIME
dnl
dnl Modified for Campcaster:
dnl * --with-boost-date-time default changed to Yes.
dnl * added some more recognized suffixes to the library's name, incl. "-st".
dnl
dnl Authors:
dnl Thomas Porschberg <thomas@randspringer.de>
dnl Michael Tindal <mtindal@paradoxpoint.com>
dnl
dnl License:
dnl Copyright © 2006 Thomas Porschberg <thomas@randspringer.de>
dnl Copying and distribution of this file, with or without modification,
dnl are permitted in any medium without royalty provided the copyright notice
dnl and this notice are preserved.
dnl-----------------------------------------------------------------------------
AC_DEFUN([AX_BOOST_DATE_TIME],
[
AC_ARG_WITH([boost-date-time],
AS_HELP_STRING([--with-boost-date-time@<:@=special-lib@:>@],
[use the Date_Time library from boost - it is possible to specify a certain library for the linker
e.g. --with-boost-date-time=boost_date_time-gcc-mt-d-1_33_1 ]),
[
if test "$withval" = "no"; then
want_boost="no"
elif test "$withval" = "yes"; then
want_boost="yes"
ax_boost_user_date_time_lib=""
else
want_boost="yes"
ax_boost_user_date_time_lib="$withval"
fi
],
[want_boost="yes"]
)
if test "x$want_boost" = "xyes"; then
AC_REQUIRE([AC_PROG_CC])
CPPFLAGS_SAVED="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
export CPPFLAGS
LDFLAGS_SAVED="$LDFLAGS"
LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
export LDFLAGS
AC_CACHE_CHECK(whether the Boost::Date_Time library is available,
ax_cv_boost_date_time,
[AC_LANG_PUSH([C++])
AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[@%:@include <boost/date_time/gregorian/gregorian_types.hpp>]],
[[using namespace boost::gregorian; date d(2002,Jan,10);
return 0;
]]),
ax_cv_boost_date_time=yes, ax_cv_boost_date_time=no)
AC_LANG_POP([C++])
])
if test "x$ax_cv_boost_date_time" = "xyes"; then
AC_DEFINE(HAVE_BOOST_DATE_TIME,,[define if the Boost::Date_Time library is available])
BN=boost_date_time
if test "x$ax_boost_user_date_time_lib" = "x"; then
for ax_lib in $BN $BN-st $BN-mt $BN-mt-s $BN-s \
$BN-$CC $BN-$CC-st $BN-$CC-mt $BN-$CC-mt-s $BN-$CC-s \
lib$BN lib$BN-st lib$BN-mt lib$BN-mt-s lib$BN-s \
lib$BN-$CC lib$BN-$CC-st lib$BN-$CC-mt lib$BN-$CC-mt-s lib$BN-$CC-s \
$BN-mgw $BN-mgw $BN-mgw-st $BN-mgw-mt $BN-mgw-mt-s $BN-mgw-s ; do
AC_CHECK_LIB($ax_lib, main, [BOOST_DATE_TIME_LIB="-l$ax_lib" AC_SUBST(BOOST_DATE_TIME_LIB) link_date_time="yes" break],
[link_date_time="no"])
done
else
for ax_lib in $ax_boost_user_date_time_lib $BN-$ax_boost_user_date_time_lib; do
AC_CHECK_LIB($ax_lib, main,
[BOOST_DATE_TIME_LIB="-l$ax_lib" AC_SUBST(BOOST_DATE_TIME_LIB) link_date_time="yes" break],
[link_date_time="no"])
done
fi
if test "x$link_date_time" = "xno"; then
AC_MSG_ERROR(Could not link against $ax_lib !)
fi
fi
CPPFLAGS="$CPPFLAGS_SAVED"
LDFLAGS="$LDFLAGS_SAVED"
fi
])
dnl-----------------------------------------------------------------------------
dnl Macro to check for curl of sufficient version by looking at curl-config
dnl
dnl usage:
dnl AC_CHECK_CURL(version, action-if, action-not)
dnl
dnl defines CURL_LIBS, CURL_CFLAGS, see curl-config man page
dnl-----------------------------------------------------------------------------
AC_DEFUN([AC_CHECK_CURL], [
succeeded=no
if test -z "$CURL_CONFIG"; then
AC_PATH_PROG(CURL_CONFIG, curl-config, no)
fi
if test "$CURL_CONFIG" = "no" ; then
echo "*** The curl-config script could not be found. Make sure it is"
echo "*** in your path, and that curl is properly installed."
echo "*** Or see http://curl.haxx.se/"
else
dnl curl-config --version returns "libcurl <version>", thus cut the number
CURL_VERSION=`$CURL_CONFIG --version | cut -d" " -f2`
AC_MSG_CHECKING(for curl >= $1)
VERSION_CHECK=`expr $CURL_VERSION \>\= $1`
if test "$VERSION_CHECK" = "1" ; then
AC_MSG_RESULT(yes)
succeeded=yes
AC_MSG_CHECKING(CURL_CFLAGS)
CURL_CFLAGS=`$CURL_CONFIG --cflags`
AC_MSG_RESULT($CURL_CFLAGS)
AC_MSG_CHECKING(CURL_LIBS)
CURL_LIBS=`$CURL_CONFIG --libs`
AC_MSG_RESULT($CURL_LIBS)
else
CURL_CFLAGS=""
CURL_LIBS=""
## If we have a custom action on failure, don't print errors, but
## do set a variable so people can do so.
ifelse([$3], ,echo "can't find curl >= $1",)
fi
AC_SUBST(CURL_CFLAGS)
AC_SUBST(CURL_LIBS)
fi
if test $succeeded = yes; then
ifelse([$2], , :, [$2])
else
ifelse([$3], , AC_MSG_ERROR([Library requirements (curl) not met.]), [$3])
fi
])

View File

@ -1,25 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<audioClip id="0000000000000001"
playlength="00:18:30.000000" uri="file:var/test1.mp3">
<metadata
xmlns="http://mdlf.org/campcaster/elements/1.0/"
xmlns:ls="http://mdlf.org/campcaster/elements/1.0/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
>
<dc:title >File Title txt</dc:title>
<dcterms:alternative >Alternative File Title ín sőmé %$#@* LÁNGŰAGÉ</dcterms:alternative>
<dc:subject >Keywords: qwe, asd, zcx</dc:subject>
<dc:description >Abstract txt</dc:description>
<dc:date >2004-05-21</dc:date>
<dcterms:available >2004-05-22</dcterms:available>
<dcterms:issued >2004-05-23</dcterms:issued>
<dcterms:modified >2004-05-24</dcterms:modified>
<dcterms:valid >2004-05-25</dcterms:valid>
<dcterms:extent >00:18:30.000000</dcterms:extent>
<dcterms:medium >online</dcterms:medium>
<dcterms:spatial >Spatial Coverage</dcterms:spatial>
<dcterms:temporal >Temporal Coverage</dcterms:temporal>
</metadata>
</audioClip>

View File

@ -1,135 +0,0 @@
dnl-----------------------------------------------------------------------------
dnl Copyright (c) 2010 Sourcefabric O.P.S.
dnl
dnl This file is part of the Campcaster project.
dnl http://campcaster.sourcefabric.org/
dnl
dnl Campcaster is free software; you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
dnl the Free Software Foundation; either version 2 of the License, or
dnl (at your option) any later version.
dnl
dnl Campcaster is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dnl GNU General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License
dnl along with Campcaster; if not, write to the Free Software
dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
dnl
dnl-----------------------------------------------------------------------------
dnl-----------------------------------------------------------------------------
dnl NOTE: Run all configure related scripts from the tmp directory of the
dnl project.
dnl This is due to the fact that configure spreads a lot of trash around,
dnl like atom4te cache directories, config.* files, etc. into the directory
dnl it is being run from. We clearly don't want these in our base directory.
dnl-----------------------------------------------------------------------------
AC_INIT(Core, 0.0, bugs@campware.org)
AC_PREREQ(2.59)
AC_COPYRIGHT([Copyright (c) 2010 Sourcefabric O.P.S. under the GNU GPL])
AC_REVISION($Revision$)
AC_CONFIG_SRCDIR(../src/UniqueId.cxx)
AC_CONFIG_HEADERS(configure.h)
AC_PROG_CXX()
AC_CHECK_TYPES([uint64_t, uint32_t, uint16_t, uint8_t],
HAVE_INTEGRAL_TYPES="yes", HAVE_INTEGRAL_TYPES="no")
if test "x${HAVE_INTEGRAL_TYPES}" = "xno" ; then
AC_MSG_ERROR([a required integral type is not available])
fi
AC_CHECK_HEADERS(getopt.h sys/time.h time.h sys/types.h pwd.h errno.h stdint.h)
dnl-----------------------------------------------------------------------------
dnl specify whether debug info should be compiled into the executable
dnl-----------------------------------------------------------------------------
AC_SUBST(CXXFLAGS)
AC_ARG_ENABLE([debug],
AC_HELP_STRING([--enable-debug], [compile with debug info (no)]),
[],
[enable_debug=no])
if test "x${enable_debug}" = "xyes"; then
CXXFLAGS="-g -O0"
AC_DEFINE(YDEBUG, 1, [Debug is on])
else
CXXFLAGS="-O3"
fi
AC_MSG_RESULT([using compiler options: ${CXXFLAGS}])
dnl-----------------------------------------------------------------------------
dnl specify the pkg-config path
dnl-----------------------------------------------------------------------------
AC_ARG_WITH([pkg-config-path],
AC_HELP_STRING([--with-pkg-config-path],
[use the pkg-config path (prefix/lib/pkgconfig)]),
[PKG_CONFIG_PATH=${withval}],
[PKG_CONFIG_PATH=${prefix}/lib/pkgconfig:$PKG_CONFIG_PATH])
AC_MSG_RESULT([using pkg-config path: ${PKG_CONFIG_PATH}])
export PKG_CONFIG_PATH
export PATH=${prefix}/bin:${PATH}
AX_BOOST_BASE([1.33.1])
if test "x${BOOST_CPPFLAGS}" != "x"; then
AX_BOOST_DATE_TIME
if test "x${BOOST_DATE_TIME_LIB}" = "x"; then
AC_MSG_ERROR([Boost date-time library not found])
fi
else
AC_MSG_ERROR([Boost library >= 1.33.1 not found])
fi
PKG_CHECK_MODULES(LIBXMLPP,[libxml++-2.6 >= 2.8.1])
AC_SUBST(LIBXMLPP_CFLAGS)
AC_SUBST(LIBXMLPP_LIBS)
AC_CHECK_CURL(7.12.3)
AC_SUBST(CURL_CFLAGS)
AC_SUBST(CURL_LIBS)
AC_CHECK_TAGLIB(1.3.1)
AC_SUBST(TAGLIB_CFLAGS)
AC_SUBST(TAGLIB_LIBS)
AC_CHECK_ICU(3.0)
AC_SUBST(ICU_CFLAGS)
AC_SUBST(ICU_CXXFLAGS)
AC_SUBST(ICU_LIBS)
AC_PATH_PROG(GENRB, genrb)
AC_SUBST(GENRB)
dnl-----------------------------------------------------------------------------
dnl enable compilaton for code coverage data
dnl-----------------------------------------------------------------------------
AC_SUBST(COVERAGE_CXXFLAGS)
AC_ARG_ENABLE( coverage,
[ --enable-coverage enable code coverage data generaton (no) ],
ENABLE_COVERAGE=${enableval}, ENABLE_COVERAGE="no" )
if test "x${ENABLE_COVERAGE}" == "xyes" ; then
COVERAGE_CXXFLAGS="-fprofile-arcs -ftest-coverage"
AC_MSG_RESULT([compiling in code coverage mode])
else
AC_MSG_RESULT([not compiling in code coverage mode])
fi
AC_CONFIG_FILES(../Makefile:../etc/Makefile.in)
AC_OUTPUT()

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE fadeInfo [
<!ELEMENT fadeInfo EMPTY >
<!ATTLIST fadeInfo id NMTOKEN #REQUIRED >
<!ATTLIST fadeInfo fadeIn NMTOKEN #REQUIRED >
<!ATTLIST fadeInfo fadeOut NMTOKEN #REQUIRED >
]>
<fadeInfo id="0000000000009901" fadeIn="00:00:02.000000"
fadeOut="00:00:01.0005"/>

View File

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE metadataType [
<!ELEMENT metadataType EMPTY >
<!ATTLIST metadataType dcName NMTOKEN #REQUIRED >
<!ATTLIST metadataType id3Tag NMTOKEN #IMPLIED >
<!ATTLIST metadataType localizationKey NMTOKEN #REQUIRED >
<!ATTLIST metadataType tab NMTOKEN #IMPLIED >
]>
<metadataType dcName = "dc:creator"
id3Tag = "TPE2"
localizationKey = "creator"
tab = "main"
/>

View File

@ -1,212 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE metadataTypeContainer [
<!ELEMENT metadataTypeContainer (metadataType+) >
<!ELEMENT metadataType (constraint?) >
<!ATTLIST metadataType dcName NMTOKEN #REQUIRED >
<!ATTLIST metadataType id3Tag CDATA #IMPLIED >
<!ATTLIST metadataType localizationKey CDATA #REQUIRED >
<!ATTLIST metadataType tab NMTOKEN #IMPLIED >
<!ELEMENT constraint (value*) >
<!ATTLIST constraint type NMTOKEN #REQUIRED >
<!ELEMENT value (#PCDATA) >
]>
<metadataTypeContainer>
<metadataType dcName = "dc:title"
id3Tag = "TIT2"
localizationKey = "title"
tab = "main"
/>
<metadataType dcName = "dc:creator"
id3Tag = "TPE1"
localizationKey = "creator"
tab = "main"
/>
<metadataType dcName = "dc:source"
id3Tag = "TALB"
localizationKey = "album"
tab = "music"
/>
<metadataType dcName = "ls:year"
id3Tag = "TYER"
localizationKey = "year"
tab = "music" >
<constraint type = "numericRange" >
<value>0</value>
<value>3000</value>
</constraint>
</metadataType>
<metadataType dcName = "dc:type"
id3Tag = "TCON"
localizationKey = "genre"
tab = "main"
/>
<metadataType dcName = "dc:description"
id3Tag = "COMM"
localizationKey = "description"
tab = "main"
/>
<metadataType dcName = "dc:format"
localizationKey = "format" >
<constraint type = "enumeration" >
<value>mp3</value>
<value>mpeg</value>
<value>ogg</value>
</constraint>
</metadataType>
<metadataType dcName = "ls:bpm"
id3Tag = "TBPM"
localizationKey = "bpm"
tab = "music" >
<constraint type = "numeric" />
</metadataType>
<metadataType dcName = "ls:rating"
id3Tag = "POPM"
localizationKey = "rating"
tab = "music"
/>
<metadataType dcName = "dcterms:extent"
localizationKey = "length"
/>
<metadataType dcName = "ls:encoded_by"
id3Tag = "TENC"
localizationKey = "encoded_by"
tab = "music"
/>
<metadataType dcName = "ls:track_num"
id3Tag = "TRCK"
localizationKey = "track_number"
tab = "music" >
<constraint type = "numeric" />
</metadataType>
<metadataType dcName = "ls:disc_num"
id3Tag = "TPOS"
localizationKey = "disc_number"
tab = "music" >
<constraint type = "numeric" />
</metadataType>
<metadataType dcName = "ls:mood"
id3Tag = "TMOO"
localizationKey = "mood"
tab = "music"
/>
<metadataType dcName = "dc:publisher"
id3Tag = "TPUB"
localizationKey = "publishing_label"
tab = "music"
/>
<metadataType dcName = "ls:composer"
id3Tag = "TCOM"
localizationKey = "composer"
tab = "music"
/>
<metadataType dcName = "ls:bitrate"
localizationKey = "bitrate"
tab = "music" >
<constraint type = "numeric" />
</metadataType>
<metadataType dcName = "ls:channels"
localizationKey = "channels"
tab = "music"
/>
<metadataType dcName = "ls:samplerate"
localizationKey = "sample_rate"
tab = "music" >
<constraint type = "numeric" />
</metadataType>
<metadataType dcName = "ls:encoder"
id3Tag = "TSSE"
localizationKey = "encoding_software"
tab = "music"
/>
<metadataType dcName = "ls:crc"
localizationKey = "checksum"
/>
<metadataType dcName = "ls:lyrics"
localizationKey = "lyrics"
tab = "music"
/>
<metadataType dcName = "ls:orchestra"
id3Tag = "TPE2"
localizationKey = "orchestra_or_band"
tab = "music"
/>
<metadataType dcName = "ls:conductor"
id3Tag = "TPE3"
localizationKey = "conductor"
tab = "music"
/>
<metadataType dcName = "ls:lyricist"
id3Tag = "TEXT"
localizationKey = "lyricist"
tab = "music"
/>
<metadataType dcName = "ls:originallyricist"
id3Tag = "TOLY"
localizationKey = "original_lyricist"
tab = "music"
/>
<metadataType dcName = "ls:radiostationname"
id3Tag = "TRSN"
localizationKey = "radio_station_name"
/>
<metadataType dcName = "ls:audiofileinfourl"
id3Tag = "WOAF"
localizationKey = "audio_file_info_url"
/>
<metadataType dcName = "ls:artisturl"
id3Tag = "WOAR"
localizationKey = "artist_url"
/>
<metadataType dcName = "ls:audiosourceurl"
id3Tag = "WOAS"
localizationKey = "audio_source_url"
/>
<metadataType dcName = "ls:radiostationurl"
id3Tag = "WORS"
localizationKey = "radio_station_url"
/>
<metadataType dcName = "ls:buycdurl"
id3Tag = "WPAY"
localizationKey = "buy_cd_url"
/>
<metadataType dcName = "ls:isrcnumber"
id3Tag = "TSRC"
localizationKey = "isrc_number"
/>
<metadataType dcName = "ls:catalognumber"
localizationKey = "catalog_number"
/>
<metadataType dcName = "ls:originalartist"
id3Tag = "TOPE"
localizationKey = "original_artist"
tab = "music"
/>
<metadataType dcName = "dc:rights"
id3Tag = "TCOP"
localizationKey = "copyright"
tab = "music"
/>
<metadataType dcName = "dcterms:temporal"
localizationKey = "report_date_time"
tab = "voice"
/>
<metadataType dcName = "dcterms:spatial"
localizationKey = "report_location"
tab = "voice"
/>
<metadataType dcName = "dcterms:entity"
localizationKey = "report_organizations"
tab = "voice"
/>
<metadataType dcName = "dc:subject"
localizationKey = "subject"
tab = "voice"
/>
</metadataTypeContainer>

View File

@ -1,58 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE playlist [
<!ELEMENT playlist (playlistElement*) >
<!ATTLIST playlist id NMTOKEN #REQUIRED >
<!ATTLIST playlist title CDATA "" >
<!ATTLIST playlist playlength NMTOKEN #REQUIRED >
<!ELEMENT playlistElement ((audioClip|playlist), fadeInfo?) >
<!ATTLIST playlistElement id NMTOKEN #REQUIRED >
<!ATTLIST playlistElement relativeOffset NMTOKEN #REQUIRED >
<!ELEMENT audioClip EMPTY >
<!ATTLIST audioClip id NMTOKEN #REQUIRED >
<!ATTLIST audioClip playlength NMTOKEN #REQUIRED >
<!ATTLIST audioClip title CDATA #REQUIRED >
<!ATTLIST audioClip uri CDATA #IMPLIED >
<!ELEMENT fadeInfo EMPTY >
<!ATTLIST fadeInfo id NMTOKEN #REQUIRED >
<!ATTLIST fadeInfo fadeIn NMTOKEN #REQUIRED >
<!ATTLIST fadeInfo fadeOut NMTOKEN #REQUIRED >
]>
<playlist id="0000000000000001"
title="My First Playlist"
playlength="00:00:34.000000" >
<playlistElement id="0000000000000101"
relativeOffset="00:00:00.000000" >
<audioClip id="0000000000010001"
playlength="00:00:11.000000"
title = "one"
uri="file:var/test1.mp3" />
</playlistElement>
<playlistElement id="0000000000000102"
relativeOffset="00:00:11.000000" >
<audioClip id="0000000000010002"
playlength="00:00:12.000000"
title = "two"
uri="file:var/test2.mp3" />
<fadeInfo id="0000000000009901"
fadeIn="00:00:02.000000"
fadeOut="00:00:01.500000" />
</playlistElement>
<playlistElement id="0000000000000103"
relativeOffset="00:00:23.000000" >
<playlist id="0000000000000002"
playlength="00:00:11.000000" >
<playlistElement id="0000000000000111"
relativeOffset="00:00:00.000000" >
<audioClip id="0000000000010003"
playlength="00:00:11.000000"
title = "three"
uri="file:var/test3.mp3" />
</playlistElement>
</playlist>
</playlistElement>
</playlist>

View File

@ -1,39 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE playlistElement [
<!ELEMENT playlistElement ((audioClip|playlist), fadeInfo?) >
<!ATTLIST playlistElement id NMTOKEN #REQUIRED >
<!ATTLIST playlistElement relativeOffset NMTOKEN #REQUIRED >
<!ELEMENT playlist (playlistElement*) >
<!ATTLIST playlist id NMTOKEN #REQUIRED >
<!ATTLIST playlist playlength NMTOKEN #REQUIRED >
<!ELEMENT audioClip EMPTY >
<!ATTLIST audioClip id NMTOKEN #REQUIRED >
<!ATTLIST audioClip playlength NMTOKEN #REQUIRED >
<!ATTLIST audioClip title CDATA #REQUIRED >
<!ATTLIST audioClip uri CDATA #IMPLIED >
<!ELEMENT fadeInfo EMPTY >
<!ATTLIST fadeInfo id NMTOKEN #REQUIRED >
<!ATTLIST fadeInfo fadeIn NMTOKEN #REQUIRED >
<!ATTLIST fadeInfo fadeOut NMTOKEN #REQUIRED >
]>
<playlistElement id="0000000000000103"
relativeOffset="00:00:11.000000" >
<playlist id="0000000000000002"
playlength="00:00:11.000000" >
<playlistElement id="0000000000000111"
relativeOffset="00:00:00.000000" >
<audioClip id="0000000000010003"
playlength="00:00:11.000000"
title = "three"
uri="file:var/test3.mp3" />
</playlistElement>
</playlist>
<fadeInfo id="0000000000009901"
fadeIn="00:00:02.000000"
fadeOut="00:00:01.500000" />
</playlistElement>

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE rdsContainer [
<!ELEMENT rdsContainer (rdsItem*) >
<!ELEMENT rdsItem EMPTY >
<!ATTLIST rdsItem key CDATA #REQUIRED >
<!ATTLIST rdsItem value CDATA #REQUIRED >
<!ATTLIST rdsItem enabled (0|1) #REQUIRED >
]>
<rdsContainer>
<rdsItem key="PS" value="BBC Four" enabled="1" />
<rdsItem key="RT" value="C. Monster - Monsterpiece Theater"
enabled="1" />
<rdsItem key="RT" value="Acme Birdseed for the discerning coyote"
enabled="0" />
</rdsContainer>

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE resourceBundle [
<!ELEMENT resourceBundle EMPTY >
<!ATTLIST resourceBundle path CDATA #REQUIRED >
<!ATTLIST resourceBundle locale CDATA #REQUIRED >
]>
<resourceBundle path = "./tmp/Core"
locale = "en"
/>

View File

@ -1,63 +0,0 @@
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>Campcaster unit test results</title>
</head>
<body>
<h1>Preface</h1>
This document is part of the
<a href="http://campcaster.sourcefabric.org/">Campcaster</a>
project, Copyright &#169; 2004 <a href="http://www.mdlf.org/">Media
Development Loan Fund</a>, under the GNU
<a href="http://www.gnu.org/licenses/gpl.html">GPL</a>.
<br/>
This is an automatically generated document.
<h1>Scope</h1>
This document contains the generated unit test results for the
<a href="http://campcaster.sourcefabric.org/">Campcaster</a> project.
<h1>Summary</h1>
<xsl:for-each select="//Statistics">
<table>
<tr>
<td><b>Total number of tests:</b></td>
<td><xsl:value-of select="Tests"/></td>
</tr>
<tr>
<td><b>Tests passed:</b></td>
<td><xsl:value-of select="count(/*/SuccessfulTests/Test)"/></td>
</tr>
<tr>
<td><b>Tests failed:</b></td>
<td><xsl:value-of select="Failures"/></td>
</tr>
<tr>
<td><b>Test errors:</b></td>
<td><xsl:value-of select="Errors"/></td>
</tr>
</table>
</xsl:for-each>
<h1>Tests</h1>
<table>
<tr>
<th>test name</th>
<th>test status</th>
</tr>
<xsl:for-each select="//Test | //FailedTest">
<xsl:sort select="Name"/>
<tr>
<td><xsl:value-of select="Name"/></td>
<xsl:if test="ancestor::FailedTests"><td bgcolor="red">failed</td></xsl:if>
<xsl:if test="ancestor::SuccessfulTests"><td bgcolor="lightblue">passed</td></xsl:if>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

View File

@ -1,212 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_AsyncState_h
#define LiveSupport_Core_AsyncState_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#include <ostream>
#include <string>
#include "LiveSupport/Core/Ptr.h"
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A class representing the state of an asynchronous process.
*
* It provides some constants, plus conversion methods to and from
* strings (used when sending through XML-RPC methods).
*
* There are two sets of conversion methods, because the states have
* different names in the storage server for backup-related stuff and
* general transport stuff.
*/
class AsyncState
{
private:
/**
* The possible states of an asynchronous process.
*/
typedef enum { innerInitState,
innerPendingState,
innerFinishedState,
innerClosedState,
innerFailedState,
innerInvalidState } InnerState;
/**
* The value of this state.
*/
InnerState value;
/**
* A private constructor.
*/
AsyncState(InnerState state) throw ()
: value(state)
{
}
public:
/**
* Default constructor; sets the state to "invalid".
*/
AsyncState(void) throw ()
: value(innerInvalidState)
{
}
/**
* Constant instance: init.
*/
static const AsyncState initState;
/**
* Constant instance: pending.
*/
static const AsyncState pendingState;
/**
* Constant instance: finished.
*/
static const AsyncState finishedState;
/**
* Constant instance: closed.
*/
static const AsyncState closedState;
/**
* Constant instance: failed.
*/
static const AsyncState failedState;
/**
* Constant instance: invalid.
*/
static const AsyncState invalidState;
/**
* Construct from a transport string.
*
* @param transportString a string used by the getTransportInfo
* method of the storage server.
* @return an AsyncState with the corresponding value.
*/
static AsyncState
fromTransportString(const std::string & transportString)
throw ();
/**
* Construct from a backup string.
*
* @param backupString a string used by the xxxxBackupCheck
* method of the storage server.
* @return an AsyncState with the corresponding value.
*/
static AsyncState
fromBackupString(const std::string & backupString)
throw ();
/**
* Convert to a transport string.
*
* @return a string used by the getTransportInfo method of the
* storage server.
*/
Ptr<std::string>::Ref
toTransportString(void) const throw ();
/**
* Convert to a backup string.
*
* @return a string used by the xxxxBackupCheck method of the
* storage server.
*/
Ptr<std::string>::Ref
toBackupString(void) const throw ();
/**
* Check for equality.
*
* @param other the other AsyncState to compare with.
* @return true if the two states are equal.
*/
bool
operator==(const AsyncState & other) const throw ()
{
return (value == other.value);
}
/**
* Check for inequality.
*
* @param other the other AsyncState to compare with.
* @return true if the two states are not equal.
*/
bool
operator!=(const AsyncState & other) const throw ()
{
return (value != other.value);
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
/**
* Print to an ostream.
*
* @param ostream the ostream to print to.
* @param state the AsyncState to print.
* @return a reference to the same ostream object.
*/
std::ostream&
operator<<(std::ostream& ostream, const LiveSupport::Core::AsyncState state)
throw ();
#endif // LiveSupport_Core_AsyncState_h

View File

@ -1,611 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_AudioClip_h
#define LiveSupport_Core_AudioClip_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <stdexcept>
#include <string>
#include <libxml++/libxml++.h>
#include <XmlRpcValue.h>
#include <boost/date_time/posix_time/posix_time.hpp>
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/UniqueId.h"
#include "LiveSupport/Core/Configurable.h"
#include "LiveSupport/Core/Playable.h"
#include "LiveSupport/Core/MetadataTypeContainer.h"
namespace LiveSupport {
namespace Core {
using namespace std;
using namespace boost::posix_time;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A class representing an audio clip.
* AudioClips contain the basic information about the audio clip.
* An AudioClip is contained in a PlaylistElement, which provides the
* relative offset and fade in/fade out information. A PlaylistElement,
* in turn, is contained in a Playlist.
*
* This object has to be configured with an XML configuration element
* called audioClip. This may look like the following:
*
* <pre><code>
* &lt;audioClip id="1"
* title="Name of the Song"
* playlength="00:18:30.000000"
* uri="file:var/test1.mp3" &gt;
* &lt;metadata
* xmlns="http://mdlf.org/livesupport/elements/1.0/"
* xmlns:ls="http://mdlf.org/livesupport/elements/1.0/"
* xmlns:dc="http://purl.org/dc/elements/1.1/"
* xmlns:dcterms="http://purl.org/dc/terms/"
* xmlns:xml="http://www.w3.org/XML/1998/namespace" &gt;
* &lt;dc:title &gt;File Title txt&lt;/dc:title&gt;
* &lt;dcterms:extent &gt;00:02:30.000000&lt;/dcterms:extent&gt;
* ...
* &lt;/metadata&gt;
* &lt;/audioClip&gt;
* </code></pre>
*
* The metadata element is optional. The <code>configure()</code> method
* sets only those fields which had not been set previously: e.g., if we set
* some or all fields of the AudioClip in the constructor, then these fields
* in the XML element will be ignored by <code>configure()</code>.
* The <code>title</code> attribute and the <code>&lt;dc:title&gt;</code>
* element set the same field; if both are present, the title is set from
* the attribute and the element is ignored..
* The same is true for the <code>playlength</code> attribute and the
* <code>&lt;dcterms:extent&gt;</code> element.
* It is required that by the end of the configure() method, the playlength
* is set somehow (from a constructor, the attribute or the element).
* If the title is not set by the end of the configure() method, it is then
* set to the empty string.
* Embedded XML elements are currently ignored: e.g.,
* <pre><code> &lt;group&gt;
* &lt;member1&gt;value1&lt;/member1&gt;
* &lt;member2&gt;value2&lt;/member2&gt;
* &lt;/group&gt;</code></pre>
* produces a single metadata field <code>group</code> with an empty value,
* and ignores <code>member1</code> and <code>member2</code>.
* TODO: fix this?
*
* The URI is not normally part of the XML element; it's only included
* as an optional attribute for testing purposes.
*
* The DTD for the above element is:
*
* <pre><code>
* &lt;!ELEMENT audioClip (metadata?) &gt;
* &lt;!ATTLIST audioClip id NMTOKEN #IMPLIED &gt;
* &lt;!ATTLIST audioClip title CDATA #IMPLIED &gt;
* &lt;!ATTLIST audioClip playlength NMTOKEN #IMPLIED &gt;
* &lt;!ATTLIST audioClip uri CDATA #IMPLIED &gt;
* </code></pre>
*/
class AudioClip : public Configurable,
public Playable
{
private:
/**
* The name of the configuration XML elmenent used by AudioClip.
*/
static const std::string configElementNameStr;
/**
* The unique id of the audio clip.
*/
Ptr<UniqueId>::Ref id;
/**
* The title of the audio clip.
*/
Ptr<const Glib::ustring>::Ref title;
/**
* The playling length of the audio clip.
*/
Ptr<time_duration>::Ref playlength;
/**
* The location of the binary audio clip sound file.
*/
Ptr<const std::string>::Ref uri;
/**
* The identifying token returned by the storage server.
*/
Ptr<const std::string>::Ref token;
/**
* This audio clip in XML format.
*/
Ptr<xmlpp::Document>::Ref xmlAudioClip;
/**
* Set the value of a metadata field in this audio clip.
*
* @param value the new value of the metadata field.
* @param name the name of the metadata field (without prefix)
* @param prefix the prefix of the metadata field
* @exception std::invalid_argument if the key is dcterms:extent,
* but the value is not a valid ISO-8601 time
*/
virtual void
setMetadata(Ptr<const Glib::ustring>::Ref value,
const std::string &name, const std::string &prefix)
throw (std::invalid_argument);
/**
* Convert a time_duration to string, in format HH:MM:SS.ssssss.
*/
std::string
toFixedString(Ptr<time_duration>::Ref time) const throw ()
{
if (time->fractional_seconds()) {
return to_simple_string(*time);
} else {
return to_simple_string(*time) + ".000000";
}
}
/**
* Set the playlength member of this audio clip.
*
* @param timeString the new playlength
* @exception std::invalid_argument if the argument is not
* a valid ISO-8601 time
*/
void
setPlaylength(Ptr<const std::string>::Ref timeString)
throw (std::invalid_argument);
public:
/**
* Copy constructor.
*
* Copies the <i>pointers</i> for all fields except xmlAudioClip.
* These fields are immutable; if you want to modify them, call the
* appropriate setter function with (a pointer to) an object
* with the new value.
*
* @param otherAudioClip the audio clip to be copied
*/
AudioClip(const AudioClip & otherAudioClip) throw ();
/**
* Default constructor.
*
* This constructor creates an AudioClip with a null pointer
* for all (ID, playlength, title, uri) fields! It is meant for
* internal use only. If you want to upload a new audio clip to
* the storage, use the constructor with (title, playlength, uri)
* arguments.
*/
AudioClip(void) throw ()
: Playable(AudioClipType)
{
}
/**
* Create an audio clip by specifying its unique ID.
* The other fields will be filled in by configure().
*
* This constructor creates an AudioClip with a null pointer
* for all fields except the ID! It is meant for internal use only.
* If you want to upload a new audio clip to the storage,
* use the constructor with (title, playlength, uri) arguments.
*
* @param id the id of the audio clip.
*/
AudioClip(Ptr<UniqueId>::Ref id) throw ()
: Playable(AudioClipType)
{
this->id = id;
}
/**
* Create an audio clip by specifying all details, except
* for the title. The title is set to the empty string.
*
* This is used for testing purposes.
* If you want to upload a new audio clip to the storage,
* use the constructor with (title, playlength, uri) arguments.
*
* @param id the id of the audio clip.
* @param playlength the playing length of the audio clip.
* @param uri the location of the sound file corresponding to
* this audio clip object (optional)
*/
AudioClip(Ptr<UniqueId>::Ref id,
Ptr<time_duration>::Ref playlength,
Ptr<const std::string>::Ref uri = Ptr<string>::Ref())
throw ();
/**
* Create an audio clip by specifying all details.
*
* This is used for testing purposes.
* If you want to upload a new audio clip to the storage,
* use the constructor with (title, playlength, uri) arguments.
*
* @param id the id of the audio clip.
* @param title the title of the audio clip.
* @param playlength the playing length of the audio clip.
* @param uri the location of the sound file corresponding to
* this audio clip object (optional)
*/
AudioClip(Ptr<UniqueId>::Ref id,
Ptr<const Glib::ustring>::Ref title,
Ptr<time_duration>::Ref playlength,
Ptr<const std::string>::Ref uri = Ptr<string>::Ref())
throw ();
/**
* Create an audio clip by specifying all details which need
* to be set by the user.
* The ID is left blank (i.e., a null pointer),
* and can be set later using setId().
*
* This constructor is used when a new audio clip is uploaded to
* the storage. For example:
* <pre><code>
* Ptr<StorageClientFactory>::Ref
* storageClientFactory = StorageClientFactory::getInstance();
* Ptr<StorageClientInterface>::Ref
* storageClient = storageClientFactory->getStorageClient();
* Ptr<AudioClip>::Ref
* audioClip(new AudioClip(title, playlength, uri));
* storageClient->storeAudioClip(sessionId, audioClip);
* std::cerr << audioClip->getId()->getId(); // has been set by the
* // storage client
* </code></pre>
*
* @see StorageClient::StorageClientFactory
* @see StorageClient::StorageClientInterface
*
* @param playlength the playing length of the audio clip.
* @param title the title of the audio clip.
* @param uri the location of the sound file corresponding to
* this audio clip object.
*/
AudioClip(Ptr<const Glib::ustring>::Ref title,
Ptr<time_duration>::Ref playlength,
Ptr<const std::string>::Ref uri)
throw ();
/**
* Convert the audio clip to an XmlRpcValue (marshalling).
*
* @return an XmlRpcValue struct, containing a
* field named <i>audioClip</i>, with value of type string,
* which contains an XML document representing the audio clip.
*/
operator XmlRpc::XmlRpcValue() const
throw ();
/**
* Construct an audio clip from an XmlRpcValue (demarshalling).
*
* @param xmlRpcValue an XmlRpcValue struct, containing a
* field named <i>audioClip</i>, with value of type string,
* which contains an XML document, the root node of which
* can be passed to the configure() method.
* @exception std::invalid_argument if the argument is invalid
*/
AudioClip(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* A virtual destructor, as this class has virtual functions.
*/
virtual
~AudioClip(void) throw ()
{
}
/**
* Return the name of the XML element this object expects
* to be sent to a call to configure().
*
* @return the name of the expected XML configuration element.
*/
static const std::string
getConfigElementName(void) throw ()
{
return configElementNameStr;
}
/**
* Configure the object based on the XML element supplied.
* The supplied element is expected to be of the name
* returned by configElementName().
*
* @param element the XML element to configure the object from.
* @exception std::invalid_argument if the supplied XML element
* contains bad configuraiton information
*/
virtual void
configure(const xmlpp::Element & element)
throw (std::invalid_argument);
/**
* Return the id of the audio clip.
*
* @return the unique id of the audio clip.
*/
virtual Ptr<UniqueId>::Ref
getId(void) const throw ()
{
return id;
}
/**
* Set the ID of the object. This is only allowed if the ID was
* a null pointer; once the ID is set, it can not be changed.
*
* @param id the new unique id of the audio clip.
*/
void
setId(Ptr<UniqueId>::Ref id) throw (std::invalid_argument)
{
if (!this->id) {
this->id = id;
}
else {
throw std::invalid_argument("can not set the ID twice");
}
}
/**
* Return the total playing length for this audio clip.
*
* @return the playing length in microseconds.
*/
virtual Ptr<time_duration>::Ref
getPlaylength(void) const throw ()
{
return playlength;
}
/**
* Return the URI of the binary sound file of this audio clip,
* which can be played by the audio player.
*
* @return the URI.
*/
virtual Ptr<const std::string>::Ref
getUri(void) const throw ()
{
return uri;
}
/**
* Set the URI of the binary sound file of this audio clip,
* which can be played by the audio player.
*
* @param uri the new URI.
*/
virtual void
setUri(Ptr<const std::string>::Ref uri) throw ()
{
this->uri = uri;
}
/**
* Return the token which is used to identify this audio clip
* to the storage server.
*
* @return the token.
*/
virtual Ptr<const std::string>::Ref
getToken(void) const throw ()
{
return token;
}
/**
* Set the token which is used to identify this audio clip
* to the storage server.
*
* @param token a new token.
*/
virtual void
setToken(Ptr<const std::string>::Ref token)
throw ()
{
this->token = token;
}
/**
* Return the title of this audio clip.
*
* @return the title.
*/
virtual Ptr<const Glib::ustring>::Ref
getTitle(void) const throw ()
{
return title;
}
/**
* Set the title of this audio clip.
*
* @param title a new title.
*/
virtual void
setTitle(Ptr<const Glib::ustring>::Ref title)
throw ();
/**
* Return the value of a metadata field in this audio clip.
* If the audio clip does not have this metadata field, returns a null
* pointer.
*
* @param key the name of the metadata field
* @return the value of the metadata field; 0 if there is
* no such field;
*/
virtual Ptr<Glib::ustring>::Ref
getMetadata(const std::string &key) const
throw ();
/**
* Set the value of a metadata field in this audio clip.
*
* @param value the new value of the metadata field.
* @param key the name of the metadata field
* @exception std::invalid_argument if the key is dcterms:extent,
* but the value is not a valid ISO-8601 time
*/
virtual void
setMetadata(Ptr<const Glib::ustring>::Ref value,
const std::string &key)
throw (std::invalid_argument);
/**
* Return a partial XML representation of this audio clip or playlist.
*
* This is a string containing a single <audioClip> or <playlist>
* XML element, with minimal information (ID, title, playlength)
* only, without an XML header or any other metadata.
*
* The encoding is UTF-8. IDs are 16-digit hexadecimal numbers,
* time durations have the format "hh:mm:ss.ssssss".
*
* @return a string representation of the audio clip as an XML element
*/
virtual Ptr<Glib::ustring>::Ref
getXmlElementString(void) const throw ();
/**
* Return a complete XML representation of this audio clip.
*
* This is a string containing a an XML document with an <audioClip>
* root node, together with an XML header.
*
* The encoding is UTF-8. IDs are 16-digit hexadecimal numbers,
* time durations have the format "hh:mm:ss.ssssss".
*
* The audio clip or playlist can be completely reconstructed from
* the string returned by this method:
* <pre><code>
* Ptr<AudioClip>::Ref audioClip1 = ... something ...;
* Ptr<xmlpp::DomParser>::Ref parser;
* parser->parse_memory(*audioClip1->getXmlDocumentString());
* const xmlpp::Document* document = parser->get_document();
* const xmlpp::Element* root = document->get_root_node();
* Ptr<AudioClip>::Ref audioClip2(new AudioClip());
* audioClip2->configure(*root);
* </code></pre>
* results in two identical audio clips (and the same works for
* playlists, too).
*
* The XML document has the (pseudo-) DTD
* <pre><code>
* &lt;!ELEMENT audioClip (metadata) &gt;
* &lt;!ATTLIST audioClip id NMTOKEN #REQUIRED &gt;
*
* &lt;!ELEMENT metadata (dcterms:extent, dc:title, (ANY)*) &gt;
* &lt;!ELEMENT dcterms:extent (NMTOKEN) &gt;
* &lt;!ELEMENT dc:title (CDATA) &gt;
* </code></pre>
*
* If the audio clip has no metadata at all (this is possible if
* it was created by the default constructor or the constructor
* which takes a unique ID only), a null pointer is returned.
*
* @return a string representation of the audio clip as an XML document
*/
virtual Ptr<Glib::ustring>::Ref
getXmlDocumentString(void) const throw ();
/**
* Read the metadata contained in the id3v2 tags of the mp3 sound
* file. If no id3v2 tags are found, the file is searched for other
* (id3v1, APE, XiphComment) tags.
*
* The tags are processed and translated into Dublin Core
* metadata fields using the MetadataTypeContainer object.
*
* @param metadataTypes contains a list of all supported
* metadata types.
* @exception std::invalid_argument if the AudioClip instance does not
* have a uri field, or the file name contained in the uri
* field is invalid.
*/
void
readTag(Ptr<MetadataTypeContainer>::Ref metadataTypes)
throw (std::invalid_argument);
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
/**
* Auxilliary method used by setMetadata() and getMetadata().
*/
void
separateNameAndNameSpace(const std::string & key,
std::string & name,
std::string & nameSpace)
throw ();
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_AudioClip_h

View File

@ -1,116 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_BaseTestMethod_h
#define LiveSupport_Core_BaseTestMethod_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <stdexcept>
#include <libxml++/libxml++.h>
#include <cppunit/extensions/HelperMacros.h>
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A base class for the test methods.
* Subclass this class for the methods that use configuration files.
* This class gives helpers to access the configuration files
* from various locations (~/.campcaster, ./etc)
*/
class BaseTestMethod : public CPPUNIT_NS::TestFixture
{
private:
/**
* Get the current working directory.
*
* @return the current working directory.
*/
static std::string
getCwd(void) throw ();
public:
/**
* Return the full path for a configuration file.
*
* @param configFileName the name of the configuration file.
* @return the full path of the configuration file, found in the
* appropriate directory.
* @exception std::invalid_argument if the specified config file
* does not exist.
*/
static std::string
getConfigFile(const std::string configFileName)
throw (std::invalid_argument);
/**
* Helper function to return an XML Document object based on
* a config file name.
* First, the proper location of the config file is found.
*
* @param parser the XML DOM parser to use for parsing.
* @param configFileName the name of the configuration file.
* @return an XML document, containing the contents of the
* config file
* @exception std::invalid_argument if the configuration file
* could not be found
* @exception std::exception on parsing errors.
*/
static const xmlpp::Document *
getConfigDocument(xmlpp::DomParser & parser,
const std::string configFileName)
throw (std::invalid_argument,
std::exception);
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_BaseTestMethod_h

View File

@ -1,98 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_Configurable_h
#define LiveSupport_Core_Configurable_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <string>
#include <stdexcept>
#include <libxml++/libxml++.h>
#include "LiveSupport/Core/Ptr.h"
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* An interface marking a class configurable by an XML element.
*/
class Configurable
{
public:
/**
* Configure the object based on the XML element supplied.
* The supplied element is expected to be of the name
* returned by configElementName().
*
* @param element the XML element to configure the object from.
* @exception std::invalid_argument if the supplied XML element
* contains bad configuraiton information
* @exception std::logic_error if the object has already
* been configured, and can not be reconfigured.
*/
virtual void
configure(const xmlpp::Element & element)
throw (std::invalid_argument,
std::logic_error)
= 0;
/**
* A virtual destructor, as this class has virtual functions.
*/
virtual
~Configurable(void) throw ()
{
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_Configurable_h

View File

@ -1,269 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2003-2005 Max Howell <max.howell@methylblue.com>
(c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef CAMPCASTER_DEBUG_H
#define CAMPCASTER_DEBUG_H
#include "configure.h"
#include <iostream>
#include <sys/time.h>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <XmlRpcValue.h>
#ifndef DEBUG_PREFIX
#define CMP_PREFIX ""
#else
#define CMP_PREFIX "[" DEBUG_PREFIX "] "
#endif
/**
* @namespace LiveSupport::Core::Debug
* @short A debug output API with indentation and block timing.
* @author Max Howell <max.howell@methylblue.com>
* @author Ian Monroe <ian@monroe.nu>
*/
namespace LiveSupport {
namespace Core {
namespace Debug {
static int indentAmount = 0;
}
}
}
using namespace LiveSupport;
using namespace LiveSupport::Core;
#ifndef YDEBUG
class NoDebugStream;
typedef NoDebugStream & (*NDBGFUNC)(NoDebugStream &);
class NoDebugStream {
public:
/// Default constructor.
NoDebugStream() {}
~NoDebugStream() {}
NoDebugStream& operator<<(NDBGFUNC) { return *this; }
/**
* Does nothing.
* @return this stream
*/
NoDebugStream &operator<<(short int ) { return *this; }
/**
* Does nothing.
* @return this stream
*/
NoDebugStream &operator<<(unsigned short int ) { return *this; }
/**
* Does nothing.
* @return this stream
*/
NoDebugStream &operator<<(char ) { return *this; }
/**
* Does nothing.
* @return this stream
*/
NoDebugStream &operator<<(unsigned char ) { return *this; }
/**
* Does nothing.
* @return this stream
*/
NoDebugStream &operator<<(int ) { return *this; }
/**
* Does nothing.
* @return this stream
*/
NoDebugStream &operator<<(unsigned int ) { return *this; }
/**
* Does nothing.
* @return this stream
*/
NoDebugStream &operator<<(const char *) { return *this; }
/**
* Does nothing.
* @return this stream
*/
NoDebugStream& operator<<(const void *) { return *this; }
/**
* Does nothing.
* @return this stream
*/
NoDebugStream& operator<<(void *) { return *this; }
/**
* Does nothing.
* @return this stream
*/
NoDebugStream& operator<<(double) { return *this; }
/**
* Does nothing.
* @return this stream
*/
NoDebugStream& operator<<(long) { return *this; }
/**
* Does nothing.
* @return this stream
*/
NoDebugStream& operator<<(unsigned long) { return *this; }
/**
* Does nothing.
* @return this stream
*/
NoDebugStream& operator<<(std::string) { return *this; }
/**
* Does nothing.
* @return this stream
*/
NoDebugStream& operator<<(boost::posix_time::ptime)
{ return *this; }
/**
* Does nothing.
* @return this stream
*/
NoDebugStream& operator<<(boost::posix_time::time_duration)
{ return *this; }
/**
* Does nothing.
* @return this stream
*/
NoDebugStream& operator<<(XmlRpc::XmlRpcValue)
{ return *this; }
};
static inline NoDebugStream debug() { return NoDebugStream(); }
static inline NoDebugStream warning() { return NoDebugStream(); }
static inline NoDebugStream error() { return NoDebugStream(); }
inline NoDebugStream &endl( NoDebugStream & s) { return s; }
#else
static inline std::ostream& debug() { return std::cout << std::string(Debug::indentAmount, ' ') << CMP_PREFIX; }
static inline std::ostream& warning() { return std::cout << std::string(Debug::indentAmount, ' ') << CMP_PREFIX << "[WARNING!] "; }
static inline std::ostream& error() { return std::cout << std::string(Debug::indentAmount, ' ') << CMP_PREFIX << "[ERROR!] "; }
#endif
using std::endl;
namespace LiveSupport { namespace Core {
namespace Debug
{
/**
* @class Debug::Block
* @short Use this to label sections of your code
*
* Usage:
* #define DEBUG_PREFIX "Prefix"
* #include "LiveSupport/Core/Debug.h"
*
* void function()
* {
* ...
* {
* Debug::Block myBlock( "section" );
*
* debug() << "output1" << endl;
* debug() << "output2" << endl;
* }
* ...
* }
*
* Will output:
*
* BEGIN: section
* [prefix] output1
* [prefix] output2
* END: section - Took 0.1s
*
* Its not thread-safe with the indentation count. But a race condition
* involving indentation width isn't a big deal.
*/
class Block
{
public:
Block( std::string label )
: m_label( label )
{
gettimeofday( &m_start, 0 );
debug() << "BEGIN: " << m_label << endl;
indentAmount += 2; //critical section
}
~Block()
{
timeval end;
gettimeofday( &end, 0 );
end.tv_sec -= m_start.tv_sec;
if( end.tv_usec < m_start.tv_usec) {
// Manually carry a one from the seconds field.
end.tv_usec += 1000000;
end.tv_sec--;
}
end.tv_usec -= m_start.tv_usec;
double duration = double(end.tv_sec) + (double(end.tv_usec) / 1000000.0);
indentAmount -= 2; //critical section
debug() << "END__: " << m_label << " - Took " << duration << "s\n";
}
private:
const std::string m_label;
timeval m_start;
};
/**
* @name Debug::stamp()
* @short To facilitate crash/freeze bugs, by making it easy to mark code that has been processed
*
* Usage:
*
* {
* Debug::stamp();
* function1();
* Debug::stamp();
* function2();
* Debug::stamp();
* }
*
* Will output (assuming the crash occurs in function2()
*
* app: Stamp: 1
* app: Stamp: 2
*
*/
inline void stamp()
{
static int n = 0;
debug() << "| Stamp: " << ++n << endl;
}
}
} } //LiveSupport and Core namespaces
#define DEBUG_BLOCK Debug::Block uniquelyNamedStackAllocatedStandardBlock( __PRETTY_FUNCTION__ );
/// Standard function announcer
#define DEBUG_FUNC_INFO { debug() << '[' << __PRETTY_FUNCTION__ << ']' << endl; }
/// Announce a line
#define DEBUG_LINE_INFO { debug() << '[' << __PRETTY_FUNCTION__ << ']' << "Line: " << __LINE__ << endl; }
#endif //CAMPCASTER_DEBUG_H

View File

@ -1,255 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_FadeInfo_h
#define LiveSupport_Core_FadeInfo_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <stdexcept>
#include <string>
#include <libxml++/libxml++.h>
#include <boost/date_time/posix_time/posix_time.hpp>
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/UniqueId.h"
#include "LiveSupport/Core/Configurable.h"
namespace LiveSupport {
namespace Core {
using namespace std;
using namespace boost::posix_time;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A class representing fade in / fade out information of a playlist element.
* This is contained in a PlaylistElement, a list of which, in turn, is
* contained in a Playlist.
*
* This object has to be configured with an XML configuration element
* called fadeInfo. This may look like the following:
*
* <pre><code>
* &lt;fadeInfo id="9901"
* fadeIn="00:00:02.000000"
* fadeOut="00:00:01.500000" &gt;
* &lt;/fadeInfo&gt;
* </code></pre>
*
* The DTD for the above element is:
*
* <pre><code>
* &lt;!ELEMENT fadeInfo EMPTY &gt;
* &lt;!ATTLIST fadeInfo id NMTOKEN #REQUIRED &gt;
* &lt;!ATTLIST fadeInfo fadeIn NMTOKEN #REQUIRED &gt;
* &lt;!ATTLIST fadeInfo fadeIn NMTOKEN #REQUIRED &gt;
* </code></pre>
*/
class FadeInfo : public Configurable
{
private:
/**
* The name of the configuration XML elmenent used by FadeInfo.
*/
static const std::string configElementNameStr;
/**
* The unique id of the fade info.
*/
Ptr<UniqueId>::Ref id;
/**
* The length of fade in period.
*/
Ptr<time_duration>::Ref fadeIn;
/**
* The length of fade out period.
*/
Ptr<time_duration>::Ref fadeOut;
/**
* Convert a time_duration to string, in format HH:MM:SS.ssssss.
*/
std::string
toFixedString(Ptr<time_duration>::Ref time) const throw ()
{
if (time->fractional_seconds()) {
return to_simple_string(*time);
} else {
return to_simple_string(*time) + ".000000";
}
}
public:
/**
* Default constructor.
*/
FadeInfo(void) throw ()
{
}
/**
* Create a fade info instance by specifying all details.
* This is used for testing purposes.
*
* @param id the id of the fade info.
* @param fadeIn the length of the fade in period.
* @param fadeOut the length of the fade in period.
*/
FadeInfo(Ptr<UniqueId>::Ref id,
Ptr<time_duration>::Ref fadeIn,
Ptr<time_duration>::Ref fadeOut) throw()
{
this->id = id;
this->fadeIn = fadeIn;
this->fadeOut = fadeOut;
}
/**
* Create a fade info instance by specifying the fade in and fade out.
*
* @param fadeIn the length of the fade in period.
* @param fadeOut the length of the fade in period.
*/
FadeInfo(Ptr<time_duration>::Ref fadeIn,
Ptr<time_duration>::Ref fadeOut) throw()
{
this->id = UniqueId::generateId();
this->fadeIn = fadeIn;
this->fadeOut = fadeOut;
}
/**
* A virtual destructor, as this class has virtual functions.
*/
virtual
~FadeInfo(void) throw ()
{
}
/**
* Return the name of the XML element this object expects
* to be sent to a call to configure().
*
* @return the name of the expected XML configuration element.
*/
static const std::string
getConfigElementName(void) throw ()
{
return configElementNameStr;
}
/**
* Configure the object based on the XML element supplied.
* The supplied element is expected to be of the name
* returned by configElementName().
*
* @param element the XML element to configure the object from.
* @exception std::invalid_argument if the supplied XML element
* contains bad configuraiton information
*/
virtual void
configure(const xmlpp::Element & element)
throw (std::invalid_argument);
/**
* Return the id of the fade info instance.
*
* @return the unique id of the fade info instance.
*/
Ptr<UniqueId>::Ref
getId(void) const throw ()
{
return id;
}
/**
* Return the length of the fade in period.
*
* @return the length of the fade in period, in microseconds.
*/
Ptr<time_duration>::Ref
getFadeIn(void) const throw ()
{
return fadeIn;
}
/**
* Return the length of the fade in period.
*
* @return the length of the fade in period, in microseconds.
*/
Ptr<time_duration>::Ref
getFadeOut(void) const throw ()
{
return fadeOut;
}
/**
* Return an XML representation of this fadeInfo element.
*
* This is a string containing a single <fadeInfo>
* XML element, which is empty, and has a fadeIn and a fadeOut
* argument (of format hh:mm:ss.ssssss).
*
* The encoding is UTF-8. IDs are 16-digit hexadecimal numbers,
* time durations have the format "hh:mm:ss.ssssss".
*
* @return a string representation of the audio clip as an XML element
*/
Ptr<Glib::ustring>::Ref
getXmlElementString(void) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_FadeInfo_h

View File

@ -1,157 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
To report bugs, send an e-mail to bugs@campware.org
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $
Version : $Revision$
Location : $URL: svn+ssh://fgerlits@code.campware.org/home/svn/repo/livesupport/trunk/livesupport/src/modules/core/include/LiveSupport/Core/FileTools.h $
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_FileTools_h
#define LiveSupport_Core_FileTools_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <stdexcept>
#include "LiveSupport/Core/Ptr.h"
namespace LiveSupport {
namespace Core {
using namespace LiveSupport;
using namespace LiveSupport::Core;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A collection of tools for handling files and URLs.
*
* @author $Author: fgerlits $
* @version $Revision$
*/
class FileTools
{
public:
/**
* Copy the contents of a URL to a local file.
*
* @param url the URL to read.
* @param path the local path where the file is saved.
* @exception std::runtime_error on errors.
*/
static void
copyUrlToFile(const std::string & url,
const std::string & path)
throw (std::runtime_error);
/**
* Upload the contents of a local file to a writable URL.
*
* @param path the local path where the file is.
* @param url the URL to write.
* @exception std::runtime_error on errors.
*/
static void
copyFileToUrl(const std::string & path,
const std::string & url)
throw (std::runtime_error);
/**
* Generate a temporary file name.
*
* @return a temporary file name.
*/
static const std::string
tempnam(void) throw ();
/**
* Append a file to an existing tarball.
*
* @param tarFileName the name of the existing tar file
* @param newFileRealName the name of the new file to append
* @param newFileInTarball the name of the new file in the tarball
* @exception std::runtime_error on file / tarball handling issues.
*/
static void
appendFileToTarball(const std::string & tarFileName,
const std::string & newFileRealName,
const std::string & newFileInTarball)
throw (std::runtime_error);
/**
* Check if a file exists in a given tarball.
*
* @param tarFileName the name of the existing tar file
* @param fileName the name of the file to check in the traball.
* @return true if a file named fileName exists in the tarball,
* false otherwise.
* @exception std::runtime_error on file / tarball handling issues.
*/
static bool
existsInTarball(const std::string & tarFileName,
const std::string & fileName)
throw (std::runtime_error);
/**
* Extract a file from a tarball.
*
* @param tarFileName the name of the existing tar file.
* @param fileInTarball the name of the file to be extracted
* in the tarball.
* @param fileExtracted the name of the new file to create.
* @exception std::runtime_error on file / tarball handling issues.
*/
static void
extractFileFromTarball(const std::string & tarFileName,
const std::string & fileInTarball,
const std::string & fileExtracted)
throw (std::runtime_error);
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_FileTools_h

View File

@ -1,135 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_Installable_h
#define LiveSupport_Core_Installable_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <string>
#include <stdexcept>
#include "LiveSupport/Core/Ptr.h"
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* An interface for having objects that can install themselves.
* The concept of installation means setting up for long-term use.
* When something installs, it creates databases, writes configuration
* files, etc. It sets up the object to be run. This is not to be
* confused with instance initialization, e.g. when a server is started
* or stopped.
*
* The following life cycle is expected from systems impelementing this
* interface:
*
* <ul>
* <li>install</li>
* <li><ul>
* <li>start</li>
* <li>stop</li>
* <li>start</li>
* <li>stop</li>
* </ul></li>
* <li>uninstall</li>
* </ul>
*
* Later more stages will be added, and load/save (externalization)
* facilities.
*/
class Installable
{
public:
/**
* Install the component.
* This step involves creating the environment in which the component
* will run. This may be creation of coniguration files,
* database tables, etc.
*
* @exception std::exception on installation problems.
*/
virtual void
install(void) throw (std::exception)
= 0;
/**
* Check to see if the component has already been installed.
*
* @return true if the component is properly installed,
* false otherwise
* @exception std::exception on generic problems
*/
virtual bool
isInstalled(void) throw (std::exception)
= 0;
/**
* Uninstall the component.
* Removes all the resources created in the install step.
*
* @exception std::exception on unistallation problems.
*/
virtual void
uninstall(void) throw (std::exception)
= 0;
/**
* A virtual destructor, as this class has virtual functions.
*/
virtual
~Installable(void) throw ()
{
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_Installable_h

View File

@ -1,144 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_LocalizedConfigurable_h
#define LiveSupport_Core_LocalizedConfigurable_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include "LiveSupport/Core/Configurable.h"
#include "LiveSupport/Core/LocalizedObject.h"
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A configurable element, that is also localized. Reads localization
* information from the configuration file itself.
*
* The configure() function expects the following XML element:
*
* <pre><code>
* <resourceBundle path = "path/to/Bundle"
* locale = "en"
* />
* </code></pre>
*
* <pre><code>
* <!DOCTYPE resourceBundle [
*
* <!ELEMENT resourceBundle EMPTY >
* <!ATTLIST resourceBundle path CDATA #REQUIRED >
* <!ATTLIST resourceBundle locale CDATA #REQUIRED >
*
* ]>
* </code></pre>
*/
class LocalizedConfigurable : public Configurable, public LocalizedObject
{
private:
/**
* The path to the resource bundles.
*/
std::string bundlePath;
public:
/**
* The default constructor.
*/
LocalizedConfigurable(void) throw ()
{
}
/**
* A virtual destructor.
*/
virtual
~LocalizedConfigurable(void) throw ()
{
}
/**
* Configure the object based on the XML element supplied.
* The supplied element is expected to be of the name
* returned by configElementName().
*
* @param element the XML element to configure the object from.
* @exception std::invalid_argument if the supplied XML element
* contains bad configuraiton information
* @exception std::logic_error if the object has already
* been configured, and can not be reconfigured.
* @see LocalizedObject#getBundle
*/
virtual void
configure(const xmlpp::Element & element)
throw (std::invalid_argument,
std::logic_error);
/**
* Change the current locale, which was previously specified by
* configure(), to the new locale. This results in a replacement
* of the resource bundle, read from the same path as in the
* configuration element sent to configure(), but with the new
* locale id.
*
* @param newLocale the new locale id.
* @exception std::invalid_argument if there is no bundle by
* the specified locale
*/
virtual void
changeLocale(const std::string newLocale)
throw (std::invalid_argument);
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_LocalizedConfigurable_h

View File

@ -1,491 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_LocalizedObject_h
#define LiveSupport_Core_LocalizedObject_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <stdexcept>
#include <unicode/resbund.h>
#include <unicode/fmtable.h>
#include <libxml++/libxml++.h>
#include "LiveSupport/Core/Ptr.h"
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Base class for localized objects, containing some helper functions
* to make localized life easier.
*/
class LocalizedObject
{
private:
/**
* The name of the configuration XML elmenent used by this object.
*/
static const std::string configElementNameStr;
/**
* The resource bundle holding the localized resources for this
* object.
*/
Ptr<ResourceBundle>::Ref bundle;
protected:
/**
* The default constructor.
*/
LocalizedObject(void) throw ()
{
}
public:
/**
* Constructor.
*
* @param bundle the resource bundle holding the localized
* resources for this window
*/
LocalizedObject(Ptr<ResourceBundle>::Ref bundle) throw ()
{
this->bundle = bundle;
}
/**
* Virtual destructor.
*/
virtual
~LocalizedObject(void) throw ()
{
}
/**
* Return the name of the XML element that is expected
* to be sent to a call to getBundle().
*
* @return the name of the expected XML configuration element.
* @see #getBundle(const xmlpp::Element &)
*/
static const std::string
getConfigElementName(void) throw ()
{
return configElementNameStr;
}
/**
* Load a resource bundle based on an XML configuration element.
*
* The DTD for the lement to be supplied to this function is:
* <pre><code>
* <!DOCTYPE resourceBundle [
* <!ELEMENT resourceBundle EMPTY >
* <!ATTLIST resourceBundle path CDATA #REQUIRED >
* <!ATTLIST resourceBundle locale CDATA #REQUIRED >
* ]>
* </code></pre>
*
* a sample configuration element is as follows:
*
* <pre><code>
* <resourceBundle path = "./tmp/localization"
* locale = "en"
* />
* </code></pre>
*
* for an overview of resource bundle parameters, see the ICU
* documentation on <a
* href=http://oss.software.ibm.com/icu/userguide/ResourceManagement.html>
* resource management</a>
*
* @param element the XML configuration element
* @return the resource bundle, based on this element.
* @exception std::invalid_argument if the supplied element is not
* a proper resource bundle configuration element.
* @see http://oss.software.ibm.com/icu/userguide/ResourceManagement.html
*/
static Ptr<ResourceBundle>::Ref
getBundle(const xmlpp::Element & element)
throw (std::invalid_argument);
/**
* Get the resource bundle for this object.
*
* @return the resource bundle for this object.
*/
Ptr<ResourceBundle>::Ref
getBundle(void) const throw ()
{
return bundle;
}
/**
* Change the resource bundle for this object.
*
* @param bundle the new resource bundle used by the object.
*/
virtual void
setBundle(Ptr<ResourceBundle>::Ref bundle) throw ()
{
this->bundle = bundle;
}
/**
* Get a resource bundle nested inside our bundle.
*
* @param key the name of the resource bundle to get.
* @exception std::invalid_argument if there is no bundle by
* the specified key
*/
Ptr<ResourceBundle>::Ref
getBundle(const Glib::ustring & key)
throw (std::invalid_argument)
{
return getBundle(getBundle(), key.c_str());
}
/**
* Get a resource bundle nested inside our bundle.
*
* @param key the name of the resource bundle to get.
* @exception std::invalid_argument if there is no bundle by
* the specified key
*/
Ptr<ResourceBundle>::Ref
getBundle(const char * key) throw (std::invalid_argument)
{
return getBundle(getBundle(), key);
}
/**
* Get a resource bundle nested inside our bundle.
*
* @param bundle the resource bundle containing the key.
* @param key the name of the nested resource bundle to get.
* @exception std::invalid_argument if there is no bundle by
* the specified key
*/
Ptr<ResourceBundle>::Ref
getBundle(Ptr<ResourceBundle>::Ref bundle,
const char * key)
throw (std::invalid_argument);
/**
* Get a string from the resource bundle.
*
* @param key the key identifying the requested string.
* @return the requested string
* @exception std::invalid_argument if there is no string for the
* specified key.
*/
virtual Ptr<UnicodeString>::Ref
getResourceString(const char * key)
throw (std::invalid_argument)
{
return getResourceString(getBundle(), key);
}
/**
* Get a string from the resource bundle.
*
* @param bundle the nested resource bundle containing the key.
* @param key the key identifying the requested string.
* @return the requested string
* @exception std::invalid_argument if there is no string for the
* specified key.
*/
virtual Ptr<UnicodeString>::Ref
getResourceString(const char * bundle,
const char * key)
throw (std::invalid_argument)
{
return getResourceString(getBundle(bundle), key);
}
/**
* Get a string from the resource bundle.
*
* @param bundle the nested resource bundle containing the key.
* @param key the key identifying the requested string.
* @return the requested string
* @exception std::invalid_argument if there is no string for the
* specified key.
*/
virtual Ptr<UnicodeString>::Ref
getResourceString(Ptr<ResourceBundle>::Ref bundle,
const char * key)
throw (std::invalid_argument);
/**
* A convenience function to format a message.
* For more information, see the ICU MessageFormat class
* documentation.
*
* @param pattern the pattern to format
* @param arguments the arguments to use in the formatting
* @param nArguments the number of arguments supplied
* @return the formatted string
* @exception std::invalid_argument if the pattern is bad, or
* the arguments do not match
* @see http://oss.software.ibm.com/icu/apiref/classMessageFormat.html
*/
static Ptr<UnicodeString>::Ref
formatMessage(Ptr<const UnicodeString>::Ref pattern,
Formattable * arguments,
unsigned int nArguments)
throw (std::invalid_argument);
/**
* A convenience function to format a message, based on a pattern
* loaded from a resource.
* For more information, see the ICU MessageFormat class
* documentation.
*
* @param patternKey the key of the pattern to format
* @param arguments the arguments to use in the formatting
* @param nArguments the number of arguments supplied
* @return the formatted string
* @exception std::invalid_argument if the pattern is bad, or
* the arguments do not match, or there is no resource
* specified by patternKey
* @see http://oss.software.ibm.com/icu/apiref/classMessageFormat.html
*/
virtual Ptr<Glib::ustring>::Ref
formatMessage(const char * patternKey,
Formattable * arguments,
unsigned int nArguments)
throw (std::invalid_argument);
/**
* A convenience function to format a message, based on a pattern
* loaded from a resource.
* For more information, see the ICU MessageFormat class
* documentation.
*
* @param patternKey the key of the pattern to format
* @param arguments the arguments to use in the formatting
* @param nArguments the number of arguments supplied
* @return the formatted string
* @exception std::invalid_argument if the pattern is bad, or
* the arguments do not match, or there is no resource
* specified by patternKey
* @see http://oss.software.ibm.com/icu/apiref/classMessageFormat.html
*/
virtual Ptr<Glib::ustring>::Ref
formatMessage(const std::string & patternKey,
Formattable * arguments,
unsigned int nArguments)
throw (std::invalid_argument)
{
return formatMessage(patternKey.c_str(), arguments, nArguments);
}
/**
* A convenience function to format a message, based on a pattern
* loaded from a resource, with one argument.
* For more information, see the ICU MessageFormat class
* documentation.
*
* @param patternKey the key of the pattern to format
* @param argument1 the single argument to the message.
* @return the formatted string
* @exception std::invalid_argument if the pattern is bad, or
* the arguments do not match, or there is no resource
* specified by patternKey
* @see http://oss.software.ibm.com/icu/apiref/classMessageFormat.html
*/
virtual Ptr<Glib::ustring>::Ref
formatMessage(const std::string & patternKey,
const Glib::ustring & argument1)
throw (std::invalid_argument);
/**
* A convenience function to format a message, based on a pattern
* loaded from a resource, with two arguments.
* For more information, see the ICU MessageFormat class
* documentation.
*
* @param patternKey the key of the pattern to format
* @param argument1 the first argument to the message.
* @param argument2 the second argument to the message.
* @return the formatted string
* @exception std::invalid_argument if the pattern is bad, or
* the arguments do not match, or there is no resource
* specified by patternKey
* @see http://oss.software.ibm.com/icu/apiref/classMessageFormat.html
*/
virtual Ptr<Glib::ustring>::Ref
formatMessage(const std::string & patternKey,
const Glib::ustring & argument1,
const Glib::ustring & argument2)
throw (std::invalid_argument);
/**
* A convenience function to format a message, based on a pattern
* loaded from a resource, with three arguments.
* For more information, see the ICU MessageFormat class
* documentation.
*
* @param patternKey the key of the pattern to format
* @param argument1 the first argument to the message.
* @param argument2 the second argument to the message.
* @param argument3 the second argument to the message.
* @return the formatted string
* @exception std::invalid_argument if the pattern is bad, or
* the arguments do not match, or there is no resource
* specified by patternKey
* @see http://oss.software.ibm.com/icu/apiref/classMessageFormat.html
*/
virtual Ptr<Glib::ustring>::Ref
formatMessage(const std::string & patternKey,
const Glib::ustring & argument1,
const Glib::ustring & argument2,
const Glib::ustring & argument3)
throw (std::invalid_argument);
/**
* Convert an ICU unicode string to a Glib ustring.
*
* @param unicodeString the ICU unicode string to convert.
* @return the same string as supplied, in Glib ustring form.
*/
static Ptr<Glib::ustring>::Ref
unicodeStringToUstring(Ptr<const UnicodeString>::Ref unicodeString)
throw ();
/**
* Convert a Glib ustring to an ICU unicode string.
*
* @param gString the Glib ustring to convert
* @return the same string as supplied, in ICU unicode form.
*/
static Ptr<UnicodeString>::Ref
ustringToUnicodeString(Ptr<const Glib::ustring>::Ref gString)
throw ();
/**
* Convert a Glib ustring to an ICU unicode string.
*
* @param gString the Glib ustring to convert
* @return the same string as supplied, in ICU unicode form.
*/
static Ptr<UnicodeString>::Ref
ustringToUnicodeString(const Glib::ustring & gString)
throw ();
/**
* Get a string from the resource bundle, as a Glib ustring.
*
* @param key the key identifying the requested string.
* @return the requested string
* @exception std::invalid_argument if there is no string for the
* specified key.
*/
Ptr<Glib::ustring>::Ref
getResourceUstring(const char * key)
throw (std::invalid_argument)
{
return unicodeStringToUstring(getResourceString(key));
}
/**
* Get a string from the resource bundle, as a Glib ustring.
*
* @param key the key identifying the requested string.
* @return the requested string
* @exception std::invalid_argument if there is no string for the
* specified key.
*/
Ptr<Glib::ustring>::Ref
getResourceUstring(const std::string &key)
throw (std::invalid_argument)
{
return unicodeStringToUstring(getResourceString(key.c_str()));
}
/**
* Get a string from a resource bundle nested inside this bundle,
* as a Glib ustring.
*
* @param bundle the name of the resource bundle to get.
* @param key the key identifying the requested string.
* @return the requested string
* @exception std::invalid_argument if there is no string for the
* specified key.
*/
Ptr<Glib::ustring>::Ref
getResourceUstring(const char * bundle,
const char * key)
throw (std::invalid_argument)
{
return unicodeStringToUstring(getResourceString(bundle, key) );
}
/**
* Get some binary data as a string.
* Reads the binary data either from a <code>binary</code> or from
* an <code>import</code> key, and returns it as a Glib::ustring.
* The binary data is assumed to be in UTF-8 encoding.
*
* @param key the key identifying the requested binary data.
* @return the requested binary data as a string.
* @exception std::invalid_argument if there is no such key, or the
* value is not of binary type, or it isn't valid UTF-8.
*/
Ptr<Glib::ustring>::Ref
getBinaryResourceAsUstring(const char * key)
throw (std::invalid_argument);
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_LocalizedObject_h

View File

@ -1,255 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------
This class is based on the following with minor modifications
(see http://userpages.umbc.edu/~mabzug1/cs/md5/md5.html).
------------------------------------------------------------------------------
// Md5.CC - source code for the C++/object oriented translation and
// modification of Md5.
// Translation and modification (c) 1995 by Mordechai T. Abzug
// This translation/ modification is provided "as is," without express or
// implied warranty of any kind.
// The translator/ modifier does not claim (1) that Md5 will do what you think
// it does; (2) that this translation/ modification is accurate; or (3) that
// this software is "merchantible." (Language for this disclaimer partially
// copied from the disclaimer below).
------------------------------------------------------------------------------
Which was based on:
------------------------------------------------------------------------------
Md5.H - header file for Md5C.C
MDDRIVER.C - test driver for MD2, MD4 and Md5
Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
rights reserved.
License to copy and use this software is granted provided that it
is identified as the "RSA Data Security, Inc. Md5 Message-Digest
Algorithm" in all material mentioning or referencing this software
or this function.
License is also granted to make and use derivative works provided
that such works are identified as "derived from the RSA Data
Security, Inc. Md5 Message-Digest Algorithm" in all material
mentioning or referencing the derived work.
RSA Data Security, Inc. makes no representations concerning either
the merchantability of this software or the suitability of this
software for any particular purpose. It is provided "as is"
without express or implied warranty of any kind.
These notices must be retained in any copies of any part of this
documentation and/or software.
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_Md5_h
#define LiveSupport_Core_Md5_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_STDINT_H
#include <stdint.h>
#else
#error need stdint.h
#endif
#include <stdio.h>
#include <sstream>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <stdexcept>
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A class for generating md5 sums.
*
* First, one creates an Md5 object from a file, istream or string; then
* one can either call hexDigest() or simply convert the object to std::string
* in order to obtain the md5 sum in the form of 32 hexadecimal (lower case)
* digits.
*
* This is a trimmed version of the C++ class written by Mordechai T. Abzug
* on the basis of the original C code by RSA Data Security, Inc. See the
* header of the source file for further information.
*/
class Md5
{
private:
// first, some types:
typedef unsigned int uint4; // assumes integer is 4 words long
typedef unsigned short int uint2; // assumes short integer is 2 words long
typedef unsigned char uint1; // assumes char is 1 word long
// methods for controlled operation:
void update (uint1 *input, uint4 input_length);
void update (std::istream& stream);
void update (FILE *file);
void update (const std::string& s);
void finalize () throw(std::invalid_argument);
// next, the private data:
uint4 state[4];
uint4 count[2]; // number of *bits*, mod 2^64
uint1 buffer[64]; // input buffer
uint1 digest[16];
uint1 finalized;
/**
* The low 64 bits of the checksum.
*/
uint64_t low64;
/**
* The high 64 bits of the checksum.
*/
uint64_t high64;
// last, the private methods, mostly static:
void init (); // called by all constructors
void transform (uint1 *buffer); // does the real update work. Note
// that length is implied to be 64.
static void encode (uint1 *dest, uint4 *src, uint4 length);
static void decode (uint4 *dest, uint1 *src, uint4 length);
static void memcpy (uint1 *dest, uint1 *src, uint4 length);
static void memset (uint1 *start, uint1 val, uint4 length);
static inline uint4 rotate_left (uint4 x, uint4 n);
static inline uint4 F (uint4 x, uint4 y, uint4 z);
static inline uint4 G (uint4 x, uint4 y, uint4 z);
static inline uint4 H (uint4 x, uint4 y, uint4 z);
static inline uint4 I (uint4 x, uint4 y, uint4 z);
static inline void FF (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x,
uint4 s, uint4 ac);
static inline void GG (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x,
uint4 s, uint4 ac);
static inline void HH (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x,
uint4 s, uint4 ac);
static inline void II (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x,
uint4 s, uint4 ac);
/**
* Calculate the lower and higher 64 bit values for the checksum
*/
void
calcNumericRepresentation(void) throw ();
public:
/**
* Construct from a std::string
*/
Md5 (const std::string &s) throw(std::invalid_argument);
/**
* Construct from an istream
*/
Md5 (std::istream& stream) throw(std::invalid_argument);
/**
* Construct from a file
*/
Md5 (FILE *file) throw(std::invalid_argument);
/**
* Get the md5 sum as a 32 digit ascii-hex string
*/
std::string hexDigest () throw();
/**
* Get the md5 sum as a 32 digit ascii-hex string
*/
operator std::string () throw();
/**
* Return the lower 64 bits of the checksum.
*
* @return the lower 64 bits of the checksum.
*/
uint64_t
low64bits(void) const throw ()
{
return low64;
}
/**
* Return the higher 64 bits of the checksum.
*
* @return the higher 64 bits of the checksum.
*/
uint64_t
high64bits(void) const throw ()
{
return high64;
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_Md5_h

View File

@ -1,173 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_MetadataConstraint_h
#define LiveSupport_Core_MetadataConstraint_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/Configurable.h"
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A class for representing a constraint on the values of a metadata type.
*
* This is an abstract-cum-factory class for constructing the concrete
* constraint subclasses. You construct and configure this class, which
* will transparently construct the concrete subclass desired, and delegate
* the actual value checking to it.
*
* This object has to be configured with an XML configuration element
* called constraint. This may look like the following:
*
* <pre><code>
* <constraint type = "numericRange">
* <value>1</value>
* <value>12</value>
* </constraint>
* </code></pre>
*
* The type attribute identifies this MetadataConstraint object as belonging
* to the subclass NumericRangeConstraint. Other subclasses are
* NumericConstraint, EnumerationConstraint etc.
*
* Each MetadataType object may contain an optional MetadataConstraint member
* object, which restricts the acceptable values for this metadata type.
*
* The DTD for the expected XML element looks like the following:
*
* <pre><code>
* <!ELEMENT constraint (value*) >
* <!ATTLIST constraint type NMTOKEN #REQUIRED >
* <!ELEMENT value (CDATA) >
* </code></pre>
*
* @see MetadataConstraintContainer
*/
class MetadataConstraint : public Configurable
{
private:
/**
* The name of the configuration XML element used by MetadataConstraint.
*/
static const std::string configElementNameStr;
/**
* A reference to a concrete subclass.
*/
Ptr<MetadataConstraint>::Ref concreteConstraint;
protected:
/**
* The name of the type attribute.
*/
static const std::string typeAttributeName;
/**
* The name of the configuration element for the constraint values.
*/
static const std::string valueElementName;
public:
/**
* Constructor.
*/
MetadataConstraint() throw ()
{
}
/**
* A virtual destructor, as this class has virtual functions.
*/
virtual
~MetadataConstraint(void) throw ()
{
}
/**
* Return the name of the XML element this object expects
* to be sent to a call to configure().
*
* @return the name of the expected XML configuration element.
*/
static const std::string
getConfigElementName(void) throw ()
{
return configElementNameStr;
}
/**
* Configure the metadata object based on an XML configuration element.
*
* @param element the XML configuration element.
* @exception std::invalid_argument of the supplied XML element
* contains bad configuration information
*/
virtual void
configure(const xmlpp::Element & element)
throw (std::invalid_argument);
/**
* Check that the given value satisfies the constraint.
*
* @param value the value to be checked against the constraint.
* @return true if the value satisfies the constraint.
* @exception std::logic_error if the object has not been
* configured yet.
*/
virtual bool
check(Ptr<const Glib::ustring>::Ref value) const
throw (std::logic_error);
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_MetadataConstraint_h

View File

@ -1,291 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_MetadataType_h
#define LiveSupport_Core_MetadataType_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <map>
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/Configurable.h"
#include "LiveSupport/Core/MetadataConstraint.h"
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
class MetadataTypeContainer;
/**
* A class for representing a metadata type.
*
* This object has to be configured with an XML configuration element
* called metadataType. This may look like the following:
*
* <pre><code>
* &lt;metadataType dcName = "dc:creator"
* id3Tag = "TPE2"
* localizationKey = "dc_creator"
* tab = "main" &gt;
* &lt;constraint type = "numericRange" &gt;
* &lt;value&gt;1&lt;/value&gt;
* &lt;value&gt;12&lt;/value&gt;
* &lt;/constraint&gt;
* &lt;/metadataType&gt;
* </code></pre>
*
* The tab attribute (if present) must be one of "main", "music" or "voice"
* (all lowercase, case sensitive).
* This determines whether, at file upload, the metadata field appears in
* the Main, Music, or Voice tab. If the attribute is omitted, the metadata
* field will appear in none of the tabs.
*
* The optional constraint sub-element can give restrictions on the acceptable
* values for this type of metadata. See the MetadataConstraint class for
* more information, including the DTD of the &lt;constraint&gt; element.
*
* See the Studio config files for a list of all metadata types.
*
* The DTD for the expected XML element looks like the following:
*
* <pre><code>
* <!ELEMENT metadataType (constraint?) >
* <!ATTLIST metadataType dcName NMTOKEN #REQUIRED >
* <!ATTLIST metadataType id3Tag NMTOKEN #IMPLIED >
* <!ATTLIST metadataType localizationKey NMTOKEN #REQUIRED >
* <!ATTLIST metadataType tab NMTOKEN #IMPLIED >
* </code></pre>
*
* @see MetadataTypeContainer
*/
class MetadataType : public Configurable
{
friend class MetadataTypeContainer;
public:
/**
* An enumeration of all possible metadata categories.
*/
typedef enum { noTab,
mainTab,
musicTab,
voiceTab } TabType;
private:
/**
* The name of the configuration XML element used by MetadataType.
*/
static const std::string configElementNameStr;
/**
* A reference to a metadata type container.
*/
Ptr<MetadataTypeContainer>::Ref container;
/**
* The Dublic Core name of this metadata type.
*/
Ptr<Glib::ustring>::Ref dcName;
/**
* The ID3v2 tag for this metadata type.
*/
Ptr<Glib::ustring>::Ref id3Tag;
/**
* The localization key for this metadata type.
*/
Ptr<Glib::ustring>::Ref localizationKey;
/**
* The localization key for this metadata type.
*/
TabType tab;
/**
* The constraint object, if any.
*/
Ptr<MetadataConstraint>::Ref constraint;
protected:
/**
* Default constructor.
*
* @param container the container this metadata type is held in.
*/
MetadataType(Ptr<MetadataTypeContainer>::Ref container)
throw ();
/**
* Constructor.
*
* @param container the container this metadata type is held in.
* @param dcName the Dublic Core metadata name.
* @param id3Tag the ID3v2 tag assciated with the metadata.
* @param localizationKey the key to get the localized name for
* the metadata
* @param tab in which tab to show this kind of metadata in the
* Upload File window (default: none of them).
*/
MetadataType(Ptr<MetadataTypeContainer>::Ref container,
Glib::ustring dcName,
Glib::ustring id3Tag,
Glib::ustring localizationKey,
TabType tab = noTab)
throw ();
/**
* Return the name of the XML element this object expects
* to be sent to a call to configure().
*
* @return the name of the expected XML configuration element.
*/
static const std::string
getConfigElementName(void) throw ()
{
return configElementNameStr;
}
/**
* Configure the metadata object based on an XML configuration element.
*
* @param element the XML configuration element.
* @exception std::invalid_argument of the supplied XML element
* contains bad configuration information
*/
virtual void
configure(const xmlpp::Element &element)
throw (std::invalid_argument);
public:
/**
* A virtual destructor, as this class has virtual functions.
*/
virtual
~MetadataType(void) throw ()
{
}
/**
* Return the Dublic Core name of the metadata type.
*
* @return the Dublic Core name of the metadata type.
*/
Ptr<const Glib::ustring>::Ref
getDcName(void) const throw ()
{
return dcName;
}
/**
* Return the ID3v2 tag name for the metadata type.
*
* @return the ID3v2 tag name for the metadata type, or a null
* pointer, if no ID3v2 tag exists for the metadata type.
*/
Ptr<const Glib::ustring>::Ref
getId3Tag(void) const throw ()
{
return id3Tag;
}
/**
* Return the localization key for the metadata type.
*
* @return the localization key for the metadata type.
*/
Ptr<const Glib::ustring>::Ref
getLocalizationKey(void) const throw ()
{
return localizationKey;
}
/**
* Return the localized name for the metadata type.
*
* @return the localized name for the metadata type.
* @exception std::invalid_argument if there is no localized
* name for this metadata type.
*/
Ptr<const Glib::ustring>::Ref
getLocalizedName(void) const throw (std::invalid_argument);
/**
* Return the tab that this metadata type should appear in,
* when an audio clip is uploaded in the Studio client.
*
* @return the name of the tab for the metadata type.
*/
TabType
getTab(void) const throw ()
{
return tab;
}
/**
* Check that the given value satisfies the constraint.
* If the metadata type has no constraints, it returns true.
* If the constraint throws an exception, it returns false.
*
* @param value the value to be checked against the constraint.
* @return true if the value satisfies the constraint.
*/
bool
check(Ptr<const Glib::ustring>::Ref value) const throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_MetadataType_h

View File

@ -1,279 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_MetadataTypeContainer_h
#define LiveSupport_Core_MetadataTypeContainer_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <map>
#include <boost/enable_shared_from_this.hpp>
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/Configurable.h"
#include "LiveSupport/Core/LocalizedObject.h"
#include "LiveSupport/Core/MetadataType.h"
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Container holding MetadataType objects.
*
* This object has to be configured with an XML configuration element
* called metadataTypeContainer. This may look like the following:
*
* <pre><code>
* &lt;metadataTypeContainer&gt;
* &lt;metadataType ... /&gt;
* &lt;metadataType ... /&gt;
* ...
* &lt;metadataType ... /&gt;
* &lt;/metadataTypeContainer&gt;
* </code></pre>
*
* The DTD for the expected XML element is the following:
*
* <pre><code>
* <!ELEMENT metadataTypeContainer (metadataType+) >
* </code></pre>
*
* For a description of the metadataType XML element, see the documentation
* for the MetadataType class.
*
* See the Studio config files for a list of all metadata types.
*
* @see MetadataType
*/
class MetadataTypeContainer : public Configurable,
public LocalizedObject,
public boost::enable_shared_from_this<MetadataTypeContainer>
{
public:
/**
* A vector type holding contant MetadataType references.
*/
typedef std::vector<Ptr<const MetadataType>::Ref> Vector;
private:
/**
* Map type for storing MetadataType objects by Glib::ustrings.
*/
typedef std::map<Glib::ustring, Ptr<const MetadataType>::Ref> NameMap;
/**
* The name of the configuration XML element used by
* MetadataTypeContainer.
*/
static const std::string configElementNameStr;
/**
* A vector holding all MetadataType references.
*/
Vector vector;
/**
* Map of MetadaType objects, stored by DC name.
*/
NameMap dcNameMap;
/**
* Map of MetadaType objects, stored by ID3v2 tags.
*/
NameMap id3TagMap;
public:
/**
* Constructor.
*
* @param bundle the resource bundle holding the localized resources.
*/
MetadataTypeContainer(Ptr<ResourceBundle>::Ref bundle)
throw ()
: LocalizedObject(bundle)
{
}
/**
* A virtual destructor, as this class has virtual functions.
*/
virtual
~MetadataTypeContainer(void) throw ()
{
}
/**
* Return the name of the XML element this object expects
* to be sent to a call to configure().
*
* @return the name of the expected XML configuration element.
*/
static const std::string
getConfigElementName(void) throw ()
{
return configElementNameStr;
}
/**
* Configure the metadata object based on an XML configuration element.
*
* @param element the XML configuration element.
* @exception std::invalid_argument of the supplied XML element
* contains bad configuration information
*/
virtual void
configure(const xmlpp::Element &element)
throw (std::invalid_argument);
/**
* Return an interator holding all MetadataType objects.
* The iterator holds objects of type Ptr<const MetadataType>::Ref.
*
* @return an iterator holding the available metadata types.
*/
Vector::const_iterator
begin(void) const throw ()
{
return vector.begin();
}
/**
* Return an interator pointing to the end of MetadataType objects.
* The iterator holds objects of type Ptr<const MetadataType>::Ref.
*
* @return an iterator pointing to the end of metadata types.
*/
Vector::const_iterator
end(void) const throw ()
{
return vector.end();
}
/**
* Tells if a MetadataType object exists with the specified
* Dublic Core name.
*
* @param dcName the DC name of the metadata type.
* @return true if a metadata type exists with the specified name,
* false otherwise
*/
bool
existsByDcName(const Glib::ustring dcName) const throw ();
/**
* Return a MetadataType object, by Dublic Core name.
*
* @param dcName the DC name of the metadata type.
* @return a MetadataType object with the supplied DC name
* @exception std::invalid_argument if no metadata type exists
* with the suplied name.
*/
Ptr<const MetadataType>::Ref
getByDcName(const Glib::ustring dcName)
throw (std::invalid_argument);
/**
* Tells if a MetadataType object exists with the specified
* ID3v2 tag.
*
* @param id3Tag the ID3v2 tag of the metadata type.
* @return true if a metadata type exists with the specified tag name,
* false otherwise
*/
bool
existsById3Tag(const Glib::ustring id3Tag) const throw ();
/**
* Return a MetadataType object, by ID3v2 tag.
*
* @param id3Tag the ID3v2 tag of the metadata type.
* @return a MetadataType object with the supplied ID3v2 tag name.
* @exception std::invalid_argument if no metadata type exists
* with the suplied tag name.
*/
Ptr<const MetadataType>::Ref
getById3Tag(const Glib::ustring id3Tag)
throw (std::invalid_argument);
/**
* Return a MetadataType object, by index.
*
* @param index the index of the item in the metadata container.
* @return the MetadataType object at the supplied index.
* @exception std::invalid_argument if the index is out of range.
*/
Ptr<const MetadataType>::Ref
getByIndex(unsigned int index) const
throw (std::invalid_argument);
/**
* Check that the given value satisfies the constraint of a metadata
* type.
* If the metadata type has no constraints, it returns true.
* If the constraint throws an exception, it returns false.
*
* @param value the value to be checked against the constraint.
* @param dcName the metadata type, by its Dublin Core name.
* @return true if the value satisfies the constraint.
* @exception std::invalid_argument if no metadata type exists
* with the suplied name.
*/
bool
check(Ptr<const Glib::ustring>::Ref value,
const Glib::ustring & dcName)
throw (std::invalid_argument);
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_MetadataTypeContainer_h

View File

@ -1,142 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_Mutex_h
#define LiveSupport_Core_Mutex_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <pthread.h>
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A simple wrapper for pthread_mutex_t.
*/
class Mutex
{
private:
/**
* The mutex object.
*/
pthread_mutex_t * mutex;
public:
/**
* Default constructor.
*/
Mutex(void) throw ()
{
mutex = new pthread_mutex_t;
pthread_mutex_init(mutex, NULL);
}
/**
* A virtual destructor, as this class has virtual functions.
*/
virtual
~Mutex(void) throw ()
{
pthread_mutex_destroy(mutex);
}
/**
* Lock the mutex.
* If the mutex is already locked, it blocks until it becomes free.
*/
void
lock(void) throw ()
{
pthread_mutex_lock(mutex);
}
/**
* Unlock a mutex.
*/
void
unlock(void) throw ()
{
pthread_mutex_unlock(mutex);
}
/**
* Try to lock a mutex.
* If the mutex is already locked, it returns false.
*
* @return true if the mutex was successfully locked; false otherwise.
*/
bool
tryLock(void) throw ()
{
return (pthread_mutex_trylock(mutex) == 0);
}
/**
* Try to lock a mutex.
* If the mutex is already locked, it returns false.
*
*` @param errorCode return parameter for the error code;
* 0 for no error.
* @return true if the mutex was successfully locked; false otherwise.
*/
bool
tryLock(int & errorCode) throw ()
{
errorCode = pthread_mutex_trylock(mutex);
return (errorCode == 0);
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_Mutex_h

View File

@ -1,100 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_NumericTools_h
#define LiveSupport_Core_NumericTools_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <sstream>
#include <glibmm/ustring.h>
namespace LiveSupport {
namespace Core {
using namespace LiveSupport;
using namespace LiveSupport::Core;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A toolbox for various small numeric functions.
*/
class NumericTools
{
public:
/**
* Convert an integer to a string.
*
* @param number the number to be converted.
* @return the string value of the number (in base 10).
*/
static Glib::ustring
itoa(int number) throw ();
/**
* Add a number to the end of a string.
* This is used in various GUI classes, to generate Glade widget
* names like "itemLabel1", "itemLabel2" etc.
*
* NOTE: the <code>index</code> parameter is 0-based (because this
* is normal in C++, for containers etc), but the return value is
* 1-based (because this is what Glade expects)!
* Thus <code>addIndex("itemLabel", 0)</code> returns "itemLabel1".
*
* @param baseString the string without the index.
* @param index the index to be added to the string (0-based).
* @return the new string, with the index added at the end (1-based).
*/
static Glib::ustring
addIndex(const Glib::ustring & baseString,
int index) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_NumericTools_h

View File

@ -1,329 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
To report bugs, send an e-mail to bugs@campware.org
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author $
Version : $Revision $
Location : $URL $
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_OptionsContainer_h
#define LiveSupport_Core_OptionsContainer_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <stdexcept>
#include <glibmm/ustring.h>
#include <libxml++/libxml++.h>
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/RdsContainer.h"
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A container for the options in gLiveSupport.xml.
*
* It supports a number of named string options (see OptionItemString),
* plus two special kinds of options: keyboard shortcuts, and RDS strings.
*
* @author $Author $
* @version $Revision $
*/
class OptionsContainer
{
public:
/**
* The list of string options one can set.
*
* These are options of type Glib::ustring; any string is accepted
* as value, no range checking is done.
*/
typedef enum { outputPlayerDeviceName,
cuePlayerDeviceName,
authenticationServer,
authenticationPort,
authenticationPath,
storageServer,
storagePort,
storagePath,
schedulerServer,
schedulerPort,
schedulerPath,
serialDeviceName } OptionItemString;
private:
/**
* The XML document containing the options.
*/
xmlpp::Document optionsDocument;
/**
* The file name (including path) used by writeToFile().
*/
Ptr<const Glib::ustring>::Ref configFileName;
/**
* Remember if we have been touched.
*/
bool touched;
/**
* Container for the RDS settings.
*/
Ptr<RdsContainer>::Ref rdsContainer;
/**
* Default constructor.
*/
OptionsContainer(void) throw ()
{
}
/**
* Find the node corresponding to an OptionItemString value.
*
* If there is no matching node, it returns a 0 pointer.
*
* @param optionItem the name of the item to find the node for
* @param isAttribute return parameter; is set to true if the
* node is an attribute, false if it's
* a CDATA text
* @return a pointer to the node found, or 0
* @exception std::invalid_argument thrown by getNode() [should
* never happen]
*/
xmlpp::Node *
selectNode(OptionItemString optionItem,
bool & isAttribute)
throw (std::invalid_argument);
/**
* Find the node corresponding to a keyboard shortcut.
*
* If there is no matching node, it returns a 0 pointer.
*
* @param containerNo the number of the KeyboardShortcutContainer
* (starting with 1, as per XPath)
* @param shortcutNo the number of the KeyboardShortcut within
* this container (also starting with 1)
* @return a pointer to the node found, or 0
* @exception std::invalid_argument thrown by getNode() [should
* never happen]
*/
xmlpp::Node *
selectKeyboardShortcutNode(int containerNo,
int shortcutNo)
throw (std::invalid_argument);
/**
* Return the first node matching an XPath string.
*
* If there is no matching node, it returns a 0 pointer.
*
* @param xPath the XPath of the node (from the root node)
* @return a pointer to the node found, or 0
* @exception std::invalid_argument if the XPath is not well formed
*/
xmlpp::Node *
getNode(const Glib::ustring & xPath)
throw (std::invalid_argument);
/**
* Create a node corresponding to an option item.
*
* So far, this is only implemented for serialDeviceName;
* for all other option items, it returns a 0 pointer.
* The XML element or attribute is created with a value of "".
*
* TODO: implement this properly; ideally, the paths would be read
* from the DTD of the default config file, and added to the current
* config file as needed.
*
* @param optionItem the option item to be created.
* @return a pointer to the node created, or 0.
*/
xmlpp::Node *
createNode(OptionItemString optionItem) throw ();
public:
/**
* Constructor with XML element parameter.
*
* @param optionsElement the XML element containing the options
* @param configFileName the name (with path) of the configuration
* file used by writeToFile()
* @see writeToFile()
*/
OptionsContainer(const xmlpp::Element & optionsElement,
Ptr<const Glib::ustring>::Ref configFileName)
throw ();
/**
* Report if the object has been touched.
*
* It returns true if there has been any calls to setOptionItem()
* since its construction or the last call to writeToFile().
*
* @return whether the options have been touched
*/
bool
isTouched(void) throw ()
{
return touched || (rdsContainer && rdsContainer->isTouched());
}
/**
* Set a string type option.
*
* @param optionItem which option to set
* @param value the new value of the option
* @exception std::invalid_argument if the option name is not found
*/
void
setOptionItem(OptionItemString optionItem,
Ptr<const Glib::ustring>::Ref value)
throw (std::invalid_argument);
/**
* Get a string type option.
*
* @return the value of the option
* @exception std::invalid_argument if the option name is not found
*/
Ptr<Glib::ustring>::Ref
getOptionItem(OptionItemString optionItem)
throw (std::invalid_argument);
/**
* Set a keyboard shortcut type option.
*
* @param containerNo which container to modify
* @param shortcutNo which shortcut to modify within this
* container
* @param value the name of the new shortcut key
* @exception std::invalid_argument if the shortcut is not found
*/
void
setKeyboardShortcutItem(int containerNo,
int shortcutNo,
Ptr<const Glib::ustring>::Ref value)
throw (std::invalid_argument);
/**
* Set the value of the RDS options.
* The key can be any of the RDS data codes, like PS, PI, PTY, RT,
* etc. If there is already a value set for this code, it gets
* overwritten, otherwise a new key-value pair is added.
*
* @param key which setting to modify
* @param value the new value of the RDS setting
* @param enabled the new enabled/disabled state of the
* RDS setting
*/
void
setRdsOptions(Ptr<const Glib::ustring>::Ref key,
Ptr<const Glib::ustring>::Ref value,
bool enabled) throw ();
/**
* Get the value of an RDS string.
* The key can be any of the RDS data codes, like PS, PI, PTY, RT,
* etc.
*
* @param key which setting to modify
* @return the value of the RDS setting
* @exception std::invalid_argument if there is no such RDS option.
*/
Ptr<const Glib::ustring>::Ref
getRdsValue(Ptr<const Glib::ustring>::Ref key)
throw (std::invalid_argument);
/**
* Get the enabled/disabled state of an RDS option.
*
* @param key which setting to modify
* @return true if the RDS option is enabled, false otherwise.
* @exception std::invalid_argument if there is no such RDS option.
*/
bool
getRdsEnabled(Ptr<const Glib::ustring>::Ref key)
throw (std::invalid_argument);
/**
* Get a string containing all the RDS values.
* This string can be sent to the RDS encoder.
*
* @return a string which can be sent to the RDS encoder;
* a 0 pointer if no RDS options have been defined.
*/
Ptr<Glib::ustring>::Ref
getCompleteRdsString(void) throw ()
{
return rdsContainer ? rdsContainer->toString()
: Ptr<Glib::ustring>::Ref();
}
/**
* Save the options to a file.
*
* This writes the options in XML format to the file specified in the
* constructor. The directory must already exist (it's OK if the file
* does not), otherwise nothing is written.
*/
void
writeToFile(void) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_OptionsContainer_h

View File

@ -1,161 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_PlayLogEntry_h
#define LiveSupport_Core_PlayLogEntry_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <stdexcept>
#include <string>
#include <libxml++/libxml++.h>
#include <boost/date_time/posix_time/posix_time.hpp>
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/UniqueId.h"
namespace LiveSupport {
namespace Core {
using namespace boost::posix_time;
using namespace LiveSupport::Core;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A class representing a play log entry.
* PlayLogEntries contain information about the audio clips played.
*/
class PlayLogEntry
{
private:
/**
* The unique id of the play log entry.
*/
Ptr<UniqueId>::Ref id;
/**
* The id of the audio clip referenced by this play log entry.
*/
Ptr<UniqueId>::Ref audioClipId;
/**
* The time this audio clip was played.
*/
Ptr<ptime>::Ref timestamp;
public:
/**
* Default constructor.
*/
PlayLogEntry(void) throw ()
{
}
/**
* Create a play log entry by specifying all details.
*
* @param id the ID of the play log entry.
* @param audioClipId the ID of the audio clip logged
* @param timestamp the time this audio clip was played.
*/
PlayLogEntry(Ptr<UniqueId>::Ref id,
Ptr<UniqueId>::Ref audioClipId,
Ptr<ptime>::Ref timestamp) throw()
{
this->id = id;
this->audioClipId = audioClipId;
this->timestamp = timestamp;
}
/**
* A virtual destructor, as this class has virtual functions.
*/
virtual
~PlayLogEntry(void) throw ()
{
}
/**
* Return the ID of the play log entry.
*
* @return the unique ID of the play log entry.
*/
Ptr<const UniqueId>::Ref
getId(void) const throw ()
{
return id;
}
/**
* Return the ID of the audio clip referenced by this entry.
*
* @return the unique ID of the audio clip.
*/
Ptr<const UniqueId>::Ref
getAudioClipId(void) const throw ()
{
return audioClipId;
}
/**
* Return the time this audio clip was played.
*
* @return the the time the audio clip was played.
*/
Ptr<const ptime>::Ref
getTimestamp(void) const throw ()
{
return timestamp;
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_PlayLogEntry_h

View File

@ -1,307 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_Playable_h
#define LiveSupport_Core_Playable_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <stdexcept>
#include <string>
#include <libxml++/libxml++.h>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <glibmm/ustring.h>
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/UniqueId.h"
#include "LiveSupport/Core/Configurable.h"
namespace LiveSupport {
namespace Core {
class AudioClip; // forward declarations to avoid circularity
class Playlist;
using namespace boost::posix_time;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* An abstract class which is extended by AudioClip and Playlist.
* It contains the methods which are common to these classes.
*/
class Playable : public boost::enable_shared_from_this<Playable>
{
public:
/**
* The sub-types a Playable object can belong to.
*/
enum Type { AudioClipType, PlaylistType };
private:
/**
* The type of this playable object (audio clip or playlist).
*/
Type type;
protected:
/**
* Only my children are allowed to instantiate me.
*
* @param typeParam either AudioClipType or PlaylistType.
*/
Playable(Type typeParam) throw ()
: type(typeParam)
{
}
public:
/**
* A virtual destructor, as this class has virtual functions.
*/
virtual
~Playable(void) throw ()
{
}
/**
* Return the id of the audio clip or playlist.
*
* @return the unique id of the audio clip or playlist.
*/
virtual Ptr<UniqueId>::Ref
getId(void) const throw () = 0;
/**
* Return the total playing length for this audio clip or playlist.
*
* @return the playing length in microseconds.
*/
virtual Ptr<time_duration>::Ref
getPlaylength(void) const throw () = 0;
/**
* Return the URI of the sound file of this audio clip or
* playlist, which can be played by the audio player. This
* sound file can be an mp3 or a SMIL file.
*
* @return the URI.
*/
virtual Ptr<const std::string>::Ref
getUri(void) const throw () = 0;
/**
* Set the URI of the sound file of this audio clip or
* playlist, which can be played by the audio player. This
* sound file can be an mp3 or a SMIL file.
*
* @param uri the new URI.
*/
virtual void
setUri(Ptr<const std::string>::Ref uri) throw () = 0;
/**
* Return the token which is used to identify this audio clip
* or playlist to the storage server.
*
* The token is set when the Playable object is acquired and
* unset (made null again) when it is released.
*
* @return the token.
*/
virtual Ptr<const std::string>::Ref
getToken(void) const throw () = 0;
/**
* Set the token which is used to identify this audio clip
* or playlist to the storage server.
*
* The token is set when the Playable object is acquired and
* unset (made null again) when it is released.
*
* @param token a new token.
*/
virtual void
setToken(Ptr<const std::string>::Ref token)
throw () = 0;
/**
* Return the title of this audio clip or playlist.
*
* @return the title.
*/
virtual Ptr<const Glib::ustring>::Ref
getTitle(void) const throw () = 0;
/**
* Set the title of this audio clip or playlist.
*
* @param title a new title.
*/
virtual void
setTitle(Ptr<const Glib::ustring>::Ref title)
throw () = 0;
/**
* Return the value of a metadata field in this audio clip or playlist.
* If the playable does not have this metadata field, returns a null
* pointer.
*
* @param key the name of the metadata field
* @return the value of the metadata field; 0 if there is
* no such field;
*/
virtual Ptr<Glib::ustring>::Ref
getMetadata(const std::string &key) const
throw () = 0;
/**
* Set the value of a metadata field in this audio clip or playlist.
*
* @param value the new value of the metadata field.
* @param key the name of the metadata field
* @exception std::invalid_argument if the key is dcterms:extent,
* but the value is not a valid ISO-8601 time
*/
virtual void
setMetadata(Ptr<const Glib::ustring>::Ref value,
const std::string &key)
throw (std::invalid_argument)
= 0;
/**
* Return a partial XML representation of this audio clip or playlist.
*
* This is a string containing a single <audioClip> or <playlist>
* XML element, with minimal information (ID, title, playlength)
* only, without an XML header or any other metadata.
*
* The encoding is UTF-8. IDs are 16-digit hexadecimal numbers,
* time durations have the format "hh:mm:ss.ssssss".
*
* @return a string representation of the audio clip as an XML element
*/
virtual Ptr<Glib::ustring>::Ref
getXmlElementString(void) const throw () = 0;
/**
* Return a complete XML representation of this audio clip or playlist.
*
* This is a string containing a an XML document with an <audioClip>
* or <playlist> root node, together with an XML header and a
* <metadata> element (in the case of playlists, for the outermost
* playlist only).
*
* The encoding is UTF-8. IDs are 16-digit hexadecimal numbers,
* time durations have the format "hh:mm:ss.ssssss".
*
* The audio clip or playlist can be reconstructed from
* the string returned by this method:
* <pre><code>
* Ptr<AudioClip>::Ref audioClip1 = ... something ...;
* Ptr<xmlpp::DomParser>::Ref parser;
* parser->parse_memory(*audioClip1->getXmlDocumentString());
* const xmlpp::Document* document = parser->get_document();
* const xmlpp::Element* root = document->get_root_node();
* Ptr<AudioClip>::Ref audioClip2(new AudioClip());
* audioClip2->configure(*root);
* </code></pre>
* results in two identical audio clips (this works for playlists,
* too, but see the note at Playlist::getXmlDocumentString()).
*
* @return a string representation of the audio clip as an XML document
*/
virtual Ptr<Glib::ustring>::Ref
getXmlDocumentString(void) const throw () = 0;
/**
* Return the type of this object.
*
* @return either AudioClipType or PlaylistType.
*/
Type
getType(void) const throw ()
{
return type;
}
/**
* Return an audio clip pointer to this object. If the object's
* type is not AudioClipType, returns a zero pointer.
*
* @see getType()
* @return an audio clip pointer to this object.
*/
Ptr<AudioClip>::Ref
getAudioClip(void) throw ();
/**
* Return a playlist pointer to this object. If the object's
* type is not PlaylistType, returns a zero pointer.
*
* @see getType()
* @return a playlist pointer to this object.
*/
Ptr<Playlist>::Ref
getPlaylist(void) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_Playable_h

View File

@ -1,927 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_Playlist_h
#define LiveSupport_Core_Playlist_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <map>
#include <stdexcept>
#include <libxml++/libxml++.h>
#include <XmlRpcValue.h>
#include <boost/date_time/posix_time/posix_time.hpp>
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/UniqueId.h"
#include "LiveSupport/Core/Configurable.h"
#include "LiveSupport/Core/Playable.h"
#include "LiveSupport/Core/PlaylistElement.h"
namespace LiveSupport {
namespace Core {
using namespace boost::posix_time;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A class representing playlist.
* Playlist are containers for AudioClips, with the additional
* information of when and how each audio clip is played inside
* the playlist.
*
* This object has to be configured with an XML configuration element
* called playlist. This may look like the following:
*
* <pre><code>
* &lt;playlist id="0000000000000001"
* title="My Playlist"
* playlength="00:18:30.000000"&gt;
* &lt;playlistElement&gt; ... &lt;/playlistElement&gt;
* ...
* &lt;playlistElement&gt; ... &lt;/playlistElement&gt;
* &lt;metadata xmlns="http://mdlf.org/livesupport/elements/1.0/"
* xmlns:ls="http://mdlf.org/livesupport/elements/1.0/"
* xmlns:dc="http://purl.org/dc/elements/1.1/"
* xmlns:dcterms="http://purl.org/dc/terms/"
* xmlns:xml="http://www.w3.org/XML/1998/namespace"&gt;
* &lt;dc:title&gt;File Title txt&lt;/dc:title&gt;
* &lt;dcterms:extent&gt;00:02:30.000000&lt;/dcterms:extent&gt;
* ...
* &lt;/metadata&gt;
* &lt;/playlist&gt;
* </code></pre>
*
* The DTD for the above element is:
*
* <pre><code>
* &lt;!ELEMENT playlist (playlistElement*, metadata?) &gt;
* &lt;!ATTLIST playlist id NMTOKEN #REQUIRED &gt;
* &lt;!ATTLIST playlist title CDATA "" &gt;
* &lt;!ATTLIST playlist playlength NMTOKEN #IMPLIED &gt;
* </code></pre>
*
* For detais of the playlistElement element, see the documentation
* for the PlaylistElement class.
*
* The metadata element is optional. The <code>configure()</code> method
* sets only those fields which had not been set previously: e.g., if we set
* some or all fields of the Playlist in the constructor, then these fields
* in the XML element will be ignored by <code>configure()</code>.
* The <code>title</code> attribute and the <code>&lt;dc:title&gt;</code>
* element set the same field; if both are present, the title is set from
* the attribute and the element is ignored..
* The same is true for the <code>playlength</code> attribute and the
* <code>&lt;dcterms:extent&gt;</code> element.
*
* It is required that by the end of the configure() method, the playlength
* is set somehow (from a constructor, the attribute or the element).
* If the title is not set by the end of the configure() method, it is then
* set to the empty string.
*
* A Playlist can be of various kinds, depending on what we want to use it
* for, and how we got it from the StorageClientInterface:
* <ul>
* <li>A playlist obtained by getPlaylist() has its <code>uri</code>,
* <code>token</code> and <code>editToken</code> fields all unset
* (i.e., null). Such playlists contain sub-playlists which
* are just stubs, i.e., <code>id, title, playlength</code> triples,
* without actual references to its content objects.</li>
* <li>A playlist obtained by acquirePlaylist() has its <code>uri</code>
* and <code>token</code> fields set, but its <code>editToken</code>
* field unset. These are complete Playlist objects, and their
* sub-playlists contain references to all their sub-objects etc.
* The sub-playlists have their <code>uri</code> fields set, which
* allows them to be played by the audio player, but their
* <code>token</code> field is unset, because these sub-playlists
* are acquired and will be released recursively when the outermost
* playlist containing them is acquired and released.</li>
* <li>A playlist obtained by editPlaylist() has its <code>editToken</code>
* field set (but <code>uri</code> and <code>token</code> unset).
* The sub-playlists of these are also just stubs.</li>
* </ul>
*
* The playlists are stored by the storage server in the format returned by
* the getXmlDocumentString() function:
* <ul>
* <li>The outermost &lt;playlist&gt; has an id attribute,
* a list of &lt;playlistElement&gt; children
* and a &lt;metadata&gt; child.</li>
* <li>Each &lt;playlistElement&gt; has an id
* and a relativeOffset attribute,
* either a &lt;playlist&gt; or an &lt;audioClip&gt; child,
* and optionally a &lt;fadeInfo&gt; child.</li>
* <li>Each &lt;playlist&gt; and &lt;audioClip&gt; has id, title
* and playlength attributes (and no children).</li>
* <li>Each &lt;fadeInfo&gt; has fadeIn and fadeOut attributes
* (and no children).</li>
* <li>The &lt;metadata&gt; element contains all the metadata of
* the outermost playlist.
* The dc:title and dcterms:extent elements are compulsory,
* everything else is optional.</li>
* </ul>
* An example:
*
* <pre><code>
* &lt;playlist id="0000000000000001"&gt;
* &lt;playlistElement id="0000000000000101"
* relativeOffset="00:00:00.000000"&gt;
* &lt;audioClip id="0000000000010001"
* title="My Audio Clip"
* playlength="00:02:30.000000"/&gt;
* &lt;fadeInfo id="0000000000009901"
* fadeIn="00:00:02.000000"
* fadeOut="00:00:01.500000"/&gt;
* &lt;/playlistElement&gt;
* &lt;playlistElement id="0000000000000102"
* relativeOffset="00:02:30.000000"&gt;
* &lt;playlist id="0000000000000002"
* title="Embedded Playlist"
* playlength="00:18:30.000000"/&gt;
* &lt;/playlistElement&gt;
* &lt;metadata xmlns="http://mdlf.org/livesupport/elements/1.0/"
* xmlns:ls="http://mdlf.org/livesupport/elements/1.0/"
* xmlns:dc="http://purl.org/dc/elements/1.1/"
* xmlns:dcterms="http://purl.org/dc/terms/"
* xmlns:xml="http://www.w3.org/XML/1998/namespace"&gt;
* &lt;dc:title&gt;My Playlist&lt;/dc:title&gt;
* &lt;dcterms:extent&gt;00:21:00.000000&lt;/dcterms:extent&gt;
* ...
* &lt;/metadata&gt;
* &lt;/playlist&gt;
* </code></pre>
*
*/
class Playlist : public Configurable,
public Playable
{
private:
/**
* The name of the configuration XML elmenent used by Playlist.
*/
static const std::string configElementNameStr;
/**
* The unique id of the playlist.
*/
Ptr<UniqueId>::Ref id;
/**
* The title of the playlist.
*/
Ptr<const Glib::ustring>::Ref title;
/**
* The playling length of the playlist.
*/
Ptr<time_duration>::Ref playlength;
/**
* The uri of the SMIL file generated from this playlist (if any).
*/
Ptr<const std::string>::Ref uri;
/**
* The token given to this playlist by the storage server when
* the playlist is acquired; removed when it is released.
*/
Ptr<const std::string>::Ref token;
/**
* The token given to this playlist by the storage server when
* it is opened for editing; removed when it is saved or reverted.
*/
Ptr<const std::string>::Ref editToken;
/**
* A map type for storing the playlist elements associated with
* this playlist, indexed by their relative offsets.
*/
typedef std::multimap<time_duration, Ptr<PlaylistElement>::Ref>
PlaylistElementListType;
/**
* The list of playlist elements for this playlist.
*/
Ptr<PlaylistElementListType>::Ref elementList;
/**
* A saved copy of this playlist.
*/
Ptr<Playlist>::Ref savedCopy;
/**
* This playlist in XML format.
*/
Ptr<xmlpp::Document>::Ref xmlPlaylist;
/**
* Set the value of a metadata field in this playlist.
*
* @param value the new value of the metadata field.
* @param name the name of the metadata field (without prefix)
* @param prefix the prefix of the metadata field
* @exception std::invalid_argument if the key is dcterms:extent,
* but the value is not a valid ISO-8601 time
*/
void
setMetadata(Ptr<const Glib::ustring>::Ref value,
const std::string &name, const std::string &prefix)
throw (std::invalid_argument);
/**
* Set the total playing length of this playlist.
*
* @param playlength the playing length in microseconds precision.
*/
void
setPlaylength(Ptr<time_duration>::Ref playlength)
throw ();
/**
* Set the playlength member of this audio clip.
*
* @param timeString the playing length in microseconds precision.
* @exception std::invalid_argument if the argument is not
* a valid ISO-8601 time
*/
void
setPlaylength(Ptr<const std::string>::Ref timeString)
throw (std::invalid_argument);
/**
* A private iterator type for internal use. It is non-constant;
* otherwise it is the same as Playlist::const_iterator.
*/
typedef PlaylistElementListType::iterator iterator;
/**
* Get an iterator pointing to a playlist element with a given ID.
*
* @param playlistElementId (a pointer to) the ID of the
* playlist element.
* @return an iterator to the playlist element if it exists,
* or <code>this->end()</code> if it does not.
*/
iterator
find(Ptr<UniqueId>::Ref playlistElementId)
throw ();
/**
* Convert a time_duration to string, in format HH:MM:SS.ssssss.
*/
std::string
toFixedString(Ptr<time_duration>::Ref time) const
throw ()
{
if (time->fractional_seconds()) {
return to_simple_string(*time);
} else {
return to_simple_string(*time) + ".000000";
}
}
public:
/**
* Copy constructor.
*
* @param otherPlaylist the playlist to be copied
*/
Playlist(const Playlist & otherPlaylist)
throw ();
/**
* Default constructor.
*
* NOTE: this constructor creates a Playlist with a null pointer
* for both the ID and the playlength fields! It is meant for
* internal use only.
*
* If you want to create an empty Playlist, use the storage client:
* <pre><code>
* Ptr<StorageClientFactory>::Ref
* storageClientFactory = StorageClientFactory::getInstance();
* Ptr<StorageClientInterface>::Ref
* storageClient = storageClientFactory->getStorageClient();
* Ptr<Playlist>::Ref
* playlist = storageClient->createPlaylist(sessionId);
* </code></pre>
*
* @see StorageClient::StorageClientFactory
* @see StorageClient::StorageClientInterface
*/
Playlist(void) throw ()
: Playable(PlaylistType)
{
elementList.reset(new PlaylistElementListType);
}
/**
* Create a playlist by specifying its ID only.
*
* For internal use; see the note at the default constructor.
*/
Playlist(Ptr<UniqueId>::Ref id) throw ()
: Playable(PlaylistType)
{
this->id = id;
elementList.reset(new PlaylistElementListType);
}
/**
* Create a playlist by specifying all details, except the title.
*
* This is used for testing purposes;
* see the note at the default constructor.
*
* @param id the id of the playlist.
* @param playlength the playing length of the playlist.
* @param uri the location of the SMIL file representing this
* playlist (optional)
*/
Playlist(Ptr<UniqueId>::Ref id,
Ptr<time_duration>::Ref playlength,
Ptr<const std::string>::Ref uri = Ptr<std::string>::Ref())
throw ();
/**
* Create a playlist by specifying all details.
*
* This is used for testing purposes;
* see the note at the default constructor.
*
* @param id the id of the playlist.
* @param title the title of the playlist.
* @param playlength the playing length of the playlist.
* @param uri the location of the SMIL file representing this
* playlist (optional)
*/
Playlist(Ptr<UniqueId>::Ref id,
Ptr<const Glib::ustring>::Ref title,
Ptr<time_duration>::Ref playlength,
Ptr<const std::string>::Ref uri = Ptr<std::string>::Ref())
throw ();
/**
* Convert the playlist to an XmlRpcValue (marshalling).
*
* @return an XmlRpcValue struct, containing a
* field named <i>playlist</i>, with value of type string,
* which contains an XML document representing the playlist.
*/
operator XmlRpc::XmlRpcValue() const
throw ();
/**
* Construct a playlist from an XmlRpcValue (demarshalling).
*
* @param xmlRpcValue an XmlRpcValue struct, containing a
* field named <i>playlist</i>, with value of type string,
* which contains an XML document, the root node of which
* can be passed to the configure() method.
* @exception std::invalid_argument if the argument is invalid
*/
Playlist(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* A virtual destructor, as this class has virtual functions.
*/
virtual
~Playlist(void) throw ()
{
}
/**
* Return the name of the XML element this object expects
* to be sent to a call to configure().
*
* @return the name of the expected XML configuration element.
*/
static const std::string
getConfigElementName(void) throw ()
{
return configElementNameStr;
}
/**
* Configure the object based on the XML element supplied.
* The supplied element is expected to be of the name
* returned by configElementName().
*
* @param element the XML element to configure the object from.
* @exception std::invalid_argument if the supplied XML element
* contains bad configuraiton information
*/
virtual void
configure(const xmlpp::Element & element)
throw (std::invalid_argument);
/**
* Return the id of the playlist.
*
* @return the unique id of the playlist.
*/
virtual Ptr<UniqueId>::Ref
getId(void) const throw ()
{
return id;
}
/**
* Return the title of this playlist.
*
* @return the title.
*/
virtual Ptr<const Glib::ustring>::Ref
getTitle(void) const throw ()
{
return title;
}
/**
* Set the title of this playlist.
*
* @param title a new title.
*/
virtual void
setTitle(Ptr<const Glib::ustring>::Ref title)
throw ();
/**
* Return the total playing length for this playlist.
*
* @return the playing length in microseconds precision.
*/
virtual Ptr<time_duration>::Ref
getPlaylength(void) const throw ()
{
return playlength;
}
/**
* Return the URI of the SMIL file created from this
* playlist, which can be played by the audio player.
*
* @return the URI.
*/
virtual Ptr<const std::string>::Ref
getUri(void) const throw ()
{
return uri;
}
/**
* Set the URI of the SMIL file created from this
* playlist, which can be played by the audio player.
*
* @param uri the new URI.
*/
virtual void
setUri(Ptr<const std::string>::Ref uri) throw ()
{
this->uri = uri;
}
/**
* Return the token which is used to identify this
* playlist to the storage server.
*
* The token is set when the Playable object is acquired and
* unset (made null again) when it is released.
*
* @return the token.
*/
virtual Ptr<const std::string>::Ref
getToken(void) const throw ()
{
return token;
}
/**
* Set the token which is used to identify this
* playlist to the storage server.
*
* The token is set when the Playable object is acquired and
* unset (made null again) when it is released.
*
* @param token a new token.
*/
virtual void
setToken(Ptr<const std::string>::Ref token)
throw ()
{
this->token = token;
}
/**
* Return the token which is used to identify this
* playlist to the storage server.
*
* The edit token is set when the Playable object is opened for
* editing and unset (made null again) when it is saved or reverted.
*
* @return the token.
*/
virtual Ptr<const std::string>::Ref
getEditToken(void) const throw ()
{
return editToken;
}
/**
* Set the token which is used to identify this
* playlist to the storage server.
*
* The edit token is set when the Playable object is opened for
* editing and unset (made null again) when it is saved or reverted.
*
* @param token a new token.
*/
virtual void
setEditToken(Ptr<const std::string>::Ref token)
throw ()
{
this->editToken = token;
}
/**
* Test whether the playlist is locked for editing.
*
* @return true if the playlist is currently being edited
*/
bool
isLocked() const throw ()
{
return (editToken.get() != 0);
}
/**
* The iterator type for this class. A Playlist::const_iterator
* is a (constant) pointer to a <code>pair &lt; time_duration,
* Ptr&lt;PlaylistElement&gt;::Ref &gt;</code>.
* If <code>it</code> is such an iterator, then <code>it->second</code>
* is the playlist element referenced by the iterator, and
* <code>it->first</code> is its relative offset in the playlist.
* The playlist elements are listed in the order of their relative
* offset (starting time).
*
* @see begin(), end(), find()
*/
typedef PlaylistElementListType::const_iterator const_iterator;
/**
* Get an iterator pointing to the first playlist element.
*/
const_iterator
begin() const throw ()
{
return elementList->begin();
}
/**
* Get an iterator pointing to one after the last playlist element.
*/
const_iterator
end() const throw ()
{
return elementList->end();
}
/**
* Get an iterator pointing to the first playlist element at a given
* relative offset.
*
* @param relativeOffset (a pointer to) the relative offset where
* the playlist element is.
* @return a constant iterator to the playlist element if it exists,
* or <code>this->end()</code> if it does not.
*/
const_iterator
find(Ptr<const time_duration>::Ref relativeOffset) const
throw ()
{
return elementList->find(*relativeOffset);
}
/**
* Return the number of playlist elements in the playlist.
*/
int
size() const throw ()
{
return elementList->size();
}
/**
* Add a new audio clip or sub-playlist to the playlist.
*
* Checks the type of the playlist, and calls either addAudioClip()
* or addPlaylist().
*
* @param playable the new playable item to be added
* @param relativeOffset the start of the playable item, relative
* to the start of the playlist
* @param fadeInfo the fade in / fade out info (optional)
* @return the ID of the new PlaylistElement
* @exception std::invalid_argument if playable is neither an AudioClip
* nor a Playlist
*/
Ptr<UniqueId>::Ref
addPlayable(Ptr<Playable>::Ref playable,
Ptr<time_duration>::Ref relativeOffset,
Ptr<FadeInfo>::Ref fadeInfo
= Ptr<FadeInfo>::Ref())
throw (std::invalid_argument);
/**
* Add a new audio clip to the playlist.
*
* The playlist is not checked for gaps (use valid() for that),
* but the playlength is adjusted if the new audio clip is added
* at the end of the playlist.
*
* @param audioClip the new audio clip to be added
* @param relativeOffset the start of the audio clip, relative
* to the start of the playlist
* @param fadeInfo the fade in / fade out info (optional)
* @return the ID of the new PlaylistElement
*/
Ptr<UniqueId>::Ref
addAudioClip(Ptr<AudioClip>::Ref audioClip,
Ptr<time_duration>::Ref relativeOffset,
Ptr<FadeInfo>::Ref fadeInfo
= Ptr<FadeInfo>::Ref())
throw ();
/**
* Add a new sub-playlist to the playlist.
*
* The playlist is not checked for gaps (use valid() for that),
* but the playlength is adjusted if the new sub-playlist is added
* at the end of the playlist.
*
* @param playlist the sub-playlist to be added
* @param relativeOffset the start of the sub-playlist, relative
* to the start of the containing playlist
* @param fadeInfo the fade in / fade out info (optional)
* @return the ID of the new PlaylistElement
*/
Ptr<UniqueId>::Ref
addPlaylist(Ptr<Playlist>::Ref playlist,
Ptr<time_duration>::Ref relativeOffset,
Ptr<FadeInfo>::Ref fadeInfo
= Ptr<FadeInfo>::Ref())
throw ();
/**
* Add a new playlist element to the playlist.
*
* @param playlistElement the new playlist element to be added
*/
void
addPlaylistElement(Ptr<PlaylistElement>::Ref playlistElement)
throw ();
/**
* Set the fade in / fade out info for a playlist element.
*
* @param playlistElementId the ID of the playlist element
* @param fadeInfo the new fade in / fade out info
* @exception std::invalid_argument if there is no playlist element
* at the given relative offset
*/
void
setFadeInfo(Ptr<UniqueId>::Ref playlistElementId,
Ptr<FadeInfo>::Ref fadeInfo)
throw (std::invalid_argument);
/**
* Set clipStart for a playlist element.
*
*/
void
setClipStart(Ptr<UniqueId>::Ref playlistElementId,
Ptr<time_duration>::Ref newStart)
throw (std::invalid_argument);
/**
* Set clipEnd for a playlist element.
*
*/
void
setClipEnd(Ptr<UniqueId>::Ref playlistElementId,
Ptr<time_duration>::Ref newEnd)
throw (std::invalid_argument);
/**
* Remove a playlist element from the playlist.
*
* @param playlistElementId the ID of the playlist element
* @exception std::invalid_argument if the playlist element does not
* exist
*/
void
removePlaylistElement(Ptr<UniqueId>::Ref playlistElementId)
throw (std::invalid_argument);
/**
* Check if the playlist is valid.
*
* This means that
* <ul>
* <li>there are no gaps between the playlist elements
* (overlaps are allowed); and</li>
* <li>the length of the playlist is equal
* to the ending time of the last item in it.</li>
* </ul>
*
* This is checked for the playlist itself, and all sub-playlists
* contained inside it.
*
* NOTE: all kinds of overlaps are allowed.
* TODO: restrict it somehow?
*/
bool
valid(void) const throw ();
/**
* Create a saved copy of this playlist. If a saved copy exists
* already, it is replaced by the current state.
*/
void
createSavedCopy(void) throw ();
/**
* Delete the saved copy of the playlist, if exists (or do nothing).
*/
void
deleteSavedCopy(void) throw ()
{
savedCopy.reset();
}
/**
* Revert to the saved copy of this playlist. If there is no
* saved copy, do nothing and throw an exception.
*/
void
revertToSavedCopy(void) throw (std::invalid_argument);
/**
* Return the value of a metadata field in this playlist.
* If the playlist does not have this metadata field, returns a null
* pointer.
*
* @param key the name of the metadata field
* @return the value of the metadata field; 0 if there is
* no such field;
*/
virtual Ptr<Glib::ustring>::Ref
getMetadata(const std::string &key) const
throw ();
/**
* Set the value of a metadata field in this playlist.
*
* @param value the new value of the metadata field.
* @param key the name of the metadata field
* @exception std::invalid_argument if the key is dcterms:extent,
* but the value is not a valid ISO-8601 time
*/
virtual void
setMetadata(Ptr<const Glib::ustring>::Ref value,
const std::string &key)
throw (std::invalid_argument);
/**
* Return a partial XML representation of this audio clip or playlist.
*
* This is a string containing a single &lt;playlist&gt;
* XML element, with minimal information { id, title, playlength }
* only, without an XML header or any other metadata.
* It does not contain the list of playlist elements in the playlist.
*
* The encoding is UTF-8. IDs are 16-digit hexadecimal numbers,
* time durations have the format "hh:mm:ss.ssssss".
*
* @return a string representation of the playlist as an XML element
*/
virtual Ptr<Glib::ustring>::Ref
getXmlElementString(void) const throw ();
/**
* Return a complete XML representation of this playlist.
*
* This is a string containing a an XML document with a
* &lt;playlist&gt; root node, together with an XML header and a
* &lt;metadata&gt; element (for the outermost playlist only).
*
* The playlist elements listed are only stubs returned by
* getXmlElementString(), i.e., { id, title, playlength } triples,
* without their contents. See the more detailed description at
* the top of this page.
*
* The encoding is UTF-8. IDs are 16-digit hexadecimal numbers,
* time durations have the format "hh:mm:ss.ssssss".
*
* The <i>uri</i>, <i>token</i> and <i>editToken</i> fields are not
* part of the XML document string returned.
*
* @return a string representation of the playlist as an XML document
*/
virtual Ptr<Glib::ustring>::Ref
getXmlDocumentString(void) const throw ();
/**
* Eliminate the gaps in the playlist.
*
* If there is a 2s gap between elements 2 and 3, then elements 3,
* 4, etc. are moved to 2s earlier. Elements 2 and 3 will not
* overlap, even if the first has a fade-out and the second has a
* fade-in.
*
* @return true if some gaps have been found and eliminated
*/
virtual bool
eliminateGaps(void) throw ();
/**
* Find the playlist element at the specified offset.
*
* This is used by the Master Panel to display the contents
* of the currently playing Playlist.
* When there are more than one playlist elements at the given
* offset, the one with the greatest relativeOffset is chosen.
* Can return a 0 pointer if there is no playlist element at
* the given offset.
*
* @param offset the elapsed time relative to the Playlist.
* @return the playlist element at the given offset.
*/
Ptr<PlaylistElement>::Ref
findAtOffset(Ptr<const time_duration>::Ref offset) const
throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_Playlist_h

View File

@ -1,475 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_PlaylistElement_h
#define LiveSupport_Core_PlaylistElement_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <stdexcept>
#include <string>
#include <libxml++/libxml++.h>
#include <boost/date_time/posix_time/posix_time.hpp>
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/UniqueId.h"
#include "LiveSupport/Core/Configurable.h"
#include "LiveSupport/Core/Playable.h"
#include "LiveSupport/Core/AudioClip.h"
#include "LiveSupport/Core/Playlist.h"
#include "LiveSupport/Core/FadeInfo.h"
namespace LiveSupport {
namespace Core {
using namespace boost::posix_time;
using namespace LiveSupport;
using namespace LiveSupport::Core;
// forward declaration to avoid circular reference
class Playlist;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* An item in a Playlist, consisting of an AudioClip or another Playlist
* and optional FadeInfo (fade in / fade out information).
*
* The contents of the playlist element can be accessed either by calling
* getPlayable(), or, if a specific type of element is needed, by checking
* getType() first, and then calling either getAudioClip() or getPlaylist().
*
* This object has to be configured with an XML configuration element
* called playlistElement. This may look like the following:
*
* <pre><code>
* &lt;playlistElement id="707" relativeOffset="00:12:34.000000" &gt;
* &lt;audioClip&gt; ... &lt;/audioClip&gt;
* &lt;fadeInfo&gt; ... &lt;/fadeInfo&gt;
* &lt;/playlist&gt;
* </code></pre>
*
* For detais of the audioClip and fadeInfo elements, see the documentation
* for the AudioClip and FadeInfo classes.
*
* The DTD for the above element is:
*
* <pre><code>
* &lt;!ELEMENT playlistElement ((audioClip|playlist), fadeInfo?) &gt;
* &lt;!ATTLIST playlistElement id NMTOKEN #REQUIRED &gt;
* &lt;!ATTLIST playlistElement relativeOffset NMTOKEN #REQUIRED &gt;
* </code></pre>
*/
class PlaylistElement : public Configurable
{
public:
/**
* The possible types of the playlist element (audio clip or
* sub-playlist).
*/
enum Type { AudioClipType, PlaylistType };
private:
/**
* The name of the configuration XML element used by Playlist.
*/
static const std::string configElementNameStr;
/**
* The id of the playlist element.
*/
Ptr<UniqueId>::Ref id;
/**
* The starting time of the event.
*/
Ptr<time_duration>::Ref relativeOffset;
Ptr<time_duration>::Ref clipStart;
Ptr<time_duration>::Ref clipEnd;
Ptr<time_duration>::Ref clipLength;
/**
* The type of the entry (audio clip or sub-playlist).
*/
Type type;
/**
* The generic playable object associated with the entry.
* This is either an audio clip or a playlist.
*/
Ptr<Playable>::Ref playable;
/**
* The audio clip associated with the entry.
*/
Ptr<AudioClip>::Ref audioClip;
/**
* The playlist associated with the entry.
*/
Ptr<Playlist>::Ref playlist;
/**
* The fade in / fade out info associated with the entry.
*/
Ptr<FadeInfo>::Ref fadeInfo;
/**
* Convert a time_duration to string, in format HH:MM:SS.ssssss.
*/
std::string
toFixedString(Ptr<time_duration>::Ref time) const throw ()
{
if (time->fractional_seconds()) {
return to_simple_string(*time);
} else {
return to_simple_string(*time) + ".000000";
}
}
public:
/**
* The default constructor.
*/
PlaylistElement(void) throw ();
/**
* Create a playlist element by specifying all details.
* This is used for testing purposes.
*
* @param id the id of the entry.
* @param relativeOffset the start time of this element, relative to
* the start of the playlist.
* @param audioClip (a pointer to) the audio clip associated
* with the playlist element.
* @param fadeInfo fade in / fade out information (optional)
*/
PlaylistElement(Ptr<UniqueId>::Ref id,
Ptr<time_duration>::Ref relativeOffset,
Ptr<time_duration>::Ref clipLength,
Ptr<AudioClip>::Ref audioClip,
Ptr<FadeInfo>::Ref fadeInfo
= Ptr<FadeInfo>::Ref())
throw ();
/**
* Create a new audio clip playlist element, with a new UniqueId,
* to be added to a playlist.
*
* @param relativeOffset the start time of this element, relative to
* the start of the playlist.
* @param audioClip (a pointer to) the audio clip associated
* with the playlist element.
* @param fadeInfo fade in / fade out information (optional)
*/
PlaylistElement(Ptr<time_duration>::Ref relativeOffset,
Ptr<time_duration>::Ref clipLength,
Ptr<AudioClip>::Ref audioClip,
Ptr<FadeInfo>::Ref fadeInfo
= Ptr<FadeInfo>::Ref())
throw ();
/**
* Create a new sub-playlist playlist element, with a new UniqueId,
* to be added to a playlist.
*
* @param relativeOffset the start time of this element, relative to
* the start of the playlist.
* @param playlist (a pointer to) the sub-playlist associated
* with the playlist element.
* @param fadeInfo fade in / fade out information (optional)
*/
PlaylistElement(Ptr<time_duration>::Ref relativeOffset,
Ptr<time_duration>::Ref clipLength,
Ptr<Playlist>::Ref playlist,
Ptr<FadeInfo>::Ref fadeInfo
= Ptr<FadeInfo>::Ref())
throw ();
/**
* A virtual destructor, as this class has virtual functions.
*/
virtual
~PlaylistElement(void) throw ();
/**
* Return the name of the XML element this object expects
* to be sent to a call to configure().
*
* @return the name of the expected XML configuration element.
*/
static const std::string
getConfigElementName(void) throw ()
{
return configElementNameStr;
}
/**
* Configure the object based on the XML element supplied.
* The supplied element is expected to be of the name
* returned by configElementName().
*
* @param element the XML element to configure the object from.
* @exception std::invalid_argument if the supplied XML element
* contains bad configuration information
*/
virtual void
configure(const xmlpp::Element & element)
throw (std::invalid_argument);
/**
* Return the id of the playlist element.
*
* @return the id of the playlist element.
*/
Ptr<UniqueId>::Ref
getId(void) const throw ()
{
return id;
}
/**
* Set the relative offset of the playlist element.
* Note: this is very dangerous; use only if you know what you are
* doing. Never ever change the relative offset of a PlaylistElement
* which is contained in a Playlist.
*
* @param newOffset the new relative offset of the element.
*/
void
setRelativeOffset(Ptr<time_duration>::Ref newOffset)
throw ()
{
relativeOffset = newOffset;
}
/**
* Return the relative offset of the playlist element.
*
* @return the relative offset of the element.
*/
Ptr<time_duration>::Ref
getRelativeOffset(void) const throw ()
{
return relativeOffset;
}
/**
*/
void
setClipStart(Ptr<time_duration>::Ref newStart)
throw ()
{
clipStart = newStart;
}
/**
*/
Ptr<time_duration>::Ref
getClipStart(void) const throw ()
{
return clipStart;
}
/**
*/
void
setClipEnd(Ptr<time_duration>::Ref newEnd)
throw ()
{
clipEnd = newEnd;
}
/**
*/
Ptr<time_duration>::Ref
getClipEnd(void) const throw ()
{
return clipEnd;
}
/**
*/
void
setClipLength(Ptr<time_duration>::Ref newLength)
throw ()
{
clipLength = newLength;
}
/**
*/
Ptr<time_duration>::Ref
getClipLength(void) const throw ()
{
return clipLength;
}
/**
* Return the type of this playlist element. If the return
* value is PlaylistElement::AudioClipType (resp. PlaylistType),
* the getAudioClip() (resp. getPlaylist())
* method is guaranteed to return a non-zero value.
*
* @return either AudioClipType or PlaylistType.
*/
Type
getType(void) const throw ()
{
return type;
}
/**
* Return the Playable instance (an AudioClip or a Playlist)
* associated with the playlist element. Use this if you don't
* care which type this playlist element is, e.g., you
* just want to play it in an audio player.
*
* @return the Playable instance associated with the element.
*/
Ptr<Playable>::Ref
getPlayable(void) const throw ()
{
return playable;
}
/**
* Set the Playable instance (an AudioClip or a Playlist)
* associated with the playlist element.
*
* This is used by WebStorageClient::acquirePlaylist() to replace
* a stub (id, title, playlength only) sub-playlist with a full one.
*
* @param playable the new Playable object.
*/
void
setPlayable(Ptr<Playable>::Ref playable) throw ()
{
this->playable = playable;
switch (playable->getType()) {
case Playable::AudioClipType :
audioClip = playable->getAudioClip();
type = AudioClipType;
break;
case Playable::PlaylistType :
playlist = playable->getPlaylist();
type = PlaylistType;
break;
}
}
/**
* Return the audio clip associated with the playlist element.
*
* @see getType()
* @return the audio clip associated with the element.
*/
Ptr<AudioClip>::Ref
getAudioClip(void) const throw ()
{
return audioClip;
}
/**
* Return the sub-playlist associated with the playlist element.
*
* @see getType()
* @return the sub-playlist associated with the element.
*/
Ptr<Playlist>::Ref
getPlaylist(void) const throw ()
{
return playlist;
}
/**
* Set the fade info associated with the playlist element.
*
* @param fadeInfo the fade info to be associated with the element.
*/
void
setFadeInfo(Ptr<FadeInfo>::Ref fadeInfo) throw ()
{
this->fadeInfo = fadeInfo;
}
/**
* Return the fade info associated with the playlist element.
*
* @return the fade info associated with the element.
*/
Ptr<FadeInfo>::Ref
getFadeInfo(void) const throw ()
{
return fadeInfo;
}
/**
* Return an XML representation of this playlist element.
*
* This is a string containing a single <playlistElement>
* XML element, with its ID and relativeOffset attributes,
* plus an <audioClip> or <playlist> XML element,
* plus an optional <fadeInfo> element.
*
* The encoding is UTF-8. IDs are 16-digit hexadecimal numbers,
* time durations have the format "hh:mm:ss.ssssss".
*
* @return a string representation of the audio clip as an XML element
*/
Ptr<Glib::ustring>::Ref
getXmlElementString(void) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_PlaylistElement_h

View File

@ -1,99 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_Ptr_h
#define LiveSupport_Core_Ptr_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <boost/shared_ptr.hpp>
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A placeholder class for holidng typedefs to smart pointers.
* This is a workaround, as unfortunately typedfs in themselves may
* not be templated. For a discussion on the issue, see
* http://www.gotw.ca/gotw/079.htm
*
* The smart pointers here are typedefs to the smart pointers in the
* boost library. For documentation of the boost smart pointers,
* see http://www.boost.org/libs/smart_ptr/
*/
template <class T>
class Ptr
{
private:
/**
* Default constructor.
*/
Ptr(void) throw ()
{
}
public:
/**
* This is actually a typedef to the boost shared_ptr, which
* is a reference counting shared smart pointer.
* For more on boost::shared_ptr, see
* http://www.boost.org/libs/smart_ptr/shared_ptr.htm
*
* To use this pointer, define as follows:
* <code>
* Ptr<MyType>::Ref myPointer;
* </code>
*/
typedef boost::shared_ptr<T> Ref;
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_Ptr_h

View File

@ -1,239 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_RdsContainer_h
#define LiveSupport_Core_RdsContainer_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <map>
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/Configurable.h"
#include "LiveSupport/Core/RdsItem.h"
namespace LiveSupport {
namespace Core {
using namespace LiveSupport::Core;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Container holding RdsItem objects.
*
* It is used by the OptionContainer class to hold RDS strings
* (see http://en.wikipedia.org/wiki/Radio_Data_System).
*
* This object has to be configured with an XML configuration element
* called rdsContainer. This may look like the following:
*
* <pre><code>
* &lt;rdsContainer&gt;
* &lt;rdsItem&gt; ... &lt;/rdsItem&gt;
* &lt;rdsItem&gt; ... &lt;/rdsItem&gt;
* ...
* &lt;rdsItem&gt; ... &lt;/rdsItem&gt;
* &lt;/rdsContainer&gt;
* </code></pre>
*
* The DTD for the expected XML element is the following:
*
* <pre><code>
* <!ELEMENT rdsContainer (rdsItem*) >
* </code></pre>
*
* For a description of the rdsItem XML element, see the documentation
* of the RdsItem class.
*
* @see KeyboardShortcut
*/
class RdsContainer : public Configurable
{
private:
/**
* The name of the configuration XML element used by
* RdsContainer.
*/
static const std::string configElementName;
/**
* A vector type holding contant KeyboardShortcut references.
*/
typedef std::vector<Ptr<RdsItem>::Ref>
RdsItemListType;
/**
* The list of all RdsItem references.
*/
RdsItemListType rdsItemList;
/**
* An XML document used by toXmlElement().
*/
Ptr<xmlpp::Document>::Ref xmlDocument;
/**
* Set to true by setRdsString(), and to false by toXmlElement().
*/
bool touched;
public:
/**
* Constructor.
*/
RdsContainer() throw ()
: touched(false)
{
}
/**
* A virtual destructor, as this class has virtual functions.
*/
virtual
~RdsContainer(void) throw ()
{
}
/**
* Return the name of the XML element this object expects
* to be sent to a call to configure().
*
* @return the name of the expected XML configuration element.
*/
static const std::string
getConfigElementName(void) throw ()
{
return configElementName;
}
/**
* Configure the object based on an XML configuration element.
*
* @param element the XML configuration element.
* @exception std::invalid_argument if the supplied XML element
* contains bad configuration information.
*/
virtual void
configure(const xmlpp::Element &element)
throw (std::invalid_argument);
/**
* Set the value of the RDS options.
* The key can be any of the RDS data codes, like PS, PI, PTY, RT,
* etc. If there is already a value set for this code, it gets
* overwritten, otherwise a new key-value pair is added.
*
* @param key which setting to modify.
* @param value the new value of the RDS setting.
* @param enabled whether this value will be broadcast.
*/
void
setRdsOptions(Ptr<const Glib::ustring>::Ref key,
Ptr<const Glib::ustring>::Ref value,
bool enabled) throw ();
/**
* Get the value of an RDS string.
* The key can be any of the RDS data codes, like PS, PI, PTY, RT,
* etc.
*
* @param key which setting to modify.
* @return the value of the RDS setting.
* @exception std::invalid_argument if there is no such RDS option.
*/
Ptr<const Glib::ustring>::Ref
getRdsValue(Ptr<const Glib::ustring>::Ref key)
throw (std::invalid_argument);
/**
* Get the enabled/disabled state of an RDS option.
*
* @param key which setting to modify.
* @return true if the RDS option is enabled, false otherwise.
* @exception std::invalid_argument if there is no such RDS option.
*/
bool
getRdsEnabled(Ptr<const Glib::ustring>::Ref key)
throw (std::invalid_argument);
/**
* Convert the object to a string.
*
* @return a string which can be sent to the RDS encoder.
*/
Ptr<Glib::ustring>::Ref
toString(void) throw ();
/**
* Convert the object to XML.
*
* @return an XML Element, which can be passed to configure()
* to create an object identical to this one.
*/
const xmlpp::Element *
toXmlElement(void) throw ();
/**
* Tells you whether the object has been touched since the last save.
* Starts out false; set to true by setRdsString() and set back to
* false by toXmlElement().
*
* @return whether the object has been touched.
*/
bool
isTouched(void) throw ()
{
return touched;
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_RdsContainer_h

View File

@ -1,277 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_RdsItem_h
#define LiveSupport_Core_RdsItem_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <stdexcept>
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/Configurable.h"
namespace LiveSupport {
namespace Core {
using namespace LiveSupport::Core;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A class for representing an RDS key - value pair.
*
* This object has to be configured with an XML configuration element
* called rdsItem. This may look like the following:
*
* <pre><code>
* &lt;rdsItem key = "PS"
* value = "BBC Four"
* enabled = "1" /&gt;
* </code></pre>
*
* The possible key values are PS, PI, RT, etc
* (see http://en.wikipedia.org/wiki/Radio_Data_System).
*
* There value attribute can be any string.
*
* The enabled attribute is either 0 (disabled) or 1 (enabled).
*
* The DTD for the expected XML element looks like the following:
*
* <pre><code>
* &lt;!ELEMENT rdsItem EMPTY &gt;
* &lt;!ATTLIST rdsItem key CDATA #REQUIRED &gt;
* &lt;!ATTLIST rdsItem value CDATA #REQUIRED &gt;
* &lt;!ATTLIST rdsItem enabled CDATA #REQUIRED &gt;
* </code></pre>
*
* @see RdsItemContainer
*/
class RdsItem : public Configurable
{
private:
/**
* The name of the configuration XML element used by RdsItem.
*/
static const std::string configElementName;
/**
* The key for this RDS item.
*/
Ptr<const Glib::ustring>::Ref key;
/**
* The value for this RDS item.
*/
Ptr<const Glib::ustring>::Ref value;
/**
* The enabled/disabled attribute for this RDS item.
*/
bool enabled;
/**
* An XML document used by toXmlElement().
*/
Ptr<xmlpp::Document>::Ref xmlDocument;
/**
* Set to true by setValue(), and to false by toXmlElement().
*/
bool touched;
public:
/**
* Default constructor.
*/
RdsItem() throw ()
: enabled(false),
touched(false)
{
}
/**
* Constructor which sets the variables.
*/
RdsItem(Ptr<const Glib::ustring>::Ref key,
Ptr<const Glib::ustring>::Ref value,
bool enabled = false) throw ()
: key(key),
value(value),
enabled(enabled),
touched(false)
{
}
/**
* A virtual destructor, as this class has virtual functions.
*/
virtual
~RdsItem(void) throw ()
{
}
/**
* Return the name of the XML element this object expects
* to be sent to a call to configure().
*
* @return the name of the expected XML configuration element.
*/
static const std::string
getConfigElementName(void) throw ()
{
return configElementName;
}
/**
* Configure the object based on an XML configuration element.
*
* @param element the XML configuration element.
* @exception std::invalid_argument if the supplied XML element
* contains bad configuration information
*/
virtual void
configure(const xmlpp::Element &element)
throw (std::invalid_argument);
/**
* Get the key.
* The key can be a 0 pointer if the object has not been
* configured yet.
*
* @return the key of this RDS item.
*/
Ptr<const Glib::ustring>::Ref
getKey(void) throw ()
{
return key;
}
/**
* Get the value.
* The value can be a 0 pointer if the object has not been
* configured yet.
*
* @return the key of this RDS item.
*/
Ptr<const Glib::ustring>::Ref
getValue(void) throw ()
{
return value;
}
/**
* Set the value.
*
* @param value the new value of this RDS item.
*/
void
setValue(Ptr<const Glib::ustring>::Ref value) throw ()
{
this->value = value;
touched = true;
}
/**
* Get the enabled/disabled flag.
*
* @return true if the RDS item is enabled, false if not.
*/
bool
getEnabled(void) throw ()
{
return enabled;
}
/**
* Set the enabled/disabled flag.
*
* @param enabled the new value of the flag.
*/
void
setEnabled(bool enabled) throw ()
{
this->enabled = enabled;
touched = true;
}
/**
* Convert the object to a string.
*
* @return a string which can be sent to the RDS encoder.
*/
Ptr<Glib::ustring>::Ref
toString(void) throw ();
/**
* Convert the object to XML.
*
* @return an XML Element, which can be passed to configure()
* to create an object identical to this one.
*/
const xmlpp::Element *
toXmlElement(void) throw ();
/**
* Tells you whether the object has been touched since the last save.
* Starts out false; set to true by setValue() and setEnabled();
* set back to false by toXmlElement().
*
* @return whether the object has been touched.
*/
bool
isTouched(void) throw ()
{
return touched;
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_RdsItem_h

View File

@ -1,100 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_RunnableInterface_h
#define LiveSupport_Core_RunnableInterface_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A Runnable object, that can form the main execution body of a thread.
*
* @see Thread
*/
class RunnableInterface
{
public:
/**
* A virtual destructor, as this class has virtual functions.
*/
virtual
~RunnableInterface(void) throw ()
{
}
/**
* The main execution loop for the thread.
*/
virtual void
run(void) throw () = 0;
/**
* Send a signal to the runnable object.
*
* @param userData user-specific parameter for the signal.
*/
virtual void
signal(int userData) throw () = 0;
/**
* Signal the thread to stop, gracefully.
* This is just a call to signal the execution to stop, eventually.
*/
virtual void
stop(void) throw () = 0;
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_RunnableInterface_h

View File

@ -1,272 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_ScheduleEntry_h
#define LiveSupport_Core_ScheduleEntry_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <stdexcept>
#include <string>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <libxml++/libxml++.h>
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/UniqueId.h"
namespace LiveSupport {
namespace Core {
using namespace boost::posix_time;
using namespace LiveSupport;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A scheduled event.
*/
class ScheduleEntry
{
private:
/**
* The name of the schedule entry element
*/
static const std::string scheduleEntryElementName;
/**
* The name of the id attribute in the schedule entry element
*/
static const std::string idAttrName;
/**
* The name of the playlist attribute in the schedule entry element
*/
static const std::string playlistIdAttrName;
/**
* The name of the startTime attribute in the schedule entry element
*/
static const std::string startTimeAttrName;
/**
* The name of the endTime attribute in the schedule entry element
*/
static const std::string endTimeAttrName;
/**
* The name of the playlength attribute in the schedule entry element
*/
static const std::string playlengthAttrName;
/**
* The id of the schedule entry.
*/
Ptr<UniqueId>::Ref id;
/**
* The id of the playlist associated with the entry.
*/
Ptr<UniqueId>::Ref playlistId;
/**
* The starting time of the event.
*/
Ptr<ptime>::Ref startTime;
/**
* The end time for the event.
*/
Ptr<ptime>::Ref endTime;
/**
* The playling length of the event.
*/
Ptr<time_duration>::Ref playlength;
/**
* The default constructor.
*/
ScheduleEntry(void) throw ()
{
}
public:
/**
* A constructor with initialization values.
*
* @param id the id of the entry.
* @param playlistId the id of the playlist associated with the entry.
* @param startTime the starting time for the entry.
* @param endTime the ending time for the entry.
*/
ScheduleEntry(Ptr<UniqueId>::Ref id,
Ptr<UniqueId>::Ref playlistId,
Ptr<ptime>::Ref startTime,
Ptr<ptime>::Ref endTime)
throw ()
{
this->id = id;
this->playlistId = playlistId;
this->startTime = startTime;
this->endTime = endTime;
playlength.reset(new time_duration(*endTime - *startTime));
}
/**
* A constructor based on a DOM element
*
* @param element a DOM element returned earlier by a
* toDom() call from another schedule entry.
* @throws std::invalid_argument in case of a bad DOM element
* @see #getElementName
* @see #toDom
*/
ScheduleEntry(xmlpp::Element * element)
throw (std::invalid_argument);
/**
* Return the name of the DOM element used to export / import
* a schedule entry.
*
* @return the DOM element name used at export / import.
*/
static const std::string
getElementName(void) throw ()
{
return scheduleEntryElementName;
}
/**
* Return the id of the entry.
*
* @return the id of the entry.
*/
Ptr<const UniqueId>::Ref
getId(void) const throw ()
{
return id;
}
/**
* Return the id of the playlist associated with the entry.
*
* @return the id of the playlist associated with the entry.
*/
Ptr<const UniqueId>::Ref
getPlaylistId(void) const throw ()
{
return playlistId;
}
/**
* Return the starting time for the entry.
*
* @return the starting time for the entry.
*/
Ptr<const ptime>::Ref
getStartTime(void) const throw ()
{
return startTime;
}
/**
* Return the ending time for the entry.
*
* @return the ending time for the entry.
*/
Ptr<const ptime>::Ref
getEndTime(void) const throw ()
{
return endTime;
}
/**
* Return the playlength of the schedule entry.
*
* @return the playing length of the schedule entry.
*/
Ptr<const time_duration>::Ref
getPlaylength(void) const throw ()
{
return playlength;
}
/**
* Return a DOM representation of this object.
* Can be used to serialize or generate another object with
* a DOM-based constructor.
*
* @param element the new DOM node will be a new child of this
* element.
* @see #getElementName
*/
void
toDom(xmlpp::Element * element) const throw ();
/**
* Compare a schedule entry to another one.
*
* @param other the other entry to compare to.
*/
bool
operator==(const ScheduleEntry & other) const throw ()
{
return *id == *other.id
&& *playlistId == *other.playlistId
&& *startTime == *other.startTime
&& *endTime == *other.endTime
&& *playlength == *other.playlength;
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_ScheduleEntry_h

View File

@ -1,396 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_SearchCriteria_h
#define LiveSupport_Core_SearchCriteria_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <stdexcept>
#include <cctype>
#include <XmlRpcValue.h>
#include <boost/date_time/posix_time/posix_time.hpp>
#include "LiveSupport/Core/Ptr.h"
// forward declaration of friend class
namespace LiveSupport {
namespace StorageClient {
class TestStorageClient;
} }
namespace LiveSupport {
namespace Core {
using namespace boost::posix_time;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* An object which contains a collection of search conditions.
*
* Its fields are:
* <ul>
* <li>type - values in (audioClip | playlist | all); the default is
* <i>all</i></li>
* <li>operator - values in (and | or); the default is <i>and</i></li>
* <li>condition1 : { key : string, comparison: string, value : string }
* - a search condition, where <i>key</i> is one of the
* fields in the metadata, and <i>comparison</i> is
* one of ("=" | "partial" | "prefix"
* | "<" | "<=" | ">" | ">=")</li>
* <li>...</li>
* <li>conditionN</li>
* <li>limit : int - the maximum number of results to be returned;
* the default is 0, which means unlimited</li>
* <li>offset : int - ignore the first <i>offset</i> matches;
* the default is 0.</li>
* </ul>
*
* Usage: construct a SearchCriteria object either directly using the
* constructor with 4 string arguments, or in several steps using
* addCondition() and the setter methods;
* then pass this object to StorageClientInterface::search()
* to search the local storage.
*
* The <i>key</i> and <i>value</i> fields are case-sensitive, all the other
* strings (type, operator names) are case-insensitive.
*/
class SearchCriteria
{
public:
/**
* A type to hold a single search condition.
*/
struct SearchConditionType
{
std::string key;
std::string comparisonOperator;
std::string value;
SearchConditionType(const std::string & key,
const std::string & comparisonOperator,
const std::string & value)
: key(key), comparisonOperator(comparisonOperator), value(value)
{
}
};
private:
/**
* The kind of object we are searching for.
*/
std::string type;
/**
* The logical operator joining the conditions: "and" or "or".
*/
std::string logicalOperator;
/**
* A type to hold the list of search conditions.
*/
typedef std::vector<SearchConditionType>
SearchConditionListType;
/**
* The vector of search conditions.
*/
SearchConditionListType searchConditions;
/**
* The mtime to use for "ls:mtime".
*/
Ptr<const ptime>::Ref mtimeValue;
/**
* The comparison operator to use for "ls:mtime".
*/
std::string mtimeComparisonOperator;
/**
* The maximum number of conditions to be returned.
*/
int limit;
/**
* The index of the first matching condition to be returned.
*/
int offset;
/**
* Lowercase a string.
*/
std::string
lowerCase(const std::string & s) throw()
{
std::string returnValue;
std::string::const_iterator it = s.begin();
while (it != s.end()) {
returnValue += std::tolower(*it);
++it;
}
return returnValue;
}
/**
* Give access of private members to the TestStorageClient.
*/
friend class LiveSupport::StorageClient::TestStorageClient;
/**
* Add a search condition.
*
* @param xmlRpcValue the condition to add.
* @exception std::invalid_argument on syntax errors.
*/
void
addCondition(const XmlRpc::XmlRpcValue & xmlRpcValue)
throw(std::invalid_argument);
public:
/**
* Construct an empty SearchCriteria object.
* This also works as a default constructor.
*
* @param type one of "audioClip" (default), "playlist" or "all"
* @param logicalOperator either "and" (default) or "or"
* @exception std::invalid_argument on syntax errors.
*/
SearchCriteria(const std::string & type = "all",
const std::string & logicalOperator = "and")
throw(std::invalid_argument)
: limit(0), offset(0)
{
setType(type);
setLogicalOperator(logicalOperator);
}
/**
* Construct a SearchCriteria object with a single condition.
*
* @param type one of "audioClip", "playlist" or "all"
* @param key the metadata field to search in
* @param comparisonOperator one of "=", "partial", "prefix",
* "<", "<=", ">" or ">="
* @param value the value to compare to
* @exception std::invalid_argument on syntax errors.
*/
SearchCriteria(const std::string & type,
const std::string & key,
const std::string & comparisonOperator,
const std::string & value)
throw(std::invalid_argument);
/**
* Construct a SearchCriteria object from an XmlRpcValue.
*
* @param xmlRpcValue an XmlRpcValue struct, containing
* the search criteria.
* @exception std::invalid_argument on syntax errors.
*/
SearchCriteria(const XmlRpc::XmlRpcValue & xmlRpcValue)
throw(std::invalid_argument);
/**
* Set the type field.
*
* @param type one of "audioClip", "playlist" or "all"
* @exception std::invalid_argument on syntax errors.
*/
void
setType(const std::string & type)
throw(std::invalid_argument)
{
std::string lowerCaseType = lowerCase(type);
if (lowerCaseType == "audioclip"
|| lowerCaseType == "playlist"
|| lowerCaseType == "all") {
this->type = lowerCaseType;
} else {
throw std::invalid_argument("bad type argument");
}
}
/**
* Set the logical operator field.
*
* @param logicalOperator either "and" or "or"
* @exception std::invalid_argument on syntax errors.
*/
void
setLogicalOperator(const std::string & logicalOperator)
throw(std::invalid_argument)
{
std::string lowerCaseOp = lowerCase(logicalOperator);
if (lowerCaseOp == "and" || lowerCaseOp == "or") {
this->logicalOperator = lowerCaseOp;
} else {
throw std::invalid_argument("bad logical operator argument");
}
}
/**
* Add a search condition.
*
* @param key the metadata field to search in
* @param comparisonOperator one of "=", "partial", "prefix",
* "<", "<=", ">" or ">="
* @param value the value to compare to
* @exception std::invalid_argument on syntax errors.
*/
void
addCondition(const std::string & key,
const std::string & comparisonOperator,
const std::string & value)
throw(std::invalid_argument);
/**
* Add a search condition specifying the mtime (modified-at time).
*
* @param comparisonOperator one of "=", "partial", "prefix",
* "<", "<=", ">" or ">="
* @param value the value of the mtime to compare to
* @exception std::invalid_argument on syntax errors.
*/
void
addMtimeCondition(const std::string & comparisonOperator,
Ptr<const ptime>::Ref value)
throw(std::invalid_argument);
/**
* Add a search condition.
*
* @param condition the search condition to add
* @exception std::invalid_argument on syntax errors.
*/
void
addCondition(const Ptr<SearchConditionType>::Ref condition)
throw(std::invalid_argument)
{
addCondition(condition->key,
condition->comparisonOperator,
condition->value);
}
/**
* Get the limit field.
*
* @return the maximum number of search results to be returned
*/
int
getLimit() throw()
{
return limit;
}
/**
* Set the limit field.
*
* @param limit the maximum number of search results to be returned
* @exception std::invalid_argument on syntax errors.
*/
void
setLimit(const int limit)
throw(std::invalid_argument)
{
if (limit >= 0) {
this->limit = limit;
} else {
throw std::invalid_argument("bad argument: less than zero");
}
}
/**
* Get the offset field.
*
* @return the index of the first matching condition
* to be returned (first = 0)
*/
int
getOffset() throw()
{
return offset;
}
/**
* Set the offset field.
*
* @param offset the index of the first matching condition
* to be returned (first = 0)
* @exception std::invalid_argument on syntax errors.
*/
void
setOffset(const int offset)
throw(std::invalid_argument)
{
if (offset >= 0) {
this->offset = offset;
} else {
throw std::invalid_argument("bad argument: less than zero");
}
}
/**
* Convert to an XmlRpc::XmlRpcValue.
*/
operator XmlRpc::XmlRpcValue() const throw();
/**
* Check two SearchCriteria objects for equality.
*/
bool
operator ==(const SearchCriteria & other) const throw();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_SearchCriteria_h

View File

@ -1,151 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_SessionId_h
#define LiveSupport_Core_SessionId_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <string>
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A class representing session identifiers.
*/
class SessionId
{
private:
/**
* The value of the session ID.
*/
std::string id;
/**
* Default constructor.
*/
SessionId(void) throw ()
{
}
public:
/**
* The type for the value the session id is represented in.
*/
typedef std::string IdType;
/**
* Constructor to create a SessionId with a specific value.
*
* @param id the value of the created id object.
*/
SessionId(const IdType id) throw ()
{
this->id = id;
}
/**
* Compare this is with an other one.
*
* @param otherId the other unqiue id to compare to.
* @return true if this another sessionId have the same value,
* false otherwise.
*/
bool
operator==(const SessionId & otherId) const
throw ()
{
return this->id == otherId.id;
}
/**
* Compare this is with an other one.
*
* @param otherId the other unqiue id to compare to.
* @return true if this another sessionId do not have the same value,
* false otherwise.
*/
bool
operator!=(const SessionId & otherId) const
throw ()
{
return this->id != otherId.id;
}
/**
* Compare this id with an other one.
*
* @param otherId the other session id to compare to.
* @return true if this id is smaller than the other one,
* false otherwise.
*/
bool
operator<(const SessionId & otherId) const
throw ()
{
return this->id < otherId.id;
}
/**
* Return the (string) value of this session ID.
*
* @return the value of this id.
*/
const IdType
getId(void) const throw ()
{
return id;
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_SessionId_h

View File

@ -1,173 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_Thread_h
#define LiveSupport_Core_Thread_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <pthread.h>
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/RunnableInterface.h"
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A generic thread executor class.
*
* @see RunnableInterface
*/
class Thread
{
private:
/**
* The POSIX thread for this object.
*/
pthread_t thread;
/**
* The Runnable object, that constitutes the main running body
* of the thread.
*/
Ptr<RunnableInterface>::Ref runnable;
/**
* Default constructor.
*/
Thread(void) throw ()
{
}
/**
* The thread function for the POSIX thread interface.
*
* @param thread pointer to this thread instance.
* @return always 0
*/
static void *
posixThreadFunction(void * thread) throw ();
public:
/**
* Constructor.
*
* @param runnable the Runnable object making up the execution
* part of the thread.
*/
Thread(Ptr<RunnableInterface>::Ref runnable) throw ();
/**
* A virtual destructor, as this class has virtual functions.
*/
virtual
~Thread(void) throw ()
{
}
/**
* Start the execution of the thread.
* This funcion will create a new thread and starts executing
* it by the run() function of the Runnable object. Start will
* return immediately.
*
* @exception std::exception if the thread could not be started.
*/
virtual void
start(void) throw (std::exception);
/**
* Signal the thread to stop, gracefully.
* This is just a call to signal the execution to stop, eventually.
* The thread still has to be joined after calling stop().
*
* @see #join
*/
virtual void
stop(void) throw ()
{
runnable->stop();
}
/**
* Force the current thread to relinquish use of its processor.
* So that other threads get a chance to run.
*/
static void
yield(void) throw ()
{
pthread_yield();
}
/**
* Join the thread.
* Wait for the thread to terminate and free up all its resources.
*/
virtual void
join(void) throw ();
/**
* Send a signal to the runnable object inside this thread.
*
* @param userData user-specific parameter for the signal.
*/
virtual void
signal(int userData) throw ()
{
runnable->signal(userData);
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_Thread_h

View File

@ -1,280 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_TimeConversion_h
#define LiveSupport_Core_TimeConversion_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#else
#error need sys/time.h
#endif
#include <boost/date_time/posix_time/posix_time.hpp>
#include "LiveSupport/Core/Ptr.h"
namespace LiveSupport {
namespace Core {
using namespace boost::posix_time;
using namespace LiveSupport;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A helper object holding static time conversion functions.
*
* TODO: clean this up, and use the boost conversion functions, instead of
* converting stuff manually
* (see http://boost.org/doc/html/date_time/posix_time.html).
*
*/
class TimeConversion
{
private:
/**
* Parse a time string.
*
* It cuts off the portion between the end of the string and the last
* occurrence of the separator character. For example, if called with
* the parameters "00:01:02" and ':', the function returns "02" and
* truncates the original string to "00:01".
*
* If the separator character is not found in <code>timeString</code>,
* a copy of the whole <code>timeString</code> is returned, and the
* original <code>timeString</code> is changed to the empty string.
*
* @param timeString the input argument; on return, the rest of the
* string, after the return value cut off
* @param separator a separator character, usually ':'
* @return the part of the string which was cut off
*/
static Ptr<std::string>::Ref
nextNumberFromEnd(Ptr<std::string>::Ref timeString,
char separator) throw ();
/**
* Parse a decimal string.
*
* It cuts off the portion between the end of the string and the last
* occurrence of the separator character. For example, if called with
* the parameters "1.23" and '.', the function returns "23" and
* truncates the original string to "1".
*
* If the separator character is not found in <code>timeString</code>,
* then an empty string is returned, and the
* original <code>timeString</code> remains unchanged.
*
* @param decimalString the input argument; on return, the rest of
* the string, after the return value cut off
* @param separator a separator character, usually '.'
* @return the part of the string which was cut off
*/
static Ptr<std::string>::Ref
nextNumberFromStart(Ptr<std::string>::Ref decimalString,
char separator) throw ();
/**
* The default constructor.
*/
TimeConversion(void) throw ()
{
}
public:
/**
* Convert a struct timeval to a boost::posix_time::ptime,
* with microsecond precision.
*
* @param timeval the struct timeval to convert.
* @return a boost::posix_time::ptime, holding the same time.
* @exception std::out_of_range if timeval represents a time that
* can not be handled by ptime
*/
static Ptr<ptime>::Ref
timevalToPtime(const struct timeval *timeval)
throw (std::out_of_range);
/**
* Convert a struct tm to a boost::posix_time::ptime,
* with second precision.
*
* @param time the struct tm to convert.
* @return a boost::posix_time::ptime, holding the same time.
* @exception std::out_of_range if time represents a time that
* can not be handled by ptime
*/
static Ptr<ptime>::Ref
tmToPtime(const struct tm *time)
throw (std::out_of_range);
/**
* Convert a boost::posix_time::ptime to a struct tm,
* with second precision.
*
* @param convertFrom the boost::posix_time::ptime to convert.
* @param convertTo holds the result of the conversion
* @return a struct tm, holding the same time.
*/
static void
ptimeToTm(Ptr<const ptime>::Ref convertFrom, struct tm & convertTo)
throw ();
/**
* Return the current time, with microsecond precision.
*
* @return the current time, with microsecond precision.
*/
static Ptr<ptime>::Ref
now(void) throw ();
/**
* Return the current time, with microsecond precision, as a string.
*
* @return the current time, with microsecond precision.
*/
static Ptr<std::string>::Ref
nowString(void) throw ();
/**
* Sleep for the specified time duration, with microsecond precision.
*
* @param duration sleep for this duration.
*/
static void
sleep(Ptr<const time_duration>::Ref duration) throw ();
/**
* Convert a time_duration to a format used in SMILs.
* This means number of seconds, rounded to the nearest millisecond.
* For example: "1234.567s", "0.890s", or "3.000s".
*
* @param duration the time duration to convert.
*/
static Ptr<std::string>::Ref
timeDurationToSmilString(Ptr<const time_duration>::Ref duration)
throw ();
/**
* Convert a time_duration to a rounded format used on the screen.
*
* This means a hh:mm:ss format, rounded to the nearest second.
*
* For example: "01:02:03" or "00:10:00". The hours field can be
* more than two characters wide, e.g.: "8765:48:45".
*
* @param duration the time duration to convert.
* @return the time duration in string format
*/
static Ptr<std::string>::Ref
timeDurationToHhMmSsString(Ptr<const time_duration>::Ref duration)
throw ();
/**
* Convert a time_duration to a format used for fade info.
*
* This means a hh:mm:ss.ffffff format, with hours, minutes and
* fractions left off when zero.
*
* For example: 01:02:03.004, 1:02 (meaning 1m 2s), 3 (meaning 3s),
* 0.002 (meaning 2ms). Zero is represented as 0.
*
* @param duration the time duration to convert.
* @return the time duration in string format
*/
static Ptr<std::string>::Ref
timeDurationToShortString(Ptr<const time_duration>::Ref duration)
throw ();
/**
* Parse a string to a time_duration.
* Similar to boost::posix_time::duration_from_string(), only
* not broken quite as badly.
*
* Parsing is right-to-left, starting with seconds: for example,
* 5 means 5 seconds; 01:02.03 means 1m 2.03s; 1:2:3 means 1h 2m 3s.
*
* If the time format is invalid, no exception is thrown, but the
* result is undefined (usually 00:00:00).
* TODO: fix this, by adding a format check
*
* @param durationString the duration as string
* @return the duration as a time_duration
*/
static Ptr<time_duration>::Ref
parseTimeDuration(Ptr<const std::string>::Ref durationString)
throw ();
/**
* Get the number of digits used for fractional seconds
* in time durations.
* @return the constant 6, for microsecond precision.
*/
static int
getNumberOfDigitsPrecision(void) throw ();
/**
* Round the time duration to the nearest second.
*
* @param duration the time to be rounded; it will not be
* modified.
* @return the rounded value.
*/
static Ptr<time_duration>::Ref
roundToNearestSecond(Ptr<const time_duration>::Ref duration)
throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_TimeConversion_h

View File

@ -1,246 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_UniqueId_h
#define LiveSupport_Core_UniqueId_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include "LiveSupport/Core/Ptr.h"
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A class representing globally unique identifiers.
*/
class UniqueId
{
public:
/**
* The type for the numeric value the unique id is represented in.
* This is set to 'long long int', i.e., 64-bit signed integers.
* TODO: change this into something not quite as non-portable.
*/
typedef long long int IdType;
private:
/**
* The value of the id.
*/
IdType id;
/**
* A string representation of the id, in hexadecimal notation.
*/
std::string idAsString;
/**
* Default constructor.
*/
UniqueId(void) throw ()
{
}
public:
/**
* Constructor to create a UniqueId with a specific integer value.
* The argument is expected to be between 0 and 2^31-1 (inclusive).
*
* @param id the numeric value of the created id object.
*/
UniqueId(const IdType id) throw ()
{
this->id = id;
std::stringstream idWriter;
idWriter << std::hex << std::setw(16) << std::setfill('0') << id;
this->idAsString = idWriter.str();
}
/**
* Constructor to create a UniqueId with a specific string value.
* If the argument is not a valid hexadecimal number between 0 and
* 2^31-1 (inclusive), the integer value of the UniqueId will be
* bogus.
*
* @param idAsString the string value of the created id object,
* in hexadecimal notation.
*/
UniqueId(const std::string idAsString) throw ()
{
this->idAsString = idAsString;
// TODO: add error checking
std::stringstream idReader(idAsString);
idReader >> std::hex >> this->id;
}
/**
* Create a UniqueId from a numeric value, which is a string
* representation of the id, in base 10.
* If the argument is not a valid decimal number between 0 and
* 2^31-1 (inclusive), the value of the UniqueId will be
* bogus.
*
* @param idStr the id in base 10, in string from.
* @return a new UniqueId with the specified ID value.
*/
static Ptr<UniqueId>::Ref
fromDecimalString(const std::string idStr) throw ()
{
IdType id;
// TODO: error checking
std::stringstream idReader(idStr);
idReader >> id;
Ptr<UniqueId>::Ref uid(new UniqueId(id));
return uid;
}
/**
* Return the UniqueId as a string in base 10.
*
* @return a new string containing the value of the UniqueId.
*/
Ptr<std::string>::Ref
toDecimalString(void) const throw ()
{
std::stringstream idWriter;
idWriter << std::dec << id;
Ptr<std::string>::Ref idString(new std::string(
idWriter.str() ));
return idString;
}
/**
* Compare this is with an other one.
*
* @param otherId the other unqiue id to compare to.
* @return true if this an otherId have the same ID value,
* false otherwise.
*/
bool
operator==(const UniqueId & otherId) const throw ()
{
return this->id == otherId.id;
}
/**
* Compare this is with an other one.
*
* @param otherId the other unqiue id to compare to.
* @return true if this an otherId do not have the same ID value,
* false otherwise.
*/
bool
operator!=(const UniqueId & otherId) const throw ()
{
return this->id != otherId.id;
}
/**
* Compare this id with an other one.
*
* @param otherId the other unique id to compare to.
* @return true if this id is smaller than the other one,
* false otherwise.
*/
bool
operator<(const UniqueId & otherId) const throw ()
{
return this->id < otherId.id;
}
/**
* Generate a globally unique id. This is used for testing.
* In real life, unique IDs are generated by the storage server.
*/
static Ptr<UniqueId>::Ref
generateId(void) throw ();
/**
* Return the numeric value of this globally unique id.
*
* @return the numeric value of this id.
*/
const IdType
getId(void) const throw ()
{
return id;
}
/**
* Return the numeric value of this globally unique id
* (alternative syntax).
*
* @return the numeric value of this id.
*/
operator IdType() const throw ()
{
return id;
}
/**
* Return the string value of this globally unique id.
*
* @return the string value of this id.
*/
operator std::string() const throw ()
{
return idAsString;
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_UniqueId_h

View File

@ -1,312 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
This code is based upon the Leach working draft for UUIDs,
http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt
and the sample code therein.
The original copyright message of the sample code is the following:
** Copyright (c) 1990- 1993, 1996 Open Software Foundation, Inc.
** Copyright (c) 1989 by Hewlett-Packard Company, Palo Alto, Ca. &
** Digital Equipment Corporation, Maynard, Mass.
** Copyright (c) 1998 Microsoft.
** To anyone who acknowledges that this file is provided "AS IS"
** without any express or implied warranty: permission to use, copy,
** modify, and distribute this file for any purpose is hereby
** granted without fee, provided that the above copyright notices and
** this notice appears in all source code copies, and that none of
** the names of Open Software Foundation, Inc., Hewlett-Packard
** Company, or Digital Equipment Corporation be used in advertising
** or publicity pertaining to distribution of the software without
** specific, written prior permission. Neither Open Software
** Foundation, Inc., Hewlett-Packard Company, Microsoft, nor Digital Equipment
** Corporation makes any representations about the suitability of
** this software for any purpose.
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_Uuid_h
#define LiveSupport_Core_Uuid_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_STDINT_H
#include <stdint.h>
#else
#error need stdint.h
#endif
#include <string>
#include "LiveSupport/Core/Ptr.h"
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A class representing globally unique identifiers.
* This implementation is based on the Leach UUID/GUID draft:
* http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt
*
* @see http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt
*/
class Uuid
{
private:
/**
* The raw time type
*/
typedef uint64_t UuidTime;
/**
* Structure holding a 6-byte system node id.
*/
typedef struct {
char nodeId[6];
} UuidNode;
/**
* The value of the id.
*/
long long int id;
/**
* A string representation of the id, in hexadecimal notation.
*/
std::string idAsString;
/**
* The low part of time.
*/
uint32_t timeLow;
/**
* The middle part of time.
*/
uint16_t timeMid;
/**
* The high part of time, with version included.
*/
uint16_t timeHiAndVersion;
/**
* Clock sequence number high and reserved parts.
*/
uint8_t clockSeqHiAndReserved;
/**
* Clock sequenc number, low part.
*/
uint8_t clockSeqLow;
/**
* The 6 byte system node id.
*/
uint8_t node[6];
/**
* Default constructor.
*/
Uuid(void) throw ()
{
}
/**
* Compare two UUIDs
*
* @param id1 one id to compare
* @param id2 the other id to compare
* @return true if they are equal, false otherwise
*/
static bool
compare(const Uuid & id1,
const Uuid & id2) throw ();
/**
* Return the current time, but always return a different value,
* even if the system clock granularity is not fine enough.
*
* @param timestamp an out parameter for the current time.
*/
static void
getCurrentTime(UuidTime * timestamp) throw ();
/**
* Try to generate a truely random number (which is not possible,
* of course).
*
* @return a random number
*/
static uint16_t
trueRandom(void) throw ();
/**
* Read the last saved state of the UUID generator from
* non-volatile storage.
*
* @param clockSeq out parameter for the clock sequence
* @param timestamp out parameter for the timestamp
* @param node out parameter for the system node id
*/
int
readState(uint16_t * clockSeq,
UuidTime * timestamp,
UuidNode * node) throw ();
/**
* Write the last saved state of the UUID generator to
* non-volatile storage.
*
* @param clockSeq the clock sequence
* @param timestamp the timestamp
* @param node the system node id
*/
void
writeState(uint16_t clockSeq,
UuidTime timestamp,
UuidNode node) throw ();
/**
* Generate a type 1 UUID.
* This function will fill out the object's internal attributes
* for it to become a proper UUID.
*
* For UUID types, see
* http://www.webdav.org/specs/draft-leach-uuids-guids-01.txt
*
* @param clockSeq the clock sequence
* @param timestamp the time stamp
* @param node the system node id
*/
void
format(uint16_t clockSeq,
UuidTime timestamp,
UuidNode node) throw ();
/**
* Get the system time in the UUID UTC base time,
* which is October 15, 1582.
*
* @param uuidTime an out parameter for the time.
*/
static void
getSystemTime(UuidTime * uuidTime) throw ();
/**
* Return the IEEE node id.
*
* @param node an out parameter for the node id.
*/
static void
getIeeeNodeIdentifier(UuidNode * node) throw ();
/**
* Create a string representation of the UUID.
* Store the result in the idAsString attribute.
*/
void
representAsString(void) throw ();
public:
/**
* Generate a globally unique id. This is used for testing.
* In real life, unique IDs are generated by the storage server.
*/
static Ptr<Uuid>::Ref
generateId(void) throw ();
/**
* Compare this is with an other one.
*
* @param otherId the other unqiue id to compare to.
* @return true if this an otherId have the same ID value,
* false otherwise.
*/
bool
operator==(const Uuid & otherId) const throw ()
{
return compare(*this, otherId);
}
/**
* Compare this is with an other one.
*
* @param otherId the other unqiue id to compare to.
* @return true if this an otherId do not have the same ID value,
* false otherwise.
*/
bool
operator!=(const Uuid & otherId) const throw ()
{
return !compare(*this, otherId);
}
/**
* Return the string value of this globally unique id.
*
* @return the string value of this id.
*/
operator std::string() const throw ()
{
return idAsString;
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
inline std::ostream &
operator<< (std::ostream & os,
const Uuid & id)
{
os << (std::string) id;
return os;
}
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_Uuid_h

View File

@ -1,113 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_XmlRpcCommunicationException_h
#define LiveSupport_Core_XmlRpcCommunicationException_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include "LiveSupport/Core/XmlRpcException.h"
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Exception signaling an XML-RPC problem: could not find the XML-RPC server,
* the server responded 'no such method', or the method response could not be
* parsed.
*/
class XmlRpcCommunicationException : public XmlRpcException
{
public:
/**
* Constructor based on a string.
*
* @param msg the message of the exception.
*/
XmlRpcCommunicationException(const std::string &msg) throw ()
: XmlRpcException(msg)
{
}
/**
* Constructor based on a parent exception.
*
* @param parent the parent exception to this one.
*/
XmlRpcCommunicationException(const std::exception & parent)
throw ()
: XmlRpcException(parent)
{
}
/**
* Constructor based on a message ant a parent exception.
*
* @param msg the message of the exception.
* @param parent the parent exception.
*/
XmlRpcCommunicationException(const std::string & msg,
const std::exception & parent)
throw ()
: XmlRpcException(msg, parent)
{
}
/**
* Virtual destructor.
*/
~XmlRpcCommunicationException(void) throw ()
{
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_XmlRpcCommunicationException_h

View File

@ -1,153 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_XmlRpcException_h
#define LiveSupport_Core_XmlRpcException_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <stdexcept>
#include "LiveSupport/Core/Ptr.h"
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Common parent of exception classes for XML-RPC related problems.
*/
class XmlRpcException : public std::exception
{
private:
/**
* The message of the exception.
*/
Ptr<std::string>::Ref message;
/**
* A possible embedded exception.
*/
const std::exception & parent;
public:
/**
* Constructor based on a string.
*
* @param msg the message of the exception.
*/
XmlRpcException(const std::string &msg) throw ()
: parent(*this)
{
message.reset(new std::string(msg));
}
/**
* Constructor based on a parent exception.
*
* @param parent the parent exception to this one.
*/
XmlRpcException(const std::exception & parent) throw ()
: parent(parent)
{
message.reset(new std::string(parent.what()));
}
/**
* Constructor based on a message ant a parent exception.
*
* @param msg the message of the exception.
* @param parent the parent exception.
*/
XmlRpcException(const std::string & msg,
const std::exception & parent) throw ();
/**
* Virtual destructor.
*/
~XmlRpcException(void) throw ()
{
}
/**
* Set the message of the exception.
*
* @param msg the new message of the exception.
*/
void
setMessage(const std::string & msg) throw ()
{
message.reset(new std::string(msg));
}
/**
* Get the message of the exception.
*
* @return the message of the exception.
*/
virtual const char *
what(void) const throw ()
{
return message->c_str();
}
/**
* Get the parent exception.
*
* @return the parent exception, which may be null.
*/
virtual const std::exception *
getParent(void) const throw ()
{
return &parent == this ? 0 : &parent;
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_XmlRpcException_h

View File

@ -1,112 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_XmlRpcIOException_h
#define LiveSupport_Core_XmlRpcIOException_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include "LiveSupport/Core/XmlRpcException.h"
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Exception signaling an XML-RPC problem: there was a problem with a local
* I/O operation.
*/
class XmlRpcIOException : public XmlRpcException
{
public:
/**
* Constructor based on a string.
*
* @param msg the message of the exception.
*/
XmlRpcIOException(const std::string &msg) throw ()
: XmlRpcException(msg)
{
}
/**
* Constructor based on a parent exception.
*
* @param parent the parent exception to this one.
*/
XmlRpcIOException(const std::exception & parent)
throw ()
: XmlRpcException(parent)
{
}
/**
* Constructor based on a message ant a parent exception.
*
* @param msg the message of the exception.
* @param parent the parent exception.
*/
XmlRpcIOException(const std::string & msg,
const std::exception & parent)
throw ()
: XmlRpcException(msg, parent)
{
}
/**
* Virtual destructor.
*/
~XmlRpcIOException(void) throw ()
{
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_XmlRpcIOException_h

View File

@ -1,113 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_XmlRpcInvalidArgumentException_h
#define LiveSupport_Core_XmlRpcInvalidArgumentException_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include "LiveSupport/Core/XmlRpcException.h"
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Exception signaling an XML-RPC problem: invalid argument (functions which
* throw an XmlRpcException throw this when they would normally throw a
* std::invalid_argument).
*/
class XmlRpcInvalidArgumentException : public XmlRpcException
{
public:
/**
* Constructor based on a string.
*
* @param msg the message of the exception.
*/
XmlRpcInvalidArgumentException(const std::string &msg) throw ()
: XmlRpcException(msg)
{
}
/**
* Constructor based on a parent exception.
*
* @param parent the parent exception to this one.
*/
XmlRpcInvalidArgumentException(const std::exception & parent)
throw ()
: XmlRpcException(parent)
{
}
/**
* Constructor based on a message ant a parent exception.
*
* @param msg the message of the exception.
* @param parent the parent exception.
*/
XmlRpcInvalidArgumentException(const std::string & msg,
const std::exception & parent)
throw ()
: XmlRpcException(msg, parent)
{
}
/**
* Virtual destructor.
*/
~XmlRpcInvalidArgumentException(void) throw ()
{
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_XmlRpcInvalidArgumentException_h

View File

@ -1,112 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_XmlRpcInvalidDataException_h
#define LiveSupport_Core_XmlRpcInvalidDataException_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include "LiveSupport/Core/XmlRpcException.h"
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Exception signaling an XML-RPC problem: invalid data returned by the method.
* This could be a malformed AudioClip or Playlist, for example.
*/
class XmlRpcInvalidDataException : public XmlRpcException
{
public:
/**
* Constructor based on a string.
*
* @param msg the message of the exception.
*/
XmlRpcInvalidDataException(const std::string &msg) throw ()
: XmlRpcException(msg)
{
}
/**
* Constructor based on a parent exception.
*
* @param parent the parent exception to this one.
*/
XmlRpcInvalidDataException(const std::exception & parent)
throw ()
: XmlRpcException(parent)
{
}
/**
* Constructor based on a message ant a parent exception.
*
* @param msg the message of the exception.
* @param parent the parent exception.
*/
XmlRpcInvalidDataException(const std::string & msg,
const std::exception & parent)
throw ()
: XmlRpcException(msg, parent)
{
}
/**
* Virtual destructor.
*/
~XmlRpcInvalidDataException(void) throw ()
{
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_XmlRpcInvalidDataException_h

View File

@ -1,166 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_XmlRpcMethodFaultException_h
#define LiveSupport_Core_XmlRpcMethodFaultException_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <sstream>
#include "LiveSupport/Core/XmlRpcException.h"
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
namespace {
/*------------------------------------------------------------------------------
* The default fault code, the value when no fault code is set.
*----------------------------------------------------------------------------*/
const int defaultFaultCode = -1;
}
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Exception signaling an XML-RPC problem: the XML-RPC method returned a fault
* response.
*/
class XmlRpcMethodFaultException : public XmlRpcException
{
private:
/**
* The XML-RPC faultCode of the exception.
*/
int faultCode;
public:
/**
* Constructor based on a string.
*
* @param msg the message of the exception.
*/
XmlRpcMethodFaultException(const std::string &msg) throw ()
: XmlRpcException(msg),
faultCode(defaultFaultCode)
{
}
/**
* Constructor based on a parent exception.
*
* @param parent the parent exception to this one.
*/
XmlRpcMethodFaultException(const std::exception & parent)
throw ()
: XmlRpcException(parent),
faultCode(defaultFaultCode)
{
}
/**
* Constructor based on a message and a parent exception.
*
* @param msg the message of the exception.
* @param parent the parent exception.
*/
XmlRpcMethodFaultException(const std::string & msg,
const std::exception & parent)
throw ()
: XmlRpcException(msg, parent),
faultCode(defaultFaultCode)
{
}
/**
* Constructor based on a fault code, fault string pair.
*
* @param methodName the name of the method throwing the exception.
* @param faultCode the code of the exception.
* @param faultString the message of the exception.
*/
XmlRpcMethodFaultException(const std::string & methodName,
int faultCode,
const std::string & faultString)
throw ()
: XmlRpcException(""),
faultCode(faultCode)
{
std::stringstream msg;
msg << "XML-RPC method '"
<< methodName
<< "' returned error message:\n"
<< faultCode
<< " - "
<< faultString;
setMessage(msg.str());
}
/**
* Virtual destructor.
*/
~XmlRpcMethodFaultException(void) throw ()
{
}
/**
* Get the XML-RPC faultCode of the exception.
*
* @return the fault code, if one is set; or -1 if not.
*/
int
getFaultCode(void) const throw ()
{
return faultCode;
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_XmlRpcMethodFaultException_h

View File

@ -1,112 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_XmlRpcMethodResponseException_h
#define LiveSupport_Core_XmlRpcMethodResponseException_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include "LiveSupport/Core/XmlRpcException.h"
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Exception signaling an XML-RPC problem: the XML-RPC method call completed
* normally, but the response received has incorrect syntax.
*/
class XmlRpcMethodResponseException : public XmlRpcException
{
public:
/**
* Constructor based on a string.
*
* @param msg the message of the exception.
*/
XmlRpcMethodResponseException(const std::string &msg) throw ()
: XmlRpcException(msg)
{
}
/**
* Constructor based on a parent exception.
*
* @param parent the parent exception to this one.
*/
XmlRpcMethodResponseException(const std::exception & parent)
throw ()
: XmlRpcException(parent)
{
}
/**
* Constructor based on a message ant a parent exception.
*
* @param msg the message of the exception.
* @param parent the parent exception.
*/
XmlRpcMethodResponseException(const std::string & msg,
const std::exception & parent)
throw ()
: XmlRpcException(msg, parent)
{
}
/**
* Virtual destructor.
*/
~XmlRpcMethodResponseException(void) throw ()
{
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_XmlRpcMethodResponseException_h

View File

@ -1,746 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_XmlRpcTools_h
#define LiveSupport_Core_XmlRpcTools_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <stdexcept>
#include <string>
#include <vector>
#include <XmlRpcValue.h>
#include <XmlRpcException.h>
#include <boost/date_time/posix_time/posix_time.hpp>
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/SessionId.h"
#include "LiveSupport/Core/Playlist.h"
#include "LiveSupport/Core/ScheduleEntry.h"
#include "LiveSupport/Core/PlayLogEntry.h"
#include "LiveSupport/Core/SearchCriteria.h"
#include "LiveSupport/Core/AsyncState.h"
namespace LiveSupport {
namespace Core {
using namespace LiveSupport;
using namespace LiveSupport::Core;
using namespace LiveSupport::StorageClient;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A toolbox for converting between inner representations of classes
* and XmlRpcValues. Used by almost all XmlRpcServerMethod subclasses
* in the Scheduler.
*/
class XmlRpcTools
{
private:
/**
* Convert a boost::posix_time::ptime to an XmlRpcValue
*
* @param ptime the ptime to convert
* @param xmlRpcValue the output parameter holding the value of
* the conversion.
*/
static void
ptimeToXmlRpcValue(Ptr<const ptime>::Ref ptime,
XmlRpc::XmlRpcValue & xmlRpcValue)
throw ();
/**
* Convert a PlayLogEntry to an XmlRpcValue
*
* @param playLogEntry the PlayLogEntry to convert.
* @param xmlRpcValue the output parameter holding the result of
* the conversion.
*/
static void
playLogEntryToXmlRpcValue(Ptr<const PlayLogEntry>::Ref playLogEntry,
XmlRpc::XmlRpcValue & returnValue)
throw ();
public:
/**
* Extract the schedule entry id from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return a UniqueId that was found in the XML-RPC parameter.
* @exception std::invalid_argument if there was no UniqueId
* in xmlRpcValue
*/
static Ptr<UniqueId>::Ref
extractScheduleEntryId(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Extract the generic 'id' from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return a UniqueId that was found in the XML-RPC parameter.
* @exception std::invalid_argument if there was no playlistId
* member in xmlRpcValue
*/
static Ptr<UniqueId>::Ref
extractId(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Extract the playlist ID from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return a UniqueId that was found in the XML-RPC parameter.
* @exception std::invalid_argument if there was no playlistId
* member in xmlRpcValue
*/
static Ptr<UniqueId>::Ref
extractPlaylistId(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Extract the playlist element ID from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return a UniqueId that was found in the XML-RPC parameter.
* @exception std::invalid_argument if there was no playlistElementId
* member in xmlRpcValue
*/
static Ptr<UniqueId>::Ref
extractPlaylistElementId(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Extract the audio clip id from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return a UniqueId that was found in the XML-RPC parameter.
* @exception std::invalid_argument if there was no audioClipId
* member in xmlRpcValue
*/
static Ptr<UniqueId>::Ref
extractAudioClipId(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Extract the relative offset from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return a time_duration that was found in the XML-RPC parameter.
* @exception std::invalid_argument if there was no relativeOffset
* member in xmlRpcValue
*/
static Ptr<time_duration>::Ref
extractRelativeOffset(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Extract the relative offset from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return a time_duration that was found in the XML-RPC parameter.
* @exception std::invalid_argument if there was no relativeOffset
* member in xmlRpcValue
*/
static Ptr<time_duration>::Ref
extractClipStart(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Extract the relative offset from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return a time_duration that was found in the XML-RPC parameter.
* @exception std::invalid_argument if there was no relativeOffset
* member in xmlRpcValue
*/
static Ptr<time_duration>::Ref
extractClipEnd(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Extract the relative offset from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return a time_duration that was found in the XML-RPC parameter.
* @exception std::invalid_argument if there was no relativeOffset
* member in xmlRpcValue
*/
static Ptr<time_duration>::Ref
extractClipLength(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Convert a Playlist to an XmlRpcValue
*
* @param playlist the Playlist to convert.
* @param xmlRpcValue the output parameter holding the result of
* the conversion.
*/
static void
playlistToXmlRpcValue(Ptr<const Playlist>::Ref playlist,
XmlRpc::XmlRpcValue & xmlRpcValue)
throw ();
/**
* Convert a vector of Playlists to an XML-RPC return value.
*
* @param playlistVector a list of Playlists.
* @param returnValue the output parameter holding an XML-RPC
* representation of the list of Playlists.
*/
static void
playlistVectorToXmlRpcValue(
const Ptr<std::vector<Ptr<Playlist>::Ref> >::Ref playlistVector,
XmlRpc::XmlRpcValue & returnValue)
throw ();
/**
* Convert an AudioClip to an XmlRpcValue
*
* @param audioClip the AudioClip to convert.
* @param xmlRpcValue the output parameter holding the result of
* the conversion.
*/
static void
audioClipToXmlRpcValue(Ptr<const AudioClip>::Ref audioClip,
XmlRpc::XmlRpcValue & xmlRpcValue)
throw ();
/**
* Convert a vector of AudioClips to an XML-RPC return value.
*
* @param audioClipVector a list of AudioClips.
* @param returnValue the output parameter holding an XML-RPC
* representation of the list of AudioClips.
*/
static void
audioClipVectorToXmlRpcValue(
const Ptr<std::vector<Ptr<AudioClip>::Ref> >::Ref audioClipVector,
XmlRpc::XmlRpcValue & returnValue)
throw ();
/**
* Extract a Playlist from an XML-RPC parameter.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return the extracted Playlist.
*/
static Ptr<Playlist>::Ref
extractPlaylist(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Extract a vector of Playlists from an XML-RPC parameter.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return a list of Playlists.
*/
static Ptr<std::vector<Ptr<Playlist>::Ref> >::Ref
extractPlaylistVector(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Extract an AudioClip from an XML-RPC parameter.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return the extracted AudioClip.
*/
static Ptr<AudioClip>::Ref
extractAudioClip(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Extract a vector of AudioClips from an XML-RPC parameter.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return a list of AudioClips.
*/
static Ptr<std::vector<Ptr<AudioClip>::Ref> >::Ref
extractAudioClipVector(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Convert an error code, message pair to an XML-RPC fault response.
* This is done by throwing an XmlRpc::XmlRpcException. The client
* receives a fault response, and the return value is set to a
* { faultCode, faultString } structure holding the error code and
* message.
*
* @param errorCode the numerical code of the error.
* @param errorMessage a short English description of the error.
* @param xmlRpcValue remains here from an earlier version
* TODO: remove this later.
*/
static void
markError(int errorCode, const std::string errorMessage,
XmlRpc::XmlRpcValue & xmlRpcValue)
throw (XmlRpc::XmlRpcException);
/**
* Convert the valid status of a playlist to an XmlRpcValue
*
* @param validStatus true if the playlist is valid, false otherwise.
* @param xmlRpcValue the output parameter holding the result of
* the conversion.
*/
static void
validStatusToXmlRpcValue(bool validStatus,
XmlRpc::XmlRpcValue & xmlRpcValue)
throw ();
/**
* Extract the 'from' time parameter from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return the time value for the 'from' parameter
* @exception std::invalid_argument if there was no from parameter
* in xmlRpcValue
*/
static Ptr<boost::posix_time::ptime>::Ref
extractFromTime(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Extract the 'to' parameter from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return the time value for the 'to' parameter
* @exception std::invalid_argument if there was no to parameter
* in xmlRpcValue
*/
static Ptr<boost::posix_time::ptime>::Ref
extractToTime(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Extract the 'start' parameter from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return the time value for the 'start' parameter
* @exception std::invalid_argument if there was no to parameter
* in xmlRpcValue
*/
static Ptr<boost::posix_time::ptime>::Ref
extractStartTime(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Extract the 'end' parameter from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return the time value for the 'end' parameter
* @exception std::invalid_argument if there was no to parameter
* in xmlRpcValue
*/
static Ptr<boost::posix_time::ptime>::Ref
extractEndTime(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Add a 'from' time value to an XmlRpcValue.
*
* @param from the 'from' time value to add.
* @param returnValue an output parameter, which has the
* 'from' time added after the function returns.
*/
static void
fromTimeToXmlRpcValue(
Ptr<const boost::posix_time::ptime>::Ref from,
XmlRpc::XmlRpcValue & returnValue)
throw ();
/**
* Add a 'to' time value to an XmlRpcValue.
*
* @param to the 'to' time value to add.
* @param returnValue an output parameter, which has the
* 'to' time added after the function returns.
*/
static void
toTimeToXmlRpcValue(
Ptr<const boost::posix_time::ptime>::Ref to,
XmlRpc::XmlRpcValue & returnValue)
throw ();
/**
* Extract the playtime from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return the playing time, as stored in the XML-RPC parameter
* @exception std::invalid_argument if there was no playtime
* in xmlRpcValue
*/
static Ptr<boost::posix_time::ptime>::Ref
extractPlayschedule(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Extract the fade in time from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return a time_duration that was found in the XML-RPC parameter.
* @exception std::invalid_argument if there was no fadeIn
* member in xmlRpcValue
*/
static Ptr<time_duration>::Ref
extractFadeIn(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Extract the fade out time from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return a time_duration that was found in the XML-RPC parameter.
* @exception std::invalid_argument if there was no fadeOut
* member in xmlRpcValue
*/
static Ptr<time_duration>::Ref
extractFadeOut(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Convert a vector of ScheduleEntries to an XML-RPC return value.
*
* @param scheduleEntries a list of ScheduleEntries.
* @param returnValue the output parameter holding an XML-RPC
* representation of the suppied schedule entires.
*/
static void
scheduleEntriesToXmlRpcValue(
Ptr<std::vector<Ptr<ScheduleEntry>::Ref> >::Ref scheduleEntries,
XmlRpc::XmlRpcValue & returnValue)
throw ();
/**
* Convert an XmlRpcValue array, holding schedule entries,
* to a vector of ScheduleEntry object references.
*
* @param xmlRpcValue the XML-RPC array holding the schedule entry
* data
* @return a vector of ScheduleEntry object references, holding
* the same data.
*/
static Ptr<std::vector<Ptr<ScheduleEntry>::Ref> >::Ref
extractScheduleEntries(XmlRpc::XmlRpcValue & xmlRpcValue)
throw ();
/**
* Convert a schedule entry ID (a UniqueId) to an XmlRpcValue
*
* @param scheduleEntryId the UniqueId to convert.
* @param returnValue the output parameter holding the result of
* the conversion.
*/
static void
scheduleEntryIdToXmlRpcValue(
Ptr<const UniqueId>::Ref scheduleEntryId,
XmlRpc::XmlRpcValue & returnValue) throw ();
/**
* Add a session id to an XmlRpcValue
*
* @param sessionId the session id to add to the XmlRpcValue
* @param returnValue an output parameter, which has the
* session id added after the function returns.
*/
static void
sessionIdToXmlRpcValue(
Ptr<const SessionId>::Ref sessionId,
XmlRpc::XmlRpcValue & returnValue) throw ();
/**
* Add a playlist ID to an XmlRpcValue
*
* @param playlistId the playlist ID to add to the XmlRpcValue
* @param returnValue an output parameter, which has the
* playlist ID added after the function returns.
*/
static void
playlistIdToXmlRpcValue(
Ptr<const UniqueId>::Ref playlistId,
XmlRpc::XmlRpcValue & returnValue) throw ();
/**
* Add an audio clip ID to an XmlRpcValue
*
* @param audioClipId the audio clip ID to add to the XmlRpcValue
* @param returnValue an output parameter, which has the
* audio clip ID added after the function returns.
*/
static void
audioClipIdToXmlRpcValue(
Ptr<const UniqueId>::Ref audioClipId,
XmlRpc::XmlRpcValue & returnValue) throw ();
/**
* Add a playlist element ID to an XmlRpcValue
*
* @param playlistElementId the playlist element ID
* to add to the XmlRpcValue
* @param returnValue an output parameter, which has the
* playlist element ID added after the function returns.
*/
static void
playlistElementIdToXmlRpcValue(
Ptr<const UniqueId>::Ref playlistElementId,
XmlRpc::XmlRpcValue & returnValue) throw ();
/**
* Add a playtime value to an XmlRpcValue.
*
* @param playtime the playtime to add to the XmlRpcValue
* @param returnValue an output parameter, which has the
* playtime added after the function returns.
*/
static void
playtimeToXmlRpcValue(
Ptr<const boost::posix_time::ptime>::Ref playtime,
XmlRpc::XmlRpcValue & returnValue)
throw ();
/**
* Convert a vector of PlayLogEntries to an XML-RPC return value.
*
* @param playLogVector a list of PlayLogEntries.
* @param returnValue the output parameter holding an XML-RPC
* representation of the list of PlayLogEntries.
*/
static void
playLogVectorToXmlRpcValue(
Ptr<const std::vector<Ptr<PlayLogEntry>::Ref> >::Ref
playLogVector,
XmlRpc::XmlRpcValue & returnValue)
throw ();
/**
* Extract the session ID from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return a SessionId that was found in the XML-RPC parameter.
* @exception std::invalid_argument if there was no sessionId
* member in xmlRpcValue
*/
static Ptr<SessionId>::Ref
extractSessionId(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Extract the login name from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return a std::string that was found in the XML-RPC parameter.
* @exception std::invalid_argument if there was no login
* member in xmlRpcValue
*/
static Ptr<std::string>::Ref
extractLoginName(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Extract the password from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return a std::string that was found in the XML-RPC parameter.
* @exception std::invalid_argument if there was no sessionId
* member in xmlRpcValue
*/
static Ptr<std::string>::Ref
extractPassword(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Extract the search criteria from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return a search criteria that was found in the XML-RPC parameter.
* @exception std::invalid_argument if there was no criteria
* member in xmlRpcValue.
*/
static Ptr<SearchCriteria>::Ref
extractSearchCriteria(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Convert a SearchCriteria to an XmlRpcValue.
*
* @param criteria the SearchCriteria to convert.
* @param returnValue the output parameter holding the result of
* the conversion.
*/
static void
searchCriteriaToXmlRpcValue(
Ptr<const SearchCriteria>::Ref criteria,
XmlRpc::XmlRpcValue & returnValue)
throw ();
/**
* Extract a token from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return a string token that was found in the XML-RPC parameter.
* @exception std::invalid_argument if there was no token
* member in xmlRpcValue.
*/
static Ptr<Glib::ustring>::Ref
extractToken(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Convert a string token to an XmlRpcValue.
*
* @param token the string token to convert.
* @param returnValue the output parameter holding the result of
* the conversion.
*/
static void
tokenToXmlRpcValue(Ptr<const Glib::ustring>::Ref token,
XmlRpc::XmlRpcValue & returnValue)
throw ();
/**
* Extract the backup status from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return an AsyncState that was found in the XML-RPC parameter.
* @exception std::invalid_argument if there was no "status"
* member in xmlRpcValue.
*/
static AsyncState
extractBackupStatus(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Convert an AsyncState returned by one
* of the backup methods to an XmlRpcValue.
*
* @param status the AsyncState to convert.
* @param returnValue the output parameter holding the result of
* the conversion.
*/
static void
backupStatusToXmlRpcValue(AsyncState status,
XmlRpc::XmlRpcValue & returnValue)
throw ();
/**
* Extract a URL string from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return a URL string that was found in the XML-RPC parameter.
* @exception std::invalid_argument if there was no "url"
* member in xmlRpcValue.
*/
static Ptr<Glib::ustring>::Ref
extractUrl(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Convert a URL string to an XmlRpcValue.
*
* @param url the URL string to convert.
* @param returnValue the output parameter holding the result of
* the conversion.
*/
static void
urlToXmlRpcValue(Ptr<const Glib::ustring>::Ref url,
XmlRpc::XmlRpcValue & returnValue)
throw ();
/**
* Extract a path string from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return a path string that was found in the XML-RPC parameter.
* @exception std::invalid_argument if there was no "path"
* member in xmlRpcValue.
*/
static Ptr<Glib::ustring>::Ref
extractPath(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Convert a path string to an XmlRpcValue.
*
* @param path the path string to convert.
* @param returnValue the output parameter holding the result of
* the conversion.
*/
static void
pathToXmlRpcValue(Ptr<const Glib::ustring>::Ref path,
XmlRpc::XmlRpcValue & returnValue)
throw ();
/**
* Extract a fault string from the XML-RPC parameters.
*
* @param xmlRpcValue the XML-RPC parameter to extract from.
* @return a fault string that was found in the XML-RPC parameter.
* @exception std::invalid_argument if there was no "faultString"
* member in xmlRpcValue.
*/
static Ptr<Glib::ustring>::Ref
extractFaultString(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument);
/**
* Convert a fault string to an XmlRpcValue.
*
* @param faultString the fault string to convert.
* @param xmlRpcValue the output parameter holding the result of
* the conversion.
*/
static void
faultStringToXmlRpcValue(Ptr<const Glib::ustring>::Ref faultString,
XmlRpc::XmlRpcValue & returnValue)
throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_XmlRpcTools_h

View File

@ -1 +0,0 @@
keep me

View File

@ -1,195 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#include "LiveSupport/Core/AsyncState.h"
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* Constant instance: init.
*----------------------------------------------------------------------------*/
const AsyncState AsyncState::initState(innerInitState);
/*------------------------------------------------------------------------------
* Constant instance: pending.
*----------------------------------------------------------------------------*/
const AsyncState AsyncState::pendingState(innerPendingState);
/*------------------------------------------------------------------------------
* Constant instance: finished.
*----------------------------------------------------------------------------*/
const AsyncState AsyncState::finishedState(innerFinishedState);
/*------------------------------------------------------------------------------
* Constant instance: closed.
*----------------------------------------------------------------------------*/
const AsyncState AsyncState::closedState(innerClosedState);
/*------------------------------------------------------------------------------
* Constant instance: failed.
*----------------------------------------------------------------------------*/
const AsyncState AsyncState::failedState(innerFailedState);
/*------------------------------------------------------------------------------
* Constant instance: invalid.
*----------------------------------------------------------------------------*/
const AsyncState AsyncState::invalidState(innerInvalidState);
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Construct from a transport string.
*----------------------------------------------------------------------------*/
AsyncState
AsyncState :: fromTransportString(const std::string & transportString)
throw ()
{
if (transportString == "init") {
return initState;
} else if (transportString == "pending" || transportString == "waiting") {
return pendingState;
} else if (transportString == "finished") {
return finishedState;
} else if (transportString == "closed") {
return closedState;
} else if (transportString == "failed") {
return failedState;
}
return invalidState;
}
/*------------------------------------------------------------------------------
* Construct from a backup string.
*----------------------------------------------------------------------------*/
AsyncState
AsyncState :: fromBackupString(const std::string & backupString)
throw ()
{
if (backupString == "working") {
return pendingState;
} else if (backupString == "success") {
return finishedState;
} else if (backupString == "fault") {
return failedState;
}
return invalidState;
}
/*------------------------------------------------------------------------------
* Convert to a transport string.
*----------------------------------------------------------------------------*/
Ptr<std::string>::Ref
AsyncState :: toTransportString(void) const throw ()
{
Ptr<std::string>::Ref transportString(new std::string());
switch (value) {
case innerInitState: *transportString = "init";
break;
case innerPendingState: *transportString = "pending";
break;
case innerFinishedState: *transportString = "finished";
break;
case innerClosedState: *transportString = "closed";
break;
case innerFailedState: *transportString = "failed";
break;
case innerInvalidState: *transportString = "(invalid)";
break;
}
return transportString;
}
/*------------------------------------------------------------------------------
* Convert to a backup string.
*----------------------------------------------------------------------------*/
Ptr<std::string>::Ref
AsyncState :: toBackupString(void) const throw ()
{
Ptr<std::string>::Ref backupString(new std::string());
switch (value) {
case innerInitState: *backupString = "(init)";
break;
case innerPendingState: *backupString = "working";
break;
case innerFinishedState: *backupString = "success";
break;
case innerClosedState: *backupString = "(closed)";
break;
case innerFailedState: *backupString = "fault";
break;
case innerInvalidState: *backupString = "(invalid)";
break;
}
return backupString;
}
/*------------------------------------------------------------------------------
* Print to an ostream.
*----------------------------------------------------------------------------*/
std::ostream &
operator<<(std::ostream & ostream, const LiveSupport::Core::AsyncState state)
throw ()
{
Ptr<std::string>::Ref transportState = state.toTransportString();
ostream << *transportState;
return ostream;
}

View File

@ -1,127 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#include <string>
#include <iostream>
#include "LiveSupport/Core/AsyncState.h"
#include "AsyncStateTest.h"
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
CPPUNIT_TEST_SUITE_REGISTRATION(AsyncStateTest);
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Set up the test environment
*----------------------------------------------------------------------------*/
void
AsyncStateTest :: setUp(void) throw ()
{
}
/*------------------------------------------------------------------------------
* Clean up the test environment
*----------------------------------------------------------------------------*/
void
AsyncStateTest :: tearDown(void) throw ()
{
}
/*------------------------------------------------------------------------------
* Test the basic conversions.
*----------------------------------------------------------------------------*/
void
AsyncStateTest :: firstTest(void)
throw (CPPUNIT_NS::Exception)
{
AsyncState state = AsyncState::invalidState;
Ptr<std::string>::Ref transportString;
Ptr<std::string>::Ref backupString;
state = AsyncState::initState;
transportString = state.toTransportString();
CPPUNIT_ASSERT_EQUAL(AsyncState::fromTransportString(*transportString),
state);
state = AsyncState::pendingState;
transportString = state.toTransportString();
backupString = state.toBackupString();
CPPUNIT_ASSERT_EQUAL(AsyncState::fromTransportString(*transportString),
state);
CPPUNIT_ASSERT_EQUAL(AsyncState::fromBackupString(*backupString),
state);
state = AsyncState::finishedState;
transportString = state.toTransportString();
backupString = state.toBackupString();
CPPUNIT_ASSERT_EQUAL(AsyncState::fromTransportString(*transportString),
state);
CPPUNIT_ASSERT_EQUAL(AsyncState::fromBackupString(*backupString),
state);
state = AsyncState::closedState;
transportString = state.toTransportString();
CPPUNIT_ASSERT_EQUAL(AsyncState::fromTransportString(*transportString),
state);
state = AsyncState::failedState;
transportString = state.toTransportString();
backupString = state.toBackupString();
CPPUNIT_ASSERT_EQUAL(AsyncState::fromTransportString(*transportString),
state);
CPPUNIT_ASSERT_EQUAL(AsyncState::fromBackupString(*backupString),
state);
}
/*------------------------------------------------------------------------------
* Test the printing to an ostream.
*----------------------------------------------------------------------------*/
void
AsyncStateTest :: ostreamTest(void)
throw (CPPUNIT_NS::Exception)
{
std::ostringstream stream;
AsyncState state = AsyncState::finishedState;
stream << state;
CPPUNIT_ASSERT(stream.str() == "finished");
}

View File

@ -1,104 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef AsyncStateTest_h
#define AsyncStateTest_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#include <cppunit/extensions/HelperMacros.h>
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Unit test for the AsyncState class.
*
* @see AsyncState
*/
class AsyncStateTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(AsyncStateTest);
CPPUNIT_TEST(firstTest);
CPPUNIT_TEST(ostreamTest);
CPPUNIT_TEST_SUITE_END();
protected:
/**
* Test the basic conversions.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
firstTest(void) throw (CPPUNIT_NS::Exception);
/**
* Test the printing to an ostream.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
ostreamTest(void) throw (CPPUNIT_NS::Exception);
public:
/**
* Set up the environment for the test case.
*/
void
setUp(void) throw ();
/**
* Clean up the environment after the test case.
*/
void
tearDown(void) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // AsyncStateTest_h

View File

@ -1,742 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <sstream>
#include <typeinfo>
#include <fileref.h> // for TagLib
#include <mpegfile.h> // for TagLib
#include <id3v1tag.h> // for TagLib
#include <id3v2tag.h> // for TagLib
#include "LiveSupport/Core/TimeConversion.h"
#include "LiveSupport/Core/AudioClip.h"
using namespace boost::posix_time;
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/**
* The name of the config element for this class
*/
const std::string AudioClip::configElementNameStr = "audioClip";
/**
* The name of the attribute to get the id of the audio clip.
*/
static const std::string idAttrName = "id";
/**
* The name of the attribute to get the URI of the audio clip.
*/
static const std::string uriAttrName = "uri";
/**
* The name of the attribute to get the playlength of the audio clip.
*/
static const std::string playlengthAttrName = "playlength";
/**
* The name of the attribute to get the title of the audio clip.
*/
static const std::string titleAttrName = "title";
/**
* The name of the metadata child element.
*/
static const std::string metadataElementName = "metadata";
/**
* The prefix of the extent (length) metadata element.
*/
static const std::string extentElementPrefix = "dcterms";
/**
* The name of the extent (length) metadata element.
*/
static const std::string extentElementName = "extent";
/**
* The prefix of the title metadata element.
*/
static const std::string titleElementPrefix = "dc";
/**
* The name of the title metadata element.
*/
static const std::string titleElementName = "title";
/**
* The prefix for the Live Support extension elements.
*/
static const std::string liveSupportNamespacePrefix = "ls";
/**
* The prefix for the "xml:" prefix elements.
*/
static const std::string xmlNamespacePrefix = "xml";
/**
* The URI identifier for the default namespace
*/
static const std::string defaultNamespaceUri
= "http://mdlf.org/livesupport/elements/1.0/";
/**
* The URI identifier for the "ls" prefix.
*/
static const std::string liveSupportNamespaceUri
= "http://mdlf.org/livesupport/elements/1.0/";
/**
* The URI identifier for the "dc" prefix
*/
static const std::string dcNamespaceUri
= "http://purl.org/dc/elements/1.1/";
/**
* The URI identifier for the "dcterms" prefix
*/
static const std::string dctermsNamespaceUri
= "http://purl.org/dc/terms/";
/**
* The URI identifier for the "xml" prefix
*/
static const std::string xmlNamespaceUri
= "http://www.w3.org/XML/1998/namespace";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Copy constructor.
*----------------------------------------------------------------------------*/
AudioClip :: AudioClip(const AudioClip & otherAudioClip) throw ()
: Playable(AudioClipType)
{
this->id = otherAudioClip.id;
this->title = otherAudioClip.title;
this->playlength = otherAudioClip.playlength;
this->uri = otherAudioClip.uri;
this->token = otherAudioClip.token;
if (otherAudioClip.xmlAudioClip) {
xmlAudioClip.reset(new xmlpp::Document);
xmlAudioClip->create_root_node_by_import(
otherAudioClip.xmlAudioClip->get_root_node(),
true); // true == recursive
}
}
/*------------------------------------------------------------------------------
* Test constructor without title.
*----------------------------------------------------------------------------*/
AudioClip :: AudioClip(Ptr<UniqueId>::Ref id,
Ptr<time_duration>::Ref playlength,
Ptr<const std::string>::Ref uri)
throw ()
: Playable(AudioClipType)
{
this->id = id;
this->title.reset(new Glib::ustring(""));
this->playlength = playlength;
this->uri = uri;
setMetadata(title, titleElementName, titleElementPrefix);
Ptr<const Glib::ustring>::Ref playlengthString(new const Glib::ustring(
toFixedString(playlength) ));
setMetadata(playlengthString, extentElementName, extentElementPrefix);
}
/*------------------------------------------------------------------------------
* Test constructor with title.
*----------------------------------------------------------------------------*/
AudioClip :: AudioClip(Ptr<UniqueId>::Ref id,
Ptr<const Glib::ustring>::Ref title,
Ptr<time_duration>::Ref playlength,
Ptr<const std::string>::Ref uri)
throw ()
: Playable(AudioClipType)
{
this->id = id;
this->title = title;
this->playlength = playlength;
this->uri = uri;
setMetadata(title, titleElementName, titleElementPrefix);
Ptr<const Glib::ustring>::Ref playlengthString(new const Glib::ustring(
toFixedString(playlength) ));
setMetadata(playlengthString, extentElementName, extentElementPrefix);
}
/*------------------------------------------------------------------------------
* Constructor without ID.
*----------------------------------------------------------------------------*/
AudioClip :: AudioClip(Ptr<const Glib::ustring>::Ref title,
Ptr<time_duration>::Ref playlength,
Ptr<const std::string>::Ref uri)
throw ()
: Playable(AudioClipType)
{
this->title = title;
this->playlength = playlength;
this->uri = uri;
setMetadata(title, titleElementName, titleElementPrefix);
Ptr<const Glib::ustring>::Ref playlengthString(new const Glib::ustring(
toFixedString(playlength) ));
setMetadata(playlengthString, extentElementName, extentElementPrefix);
}
/*------------------------------------------------------------------------------
* Convert to an XmlRpcValue.
*----------------------------------------------------------------------------*/
AudioClip :: operator XmlRpc::XmlRpcValue() const
throw()
{
XmlRpc::XmlRpcValue xmlRpcValue;
xmlRpcValue[configElementNameStr] = std::string(*getXmlDocumentString());
return xmlRpcValue;
}
/*------------------------------------------------------------------------------
* Construct from an XmlRpcValue.
*----------------------------------------------------------------------------*/
AudioClip :: AudioClip(XmlRpc::XmlRpcValue & xmlRpcValue)
throw (std::invalid_argument)
: Playable(AudioClipType)
{
if (!xmlRpcValue.hasMember(configElementNameStr)) {
throw std::invalid_argument("no audio clip data found in XmlRpcValue");
}
xmlpp::DomParser parser;
try {
parser.parse_memory(std::string(xmlRpcValue[configElementNameStr]));
} catch (xmlpp::exception &e) {
throw std::invalid_argument("error parsing XML document");
}
configure(*parser.get_document()->get_root_node()); // may throw
}
/*------------------------------------------------------------------------------
* Set the value of the title field.
*----------------------------------------------------------------------------*/
void
AudioClip :: setTitle(Ptr<const Glib::ustring>::Ref title)
throw ()
{
this->title = title;
setMetadata(title, titleElementName, titleElementPrefix);
}
/*------------------------------------------------------------------------------
* Set the value of the playlength from a string (private).
*----------------------------------------------------------------------------*/
void
AudioClip :: setPlaylength(Ptr<const std::string>::Ref timeString)
throw (std::invalid_argument)
{
try {
playlength = TimeConversion::parseTimeDuration(timeString);
} catch (std::exception &e) {
std::string eMsg = "bad time format in playlength: ";
eMsg += e.what();
throw std::invalid_argument(eMsg);
}
}
/*------------------------------------------------------------------------------
* Create an audio clip object based on an XML element.
*----------------------------------------------------------------------------*/
void
AudioClip :: configure(const xmlpp::Element & element)
throw (std::invalid_argument)
{
if (element.get_name() != configElementNameStr) {
std::string eMsg = "bad configuration element ";
eMsg += element.get_name();
throw std::invalid_argument(eMsg);
}
const xmlpp::Attribute * attribute = 0;
if (!id) {
if (!(attribute = element.get_attribute(idAttrName))) {
std::string eMsg = "missing attribute ";
eMsg += idAttrName;
throw std::invalid_argument(eMsg);
}
id.reset(new UniqueId(attribute->get_value()));
}
if (!playlength
&& (attribute = element.get_attribute(playlengthAttrName))) {
Ptr<const Glib::ustring>::Ref playlengthString(new const Glib::ustring(
attribute->get_value() ));
setMetadata(playlengthString, extentElementName, extentElementPrefix);
}
if (!title
&& (attribute = element.get_attribute(titleAttrName))) {
title.reset(new const Glib::ustring(attribute->get_value()));
setMetadata(title, titleElementName, titleElementPrefix);
}
if (!uri
&& (attribute = element.get_attribute(uriAttrName))) {
uri.reset(new const std::string(attribute->get_value()));
}
xmlpp::Node::NodeList childNodes
= element.get_children(metadataElementName);
xmlpp::Node::NodeList::iterator it = childNodes.begin();
if (it != childNodes.end()) {
const xmlpp::Element * metadataElement
= dynamic_cast<const xmlpp::Element*> (*it);
xmlAudioClip.reset(new xmlpp::Document);
xmlpp::Element* root = xmlAudioClip->create_root_node(
configElementNameStr);
root->set_attribute(idAttrName, std::string(*id));
root->import_node(metadataElement, true); // true = recursive
const xmlpp::Node::NodeList dataFieldList
= metadataElement->get_children();
xmlpp::Node::NodeList::const_iterator listIt = dataFieldList.begin();
while (listIt != dataFieldList.end()) {
const xmlpp::Node* dataNode = *listIt;
std::string prefix = dataNode->get_namespace_prefix();
std::string name = dataNode->get_name();
const xmlpp::Element*
dataElement
= dynamic_cast<const xmlpp::Element*> (dataNode);
if (!dataElement) {
++listIt;
continue;
}
if (!playlength && prefix == extentElementPrefix
&& name == extentElementName) {
if (dataElement->has_child_text()) {
Ptr<std::string>::Ref playlengthString(new std::string(
dataElement->get_child_text()
->get_content() ));
setPlaylength(playlengthString);
} else { // or just leave blank? bad either way
playlength.reset(new time_duration(0,0,0,0));
}
}
if (!title && prefix == titleElementPrefix
&& name == titleElementName) {
Glib::ustring value;
if (dataElement->has_child_text()) {
value = dataElement->get_child_text()->get_content();
} else {
value = "";
}
Ptr<const Glib::ustring>::Ref ptrToValue(
new const Glib::ustring(value));
title = ptrToValue;
}
++listIt;
}
++it;
if (it != childNodes.end()) {
std::string eMsg = "more than one ";
eMsg += metadataElementName;
eMsg += " XML element";
throw std::invalid_argument(eMsg);
}
}
if (!playlength) {
std::string eMsg = "missing attribute ";
eMsg += playlengthAttrName;
eMsg += " or metadata element ";
eMsg += extentElementPrefix + ":" + extentElementName;
throw std::invalid_argument(eMsg);
}
if (!title) {
title.reset(new const Glib::ustring(""));
}
}
/*------------------------------------------------------------------------------
* Return the value of a metadata field.
*----------------------------------------------------------------------------*/
Ptr<Glib::ustring>::Ref
AudioClip :: getMetadata(const std::string & key) const
throw ()
{
std::string name, prefix;
separateNameAndNameSpace(key, name, prefix);
Ptr<Glib::ustring>::Ref value;
if (! xmlAudioClip) {
return value;
}
xmlpp::Element* rootNode = xmlAudioClip->get_root_node();
if (! rootNode) {
return value;
}
xmlpp::Node::NodeList rootList = rootNode->get_children(
metadataElementName);
if (rootList.size() == 0) {
return value;
}
xmlpp::Node* metadata = rootList.front();
xmlpp::Node::NodeList nodeList = metadata->get_children(name);
xmlpp::Node::NodeList::iterator it = nodeList.begin();
while (it != nodeList.end()) {
xmlpp::Node* node = *it;
if (node->get_namespace_prefix() == prefix) {
xmlpp::Element* element = dynamic_cast<xmlpp::Element*> (node);
xmlpp::TextNode* textNode = element->get_child_text();
if (textNode) {
value.reset(new Glib::ustring(textNode->get_content()));
} else {
value.reset(new Glib::ustring(""));
}
return value;
}
++it;
}
return value;
}
/*------------------------------------------------------------------------------
* Set the value of a metadata field (public).
*----------------------------------------------------------------------------*/
void
AudioClip :: setMetadata(Ptr<const Glib::ustring>::Ref value,
const std::string &key)
throw (std::invalid_argument)
{
std::string name;
std::string prefix;
separateNameAndNameSpace(key, name, prefix);
setMetadata(value, name, prefix);
}
/*------------------------------------------------------------------------------
* Set the value of a metadata field (private).
*----------------------------------------------------------------------------*/
void
AudioClip :: setMetadata(Ptr<const Glib::ustring>::Ref value,
const std::string &name, const std::string &prefix)
throw (std::invalid_argument)
{
if (prefix == extentElementPrefix && name == extentElementName) {
Ptr<const std::string>::Ref valueString(new const std::string(
*value));
setPlaylength(valueString); // may throw invalid_argument
}
if (prefix == titleElementPrefix && name == titleElementName) {
title = value;
}
// create a new xmlpp::Document for the metadata if necessary
if (! xmlAudioClip) {
xmlAudioClip.reset(new xmlpp::Document);
}
xmlpp::Element* rootNode = xmlAudioClip->get_root_node();
if (! rootNode) {
rootNode = xmlAudioClip->create_root_node(configElementNameStr);
if (id) {
rootNode->set_attribute(idAttrName, std::string(*id));
}
}
xmlpp::Node::NodeList rootList = rootNode->get_children(
metadataElementName);
xmlpp::Element* metadata;
if (rootList.size() > 0) {
metadata = dynamic_cast<xmlpp::Element*> (rootList.front());
} else {
metadata = rootNode->add_child(metadataElementName);
metadata->set_namespace_declaration(defaultNamespaceUri);
metadata->set_namespace_declaration(liveSupportNamespaceUri,
liveSupportNamespacePrefix);
metadata->set_namespace_declaration(dcNamespaceUri,
titleElementPrefix);
metadata->set_namespace_declaration(dctermsNamespaceUri,
extentElementPrefix);
metadata->set_namespace_declaration(xmlNamespaceUri,
xmlNamespacePrefix);
}
// find the element to be modified
xmlpp::Node::NodeList nodeList = metadata->get_children(name);
xmlpp::Node::NodeList::iterator it = nodeList.begin();
xmlpp::Element* element = 0;
while (it != nodeList.end()) {
xmlpp::Node* node = *it;
if (node->get_namespace_prefix() == prefix) {
element = dynamic_cast<xmlpp::Element*> (nodeList.front());
break;
}
++it;
}
// or add it if it did not exist before
if (it == nodeList.end()) {
element = metadata->add_child(name);
try {
element->set_namespace(prefix);
}
catch (xmlpp::exception &e) {
// this namespace has not been declared; well OK, do nothing then
}
}
element->set_child_text(*value);
}
/*------------------------------------------------------------------------------
* Return a string containing the essential fields of this object, in XML.
*----------------------------------------------------------------------------*/
Ptr<Glib::ustring>::Ref
AudioClip :: getXmlElementString(void) const throw ()
{
Ptr<Glib::ustring>::Ref xmlString(new Glib::ustring);
xmlString->append("<");
xmlString->append(configElementNameStr + " ");
xmlString->append(idAttrName + "=\""
+ std::string(*id)
+ "\" ");
xmlString->append(Glib::ustring(titleAttrName) + "=\""
+ *title
+ "\" ");
xmlString->append(playlengthAttrName + "=\""
+ toFixedString(playlength)
+ "\"/>");
return xmlString;
}
/*------------------------------------------------------------------------------
* Return a string containing an XML representation of this audio clip.
*----------------------------------------------------------------------------*/
Ptr<Glib::ustring>::Ref
AudioClip :: getXmlDocumentString() const throw ()
{
Ptr<xmlpp::Document>::Ref localDocument;
if (xmlAudioClip) {
localDocument = xmlAudioClip;
} else {
localDocument.reset(new xmlpp::Document());
xmlpp::Element* rootNode = localDocument->create_root_node(
configElementNameStr);
if (id) {
rootNode->set_attribute(idAttrName, std::string(*id));
}
xmlpp::Element* metadata = rootNode->add_child(metadataElementName);
metadata->set_namespace_declaration(defaultNamespaceUri);
metadata->set_namespace_declaration(liveSupportNamespaceUri,
liveSupportNamespacePrefix);
metadata->set_namespace_declaration(dcNamespaceUri,
titleElementPrefix);
metadata->set_namespace_declaration(dctermsNamespaceUri,
extentElementPrefix);
metadata->set_namespace_declaration(xmlNamespaceUri,
xmlNamespacePrefix);
}
Ptr<Glib::ustring>::Ref metadataString(new Glib::ustring(
localDocument->write_to_string() ));
return metadataString;
}
/*------------------------------------------------------------------------------
* Read the metadata contained in the id3v2 tag of the binary sound file.
*----------------------------------------------------------------------------*/
void
AudioClip :: readTag(Ptr<MetadataTypeContainer>::Ref metadataTypes)
throw (std::invalid_argument)
{
if (!getUri()) {
throw std::invalid_argument("audio clip has no uri field");
}
std::string uri = *getUri();
if (uri.substr(0,7) == "file://") {
uri = uri.substr(7);
} else if (uri.substr(0,5) == "file:") {
uri = uri.substr(5);
}
if (!TagLib::File::isReadable(uri.c_str())) {
throw std::invalid_argument("binary sound file not found");
}
TagLib::MPEG::File mpegFile(uri.c_str());
TagLib::ID3v2::Tag* id3v2Tag = mpegFile.ID3v2Tag();
if (id3v2Tag) {
Ptr<const MetadataType>::Ref metadata;
Ptr<const Glib::ustring>::Ref value;
TagLib::ID3v2::FrameListMap frameListMap = id3v2Tag->frameListMap();
TagLib::ID3v2::FrameListMap::ConstIterator it;
for (it = frameListMap.begin(); it != frameListMap.end(); ++it) {
std::string keyString(it->first.data(), 4);
try {
metadata = metadataTypes->getById3Tag(keyString);
TagLib::ID3v2::FrameList frameList = it->second;
if (!frameList.isEmpty()) {
value.reset(new const Glib::ustring(
frameList.front()->toString().to8Bit(true)));
setMetadata(value, *metadata->getDcName());
}
} catch (std::invalid_argument &e) {
// id3v2 tag name not found in MetadataTypeContainer
// TODO: print warning?
}
}
return;
}
TagLib::FileRef genericFileRef(uri.c_str());
TagLib::Tag* tag = genericFileRef.tag();
if (tag) {
TagLib::String stringValue;
TagLib::uint intValue;
Ptr<const Glib::ustring>::Ref value;
stringValue = tag->artist();
if (!stringValue.isNull()) {
value.reset(new const Glib::ustring(stringValue.to8Bit(true)));
setMetadata(value, "dc:creator");
}
stringValue = tag->title();
if (!stringValue.isNull()) {
value.reset(new const Glib::ustring(stringValue.to8Bit(true)));
setMetadata(value, "dc:title");
}
stringValue = tag->album();
if (!stringValue.isNull()) {
value.reset(new const Glib::ustring(stringValue.to8Bit(true)));
setMetadata(value, "dc:source");
}
stringValue = tag->comment();
if (!stringValue.isNull()) {
value.reset(new const Glib::ustring(stringValue.to8Bit(true)));
setMetadata(value, "dc:description");
}
stringValue = tag->genre();
if (!stringValue.isNull()) {
value.reset(new const Glib::ustring(stringValue.to8Bit(true)));
setMetadata(value, "dc:type");
}
intValue = tag->year();
if (intValue != 0) {
std::stringstream yearString;
yearString << intValue;
value.reset(new const Glib::ustring(yearString.str()));
setMetadata(value, "ls:year");
}
intValue = tag->track();
if (intValue != 0) {
std::stringstream trackString;
trackString << intValue;
value.reset(new const Glib::ustring(trackString.str()));
setMetadata(value, "ls:track_num");
}
}
}
/*------------------------------------------------------------------------------
* Separate a key into the metadata name and its namespace
*----------------------------------------------------------------------------*/
void
LiveSupport::Core :: separateNameAndNameSpace(const std::string & key,
std::string & name,
std::string & prefix)
throw ()
{
unsigned int colonPosition = key.find(':');
if (colonPosition != std::string::npos) { // there is a colon
prefix = key.substr(0, colonPosition);
name = key.substr(colonPosition+1);
} else { // no colon found
prefix = "";
name = key;
}
}

View File

@ -1,272 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#else
#error "Need unistd.h"
#endif
#include <string>
#include <iostream>
#include "LiveSupport/Core/AudioClip.h"
#include "LiveSupport/Core/Playlist.h"
#include "AudioClipTest.h"
using namespace std;
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
CPPUNIT_TEST_SUITE_REGISTRATION(AudioClipTest);
/**
* The name of the configuration file for the audio clip.
*/
static const std::string configFileName = "etc/audioClip.xml";
/**
* The name of the configuration file for the resource bundle.
*/
static const std::string bundleConfigFileName = "etc/resourceBundle.xml";
/**
* The name of the configuration file for the metadata type container.
*/
static const std::string metadataConfigFileName
= "etc/metadataTypeContainer.xml";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Set up the test environment
*----------------------------------------------------------------------------*/
void
AudioClipTest :: setUp(void) throw (CPPUNIT_NS::Exception)
{
try {
Ptr<xmlpp::DomParser>::Ref parser(
new xmlpp::DomParser(configFileName, false));
const xmlpp::Document * document = parser->get_document();
const xmlpp::Element * root = document->get_root_node();
audioClip.reset(new AudioClip());
audioClip->configure(*root);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL("semantic error in audio clip configuration file");
} catch (xmlpp::exception &e) {
std::string eMsg = "error parsing audio clip configuration file\n";
eMsg += e.what();
CPPUNIT_FAIL(eMsg);
}
Ptr<ResourceBundle>::Ref bundle;
try {
Ptr<xmlpp::DomParser>::Ref parser(
new xmlpp::DomParser(bundleConfigFileName, false));
const xmlpp::Document * document = parser->get_document();
const xmlpp::Element * root = document->get_root_node();
bundle = LocalizedObject::getBundle(*root);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL("semantic error in configuration file");
} catch (std::exception &e) {
std::string eMsg = "error parsing audio clip configuration file\n";
eMsg += e.what();
CPPUNIT_FAIL(eMsg);
}
CPPUNIT_ASSERT(bundle);
try {
Ptr<xmlpp::DomParser>::Ref parser(
new xmlpp::DomParser(metadataConfigFileName, false));
const xmlpp::Document * document = parser->get_document();
const xmlpp::Element * root = document->get_root_node();
metadataTypes.reset(new MetadataTypeContainer(bundle));
metadataTypes->configure(*root);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL("semantic error in metadata configuration file");
} catch (xmlpp::exception &e) {
std::string eMsg = "error parsing metadata configuration file\n";
eMsg += e.what();
CPPUNIT_FAIL(eMsg);
}
}
/*------------------------------------------------------------------------------
* Clean up the test environment
*----------------------------------------------------------------------------*/
void
AudioClipTest :: tearDown(void) throw ()
{
}
/*------------------------------------------------------------------------------
* Test to see if the singleton Hello object is accessible
*----------------------------------------------------------------------------*/
void
AudioClipTest :: firstTest(void)
throw (CPPUNIT_NS::Exception)
{
CPPUNIT_ASSERT(audioClip);
CPPUNIT_ASSERT(audioClip->getId());
CPPUNIT_ASSERT(audioClip->getId()->getId() == 0x1);
Ptr<const boost::posix_time::time_duration>::Ref duration
= audioClip->getPlaylength();
CPPUNIT_ASSERT(duration);
CPPUNIT_ASSERT(duration->hours() == 0);
CPPUNIT_ASSERT(duration->minutes() == 18);
CPPUNIT_ASSERT(duration->seconds() == 30);
Ptr<const Glib::ustring>::Ref title = audioClip->getTitle();
CPPUNIT_ASSERT(title);
CPPUNIT_ASSERT(*title == "File Title txt");
Ptr<const Glib::ustring>::Ref subject = audioClip
->getMetadata("dc:subject");
CPPUNIT_ASSERT(subject);
CPPUNIT_ASSERT(*subject == "Keywords: qwe, asd, zcx");
Ptr<const Glib::ustring>::Ref alternativeTitle = audioClip
->getMetadata("dcterms:alternative");
CPPUNIT_ASSERT(alternativeTitle);
CPPUNIT_ASSERT(*alternativeTitle ==
"Alternative File Title ín sőmé %$#@* LÁNGŰAGÉ");
CPPUNIT_ASSERT(audioClip->getXmlElementString());
CPPUNIT_ASSERT(*audioClip->getXmlElementString() ==
"<audioClip id=\"0000000000000001\" "
"title=\"File Title txt\" "
"playlength=\"00:18:30.000000\"/>");
}
/*------------------------------------------------------------------------------
* Test conversion to and from Playable
*----------------------------------------------------------------------------*/
void
AudioClipTest :: conversionTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<Playable>::Ref playable = audioClip;
CPPUNIT_ASSERT(playable->getType() == Playable::AudioClipType);
Ptr<AudioClip>::Ref otherAudioClip = playable->getAudioClip();
CPPUNIT_ASSERT(otherAudioClip == audioClip);
Ptr<Playlist>::Ref playlist = playable->getPlaylist();
CPPUNIT_ASSERT(!playlist);
}
/*------------------------------------------------------------------------------
* Test id3v2 tag extraction
*----------------------------------------------------------------------------*/
void
AudioClipTest :: tagTest(void)
throw (CPPUNIT_NS::Exception)
{
// should work with either plain file path...
Ptr<std::string>::Ref uri(new std::string("var/test10001.mp3"));
audioClip->setUri(uri);
try {
audioClip->readTag(metadataTypes);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL(e.what());
}
Ptr<const Glib::ustring>::Ref title
= audioClip->getMetadata("dc:title");
CPPUNIT_ASSERT(*title == "Theme Song");
Ptr<const Glib::ustring>::Ref artist
= audioClip->getMetadata("dc:creator");
CPPUNIT_ASSERT(*artist == "The Muppets");
Ptr<const Glib::ustring>::Ref album
= audioClip->getMetadata("dc:source");
CPPUNIT_ASSERT(*album == "מוישה אופניק");
// ... or with URI
uri.reset(new std::string("file:var/test10001.mp3"));
audioClip->setUri(uri);
try {
audioClip->readTag(metadataTypes);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL(e.what());
}
title = audioClip->getMetadata("dc:title");
CPPUNIT_ASSERT(*title == "Theme Song");
artist = audioClip->getMetadata("dc:creator");
CPPUNIT_ASSERT(*artist == "The Muppets");
album = audioClip->getMetadata("dc:source");
CPPUNIT_ASSERT(*album == "מוישה אופניק");
// Moshe Offnik is the Israeli/Palestinian version of Oscar The Grouch
}
/*------------------------------------------------------------------------------
* Marshalling test
*----------------------------------------------------------------------------*/
void
AudioClipTest :: marshallingTest(void)
throw (CPPUNIT_NS::Exception)
{
XmlRpc::XmlRpcValue xmlRpcValue = *audioClip;
CPPUNIT_ASSERT(xmlRpcValue.hasMember("audioClip"));
Ptr<AudioClip>::Ref otherAudioClip;
CPPUNIT_ASSERT_NO_THROW(otherAudioClip.reset(new AudioClip(xmlRpcValue)));
CPPUNIT_ASSERT(*audioClip->getId() == *otherAudioClip->getId());
CPPUNIT_ASSERT(*audioClip->getTitle()
== *otherAudioClip->getTitle());
CPPUNIT_ASSERT(*audioClip->getPlaylength()
== *otherAudioClip->getPlaylength());
}

View File

@ -1,138 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef AudioClipTest_h
#define AudioClipTest_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <cppunit/extensions/HelperMacros.h>
#include "LiveSupport/Core/AudioClip.h"
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Unit test for the AudioClip class.
*
* @see AudioClip
*/
class AudioClipTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(AudioClipTest);
CPPUNIT_TEST(firstTest);
CPPUNIT_TEST(conversionTest);
CPPUNIT_TEST(tagTest);
CPPUNIT_TEST(marshallingTest);
CPPUNIT_TEST_SUITE_END();
private:
/**
* The audio clip to test.
*/
Ptr<AudioClip>::Ref audioClip;
/**
* The list of supported metadata types.
*/
Ptr<MetadataTypeContainer>::Ref metadataTypes;
protected:
/**
* A simple test.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
firstTest(void) throw (CPPUNIT_NS::Exception);
/**
* Testing conversion to and from Playable.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
conversionTest(void) throw (CPPUNIT_NS::Exception);
/**
* Id3v2 tag extraction test.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
tagTest(void) throw (CPPUNIT_NS::Exception);
/**
* Testing conversion to and from XmlRpcValue.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
marshallingTest(void) throw (CPPUNIT_NS::Exception);
public:
/**
* Set up the environment for the test case.
*/
void
setUp(void) throw (CPPUNIT_NS::Exception);
/**
* Clean up the environment after the test case.
*/
void
tearDown(void) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // AudioClipTest_h

View File

@ -1,144 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#else
#error need sys/types.h
#endif
#ifdef HAVE_PWD_H
#include <pwd.h>
#else
#error need pwd.h
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#else
#error need errno.h
#endif
#include <fstream>
#include "LiveSupport/Core/BaseTestMethod.h"
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Return the current working directory
*----------------------------------------------------------------------------*/
std::string
BaseTestMethod :: getCwd(void) throw ()
{
size_t size = 100;
char * buffer;
while (true) {
buffer = new char[size];
if (getcwd(buffer, size)) {
break;
}
delete[] buffer;
if (errno != ERANGE) {
return "";
}
size *= 2;
}
std::string cwd(buffer);
delete[] buffer;
return cwd;
}
/*------------------------------------------------------------------------------
* Return the full path for a configuration file.
*----------------------------------------------------------------------------*/
std::string
BaseTestMethod :: getConfigFile(const std::string configFileName)
throw (std::invalid_argument)
{
std::string fileName;
std::ifstream file;
// first, try with ~/.campcaster/configFileName
struct passwd * pwd = getpwuid(getuid());
if (pwd) {
fileName += pwd->pw_dir;
fileName += "/.campcaster/" + configFileName;
file.open(fileName.c_str());
if (file.good()) {
file.close();
return fileName;
}
file.close();
file.clear();
}
// second, try with ./etc/configFileName
fileName = getCwd() + "/etc/" + configFileName;
file.open(fileName.c_str());
if (file.good()) {
file.close();
return fileName;
}
file.close();
throw std::invalid_argument("can't find config file " + configFileName);
}
/*------------------------------------------------------------------------------
* Return a configuration document
*----------------------------------------------------------------------------*/
const xmlpp::Document *
BaseTestMethod :: getConfigDocument(xmlpp::DomParser & parser,
const std::string configFileName)
throw (std::invalid_argument,
std::exception)
{
std::string realFileName = getConfigFile(configFileName);
parser.set_validate();
parser.parse_file(realFileName);
return parser.get_document();
}

View File

@ -1,128 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#include "EnumerationConstraint.h"
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
namespace {
/*------------------------------------------------------------------------------
* The value of the type attribute for this class.
*----------------------------------------------------------------------------*/
const std::string typeAttributeValue = "enumeration";
}
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Create a constraint element object based on an XML element.
*----------------------------------------------------------------------------*/
void
EnumerationConstraint :: configure(const xmlpp::Element & element)
throw (std::invalid_argument)
{
if (element.get_name() != getConfigElementName()) {
throw std::invalid_argument("bad configuration element "
+ element.get_name());
}
const xmlpp::Attribute* typeAttribute;
if (!(typeAttribute = element.get_attribute(typeAttributeName))) {
throw std::invalid_argument("missing attribute " + typeAttributeName);
}
std::string type = typeAttribute->get_value();
if (type != typeAttributeValue) {
throw std::invalid_argument(typeAttributeValue
+ " constraint configured with a"
+ " constraint element of type "
+ type);
}
xmlpp::Node::NodeList childNodes = element.get_children(valueElementName);
xmlpp::Node::NodeList::iterator it = childNodes.begin();
if (it == childNodes.end()) {
throw std::invalid_argument("empty enumeration constraint");
}
for (; it != childNodes.end(); ++it) {
readValue(*it);
}
}
/*------------------------------------------------------------------------------
* Read an enumeration value from an XML node.
*----------------------------------------------------------------------------*/
void
EnumerationConstraint :: readValue(const xmlpp::Node * node)
throw (std::invalid_argument)
{
const xmlpp::Element * valueElement
= dynamic_cast<const xmlpp::Element*> (node);
if (valueElement) {
allowedValues.push_back(valueElement->get_child_text()
->get_content() );
} else {
throw std::invalid_argument("bad sub-element found in constraint");
}
}
/*------------------------------------------------------------------------------
* Check that the given value satisfies the constraint.
*----------------------------------------------------------------------------*/
bool
EnumerationConstraint :: check(Ptr<const Glib::ustring>::Ref value) const
throw (std::logic_error)
{
if (!value) {
throw std::logic_error("EnumerationConstraint::check() called with "
"a 0 pointer value");
}
ListType::const_iterator it;
for (it = allowedValues.begin(); it != allowedValues.end(); ++it) {
if (*it == *value) {
return true;
}
}
return false;
}

View File

@ -1,166 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_EnumerationConstraint_h
#define LiveSupport_Core_EnumerationConstraint_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#include "LiveSupport/Core/MetadataConstraint.h"
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A class for representing a metadata constraint allowing only strings from
* a given list of values.
*
* This is a concrete subclass of MetadataConstraint. Do not explicitly
* instantiate this class; create a MetadataConstraint object instead, and
* configure it with an XML element with the appropriate type attribute.
*
* This object has to be configured with an XML configuration element
* called constraint. This may look like the following:
*
* <pre><code>
* <constraint type = "enumeration">
* <value>Monday</value>
* ...
* <value>Sunday</value>
* </constraint>
* </code></pre>
*
* A metadata type with this kind of constraint can only accept one of the
* strings listed in the value elements (in a case-sensitive way).
*
* The DTD for the expected XML element looks like the following:
*
* <pre><code>
* <!ELEMENT constraint (value+) >
* <!ATTLIST constraint type "enumeration" #FIXED >
* <!ELEMENT value (#PCDATA) >
* </code></pre>
*
* @see EnumerationConstraintContainer
*/
class EnumerationConstraint : public MetadataConstraint
{
private:
/**
* The type for storing the enumeration values.
*/
typedef std::vector<Glib::ustring> ListType;
/**
* The list of allowed enumeration values.
*/
ListType allowedValues;
/**
* Read an enumeration value from an XML node.
*
* @param node the node containing the value.
* @exception std::invalid_argument if the XML node is not
* of the expected form.
*/
void
readValue(const xmlpp::Node * node) throw (std::invalid_argument);
public:
/**
* Constructor.
*/
EnumerationConstraint() throw ()
{
}
/**
* A virtual destructor, as this class has virtual functions.
*/
virtual
~EnumerationConstraint(void) throw ()
{
}
/**
* Return the name of the XML element this object expects
* to be sent to a call to configure().
*
* @return the name of the expected XML configuration element.
*/
static const std::string
getConfigElementName(void) throw ()
{
return MetadataConstraint::getConfigElementName();
}
/**
* Configure the metadata object based on an XML configuration element.
*
* @param element the XML configuration element.
* @exception std::invalid_argument of the supplied XML element
* contains bad configuration information
*/
virtual void
configure(const xmlpp::Element &element)
throw (std::invalid_argument);
/**
* Check that the given value satisfies the constraint.
*
* @param value the value to be checked against the constraint.
* @return true if the value satisfies the constraint.
* @exception std::logic_error if the parameter is a 0 pointer.
*/
virtual bool
check(Ptr<const Glib::ustring>::Ref value) const
throw (std::logic_error);
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_EnumerationConstraint_h

View File

@ -1,133 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <sstream>
#include "LiveSupport/Core/TimeConversion.h"
#include "LiveSupport/Core/FadeInfo.h"
using namespace boost::posix_time;
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* The name of the config element for this class
*----------------------------------------------------------------------------*/
const std::string FadeInfo::configElementNameStr = "fadeInfo";
/**
* The name of the attribute to get the id of the audio clip.
*/
static const std::string idAttrName = "id";
/**
* The name of the attribute to get the fade in.
*/
static const std::string fadeInAttrName = "fadeIn";
/**
* The name of the attribute to get the fade out.
*/
static const std::string fadeOutAttrName = "fadeOut";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Create a fade info object based on an XML element.
*----------------------------------------------------------------------------*/
void
FadeInfo :: configure(const xmlpp::Element & element)
throw (std::invalid_argument)
{
if (element.get_name() != configElementNameStr) {
std::string eMsg = "bad configuration element ";
eMsg += element.get_name();
throw std::invalid_argument(eMsg);
}
const xmlpp::Attribute * attribute = 0;
if (!(attribute = element.get_attribute(idAttrName))) {
std::string eMsg = "missing attribute ";
eMsg += idAttrName;
throw std::invalid_argument(eMsg);
}
id.reset(new UniqueId(attribute->get_value()));
if (!(attribute = element.get_attribute(fadeInAttrName))) {
std::string eMsg = "missing attribute ";
eMsg += idAttrName;
throw std::invalid_argument(eMsg);
}
Ptr<std::string>::Ref fadeInString(new std::string(
attribute->get_value() ));
fadeIn = TimeConversion::parseTimeDuration(fadeInString);
if (!(attribute = element.get_attribute(fadeOutAttrName))) {
std::string eMsg = "missing attribute ";
eMsg += idAttrName;
throw std::invalid_argument(eMsg);
}
Ptr<std::string>::Ref fadeOutString(new std::string(
attribute->get_value() ));
fadeOut = TimeConversion::parseTimeDuration(fadeOutString);
}
/*------------------------------------------------------------------------------
* Return a string containing the essential fields of this object, in XML.
*----------------------------------------------------------------------------*/
Ptr<Glib::ustring>::Ref
FadeInfo :: getXmlElementString(void) throw ()
{
Ptr<Glib::ustring>::Ref xmlString(new Glib::ustring);
xmlString->append("<");
xmlString->append(configElementNameStr + " ");
xmlString->append(idAttrName + "=\""
+ std::string(*id)
+ "\" ");
xmlString->append(fadeInAttrName + "=\""
+ toFixedString(fadeIn)
+ "\" ");
xmlString->append(fadeOutAttrName + "=\""
+ toFixedString(fadeOut)
+ "\"/>");
return xmlString;
}

View File

@ -1,128 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#else
#error "Need unistd.h"
#endif
#include <string>
#include <iostream>
#include "LiveSupport/Core/FadeInfo.h"
#include "FadeInfoTest.h"
using namespace std;
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
CPPUNIT_TEST_SUITE_REGISTRATION(FadeInfoTest);
/**
* The name of the configuration file for the audio clip.
*/
static const std::string configFileName = "etc/fadeInfo.xml";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Set up the test environment
*----------------------------------------------------------------------------*/
void
FadeInfoTest :: setUp(void) throw ()
{
}
/*------------------------------------------------------------------------------
* Clean up the test environment
*----------------------------------------------------------------------------*/
void
FadeInfoTest :: tearDown(void) throw ()
{
}
/*------------------------------------------------------------------------------
* Test to see if the singleton Hello object is accessible
*----------------------------------------------------------------------------*/
void
FadeInfoTest :: firstTest(void)
throw (CPPUNIT_NS::Exception)
{
try {
Ptr<xmlpp::DomParser>::Ref parser(
new xmlpp::DomParser(configFileName, true));
const xmlpp::Document * document = parser->get_document();
const xmlpp::Element * root = document->get_root_node();
Ptr<FadeInfo>::Ref fadeInfo(new FadeInfo());
fadeInfo->configure(*root);
CPPUNIT_ASSERT(fadeInfo->getId()->getId() == 0x9901);
Ptr<const boost::posix_time::time_duration>::Ref
fadeIn = fadeInfo->getFadeIn();
CPPUNIT_ASSERT(fadeIn->hours() == 0);
CPPUNIT_ASSERT(fadeIn->minutes() == 0);
CPPUNIT_ASSERT(fadeIn->seconds() == 2);
Ptr<const boost::posix_time::time_duration>::Ref
fadeOut = fadeInfo->getFadeOut();
CPPUNIT_ASSERT(fadeOut->hours() == 0);
CPPUNIT_ASSERT(fadeOut->minutes() == 0);
CPPUNIT_ASSERT(fadeOut->seconds() == 1);
CPPUNIT_ASSERT(fadeOut->fractional_seconds() == 500);
CPPUNIT_ASSERT(*fadeInfo->getXmlElementString() ==
"<fadeInfo id=\"0000000000009901\" "
"fadeIn=\"00:00:02.000000\" "
"fadeOut=\"00:00:01.000500\"/>");
} catch (std::invalid_argument &e) {
std::string eMsg = "semantic error in configuration file:\n";
eMsg += e.what();
CPPUNIT_FAIL(eMsg);
} catch (xmlpp::exception &e) {
std::string eMsg = "error parsing configuration file:\n";
eMsg += e.what();
CPPUNIT_FAIL(eMsg);
}
}

View File

@ -1,99 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef FadeInfoTest_h
#define FadeInfoTest_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <cppunit/extensions/HelperMacros.h>
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Unit test for the FadeInfo class.
*
* @see FadeInfo
*/
class FadeInfoTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(FadeInfoTest);
CPPUNIT_TEST(firstTest);
CPPUNIT_TEST_SUITE_END();
protected:
/**
* A simple test.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
firstTest(void) throw (CPPUNIT_NS::Exception);
public:
/**
* Set up the environment for the test case.
*/
void
setUp(void) throw ();
/**
* Clean up the environment after the test case.
*/
void
tearDown(void) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // FadeInfoTest_h

View File

@ -1,332 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
To report bugs, send an e-mail to bugs@campware.org
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $
Version : $Revision$
Location : $URL: svn+ssh://fgerlits@code.campware.org/home/svn/repo/livesupport/trunk/livesupport/src/modules/core/src/FileTools.cxx $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_TIME_H
#include <time.h>
#else
#error need time.h
#endif
#ifdef HAVE_TIME_H
#include <stdio.h>
#else
#error need stdio.h
#endif
#include <fcntl.h>
#include <libtar.h>
#include <iostream>
#include <fstream>
#include <curl/curl.h>
#include <curl/easy.h>
#include "LiveSupport/Core/FileTools.h"
using namespace LiveSupport;
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Copy the contents of a URL to a local file.
*----------------------------------------------------------------------------*/
void
FileTools :: copyUrlToFile(const std::string & url,
const std::string & path)
throw (std::runtime_error)
{
FILE* file = fopen(path.c_str(), "wb");
if (!file) {
throw std::runtime_error("File location is not writable.");
}
CURL* handle = curl_easy_init();
if (!handle) {
fclose(file);
throw std::runtime_error("Could not obtain curl handle.");
}
int status = curl_easy_setopt(handle, CURLOPT_URL, url.c_str());
status |= curl_easy_setopt(handle, CURLOPT_WRITEDATA, file);
status |= curl_easy_setopt(handle, CURLOPT_HTTPGET, 1);
if (status) {
fclose(file);
throw std::runtime_error("Could not set curl options.");
}
status = curl_easy_perform(handle);
if (status) {
fclose(file);
throw std::runtime_error("Error downloading file.");
}
curl_easy_cleanup(handle);
fclose(file);
}
/*------------------------------------------------------------------------------
* Upload the contents of a local file to a writable URL.
*----------------------------------------------------------------------------*/
void
FileTools :: copyFileToUrl(const std::string & path,
const std::string & url)
throw (std::runtime_error)
{
FILE* file = fopen(path.c_str(), "rb");
if (!file) {
throw std::runtime_error("File not found.");
}
fseek(file, 0, SEEK_END);
long fileSize = ftell(file);
rewind(file);
CURL* handle = curl_easy_init();
if (!handle) {
throw std::runtime_error("Could not obtain curl handle.");
}
int status = curl_easy_setopt(handle, CURLOPT_READDATA, file);
status |= curl_easy_setopt(handle, CURLOPT_INFILESIZE, fileSize);
// works for files of size up to 2 GB
status |= curl_easy_setopt(handle, CURLOPT_PUT, 1);
status |= curl_easy_setopt(handle, CURLOPT_URL, url.c_str());
// status |= curl_easy_setopt(handle, CURLOPT_HEADER, 1);
// status |= curl_easy_setopt(handle, CURLOPT_ENCODING, "deflate");
if (status) {
throw std::runtime_error("Could not set curl options.");
}
status = curl_easy_perform(handle);
if (status) {
throw std::runtime_error("Error uploading file.");
}
curl_easy_cleanup(handle);
fclose(file);
}
/*------------------------------------------------------------------------------
* Create a temporary file name
*----------------------------------------------------------------------------*/
const std::string
FileTools :: tempnam(void) throw ()
{
std::string fileName(::tempnam(NULL, NULL));
return fileName;
}
/*------------------------------------------------------------------------------
* Append a file to an existing tarball
*----------------------------------------------------------------------------*/
void
FileTools :: appendFileToTarball(const std::string & tarFileName,
const std::string & newFileRealName,
const std::string & newFileInTarball)
throw (std::runtime_error)
{
TAR * tar;
off_t tarFileEnd; // keeps read position it tarball
// first chop off the existing EOF from the tarball
// open for reading first to determine where EOT block begins
if (tar_open(&tar,
(char*) tarFileName.c_str(),
NULL,
O_RDONLY,
0,
0) == -1) {
throw std::runtime_error("can't open tarball");
}
// go through all files in tarball and record end position
// of the last file read
tarFileEnd = 0;
while (th_read(tar) == 0) {
if (TH_ISREG(tar)) {
tar_skip_regfile(tar);
}
tarFileEnd = lseek(tar->fd, 0, SEEK_CUR);
}
// at this point, tarFileEnd is position where EOT block begins
tar_close(tar); // close for reading
//truncate EOT from the tarball
if (truncate(tarFileName.c_str(), tarFileEnd) == -1) {
throw std::runtime_error("can't truncate tarball");
}
// and now append the new file, and put an EOF at the end
// open truncated tarball (without EOT block) for writing and append
if (tar_open(&tar,
(char*) tarFileName.c_str(),
NULL,
O_WRONLY | O_APPEND,
0666,
0) == -1) {
throw std::runtime_error("can't open tarball");
}
// add the new file
if (tar_append_file(tar,
(char*) newFileRealName.c_str(),
(char*) newFileInTarball.c_str()) == -1) {
tar_close(tar);
throw std::runtime_error("can't append file to tarball");
}
// add EOT at the end and close tarball
tar_append_eof(tar);
tar_close(tar);
}
/*------------------------------------------------------------------------------
* Check if a file is in the tarball
*----------------------------------------------------------------------------*/
bool
FileTools :: existsInTarball(const std::string & tarFileName,
const std::string & fileName)
throw (std::runtime_error)
{
TAR * tar;
bool result = false;
if (tar_open(&tar,
(char*) tarFileName.c_str(),
NULL,
O_RDONLY,
0,
0) == -1) {
throw std::runtime_error("can't open tarball");
}
while (th_read(tar) == 0) {
if (TH_ISREG(tar)) {
char * path = th_get_pathname(tar);
if (fileName == path) {
result = true;
break;
}
tar_skip_regfile(tar);
}
}
// at this point, tarFileEnd is position where EOT block begins
tar_close(tar); // close for reading
return result;
}
/*------------------------------------------------------------------------------
* Extract a file from a tarball.
*----------------------------------------------------------------------------*/
void
FileTools :: extractFileFromTarball(const std::string & tarFileName,
const std::string & fileInTarball,
const std::string & fileExtracted)
throw (std::runtime_error)
{
TAR * tar;
bool found = false;
if (tar_open(&tar,
(char*) tarFileName.c_str(),
NULL,
O_RDONLY,
0,
0) == -1) {
throw std::runtime_error("can't open tarball");
}
while (th_read(tar) == 0) {
if (TH_ISREG(tar)) {
char * path = th_get_pathname(tar);
if (fileInTarball == path) {
found = true;
if (tar_extract_file(tar,
(char *) fileExtracted.c_str()) != 0) {
std::string errorMsg = "can't extract file ";
errorMsg += fileInTarball;
errorMsg += " from tarball ";
errorMsg += tarFileName;
throw std::runtime_error(errorMsg);
}
break;
}
tar_skip_regfile(tar);
}
}
// at this point, tarFileEnd is position where EOT block begins
tar_close(tar); // close for reading
if (!found) {
std::string errorMsg = "could not find file ";
errorMsg += fileInTarball;
errorMsg += " in the tarball ";
errorMsg += tarFileName;
throw std::runtime_error(errorMsg);
}
}

View File

@ -1,149 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
To report bugs, send an e-mail to bugs@campware.org
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $
Version : $Revision: 1871 $
Location : $URL: svn+ssh://maroy@code.campware.org/home/svn/repo/livesupport/trunk/livesupport/src/modules/core/src/FileToolsTest.cxx $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#else
#error "Need unistd.h"
#endif
#include <string>
#include <iostream>
#include "LiveSupport/Core/FileTools.h"
#include "LiveSupport/Core/Playlist.h"
#include "FileToolsTest.h"
using namespace std;
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
CPPUNIT_TEST_SUITE_REGISTRATION(FileToolsTest);
namespace {
/**
* The name of the test tar file
*/
const std::string tarFileName = "var/hello.tar";
/**
* The name of the test file in the tar file
*/
const std::string fileInTarName = "hello";
/**
* The name of the test file after extraction
*/
const std::string fileExtracted = "tmp/hello.txt";
}
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Set up the test environment
*----------------------------------------------------------------------------*/
void
FileToolsTest :: setUp(void) throw ()
{
}
/*------------------------------------------------------------------------------
* Clean up the test environment
*----------------------------------------------------------------------------*/
void
FileToolsTest :: tearDown(void) throw ()
{
}
/*------------------------------------------------------------------------------
* Test to see if the sample hello tarfile is accessible
*----------------------------------------------------------------------------*/
void
FileToolsTest :: existsInTarTest(void)
throw (CPPUNIT_NS::Exception)
{
CPPUNIT_ASSERT(FileTools::existsInTarball(tarFileName, fileInTarName));
CPPUNIT_ASSERT(!FileTools::existsInTarball(tarFileName, "foobar"));
}
/*------------------------------------------------------------------------------
* Test to see if the sample hello tarfile is accessible
*----------------------------------------------------------------------------*/
void
FileToolsTest :: extractFileFromTarballTest(void)
throw (CPPUNIT_NS::Exception)
{
FILE * file;
remove(fileExtracted.c_str());
file = fopen(fileExtracted.c_str(), "r");
CPPUNIT_ASSERT(file == 0);
CPPUNIT_ASSERT_NO_THROW(
FileTools::extractFileFromTarball(tarFileName,
fileInTarName,
fileExtracted)
);
file = fopen(fileExtracted.c_str(), "r");
CPPUNIT_ASSERT(file != 0);
CPPUNIT_ASSERT(fclose(file) == 0);
CPPUNIT_ASSERT(remove(fileExtracted.c_str()) == 0);
file = fopen(fileExtracted.c_str(), "r");
CPPUNIT_ASSERT(file == 0);
CPPUNIT_ASSERT_THROW(
FileTools::extractFileFromTarball(tarFileName,
"foobar",
fileExtracted),
std::runtime_error
);
}

View File

@ -1,111 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef FileToolsTest_h
#define FileToolsTest_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <cppunit/extensions/HelperMacros.h>
#include "LiveSupport/Core/FileTools.h"
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Unit test for the FileTools class.
*
* @see FileTools
*/
class FileToolsTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(FileToolsTest);
CPPUNIT_TEST(existsInTarTest);
CPPUNIT_TEST(extractFileFromTarballTest);
CPPUNIT_TEST_SUITE_END();
private:
protected:
/**
* Test the existsInTarball() function.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
existsInTarTest(void) throw (CPPUNIT_NS::Exception);
/**
* Test the extractFileFromTarball() function.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
extractFileFromTarballTest(void) throw (CPPUNIT_NS::Exception);
public:
/**
* Set up the environment for the test case.
*/
void
setUp(void) throw ();
/**
* Clean up the environment after the test case.
*/
void
tearDown(void) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // FileToolsTest_h

View File

@ -1,111 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <unicode/msgfmt.h>
#include "LiveSupport/Core/LocalizedConfigurable.h"
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/**
* The name of the attribute to get the path of the resource bundle.
*/
static const std::string pathAttrName = "path";
/**
* The name of the attribute to get the locale of the resource bundle.
*/
static const std::string localeAttrName = "locale";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Load a resource bunlde based on an XML configuration element.
*----------------------------------------------------------------------------*/
void
LocalizedConfigurable :: configure(const xmlpp::Element & element)
throw (std::invalid_argument,
std::logic_error)
{
if (element.get_name() != LocalizedObject::getConfigElementName()) {
std::string eMsg = "Bad configuration element ";
eMsg += element.get_name();
throw std::invalid_argument(eMsg);
}
const xmlpp::Attribute * attribute = 0;
if (!(attribute = element.get_attribute(pathAttrName))) {
std::string eMsg = "Missing attribute ";
eMsg += pathAttrName;
throw std::invalid_argument(eMsg);
}
bundlePath = attribute->get_value();
if (!(attribute = element.get_attribute(localeAttrName))) {
std::string eMsg = "Missing attribute ";
eMsg += localeAttrName;
throw std::invalid_argument(eMsg);
}
std::string locale = attribute->get_value();
changeLocale(locale);
}
/*------------------------------------------------------------------------------
* Change the resource bundle to reflect the specified locale
*----------------------------------------------------------------------------*/
void
LocalizedConfigurable :: changeLocale(const std::string newLocale)
throw (std::invalid_argument)
{
UErrorCode status = U_ZERO_ERROR;
Ptr<ResourceBundle>::Ref resourceBundle(
new ResourceBundle(bundlePath.c_str(),
newLocale.c_str(),
status));
if (!U_SUCCESS(status)) {
throw std::invalid_argument("opening resource bundle a failure");
}
setBundle(resourceBundle);
}

View File

@ -1,167 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <string>
#include <iostream>
#include <unicode/resbund.h>
#include "LiveSupport/Core/LocalizedConfigurable.h"
#include "LocalizedConfigurableTest.h"
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
CPPUNIT_TEST_SUITE_REGISTRATION(LocalizedConfigurableTest);
/**
* The name of the configuration file for the resource bundle.
*/
static const std::string configFileName = "etc/resourceBundle.xml";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Set up the test environment
*----------------------------------------------------------------------------*/
void
LocalizedConfigurableTest :: setUp(void) throw ()
{
}
/*------------------------------------------------------------------------------
* Clean up the test environment
*----------------------------------------------------------------------------*/
void
LocalizedConfigurableTest :: tearDown(void) throw ()
{
}
/*------------------------------------------------------------------------------
* A simple smoke test.
*----------------------------------------------------------------------------*/
void
LocalizedConfigurableTest :: simpleTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<LocalizedConfigurable>::Ref locConf(new LocalizedConfigurable());
try {
Ptr<xmlpp::DomParser>::Ref parser(
new xmlpp::DomParser(configFileName, true));
const xmlpp::Document * document = parser->get_document();
const xmlpp::Element * root = document->get_root_node();
locConf->configure(*root);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL("semantic error in configuration file");
} catch (std::exception &e) {
CPPUNIT_FAIL(e.what());
}
try {
Ptr<LocalizedObject>::Ref section1(new LocalizedObject(
locConf->getBundle("section1")));
Ptr<UnicodeString>::Ref foo = section1->getResourceString("foo");
CPPUNIT_ASSERT(foo->compare("fou") == 0);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL(e.what());
}
}
/*------------------------------------------------------------------------------
* A test to see if chaning the locale works.
*----------------------------------------------------------------------------*/
void
LocalizedConfigurableTest :: changeLocaleTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<LocalizedConfigurable>::Ref locConf(new LocalizedConfigurable());
try {
Ptr<xmlpp::DomParser>::Ref parser(
new xmlpp::DomParser(configFileName, true));
const xmlpp::Document * document = parser->get_document();
const xmlpp::Element * root = document->get_root_node();
locConf->configure(*root);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL("semantic error in configuration file");
} catch (std::exception &e) {
CPPUNIT_FAIL(e.what());
}
// see if all is OK in english
try {
Ptr<LocalizedObject>::Ref section1(new LocalizedObject(
locConf->getBundle("section1")));
Ptr<UnicodeString>::Ref foo = section1->getResourceString("foo");
CPPUNIT_ASSERT(foo->compare("fou") == 0);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL(e.what());
}
// see if all is OK when changing to hungarian.
try {
locConf->changeLocale("hu");
Ptr<LocalizedObject>::Ref section1(new LocalizedObject(
locConf->getBundle("section1")));
Ptr<UnicodeString>::Ref foo = section1->getResourceString("foo");
CPPUNIT_ASSERT(foo->charAt(0) == 0x0066); // 'f'
CPPUNIT_ASSERT(foo->charAt(1) == 0x00fa); // 'u' with acute
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL(e.what());
}
// see if all is OK when changing to japanese.
try {
locConf->changeLocale("jp");
Ptr<LocalizedObject>::Ref section1(new LocalizedObject(
locConf->getBundle("section1")));
Ptr<UnicodeString>::Ref foo = section1->getResourceString("foo");
CPPUNIT_ASSERT(foo->charAt(0) == 0x3075); // hiragana fu
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL(e.what());
}
}

View File

@ -1,108 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LocalizedConfigurableTest_h
#define LocalizedConfigurableTest_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <cppunit/extensions/HelperMacros.h>
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Unit test for the LocalizedConfigurable class.
*
* @see LocalizedObject
*/
class LocalizedConfigurableTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(LocalizedConfigurableTest);
CPPUNIT_TEST(simpleTest);
CPPUNIT_TEST(changeLocaleTest);
CPPUNIT_TEST_SUITE_END();
protected:
/**
* A simple smoke test.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
simpleTest(void) throw (CPPUNIT_NS::Exception);
/**
* A test to see if changing the locale works.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
changeLocaleTest(void) throw (CPPUNIT_NS::Exception);
public:
/**
* Set up the environment for the test case.
*/
void
setUp(void) throw ();
/**
* Clean up the environment after the test case.
*/
void
tearDown(void) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LocalizedConfigurableTest_h

View File

@ -1,335 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <unicode/msgfmt.h>
#include <string.h>
#include "LiveSupport/Core/LocalizedObject.h"
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* The name of the config element for this class
*----------------------------------------------------------------------------*/
const std::string LocalizedObject::configElementNameStr = "resourceBundle";
/**
* The name of the attribute to get the path of the resource bundle.
*/
static const std::string pathAttrName = "path";
/**
* The name of the attribute to get the locale of the resource bundle.
*/
static const std::string localeAttrName = "locale";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Load a resource bunlde based on an XML configuration element.
*----------------------------------------------------------------------------*/
Ptr<ResourceBundle>::Ref
LocalizedObject :: getBundle(const xmlpp::Element & element)
throw (std::invalid_argument)
{
if (element.get_name() != configElementNameStr) {
std::string eMsg = "Bad configuration element ";
eMsg += element.get_name();
throw std::invalid_argument(eMsg);
}
const xmlpp::Attribute * attribute = 0;
if (!(attribute = element.get_attribute(pathAttrName))) {
std::string eMsg = "Missing attribute ";
eMsg += pathAttrName;
throw std::invalid_argument(eMsg);
}
std::string path = attribute->get_value();
if (!(attribute = element.get_attribute(localeAttrName))) {
std::string eMsg = "Missing attribute ";
eMsg += localeAttrName;
throw std::invalid_argument(eMsg);
}
std::string locale = attribute->get_value();
UErrorCode status = U_ZERO_ERROR;
Ptr<ResourceBundle>::Ref resourceBundle(
new ResourceBundle(path.c_str(),
locale.c_str(),
status));
if (!U_SUCCESS(status)) {
throw std::invalid_argument("opening resource bundle a failure");
}
return resourceBundle;
}
/*------------------------------------------------------------------------------
* Get a resource bundle by the specified key
*----------------------------------------------------------------------------*/
Ptr<ResourceBundle>::Ref
LocalizedObject :: getBundle(Ptr<ResourceBundle>::Ref bundle,
const char * key)
throw (std::invalid_argument)
{
UErrorCode status = U_ZERO_ERROR;
Ptr<ResourceBundle>::Ref resourceBundle(new ResourceBundle(
bundle->getWithFallback(key, status)));
if (!U_SUCCESS(status)) {
std::string eMsg = "can't get resource bundle for key '";
eMsg += key;
eMsg += "' and locale '";
eMsg += bundle->getLocale().getName();
eMsg += "'";
throw std::invalid_argument(eMsg);
}
return resourceBundle;
}
/*------------------------------------------------------------------------------
* Get a string from a resource bundle in the ICU string format
*----------------------------------------------------------------------------*/
Ptr<UnicodeString>::Ref
LocalizedObject :: getResourceString(Ptr<ResourceBundle>::Ref bundle,
const char * key)
throw (std::invalid_argument)
{
Ptr<ResourceBundle>::Ref rb = getBundle(bundle, key);
if (rb->getType() == URES_STRING) {
UErrorCode status = U_ZERO_ERROR;
Ptr<UnicodeString>::Ref str(new UnicodeString(rb->getString(status)));
if (!U_SUCCESS(status)) {
throw std::invalid_argument("requested resource not a string");
}
return str;
} else {
throw std::invalid_argument("requested resource not a string");
}
}
/*------------------------------------------------------------------------------
* Format a message
*----------------------------------------------------------------------------*/
Ptr<UnicodeString>::Ref
LocalizedObject :: formatMessage(Ptr<const UnicodeString>::Ref pattern,
Formattable * arguments,
unsigned int nArguments)
throw (std::invalid_argument)
{
Ptr<UnicodeString>::Ref message(new UnicodeString());
UErrorCode err = U_ZERO_ERROR;
MessageFormat::format(*pattern, arguments, nArguments, *message, err);
if (!U_SUCCESS(err)) {
throw std::invalid_argument("can't format string");
}
return message;
}
/*------------------------------------------------------------------------------
* Format a message, based on a resource key for its pattern
*----------------------------------------------------------------------------*/
Ptr<Glib::ustring>::Ref
LocalizedObject :: formatMessage(const char * patternKey,
Formattable * arguments,
unsigned int nArguments)
throw (std::invalid_argument)
{
return unicodeStringToUstring(
formatMessage(getResourceString(patternKey), arguments, nArguments));
}
/*------------------------------------------------------------------------------
* Format a message, based on a resource key for its pattern
* and one argument for formatting.
*----------------------------------------------------------------------------*/
Ptr<Glib::ustring>::Ref
LocalizedObject :: formatMessage(const std::string & patternKey,
const Glib::ustring & argument1)
throw (std::invalid_argument)
{
Ptr<UnicodeString>::Ref uArgument1 = ustringToUnicodeString(argument1);
Formattable arguments[] = { *uArgument1 };
return formatMessage(patternKey, arguments, 1);
}
/*------------------------------------------------------------------------------
* Format a message, based on a resource key for its pattern
* and two arguments for formatting.
*----------------------------------------------------------------------------*/
Ptr<Glib::ustring>::Ref
LocalizedObject :: formatMessage(const std::string & patternKey,
const Glib::ustring & argument1,
const Glib::ustring & argument2)
throw (std::invalid_argument)
{
Ptr<UnicodeString>::Ref uArgument1 = ustringToUnicodeString(argument1);
Ptr<UnicodeString>::Ref uArgument2 = ustringToUnicodeString(argument2);
Formattable arguments[] = { *uArgument1,
*uArgument2 };
return formatMessage(patternKey, arguments, 2);
}
/*------------------------------------------------------------------------------
* Format a message, based on a resource key for its pattern
* and one argument for formatting.
*----------------------------------------------------------------------------*/
Ptr<Glib::ustring>::Ref
LocalizedObject :: formatMessage(const std::string & patternKey,
const Glib::ustring & argument1,
const Glib::ustring & argument2,
const Glib::ustring & argument3)
throw (std::invalid_argument)
{
Ptr<UnicodeString>::Ref uArgument1 = ustringToUnicodeString(argument1);
Ptr<UnicodeString>::Ref uArgument2 = ustringToUnicodeString(argument2);
Ptr<UnicodeString>::Ref uArgument3 = ustringToUnicodeString(argument3);
Formattable arguments[] = { *uArgument1,
*uArgument2,
*uArgument3 };
return formatMessage(patternKey, arguments, 3);
}
/*------------------------------------------------------------------------------
* Create a Glib ustring from an ICU UnicodeString
*----------------------------------------------------------------------------*/
Ptr<Glib::ustring>::Ref
LocalizedObject :: unicodeStringToUstring(
Ptr<const UnicodeString>::Ref unicodeString)
throw ()
{
const UChar * uchars = unicodeString->getBuffer();
int32_t length = unicodeString->length();
Ptr<Glib::ustring>::Ref ustr(new Glib::ustring());
ustr->reserve(length);
while (length--) {
ustr->push_back((gunichar) (*(uchars++)));
}
return ustr;
}
/*------------------------------------------------------------------------------
* Create an ICU UnicodeString from a Glib ustring
*----------------------------------------------------------------------------*/
Ptr<UnicodeString>::Ref
LocalizedObject :: ustringToUnicodeString(
Ptr<const Glib::ustring>::Ref gString)
throw ()
{
Ptr<UnicodeString>::Ref uString(new UnicodeString());
Glib::ustring::const_iterator it = gString->begin();
Glib::ustring::const_iterator end = gString->end();
while (it < end) {
uString->append((UChar32) *it++);
}
return uString;
}
/*------------------------------------------------------------------------------
* Create an ICU UnicodeString from a Glib ustring
*----------------------------------------------------------------------------*/
Ptr<UnicodeString>::Ref
LocalizedObject :: ustringToUnicodeString(const Glib::ustring & gString)
throw ()
{
Ptr<UnicodeString>::Ref uString(new UnicodeString());
Glib::ustring::const_iterator it = gString.begin();
Glib::ustring::const_iterator end = gString.end();
while (it < end) {
uString->append((UChar32) *it++);
}
return uString;
}
/*------------------------------------------------------------------------------
* Get a string from a resource bundle in the ICU string format
*----------------------------------------------------------------------------*/
Ptr<Glib::ustring>::Ref
LocalizedObject :: getBinaryResourceAsUstring(const char * key)
throw (std::invalid_argument)
{
Ptr<ResourceBundle>::Ref rb = getBundle(key);
if (rb->getType() == URES_BINARY) {
int32_t length;
UErrorCode status = U_ZERO_ERROR;
const uint8_t * data = rb->getBinary(length, status);
if (!U_SUCCESS(status)) {
throw std::invalid_argument("could not get requested "
"binary resource");
}
char * strBuf = new char[length + 1];
memcpy(strBuf, data, length);
strBuf[length] = 0;
Ptr<Glib::ustring>::Ref string(new Glib::ustring(strBuf));
if (string->validate()) {
return string;
} else {
std::string errorMessage = "invalid UTF-8 sequence found ";
errorMessage += "in resource '";
errorMessage += key;
errorMessage += "'";
throw std::invalid_argument(errorMessage);
}
} else {
throw std::invalid_argument("requested resource is not a binary value");
}
}

View File

@ -1,342 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <string>
#include <iostream>
#include <unicode/resbund.h>
#include "LiveSupport/Core/LocalizedObject.h"
#include "LocalizedObjectTest.h"
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
CPPUNIT_TEST_SUITE_REGISTRATION(LocalizedObjectTest);
/**
* The name of the configuration file for the resource bundle.
*/
static const std::string configFileName = "etc/resourceBundle.xml";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Set up the test environment
*----------------------------------------------------------------------------*/
void
LocalizedObjectTest :: setUp(void) throw ()
{
}
/*------------------------------------------------------------------------------
* Clean up the test environment
*----------------------------------------------------------------------------*/
void
LocalizedObjectTest :: tearDown(void) throw ()
{
}
/*------------------------------------------------------------------------------
* A simple smoke test.
*----------------------------------------------------------------------------*/
void
LocalizedObjectTest :: simpleTest(void)
throw (CPPUNIT_NS::Exception)
{
UErrorCode status = U_ZERO_ERROR;
Ptr<ResourceBundle>::Ref bundle(new ResourceBundle("./tmp/" PACKAGE_NAME,
"root",
status));
CPPUNIT_ASSERT(U_SUCCESS(status));
try {
Ptr<LocalizedObject>::Ref locObj(new LocalizedObject(bundle));
Ptr<LocalizedObject>::Ref section1(new LocalizedObject(
locObj->getBundle("section1")));
Ptr<UnicodeString>::Ref foo = section1->getResourceString("foo");
CPPUNIT_ASSERT(foo->compare("foo") == 0);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL(e.what());
}
}
/*------------------------------------------------------------------------------
* A test to see different locales and fallback to work.
*----------------------------------------------------------------------------*/
void
LocalizedObjectTest :: fallbackTest(void)
throw (CPPUNIT_NS::Exception)
{
UErrorCode status = U_ZERO_ERROR;
Ptr<ResourceBundle>::Ref rootBundle;
Ptr<ResourceBundle>::Ref enBundle;
rootBundle.reset(new ResourceBundle("./tmp/" PACKAGE_NAME, "root", status));
CPPUNIT_ASSERT(U_SUCCESS(status));
enBundle.reset(new ResourceBundle("./tmp/" PACKAGE_NAME, "en", status));
CPPUNIT_ASSERT(U_SUCCESS(status));
// first, see the root bundle
try {
Ptr<LocalizedObject>::Ref locObj(new LocalizedObject(rootBundle));
Ptr<LocalizedObject>::Ref section1(new LocalizedObject(
locObj->getBundle("section1")));
Ptr<UnicodeString>::Ref foo = section1->getResourceString("foo");
CPPUNIT_ASSERT(foo->compare("foo") == 0);
Ptr<UnicodeString>::Ref bar = section1->getResourceString("bar");
CPPUNIT_ASSERT(bar->compare("bar") == 0);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL(e.what());
}
// now, the en bundle
try {
Ptr<LocalizedObject>::Ref locObj(new LocalizedObject(enBundle));
Ptr<LocalizedObject>::Ref section1(new LocalizedObject(
locObj->getBundle("section1")));
Ptr<UnicodeString>::Ref foo = section1->getResourceString("foo");
CPPUNIT_ASSERT(foo->compare("fou") == 0);
Ptr<UnicodeString>::Ref bar = section1->getResourceString("bar");
CPPUNIT_ASSERT(bar->compare("bar") == 0);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL(e.what());
}
}
/*------------------------------------------------------------------------------
* A test to see funny unicode characters to work.
*----------------------------------------------------------------------------*/
void
LocalizedObjectTest :: unicodeTest(void)
throw (CPPUNIT_NS::Exception)
{
UErrorCode status = U_ZERO_ERROR;
Ptr<ResourceBundle>::Ref huBundle;
Ptr<ResourceBundle>::Ref jpBundle;
huBundle.reset(new ResourceBundle("./tmp/" PACKAGE_NAME, "hu", status));
CPPUNIT_ASSERT(U_SUCCESS(status));
try {
Ptr<LocalizedObject>::Ref locObj(new LocalizedObject(huBundle));
Ptr<LocalizedObject>::Ref section1(new LocalizedObject(
locObj->getBundle("section1")));
Ptr<UnicodeString>::Ref foo = section1->getResourceString("foo");
CPPUNIT_ASSERT(foo->charAt(0) == 0x0066); // 'f'
CPPUNIT_ASSERT(foo->charAt(1) == 0x00fa); // 'u' with acute
Ptr<UnicodeString>::Ref bar = section1->getResourceString("bar");
CPPUNIT_ASSERT(bar->charAt(0) == 0x0062); // 'b'
CPPUNIT_ASSERT(bar->charAt(1) == 0x00e1); // 'a' with acute
CPPUNIT_ASSERT(bar->charAt(2) == 0x0072); // 'r'
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL(e.what());
}
jpBundle.reset(new ResourceBundle("./tmp/" PACKAGE_NAME, "jp", status));
CPPUNIT_ASSERT(U_SUCCESS(status));
try {
Ptr<LocalizedObject>::Ref locObj(new LocalizedObject(jpBundle));
Ptr<LocalizedObject>::Ref section1(new LocalizedObject(
locObj->getBundle("section1")));
Ptr<UnicodeString>::Ref foo = section1->getResourceString("foo");
CPPUNIT_ASSERT(foo->charAt(0) == 0x3075); // hiragana fu
Ptr<UnicodeString>::Ref bar = section1->getResourceString("bar");
CPPUNIT_ASSERT(bar->charAt(0) == 0x3070); // hiragana ba
CPPUNIT_ASSERT(bar->charAt(1) == 0x308b); // hiragana ru
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL(e.what());
}
}
/*------------------------------------------------------------------------------
* Test message formatting.
*----------------------------------------------------------------------------*/
void
LocalizedObjectTest :: formatMessageTest(void)
throw (CPPUNIT_NS::Exception)
{
UErrorCode status = U_ZERO_ERROR;
Ptr<ResourceBundle>::Ref bundle(new ResourceBundle("./tmp/" PACKAGE_NAME,
"root",
status));
CPPUNIT_ASSERT(U_SUCCESS(status));
try {
Ptr<Glib::ustring>::Ref message;
Ptr<LocalizedObject>::Ref locObj(new LocalizedObject(bundle));
Ptr<LocalizedObject>::Ref messages(new LocalizedObject(
locObj->getBundle("messages")));
Formattable arguments[] = { "p1", "p2" };
// test formatting through a key
message = messages->formatMessage("aMessage", arguments, 2);
CPPUNIT_ASSERT(*message == "parameter 0: p1, parameter 1: p2");
// test formatting through an explicit pattern
Ptr<UnicodeString>::Ref uMessage;
Ptr<UnicodeString>::Ref pattern(new UnicodeString(
"only 1 parameter: {0}"));
uMessage = LocalizedObject::formatMessage(pattern, arguments, 1);
CPPUNIT_ASSERT(uMessage->compare("only 1 parameter: p1") == 0);
// test formatting through a key, and a fixed number of parameters
message = messages->formatMessage("aMessage3Args", "p0");
CPPUNIT_ASSERT(*message == "p0: p0, p2: {2}, p1: {1}");
message = messages->formatMessage("aMessage3Args", "p0", "p1");
CPPUNIT_ASSERT(*message == "p0: p0, p2: {2}, p1: p1");
message = messages->formatMessage("aMessage3Args", "p0", "p1", "p2");
CPPUNIT_ASSERT(*message == "p0: p0, p2: p2, p1: p1");
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL(e.what());
}
}
/*------------------------------------------------------------------------------
* Test to see if resource bundle can be loaded based on a config file
*----------------------------------------------------------------------------*/
void
LocalizedObjectTest :: loadFromConfigTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<ResourceBundle>::Ref bundle;
try {
Ptr<xmlpp::DomParser>::Ref parser(
new xmlpp::DomParser(configFileName, true));
const xmlpp::Document * document = parser->get_document();
const xmlpp::Element * root = document->get_root_node();
bundle = LocalizedObject::getBundle(*root);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL("semantic error in configuration file");
} catch (std::exception &e) {
CPPUNIT_FAIL(e.what());
}
CPPUNIT_ASSERT(bundle.get());
// now, see if this really is the en bundle
try {
Ptr<LocalizedObject>::Ref locObj(new LocalizedObject(bundle));
Ptr<LocalizedObject>::Ref section1(new LocalizedObject(
locObj->getBundle("section1")));
Ptr<UnicodeString>::Ref foo = section1->getResourceString("foo");
CPPUNIT_ASSERT(foo->compare("fou") == 0);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL(e.what());
}
}
/*------------------------------------------------------------------------------
* Test the ustring related functions.
*----------------------------------------------------------------------------*/
void
LocalizedObjectTest :: ustringTest(void)
throw (CPPUNIT_NS::Exception)
{
UErrorCode status = U_ZERO_ERROR;
Ptr<ResourceBundle>::Ref bundle(new ResourceBundle("./tmp/" PACKAGE_NAME,
"root",
status));
CPPUNIT_ASSERT(U_SUCCESS(status));
// test getting an ustring resource
try {
Ptr<LocalizedObject>::Ref locObj(new LocalizedObject(bundle));
Ptr<LocalizedObject>::Ref section1(new LocalizedObject(
locObj->getBundle("section1")));
Ptr<Glib::ustring>::Ref foo = section1->getResourceUstring("foo");
CPPUNIT_ASSERT(*foo == "foo");
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL(e.what());
}
// test message formatting to ustring
try {
Ptr<Glib::ustring>::Ref message;
Ptr<LocalizedObject>::Ref locObj(new LocalizedObject(bundle));
Ptr<LocalizedObject>::Ref messages(new LocalizedObject(
locObj->getBundle("messages")));
Formattable arguments[] = { "p1", "p2" };
// test formatting through a key
message = messages->formatMessage("aMessage", arguments, 2);
CPPUNIT_ASSERT(*message == "parameter 0: p1, parameter 1: p2");
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL(e.what());
}
}
/*------------------------------------------------------------------------------
* Test the ustring related functions in problematic situations
* see http://bugs.campware.org/view.php?id=792
*----------------------------------------------------------------------------*/
void
LocalizedObjectTest :: ustringNegativeTest(void)
throw (CPPUNIT_NS::Exception)
{
bool gotException;
UErrorCode status = U_ZERO_ERROR;
Ptr<ResourceBundle>::Ref bundle(new ResourceBundle("./tmp/" PACKAGE_NAME,
"root",
status));
CPPUNIT_ASSERT(U_SUCCESS(status));
// test getting a missing ustring resource
gotException = false;
try {
Ptr<LocalizedObject>::Ref locObj(new LocalizedObject(bundle));
Ptr<LocalizedObject>::Ref section1(new LocalizedObject(
locObj->getBundle("section1")));
Ptr<Glib::ustring>::Ref foo =
section1->getResourceUstring("nonexistentKey");
} catch (std::invalid_argument &e) {
gotException = true;
}
CPPUNIT_ASSERT(gotException);
}

View File

@ -1,156 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LocalizedObjectTest_h
#define LocalizedObjectTest_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <cppunit/extensions/HelperMacros.h>
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Unit test for the LocalizedObject class.
*
* @see LocalizedObject
*/
class LocalizedObjectTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(LocalizedObjectTest);
CPPUNIT_TEST(simpleTest);
CPPUNIT_TEST(fallbackTest);
CPPUNIT_TEST(unicodeTest);
CPPUNIT_TEST(formatMessageTest);
CPPUNIT_TEST(loadFromConfigTest);
CPPUNIT_TEST(ustringTest);
CPPUNIT_TEST(ustringNegativeTest);
CPPUNIT_TEST_SUITE_END();
protected:
/**
* A simple smoke test.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
simpleTest(void) throw (CPPUNIT_NS::Exception);
/**
* Test to see if multiple locales work, and they fall back to
* more generic values.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
fallbackTest(void) throw (CPPUNIT_NS::Exception);
/**
* Test to see if funny unicode characters work properly.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
unicodeTest(void) throw (CPPUNIT_NS::Exception);
/**
* A test to see if message formatting works all right.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
formatMessageTest(void) throw (CPPUNIT_NS::Exception);
/**
* A test to see if a resource bundle can be loaded based on a
* configuration file
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
loadFromConfigTest(void) throw (CPPUNIT_NS::Exception);
/**
* A test to check the Glib::ustring related functions.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
ustringTest(void) throw (CPPUNIT_NS::Exception);
/**
* A test to check the Glib::ustring related function beaviour
* in problematic situations.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
ustringNegativeTest(void) throw (CPPUNIT_NS::Exception);
public:
/**
* Set up the environment for the test case.
*/
void
setUp(void) throw ();
/**
* Clean up the environment after the test case.
*/
void
tearDown(void) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LocalizedObjectTest_h

View File

@ -1,586 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------
This class is based on the following with minor modifications
(see http://userpages.umbc.edu/~mabzug1/cs/md5/md5.html).
------------------------------------------------------------------------------
// Md5.CC - source code for the C++/object oriented translation and
// modification of Md5.
// Translation and modification (c) 1995 by Mordechai T. Abzug
// This translation/ modification is provided "as is," without express or
// implied warranty of any kind.
// The translator/ modifier does not claim (1) that Md5 will do what you think
// it does; (2) that this translation/ modification is accurate; or (3) that
// this software is "merchantible." (Language for this disclaimer partially
// copied from the disclaimer below).
------------------------------------------------------------------------------
Which was based on:
------------------------------------------------------------------------------
Md5.H - header file for Md5C.C
MDDRIVER.C - test driver for MD2, MD4 and Md5
Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
rights reserved.
License to copy and use this software is granted provided that it
is identified as the "RSA Data Security, Inc. Md5 Message-Digest
Algorithm" in all material mentioning or referencing this software
or this function.
License is also granted to make and use derivative works provided
that such works are identified as "derived from the RSA Data
Security, Inc. Md5 Message-Digest Algorithm" in all material
mentioning or referencing the derived work.
RSA Data Security, Inc. makes no representations concerning either
the merchantability of this software or the suitability of this
software for any particular purpose. It is provided "as is"
without express or implied warranty of any kind.
These notices must be retained in any copies of any part of this
documentation and/or software.
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#include "LiveSupport/Core/Md5.h"
#include <assert.h>
#include <string>
#include <iostream>
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Construct from a string.
*----------------------------------------------------------------------------*/
Md5::Md5(const std::string &s) throw(std::invalid_argument)
{
init();
update (s);
finalize();
calcNumericRepresentation();
}
/*------------------------------------------------------------------------------
* Construct from an istream.
*----------------------------------------------------------------------------*/
Md5::Md5(std::istream& stream) throw(std::invalid_argument)
{
init();
update (stream);
finalize();
calcNumericRepresentation();
}
/*------------------------------------------------------------------------------
* Construct from a file.
*----------------------------------------------------------------------------*/
Md5::Md5(FILE *file) throw(std::invalid_argument)
{
init();
update(file);
finalize ();
calcNumericRepresentation();
}
/*------------------------------------------------------------------------------
* Output the md5 sum as a hexadecimal string.
*----------------------------------------------------------------------------*/
std::string Md5::hexDigest() throw()
{
std::stringstream strStr;
for (int i=0; i<16; i++) {
strStr << std::hex << std::setw(2) << std::setfill('0')
<< int(digest[i]);
}
return strStr.str();
}
/*------------------------------------------------------------------------------
* Calculate the numeric representation of the checksum
*----------------------------------------------------------------------------*/
void
Md5 :: calcNumericRepresentation(void) throw ()
{
low64 = (uint64_t) digest[15];
low64 |= ((uint64_t) digest[14]) << 8;
low64 |= ((uint64_t) digest[13]) << 16;
low64 |= ((uint64_t) digest[12]) << 24;
low64 |= ((uint64_t) digest[11]) << 32;
low64 |= ((uint64_t) digest[10]) << 40;
low64 |= ((uint64_t) digest[9]) << 48;
low64 |= ((uint64_t) digest[8]) << 56;
high64 = (uint64_t) digest[7];
high64 |= ((uint64_t) digest[6]) << 8;
high64 |= ((uint64_t) digest[5]) << 16;
high64 |= ((uint64_t) digest[4]) << 24;
high64 |= ((uint64_t) digest[3]) << 32;
high64 |= ((uint64_t) digest[2]) << 40;
high64 |= ((uint64_t) digest[1]) << 48;
high64 |= ((uint64_t) digest[0]) << 56;
}
/*------------------------------------------------------------------------------
* Convert the md5 sum to a hexadecimal string.
*----------------------------------------------------------------------------*/
Md5::operator std::string() throw()
{
return hexDigest();
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ private methods */
// Md5 block update operation. Continues an Md5 message-digest
// operation, processing another message block, and updating the
// context.
void Md5::update (uint1 *input, uint4 input_length)
{
uint4 input_index, buffer_index;
uint4 buffer_space; // how much space is left in buffer
if (finalized){ // so we can't update!
throw std::invalid_argument("Md5::update: "
"Can't update a finalized digest!");
}
// Compute number of bytes mod 64
buffer_index = (unsigned int)((count[0] >> 3) & 0x3F);
// Update number of bits
if ( (count[0] += ((uint4) input_length << 3))<((uint4) input_length << 3) )
count[1]++;
count[1] += ((uint4)input_length >> 29);
buffer_space = 64 - buffer_index; // how much space is left in buffer
// Transform as many times as possible.
if (input_length >= buffer_space) { // ie. we have enough to fill the buffer
// fill the rest of the buffer and transform
memcpy (buffer + buffer_index, input, buffer_space);
transform (buffer);
// now, transform each 64-byte piece of the input, bypassing the buffer
for (input_index = buffer_space; input_index + 63 < input_length;
input_index += 64) {
transform (input+input_index);
}
buffer_index = 0; // so we can buffer remaining
} else {
input_index=0; // so we can buffer the whole input
}
// and here we do the buffering:
memcpy(buffer+buffer_index, input+input_index, input_length-input_index);
}
// Md5 update for files.
// Like above, except that it works on files (and uses above as a primitive.)
void Md5::update(FILE *file)
{
uint1 buffer[1024];
uint4 len;
while ((len=fread(buffer, 1, 1024, file)))
update(buffer, len);
// deleted by me (fgerlits) to make it work more like the istream version
// fclose (file);
}
// Md5 update for istreams.
// Like update for files; see above.
void Md5::update(std::istream& stream)
{
uint1 buffer[1024];
uint4 len;
while (stream.good()){ // note that return value of read is unusable.
stream.read((char *)buffer, 1024);
len=stream.gcount();
update(buffer, len);
}
}
// Md5 update for strings.
// Like update for files; see above.
void Md5::update(const std::string &s)
{
uint1 buffer[1024];
uint4 len;
uint4 pos = 0;
while (pos < s.size()){
len = s.copy((char *)buffer, 1024, pos);
update(buffer, len);
pos += len;
}
}
// Md5 finalization. Ends an Md5 message-digest operation, writing the
// the message digest and zeroizing the context.
void Md5::finalize () throw (std::invalid_argument)
{
uint1 bits[8];
uint4 index, padLen;
static uint1 PADDING[64]={
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
if (finalized){
throw std::invalid_argument("Md5::finalize: "
"Already finalized this digest!");
}
// Save number of bits
encode (bits, count, 8);
// Pad out to 56 mod 64.
index = (uint4) ((count[0] >> 3) & 0x3f);
padLen = (index < 56) ? (56 - index) : (120 - index);
update (PADDING, padLen);
// Append length (before padding)
update (bits, 8);
// Store state in digest
encode (digest, state, 16);
// Zeroize sensitive information
memset (buffer, 0, sizeof(*buffer));
finalized=1;
}
// PRIVATE METHODS:
void Md5::init(){
finalized=0; // we just started!
// Nothing counted, so count=0
count[0] = 0;
count[1] = 0;
// Load magic initialization constants.
state[0] = 0x67452301;
state[1] = 0xefcdab89;
state[2] = 0x98badcfe;
state[3] = 0x10325476;
}
// Constants for Md5Transform routine.
// Although we could use C++ style constants, defines are actually better,
// since they let us easily evade scope clashes.
#define S11 7
#define S12 12
#define S13 17
#define S14 22
#define S21 5
#define S22 9
#define S23 14
#define S24 20
#define S31 4
#define S32 11
#define S33 16
#define S34 23
#define S41 6
#define S42 10
#define S43 15
#define S44 21
// Md5 basic transformation. Transforms state based on block.
void Md5::transform (uint1 block[64]){
uint4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
decode (x, block, 64);
assert(!finalized); // not just a user error, since the method is private
/* Round 1 */
FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
/* Round 2 */
GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
/* Round 3 */
HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
/* Round 4 */
II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
// Zeroize sensitive information.
memset ( (uint1 *) x, 0, sizeof(x));
}
// Encodes input (UINT4) into output (unsigned char). Assumes len is
// a multiple of 4.
void Md5::encode (uint1 *output, uint4 *input, uint4 len) {
unsigned int i, j;
for (i = 0, j = 0; j < len; i++, j += 4) {
output[j] = (uint1) (input[i] & 0xff);
output[j+1] = (uint1) ((input[i] >> 8) & 0xff);
output[j+2] = (uint1) ((input[i] >> 16) & 0xff);
output[j+3] = (uint1) ((input[i] >> 24) & 0xff);
}
}
// Decodes input (unsigned char) into output (UINT4). Assumes len is
// a multiple of 4.
void Md5::decode (uint4 *output, uint1 *input, uint4 len){
unsigned int i, j;
for (i = 0, j = 0; j < len; i++, j += 4)
output[i] = ((uint4)input[j]) | (((uint4)input[j+1]) << 8) |
(((uint4)input[j+2]) << 16) | (((uint4)input[j+3]) << 24);
}
// Note: Replace "for loop" with standard memcpy if possible.
void Md5::memcpy (uint1 *output, uint1 *input, uint4 len){
unsigned int i;
for (i = 0; i < len; i++)
output[i] = input[i];
}
// Note: Replace "for loop" with standard memset if possible.
void Md5::memset (uint1 *output, uint1 value, uint4 len){
unsigned int i;
for (i = 0; i < len; i++)
output[i] = value;
}
// ROTATE_LEFT rotates x left n bits.
inline unsigned int Md5::rotate_left (uint4 x, uint4 n){
return (x << n) | (x >> (32-n)) ;
}
// F, G, H and I are basic Md5 functions.
inline unsigned int Md5::F (uint4 x, uint4 y, uint4 z){
return (x & y) | (~x & z);
}
inline unsigned int Md5::G (uint4 x, uint4 y, uint4 z){
return (x & z) | (y & ~z);
}
inline unsigned int Md5::H (uint4 x, uint4 y, uint4 z){
return x ^ y ^ z;
}
inline unsigned int Md5::I (uint4 x, uint4 y, uint4 z){
return y ^ (x | ~z);
}
// FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
// Rotation is separate from addition to prevent recomputation.
inline void Md5::FF(uint4& a, uint4 b, uint4 c, uint4 d, uint4 x,
uint4 s, uint4 ac){
a += F(b, c, d) + x + ac;
a = rotate_left (a, s) +b;
}
inline void Md5::GG(uint4& a, uint4 b, uint4 c, uint4 d, uint4 x,
uint4 s, uint4 ac){
a += G(b, c, d) + x + ac;
a = rotate_left (a, s) +b;
}
inline void Md5::HH(uint4& a, uint4 b, uint4 c, uint4 d, uint4 x,
uint4 s, uint4 ac){
a += H(b, c, d) + x + ac;
a = rotate_left (a, s) +b;
}
inline void Md5::II(uint4& a, uint4 b, uint4 c, uint4 d, uint4 x,
uint4 s, uint4 ac){
a += I(b, c, d) + x + ac;
a = rotate_left (a, s) +b;
}

View File

@ -1,113 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#else
#error "Need unistd.h"
#endif
#include <string>
#include <iostream>
#include "LiveSupport/Core/Md5.h"
#include "Md5Test.h"
using namespace std;
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
CPPUNIT_TEST_SUITE_REGISTRATION(Md5Test);
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Set up the test environment
*----------------------------------------------------------------------------*/
void
Md5Test :: setUp(void) throw ()
{
}
/*------------------------------------------------------------------------------
* Clean up the test environment
*----------------------------------------------------------------------------*/
void
Md5Test :: tearDown(void) throw ()
{
}
/*------------------------------------------------------------------------------
* Test to see if we can construct some simple md5 sums
*----------------------------------------------------------------------------*/
void
Md5Test :: firstTest(void)
throw (CPPUNIT_NS::Exception)
{
// test the construction from string
Md5 emptyString("");
CPPUNIT_ASSERT(emptyString.hexDigest()
== "d41d8cd98f00b204e9800998ecf8427e");
Md5 someString("Some other random string.");
CPPUNIT_ASSERT(someString.hexDigest()
== "9007a3599f5d3ae2ac11a29308f964eb");
std::string s = someString;
CPPUNIT_ASSERT(s == "9007a3599f5d3ae2ac11a29308f964eb");
CPPUNIT_ASSERT(someString.low64bits() == 0xac11a29308f964ebLL);
CPPUNIT_ASSERT(someString.high64bits() == 0x9007a3599f5d3ae2LL);
// test the construction from a FILE*
FILE *f = fopen("var/md5test.data", "r");
Md5 testFile(f);
CPPUNIT_ASSERT(testFile.hexDigest()
== "fc359d2b366cc110db86c3d68bdf39c4");
fclose(f);
// test the construction from an istream
std::ifstream ifs("var/md5test.data");
Md5 testFileStream(ifs);
CPPUNIT_ASSERT(testFileStream.hexDigest()
== "fc359d2b366cc110db86c3d68bdf39c4");
ifs.close();
}

View File

@ -1,99 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef Md5Test_h
#define Md5Test_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <cppunit/extensions/HelperMacros.h>
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Unit test for the Md5 class.
*
* @see Md5
*/
class Md5Test : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(Md5Test);
CPPUNIT_TEST(firstTest);
CPPUNIT_TEST_SUITE_END();
protected:
/**
* A simple test.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
firstTest(void) throw (CPPUNIT_NS::Exception);
public:
/**
* Set up the environment for the test case.
*/
void
setUp(void) throw ();
/**
* Clean up the environment after the test case.
*/
void
tearDown(void) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // Md5Test_h

View File

@ -1,110 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#include "NumericConstraint.h"
#include "NumericRangeConstraint.h"
#include "EnumerationConstraint.h"
#include "LiveSupport/Core/MetadataConstraint.h"
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* The name of the config element for this class
*----------------------------------------------------------------------------*/
const std::string MetadataConstraint::configElementNameStr = "constraint";
/*------------------------------------------------------------------------------
* The name of the type attribute.
*----------------------------------------------------------------------------*/
const std::string MetadataConstraint::typeAttributeName = "type";
/*------------------------------------------------------------------------------
* The name of the configuration element for the constraint values.
*----------------------------------------------------------------------------*/
const std::string MetadataConstraint::valueElementName = "value";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Create a constraint element object based on an XML element.
*----------------------------------------------------------------------------*/
void
MetadataConstraint :: configure(const xmlpp::Element & element)
throw (std::invalid_argument)
{
if (element.get_name() != configElementNameStr) {
throw std::invalid_argument("bad configuration element "
+ element.get_name());
}
const xmlpp::Attribute* typeAttribute;
if (!(typeAttribute = element.get_attribute(typeAttributeName))) {
throw std::invalid_argument("missing attribute " + typeAttributeName);
}
std::string type = typeAttribute->get_value();
if (type == "numeric") {
concreteConstraint.reset(new NumericConstraint());
concreteConstraint->configure(element);
} else if (type == "numericRange") {
concreteConstraint.reset(new NumericRangeConstraint());
concreteConstraint->configure(element);
} else if (type == "enumeration") {
concreteConstraint.reset(new EnumerationConstraint());
concreteConstraint->configure(element);
} else {
throw std::invalid_argument("unknown metadata constraint" + type);
}
}
/*------------------------------------------------------------------------------
* Check that the given value satisfies the constraint.
*----------------------------------------------------------------------------*/
inline bool
MetadataConstraint :: check(Ptr<const Glib::ustring>::Ref value) const
throw (std::logic_error)
{
if (concreteConstraint) {
return concreteConstraint->check(value);
} else {
throw std::logic_error("MetadataConstraint not configured yet");
}
}

View File

@ -1,195 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include "LiveSupport/Core/MetadataTypeContainer.h"
#include "LiveSupport/Core/MetadataType.h"
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* The name of the config element for this class
*----------------------------------------------------------------------------*/
const std::string MetadataType::configElementNameStr = "metadataType";
/**
* The name of the attribute of the DC name in the metadataType element.
*/
static const std::string dcNameAttrName = "dcName";
/**
* The name of the attribute of the ID3v2 tag in the metadataType element
*/
static const std::string id3TagAttrName = "id3Tag";
/**
* The name of the attribute of the localization key in the
* metadataType element.
*/
static const std::string localizationKeyAttrName = "localizationKey";
/**
* The name of the attribute of the tab name in the metadataType element
*/
static const std::string tabAttrName = "tab";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Constructor.
*----------------------------------------------------------------------------*/
MetadataType :: MetadataType(Ptr<MetadataTypeContainer>::Ref container)
throw ()
: container(container),
tab(noTab)
{
}
/*------------------------------------------------------------------------------
* Constructor.
*----------------------------------------------------------------------------*/
MetadataType :: MetadataType(Ptr<MetadataTypeContainer>::Ref container,
Glib::ustring dcName,
Glib::ustring id3Tag,
Glib::ustring localizationKey,
TabType tab)
throw ()
: container(container),
tab(tab)
{
this->dcName.reset(new Glib::ustring(dcName));
this->id3Tag.reset(new Glib::ustring(id3Tag));
this->localizationKey.reset(new Glib::ustring(localizationKey));
}
/*------------------------------------------------------------------------------
* Create a metadata type element object based on an XML element.
*----------------------------------------------------------------------------*/
void
MetadataType :: configure(const xmlpp::Element & element)
throw (std::invalid_argument)
{
if (element.get_name() != configElementNameStr) {
throw std::invalid_argument("bad configuration element "
+ element.get_name());
}
const xmlpp::Attribute* attribute;
// set the DC name
if (!(attribute = element.get_attribute(dcNameAttrName))) {
throw std::invalid_argument("missing attribute " + dcNameAttrName);
}
dcName.reset(new Glib::ustring(attribute->get_value()));
// get the ID3v2 tag name, optional
if ((attribute = element.get_attribute(id3TagAttrName))) {
id3Tag.reset(new Glib::ustring(attribute->get_value()));
}
// get the localization key
if (!(attribute = element.get_attribute(localizationKeyAttrName))) {
throw std::invalid_argument("missing attribute "
+ localizationKeyAttrName);
}
localizationKey.reset(new Glib::ustring(attribute->get_value()));
// get the tab, optional
tab = noTab;
if ((attribute = element.get_attribute(tabAttrName))) {
Glib::ustring tabString = attribute->get_value();
if (tabString == "main") {
tab = mainTab;
} else if (tabString == "music") {
tab = musicTab;
} else if (tabString == "voice") {
tab = voiceTab;
}
}
// get the constraint, optional
xmlpp::Node::NodeList childNodes = element.get_children(
MetadataConstraint::getConfigElementName());
xmlpp::Node::NodeList::iterator it = childNodes.begin();
if (it != childNodes.end()) {
const xmlpp::Element * constraintElement
= dynamic_cast<const xmlpp::Element*> (*it);
if (constraintElement) {
constraint.reset(new MetadataConstraint());
constraint->configure(*constraintElement);
}
}
}
/*------------------------------------------------------------------------------
* Return the localized name for this metadata type.
*----------------------------------------------------------------------------*/
Ptr<const Glib::ustring>::Ref
MetadataType :: getLocalizedName(void) const
throw (std::invalid_argument)
{
return container->getResourceUstring(*localizationKey);
}
/*------------------------------------------------------------------------------
* Check that the given value satisfies the constraint.
*----------------------------------------------------------------------------*/
bool
MetadataType :: check(Ptr<const Glib::ustring>::Ref value) const
throw ()
{
if (!value) {
return false;
}
if (constraint) {
try {
return constraint->check(value);
} catch (std::logic_error &e) {
return false;
}
} else {
return true;
}
}

View File

@ -1,181 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include "LiveSupport/Core/MetadataTypeContainer.h"
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* The name of the config element for this class
*----------------------------------------------------------------------------*/
const std::string MetadataTypeContainer::configElementNameStr
= "metadataTypeContainer";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Create a metadata type container element object based on an XML element.
*----------------------------------------------------------------------------*/
void
MetadataTypeContainer :: configure(const xmlpp::Element & element)
throw (std::invalid_argument)
{
if (element.get_name() != configElementNameStr) {
throw std::invalid_argument("bad configuration element "
+ element.get_name());
}
// get the metadataType child elements, and process them
xmlpp::Node::NodeList childNodes = element.get_children(
MetadataType::getConfigElementName());
xmlpp::Node::NodeList::iterator it = childNodes.begin();
xmlpp::Node::NodeList::iterator end = childNodes.end();
while (it != end) {
const xmlpp::Element * metadataTypeElement
= dynamic_cast<const xmlpp::Element*> (*it);
Ptr<MetadataType>::Ref metadataType(
new MetadataType(shared_from_this()));
metadataType->configure(*metadataTypeElement);
if (dcNameMap.find(*metadataType->getDcName()) != dcNameMap.end()) {
throw std::invalid_argument("trying to insert duplicate metadata "
"type: " + *metadataType->getDcName());
}
if (metadataType->getId3Tag().get()) {
if (id3TagMap.find(*metadataType->getId3Tag()) != id3TagMap.end()) {
throw std::invalid_argument("trying to insert duplicate "
"metadata by ID3v2 tag: "
+ *metadataType->getId3Tag());
}
}
dcNameMap[*metadataType->getDcName()] = metadataType;
if (metadataType->getId3Tag().get()) {
id3TagMap[*metadataType->getId3Tag()] = metadataType;
}
vector.push_back(metadataType);
++it;
}
}
/*------------------------------------------------------------------------------
* Tell if a metadata type object by the Dublin Core name exists
*----------------------------------------------------------------------------*/
bool
MetadataTypeContainer :: existsByDcName(const Glib::ustring dcName) const
throw ()
{
return dcNameMap.find(dcName) != dcNameMap.end();
}
/*------------------------------------------------------------------------------
* Look for a metadata type object by the Dublin Core name
*----------------------------------------------------------------------------*/
Ptr<const MetadataType>::Ref
MetadataTypeContainer :: getByDcName(const Glib::ustring dcName)
throw (std::invalid_argument)
{
if (!existsByDcName(dcName)) {
throw std::invalid_argument("no metadata type by the DC name " +dcName);
}
return dcNameMap[dcName];
}
/*------------------------------------------------------------------------------
* Tell if a metadata type object by the ID3v2 tag name exists.
*----------------------------------------------------------------------------*/
bool
MetadataTypeContainer :: existsById3Tag(const Glib::ustring id3Tag) const
throw ()
{
return id3TagMap.find(id3Tag) != id3TagMap.end();
}
/*------------------------------------------------------------------------------
* Look for a metadata type object by the ID3v2 tag name.
*----------------------------------------------------------------------------*/
Ptr<const MetadataType>::Ref
MetadataTypeContainer :: getById3Tag(const Glib::ustring id3Tag)
throw (std::invalid_argument)
{
if (!existsById3Tag(id3Tag)) {
throw std::invalid_argument("no metadata type by the ID3v2 Tag "
+ id3Tag);
}
return id3TagMap[id3Tag];
}
/*------------------------------------------------------------------------------
* Look for a metadata type object by the ID3v2 tag name.
*----------------------------------------------------------------------------*/
Ptr<const MetadataType>::Ref
MetadataTypeContainer :: getByIndex(unsigned int index) const
throw (std::invalid_argument)
{
if (index < 0 || index >= vector.size()) {
throw std::invalid_argument("index out of range in "
"MetadataTypeContainer::getByIndex()");
}
return vector.at(index);
}
/*------------------------------------------------------------------------------
* Check that the given value satisfies the constraint of a metadata type.
*----------------------------------------------------------------------------*/
bool
MetadataTypeContainer :: check(Ptr<const Glib::ustring>::Ref value,
const Glib::ustring & dcName)
throw (std::invalid_argument)
{
Ptr<const MetadataType>::Ref metadataType = getByDcName(dcName);
return metadataType->check(value);
}

View File

@ -1,337 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#else
#error "Need unistd.h"
#endif
#include <string>
#include <iostream>
#include "LiveSupport/Core/MetadataTypeContainer.h"
#include "MetadataTypeContainerTest.h"
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
CPPUNIT_TEST_SUITE_REGISTRATION(MetadataTypeContainerTest);
/**
* The name of the configuration file for the resource bundle.
*/
static const std::string bundleConfigFileName = "etc/resourceBundle.xml";
/**
* The name of the configuration file for the metadataType element.
*/
static const std::string metadataTypeConfigFileName = "etc/metadataType.xml";
/**
* The name of the configuration file for the metadataTypeContainer element.
*/
static const std::string configFileName = "etc/metadataTypeContainer.xml";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Set up the test environment
*----------------------------------------------------------------------------*/
void
MetadataTypeContainerTest :: setUp(void) throw (CPPUNIT_NS::Exception)
{
Ptr<ResourceBundle>::Ref rootBundle;
try {
Ptr<xmlpp::DomParser>::Ref parser(
new xmlpp::DomParser(bundleConfigFileName, true));
const xmlpp::Document * document = parser->get_document();
const xmlpp::Element * root = document->get_root_node();
rootBundle = LocalizedObject::getBundle(*root);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL("semantic error in bundle configuration file");
} catch (std::exception &e) {
CPPUNIT_FAIL(std::string("XML error in bundle configuration file:\n")
+ e.what());
}
CPPUNIT_ASSERT(rootBundle);
UErrorCode icuError = U_ZERO_ERROR;
bundle.reset(new ResourceBundle(rootBundle->get("metadata", icuError)));
CPPUNIT_ASSERT(U_SUCCESS(icuError));
CPPUNIT_ASSERT(bundle);
try {
Ptr<xmlpp::DomParser>::Ref parser(
new xmlpp::DomParser(configFileName, true));
const xmlpp::Document * document = parser->get_document();
const xmlpp::Element * root = document->get_root_node();
container.reset(new MetadataTypeContainer(bundle));
container->configure(*root);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL(std::string("semantic error in metadata container"
" configuration file:\n")
+ e.what());
} catch (xmlpp::exception &e) {
CPPUNIT_FAIL(std::string("XML error in metadata container"
" configuration file:\n")
+ e.what());
}
}
/*------------------------------------------------------------------------------
* Clean up the test environment
*----------------------------------------------------------------------------*/
void
MetadataTypeContainerTest :: tearDown(void) throw ()
{
}
/*------------------------------------------------------------------------------
* Test to see if the singleton Hello object is accessible
*----------------------------------------------------------------------------*/
void
MetadataTypeContainerTest :: firstTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<const MetadataType>::Ref metadataType;
bool gotException;
// test double-configuration
try {
Ptr<xmlpp::DomParser>::Ref parser(
new xmlpp::DomParser(configFileName, true));
const xmlpp::Document * document = parser->get_document();
const xmlpp::Element * root = document->get_root_node();
gotException = false;
try {
container->configure(*root);
} catch (std::invalid_argument &e) {
gotException = true;
}
CPPUNIT_ASSERT(gotException);
} catch (xmlpp::exception &e) {
CPPUNIT_FAIL(std::string("XML error in configuration file:\n")
+ e.what());
}
// a simple positive check on the DC name
CPPUNIT_ASSERT(container->existsByDcName("dc:creator"));
metadataType = container->getByDcName("dc:creator");
CPPUNIT_ASSERT(*metadataType->getDcName() == "dc:creator");
CPPUNIT_ASSERT(*metadataType->getId3Tag() == "TPE1");
CPPUNIT_ASSERT(*metadataType->getLocalizationKey() == "creator");
// a negative check on the DC name
CPPUNIT_ASSERT(!container->existsByDcName("dc:nonExistent"));
gotException = false;
try {
container->getByDcName("dc:nonExistent");
} catch (std::invalid_argument &e) {
gotException = true;
}
CPPUNIT_ASSERT(gotException);
// a simple positive check on the ID3v2 tag
CPPUNIT_ASSERT(container->existsById3Tag("TPE1"));
metadataType = container->getById3Tag("TPE1");
CPPUNIT_ASSERT(*metadataType->getDcName() == "dc:creator");
CPPUNIT_ASSERT(*metadataType->getId3Tag() == "TPE1");
CPPUNIT_ASSERT(*metadataType->getLocalizationKey() == "creator");
// a negative check on the ID3v2 tag
CPPUNIT_ASSERT(!container->existsById3Tag("NonExistentTag"));
gotException = false;
try {
container->getById3Tag("NonExistentTag");
} catch (std::invalid_argument &e) {
gotException = true;
}
CPPUNIT_ASSERT(gotException);
// two simple positive checks on the tab attribute
CPPUNIT_ASSERT(container->existsByDcName("dc:title"));
metadataType = container->getByDcName("dc:title");
CPPUNIT_ASSERT(metadataType->getTab() == MetadataType::mainTab);
CPPUNIT_ASSERT(container->existsByDcName("ls:buycdurl"));
metadataType = container->getByDcName("ls:buycdurl");
CPPUNIT_ASSERT(metadataType->getTab() == MetadataType::noTab);
}
/*------------------------------------------------------------------------------
* Test the iterator feature of the container.
*----------------------------------------------------------------------------*/
void
MetadataTypeContainerTest :: iteratorTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<const MetadataType>::Ref metadataType;
MetadataTypeContainer::Vector::const_iterator it;
MetadataTypeContainer::Vector::const_iterator end;
// check the first two elements in the container
it = container->begin();
end = container->end();
CPPUNIT_ASSERT(it != end);
metadataType = (Ptr<const MetadataType>::Ref) *it;
CPPUNIT_ASSERT(*metadataType->getDcName() == "dc:title");
CPPUNIT_ASSERT(*metadataType->getId3Tag() == "TIT2");
CPPUNIT_ASSERT(*metadataType->getLocalizationKey() == "title");
++it;
CPPUNIT_ASSERT(it != end);
metadataType = (Ptr<const MetadataType>::Ref) *it;
CPPUNIT_ASSERT(*metadataType->getDcName() == "dc:creator");
CPPUNIT_ASSERT(*metadataType->getId3Tag() == "TPE1");
CPPUNIT_ASSERT(*metadataType->getLocalizationKey() == "creator");
// test on an empty container
container.reset(new MetadataTypeContainer(bundle));
it = container->begin();
end = container->end();
CPPUNIT_ASSERT(it == end);
}
/*------------------------------------------------------------------------------
* Test localized metadata type names.
*----------------------------------------------------------------------------*/
void
MetadataTypeContainerTest :: localizedTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<const MetadataType>::Ref metadataType;
CPPUNIT_ASSERT(container->existsByDcName("dc:creator"));
metadataType = container->getByDcName("dc:creator");
CPPUNIT_ASSERT(*metadataType->getLocalizedName() == "Creator");
UErrorCode status = U_ZERO_ERROR;
Ptr<ResourceBundle>::Ref rootBundle;
Ptr<ResourceBundle>::Ref huBundle;
Ptr<ResourceBundle>::Ref jpBundle;
Ptr<const Glib::ustring>::Ref ustr;
// test with hungarian
rootBundle.reset(new ResourceBundle("./tmp/" PACKAGE_NAME, "hu", status));
CPPUNIT_ASSERT(U_SUCCESS(status));
huBundle.reset(new ResourceBundle(rootBundle->get("metadata", status)));
CPPUNIT_ASSERT(U_SUCCESS(status));
container->setBundle(huBundle);
ustr = metadataType->getLocalizedName();
CPPUNIT_ASSERT(ustr->length() == 6);
CPPUNIT_ASSERT((*ustr)[0] == 0x0045); // 'E'
CPPUNIT_ASSERT((*ustr)[1] == 0x006C); // 'l'
CPPUNIT_ASSERT((*ustr)[2] == 0x0151); // 'o' with double acute
CPPUNIT_ASSERT((*ustr)[3] == 0x0061); // 'a'
CPPUNIT_ASSERT((*ustr)[4] == 0x0064); // 'd'
CPPUNIT_ASSERT((*ustr)[5] == 0x00F3); // 'o' with acute
// test with japanese
rootBundle.reset(new ResourceBundle("./tmp/" PACKAGE_NAME, "jp", status));
CPPUNIT_ASSERT(U_SUCCESS(status));
jpBundle.reset(new ResourceBundle(rootBundle->get("metadata", status)));
CPPUNIT_ASSERT(U_SUCCESS(status));
container->setBundle(jpBundle);
ustr = metadataType->getLocalizedName();
CPPUNIT_ASSERT(ustr->length() == 6);
CPPUNIT_ASSERT((*ustr)[0] == 0x30af); // katakana ku
CPPUNIT_ASSERT((*ustr)[1] == 0x30ea); // katakana ri
CPPUNIT_ASSERT((*ustr)[2] == 0x30a8); // katakana e
CPPUNIT_ASSERT((*ustr)[3] == 0x30fc); // katakana '-'
CPPUNIT_ASSERT((*ustr)[4] == 0x30bf); // katakana ta
CPPUNIT_ASSERT((*ustr)[5] == 0x30fc); // katakana '-'
}
/*------------------------------------------------------------------------------
* Test to see if the constraints work.
*----------------------------------------------------------------------------*/
void
MetadataTypeContainerTest :: constraintTest(void)
throw (CPPUNIT_NS::Exception)
{
// test the case of no constraint; everything is OK
Ptr<Glib::ustring>::Ref title;
CPPUNIT_ASSERT(!container->check(title, "dc:title")); // except a 0 pointer
title.reset(new Glib::ustring("Some title"));
CPPUNIT_ASSERT(container->check(title, "dc:title"));
// test the numeric constraint; [0-9]+ required
Ptr<Glib::ustring>::Ref bpm(new Glib::ustring ("1000"));
CPPUNIT_ASSERT(container->check(bpm, "ls:bpm"));
bpm->assign("2000 or more");
CPPUNIT_ASSERT(!container->check(bpm, "ls:bpm"));
bpm->assign("");
CPPUNIT_ASSERT(!container->check(bpm, "ls:bpm"));
// test the numeric range constraint; [0-9]+ required, between 0 and 3000
Ptr<Glib::ustring>::Ref year(new Glib::ustring ("1000"));
CPPUNIT_ASSERT(container->check(year, "ls:year"));
year->assign("1066 AD");
CPPUNIT_ASSERT(!container->check(year, "ls:year"));
year->assign("20066");
CPPUNIT_ASSERT(!container->check(year, "ls:year"));
// test the enumeration constraint; "mp3", "mpeg" or "ogg" are allowed
Ptr<Glib::ustring>::Ref format(new Glib::ustring ("mp3"));
CPPUNIT_ASSERT(container->check(format, "dc:format"));
format->assign("wma");
CPPUNIT_ASSERT(!container->check(format, "dc:format"));
}

View File

@ -1,136 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef MetadataTypeContainerTest_h
#define MetadataTypeContainerTest_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <cppunit/extensions/HelperMacros.h>
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Unit test for the MetadataTypeContainer class.
*
* @see MetadataTypeContainer
*/
class MetadataTypeContainerTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(MetadataTypeContainerTest);
CPPUNIT_TEST(firstTest);
CPPUNIT_TEST(iteratorTest);
CPPUNIT_TEST(localizedTest);
CPPUNIT_TEST(constraintTest);
CPPUNIT_TEST_SUITE_END();
protected:
/**
* The resource bundle used by the container.
*/
Ptr<ResourceBundle>::Ref bundle;
/**
* The metadata container used in the tests.
*/
Ptr<MetadataTypeContainer>::Ref container;
/**
* A simple test.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
firstTest(void) throw (CPPUNIT_NS::Exception);
/**
* Testing the iterators available from the container.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
iteratorTest(void) throw (CPPUNIT_NS::Exception);
/**
* Test to see if localized metadata type names work.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
localizedTest(void) throw (CPPUNIT_NS::Exception);
/**
* Test to see if the constraints work.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
constraintTest(void) throw (CPPUNIT_NS::Exception);
public:
/**
* Set up the environment for the test case.
*/
void
setUp(void) throw (CPPUNIT_NS::Exception);
/**
* Clean up the environment after the test case.
*/
void
tearDown(void) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // MetadataTypeContainerTest_h

View File

@ -1,104 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#include "NumericConstraint.h"
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
namespace {
/*------------------------------------------------------------------------------
* The value of the type attribute for this class.
*----------------------------------------------------------------------------*/
const std::string typeAttributeValue = "numeric";
}
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Create a constraint element object based on an XML element.
*----------------------------------------------------------------------------*/
void
NumericConstraint :: configure(const xmlpp::Element & element)
throw (std::invalid_argument)
{
if (element.get_name() != getConfigElementName()) {
throw std::invalid_argument("bad configuration element "
+ element.get_name());
}
const xmlpp::Attribute* typeAttribute;
if (!(typeAttribute = element.get_attribute(typeAttributeName))) {
throw std::invalid_argument("missing attribute " + typeAttributeName);
}
std::string type = typeAttribute->get_value();
if (type != typeAttributeValue) {
throw std::invalid_argument(typeAttributeValue
+ " constraint configured with a"
+ " constraint element of type "
+ type);
}
}
/*------------------------------------------------------------------------------
* Check that the given value satisfies the constraint.
*----------------------------------------------------------------------------*/
bool
NumericConstraint :: check(Ptr<const Glib::ustring>::Ref value) const
throw (std::logic_error)
{
if (!value) {
throw std::logic_error("NumericConstraint::check() called with "
"a 0 pointer value");
}
Glib::ustring::const_iterator it = value->begin();
if (it == value->end()) { // the empty string is not a number
return false;
}
for (; it != value->end(); ++it) {
if (*it < '0' || *it > '9') {
return false;
}
}
return true;
}

View File

@ -1,138 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_NumericConstraint_h
#define LiveSupport_Core_NumericConstraint_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#include "LiveSupport/Core/MetadataConstraint.h"
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A class for representing a numeric metadata constraint.
*
* This is a concrete subclass of MetadataConstraint. Do not explicitly
* instantiate this class; create a MetadataConstraint object instead, and
* configure it with an XML element with the appropriate type attribute.
*
* This object has to be configured with an XML configuration element
* called constraint. This may look like the following:
*
* <pre><code>
* <constraint type = "numeric"/>
* </code></pre>
*
* A metadata type with this kind of constraint can only accept (decimal,
* non-negative) integer values, i.e., [0-9]+.
*
* The DTD for the expected XML element looks like the following:
*
* <pre><code>
* <!ELEMENT constraint EMPTY >
* <!ATTLIST constraint type "numeric" #FIXED >
* </code></pre>
*
* @see NumericConstraintContainer
*/
class NumericConstraint : public MetadataConstraint
{
public:
/**
* Constructor.
*/
NumericConstraint() throw ()
{
}
/**
* A virtual destructor, as this class has virtual functions.
*/
virtual
~NumericConstraint(void) throw ()
{
}
/**
* Return the name of the XML element this object expects
* to be sent to a call to configure().
*
* @return the name of the expected XML configuration element.
*/
static const std::string
getConfigElementName(void) throw ()
{
return MetadataConstraint::getConfigElementName();
}
/**
* Configure the metadata object based on an XML configuration element.
*
* @param element the XML configuration element.
* @exception std::invalid_argument of the supplied XML element
* contains bad configuration information
*/
virtual void
configure(const xmlpp::Element &element)
throw (std::invalid_argument);
/**
* Check that the given value satisfies the constraint.
*
* @param value the value to be checked against the constraint.
* @return true if the value satisfies the constraint.
* @exception std::logic_error if the parameter is a 0 pointer.
*/
virtual bool
check(Ptr<const Glib::ustring>::Ref value) const
throw (std::logic_error);
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_NumericConstraint_h

View File

@ -1,155 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#include <sstream>
#include "NumericConstraint.h"
#include "NumericRangeConstraint.h"
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
namespace {
/*------------------------------------------------------------------------------
* The value of the type attribute for this class.
*----------------------------------------------------------------------------*/
const std::string typeAttributeValue = "numericRange";
}
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Create a constraint element object based on an XML element.
*----------------------------------------------------------------------------*/
void
NumericRangeConstraint :: configure(const xmlpp::Element & element)
throw (std::invalid_argument)
{
if (element.get_name() != getConfigElementName()) {
throw std::invalid_argument("bad configuration element "
+ element.get_name());
}
const xmlpp::Attribute* typeAttribute;
if (!(typeAttribute = element.get_attribute(typeAttributeName))) {
throw std::invalid_argument("missing attribute " + typeAttributeName);
}
std::string type = typeAttribute->get_value();
if (type != typeAttributeValue) {
throw std::invalid_argument(typeAttributeValue
+ " constraint configured with a"
+ " constraint element of type "
+ type);
}
xmlpp::Node::NodeList childNodes = element.get_children(valueElementName);
xmlpp::Node::NodeList::iterator it = childNodes.begin();
if (it != childNodes.end()) {
minValue = readNumberFromNode(*it);
} else {
throw std::invalid_argument("sub-element not found in constraint");
}
++it;
if (it != childNodes.end()) {
maxValue = readNumberFromNode(*it);
} else {
throw std::invalid_argument("sub-element not found in constraint");
}
}
/*------------------------------------------------------------------------------
* Read a number from an xml element.
*----------------------------------------------------------------------------*/
NumericRangeConstraint :: ValueType
NumericRangeConstraint :: readNumberFromNode(
const xmlpp::Node * node) const
throw (std::invalid_argument)
{
const xmlpp::Element * valueElement
= dynamic_cast<const xmlpp::Element*> (node);
if (valueElement) {
Ptr<Glib::ustring>::Ref value(new Glib::ustring(
valueElement->get_child_text()
->get_content() ));
return readNumber(value);
} else {
throw std::invalid_argument("bad sub-element found in constraint");
}
}
/*------------------------------------------------------------------------------
* Read a number from a string.
*----------------------------------------------------------------------------*/
NumericRangeConstraint :: ValueType
NumericRangeConstraint :: readNumber(
Ptr<const Glib::ustring>::Ref value) const
throw (std::invalid_argument)
{
NumericConstraint numericConstraint;
if (!numericConstraint.check(value)) {
throw std::invalid_argument("bad number found in constraint");
}
std::istringstream valueStream(*value);
ValueType valueNumber;
valueStream >> valueNumber;
return valueNumber;
}
/*------------------------------------------------------------------------------
* Check that the given value satisfies the constraint.
*----------------------------------------------------------------------------*/
bool
NumericRangeConstraint :: check(Ptr<const Glib::ustring>::Ref value) const
throw (std::logic_error)
{
ValueType valueNumber = readNumber(value);
if (valueNumber >= minValue && valueNumber <= maxValue) {
return true;
} else {
return false;
}
}

View File

@ -1,186 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_NumericRangeConstraint_h
#define LiveSupport_Core_NumericRangeConstraint_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#include "LiveSupport/Core/MetadataConstraint.h"
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A class for representing a metadata constraint which allows numbers between
* two given values (inclusive).
*
* This is a concrete subclass of MetadataConstraint. Do not explicitly
* instantiate this class; create a MetadataConstraint object instead, and
* configure it with an XML element with the appropriate type attribute.
*
* This object has to be configured with an XML configuration element
* called constraint. This may look like the following:
*
* <pre><code>
* <constraint type = "numericRange">
* <value>1</value>
* <value>12</value>
* </constraint>
* </code></pre>
*
* A metadata type with this kind of constraint can only accept (decimal,
* non-negative) integer values, i.e., [0-9]+, which are greater than or
* equal to the first value given, and less than or equal to the second
* value given.
*
* The DTD for the expected XML element looks like the following:
*
* <pre><code>
* <!ELEMENT constraint (value, value) >
* <!ATTLIST constraint type "numericRange" #FIXED >
* <!ELEMENT value (#PCDATA) >
* </code></pre>
*
* @see NumericRangeConstraintContainer
*/
class NumericRangeConstraint : public MetadataConstraint
{
private:
/**
* The integer type used by the constraint.
*/
typedef unsigned long long ValueType;
/**
* The smallest value allowed by the constraint.
*/
ValueType minValue;
/**
* The largest value allowed by the constraint.
*/
ValueType maxValue;
/**
* Read a number from an XML node.
*
* @param node the node containing the number.
* @return the number read from the node.
* @exception std::invalid_argument if the XML node is not
* of the expected form.
*/
ValueType
readNumberFromNode(const xmlpp::Node * node) const
throw (std::invalid_argument);
/**
* Read a number from a string.
*
* @param value the string containing the number.
* @return the number read from the string.
* @exception std::invalid_argument if the string does not contain
* a number.
*/
ValueType
readNumber(Ptr<const Glib::ustring>::Ref value) const
throw (std::invalid_argument);
public:
/**
* Constructor.
*/
NumericRangeConstraint() throw ()
{
}
/**
* A virtual destructor, as this class has virtual functions.
*/
virtual
~NumericRangeConstraint(void) throw ()
{
}
/**
* Return the name of the XML element this object expects
* to be sent to a call to configure().
*
* @return the name of the expected XML configuration element.
*/
static const std::string
getConfigElementName(void) throw ()
{
return MetadataConstraint::getConfigElementName();
}
/**
* Configure the metadata object based on an XML configuration element.
*
* @param element the XML configuration element.
* @exception std::invalid_argument of the supplied XML element
* contains bad configuration information
*/
virtual void
configure(const xmlpp::Element &element)
throw (std::invalid_argument);
/**
* Check that the given value satisfies the constraint.
*
* @param value the value to be checked against the constraint.
* @return true if the value satisfies the constraint.
* @exception std::logic_error if the parameter is a 0 pointer.
*/
virtual bool
check(Ptr<const Glib::ustring>::Ref value) const
throw (std::logic_error);
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_NumericRangeConstraint_h

View File

@ -1,72 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include "LiveSupport/Core/NumericTools.h"
using namespace LiveSupport;
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Convert an integer to a string.
*----------------------------------------------------------------------------*/
Glib::ustring
NumericTools :: itoa(int number) throw ()
{
std::ostringstream stream;
stream << number;
Glib::ustring string = stream.str();
return string;
}
/*------------------------------------------------------------------------------
* Add a number to the end of a string.
*----------------------------------------------------------------------------*/
Glib::ustring
NumericTools :: addIndex(const Glib::ustring & baseString,
int index) throw ()
{
std::ostringstream stream;
stream << baseString
<< (index + 1);
return stream.str();
}

View File

@ -1,95 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include "LiveSupport/Core/NumericTools.h"
#include "NumericToolsTest.h"
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
CPPUNIT_TEST_SUITE_REGISTRATION(NumericToolsTest);
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Set up the test environment
*----------------------------------------------------------------------------*/
void
NumericToolsTest :: setUp(void) throw ()
{
}
/*------------------------------------------------------------------------------
* Clean up the test environment
*----------------------------------------------------------------------------*/
void
NumericToolsTest :: tearDown(void) throw ()
{
}
/*------------------------------------------------------------------------------
* Test the itoa() function.
*----------------------------------------------------------------------------*/
void
NumericToolsTest :: itoaTest(void)
throw (CPPUNIT_NS::Exception)
{
int i = 3142874;
Glib::ustring a = NumericTools::itoa(i);
CPPUNIT_ASSERT(a == "3142874");
}
/*------------------------------------------------------------------------------
* Test the addIndex() function.
*----------------------------------------------------------------------------*/
void
NumericToolsTest :: addIndexTest(void)
throw (CPPUNIT_NS::Exception)
{
Glib::ustring base = "itemLabel";
int index = 123;
Glib::ustring result = NumericTools::addIndex(base, index);
CPPUNIT_ASSERT(result == "itemLabel124");
Glib::ustring second = NumericTools::addIndex("second", 0);
CPPUNIT_ASSERT(second == "second1");
}

View File

@ -1,111 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------------------*/
#ifndef NumericToolsTest_h
#define NumericToolsTest_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <cppunit/extensions/HelperMacros.h>
namespace LiveSupport {
namespace Core {
using namespace LiveSupport;
using namespace LiveSupport::Core;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Unit test for the NumericTools class.
*
* @see NumericTools
*/
class NumericToolsTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(NumericToolsTest);
CPPUNIT_TEST(itoaTest);
CPPUNIT_TEST(addIndexTest);
CPPUNIT_TEST_SUITE_END();
protected:
/**
* Test the itoa() function.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
itoaTest(void) throw (CPPUNIT_NS::Exception);
/**
* Test the addIndex() function.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
addIndexTest(void) throw (CPPUNIT_NS::Exception);
public:
/**
* Set up the environment for the test case.
*/
void
setUp(void) throw ();
/**
* Clean up the environment after the test case.
*/
void
tearDown(void) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // NumericToolsTest_h

View File

@ -1,405 +0,0 @@
/*------------------------------------------------------------------------------
Copyright (c) 2010 Sourcefabric O.P.S.
This file is part of the Campcaster project.
http://campcaster.sourcefabric.org/
To report bugs, send an e-mail to bugs@campware.org
Campcaster is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Campcaster 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 Campcaster; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author $
Version : $Revision $
Location : $URL $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <iostream>
#include <fstream>
#include <sstream>
#include "LiveSupport/Core/OptionsContainer.h"
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Constructor.
*----------------------------------------------------------------------------*/
OptionsContainer :: OptionsContainer(
const xmlpp::Element & optionsElement,
Ptr<const Glib::ustring>::Ref configFileName)
throw ()
: configFileName(configFileName),
touched(false)
{
optionsDocument.create_root_node_by_import(&optionsElement, true);
// true == recursive
xmlpp::Node::NodeList nodes = optionsElement.get_children(
RdsContainer::getConfigElementName());
if (nodes.size() > 0) {
rdsContainer.reset(new RdsContainer());
rdsContainer->configure(
*dynamic_cast<const xmlpp::Element*>(nodes.front()));
}
}
/*------------------------------------------------------------------------------
* Set a string type option.
*----------------------------------------------------------------------------*/
void
OptionsContainer :: setOptionItem(OptionItemString optionItem,
Ptr<const Glib::ustring>::Ref value)
throw (std::invalid_argument)
{
bool isAttribute = false; // text node or attr node
xmlpp::Node * targetNode = selectNode(optionItem, isAttribute);
if (!targetNode) {
targetNode = createNode(optionItem);
}
if (isAttribute) {
xmlpp::Attribute * attr = dynamic_cast<xmlpp::Attribute*>(targetNode);
if (attr != 0) {
attr->set_value(*value);
touched = true;
return;
}
} else {
xmlpp::TextNode * text = dynamic_cast<xmlpp::TextNode*>(targetNode);
if (text != 0) {
text->set_content(*value);
touched = true;
return;
}
}
throw std::invalid_argument("option item not found");
}
/*------------------------------------------------------------------------------
* Get a string type option.
*----------------------------------------------------------------------------*/
Ptr<Glib::ustring>::Ref
OptionsContainer :: getOptionItem(OptionItemString optionItem)
throw (std::invalid_argument)
{
bool isAttribute = false; // text node or attr node
const xmlpp::Node * targetNode = selectNode(optionItem, isAttribute);
if (isAttribute) {
const xmlpp::Attribute *
attr = dynamic_cast<const xmlpp::Attribute*>(targetNode);
if (attr != 0) {
Ptr<Glib::ustring>::Ref value(new Glib::ustring(
attr->get_value() ));
return value;
}
} else {
const xmlpp::TextNode *
text = dynamic_cast<const xmlpp::TextNode*>(targetNode);
if (text != 0) {
Ptr<Glib::ustring>::Ref value(new Glib::ustring(
text->get_content() ));
return value;
}
}
throw std::invalid_argument("option item not found");
}
/*------------------------------------------------------------------------------
* Set a keyboard shortcut type option.
*----------------------------------------------------------------------------*/
void
OptionsContainer :: setKeyboardShortcutItem(
int containerNo,
int shortcutNo,
Ptr<const Glib::ustring>::Ref value)
throw (std::invalid_argument)
{
xmlpp::Node * targetNode = selectKeyboardShortcutNode(
containerNo, shortcutNo);
xmlpp::Attribute * attr = dynamic_cast<xmlpp::Attribute*>(targetNode);
if (attr != 0) {
attr->set_value(*value);
touched = true;
return;
} else {
throw std::invalid_argument("keyboard shortcut not found");
}
}
/*------------------------------------------------------------------------------
* Set the value of an RDS string.
*----------------------------------------------------------------------------*/
void
OptionsContainer :: setRdsOptions(Ptr<const Glib::ustring>::Ref key,
Ptr<const Glib::ustring>::Ref value,
bool enabled)
throw ()
{
if (!rdsContainer) {
rdsContainer.reset(new RdsContainer());
}
rdsContainer->setRdsOptions(key, value, enabled);
}
/*------------------------------------------------------------------------------
* Get the value of an RDS string.
*----------------------------------------------------------------------------*/
Ptr<const Glib::ustring>::Ref
OptionsContainer :: getRdsValue(Ptr<const Glib::ustring>::Ref key)
throw (std::invalid_argument)
{
if (rdsContainer) {
return rdsContainer->getRdsValue(key);
} else {
throw std::invalid_argument("no RDS container found");
}
}
/*------------------------------------------------------------------------------
* Get the enabled/disabled state of an RDS option.
*----------------------------------------------------------------------------*/
bool
OptionsContainer :: getRdsEnabled(Ptr<const Glib::ustring>::Ref key)
throw (std::invalid_argument)
{
if (rdsContainer) {
return rdsContainer->getRdsEnabled(key);
} else {
throw std::invalid_argument("no RDS container found");
}
}
/*------------------------------------------------------------------------------
* Find the node corresponding to an OptionItemString value.
*----------------------------------------------------------------------------*/
xmlpp::Node *
OptionsContainer :: selectNode(OptionItemString optionItem,
bool & isAttribute)
throw (std::invalid_argument)
{
xmlpp::Node * targetNode = 0;
switch (optionItem) {
case outputPlayerDeviceName :
targetNode = getNode("outputPlayer/audioPlayer/gstreamerPlayer/"
"@audioDevice");
isAttribute = true;
break;
case cuePlayerDeviceName :
targetNode = getNode("cuePlayer/audioPlayer/gstreamerPlayer/"
"@audioDevice");
isAttribute = true;
break;
case authenticationServer :
targetNode = getNode("authenticationClientFactory/"
"webAuthentication/location/@server");
isAttribute = true;
break;
case authenticationPort :
targetNode = getNode("authenticationClientFactory/"
"webAuthentication/location/@port");
isAttribute = true;
break;
case authenticationPath :
targetNode = getNode("authenticationClientFactory/"
"webAuthentication/location/@path");
isAttribute = true;
break;
case storageServer :
targetNode = getNode("storageClientFactory/"
"webStorage/location/@server");
isAttribute = true;
break;
case storagePort :
targetNode = getNode("storageClientFactory/"
"webStorage/location/@port");
isAttribute = true;
break;
case storagePath :
targetNode = getNode("storageClientFactory/"
"webStorage/location/@path");
isAttribute = true;
break;
case schedulerServer :
targetNode = getNode("schedulerClientFactory/"
"schedulerDaemonXmlRpcClient/@xmlRpcHost");
isAttribute = true;
break;
case schedulerPort :
targetNode = getNode("schedulerClientFactory/"
"schedulerDaemonXmlRpcClient/@xmlRpcPort");
isAttribute = true;
break;
case schedulerPath :
targetNode = getNode("schedulerClientFactory/"
"schedulerDaemonXmlRpcClient/@xmlRpcUri");
isAttribute = true;
break;
case serialDeviceName :
targetNode = getNode("serialPort/@path");
isAttribute = true;
break;
}
return targetNode;
}
/*------------------------------------------------------------------------------
* Find the node corresponding to a keyboard shortcut.
*----------------------------------------------------------------------------*/
xmlpp::Node *
OptionsContainer :: selectKeyboardShortcutNode(int containerNo,
int shortcutNo)
throw (std::invalid_argument)
{
std::stringstream xPathStream;
xPathStream << "keyboardShortcutList/keyboardShortcutContainer["
<< containerNo
<< "]/keyboardShortcut["
<< shortcutNo
<< "]/@key";
return getNode(xPathStream.str());
}
/*------------------------------------------------------------------------------
* Return the first node matching an XPath string.
*----------------------------------------------------------------------------*/
xmlpp::Node *
OptionsContainer :: getNode(const Glib::ustring & xPath)
throw (std::invalid_argument)
{
xmlpp::Element * rootNode = optionsDocument.get_root_node();
xmlpp::NodeSet nodes;
try {
nodes = rootNode->find(xPath);
} catch (xmlpp::exception &e) {
throw std::invalid_argument(e.what());
}
std::vector<xmlpp::Node*>::iterator it = nodes.begin();
if (it != nodes.end()) {
return *it;
} else {
return 0;
}
}
/*------------------------------------------------------------------------------
* Create the node corresponding to an OptionItemString value.
*----------------------------------------------------------------------------*/
xmlpp::Node *
OptionsContainer :: createNode(OptionItemString optionItem) throw ()
{
xmlpp::Element * rootNode = optionsDocument.get_root_node();
xmlpp::Element * element = 0;
xmlpp::Attribute * attribute = 0;
// only supports the serialDeviceName option item, for now
switch (optionItem) {
case serialDeviceName :
element = dynamic_cast<xmlpp::Element*>(
getNode("serialPort"));
if (!element) {
element = rootNode->add_child("serialPort");
}
attribute = dynamic_cast<xmlpp::Attribute*>(
getNode("serialPort/@path"));
if (!attribute) {
attribute = element->set_attribute("path", "");
}
return attribute;
default:
return 0;
}
}
/*------------------------------------------------------------------------------
* Save the options to a file.
*----------------------------------------------------------------------------*/
void
OptionsContainer :: writeToFile(void) throw ()
{
if (configFileName) {
if (rdsContainer && rdsContainer->isTouched()) {
xmlpp::Element * rootNode = optionsDocument.get_root_node();
xmlpp::Node::NodeList nodes = rootNode->get_children(
RdsContainer::getConfigElementName());
if (nodes.size() > 0) {
rootNode->remove_child(nodes.front());
}
rootNode->import_node(rdsContainer->toXmlElement(), true);
}
std::ofstream file(configFileName->c_str());
if (file.good()) {
optionsDocument.write_to_stream_formatted(file, "utf-8");
touched = false;
}
file.close();
}
}

Some files were not shown because too many files have changed in this diff Show More