inital checkin of unimrcp svn revision 985 from http://unimrcp.googlecode.com/svn/trunk/

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13790 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris 2009-06-16 22:31:19 +00:00
parent ec90221783
commit da925bddf8
349 changed files with 47866 additions and 0 deletions

12
libs/unimrcp/AUTHORS Normal file
View File

@ -0,0 +1,12 @@
Author(s):
Arsen Chaloyan <achaloyan@gmail.com>
Contributor(s):
Kamil Shakirov <kamils80@gmail.com>
Anthony Masse <amasse.telisma@gmail.com>
Vlad Socaciu <Curatica@gmail.com>
Garmt <garmt.noname@gmail.com>
Patrick <pnunes29@gmail.com>
Bayram <bayramboyraz@gmail.com>
Mahmoud Hassan <firstmahmoud2002@gmail.com>

103
libs/unimrcp/INSTALL Normal file
View File

@ -0,0 +1,103 @@
BUILD REQUIREMENTS
==================
UniMRCP depends on a number of third party tools and libraries,
which must be installed prior to UniMRCP build.
1. Apache Portable Runtime [>=1.2.x] (http://apr.apache.org/)
Whenever you want to build any part of UniMRCP, you need the
Apache Portable Runtime (APR) and the APR Utility (APR-util)
libraries.
2. Sofia-SIP [>=1.12.6] (http://sofia-sip.sourceforge.net/)
Sofia-SIP library is used to implement MRCPv2 specification
compliant SIP signaling. Sofia-SIP is an open-source SIP User-Agent
library, compliant with the IETF RFC3261 specification.
Use the link below to download one of known to work and
ready to use packages of APR and Sofia-SIP libraries.
http://www.unimrcp.org/dependencies/
GNU BUILD
===================
Additional requirements
- autoconf 2.57 or newer
- automake
- libtool 1.4 or newer
- gcc
- pkg-config
Build procedure
$ ./bootstrap
$ ./configure
$ make
$ make install
Installed directory layout
bin - binaries (unimrcpserver, unimrcpclient)
conf - configuration files
include - header files
libs - shared (convenient) libraries
plugins - run-time loadable modules
There are a couple of options to "./configure".
To specify where to look for the APR and APR-util libraries
use the "--with-apr=" and "--with-apr-util=" options.
For example
$ ./configure --with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr
To specify where to look for the Sofia-SIP library
use the "--with-sofia-sip=" option.
For example
$ ./configure --with-sofia-sip=/usr/local/sofia-sip
To install the default configuration use
$ make def-conf
To generate doxygen documentation from the sources use
$ make dox
To build distribution tarball use
$ make dist
WINDOWS BUILD
======================
Additional requirements
- Microsoft Visual Studio 2005
One-time pre-build preparation
You may need to adjust the paths for 3-rd party libraries
in appropriate property sheets to match your local installation,
while below are the defaults (build/vsprops).
apr.vsprops
<UserMacro
Name="AprDir"
Value="$(SolutionDir)libs\apr"
/>
<UserMacro
Name="AprUtilDir"
Value="$(SolutionDir)libs\apr-util"
/>
sofiasip.vsprops
<UserMacro
Name="SofiaDir"
Value="$(SolutionDir)libs\sofia-sip"
/>
Build procedure
Open unimrcp.sln solution file and build the solution (Build -> Build Solution).
One-time pre-run output directory preparation
Build prepare.vcproj utility project (right click on tools -> prebuild in
Solution Explorer and select Build from context menu). This is a one-time
output directory preparation. It copies all the required APR and SofiaSIP
libraries and the default configuration to the output directory.
Output directory layout
bin - binaries (unimrcpserver, unimrcpclient) and all the required dlls
conf - configuration files
plugins - run-time loadable modules

202
libs/unimrcp/LICENSE Normal file
View File

@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

42
libs/unimrcp/Makefile.am Normal file
View File

@ -0,0 +1,42 @@
macrodir = @ac_macro_dir@
auxdir = @ac_aux_dir@
AUX_DIST = $(auxdir)/config.guess \
$(auxdir)/config.sub \
$(auxdir)/install-sh \
$(auxdir)/ltconfig \
$(auxdir)/ltmain.sh \
$(auxdir)/depcomp \
$(auxdir)/missing
EXTRA_DIST = bootstrap
AUTOMAKE_OPTIONS = foreign
MAINTAINERCLEANFILES = Makefile.in aclocal.m4 configure $(AUX_DIST)
ACLOCAL = aclocal -I $(macrodir)
SUBDIRS = libs modules plugins platforms build
if TEST_SUITES
SUBDIRS += tests
endif
dox:
doxygen $(top_srcdir)/docs/doxygen.conf
def-conf:
test -d $(confdir) || $(mkinstalldirs) $(confdir)
for conffile in `find conf -name \*.xml` ; do \
filename=`echo $$conffile | sed -e 's|^.*/||'`; \
$(INSTALL) -m 644 conf/$$filename $(confdir); \
done
def-data:
test -d $(datadir) || $(mkinstalldirs) $(datadir)
for datafile in `find data -name *.pcm -o -name *.xml` ; do \
filename=`echo $$datafile | sed -e 's|^.*/||'`; \
$(INSTALL) -m 644 data/$$filename $(datadir); \
done
install-data-local:
test -d $(confdir) || $(MAKE) def-conf
test -d $(datadir) || $(MAKE) def-data
test -d $(logdir) || $(mkinstalldirs) $(logdir)

51
libs/unimrcp/README Normal file
View File

@ -0,0 +1,51 @@
INTRODUCTION
============
UniMRCP - Open Source Media Resource Control Protocol Stack.
INSTALLATION
============
See the file "INSTALLATION" for installation tips.
DOCUMENTATION
=============
See the directory "docs/dox" for doxygen generated documentation.
See the directory "docs/ea" for UML based design concepts
(Enterpise Architect generated HTML pages).
REFERENCES
==========
Website:
http://www.unimrcp.org
Project Home:
http://code.google.com/p/unimrcp/
Wiki:
http://code.google.com/p/unimrcp/w/list
Issue Tracker:
http://code.google.com/p/unimrcp/issues/list
Discussion Group:
http://groups.google.com/group/unimrcp
Version Control Repository (SVN):
http://unimrcp.googlecode.com/svn/trunk/
UML Documentation File (Enterpise Architect):
http://unimrcp.googlecode.com/svn/misc/unimrcp.eap
Commit Monitor:
http://code.google.com/p/unimrcp/source/list
http://groups.google.com/group/unimrcp-svn-commits
LICENSING
=========
UniMRCP is licensed under terms of the Apache 2.0 license.
See the file "LICENSE" for more information.
Copyright 2008 Arsen Chaloyan

14
libs/unimrcp/bootstrap Executable file
View File

@ -0,0 +1,14 @@
#! /bin/sh
case `uname` in
Darwin) libtoolize=glibtoolize ;;
*) libtoolize=libtoolize ;;
esac
set -x
$libtoolize --force --automake --copy
aclocal -I build/acmacros
automake --foreign --add-missing --copy
autoconf
rm -rf autom4te.cache

View File

@ -0,0 +1,3 @@
MAINTAINERCLEANFILES = Makefile.in
SUBDIRS = pkgconfig

View File

@ -0,0 +1,44 @@
dnl UNIMRCP_CHECK_APR
AC_DEFUN([UNIMRCP_CHECK_APR],
[
AC_MSG_NOTICE([Apache Portable Runtime (APR) library configuration])
APR_FIND_APR("", "", 1, 1)
if test $apr_found = "no"; then
AC_MSG_WARN([APR not found])
UNIMRCP_DOWNLOAD_APR
fi
if test $apr_found = "reconfig"; then
AC_MSG_WARN([APR reconfig])
fi
dnl check APR version number
apr_version="`$apr_config --version`"
AC_MSG_RESULT([$apr_version])
dnl Get build information from APR
CPPFLAGS="$CPPFLAGS `$apr_config --cppflags`"
CFLAGS="$CFLAGS `$apr_config --cflags`"
LDFLAGS="$LDFLAGS `$apr_config --ldflags`"
UNIMRCP_APR_INCLUDES="`$apr_config --includes`"
UNIMRCP_APR_LIBS="`$apr_config --link-libtool --libs`"
AC_SUBST(UNIMRCP_APR_INCLUDES)
AC_SUBST(UNIMRCP_APR_LIBS)
])
dnl UNIMRCP_DOWNLOAD_APR
dnl no apr found, print out a message telling the user what to do
AC_DEFUN([UNIMRCP_DOWNLOAD_APR],
[
echo "The Apache Portable Runtime (APR) library cannot be found."
echo "Please install APR on this system and supply the appropriate"
echo "--with-apr option to 'configure'"
AC_MSG_ERROR([no suitable APR found])
])

View File

@ -0,0 +1,42 @@
dnl UNIMRCP_CHECK_APU
AC_DEFUN([UNIMRCP_CHECK_APU],
[
AC_MSG_NOTICE([Apache Portable Runtime Utility (APU) library configuration])
APR_FIND_APU("", "", 1, 1)
if test $apu_found = "no"; then
AC_MSG_WARN([APU not found])
UNIMRCP_DOWNLOAD_APU
fi
if test $apu_found = "reconfig"; then
AC_MSG_WARN([APU reconfig])
fi
dnl check APU version number
apu_version="`$apu_config --version`"
AC_MSG_RESULT([$apu_version])
dnl Get build information from APU
LDFLAGS="$LDFLAGS `$apu_config --ldflags`"
UNIMRCP_APU_INCLUDES="`$apu_config --includes`"
UNIMRCP_APU_LIBS="`$apu_config --link-libtool --libs`"
AC_SUBST(UNIMRCP_APU_INCLUDES)
AC_SUBST(UNIMRCP_APU_LIBS)
])
dnl UNIMRCP_DOWNLOAD_APU
dnl no apr-util found, print out a message telling the user what to do
AC_DEFUN([UNIMRCP_DOWNLOAD_APU],
[
echo "The Apache Portable Runtime Utility (APU) library cannot be found."
echo "Please install APRUTIL on this system and supply the appropriate"
echo "--with-apr-util option to 'configure'"
AC_MSG_ERROR([no suitable APU found])
])

View File

@ -0,0 +1,167 @@
dnl -------------------------------------------------------- -*- autoconf -*-
dnl Licensed to the Apache Software Foundation (ASF) under one or more
dnl contributor license agreements. See the NOTICE file distributed with
dnl this work for additional information regarding copyright ownership.
dnl The ASF licenses this file to You under the Apache License, Version 2.0
dnl (the "License"); you may not use this file except in compliance with
dnl the License. You may obtain a copy of the License at
dnl
dnl http://www.apache.org/licenses/LICENSE-2.0
dnl
dnl Unless required by applicable law or agreed to in writing, software
dnl distributed under the License is distributed on an "AS IS" BASIS,
dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
dnl See the License for the specific language governing permissions and
dnl limitations under the License.
dnl
dnl find_apr.m4 : locate the APR include files and libraries
dnl
dnl This macro file can be used by applications to find and use the APR
dnl library. It provides a standardized mechanism for using APR. It supports
dnl embedding APR into the application source, or locating an installed
dnl copy of APR.
dnl
dnl APR_FIND_APR(srcdir, builddir, implicit-install-check, acceptable-majors)
dnl
dnl where srcdir is the location of the bundled APR source directory, or
dnl empty if source is not bundled.
dnl
dnl where builddir is the location where the bundled APR will will be built,
dnl or empty if the build will occur in the srcdir.
dnl
dnl where implicit-install-check set to 1 indicates if there is no
dnl --with-apr option specified, we will look for installed copies.
dnl
dnl where acceptable-majors is a space separated list of acceptable major
dnl version numbers. Often only a single major version will be acceptable.
dnl If multiple versions are specified, and --with-apr=PREFIX or the
dnl implicit installed search are used, then the first (leftmost) version
dnl in the list that is found will be used. Currently defaults to [0 1].
dnl
dnl Sets the following variables on exit:
dnl
dnl apr_found : "yes", "no", "reconfig"
dnl
dnl apr_config : If the apr-config tool exists, this refers to it. If
dnl apr_found is "reconfig", then the bundled directory
dnl should be reconfigured *before* using apr_config.
dnl
dnl Note: this macro file assumes that apr-config has been installed; it
dnl is normally considered a required part of an APR installation.
dnl
dnl If a bundled source directory is available and needs to be (re)configured,
dnl then apr_found is set to "reconfig". The caller should reconfigure the
dnl (passed-in) source directory, placing the result in the build directory,
dnl as appropriate.
dnl
dnl If apr_found is "yes" or "reconfig", then the caller should use the
dnl value of apr_config to fetch any necessary build/link information.
dnl
AC_DEFUN([APR_FIND_APR], [
apr_found="no"
if test "$target_os" = "os2-emx"; then
# Scripts don't pass test -x on OS/2
TEST_X="test -f"
else
TEST_X="test -x"
fi
ifelse([$4], [], [
ifdef(AC_WARNING,AC_WARNING([$0: missing argument 4 (acceptable-majors): Defaulting to APR 0.x then APR 1.x]))
acceptable_majors="0 1"],
[acceptable_majors="$4"])
apr_temp_acceptable_apr_config=""
for apr_temp_major in $acceptable_majors
do
case $apr_temp_major in
0)
apr_temp_acceptable_apr_config="$apr_temp_acceptable_apr_config apr-config"
;;
*)
apr_temp_acceptable_apr_config="$apr_temp_acceptable_apr_config apr-$apr_temp_major-config"
;;
esac
done
AC_MSG_CHECKING(for APR)
AC_ARG_WITH(apr,
[ --with-apr=PATH prefix for installed APR, path to APR build tree,
or the full path to apr-config],
[
if test "$withval" = "no" || test "$withval" = "yes"; then
AC_MSG_ERROR([--with-apr requires a directory or file to be provided])
fi
for apr_temp_apr_config_file in $apr_temp_acceptable_apr_config
do
for lookdir in "$withval/bin" "$withval"
do
if $TEST_X "$lookdir/$apr_temp_apr_config_file"; then
apr_found="yes"
apr_config="$lookdir/$apr_temp_apr_config_file"
break 2
fi
done
done
if test "$apr_found" != "yes" && $TEST_X "$withval" && $withval --help > /dev/null 2>&1 ; then
apr_found="yes"
apr_config="$withval"
fi
dnl if --with-apr is used, it is a fatal error for its argument
dnl to be invalid
if test "$apr_found" != "yes"; then
AC_MSG_ERROR([the --with-apr parameter is incorrect. It must specify an install prefix, a build directory, or an apr-config file.])
fi
],[
dnl If we allow installed copies, check those before using bundled copy.
if test -n "$3" && test "$3" = "1"; then
for apr_temp_apr_config_file in $apr_temp_acceptable_apr_config
do
if $apr_temp_apr_config_file --help > /dev/null 2>&1 ; then
apr_found="yes"
apr_config="$apr_temp_apr_config_file"
break
else
dnl look in some standard places
for lookdir in /usr /usr/local /usr/local/apr /opt/apr; do
if $TEST_X "$lookdir/bin/$apr_temp_apr_config_file"; then
apr_found="yes"
apr_config="$lookdir/bin/$apr_temp_apr_config_file"
break 2
fi
done
fi
done
fi
dnl if we have not found anything yet and have bundled source, use that
if test "$apr_found" = "no" && test -d "$1"; then
apr_temp_abs_srcdir="`cd $1 && pwd`"
apr_found="reconfig"
apr_bundled_major="`sed -n '/#define.*APR_MAJOR_VERSION/s/^[^0-9]*\([0-9]*\).*$/\1/p' \"$1/include/apr_version.h\"`"
case $apr_bundled_major in
"")
AC_MSG_ERROR([failed to find major version of bundled APR])
;;
0)
apr_temp_apr_config_file="apr-config"
;;
*)
apr_temp_apr_config_file="apr-$apr_bundled_major-config"
;;
esac
if test -n "$2"; then
apr_config="$2/$apr_temp_apr_config_file"
else
apr_config="$1/$apr_temp_apr_config_file"
fi
fi
])
AC_MSG_RESULT($apr_found)
])

View File

@ -0,0 +1,176 @@
dnl -------------------------------------------------------- -*- autoconf -*-
dnl Copyright 2002-2005 The Apache Software Foundation or its licensors, as
dnl applicable.
dnl
dnl Licensed under the Apache License, Version 2.0 (the "License");
dnl you may not use this file except in compliance with the License.
dnl You may obtain a copy of the License at
dnl
dnl http://www.apache.org/licenses/LICENSE-2.0
dnl
dnl Unless required by applicable law or agreed to in writing, software
dnl distributed under the License is distributed on an "AS IS" BASIS,
dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
dnl See the License for the specific language governing permissions and
dnl limitations under the License.
dnl
dnl find_apu.m4 : locate the APR-util (APU) include files and libraries
dnl
dnl This macro file can be used by applications to find and use the APU
dnl library. It provides a standardized mechanism for using APU. It supports
dnl embedding APU into the application source, or locating an installed
dnl copy of APU.
dnl
dnl APR_FIND_APU(srcdir, builddir, implicit-install-check, acceptable-majors)
dnl
dnl where srcdir is the location of the bundled APU source directory, or
dnl empty if source is not bundled.
dnl
dnl where builddir is the location where the bundled APU will be built,
dnl or empty if the build will occur in the srcdir.
dnl
dnl where implicit-install-check set to 1 indicates if there is no
dnl --with-apr-util option specified, we will look for installed copies.
dnl
dnl where acceptable-majors is a space separated list of acceptable major
dnl version numbers. Often only a single major version will be acceptable.
dnl If multiple versions are specified, and --with-apr-util=PREFIX or the
dnl implicit installed search are used, then the first (leftmost) version
dnl in the list that is found will be used. Currently defaults to [0 1].
dnl
dnl Sets the following variables on exit:
dnl
dnl apu_found : "yes", "no", "reconfig"
dnl
dnl apu_config : If the apu-config tool exists, this refers to it. If
dnl apu_found is "reconfig", then the bundled directory
dnl should be reconfigured *before* using apu_config.
dnl
dnl Note: this macro file assumes that apr-config has been installed; it
dnl is normally considered a required part of an APR installation.
dnl
dnl Note: At this time, we cannot find *both* a source dir and a build dir.
dnl If both are available, the build directory should be passed to
dnl the --with-apr-util switch.
dnl
dnl Note: the installation layout is presumed to follow the standard
dnl PREFIX/lib and PREFIX/include pattern. If the APU config file
dnl is available (and can be found), then non-standard layouts are
dnl possible, since it will be described in the config file.
dnl
dnl If a bundled source directory is available and needs to be (re)configured,
dnl then apu_found is set to "reconfig". The caller should reconfigure the
dnl (passed-in) source directory, placing the result in the build directory,
dnl as appropriate.
dnl
dnl If apu_found is "yes" or "reconfig", then the caller should use the
dnl value of apu_config to fetch any necessary build/link information.
dnl
AC_DEFUN([APR_FIND_APU], [
apu_found="no"
if test "$target_os" = "os2-emx"; then
# Scripts don't pass test -x on OS/2
TEST_X="test -f"
else
TEST_X="test -x"
fi
ifelse([$4], [],
[
ifdef(AC_WARNING,([$0: missing argument 4 (acceptable-majors): Defaulting to APU 0.x then APU 1.x]))
acceptable_majors="0 1"
], [acceptable_majors="$4"])
apu_temp_acceptable_apu_config=""
for apu_temp_major in $acceptable_majors
do
case $apu_temp_major in
0)
apu_temp_acceptable_apu_config="$apu_temp_acceptable_apu_config apu-config"
;;
*)
apu_temp_acceptable_apu_config="$apu_temp_acceptable_apu_config apu-$apu_temp_major-config"
;;
esac
done
AC_MSG_CHECKING(for APR-util)
AC_ARG_WITH(apr-util,
[ --with-apr-util=PATH prefix for installed APU, path to APU build tree,
or the full path to apu-config],
[
if test "$withval" = "no" || test "$withval" = "yes"; then
AC_MSG_ERROR([--with-apr-util requires a directory or file to be provided])
fi
for apu_temp_apu_config_file in $apu_temp_acceptable_apu_config
do
for lookdir in "$withval/bin" "$withval"
do
if $TEST_X "$lookdir/$apu_temp_apu_config_file"; then
apu_found="yes"
apu_config="$lookdir/$apu_temp_apu_config_file"
break 2
fi
done
done
if test "$apu_found" != "yes" && $TEST_X "$withval" && $withval --help > /dev/null 2>&1 ; then
apu_found="yes"
apu_config="$withval"
fi
dnl if --with-apr-util is used, it is a fatal error for its argument
dnl to be invalid
if test "$apu_found" != "yes"; then
AC_MSG_ERROR([the --with-apr-util parameter is incorrect. It must specify an install prefix, a build directory, or an apu-config file.])
fi
],[
if test -n "$3" && test "$3" = "1"; then
for apu_temp_apu_config_file in $apu_temp_acceptable_apu_config
do
if $apu_temp_apu_config_file --help > /dev/null 2>&1 ; then
apu_found="yes"
apu_config="$apu_temp_apu_config_file"
break
else
dnl look in some standard places (apparently not in builtin/default)
for lookdir in /usr /usr/local /usr/local/apr /opt/apr /usr/local/apache2 ; do
if $TEST_X "$lookdir/bin/$apu_temp_apu_config_file"; then
apu_found="yes"
apu_config="$lookdir/bin/$apu_temp_apu_config_file"
break 2
fi
done
fi
done
fi
dnl if we have not found anything yet and have bundled source, use that
if test "$apu_found" = "no" && test -d "$1"; then
apu_temp_abs_srcdir="`cd $1 && pwd`"
apu_found="reconfig"
apu_bundled_major="`sed -n '/#define.*APU_MAJOR_VERSION/s/^[^0-9]*\([0-9]*\).*$/\1/p' \"$1/include/apu_version.h\"`"
case $apu_bundled_major in
"")
AC_MSG_ERROR([failed to find major version of bundled APU])
;;
0)
apu_temp_apu_config_file="apu-config"
;;
*)
apu_temp_apu_config_file="apu-$apu_bundled_major-config"
;;
esac
if test -n "$2"; then
apu_config="$2/$apu_temp_apu_config_file"
else
apu_config="$1/$apu_temp_apu_config_file"
fi
fi
])
AC_MSG_RESULT($apu_found)
])

View File

@ -0,0 +1,49 @@
dnl UNIMRCP_CHECK_SOFIA
AC_DEFUN([UNIMRCP_CHECK_SOFIA],
[
AC_MSG_NOTICE([Sofia SIP library configuration])
AC_MSG_CHECKING([for Sofia-SIP])
AC_ARG_WITH(sofia-sip,
[ --with-sofia-sip=PATH prefix for installed Sofia-SIP or
path to Sofia-SIP build tree],
[sofia_path=$withval],
[sofia_path="/usr/local"]
)
sofiaconfig="lib/pkgconfig/sofia-sip-ua.pc"
sofiasrcdir="libsofia-sip-ua"
for dir in $sofia_path ; do
cd $dir && sofiadir=`pwd` && cd - > /dev/null
if test -f "$dir/$sofiaconfig"; then
found_sofia="yes"
UNIMRCP_SOFIA_INCLUDES="`pkg-config --cflags $dir/$sofiaconfig`"
UNIMRCP_SOFIA_LIBS="`pkg-config --libs $dir/$sofiaconfig`"
sofia_version="`pkg-config --modversion $dir/$sofiaconfig`"
break
fi
if test -d "$dir/$sofiasrcdir"; then
found_sofia="yes"
UNIMRCP_SOFIA_INCLUDES="-I$sofiadir/$sofiasrcdir -I$sofiadir/$sofiasrcdir/bnf -I$sofiadir/$sofiasrcdir/features -I$sofiadir/$sofiasrcdir/http -I$sofiadir/$sofiasrcdir/ipt -I$sofiadir/$sofiasrcdir/iptsec -I$sofiadir/$sofiasrcdir/msg -I$sofiadir/$sofiasrcdir/nea -I$sofiadir/$sofiasrcdir/nta -I$sofiadir/$sofiasrcdir/nth -I$sofiadir/$sofiasrcdir/nua -I$sofiadir/$sofiasrcdir/sdp -I$sofiadir/$sofiasrcdir/sip -I$sofiadir/$sofiasrcdir/soa -I$sofiadir/$sofiasrcdir/sresolv -I$sofiadir/$sofiasrcdir/stun -I$sofiadir/$sofiasrcdir/su -I$sofiadir/$sofiasrcdir/tport -I$sofiadir/$sofiasrcdir/url"
UNIMRCP_SOFIA_LIBS="$sofiadir/$sofiasrcdir/libsofia-sip-ua.la"
sofia_version="`pkg-config --modversion $sofiadir/packages/sofia-sip-ua.pc`"
break
fi
done
if test x_$found_sofia != x_yes; then
AC_MSG_ERROR(Cannot find Sofia-SIP - looked for sofia-config:$sofiaconfig and srcdir:$sofiasrcdir in $sofia_path)
else
AC_MSG_RESULT([$found_sofia])
AC_MSG_RESULT([$sofia_version])
case "$host" in
*darwin*)
UNIMRCP_SOFIA_LIBS="$UNIMRCP_SOFIA_LIBS -framework CoreFoundation -framework SystemConfiguration" ;;
esac
AC_SUBST(UNIMRCP_SOFIA_INCLUDES)
AC_SUBST(UNIMRCP_SOFIA_LIBS)
fi
])

View File

@ -0,0 +1,30 @@
dnl UNIMRCP_CHECK_SWIFT
AC_DEFUN([UNIMRCP_CHECK_SWIFT],
[
AC_MSG_NOTICE([Cepstral Swift library configuration])
AC_MSG_CHECKING([for Swift])
AC_ARG_WITH(swift,
[ --with-swift=PATH prefix for installed Swift],
[swift_path=$withval],
[swift_path="/opt/swift"]
)
if test -d "$swift_path"; then
found_swift="yes"
UNIMRCP_SWIFT_INCLUDES="-I$swift_path/include"
UNIMRCP_SWIFT_LIBS="-lswift -lceplex_us -lceplang_en -lm"
UNIMRCP_SWIFT_LDFLAGS="-L$swift_path/lib/ -R$swift_path/lib/"
AC_SUBST(UNIMRCP_SWIFT_INCLUDES)
AC_SUBST(UNIMRCP_SWIFT_LIBS)
AC_SUBST(UNIMRCP_SWIFT_LDFLAGS)
AC_MSG_RESULT($swift_path)
else
AC_MSG_WARN([not found - looked for $swift_path])
fi
AM_CONDITIONAL([CEPSTRAL_PLUGIN], [test x_$found_swift = x_yes])
])

View File

@ -0,0 +1,37 @@
#!/bin/sh
#
# extract version numbers from a header file
#
# USAGE: get-version.sh CMD VERSION_HEADER PREFIX
# where CMD is one of: all, major, libtool
# where PREFIX is the prefix to {MAJOR|MINOR|PATCH}_VERSION defines
#
# get-version.sh all returns a dotted version number
# get-version.sh major returns just the major version number
# get-version.sh libtool returns a version "libtool -version-info" format
#
if test $# != 3; then
echo "USAGE: $0 CMD VERSION_HEADER PREFIX"
echo " where CMD is one of: all, major, libtool"
exit 1
fi
major_sed="/#define.*$3_MAJOR_VERSION/s/^[^0-9]*\([0-9]*\).*$/\1/p"
minor_sed="/#define.*$3_MINOR_VERSION/s/^[^0-9]*\([0-9]*\).*$/\1/p"
patch_sed="/#define.*$3_PATCH_VERSION/s/^[^0-9]*\([0-9]*\).*$/\1/p"
major="`sed -n $major_sed $2`"
minor="`sed -n $minor_sed $2`"
patch="`sed -n $patch_sed $2`"
if test "$1" = "all"; then
echo ${major}.${minor}.${patch}
elif test "$1" = "major"; then
echo ${major}
elif test "$1" = "libtool"; then
# Yes, ${minor}:${patch}:${minor} is correct due to libtool idiocy.
echo ${minor}:${patch}:${minor}
else
echo "ERROR: unknown version CMD ($1)"
exit 1
fi

View File

@ -0,0 +1,4 @@
MAINTAINERCLEANFILES = Makefile.in
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = unimrcpclient.pc unimrcpserver.pc unimrcpplugin.pc

View File

@ -0,0 +1,11 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@ @UNIMRCP_APR_INCLUDES@
Name: unimrcpclient
Description: UniMRCP Client Stack
Requires:
Version: @UNI_DOTTED_VERSION@
Libs: -L${libdir} -lunimrcpclient
Cflags: @CPPFLAGS@ @CFLAGS@ -I${includedir}

View File

@ -0,0 +1,11 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@ @UNIMRCP_APR_INCLUDES@
Name: unimrcpplugin
Description: UniMRCP Server Plugin
Requires:
Version: @UNI_DOTTED_VERSION@
Libs: -L${libdir} -lunimrcpserver
Cflags: @CPPFLAGS@ @CFLAGS@ -I${includedir}

View File

@ -0,0 +1,11 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@ @UNIMRCP_APR_INCLUDES@
Name: unimrcpserver
Description: UniMRCP Server Stack
Requires:
Version: @UNI_DOTTED_VERSION@
Libs: -L${libdir} -lunimrcpserver
Cflags: @CPPFLAGS@ @CFLAGS@ -I${includedir}

View File

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="prepare"
ProjectGUID="{01D63BF5-7798-4746-852A-4B45229BB735}"
RootNamespace="prepare"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="10"
InheritedPropertySheets="$(SolutionDir)build\vsprops\apr.vsprops;$(SolutionDir)build\vsprops\sofiasip.vsprops"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
CommandLine="xcopy &quot;$(AprDir)\$(ConfigurationName)\libapr-1.dll&quot; &quot;$(SolutionDir)$(ConfigurationName)\bin\&quot; /Y&#x0D;&#x0A;xcopy &quot;$(AprUtilDir)\$(ConfigurationName)\libaprutil-1.dll&quot; &quot;$(SolutionDir)$(ConfigurationName)\bin\&quot; /Y&#x0D;&#x0A;xcopy &quot;$(AprIconvDir)\$(ConfigurationName)\libapriconv-1.dll&quot; &quot;$(SolutionDir)$(ConfigurationName)\bin\&quot; /Y&#x0D;&#x0A;xcopy &quot;$(SofiaDir)\win32\libsofia-sip-ua\$(ConfigurationName)\libsofia_sip_ua.dll&quot; &quot;$(SolutionDir)$(ConfigurationName)\bin\&quot; /Y&#x0D;&#x0A;xcopy &quot;$(SofiaDir)\win32\pthread\pthreadVC2.dll&quot; &quot;$(SolutionDir)$(ConfigurationName)\bin\&quot; /Y&#x0D;&#x0A;&#x0D;&#x0A;if not exist &quot;$(SolutionDir)$(ConfigurationName)\conf&quot; xcopy &quot;$(SolutionDir)conf\*.xml&quot; &quot;$(SolutionDir)$(ConfigurationName)\conf\&quot; /Y&#x0D;&#x0A;if not exist &quot;$(SolutionDir)$(ConfigurationName)\data&quot; xcopy &quot;$(SolutionDir)data\*&quot; &quot;$(SolutionDir)$(ConfigurationName)\data\&quot; /Y&#x0D;&#x0A;if not exist &quot;$(SolutionDir)$(ConfigurationName)\log&quot; mkdir &quot;$(SolutionDir)$(ConfigurationName)\log\&quot;&#x0D;&#x0A;"
ExcludedFromBuild="false"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
ConfigurationType="10"
InheritedPropertySheets="$(SolutionDir)build\vsprops\apr.vsprops;$(SolutionDir)build\vsprops\sofiasip.vsprops"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
CommandLine="xcopy &quot;$(AprDir)\$(ConfigurationName)\libapr-1.dll&quot; &quot;$(SolutionDir)$(ConfigurationName)\bin\&quot; /Y&#x0D;&#x0A;xcopy &quot;$(AprUtilDir)\$(ConfigurationName)\libaprutil-1.dll&quot; &quot;$(SolutionDir)$(ConfigurationName)\bin\&quot; /Y&#x0D;&#x0A;xcopy &quot;$(AprIconvDir)\$(ConfigurationName)\libapriconv-1.dll&quot; &quot;$(SolutionDir)$(ConfigurationName)\bin\&quot; /Y&#x0D;&#x0A;xcopy &quot;$(SofiaDir)\win32\libsofia-sip-ua\$(ConfigurationName)\libsofia_sip_ua.dll&quot; &quot;$(SolutionDir)$(ConfigurationName)\bin\&quot; /Y&#x0D;&#x0A;xcopy &quot;$(SofiaDir)\win32\pthread\pthreadVC2.dll&quot; &quot;$(SolutionDir)$(ConfigurationName)\bin\&quot; /Y&#x0D;&#x0A;&#x0D;&#x0A;if not exist &quot;$(SolutionDir)$(ConfigurationName)\conf&quot; xcopy &quot;$(SolutionDir)conf\*.xml&quot; &quot;$(SolutionDir)$(ConfigurationName)\conf\&quot; /Y&#x0D;&#x0A;if not exist &quot;$(SolutionDir)$(ConfigurationName)\data&quot; xcopy &quot;$(SolutionDir)data\*&quot; &quot;$(SolutionDir)$(ConfigurationName)\data\&quot; /Y&#x0D;&#x0A;if not exist &quot;$(SolutionDir)$(ConfigurationName)\log&quot; mkdir &quot;$(SolutionDir)$(ConfigurationName)\log\&quot;&#x0D;&#x0A;"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,235 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <windows.h>
#include <apr_getopt.h>
#include "apt.h"
#include "apt_pool.h"
#define WIN_SERVICE_NAME "unimrcp"
/** Register/install service in SCM */
static apt_bool_t uni_service_register(const char *root_dir_path, apr_pool_t *pool)
{
char *bin_path;
SERVICE_DESCRIPTION desc;
SC_HANDLE sch_service;
SC_HANDLE sch_manager = OpenSCManager(0,0,SC_MANAGER_ALL_ACCESS);
if(!sch_manager) {
printf("Failed to Open SCManager %d\n", GetLastError());
return FALSE;
}
bin_path = apr_psprintf(pool,"%s\\bin\\unimrcpserver.exe --service --root-dir \"%s\" -o 2",
root_dir_path,
root_dir_path);
sch_service = CreateService(
sch_manager,
WIN_SERVICE_NAME,
"UniMRCP Server",
GENERIC_EXECUTE | SERVICE_CHANGE_CONFIG,
SERVICE_WIN32_OWN_PROCESS,
SERVICE_DEMAND_START,
SERVICE_ERROR_NORMAL,
bin_path,0,0,0,0,0);
if(!sch_service) {
printf("Failed to Create Service %d\n", GetLastError());
CloseServiceHandle(sch_manager);
return FALSE;
}
desc.lpDescription = "Launches UniMRCP Server";
if(!ChangeServiceConfig2(sch_service,SERVICE_CONFIG_DESCRIPTION,&desc)) {
printf("Failed to Set Service Description %d\n", GetLastError());
}
CloseServiceHandle(sch_service);
CloseServiceHandle(sch_manager);
return TRUE;
}
/** Unregister/uninstall service from SCM */
static apt_bool_t uni_service_unregister()
{
apt_bool_t status = TRUE;
SERVICE_STATUS ss_status;
SC_HANDLE sch_service;
SC_HANDLE sch_manager = OpenSCManager(0,0,SC_MANAGER_ALL_ACCESS);
if(!sch_manager) {
printf("Failed to Open SCManager %d\n", GetLastError());
return FALSE;
}
sch_service = OpenService(sch_manager,WIN_SERVICE_NAME,DELETE|SERVICE_STOP);
if(!sch_service) {
printf("Failed to Open Service %d\n", GetLastError());
CloseServiceHandle(sch_manager);
return FALSE;
}
ControlService(sch_service,SERVICE_CONTROL_STOP,&ss_status);
if(!DeleteService(sch_service)) {
printf("Failed to Delete Service %d\n", GetLastError());
status = FALSE;
}
CloseServiceHandle(sch_service);
CloseServiceHandle(sch_manager);
return status;
}
/** Start service */
static apt_bool_t uni_service_start()
{
apt_bool_t status = TRUE;
SC_HANDLE sch_service;
SC_HANDLE sch_manager = OpenSCManager(0,0,SC_MANAGER_ALL_ACCESS);
if(!sch_manager) {
printf("Failed to Open SCManager %d\n", GetLastError());
return FALSE;
}
sch_service = OpenService(sch_manager,WIN_SERVICE_NAME,SERVICE_START);
if(!sch_service) {
printf("Failed to Open Service %d\n", GetLastError());
CloseServiceHandle(sch_manager);
return FALSE;
}
if(!StartService(sch_service,0,NULL)) {
printf("Failed to Start Service %d\n", GetLastError());
status = FALSE;
}
CloseServiceHandle(sch_service);
CloseServiceHandle(sch_manager);
return status;
}
/** Stop service */
static apt_bool_t uni_service_stop()
{
apt_bool_t status = TRUE;
SERVICE_STATUS ss_status;
SC_HANDLE sch_service;
SC_HANDLE sch_manager = OpenSCManager(0,0,SC_MANAGER_ALL_ACCESS);
if(!sch_manager) {
printf("Failed to Open SCManager %d\n", GetLastError());
return FALSE;
}
sch_service = OpenService(sch_manager,WIN_SERVICE_NAME,SERVICE_STOP);
if(!sch_service) {
printf("Failed to Open Service %d\n", GetLastError());
CloseServiceHandle(sch_manager);
return FALSE;
}
if(!ControlService(sch_service,SERVICE_CONTROL_STOP,&ss_status)) {
printf("Failed to Stop Service %d\n", GetLastError());
status = FALSE;
}
CloseServiceHandle(sch_service);
CloseServiceHandle(sch_manager);
return status;
}
static void usage()
{
printf(
"\n"
"Usage:\n"
"\n"
" unimrcpservice [options]\n"
"\n"
" Available options:\n"
"\n"
" -r [--register] rootdir : Register the Windows service.\n"
"\n"
" -u [--unregister] : Unregister the Windows service.\n"
"\n"
" -s [--start] : Start the Windows service.\n"
"\n"
" -t [--stop] : Stop the Windows service.\n"
"\n"
" -h [--help] : Show the help.\n"
"\n");
}
int main(int argc, const char * const *argv)
{
apr_pool_t *pool;
apr_status_t rv;
apr_getopt_t *opt;
static const apr_getopt_option_t opt_option[] = {
/* long-option, short-option, has-arg flag, description */
{ "register", 'r', TRUE, "register service" }, /* -r or --register arg */
{ "unregister", 'u', FALSE, "unregister service" },/* -u or --unregister */
{ "start", 's', FALSE, "start service" }, /* -s or --start */
{ "stop", 't', FALSE, "stop service" }, /* -t or --stop */
{ "help", 'h', FALSE, "show help" }, /* -h or --help */
{ NULL, 0, 0, NULL }, /* end */
};
/* APR global initialization */
if(apr_initialize() != APR_SUCCESS) {
apr_terminate();
return 0;
}
/* create APR pool */
pool = apt_pool_create();
if(!pool) {
apr_terminate();
return 0;
}
rv = apr_getopt_init(&opt, pool , argc, argv);
if(rv == APR_SUCCESS) {
int optch;
const char *optarg;
while((rv = apr_getopt_long(opt, opt_option, &optch, &optarg)) == APR_SUCCESS) {
switch(optch) {
case 'r':
uni_service_register(optarg,pool);
break;
case 'u':
uni_service_unregister();
break;
case 's':
uni_service_start();
break;
case 't':
uni_service_stop();
break;
case 'h':
usage();
break;
}
}
if(rv != APR_EOF) {
usage();
}
}
/* destroy APR pool */
apr_pool_destroy(pool);
/* APR global termination */
apr_terminate();
return 0;
}

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="<AppName>" type="win32"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>

View File

@ -0,0 +1,159 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="unimrcpservice"
ProjectGUID="{4714EF49-BFD5-4B22-95F7-95A07F1EAC25}"
RootNamespace="unimrcpservice"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
ConfigurationType="1"
InheritedPropertySheets="$(SolutionDir)build\vsprops\unidebug.vsprops;$(SolutionDir)build\vsprops\apt.vsprops"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="libaprutil-1.lib libapr-1.lib"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
AdditionalManifestFiles="unimrcpservice.exe.manifest"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
ConfigurationType="1"
InheritedPropertySheets="$(SolutionDir)build\vsprops\unirelease.vsprops;$(SolutionDir)build\vsprops\apt.vsprops"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="libaprutil-1.lib libapr-1.lib"
LinkTimeCodeGeneration="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
AdditionalManifestFiles="unimrcpservice.exe.manifest"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="src"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\unimrcp_service.c"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,66 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __UNI_VERSION_H__
#define __UNI_VERSION_H__
/**
* @file uni_version.h
* @brief UniMRCP Version Numbering
*
* UniMRCP version numbering is derived from APR project specified in:
*
* http://apr.apache.org/versioning.html
*/
#include <apr_version.h>
/** major version
* Major API changes that could cause compatibility problems for older
* programs such as structure size changes. No binary compatibility is
* possible across a change in the major version.
*/
#define UNI_MAJOR_VERSION 0
/** minor version
* Minor API changes that do not cause binary compatibility problems.
* Reset to 0 when upgrading UNI_MAJOR_VERSION
*/
#define UNI_MINOR_VERSION 6
/** patch level
* The Patch Level never includes API changes, simply bug fixes.
* Reset to 0 when upgrading UNI_MINOR_VERSION
*/
#define UNI_PATCH_VERSION 0
/**
* Check at compile time if the UNI version is at least a certain
* level.
*/
#define UNI_VERSION_AT_LEAST(major,minor,patch) \
(((major) < UNI_MAJOR_VERSION) \
|| ((major) == UNI_MAJOR_VERSION && (minor) < UNI_MINOR_VERSION) \
|| ((major) == UNI_MAJOR_VERSION && (minor) == UNI_MINOR_VERSION && (patch) <= UNI_PATCH_VERSION))
/** The formatted string of UniMRCP's version */
#define UNI_VERSION_STRING \
APR_STRINGIFY(UNI_MAJOR_VERSION) "." \
APR_STRINGIFY(UNI_MINOR_VERSION) "." \
APR_STRINGIFY(UNI_PATCH_VERSION)
#endif /* __UNI_VERSION_H__ */

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioPropertySheet
ProjectType="Visual C++"
Version="8.00"
Name="apr"
InheritedPropertySheets="$(SolutionDir)build\vsprops\unibase.vsprops"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;$(AprDir)\include&quot;;&quot;$(AprUtilDir)\include&quot;"
/>
<Tool
Name="VCLinkerTool"
AdditionalLibraryDirectories="&quot;$(AprDir)\$(ConfigurationName)&quot;;&quot;$(AprUtilDir)\$(ConfigurationName)&quot;"
/>
<UserMacro
Name="AprDir"
Value="$(ProjectRootDir)libs\apr"
/>
<UserMacro
Name="AprUtilDir"
Value="$(ProjectRootDir)libs\apr-util"
/>
<UserMacro
Name="AprIconvDir"
Value="$(ProjectRootDir)libs\apr-iconv"
/>
</VisualStudioPropertySheet>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioPropertySheet
ProjectType="Visual C++"
Version="8.00"
Name="apt"
InheritedPropertySheets="apr.vsprops"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;$(ProjectRootDir)libs\apr-toolkit\include&quot;"
PreprocessorDefinitions="APT_STATIC_LIB"
/>
<Tool
Name="VCLinkerTool"
AdditionalLibraryDirectories="&quot;$(OutDir)&quot;"
/>
</VisualStudioPropertySheet>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioPropertySheet
ProjectType="Visual C++"
Version="8.00"
Name="cepstral"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;$(CepstralSDKDir)\include&quot;"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="swift.lib"
AdditionalLibraryDirectories="&quot;$(CepstralSDKDir)\lib\lib-windows&quot;"
/>
<UserMacro
Name="CepstralSDKDir"
Value="C:\Program Files\Cepstral\sdk"
/>
</VisualStudioPropertySheet>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioPropertySheet
ProjectType="Visual C++"
Version="8.00"
Name="mpf"
InheritedPropertySheets="apt.vsprops"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;$(ProjectRootDir)libs\mpf\include&quot;"
PreprocessorDefinitions="MPF_STATIC_LIB"
/>
<Tool
Name="VCLinkerTool"
AdditionalLibraryDirectories="&quot;$(OutDir)&quot;"
/>
</VisualStudioPropertySheet>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioPropertySheet
ProjectType="Visual C++"
Version="8.00"
Name="mrcp"
InheritedPropertySheets=".\apt.vsprops"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;$(ProjectRootDir)libs\mrcp\include&quot;;&quot;$(ProjectRootDir)libs\mrcp\message\include&quot;;&quot;$(ProjectRootDir)libs\mrcp\control\include&quot;;&quot;$(ProjectRootDir)libs\mrcp\resources\include&quot;"
PreprocessorDefinitions="MRCP_STATIC_LIB"
/>
<Tool
Name="VCLinkerTool"
AdditionalLibraryDirectories="&quot;$(OutDir)&quot;"
/>
</VisualStudioPropertySheet>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioPropertySheet
ProjectType="Visual C++"
Version="8.00"
Name="mrcpclient"
InheritedPropertySheets=".\mrcpsignaling.vsprops;.\mrcpv2transport.vsprops"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;$(ProjectRootDir)libs\mrcp-client\include&quot;"
/>
<Tool
Name="VCLinkerTool"
AdditionalLibraryDirectories="&quot;$(OutDir)&quot;"
/>
</VisualStudioPropertySheet>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioPropertySheet
ProjectType="Visual C++"
Version="8.00"
Name="mrcpengine"
InheritedPropertySheets=".\mpf.vsprops;.\mrcp.vsprops"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;$(ProjectRootDir)libs\mrcp-engine\include&quot;"
/>
<Tool
Name="VCLinkerTool"
AdditionalLibraryDirectories="&quot;$(OutDir)&quot;"
/>
</VisualStudioPropertySheet>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioPropertySheet
ProjectType="Visual C++"
Version="8.00"
Name="mrcpserver"
InheritedPropertySheets=".\mrcpengine.vsprops;.\mrcpsignaling.vsprops;.\mrcpv2transport.vsprops"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;$(ProjectRootDir)libs\mrcp-server\include&quot;"
/>
<Tool
Name="VCLinkerTool"
AdditionalLibraryDirectories="&quot;$(OutDir)&quot;"
/>
</VisualStudioPropertySheet>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioPropertySheet
ProjectType="Visual C++"
Version="8.00"
Name="mrcpsignaling"
InheritedPropertySheets=".\mpf.vsprops;.\mrcp.vsprops"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;$(ProjectRootDir)libs\mrcp-signaling\include&quot;"
/>
<Tool
Name="VCLinkerTool"
AdditionalLibraryDirectories="&quot;$(OutDir)&quot;"
/>
</VisualStudioPropertySheet>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioPropertySheet
ProjectType="Visual C++"
Version="8.00"
Name="mrcpv2transport"
InheritedPropertySheets=".\mrcp.vsprops"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;$(ProjectRootDir)libs\mrcpv2-transport\include&quot;"
/>
<Tool
Name="VCLinkerTool"
AdditionalLibraryDirectories="&quot;$(OutDir)&quot;"
/>
</VisualStudioPropertySheet>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioPropertySheet
ProjectType="Visual C++"
Version="8.00"
Name="unimrcpclient"
InheritedPropertySheets="unimrcpsdk.vsprops"
>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="libunimrcpclient.lib mrcpsofiasip.lib mrcpunirtsp.lib unirtsp.lib mrcpclient.lib mrcpv2transport.lib mrcpsignaling.lib libsofia_sip_ua.lib ws2_32.lib winmm.lib"
/>
</VisualStudioPropertySheet>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioPropertySheet
ProjectType="Visual C++"
Version="8.00"
Name="unimrcpplugin"
InheritedPropertySheets="unimrcpsdk.vsprops"
>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="mrcpengine.lib"
/>
</VisualStudioPropertySheet>

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioPropertySheet
ProjectType="Visual C++"
Version="8.00"
Name="unimrcpsdk"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;$(ProjectRootDir)\include&quot;"
PreprocessorDefinitions="APT_STATIC_LIB;MPF_STATIC_LIB;MRCP_STATIC_LIB"
/>
<Tool
Name="VCLinkerTool"
AdditionalLibraryDirectories="&quot;$(ProjectRootDir)\lib&quot;"
AdditionalDependencies="mrcp.lib mpf.lib aprtoolkit.lib libaprutil-1.lib libapr-1.lib"
/>
<UserMacro
Name="ProjectRootDir"
Value="C:\Program Files\UniMRCP"
/>
</VisualStudioPropertySheet>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioPropertySheet
ProjectType="Visual C++"
Version="8.00"
Name="unimrcpserver"
InheritedPropertySheets="unimrcpsdk.vsprops"
>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="libunimrcpserver.lib mrcpsofiasip.lib mrcpunirtsp.lib unirtsp.lib mrcpserver.lib mrcpv2transport.lib mrcpsignaling.lib mrcpengine.lib libsofia_sip_ua.lib ws2_32.lib winmm.lib"
/>
</VisualStudioPropertySheet>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioPropertySheet
ProjectType="Visual C++"
Version="8.00"
Name="sofiasip"
InheritedPropertySheets="$(SolutionDir)build\vsprops\unibase.vsprops"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;$(SofiaDir)\win32&quot;;&quot;$(SofiaDir)\libsofia-sip-ua\su&quot;;&quot;$(SofiaDir)\libsofia-sip-ua\nua&quot;;&quot;$(SofiaDir)\libsofia-sip-ua\url&quot;;&quot;$(SofiaDir)\libsofia-sip-ua\sip&quot;;&quot;$(SofiaDir)\libsofia-sip-ua\msg&quot;;&quot;$(SofiaDir)\libsofia-sip-ua\sdp&quot;;&quot;$(SofiaDir)\libsofia-sip-ua\nta&quot;;&quot;$(SofiaDir)\libsofia-sip-ua\nea&quot;;&quot;$(SofiaDir)\libsofia-sip-ua\soa&quot;;&quot;$(SofiaDir)\libsofia-sip-ua\iptsec&quot;;&quot;$(SofiaDir)\libsofia-sip-ua\bnf&quot;;&quot;$(SofiaDir)\libsofia-sip-ua\features&quot;"
/>
<Tool
Name="VCLinkerTool"
AdditionalLibraryDirectories="&quot;$(SofiaDir)\win32\libsofia-sip-ua\$(ConfigurationName)&quot;"
/>
<UserMacro
Name="SofiaDir"
Value="$(ProjectRootDir)libs\sofia-sip"
/>
</VisualStudioPropertySheet>

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioPropertySheet
ProjectType="Visual C++"
Version="8.00"
Name="unibase"
OutputDirectory="$(SolutionDir)$(ConfigurationName)\bin"
IntermediateDirectory="$(ConfigurationName)"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32"
WarningLevel="4"
WarnAsError="true"
DisableSpecificWarnings="4100"
/>
<Tool
Name="VCLinkerTool"
AdditionalLibraryDirectories="&quot;$(OutDir)&quot;"
/>
<UserMacro
Name="ProjectRootDir"
Value="$(SolutionDir)"
/>
</VisualStudioPropertySheet>

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioPropertySheet
ProjectType="Visual C++"
Version="8.00"
Name="unidebug"
InheritedPropertySheets="$(SolutionDir)build\vsprops\unibase.vsprops"
>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="_DEBUG"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
DebugInformationFormat="4"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="2"
GenerateDebugInformation="true"
TargetMachine="1"
/>
</VisualStudioPropertySheet>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioPropertySheet
ProjectType="Visual C++"
Version="8.00"
Name="unimrcpclient"
InheritedPropertySheets=".\mrcpclient.vsprops;.\sofiasip.vsprops"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;$(ProjectRootDir)platforms\libunimrcp-client\include&quot;;&quot;$(ProjectRootDir)build&quot;"
/>
<Tool
Name="VCLinkerTool"
AdditionalLibraryDirectories="&quot;$(OutDir)&quot;"
/>
<UserMacro
Name="UniMRCPClientLibs"
Value="libunimrcpclient.lib mrcpclient.lib mrcpsignaling.lib mrcp.lib aprtoolkit.lib libaprutil-1.lib libapr-1.lib libsofia_sip_ua.lib ws2_32.lib winmm.lib"
/>
</VisualStudioPropertySheet>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioPropertySheet
ProjectType="Visual C++"
Version="8.00"
Name="unimrcpplugin"
OutputDirectory="$(SolutionDir)$(ConfigurationName)\plugin"
InheritedPropertySheets=".\mrcpengine.vsprops"
>
<Tool
Name="VCLinkerTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalLibraryDirectories="&quot;$(SolutionDir)$(ConfigurationName)\bin&quot;"
AdditionalDependencies="mrcpengine.lib mrcp.lib mpf.lib aprtoolkit.lib libaprutil-1.lib libapr-1.lib"
/>
</VisualStudioPropertySheet>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioPropertySheet
ProjectType="Visual C++"
Version="8.00"
Name="unimrcpserver"
InheritedPropertySheets=".\mrcpserver.vsprops;.\sofiasip.vsprops"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;$(ProjectRootDir)platforms\libunimrcp-server\include&quot;;&quot;$(ProjectRootDir)build&quot;"
/>
<Tool
Name="VCLinkerTool"
AdditionalLibraryDirectories="&quot;$(OutDir)&quot;"
/>
<UserMacro
Name="UniMRCPServerLibs"
Value="libunimrcpserver.lib mrcpserver.lib mrcpsignaling.lib mrcp.lib aprtoolkit.lib libaprutil-1.lib libapr-1.lib libsofia_sip_ua.lib ws2_32.lib winmm.lib"
/>
</VisualStudioPropertySheet>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioPropertySheet
ProjectType="Visual C++"
Version="8.00"
Name="unirelease"
InheritedPropertySheets="$(SolutionDir)build\vsprops\unibase.vsprops"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="NDEBUG;"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
DebugInformationFormat="3"
/>
</VisualStudioPropertySheet>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioPropertySheet
ProjectType="Visual C++"
Version="8.00"
Name="unirtsp"
InheritedPropertySheets="apt.vsprops"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;$(ProjectRootDir)libs\uni-rtsp\include&quot;"
PreprocessorDefinitions="RTSP_STATIC_LIB"
/>
<Tool
Name="VCLinkerTool"
AdditionalLibraryDirectories="&quot;$(OutDir)&quot;"
/>
</VisualStudioPropertySheet>

View File

@ -0,0 +1,76 @@
<!-- UniMRCP client document -->
<unimrcpclient>
<!-- Client settings (signaling, media, ...) -->
<settings>
<!-- SIP, RTSP signaling agents -->
<signaling>
<!-- SofiaSIP MRCPv2 signaling agent -->
<agent name="SIP-Agent-1" class="SofiaSIP">
<param name="client-ip" value="auto"/>
<!-- <param name="client-ext-ip" value="auto"/> -->
<param name="client-port" value="8062"/>
<param name="server-ip" value="auto"/>
<param name="server-port" value="8060"/>
<!-- <param name="force-destination" value="1"/> -->
<!-- <param name="sip-transport" value="tcp"/> -->
<param name="sip-transport" value="udp"/>
<param name="ua-name" value="UniMRCP SofiaSIP"/>
<param name="sdp-origin" value="UniMRCPClient"/>
</agent>
<!-- UniRTSP MRCPv1 signaling agent -->
<agent name="RTSP-Agent-1" class="UniRTSP">
<param name="server-ip" value="auto"/>
<param name="server-port" value="1554"/>
<!-- <param name="force-destination" value="1"/> -->
<param name="resource-location" value="media"/>
<resourcemap>
<param name="speechsynth" value="speechsynthesizer"/>
<param name="speechrecog" value="speechrecognizer"/>
</resourcemap>
</agent>
</signaling>
<!-- MRCPv2 connection agents -->
<connection>
<agent name="MRCPv2-Agent-1">
<param name="max-connection-count" value="100"/>
<!-- <param name="offer-new-connection" value="1"/> -->
</agent>
</connection>
<!-- Media engines -->
<media>
<engine name="Media-Engine-1"/>
<rtp name="RTP-Factory-1">
<param name="rtp-ip" value="auto"/>
<!-- <param name="rtp-ext-ip" value="auto"/> -->
<param name="rtp-port-min" value="4000"/>
<param name="rtp-port-max" value="5000"/>
<!-- <param name="playout-delay" value="50"/> -->
<!-- <param name="max-playout-delay" value="200"/> -->
<!-- <param name="ptime" value="20"/> -->
<param name="codecs" value="PCMU PCMA L16/96/8000"/>
</rtp>
</media>
</settings>
<!-- Client profiles -->
<profiles>
<!-- MRCPv2 default profile -->
<profile name="MRCPv2-Default">
<param name="signaling-agent" value="SIP-Agent-1"/>
<param name="connection-agent" value="MRCPv2-Agent-1"/>
<param name="media-engine" value="Media-Engine-1"/>
<param name="rtp-factory" value="RTP-Factory-1"/>
</profile>
<!-- MRCPv1 default profile -->
<profile name="MRCPv1-Default">
<param name="signaling-agent" value="RTSP-Agent-1"/>
<param name="media-engine" value="Media-Engine-1"/>
<param name="rtp-factory" value="RTP-Factory-1"/>
</profile>
<!-- more profiles might be added here -->
</profiles>
</unimrcpclient>

View File

@ -0,0 +1,80 @@
<!-- unimrcpserver document -->
<unimrcpserver>
<!-- Server settings (signaling, media, ...) -->
<settings>
<!-- SIP, RTSP signaling agents -->
<signaling>
<agent name="SIP-Agent-1" class="SofiaSIP">
<param name="sip-ip" value="auto"/>
<!-- <param name="sip-ext-ip" value="auto"/> -->
<param name="sip-port" value="8060"/>
<param name="sip-transport" value="udp,tcp"/>
<!-- <param name="force-destination" value="1"/> -->
<param name="ua-name" value="UniMRCP SofiaSIP"/>
<param name="sdp-origin" value="UniMRCPServer"/>
</agent>
<agent name="RTSP-Agent-1" class="UniRTSP">
<param name="rtsp-ip" value="auto"/>
<param name="rtsp-port" value="1554"/>
<!-- <param name="force-destination" value="1"/> -->
<resourcemap>
<param name="speechsynth" value="speechsynthesizer"/>
<param name="speechrecog" value="speechrecognizer"/>
</resourcemap>
</agent>
</signaling>
<!-- MRCPv2 connection agents -->
<connection>
<agent name="MRCPv2-Agent-1">
<param name="mrcp-ip" value="auto"/>
<param name="mrcp-port" value="1544"/>
<param name="max-connection-count" value="100"/>
<!-- <param name="force-new-connection" value="1"/> -->
</agent>
</connection>
<!-- Media engines -->
<media>
<engine name="Media-Engine-1"/>
<rtp name="RTP-Factory-1">
<param name="rtp-ip" value="auto"/>
<!-- <param name="rtp-ext-ip" value="auto"/> -->
<param name="rtp-port-min" value="5000"/>
<param name="rtp-port-max" value="6000"/>
<!-- <param name="playout-delay" value="50"/> -->
<!-- <param name="max-playout-delay" value="200"/> -->
<!-- <param name="ptime" value="20"/> -->
<param name="codecs" value="PCMU PCMA L16/96/8000"/>
<!-- <param name="own-preference" value="1"/> -->
</rtp>
</media>
<!-- Resource plugins -->
<plugin>
<engine name="Cepstral-Swift-1" class="mrcpcepstral" enable="0"/>
<engine name="Demo-Synth-1" class="demosynth" enable="1"/>
<engine name="Demo-Recog-1" class="demorecog" enable="1"/>
</plugin>
</settings>
<!-- Server profiles -->
<profiles>
<!-- MRCPv2 default profile -->
<profile name="MRCPv2-Default">
<param name="signaling-agent" value="SIP-Agent-1"/>
<param name="connection-agent" value="MRCPv2-Agent-1"/>
<param name="media-engine" value="Media-Engine-1"/>
<param name="rtp-factory" value="RTP-Factory-1"/>
</profile>
<!-- MRCPv1 default profile -->
<profile name="MRCPv1-Default">
<param name="signaling-agent" value="RTSP-Agent-1"/>
<param name="media-engine" value="Media-Engine-1"/>
<param name="rtp-factory" value="RTP-Factory-1"/>
</profile>
<!-- more profiles might be added here -->
</profiles>
</unimrcpserver>

149
libs/unimrcp/configure.ac Normal file
View File

@ -0,0 +1,149 @@
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.57)
AC_INIT([unimrcp],[0.6.0])
AC_CONFIG_AUX_DIR([build])
AC_CONFIG_MACRO_DIR([build/acmacros])
AC_PREFIX_DEFAULT(/usr/local/unimrcp)
plugindir='${prefix}/plugin'
confdir='${prefix}/conf'
logdir='${prefix}/log'
datadir='${prefix}/data'
AM_INIT_AUTOMAKE(foreign)
#Set default language
AC_LANG_C
AC_PROG_CC
AC_PROG_CXX
AC_PROG_INSTALL
#skip detection of Fortran
m4_undefine([AC_PROG_F77])
m4_defun([AC_PROG_F77],[])
AC_PROG_LIBTOOL
# get version information
get_version="build/get-version.sh"
version_hdr="build/uni_version.h"
plugin_version_hdr="libs/mrcp-engine/include/mrcp_resource_plugin.h"
UNI_DOTTED_VERSION="`$get_version all $version_hdr UNI`"
UNI_LT_VERSION="-version-info `$get_version libtool $version_hdr UNI`"
PLUGIN_LT_VERSION="-version-info `$get_version libtool $plugin_version_hdr PLUGIN`"
AC_SUBST(UNI_DOTTED_VERSION)
AC_SUBST(UNI_LT_VERSION)
AC_SUBST(PLUGIN_LT_VERSION)
echo "UniMRCP Version: ${UNI_DOTTED_VERSION}"
UNIMRCP_CHECK_APR
UNIMRCP_CHECK_APU
UNIMRCP_CHECK_SOFIA
UNIMRCP_CHECK_SWIFT
AC_SUBST(ac_aux_dir)
AC_SUBST(ac_macro_dir)
AC_SUBST(plugindir)
AC_SUBST(confdir)
AC_SUBST(logdir)
AC_DEFUN([AX_COMPILER_VENDOR],
[
AC_CACHE_CHECK([for _AC_LANG compiler vendor], ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor,
[ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor=unknown
# note: don't check for gcc first since some other compilers define __GNUC__
for ventest in intel:__ICC,__ECC,__INTEL_COMPILER ibm:__xlc__,__xlC__,__IBMC__,__IBMCPP__ gnu:__GNUC__ sun:__SUNPRO_C,__SUNPRO_CC hp:__HP_cc,__HP_aCC dec:__DECC,__DECCXX,__DECC_VER,__DECCXX_VER borland:__BORLANDC__,__TURBOC__ comeau:__COMO__ cray:_CRAYC kai:__KCC lcc:__LCC__ metrowerks:__MWERKS__ sgi:__sgi,sgi microsoft:_MSC_VER watcom:__WATCOMC__ portland:__PGI; do
vencpp="defined("`echo $ventest | cut -d: -f2 | sed 's/,/) || defined(/g'`")"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[
#if !($vencpp)
thisisanerror;
#endif
])], [ax_cv_]_AC_LANG_ABBREV[_compiler_vendor=`echo $ventest | cut -d: -f1`; break])
done
])
])
AX_COMPILER_VENDOR
AC_ARG_ENABLE(maintainer-mode,
[AC_HELP_STRING([--enable-maintainer-mode ],[turn on debugging and compile time warnings])],
[enable_maintainer_mode="$enableval"],
[enable_maintainer_mode="no"])
if test "${enable_maintainer_mode}" != "no"; then
CFLAGS="$CFLAGS -g"
if test "x${ax_cv_c_compiler_vendor}" = "xgnu" ; then
CFLAGS="$CFLAGS -Wall -Werror"
fi
fi
AC_ARG_ENABLE(test-suites,
[AC_HELP_STRING([--enable-test-suites ],[build test suites])],
[enable_test_suites="$enableval"],
[enable_test_suites="no"])
AM_CONDITIONAL([TEST_SUITES],[test "${enable_test_suites}" != "no"])
AC_ARG_ENABLE(demosynth-plugin,
[AC_HELP_STRING([--disable-demosynth-plugin ],[exclude demo synthesizer plugin from build])],
[enable_demosynth_plugin="$enableval"],
[enable_demosynth_plugin="yes"])
AM_CONDITIONAL([DEMOSYNTH_PLUGIN],[test "${enable_demosynth_plugin}" = "yes"])
AC_ARG_ENABLE(demorecog-plugin,
[AC_HELP_STRING([--disable-demorecog-plugin ],[exclude demo recognizer plugin from build])],
[enable_demorecog_plugin="$enableval"],
[enable_demorecog_plugin="yes"])
AM_CONDITIONAL([DEMORECOG_PLUGIN],[test "${enable_demorecog_plugin}" = "yes"])
AC_CONFIG_FILES([
Makefile
libs/Makefile
libs/apr-toolkit/Makefile
libs/mpf/Makefile
libs/mrcp/Makefile
libs/mrcp-signaling/Makefile
libs/mrcpv2-transport/Makefile
libs/mrcp-engine/Makefile
libs/mrcp-server/Makefile
libs/mrcp-client/Makefile
libs/uni-rtsp/Makefile
modules/Makefile
modules/mrcp-sofiasip/Makefile
modules/mrcp-unirtsp/Makefile
plugins/Makefile
plugins/mrcp-cepstral/Makefile
plugins/demo-synth/Makefile
plugins/demo-recog/Makefile
platforms/Makefile
platforms/libunimrcp-server/Makefile
platforms/libunimrcp-client/Makefile
platforms/unimrcp-server/Makefile
platforms/unimrcp-client/Makefile
tests/Makefile
tests/apttest/Makefile
tests/mpftest/Makefile
tests/mrcptest/Makefile
tests/rtsptest/Makefile
tests/strtablegen/Makefile
build/Makefile
build/pkgconfig/Makefile
build/pkgconfig/unimrcpclient.pc
build/pkgconfig/unimrcpserver.pc
build/pkgconfig/unimrcpplugin.pc
])
AC_OUTPUT

BIN
libs/unimrcp/data/demo.pcm Normal file

Binary file not shown.

View File

@ -0,0 +1,10 @@
<?xml version="1.0"?>
<grammar xmlns="http://www.w3.org/2001/06/grammar" xml:lang="en-US" version="1.0" mode="voice" root="digit">
<rule id="digit">
<one-of>
<item>one</item>
<item>two</item>
<item>three</item>
</one-of>
</rule>
</grammar>

BIN
libs/unimrcp/data/one.pcm Normal file

Binary file not shown.

View File

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<result>
<interpretation grammar="session:request1@form-level.store" confidence="97">
<instance>one</instance>
<input mode="speech">one</input>
</interpretation>
</result>

View File

@ -0,0 +1,6 @@
<?xml version="1.0"?>
<speak>
<paragraph>
<sentence>Hello World.</sentence>
</paragraph>
</speak>

View File

@ -0,0 +1,32 @@
PROJECT_NAME="UniMRCP"
INPUT=.
QUIET=YES
RECURSIVE=YES
FILE_PATTERNS=*.h
OUTPUT_DIRECTORY=docs/dox
MACRO_EXPANSION=YES
EXPAND_ONLY_PREDEF=YES
PREDEFINED="APT_DECLARE(x)=x" \
"MPF_DECLARE(x)=x" \
"MRCP_DECLARE(x)=x" \
"RTSP_DECLARE(x)=x"
OPTIMIZE_OUTPUT_FOR_C=YES
STRIP_CODE_COMMENTS=NO
FULL_PATH_NAMES=NO
CASE_SENSE_NAMES=NO
EXCLUDE_PATTERNS="*/acconfig.h" \
"*/test/*" \
"*/arch/*"
GENERATE_HTML=YES
GENERATE_LATEX=NO
GENERATE_RTF=NO
GENERATE_MAN=NO
GENERATE_XML=NO

View File

@ -0,0 +1,3 @@
MAINTAINERCLEANFILES = Makefile.in
SUBDIRS = apr-toolkit mpf mrcp mrcp-signaling mrcpv2-transport mrcp-engine mrcp-server mrcp-client uni-rtsp

View File

@ -0,0 +1,43 @@
MAINTAINERCLEANFILES = Makefile.in
INCLUDES = -I$(top_srcdir)/libs/apr-toolkit/include \
$(UNIMRCP_APR_INCLUDES) $(UNIMRCP_APU_INCLUDES)
noinst_LTLIBRARIES = libaprtoolkit.la
include_HEADERS = include/apt.h \
include/apt_obj_list.h \
include/apt_cyclic_queue.h \
include/apt_task.h \
include/apt_task_msg.h \
include/apt_consumer_task.h \
include/apt_net_server_task.h \
include/apt_net_client_task.h \
include/apt_pollset.h \
include/apt_pool.h \
include/apt_log.h \
include/apt_pair.h \
include/apt_string.h \
include/apt_string_table.h \
include/apt_text_stream.h \
include/apt_net.h \
include/apt_dir_layout.h \
include/apt_test_suite.h
libaprtoolkit_la_SOURCES = src/apt_obj_list.c \
src/apt_cyclic_queue.c \
src/apt_task.c \
src/apt_task_msg.c \
src/apt_consumer_task.c \
src/apt_net_server_task.c \
src/apt_net_client_task.c \
src/apt_pollset.c \
src/apt_pool.c \
src/apt_log.c \
src/apt_pair.c \
src/apt_string_table.c \
src/apt_text_stream.c \
src/apt_net.c \
src/apt_dir_layout.c \
src/apt_test_suite.c

View File

@ -0,0 +1,277 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="aprtoolkit"
ProjectGUID="{13DEECA0-BDD4-4744-A1A2-8EB0A44DF3D2}"
RootNamespace="aprtoolkit"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
ConfigurationType="4"
InheritedPropertySheets="$(SolutionDir)build\vsprops\unidebug.vsprops;$(SolutionDir)build\vsprops\apt.vsprops"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
ConfigurationType="4"
InheritedPropertySheets="$(SolutionDir)build\vsprops\unirelease.vsprops;$(SolutionDir)build\vsprops\apt.vsprops"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="include"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\include\apt.h"
>
</File>
<File
RelativePath=".\include\apt_consumer_task.h"
>
</File>
<File
RelativePath=".\include\apt_cyclic_queue.h"
>
</File>
<File
RelativePath=".\include\apt_dir_layout.h"
>
</File>
<File
RelativePath=".\include\apt_log.h"
>
</File>
<File
RelativePath=".\include\apt_net.h"
>
</File>
<File
RelativePath=".\include\apt_net_client_task.h"
>
</File>
<File
RelativePath=".\include\apt_net_server_task.h"
>
</File>
<File
RelativePath=".\include\apt_obj_list.h"
>
</File>
<File
RelativePath=".\include\apt_pair.h"
>
</File>
<File
RelativePath=".\include\apt_pollset.h"
>
</File>
<File
RelativePath=".\include\apt_pool.h"
>
</File>
<File
RelativePath=".\include\apt_string.h"
>
</File>
<File
RelativePath=".\include\apt_string_table.h"
>
</File>
<File
RelativePath=".\include\apt_task.h"
>
</File>
<File
RelativePath=".\include\apt_task_msg.h"
>
</File>
<File
RelativePath=".\include\apt_test_suite.h"
>
</File>
<File
RelativePath=".\include\apt_text_stream.h"
>
</File>
</Filter>
<Filter
Name="src"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
>
<File
RelativePath=".\src\apt_consumer_task.c"
>
</File>
<File
RelativePath=".\src\apt_cyclic_queue.c"
>
</File>
<File
RelativePath=".\src\apt_dir_layout.c"
>
</File>
<File
RelativePath=".\src\apt_log.c"
>
</File>
<File
RelativePath=".\src\apt_net.c"
>
</File>
<File
RelativePath=".\src\apt_net_client_task.c"
>
</File>
<File
RelativePath=".\src\apt_net_server_task.c"
>
</File>
<File
RelativePath=".\src\apt_obj_list.c"
>
</File>
<File
RelativePath=".\src\apt_pair.c"
>
</File>
<File
RelativePath=".\src\apt_pollset.c"
>
</File>
<File
RelativePath=".\src\apt_pool.c"
>
</File>
<File
RelativePath=".\src\apt_string_table.c"
>
</File>
<File
RelativePath=".\src\apt_task.c"
>
</File>
<File
RelativePath=".\src\apt_task_msg.c"
>
</File>
<File
RelativePath=".\src\apt_test_suite.c"
>
</File>
<File
RelativePath=".\src\apt_text_stream.c"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,59 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __APT_H__
#define __APT_H__
/**
* @file apt.h
* @brief APR Toolkit Definitions
*/
#include <apr.h>
#include <apr_pools.h>
#include <apr_strings.h>
#ifdef __cplusplus
/** Begin of extern "C" block */
#define APT_BEGIN_EXTERN_C extern "C" {
/** End of extern "C" block */
#define APT_END_EXTERN_C }
#else
/** Begin of extern "C" block */
#define APT_BEGIN_EXTERN_C
/** End of extern "C" block */
#define APT_END_EXTERN_C
#endif
/** Lib export/import defines (win32) */
#ifdef WIN32
#ifdef APT_STATIC_LIB
#define APT_DECLARE(type) type __stdcall
#else
#ifdef APT_LIB_EXPORT
#define APT_DECLARE(type) __declspec(dllexport) type __stdcall
#else
#define APT_DECLARE(type) __declspec(dllimport) type __stdcall
#endif
#endif
#else
#define APT_DECLARE(type) type
#endif
/** Boolean value */
typedef int apt_bool_t;
#endif /*__APT_H__*/

View File

@ -0,0 +1,63 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __APT_CONSUMER_TASK_H__
#define __APT_CONSUMER_TASK_H__
/**
* @file apt_consumer_task.h
* @brief Consumer Task Definition
*/
#include "apt_task.h"
APT_BEGIN_EXTERN_C
/** Opaque consumer task declaration */
typedef struct apt_consumer_task_t apt_consumer_task_t;
/**
* Create consumer task.
* @param obj the external object to associate with the task
* @param msg_pool the pool of task messages
* @param pool the pool to allocate memory from
*/
APT_DECLARE(apt_consumer_task_t*) apt_consumer_task_create(
void *obj,
apt_task_msg_pool_t *msg_pool,
apr_pool_t *pool);
/**
* Get task base.
* @param task the consumer task to get base for
*/
APT_DECLARE(apt_task_t*) apt_consumer_task_base_get(apt_consumer_task_t *task);
/**
* Get task vtable.
* @param task the consumer task to get vtable for
*/
APT_DECLARE(apt_task_vtable_t*) apt_consumer_task_vtable_get(apt_consumer_task_t *task);
/**
* Get consumer task object.
* @param task the consumer task to get object from
*/
APT_DECLARE(void*) apt_consumer_task_object_get(apt_consumer_task_t *task);
APT_END_EXTERN_C
#endif /*__APT_CONSUMER_TASK_H__*/

View File

@ -0,0 +1,76 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __APT_CYCLIC_QUEUE_H__
#define __APT_CYCLIC_QUEUE_H__
/**
* @file apt_cyclic_queue.h
* @brief Cyclic FIFO Queue of Opaque void* Objects
*/
#include "apt.h"
APT_BEGIN_EXTERN_C
#define CYCLIC_QUEUE_DEFAULT_SIZE 100
/** Opaque cyclic queue declaration */
typedef struct apt_cyclic_queue_t apt_cyclic_queue_t;
/**
* Create cyclic queue.
* @param size the initial size of the queue
* @return the created queue
*/
APT_DECLARE(apt_cyclic_queue_t*) apt_cyclic_queue_create(apr_size_t size);
/**
* Destroy cyclic queue.
* @param queue the queue to destroy
*/
APT_DECLARE(void) apt_cyclic_queue_destroy(apt_cyclic_queue_t *queue);
/**
* Push object to the queue.
* @param queue the queue to push object to
* @param obj the object to push
*/
APT_DECLARE(apt_bool_t) apt_cyclic_queue_push(apt_cyclic_queue_t *queue, void *obj);
/**
* Pop object from the queue.
* @param queue the queue to pop message from
*/
APT_DECLARE(void*) apt_cyclic_queue_pop(apt_cyclic_queue_t *queue);
/**
* Clear the queue (remove all the elements from the queue).
* @param queue the queue to clear
*/
APT_DECLARE(void) apt_cyclic_queue_clear(apt_cyclic_queue_t *queue);
/**
* Query whether the queue is empty.
* @param queue the queue to query
* @return TRUE if empty, otherwise FALSE
*/
APT_DECLARE(apt_bool_t) apt_cyclic_queue_is_empty(apt_cyclic_queue_t *queue);
APT_END_EXTERN_C
#endif /*__APT_CYCLIC_QUEUE_H__*/

View File

@ -0,0 +1,67 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __APT_DIR_LAYOUT_H__
#define __APT_DIR_LAYOUT_H__
/**
* @file apt_dir_layout.h
* @brief Directory Layout
*/
#include "apt.h"
APT_BEGIN_EXTERN_C
/** Directory layout declaration */
typedef struct apt_dir_layout_t apt_dir_layout_t;
/** Directory layout */
struct apt_dir_layout_t {
/** Path to config dir */
char *conf_dir_path;
/** Path to plugin dir */
char *plugin_dir_path;
/** Path to log dir */
char *log_dir_path;
/** Path to data dir */
char *data_dir_path;
};
/**
* Create (allocate) the structure of default directories layout.
*/
APT_DECLARE(apt_dir_layout_t*) apt_default_dir_layout_create(const char *root_dir_path, apr_pool_t *pool);
/**
* Create (allocate) the structure of custom directories layout.
*/
APT_DECLARE(apt_dir_layout_t*) apt_custom_dir_layout_create(
const char *conf_dir_path,
const char *plugin_dir_path,
const char *log_dir_path,
const char *data_dir_path,
apr_pool_t *pool);
/**
* Construct file path with the given file name relative to data dir.
*/
APT_DECLARE(char*) apt_datadir_filepath_get(const apt_dir_layout_t *dir_layout, const char *file_name, apr_pool_t *pool);
APT_END_EXTERN_C
#endif /*__APT_DIR_LAYOUT_H__*/

View File

@ -0,0 +1,170 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __APT_LOG_H__
#define __APT_LOG_H__
/**
* @file apt_log.h
* @brief Basic Logger
*/
#include <stdio.h>
#include <stdarg.h>
#include "apt.h"
APT_BEGIN_EXTERN_C
/** Default max size of the log file (8Mb) */
#define MAX_LOG_FILE_SIZE (8 * 1024 * 1024)
/** Default max number of rotated log files */
#define MAX_LOG_FILE_COUNT 10
/** File:line mark */
#define APT_LOG_MARK __FILE__,__LINE__
/** Format to log pointer values */
#define APT_PTR_FMT "0x%x"
/** Format to log string identifiers */
#define APT_SID_FMT "<%s>"
/** Format to log string identifiers and resources */
#define APT_SIDRES_FMT "<%s@%s>"
/** Format to log pointers and identifiers */
#define APT_PTRSID_FMT APT_PTR_FMT" "APT_SID_FMT
/** Format to log pointers, identifiers and resources */
#define APT_PTRSIDRES_FMT APT_PTR_FMT" "APT_SIDRES_FMT
/** Priority of log messages ordered from highest priority to lowest (rfc3164) */
typedef enum {
APT_PRIO_EMERGENCY, /**< system is unusable */
APT_PRIO_ALERT, /**< action must be taken immediately */
APT_PRIO_CRITICAL, /**< critical condition */
APT_PRIO_ERROR, /**< error condition */
APT_PRIO_WARNING, /**< warning condition */
APT_PRIO_NOTICE, /**< normal, but significant condition */
APT_PRIO_INFO, /**< informational message */
APT_PRIO_DEBUG, /**< debug-level message */
APT_PRIO_COUNT /**< number of priorities */
} apt_log_priority_e;
/** Header (format) of log messages */
typedef enum {
APT_LOG_HEADER_NONE = 0x00, /**< disable optional headers output */
APT_LOG_HEADER_DATE = 0x01, /**< enable date output */
APT_LOG_HEADER_TIME = 0x02, /**< enable time output */
APT_LOG_HEADER_PRIORITY = 0x04, /**< enable priority name output */
APT_LOG_HEADER_MARK = 0x08, /**< enable file:line mark output */
APT_LOG_HEADER_DEFAULT = APT_LOG_HEADER_DATE | APT_LOG_HEADER_TIME | APT_LOG_HEADER_PRIORITY
} apt_log_header_e;
/** Log output modes */
typedef enum {
APT_LOG_OUTPUT_NONE = 0x00, /**< disable logging */
APT_LOG_OUTPUT_CONSOLE = 0x01, /**< enable console output */
APT_LOG_OUTPUT_FILE = 0x02, /**< enable log file output */
} apt_log_output_e;
/** Opaque logger declaration */
typedef struct apt_logger_t apt_logger_t;
/** Prototype of extended log handler function */
typedef apt_bool_t (*apt_log_ext_handler_f)(const char *file, int line, const char *id,
apt_log_priority_e priority, const char *format, va_list arg_ptr);
/**
* Create the singleton instance of the logger.
* @param mode the log output mode
* @param priority the log priority level
* @param pool the memory pool to use
*/
APT_DECLARE(apt_bool_t) apt_log_instance_create(apt_log_output_e mode, apt_log_priority_e priority, apr_pool_t *pool);
/**
* Destroy the singleton instance of the logger.
*/
APT_DECLARE(apt_bool_t) apt_log_instance_destroy();
/**
* Get the singleton instance of the logger.
*/
APT_DECLARE(apt_logger_t*) apt_log_instance_get();
/**
* Set the singleton instance of the logger.
*/
APT_DECLARE(apt_bool_t) apt_log_instance_set(apt_logger_t *logger);
/**
* Open the log file.
* @param dir_path the path to the log directory
* @param file_name the name of the log file
* @param max_file_size the max size of the log file
* @param max_file_count the max number of files used in log rotation
* @param pool the memory pool to use
*/
APT_DECLARE(apt_bool_t) apt_log_file_open(
const char *dir_path,
const char *file_name,
apr_size_t max_file_size,
apr_size_t max_file_count,
apr_pool_t *pool);
/**
* Close the log file.
*/
APT_DECLARE(apt_bool_t) apt_log_file_close();
/**
* Set the logging output.
* @param mode the mode to set
*/
APT_DECLARE(apt_bool_t) apt_log_output_mode_set(apt_log_output_e mode);
/**
* Set the logging priority (log level).
* @param priority the priority to set
*/
APT_DECLARE(apt_bool_t) apt_log_priority_set(apt_log_priority_e priority);
/**
* Set the header (format) for log messages.
* @param header the header to set (used as bitmask)
*/
APT_DECLARE(apt_bool_t) apt_log_header_set(int header);
/**
* Set the extended external log handler.
* @param handler the handler to pass log events to
* @remark default logger is used to output the logs to stdout and/or log file,
* if external log handler isn't set
*/
APT_DECLARE(apt_bool_t) apt_log_ext_handler_set(apt_log_ext_handler_f handler);
/**
* Do logging.
* @param file the file name log entry is generated from
* @param line the line number log entry is generated from
* @param priority the priority of the entire log entry
* @param format the format of the entire log entry
*/
APT_DECLARE(apt_bool_t) apt_log(const char *file, int line, apt_log_priority_e priority, const char *format, ...);
APT_END_EXTERN_C
#endif /*__APT_LOG_H__*/

View File

@ -0,0 +1,38 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __APT_NET_H__
#define __APT_NET_H__
/**
* @file apt_net.h
* @brief Network Utilities
*/
#include "apt.h"
APT_BEGIN_EXTERN_C
/**
* Get the IP address (in numeric address string format) by hostname.
* @param addr the IP address
* @param pool the pool to allocate memory from
*/
apt_bool_t apt_ip_get(char **addr, apr_pool_t *pool);
APT_END_EXTERN_C
#endif /*__APT_NET_H__*/

View File

@ -0,0 +1,127 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __APT_NET_CLIENT_TASK_H__
#define __APT_NET_CLIENT_TASK_H__
/**
* @file apt_net_client_task.h
* @brief Network Client Task Base
*/
#include <apr_poll.h>
#include "apt_task.h"
APT_BEGIN_EXTERN_C
/** Opaque network client task declaration */
typedef struct apt_net_client_task_t apt_net_client_task_t;
/** Network client connection declaration */
typedef struct apt_net_client_connection_t apt_net_client_connection_t;
/** Virtual table of network client events */
typedef struct apt_net_client_vtable_t apt_net_client_vtable_t;
/** Network client connection */
struct apt_net_client_connection_t {
/** Memory pool */
apr_pool_t *pool;
/** External object */
void *obj;
/** Connected socket */
apr_socket_t *sock;
/** Socket poll descriptor */
apr_pollfd_t sock_pfd;
/** String identifier used for traces */
const char *id;
};
/** Virtual table of network client events */
struct apt_net_client_vtable_t {
/** Message receive handler */
apt_bool_t (*on_receive)(apt_net_client_task_t *task, apt_net_client_connection_t *connection);
};
/**
* Create network client task.
* @param max_connection_count the number of max connections
* @param obj the external object
* @param client_vtable the table of virtual methods of the net client task
* @param msg_pool the pool of task messages
* @param pool the pool to allocate memory from
*/
APT_DECLARE(apt_net_client_task_t*) apt_net_client_task_create(
apr_size_t max_connection_count,
void *obj,
const apt_net_client_vtable_t *client_vtable,
apt_task_msg_pool_t *msg_pool,
apr_pool_t *pool);
/**
* Destroy network client task.
* @param task the task to destroy
*/
APT_DECLARE(apt_bool_t) apt_net_client_task_destroy(apt_net_client_task_t *task);
/**
* Start network client task and wait for incoming requests.
* @param task the task to start
*/
APT_DECLARE(apt_bool_t) apt_net_client_task_start(apt_net_client_task_t *task);
/**
* Terminate connection task.
* @param task the task to terminate
*/
APT_DECLARE(apt_bool_t) apt_net_client_task_terminate(apt_net_client_task_t *task);
/**
* Get task base.
* @param task the network client task to get task base from
*/
APT_DECLARE(apt_task_t*) apt_net_client_task_base_get(apt_net_client_task_t *task);
/**
* Get task vtable.
* @param task the network client task to get vtable from
*/
APT_DECLARE(apt_task_vtable_t*) apt_net_client_task_vtable_get(apt_net_client_task_t *task);
/**
* Get external object.
* @param task the task to get object from
*/
APT_DECLARE(void*) apt_net_client_task_object_get(apt_net_client_task_t *task);
/**
* Create connection.
*/
APT_DECLARE(apt_net_client_connection_t*) apt_net_client_connect(apt_net_client_task_t *task, const char *ip, apr_port_t port);
/**
* Close connection.
*/
APT_DECLARE(apt_bool_t) apt_net_client_connection_close(apt_net_client_task_t *task, apt_net_client_connection_t *connection);
/**
* Close and destroy connection.
*/
APT_DECLARE(apt_bool_t) apt_net_client_disconnect(apt_net_client_task_t *task, apt_net_client_connection_t *connection);
APT_END_EXTERN_C
#endif /*__APT_NET_CLIENT_TASK_H__*/

View File

@ -0,0 +1,132 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __APT_NET_SERVER_TASK_H__
#define __APT_NET_SERVER_TASK_H__
/**
* @file apt_net_server_task.h
* @brief Network Server Task Base
*/
#include <apr_poll.h>
#include "apt_task.h"
APT_BEGIN_EXTERN_C
/** Opaque network server task declaration */
typedef struct apt_net_server_task_t apt_net_server_task_t;
/** Network server connection declaration */
typedef struct apt_net_server_connection_t apt_net_server_connection_t;
/** Virtual table of network server events */
typedef struct apt_net_server_vtable_t apt_net_server_vtable_t;
/** Network server connection */
struct apt_net_server_connection_t {
/** Memory pool */
apr_pool_t *pool;
/** External object */
void *obj;
/** Client IP address */
char *client_ip;
/** Accepted socket */
apr_socket_t *sock;
/** Socket poll descriptor */
apr_pollfd_t sock_pfd;
/** String identifier used for traces */
const char *id;
};
/** Virtual table of network server events */
struct apt_net_server_vtable_t {
/** Connect event handler */
apt_bool_t (*on_connect)(apt_net_server_task_t *task, apt_net_server_connection_t *connection);
/** Disconnect event handler */
apt_bool_t (*on_disconnect)(apt_net_server_task_t *task, apt_net_server_connection_t *connection);
/** Message receive handler */
apt_bool_t (*on_receive)(apt_net_server_task_t *task, apt_net_server_connection_t *connection);
};
/**
* Create network server task.
* @param listen_ip the listen IP address
* @param listen_port the listen port
* @param max_connection_count the number of max connections to accept
* @param obj the external object
* @param server_vtable the table of virtual methods of the net server task
* @param msg_pool the pool of task messages
* @param pool the pool to allocate memory from
*/
APT_DECLARE(apt_net_server_task_t*) apt_net_server_task_create(
const char *listen_ip,
apr_port_t listen_port,
apr_size_t max_connection_count,
void *obj,
const apt_net_server_vtable_t *server_vtable,
apt_task_msg_pool_t *msg_pool,
apr_pool_t *pool);
/**
* Destroy network server task.
* @param task the task to destroy
*/
APT_DECLARE(apt_bool_t) apt_net_server_task_destroy(apt_net_server_task_t *task);
/**
* Start network server task and wait for incoming requests.
* @param task the task to start
*/
APT_DECLARE(apt_bool_t) apt_net_server_task_start(apt_net_server_task_t *task);
/**
* Terminate connection task.
* @param task the task to terminate
*/
APT_DECLARE(apt_bool_t) apt_net_server_task_terminate(apt_net_server_task_t *task);
/**
* Get task base.
* @param task the network server task to get task base from
*/
APT_DECLARE(apt_task_t*) apt_net_server_task_base_get(apt_net_server_task_t *task);
/**
* Get task vtable.
* @param task the network server task to get vtable from
*/
APT_DECLARE(apt_task_vtable_t*) apt_net_server_task_vtable_get(apt_net_server_task_t *task);
/**
* Get external object.
* @param task the task to get object from
*/
APT_DECLARE(void*) apt_net_server_task_object_get(apt_net_server_task_t *task);
/**
* Close connection.
*/
APT_DECLARE(apt_bool_t) apt_net_server_connection_close(apt_net_server_task_t *task, apt_net_server_connection_t *connection);
/**
* Destroy connection.
*/
APT_DECLARE(void) apt_net_server_connection_destroy(apt_net_server_connection_t *connection);
APT_END_EXTERN_C
#endif /*__APT_NET_SERVER_TASK_H__*/

View File

@ -0,0 +1,137 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __APT_OBJ_LIST_H__
#define __APT_OBJ_LIST_H__
/**
* @file apt_obj_list.h
* @brief List of Opaque void* Objects
*/
#include "apt.h"
APT_BEGIN_EXTERN_C
/** Opaque list declaration */
typedef struct apt_obj_list_t apt_obj_list_t;
/** Opaque list element declaration */
typedef struct apt_list_elem_t apt_list_elem_t;
/**
* Create list.
* @param pool the pool to allocate list from
* @return the created list
*/
APT_DECLARE(apt_obj_list_t*) apt_list_create(apr_pool_t *pool);
/**
* Destroy list.
* @param list the list to destroy
*/
APT_DECLARE(void) apt_list_destroy(apt_obj_list_t *list);
/**
* Push object to the list as first in, first out.
* @param list the list to push object to
* @param obj the object to push
* @param pool the pool to allocate list element from
* @return the inserted element
*/
APT_DECLARE(apt_list_elem_t*) apt_list_push_back(apt_obj_list_t *list, void *obj, apr_pool_t *pool);
/**
* Pop object from the list as first in, first out.
* @param list the list to pop message from
* @return the popped object (if any)
*/
APT_DECLARE(void*) apt_list_pop_front(apt_obj_list_t *list);
/**
* Retrieve object of the first element in the list.
* @param list the list to retrieve from
*/
APT_DECLARE(void*) apt_list_head(apt_obj_list_t *list);
/**
* Retrieve object of the last element in the list.
* @param list the list to retrieve from
*/
APT_DECLARE(void*) apt_obj_list_tail(apt_obj_list_t *list);
/**
* Retrieve the first element of the list.
* @param list the list to retrieve from
*/
APT_DECLARE(apt_list_elem_t*) apt_list_first_elem_get(apt_obj_list_t *list);
/**
* Retrieve the last element of the list.
* @param list the list to retrieve from
*/
APT_DECLARE(apt_list_elem_t*) apt_list_last_elem_get(apt_obj_list_t *list);
/**
* Retrieve the next element of the list.
* @param list the list to retrieve from
* @param elem the element to retrieve next element from
*/
APT_DECLARE(apt_list_elem_t*) apt_list_next_elem_get(apt_obj_list_t *list, apt_list_elem_t *elem);
/**
* Retrieve the prev element of the list.
* @param list the list to retrieve from
* @param elem the element to retrieve prev element from
*/
APT_DECLARE(apt_list_elem_t*) apt_list_prev_elem_get(apt_obj_list_t *list, apt_list_elem_t *elem);
/**
* Insert element to the list.
* @param list the list to insert element to
* @param elem the element to insert before
* @param obj the object to insert
* @param pool the pool to allocate list element from
* @return the inserted element
*/
APT_DECLARE(apt_list_elem_t*) apt_list_elem_insert(apt_obj_list_t *list, apt_list_elem_t *elem, void *obj, apr_pool_t *pool);
/**
* Remove element from the list.
* @param list the list to remove element from
* @param elem the element to remove
* @return the next element (if any)
*/
APT_DECLARE(apt_list_elem_t*) apt_list_elem_remove(apt_obj_list_t *list, apt_list_elem_t *elem);
/**
* Query whether the list is empty.
* @param list the list to query
* @return TRUE if empty, otherwise FALSE
*/
APT_DECLARE(apt_bool_t) apt_list_is_empty(apt_obj_list_t *list);
/**
* Retrieve the object associated with element.
* @param elem the element to retrieve object from
*/
APT_DECLARE(void*) apt_list_elem_object_get(apt_list_elem_t *elem);
APT_END_EXTERN_C
#endif /*__APT_OBJ_LIST_H__*/

View File

@ -0,0 +1,73 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __APT_PAIR_H__
#define __APT_PAIR_H__
/**
* @file apt_pair.h
* @brief Generic Name-Value Pair
*/
#include "apr_tables.h"
#include "apt_string.h"
APT_BEGIN_EXTERN_C
/** Name-value declaration */
typedef struct apt_pair_t apt_pair_t;
/** Generic name-value pair definition ("name:value") */
struct apt_pair_t {
/** The name */
apt_str_t name;
/** The value */
apt_str_t value;
};
/** Dynamic array of name-value pairs */
typedef apr_array_header_t apt_pair_arr_t;
/** Initialize name-value pair */
static APR_INLINE void apt_pair_init(apt_pair_t *pair)
{
apt_string_reset(&pair->name);
apt_string_reset(&pair->value);
}
/** Copy name-value pair */
static APR_INLINE void apt_pair_copy(apt_pair_t *pair, const apt_pair_t *src_pair, apr_pool_t *pool)
{
apt_string_copy(&pair->name,&src_pair->name,pool);
apt_string_copy(&pair->value,&src_pair->value,pool);
}
/** Create array of name-value pairs */
APT_DECLARE(apt_pair_arr_t*) apt_pair_array_create(apr_size_t initial_size, apr_pool_t *pool);
/** Copy array of name-value pairs */
APT_DECLARE(apt_pair_arr_t*) apt_pair_array_copy(const apt_pair_arr_t *src, apr_pool_t *pool);
/** Append name-value pair */
APT_DECLARE(apt_bool_t) apt_pair_array_append(apt_pair_arr_t *arr, const apt_str_t *name, const apt_str_t *value, apr_pool_t *pool);
/** Find name-value pair by name */
APT_DECLARE(const apt_pair_t*) apt_pair_array_find(const apt_pair_arr_t *arr, const apt_str_t *name);
/** Get size of pair array */
APT_DECLARE(int) apt_pair_array_size_get(const apt_pair_arr_t *arr);
/** Get name-value pair by id */
APT_DECLARE(const apt_pair_t*) apt_pair_array_get(const apt_pair_arr_t *arr, int id);
APT_END_EXTERN_C
#endif /*__APT_PAIR_H__*/

View File

@ -0,0 +1,96 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __APT_POLLSET_H__
#define __APT_POLLSET_H__
/**
* @file apt_pollset.h
* @brief Interruptable APR-Pollset
*/
/**
* Wakeup builtin API of the pollset is introduced only in APR-1.4
* and it is not available for APR-1.2 and APR-1.3 versions. Thus
* apt_pollset_t is an extension of apr_pollset_t and provides
* pollset wakeup capabilities the similar way as it's implemented
* in APR-1.4 trunk
*/
#include <apr_poll.h>
#include "apt.h"
APT_BEGIN_EXTERN_C
/** Opaque pollset declaration */
typedef struct apt_pollset_t apt_pollset_t;
/**
* Create interruptable pollset on top of APR pollset
* @param size the maximum number of descriptors pollset can hold
* @param pool the pool to allocate memory from
*/
APT_DECLARE(apt_pollset_t*) apt_pollset_create(apr_uint32_t size, apr_pool_t *pool);
/**
* Destroy pollset.
* @param pollset the pollset to destroy
*/
APT_DECLARE(apt_bool_t) apt_pollset_destroy(apt_pollset_t *pollset);
/**
* Add pollset descriptor to a pollset.
* @param pollset the pollset to add the descriptor to
* @param descriptor the descriptor to add
*/
APT_DECLARE(apt_bool_t) apt_pollset_add(apt_pollset_t *pollset, const apr_pollfd_t *descriptor);
/**
* Remove pollset descriptor from a pollset.
* @param pollset the pollset to remove the descriptor from
* @param descriptor the descriptor to remove
*/
APT_DECLARE(apt_bool_t) apt_pollset_remove(apt_pollset_t *pollset, const apr_pollfd_t *descriptor);
/**
* Block for activity on the descriptor(s) in a pollset.
* @param pollset the pollset to use
* @param timeout the timeout in microseconds
* @param num nthe umber of signalled descriptors (output parameter)
* @param descriptors the array of signalled descriptors (output parameter)
*/
APT_DECLARE(apr_status_t) apt_pollset_poll(
apt_pollset_t *pollset,
apr_interval_time_t timeout,
apr_int32_t *num,
const apr_pollfd_t **descriptors);
/**
* Interrupt the blocked poll call.
* @param pollset the pollset to use
*/
APT_DECLARE(apt_bool_t) apt_pollset_wakeup(apt_pollset_t *pollset);
/**
* Match against builtin wake up descriptor in a pollset.
* @param pollset the pollset to use
* @param descriptor the descriptor to match
*/
APT_DECLARE(apt_bool_t) apt_pollset_is_wakeup(apt_pollset_t *pollset, const apr_pollfd_t *descriptor);
APT_END_EXTERN_C
#endif /*__APT_POLLSET_H__*/

View File

@ -0,0 +1,47 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __APT_POOL_H__
#define __APT_POOL_H__
/**
* @file apt_pool.h
* @brief APR pool management
*/
/**
* Wrappers around APR pool creation
* allow to control memory allocation policy project uses
*/
#include "apt.h"
APT_BEGIN_EXTERN_C
/**
* Create APR pool
*/
APT_DECLARE(apr_pool_t*) apt_pool_create();
/**
* Create APR subpool pool
* @param parent the parent pool
*/
APT_DECLARE(apr_pool_t*) apt_subpool_create(apr_pool_t *parent);
APT_END_EXTERN_C
#endif /*__APT_POOL_H__*/

View File

@ -0,0 +1,119 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __APT_STRING_H__
#define __APT_STRING_H__
/**
* @file apt_string.h
* @brief String Representation
*/
#include "apt.h"
APT_BEGIN_EXTERN_C
/** String declaration */
typedef struct apt_str_t apt_str_t;
/** String representation */
struct apt_str_t {
/** String buffer (might be not NULL terminated) */
char *buf;
/** Length of the string (not counting terminating NULL character if exists) */
apr_size_t length;
};
/** Reset string. */
static APR_INLINE void apt_string_reset(apt_str_t *str)
{
str->buf = NULL;
str->length = 0;
}
/**
* Set NULL terminated string.
* @param str the destination string
* @param src the NULL terminated string to set
*/
static APR_INLINE void apt_string_set(apt_str_t *str, const char *src)
{
str->buf = (char*)src;
str->length = src ? strlen(src) : 0;
}
/**
* Assign (copy) NULL terminated string.
* @param str the destination string
* @param src the NULL terminated string to copy
* @param pool the pool to allocate memory from
*/
static APR_INLINE void apt_string_assign(apt_str_t *str, const char *src, apr_pool_t *pool)
{
str->buf = NULL;
str->length = src ? strlen(src) : 0;
if(str->length) {
str->buf = apr_pstrmemdup(pool,src,str->length);
}
}
/**
* Assign (copy) n characters from the src string.
* @param str the destination string
* @param src the NULL terminated string to copy
* @param pool the pool to allocate memory from
*/
static APR_INLINE void apt_string_assign_n(apt_str_t *str, const char *src, apr_size_t length, apr_pool_t *pool)
{
str->buf = NULL;
str->length = length;
if(str->length) {
str->buf = apr_pstrmemdup(pool,src,str->length);
}
}
/**
* Copy string.
* @param dest_str the destination string
* @param src_str the source string
* @param pool the pool to allocate memory from
*/
static APR_INLINE void apt_string_copy(apt_str_t *str, const apt_str_t *src_str, apr_pool_t *pool)
{
str->buf = NULL;
str->length = src_str->length;
if(str->length) {
str->buf = apr_pstrmemdup(pool,src_str->buf,src_str->length);
}
}
/**
* Compare two strings (case insensitive).
* @param str1 the string to compare
* @param str2 the string to compare
* @return TRUE if equal, FALSE otherwise
*/
static APR_INLINE apt_bool_t apt_string_compare(const apt_str_t *str1, const apt_str_t *str2)
{
if(str1->length != str2->length || !str1->length) {
return FALSE;
}
return (strncasecmp(str1->buf,str2->buf,str1->length) == 0) ? TRUE : FALSE;
}
APT_END_EXTERN_C
#endif /*__APT_STRING_H__*/

View File

@ -0,0 +1,63 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __APT_STRING_TABLE_H__
#define __APT_STRING_TABLE_H__
/**
* @file apt_string_table.h
* @brief Generic String Table
*/
#include "apt_string.h"
APT_BEGIN_EXTERN_C
/** String table item declaration */
typedef struct apt_str_table_item_t apt_str_table_item_t;
/** String table item definition */
struct apt_str_table_item_t {
/** String value associated with id */
apt_str_t value;
/** Index of the unique (key) character to compare */
apr_size_t key;
};
/**
* Get the string by a given id.
* @param table the table to get string from
* @param size the size of the table
* @param id the id to get string by
* @return the string associated with the id, or NULL if the id is invalid
*/
APT_DECLARE(const apt_str_t*) apt_string_table_str_get(const apt_str_table_item_t table[], apr_size_t size, apr_size_t id);
/**
* Find the id associated with a given string.
* @param table the table to search for the id
* @param size the size of the table
* @param value the string to search for
* @return the id associated with the string, or invalid id if string cannot be matched
*/
APT_DECLARE(apr_size_t) apt_string_table_id_find(const apt_str_table_item_t table[], apr_size_t size, const apt_str_t *value);
APT_END_EXTERN_C
#endif /*__APT_STRING_TABLE_H__*/

View File

@ -0,0 +1,209 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __APT_TASK_H__
#define __APT_TASK_H__
/**
* @file apt_task.h
* @brief Thread Execution Abstraction
*/
#include "apt.h"
#include "apt_task_msg.h"
APT_BEGIN_EXTERN_C
/** Opaque task declaration */
typedef struct apt_task_t apt_task_t;
/** Opaque task virtual table declaration */
typedef struct apt_task_vtable_t apt_task_vtable_t;
/** Opaque task method declaration */
typedef apt_bool_t (*apt_task_method_f)(apt_task_t *task);
/** Opaque task event declaration */
typedef void (*apt_task_event_f)(apt_task_t *task);
/**
* Create task.
* @param obj the external object to associate with the task
* @param msg_pool the pool of task messages
* @param pool the pool to allocate memory from
*/
APT_DECLARE(apt_task_t*) apt_task_create(
void *obj,
apt_task_msg_pool_t *msg_pool,
apr_pool_t *pool);
/**
* Destroy task.
* @param task the task to destroy
*/
APT_DECLARE(apt_bool_t) apt_task_destroy(apt_task_t *task);
/**
* Add slave task.
* @param task the task to add slave task to
* @param child_task the child task to add
*/
APT_DECLARE(apt_bool_t) apt_task_add(apt_task_t *task, apt_task_t *child_task);
/**
* Start task.
* @param task the task to start
*/
APT_DECLARE(apt_bool_t) apt_task_start(apt_task_t *task);
/**
* Terminate task.
* @param task the task to terminate
* @param wait_till_complete whether to wait for task to complete or
* process termination asynchronously
*/
APT_DECLARE(apt_bool_t) apt_task_terminate(apt_task_t *task, apt_bool_t wait_till_complete);
/**
* Start child tasks.
* @param task the parent task
*/
APT_DECLARE(apt_bool_t) apt_task_child_start(apt_task_t *task);
/**
* Terminate child tasks.
* @param task the parent task
*/
APT_DECLARE(apt_bool_t) apt_task_child_terminate(apt_task_t *task);
/**
* Wait for task till complete.
* @param task the task to wait for
*/
APT_DECLARE(apt_bool_t) apt_task_wait_till_complete(apt_task_t *task);
/**
* Get (acquire) task message.
* @param task the task to get task message from
*/
APT_DECLARE(apt_task_msg_t*) apt_task_msg_get(apt_task_t *task);
/**
* Signal (post) message to the task.
* @param task the task to signal message to
* @param msg the message to signal
*/
APT_DECLARE(apt_bool_t) apt_task_msg_signal(apt_task_t *task, apt_task_msg_t *msg);
/**
* Signal (post) message to the parent of the specified task.
* @param task the task to signal message to
* @param msg the message to signal
*/
APT_DECLARE(apt_bool_t) apt_task_msg_parent_signal(apt_task_t *task, apt_task_msg_t *msg);
/**
* Process message signaled to the task.
* @param task the task to process message
* @param msg the message to process
*/
APT_DECLARE(apt_bool_t) apt_task_msg_process(apt_task_t *task, apt_task_msg_t *msg);
/**
* Get parent (master) task.
* @param task the task to get parent from
*/
APT_DECLARE(apt_task_t*) apt_task_parent_get(apt_task_t *task);
/**
* Get memory pool associated with task.
* @param task the task to get pool from
*/
APT_DECLARE(apr_pool_t*) apt_task_pool_get(apt_task_t *task);
/**
* Get external object associated with the task.
* @param task the task to get object from
*/
APT_DECLARE(void*) apt_task_object_get(apt_task_t *task);
/**
* Get task vtable.
* @param task the task to get vtable from
*/
APT_DECLARE(apt_task_vtable_t*) apt_task_vtable_get(apt_task_t *task);
/**
* Give a name to the task.
* @param task the task to give name for
* @param name the name to set
*/
APT_DECLARE(void) apt_task_name_set(apt_task_t *task, const char *name);
/**
* Get task name.
* @param task the task to get name from
*/
APT_DECLARE(const char*) apt_task_name_get(apt_task_t *task);
/**
* Hold task execution.
* @param msec the time to hold
*/
APT_DECLARE(void) apt_task_delay(apr_size_t msec);
/** Table of task virtual methods */
struct apt_task_vtable_t {
/** Virtual destroy method */
apt_task_method_f destroy;
/** Virtual start method*/
apt_task_method_f start;
/** Virtual terminate method */
apt_task_method_f terminate;
/** Virtual run method*/
apt_task_method_f run;
/** Virtual signal method */
apt_bool_t (*signal_msg)(apt_task_t *task, apt_task_msg_t *msg);
/** Virtual process method */
apt_bool_t (*process_msg)(apt_task_t *task, apt_task_msg_t *msg);
/** Virtual pre-run event handler */
apt_task_event_f on_pre_run;
/** Virtual post-run event handler */
apt_task_event_f on_post_run;
/** Virtual start-complete event handler */
apt_task_event_f on_start_complete;
/** Virtual terminate-complete event handler */
apt_task_event_f on_terminate_complete;
};
static APR_INLINE void apt_task_vtable_reset(apt_task_vtable_t *vtable)
{
vtable->destroy = NULL;
vtable->start = NULL;
vtable->terminate = NULL;
vtable->run = NULL;
vtable->signal_msg = NULL;
vtable->process_msg = NULL;
vtable->on_pre_run = NULL;
vtable->on_post_run = NULL;
vtable->on_start_complete = NULL;
vtable->on_terminate_complete = NULL;
}
APT_END_EXTERN_C
#endif /*__APT_TASK_H__*/

View File

@ -0,0 +1,80 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __APT_TASK_MSG_H__
#define __APT_TASK_MSG_H__
/**
* @file apt_task_msg.h
* @brief Task Message Base Definition
*/
#include "apt.h"
APT_BEGIN_EXTERN_C
/** Enumeration of task message types */
typedef enum {
TASK_MSG_CORE, /**< core task message type */
TASK_MSG_USER /**< user defined task messages start from here */
} apt_task_msg_type_e;
/** Enumeration of core task messages */
typedef enum {
CORE_TASK_MSG_NONE, /**< indefinite message */
CORE_TASK_MSG_START_COMPLETE, /**< start-complete message */
CORE_TASK_MSG_TERMINATE_REQUEST, /**< terminate-request message */
CORE_TASK_MSG_TERMINATE_COMPLETE /**< terminate-complete message */
} apt_core_task_msg_type_e;
/** Opaque task message declaration */
typedef struct apt_task_msg_t apt_task_msg_t;
/** Opaque task message pool declaration */
typedef struct apt_task_msg_pool_t apt_task_msg_pool_t;
/** Task message is used for inter task communication */
struct apt_task_msg_t {
/** Message pool the task message is allocated from */
apt_task_msg_pool_t *msg_pool;
/** Task msg type */
apt_task_msg_type_e type;
/** Task msg sub type */
int sub_type;
/** Context specific data */
char data[1];
};
/** Create pool of task messages with dynamic allocation of messages (no actual pool is created) */
APT_DECLARE(apt_task_msg_pool_t*) apt_task_msg_pool_create_dynamic(apr_size_t msg_size, apr_pool_t *pool);
/** Create pool of task messages with static allocation of messages */
APT_DECLARE(apt_task_msg_pool_t*) apt_task_msg_pool_create_static(apr_size_t msg_size, apr_size_t msg_pool_size, apr_pool_t *pool);
/** Destroy pool of task messages */
APT_DECLARE(void) apt_task_msg_pool_destroy(apt_task_msg_pool_t *msg_pool);
/** Acquire task message from task message pool */
APT_DECLARE(apt_task_msg_t*) apt_task_msg_acquire(apt_task_msg_pool_t *task_msg_pool);
/** Realese task message */
APT_DECLARE(void) apt_task_msg_release(apt_task_msg_t *task_msg);
APT_END_EXTERN_C
#endif /*__APT_TASK_MSG_H__*/

View File

@ -0,0 +1,99 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __APT_TEST_SUITE_H__
#define __APT_TEST_SUITE_H__
/**
* @file apt_test_suite.h
* @brief Test Suite and Framework Definitions
*/
#include "apt_string.h"
APT_BEGIN_EXTERN_C
/** Opaque test suite declaration */
typedef struct apt_test_suite_t apt_test_suite_t;
/** Prototype of test function */
typedef apt_bool_t (*apt_test_f)(apt_test_suite_t *suite, int argc, const char * const *argv);
/** Test suite as a base for all kind of tests */
struct apt_test_suite_t {
/** Memory pool to allocate memory from */
apr_pool_t *pool;
/** Unique name of the test suite */
apt_str_t name;
/** External object associated with the test suite */
void *obj;
/** Test function to execute */
apt_test_f tester;
};
/**
* Create test suite.
* @param pool the pool to allocate memory from
* @param name the unique name of the test suite
* @param obj the external object associated with the test suite
* @param tester the test function to execute
*/
APT_DECLARE(apt_test_suite_t*) apt_test_suite_create(apr_pool_t *pool, const char *name,
void *obj, apt_test_f tester);
/** Opaque test framework declaration */
typedef struct apt_test_framework_t apt_test_framework_t;
/**
* Create test framework.
*/
APT_DECLARE(apt_test_framework_t*) apt_test_framework_create();
/**
* Destroy test framework.
* @param framework the test framework to destroy
*/
APT_DECLARE(void) apt_test_framework_destroy(apt_test_framework_t *framework);
/**
* Add test suite to framework.
* @param framework the test framework to add test suite to
* @param suite the test suite to add
*/
APT_DECLARE(apt_bool_t) apt_test_framework_suite_add(apt_test_framework_t *framework, apt_test_suite_t *suite);
/**
* Run test suites.
* @param framework the test framework
* @param argc the number of arguments
* @param argv the array of arguments
*/
APT_DECLARE(apt_bool_t) apt_test_framework_run(apt_test_framework_t *framework, int argc, const char * const *argv);
/**
* Retrieve the memory pool.
* @param framework the test framework to retrieve memory pool from
*/
APT_DECLARE(apr_pool_t*) apt_test_framework_pool_get(apt_test_framework_t *framework);
APT_END_EXTERN_C
#endif /*__APT_TEST_SUITE_H__*/

View File

@ -0,0 +1,215 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __APT_TEXT_STREAM_H__
#define __APT_TEXT_STREAM_H__
/**
* @file apt_text_stream.h
* @brief Text Stream Parse/Generate Routine
*/
#include <stdlib.h>
#include <stdio.h>
#include "apt_string.h"
#include "apt_pair.h"
APT_BEGIN_EXTERN_C
/** Named tokens */
/** Space */
#define APT_TOKEN_SP ' '
/** Carrige return */
#define APT_TOKEN_CR 0x0D
/** Line feed */
#define APT_TOKEN_LF 0x0A
/** Text stream declaration */
typedef struct apt_text_stream_t apt_text_stream_t;
/** Text stream is used for message parsing and generation */
struct apt_text_stream_t {
/** Text stream */
apt_str_t text;
/** Current position in the buffer */
char *pos;
};
/**
* Navigate through the lines of the text stream (message).
* @param stream the text stream to navigate
* @param line the read line to return
* @return TRUE if the length of the line > 0, otherwise FALSE
*/
APT_DECLARE(apt_bool_t) apt_text_line_read(apt_text_stream_t *stream, apt_str_t *line);
/**
* Navigate through the headers (name:value pairs) of the text stream (message).
* @param stream the text stream to navigate
* @param pair the read pair to return
* @return TRUE if the length of the read name > 0, otherwise FALSE
*/
APT_DECLARE(apt_bool_t) apt_text_header_read(apt_text_stream_t *stream, apt_pair_t *pair);
/**
* Navigate through the fields of the line.
* @param stream the text stream to navigate
* @param separator the field separator
* @param skip_spaces whether to skip spaces or not
* @param field the read field to return
* @return TRUE if the length of the field > 0, otherwise FALSE
*/
APT_DECLARE(apt_bool_t) apt_text_field_read(apt_text_stream_t *stream, char separator, apt_bool_t skip_spaces, apt_str_t *field);
/** Generate header */
APT_DECLARE(apt_bool_t) apt_text_header_generate(const apt_pair_t *pair, apt_text_stream_t *text_stream);
/** Generate only the name ("name:") of the header */
APT_DECLARE(apt_bool_t) apt_text_header_name_generate(const apt_str_t *name, apt_text_stream_t *text_stream);
/** Parse array of name-value pairs */
APT_DECLARE(apt_bool_t) apt_pair_array_parse(apt_pair_arr_t *arr, const apt_str_t *value, apr_pool_t *pool);
/** Generate array of name-value pairs */
APT_DECLARE(apt_bool_t) apt_pair_array_generate(apt_pair_arr_t *arr, apt_text_stream_t *text_stream);
/** Parse boolean-value */
APT_DECLARE(apt_bool_t) apt_boolean_value_parse(const apt_str_t *str, apt_bool_t *value);
/** Generate boolean-value */
APT_DECLARE(apt_bool_t) apt_boolean_value_generate(apt_bool_t value, apt_text_stream_t *str);
/** Parse size_t value */
static APR_INLINE apr_size_t apt_size_value_parse(const apt_str_t *str)
{
return str->buf ? atol(str->buf) : 0;
}
/** Generate apr_size_t value */
static APR_INLINE apt_bool_t apt_size_value_generate(apr_size_t value, apt_text_stream_t *stream)
{
int length = sprintf(stream->pos, "%"APR_SIZE_T_FMT, value);
if(length <= 0) {
return FALSE;
}
stream->pos += length;
return TRUE;
}
/** Parse float value */
static APR_INLINE float apt_float_value_parse(const apt_str_t *str)
{
return str->buf ? (float)atof(str->buf) : 0;
}
/** Generate float value */
static APR_INLINE apt_bool_t apt_float_value_generate(float value, apt_text_stream_t *stream)
{
int length = sprintf(stream->pos,"%.1f",value);
if(length <= 0) {
return FALSE;
}
stream->pos += length;
return TRUE;
}
/** Generate string value */
static APR_INLINE apt_bool_t apt_string_value_generate(const apt_str_t *str, apt_text_stream_t *stream)
{
if(str->length) {
memcpy(stream->pos,str->buf,str->length);
stream->pos += str->length;
}
return TRUE;
}
/** Initialize text stream */
static APR_INLINE void apt_text_stream_init(apt_text_stream_t *stream, char *buffer, apr_size_t size)
{
stream->text.buf = buffer;
stream->text.length = size;
stream->pos = stream->text.buf;
}
/** Insert end of the line symbol(s) */
static APR_INLINE void apt_text_eol_insert(apt_text_stream_t *stream)
{
*stream->pos++ = APT_TOKEN_CR;
*stream->pos++ = APT_TOKEN_LF;
}
/** Insert character */
static APR_INLINE void apt_text_char_insert(apt_text_stream_t *stream, char ch)
{
*stream->pos++ = ch;
}
/** Insert space */
static APR_INLINE void apt_text_space_insert(apt_text_stream_t *stream)
{
*stream->pos++ = APT_TOKEN_SP;
}
/** Skip spaces */
static APR_INLINE void apt_text_spaces_skip(apt_text_stream_t *stream)
{
const char *end = stream->text.buf + stream->text.length;
while(stream->pos < end && *stream->pos == APT_TOKEN_SP) stream->pos++;
}
/** Skip specified character */
static APR_INLINE void apt_text_char_skip(apt_text_stream_t *stream, char ch)
{
const char *end = stream->text.buf + stream->text.length;
if(stream->pos < end && *stream->pos == ch) stream->pos++;
}
/** Check whether end of stream is reached */
static APR_INLINE apt_bool_t apt_text_is_eos(const apt_text_stream_t *stream)
{
const char *end = stream->text.buf + stream->text.length;
return (stream->pos >= end) ? TRUE : FALSE;
}
/** Scroll text stream */
APT_DECLARE(apt_bool_t) apt_text_stream_scroll(apt_text_stream_t *stream);
/** Parse id at resource string */
APT_DECLARE(apt_bool_t) apt_id_resource_parse(const apt_str_t *str, char separator, apt_str_t *id, apt_str_t *resource, apr_pool_t *pool);
/** Generate id at resource string */
APT_DECLARE(apt_bool_t) apt_id_resource_generate(const apt_str_t *id, const apt_str_t *resource, char separator, apt_str_t *str, apr_pool_t *pool);
/** Generate value plus the length (number of digits) of the value itself */
APT_DECLARE(apt_bool_t) apt_var_length_value_generate(apr_size_t *value, apr_size_t max_count, apt_str_t *str);
/**
* Generate unique identifier (hex string)
* @param id the id to generate
* @param length the length of hex string to generate
* @param pool the pool to allocate memory from
*/
APT_DECLARE(apt_bool_t) apt_unique_id_generate(apt_str_t *id, apr_size_t length, apr_pool_t *pool);
APT_END_EXTERN_C
#endif /*__APT_TEXT_STREAM_H__*/

View File

@ -0,0 +1,99 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <apr_queue.h>
#include "apt_consumer_task.h"
struct apt_consumer_task_t {
void *obj;
apt_task_t *base;
apr_queue_t *msg_queue;
};
static apt_bool_t apt_consumer_task_msg_signal(apt_task_t *task, apt_task_msg_t *msg);
static apt_bool_t apt_consumer_task_run(apt_task_t *task);
APT_DECLARE(apt_consumer_task_t*) apt_consumer_task_create(
void *obj,
apt_task_msg_pool_t *msg_pool,
apr_pool_t *pool)
{
apt_task_vtable_t *vtable;
apt_consumer_task_t *consumer_task = apr_palloc(pool,sizeof(apt_consumer_task_t));
consumer_task->obj = obj;
consumer_task->msg_queue = NULL;
if(apr_queue_create(&consumer_task->msg_queue,1024,pool) != APR_SUCCESS) {
return NULL;
}
consumer_task->base = apt_task_create(consumer_task,msg_pool,pool);
if(!consumer_task->base) {
return NULL;
}
vtable = apt_task_vtable_get(consumer_task->base);
if(vtable) {
vtable->run = apt_consumer_task_run;
vtable->signal_msg = apt_consumer_task_msg_signal;
}
return consumer_task;
}
APT_DECLARE(apt_task_t*) apt_consumer_task_base_get(apt_consumer_task_t *task)
{
return task->base;
}
APT_DECLARE(apt_task_vtable_t*) apt_consumer_task_vtable_get(apt_consumer_task_t *task)
{
return apt_task_vtable_get(task->base);
}
APT_DECLARE(void*) apt_consumer_task_object_get(apt_consumer_task_t *task)
{
return task->obj;
}
static apt_bool_t apt_consumer_task_msg_signal(apt_task_t *task, apt_task_msg_t *msg)
{
apt_consumer_task_t *consumer_task = apt_task_object_get(task);
return (apr_queue_push(consumer_task->msg_queue,msg) == APR_SUCCESS) ? TRUE : FALSE;
}
static apt_bool_t apt_consumer_task_run(apt_task_t *task)
{
apr_status_t rv;
void *msg;
apt_bool_t running = TRUE;
apt_consumer_task_t *consumer_task;
consumer_task = apt_task_object_get(task);
if(!consumer_task) {
return FALSE;
}
while(running) {
rv = apr_queue_pop(consumer_task->msg_queue,&msg);
if(rv == APR_SUCCESS) {
if(msg) {
apt_task_msg_t *task_msg = msg;
if(apt_task_msg_process(consumer_task->base,task_msg) == FALSE) {
running = FALSE;
}
}
}
}
return TRUE;
}

View File

@ -0,0 +1,104 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdlib.h>
#include "apt_cyclic_queue.h"
struct apt_cyclic_queue_t {
void **data;
apr_size_t max_size;
apr_size_t actual_size;
apr_size_t head;
apr_size_t tail;
};
static apt_bool_t apt_cyclic_queue_resize(apt_cyclic_queue_t *queue);
APT_DECLARE(apt_cyclic_queue_t*) apt_cyclic_queue_create(apr_size_t size)
{
apt_cyclic_queue_t *queue = malloc(sizeof(apt_cyclic_queue_t));
queue->max_size = size;
queue->actual_size = 0;
queue->data = malloc(sizeof(void*) * queue->max_size);
queue->head = queue->tail = 0;
return queue;
}
APT_DECLARE(void) apt_cyclic_queue_destroy(apt_cyclic_queue_t *queue)
{
if(queue->data) {
free(queue->data);
queue->data = NULL;
}
free(queue);
}
APT_DECLARE(apt_bool_t) apt_cyclic_queue_push(apt_cyclic_queue_t *queue, void *obj)
{
if(queue->actual_size >= queue->max_size) {
if(apt_cyclic_queue_resize(queue) != TRUE) {
return FALSE;
}
}
queue->data[queue->head] = obj;
queue->head = (queue->head + 1) % queue->max_size;
queue->actual_size++;
return TRUE;
}
APT_DECLARE(void*) apt_cyclic_queue_pop(apt_cyclic_queue_t *queue)
{
void *obj = NULL;
if(queue->actual_size) {
obj = queue->data[queue->tail];
queue->tail = (queue->tail + 1) % queue->max_size;
queue->actual_size--;
}
return obj;
}
APT_DECLARE(void) apt_cyclic_queue_clear(apt_cyclic_queue_t *queue)
{
queue->actual_size = 0;
queue->head = queue->tail = 0;
}
APT_DECLARE(apt_bool_t) apt_cyclic_queue_is_empty(apt_cyclic_queue_t *queue)
{
return queue->actual_size ? TRUE : FALSE;
}
static apt_bool_t apt_cyclic_queue_resize(apt_cyclic_queue_t *queue)
{
apr_size_t new_size = queue->max_size + queue->max_size/2;
void **new_data = malloc(sizeof(void*) * new_size);
apr_size_t offset;
offset = queue->max_size - queue->head;
memcpy(new_data, queue->data + queue->head, sizeof(void*) * offset);
if(queue->head) {
memcpy(new_data + offset, queue->data, sizeof(void*) * queue->head);
}
queue->tail = 0;
queue->head = queue->max_size;
queue->max_size = new_size;
free(queue->data);
queue->data = new_data;
return TRUE;
}

View File

@ -0,0 +1,74 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <apr_file_info.h>
#include "apt_dir_layout.h"
static apt_dir_layout_t* apt_dir_layout_alloc(apr_pool_t *pool)
{
apt_dir_layout_t *dir_layout = (apt_dir_layout_t*) apr_palloc(pool,sizeof(apt_dir_layout_t));
dir_layout->conf_dir_path = NULL;
dir_layout->plugin_dir_path = NULL;
dir_layout->log_dir_path = NULL;
dir_layout->data_dir_path = NULL;
return dir_layout;
}
APT_DECLARE(apt_dir_layout_t*) apt_default_dir_layout_create(const char *root_dir_path, apr_pool_t *pool)
{
apt_dir_layout_t *dir_layout = apt_dir_layout_alloc(pool);
if(root_dir_path) {
apr_filepath_merge(&dir_layout->conf_dir_path,root_dir_path,"conf",0,pool);
apr_filepath_merge(&dir_layout->plugin_dir_path,root_dir_path,"plugin",0,pool);
apr_filepath_merge(&dir_layout->log_dir_path,root_dir_path,"log",0,pool);
apr_filepath_merge(&dir_layout->data_dir_path,root_dir_path,"data",0,pool);
}
return dir_layout;
}
APT_DECLARE(apt_dir_layout_t*) apt_custom_dir_layout_create(
const char *conf_dir_path,
const char *plugin_dir_path,
const char *log_dir_path,
const char *data_dir_path,
apr_pool_t *pool)
{
apt_dir_layout_t *dir_layout = apt_dir_layout_alloc(pool);
if(conf_dir_path) {
dir_layout->conf_dir_path = apr_pstrdup(pool,conf_dir_path);
}
if(plugin_dir_path) {
dir_layout->plugin_dir_path = apr_pstrdup(pool,plugin_dir_path);
}
if(log_dir_path) {
dir_layout->log_dir_path = apr_pstrdup(pool,log_dir_path);
}
if(data_dir_path) {
dir_layout->data_dir_path = apr_pstrdup(pool,data_dir_path);
}
return dir_layout;
}
APT_DECLARE(char*) apt_datadir_filepath_get(const apt_dir_layout_t *dir_layout, const char *file_name, apr_pool_t *pool)
{
if(dir_layout && dir_layout->data_dir_path && file_name) {
char *file_path = NULL;
if(apr_filepath_merge(&file_path,dir_layout->data_dir_path,file_name,0,pool) == APR_SUCCESS) {
return file_path;
}
}
return NULL;
}

View File

@ -0,0 +1,304 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <apr_time.h>
#include <apr_file_io.h>
#include "apt_log.h"
#define MAX_LOG_ENTRY_SIZE 4096
#define MAX_PRIORITY_NAME_LENGTH 9
static const char priority_snames[APT_PRIO_COUNT][MAX_PRIORITY_NAME_LENGTH+1] =
{
"[EMERG] ",
"[ALERT] ",
"[CRITIC] ",
"[ERROR] ",
"[WARN] ",
"[NOTICE] ",
"[INFO] ",
"[DEBUG] "
};
typedef struct apt_log_file_data_t apt_log_file_data_t;
struct apt_log_file_data_t {
const char *log_dir_path;
const char *log_file_name;
FILE *file;
apr_size_t cur_size;
apr_size_t max_size;
apr_size_t cur_file_index;
apr_size_t max_file_count;
apr_thread_mutex_t *mutex;
apr_pool_t *pool;
};
struct apt_logger_t {
apt_log_output_e mode;
apt_log_priority_e priority;
int header;
apt_log_ext_handler_f ext_handler;
apt_log_file_data_t *file_data;
};
static apt_logger_t *apt_logger = NULL;
static apt_bool_t apt_do_log(const char *file, int line, apt_log_priority_e priority, const char *format, va_list arg_ptr);
static const char* apt_log_file_path_make(apt_log_file_data_t *file_data);
static apt_bool_t apt_log_file_dump(apt_log_file_data_t *file_data, const char *log_entry, apr_size_t size);
APT_DECLARE(apt_bool_t) apt_log_instance_create(apt_log_output_e mode, apt_log_priority_e priority, apr_pool_t *pool)
{
if(apt_logger) {
return FALSE;
}
apt_logger = apr_palloc(pool,sizeof(apt_logger_t));
apt_logger->mode = mode;
apt_logger->priority = priority;
apt_logger->header = APT_LOG_HEADER_DEFAULT;
apt_logger->ext_handler = NULL;
apt_logger->file_data = NULL;
return TRUE;
}
APT_DECLARE(apt_bool_t) apt_log_instance_destroy()
{
if(!apt_logger) {
return FALSE;
}
if(apt_logger->file_data) {
apt_log_file_close();
}
apt_logger = NULL;
return TRUE;
}
APT_DECLARE(apt_logger_t*) apt_log_instance_get()
{
return apt_logger;
}
APT_DECLARE(apt_bool_t) apt_log_instance_set(apt_logger_t *logger)
{
if(apt_logger){
return FALSE;
}
apt_logger = logger;
return TRUE;
}
APT_DECLARE(apt_bool_t) apt_log_file_open(const char *dir_path, const char *file_name, apr_size_t max_file_size, apr_size_t max_file_count, apr_pool_t *pool)
{
const char *log_file_path;
apt_log_file_data_t *file_data;
if(!apt_logger || !dir_path || !file_name) {
return FALSE;
}
if(apt_logger->file_data) {
return FALSE;
}
file_data = apr_palloc(pool,sizeof(apt_log_file_data_t));
file_data->log_dir_path = dir_path;
file_data->log_file_name = file_name;
file_data->cur_file_index = 0;
file_data->cur_size = 0;
file_data->max_file_count = max_file_count;
file_data->max_size = max_file_size;
file_data->mutex = NULL;
file_data->pool = pool;
if(!file_data->max_size) {
file_data->max_file_count = MAX_LOG_FILE_SIZE;
}
if(!file_data->max_file_count) {
file_data->max_file_count = MAX_LOG_FILE_COUNT;
}
/* create mutex */
if(apr_thread_mutex_create(&file_data->mutex,APR_THREAD_MUTEX_DEFAULT,pool) != APR_SUCCESS) {
return FALSE;
}
/* open log file */
log_file_path = apt_log_file_path_make(file_data);
file_data->file = fopen(log_file_path,"wb");
if(!file_data->file) {
apr_thread_mutex_destroy(file_data->mutex);
return FALSE;
}
apt_logger->file_data = file_data;
return TRUE;
}
APT_DECLARE(apt_bool_t) apt_log_file_close()
{
apt_log_file_data_t *file_data;
if(!apt_logger || !apt_logger->file_data) {
return FALSE;
}
file_data = apt_logger->file_data;
if(file_data->file) {
/* close log file */
fclose(file_data->file);
file_data->file = NULL;
/* destroy mutex */
apr_thread_mutex_destroy(file_data->mutex);
file_data->mutex = NULL;
}
apt_logger->file_data = NULL;
return TRUE;
}
APT_DECLARE(apt_bool_t) apt_log_output_mode_set(apt_log_output_e mode)
{
if(!apt_logger) {
return FALSE;
}
apt_logger->mode = mode;
return TRUE;
}
APT_DECLARE(apt_bool_t) apt_log_priority_set(apt_log_priority_e priority)
{
if(!apt_logger || priority >= APT_PRIO_COUNT) {
return FALSE;
}
apt_logger->priority = priority;
return TRUE;
}
APT_DECLARE(apt_bool_t) apt_log_header_set(int header)
{
if(!apt_logger) {
return FALSE;
}
apt_logger->header = header;
return TRUE;
}
APT_DECLARE(apt_bool_t) apt_log_ext_handler_set(apt_log_ext_handler_f handler)
{
if(!apt_logger) {
return FALSE;
}
apt_logger->ext_handler = handler;
return TRUE;
}
APT_DECLARE(apt_bool_t) apt_log(const char *file, int line, apt_log_priority_e priority, const char *format, ...)
{
apt_bool_t status = TRUE;
if(!apt_logger) {
return FALSE;
}
if(priority <= apt_logger->priority) {
va_list arg_ptr;
va_start(arg_ptr, format);
if(apt_logger->ext_handler) {
status = apt_logger->ext_handler(file,line,NULL,priority,format,arg_ptr);
}
else {
status = apt_do_log(file,line,priority,format,arg_ptr);
}
va_end(arg_ptr);
}
return status;
}
static apt_bool_t apt_do_log(const char *file, int line, apt_log_priority_e priority, const char *format, va_list arg_ptr)
{
char log_entry[MAX_LOG_ENTRY_SIZE];
apr_size_t offset = 0;
apr_time_exp_t result;
apr_time_t now = apr_time_now();
apr_time_exp_lt(&result,now);
if(apt_logger->header & APT_LOG_HEADER_DATE) {
offset += apr_snprintf(log_entry+offset,MAX_LOG_ENTRY_SIZE-offset,"%4d-%02d-%02d ",
result.tm_year+1900,
result.tm_mon+1,
result.tm_mday);
}
if(apt_logger->header & APT_LOG_HEADER_TIME) {
offset += apr_snprintf(log_entry+offset,MAX_LOG_ENTRY_SIZE-offset,"%02d:%02d:%02d:%06d ",
result.tm_hour,
result.tm_min,
result.tm_sec,
result.tm_usec);
}
if(apt_logger->header & APT_LOG_HEADER_MARK) {
offset += apr_snprintf(log_entry+offset,MAX_LOG_ENTRY_SIZE-offset,"%s:%03d ",file,line);
}
if(apt_logger->header & APT_LOG_HEADER_PRIORITY) {
memcpy(log_entry+offset,priority_snames[priority],MAX_PRIORITY_NAME_LENGTH);
offset += MAX_PRIORITY_NAME_LENGTH;
}
offset += apr_vsnprintf(log_entry+offset,MAX_LOG_ENTRY_SIZE-offset,format,arg_ptr);
log_entry[offset++] = '\n';
log_entry[offset] = '\0';
if((apt_logger->mode & APT_LOG_OUTPUT_CONSOLE) == APT_LOG_OUTPUT_CONSOLE) {
printf(log_entry);
}
if((apt_logger->mode & APT_LOG_OUTPUT_FILE) == APT_LOG_OUTPUT_FILE && apt_logger->file_data) {
apt_log_file_dump(apt_logger->file_data,log_entry,offset);
}
return TRUE;
}
static const char* apt_log_file_path_make(apt_log_file_data_t *file_data)
{
char *log_file_path = NULL;
const char *log_file_name = apr_psprintf(file_data->pool,"%s-%d.log",file_data->log_file_name,file_data->cur_file_index);
apr_filepath_merge(&log_file_path,file_data->log_dir_path,log_file_name,0,file_data->pool);
return log_file_path;
}
static apt_bool_t apt_log_file_dump(apt_log_file_data_t *file_data, const char *log_entry, apr_size_t size)
{
apr_thread_mutex_lock(file_data->mutex);
file_data->cur_size += size;
if(file_data->cur_size > file_data->max_size) {
const char *log_file_path;
/* close current log file */
fclose(file_data->file);
/* roll over the next log file */
file_data->cur_file_index++;
file_data->cur_file_index %= file_data->max_file_count;
/* open log file */
log_file_path = apt_log_file_path_make(file_data);
file_data->file = fopen(log_file_path,"wb");
if(!file_data->file) {
return FALSE;
}
file_data->cur_size = size;
}
/* write to log file */
fwrite(log_entry,1,size,file_data->file);
fflush(file_data->file);
apr_thread_mutex_unlock(file_data->mutex);
return TRUE;
}

View File

@ -0,0 +1,35 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <apr_network_io.h>
#include "apt_net.h"
/** Get the IP address (in numeric address string format) by hostname */
apt_bool_t apt_ip_get(char **addr, apr_pool_t *pool)
{
apr_sockaddr_t *sockaddr = NULL;
char *hostname = apr_palloc(pool,APRMAXHOSTLEN+1);
if(apr_gethostname(hostname,APRMAXHOSTLEN,pool) != APR_SUCCESS) {
return FALSE;
}
if(apr_sockaddr_info_get(&sockaddr,hostname,APR_INET,0,0,pool) != APR_SUCCESS) {
return FALSE;
}
if(apr_sockaddr_ip_get(addr,sockaddr) != APR_SUCCESS) {
return FALSE;
}
return TRUE;
}

View File

@ -0,0 +1,320 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "apt_net_client_task.h"
#include "apt_task.h"
#include "apt_pool.h"
#include "apt_pollset.h"
#include "apt_cyclic_queue.h"
#include "apt_log.h"
/** Network client task */
struct apt_net_client_task_t {
apr_pool_t *pool;
apt_task_t *base;
void *obj;
apr_size_t max_connection_count;
apr_thread_mutex_t *guard;
apt_cyclic_queue_t *msg_queue;
apt_pollset_t *pollset;
const apt_net_client_vtable_t *client_vtable;
};
static apt_bool_t apt_net_client_task_msg_signal(apt_task_t *task, apt_task_msg_t *msg);
static apt_bool_t apt_net_client_task_run(apt_task_t *task);
static apt_bool_t apt_net_client_task_on_destroy(apt_task_t *task);
/** Create connection task */
APT_DECLARE(apt_net_client_task_t*) apt_net_client_task_create(
apr_size_t max_connection_count,
void *obj,
const apt_net_client_vtable_t *client_vtable,
apt_task_msg_pool_t *msg_pool,
apr_pool_t *pool)
{
apt_task_vtable_t *vtable;
apt_net_client_task_t *task;
task = apr_palloc(pool,sizeof(apt_net_client_task_t));
task->pool = pool;
task->obj = obj;
task->pollset = NULL;
task->max_connection_count = max_connection_count;
if(!client_vtable || !client_vtable->on_receive) {
return NULL;
}
task->client_vtable = client_vtable;
task->base = apt_task_create(task,msg_pool,pool);
if(!task->base) {
return NULL;
}
vtable = apt_task_vtable_get(task->base);
if(vtable) {
vtable->run = apt_net_client_task_run;
vtable->destroy = apt_net_client_task_on_destroy;
vtable->signal_msg = apt_net_client_task_msg_signal;
}
task->msg_queue = apt_cyclic_queue_create(CYCLIC_QUEUE_DEFAULT_SIZE);
apr_thread_mutex_create(&task->guard,APR_THREAD_MUTEX_UNNESTED,pool);
return task;
}
/** Virtual destroy handler */
static apt_bool_t apt_net_client_task_on_destroy(apt_task_t *base)
{
apt_net_client_task_t *task = apt_task_object_get(base);
if(task->guard) {
apr_thread_mutex_destroy(task->guard);
task->guard = NULL;
}
if(task->msg_queue) {
apt_cyclic_queue_destroy(task->msg_queue);
task->msg_queue = NULL;
}
return TRUE;
}
/** Destroy connection task. */
APT_DECLARE(apt_bool_t) apt_net_client_task_destroy(apt_net_client_task_t *task)
{
return apt_task_destroy(task->base);
}
/** Start connection task. */
APT_DECLARE(apt_bool_t) apt_net_client_task_start(apt_net_client_task_t *task)
{
return apt_task_start(task->base);
}
/** Terminate connection task. */
APT_DECLARE(apt_bool_t) apt_net_client_task_terminate(apt_net_client_task_t *task)
{
return apt_task_terminate(task->base,TRUE);
}
/** Get task */
APT_DECLARE(apt_task_t*) apt_net_client_task_base_get(apt_net_client_task_t *task)
{
return task->base;
}
/** Get task vtable */
APT_DECLARE(apt_task_vtable_t*) apt_net_client_task_vtable_get(apt_net_client_task_t *task)
{
return apt_task_vtable_get(task->base);
}
/** Get external object */
APT_DECLARE(void*) apt_net_client_task_object_get(apt_net_client_task_t *task)
{
return task->obj;
}
/** Create connection */
APT_DECLARE(apt_net_client_connection_t*) apt_net_client_connect(apt_net_client_task_t *task, const char *ip, apr_port_t port)
{
char *local_ip = NULL;
char *remote_ip = NULL;
apr_sockaddr_t *l_sockaddr = NULL;
apr_sockaddr_t *r_sockaddr = NULL;
apt_net_client_connection_t *connection;
apr_pool_t *pool = apt_pool_create();
if(!pool) {
return NULL;
}
connection = apr_palloc(pool,sizeof(apt_net_client_connection_t));
connection->pool = pool;
connection->obj = NULL;
connection->sock = NULL;
if(apr_sockaddr_info_get(&r_sockaddr,ip,APR_INET,port,0,connection->pool) != APR_SUCCESS) {
apr_pool_destroy(pool);
return NULL;
}
if(apr_socket_create(&connection->sock,r_sockaddr->family,SOCK_STREAM,APR_PROTO_TCP,connection->pool) != APR_SUCCESS) {
apr_pool_destroy(pool);
return NULL;
}
apr_socket_opt_set(connection->sock, APR_SO_NONBLOCK, 0);
apr_socket_timeout_set(connection->sock, -1);
apr_socket_opt_set(connection->sock, APR_SO_REUSEADDR, 1);
if(apr_socket_connect(connection->sock,r_sockaddr) != APR_SUCCESS) {
apr_socket_close(connection->sock);
apr_pool_destroy(pool);
return NULL;
}
if(apr_socket_addr_get(&l_sockaddr,APR_LOCAL,connection->sock) != APR_SUCCESS) {
apr_socket_close(connection->sock);
apr_pool_destroy(pool);
return NULL;
}
apr_sockaddr_ip_get(&local_ip,l_sockaddr);
apr_sockaddr_ip_get(&remote_ip,r_sockaddr);
connection->id = apr_psprintf(pool,"%s:%hu <-> %s:%hu",
local_ip,l_sockaddr->port,
remote_ip,r_sockaddr->port);
memset(&connection->sock_pfd,0,sizeof(apr_pollfd_t));
connection->sock_pfd.desc_type = APR_POLL_SOCKET;
connection->sock_pfd.reqevents = APR_POLLIN;
connection->sock_pfd.desc.s = connection->sock;
connection->sock_pfd.client_data = connection;
if(apt_pollset_add(task->pollset,&connection->sock_pfd) != TRUE) {
apr_socket_close(connection->sock);
apr_pool_destroy(pool);
return NULL;
}
apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Established TCP Connection %s",connection->id);
return connection;
}
/** Close connection */
APT_DECLARE(apt_bool_t) apt_net_client_connection_close(apt_net_client_task_t *task, apt_net_client_connection_t *connection)
{
if(connection->sock) {
apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Close TCP Connection %s",connection->id);
apt_pollset_remove(task->pollset,&connection->sock_pfd);
apr_socket_close(connection->sock);
connection->sock = NULL;
}
return TRUE;
}
/** Close and destroy connection */
APT_DECLARE(apt_bool_t) apt_net_client_disconnect(apt_net_client_task_t *task, apt_net_client_connection_t *connection)
{
apt_net_client_connection_close(task,connection);
apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Destroy TCP Connection %s",connection->id);
apr_pool_destroy(connection->pool);
return TRUE;
}
/** Create the pollset */
static apt_bool_t apt_net_client_task_pollset_create(apt_net_client_task_t *task)
{
/* create pollset */
task->pollset = apt_pollset_create((apr_uint32_t)task->max_connection_count, task->pool);
if(!task->pollset) {
apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create Pollset");
return FALSE;
}
return TRUE;
}
/** Destroy the pollset */
static void apt_net_client_task_pollset_destroy(apt_net_client_task_t *task)
{
if(task->pollset) {
apt_pollset_destroy(task->pollset);
task->pollset = NULL;
}
}
static apt_bool_t apt_net_client_task_process(apt_net_client_task_t *task)
{
apt_bool_t status = TRUE;
apt_bool_t running = TRUE;
apt_task_msg_t *msg;
do {
apr_thread_mutex_lock(task->guard);
msg = apt_cyclic_queue_pop(task->msg_queue);
apr_thread_mutex_unlock(task->guard);
if(msg) {
status = apt_task_msg_process(task->base,msg);
}
else {
running = FALSE;
}
}
while(running == TRUE);
return status;
}
static apt_bool_t apt_net_client_task_run(apt_task_t *base)
{
apt_net_client_task_t *task = apt_task_object_get(base);
apt_bool_t running = TRUE;
apr_status_t status;
apr_int32_t num;
const apr_pollfd_t *ret_pfd;
int i;
if(!task) {
apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Start Network Client Task");
return FALSE;
}
if(apt_net_client_task_pollset_create(task) == FALSE) {
apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create Pollset");
return FALSE;
}
while(running) {
status = apt_pollset_poll(task->pollset, -1, &num, &ret_pfd);
if(status != APR_SUCCESS) {
continue;
}
for(i = 0; i < num; i++) {
if(apt_pollset_is_wakeup(task->pollset,&ret_pfd[i])) {
apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Process Control Message");
if(apt_net_client_task_process(task) == FALSE) {
running = FALSE;
break;
}
continue;
}
apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Process Message");
task->client_vtable->on_receive(task,ret_pfd[i].client_data);
}
}
apt_net_client_task_pollset_destroy(task);
apt_task_child_terminate(task->base);
return TRUE;
}
static apt_bool_t apt_net_client_task_msg_signal(apt_task_t *base, apt_task_msg_t *msg)
{
apt_bool_t status;
apt_net_client_task_t *task = apt_task_object_get(base);
apr_thread_mutex_lock(task->guard);
status = apt_cyclic_queue_push(task->msg_queue,msg);
apr_thread_mutex_unlock(task->guard);
if(apt_pollset_wakeup(task->pollset) != TRUE) {
apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Signal Control Message");
status = FALSE;
}
return status;
}

View File

@ -0,0 +1,391 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "apt_net_server_task.h"
#include "apt_task.h"
#include "apt_pool.h"
#include "apt_pollset.h"
#include "apt_cyclic_queue.h"
#include "apt_log.h"
/** Network server task */
struct apt_net_server_task_t {
apr_pool_t *pool;
apt_task_t *base;
void *obj;
apr_size_t max_connection_count;
apr_thread_mutex_t *guard;
apt_cyclic_queue_t *msg_queue;
apt_pollset_t *pollset;
/* Listening socket descriptor */
apr_sockaddr_t *sockaddr;
apr_socket_t *listen_sock;
apr_pollfd_t listen_sock_pfd;
const apt_net_server_vtable_t *server_vtable;
};
static apt_bool_t apt_net_server_task_msg_signal(apt_task_t *task, apt_task_msg_t *msg);
static apt_bool_t apt_net_server_task_run(apt_task_t *task);
static apt_bool_t apt_net_server_task_on_destroy(apt_task_t *task);
/** Create connection task */
APT_DECLARE(apt_net_server_task_t*) apt_net_server_task_create(
const char *listen_ip,
apr_port_t listen_port,
apr_size_t max_connection_count,
void *obj,
const apt_net_server_vtable_t *server_vtable,
apt_task_msg_pool_t *msg_pool,
apr_pool_t *pool)
{
apt_task_vtable_t *vtable;
apt_net_server_task_t *task;
task = apr_palloc(pool,sizeof(apt_net_server_task_t));
task->pool = pool;
task->obj = obj;
task->sockaddr = NULL;
task->listen_sock = NULL;
task->pollset = NULL;
task->max_connection_count = max_connection_count;
apr_sockaddr_info_get(&task->sockaddr,listen_ip,APR_INET,listen_port,0,task->pool);
if(!task->sockaddr) {
return NULL;
}
if(!server_vtable || !server_vtable->on_connect ||
!server_vtable->on_disconnect || !server_vtable->on_receive) {
return NULL;
}
task->server_vtable = server_vtable;
task->base = apt_task_create(task,msg_pool,pool);
if(!task->base) {
return NULL;
}
vtable = apt_task_vtable_get(task->base);
if(vtable) {
vtable->run = apt_net_server_task_run;
vtable->destroy = apt_net_server_task_on_destroy;
vtable->signal_msg = apt_net_server_task_msg_signal;
}
task->msg_queue = apt_cyclic_queue_create(CYCLIC_QUEUE_DEFAULT_SIZE);
apr_thread_mutex_create(&task->guard,APR_THREAD_MUTEX_UNNESTED,pool);
return task;
}
/** Virtual destroy handler */
static apt_bool_t apt_net_server_task_on_destroy(apt_task_t *base)
{
apt_net_server_task_t *task = apt_task_object_get(base);
if(task->guard) {
apr_thread_mutex_destroy(task->guard);
task->guard = NULL;
}
if(task->msg_queue) {
apt_cyclic_queue_destroy(task->msg_queue);
task->msg_queue = NULL;
}
return TRUE;
}
/** Destroy connection task. */
APT_DECLARE(apt_bool_t) apt_net_server_task_destroy(apt_net_server_task_t *task)
{
return apt_task_destroy(task->base);
}
/** Start connection task. */
APT_DECLARE(apt_bool_t) apt_net_server_task_start(apt_net_server_task_t *task)
{
return apt_task_start(task->base);
}
/** Terminate connection task. */
APT_DECLARE(apt_bool_t) apt_net_server_task_terminate(apt_net_server_task_t *task)
{
return apt_task_terminate(task->base,TRUE);
}
/** Get task */
APT_DECLARE(apt_task_t*) apt_net_server_task_base_get(apt_net_server_task_t *task)
{
return task->base;
}
/** Get task vtable */
APT_DECLARE(apt_task_vtable_t*) apt_net_server_task_vtable_get(apt_net_server_task_t *task)
{
return apt_task_vtable_get(task->base);
}
/** Get external object */
APT_DECLARE(void*) apt_net_server_task_object_get(apt_net_server_task_t *task)
{
return task->obj;
}
/** Create listening socket and add to pollset */
static apt_bool_t apt_net_server_task_listen_socket_create(apt_net_server_task_t *task)
{
apr_status_t status;
if(!task->sockaddr) {
return FALSE;
}
/* create listening socket */
status = apr_socket_create(&task->listen_sock, task->sockaddr->family, SOCK_STREAM, APR_PROTO_TCP, task->pool);
if(status != APR_SUCCESS) {
return FALSE;
}
apr_socket_opt_set(task->listen_sock, APR_SO_NONBLOCK, 0);
apr_socket_timeout_set(task->listen_sock, -1);
apr_socket_opt_set(task->listen_sock, APR_SO_REUSEADDR, 1);
status = apr_socket_bind(task->listen_sock, task->sockaddr);
if(status != APR_SUCCESS) {
apr_socket_close(task->listen_sock);
task->listen_sock = NULL;
return FALSE;
}
status = apr_socket_listen(task->listen_sock, SOMAXCONN);
if(status != APR_SUCCESS) {
apr_socket_close(task->listen_sock);
task->listen_sock = NULL;
return FALSE;
}
memset(&task->listen_sock_pfd,0,sizeof(apr_pollfd_t));
task->listen_sock_pfd.desc_type = APR_POLL_SOCKET;
task->listen_sock_pfd.reqevents = APR_POLLIN;
task->listen_sock_pfd.desc.s = task->listen_sock;
task->listen_sock_pfd.client_data = task->listen_sock;
if(apt_pollset_add(task->pollset, &task->listen_sock_pfd) != TRUE) {
apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Add Listen Socket to Pollset");
apr_socket_close(task->listen_sock);
task->listen_sock = NULL;
}
return TRUE;
}
/** Remove from pollset and destroy listening socket */
static void apt_net_server_task_listen_socket_destroy(apt_net_server_task_t *task)
{
apt_pollset_remove(task->pollset,&task->listen_sock_pfd);
if(task->listen_sock) {
apr_socket_close(task->listen_sock);
task->listen_sock = NULL;
}
}
/** Create the pollset */
static apt_bool_t apt_net_server_task_pollset_create(apt_net_server_task_t *task)
{
/* create pollset */
task->pollset = apt_pollset_create((apr_uint32_t)task->max_connection_count + 1, task->pool);
if(!task->pollset) {
apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create Pollset");
return FALSE;
}
/* create listening socket */
if(apt_net_server_task_listen_socket_create(task) != TRUE) {
apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create Listen Socket");
}
return TRUE;
}
/** Destroy the pollset */
static void apt_net_server_task_pollset_destroy(apt_net_server_task_t *task)
{
apt_net_server_task_listen_socket_destroy(task);
if(task->pollset) {
apt_pollset_destroy(task->pollset);
task->pollset = NULL;
}
}
static apt_bool_t apt_net_server_task_process(apt_net_server_task_t *task)
{
apt_bool_t status = TRUE;
apt_bool_t running = TRUE;
apt_task_msg_t *msg;
do {
apr_thread_mutex_lock(task->guard);
msg = apt_cyclic_queue_pop(task->msg_queue);
apr_thread_mutex_unlock(task->guard);
if(msg) {
status = apt_task_msg_process(task->base,msg);
}
else {
running = FALSE;
}
}
while(running == TRUE);
return status;
}
static apt_bool_t apt_net_server_task_accept(apt_net_server_task_t *task)
{
char *local_ip = NULL;
char *remote_ip = NULL;
apr_sockaddr_t *l_sockaddr = NULL;
apr_sockaddr_t *r_sockaddr = NULL;
apt_net_server_connection_t *connection;
apr_pool_t *pool = apt_pool_create();
if(!pool) {
return FALSE;
}
connection = apr_palloc(pool,sizeof(apt_net_server_connection_t));
connection->pool = pool;
connection->obj = NULL;
connection->sock = NULL;
connection->client_ip = NULL;
if(apr_socket_accept(&connection->sock,task->listen_sock,connection->pool) != APR_SUCCESS) {
apr_pool_destroy(pool);
return FALSE;
}
if(apr_socket_addr_get(&l_sockaddr,APR_LOCAL,connection->sock) != APR_SUCCESS ||
apr_socket_addr_get(&r_sockaddr,APR_REMOTE,connection->sock) != APR_SUCCESS) {
apr_pool_destroy(pool);
return FALSE;
}
apr_sockaddr_ip_get(&local_ip,l_sockaddr);
apr_sockaddr_ip_get(&remote_ip,r_sockaddr);
connection->client_ip = remote_ip;
connection->id = apr_psprintf(pool,"%s:%hu <-> %s:%hu",
local_ip,l_sockaddr->port,
remote_ip,r_sockaddr->port);
memset(&connection->sock_pfd,0,sizeof(apr_pollfd_t));
connection->sock_pfd.desc_type = APR_POLL_SOCKET;
connection->sock_pfd.reqevents = APR_POLLIN;
connection->sock_pfd.desc.s = connection->sock;
connection->sock_pfd.client_data = connection;
if(apt_pollset_add(task->pollset,&connection->sock_pfd) != TRUE) {
apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Add to Pollset");
apr_socket_close(connection->sock);
apr_pool_destroy(pool);
return FALSE;
}
apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Accepted TCP Connection %s",connection->id);
task->server_vtable->on_connect(task,connection);
return TRUE;
}
static apt_bool_t apt_net_server_task_run(apt_task_t *base)
{
apt_net_server_task_t *task = apt_task_object_get(base);
apt_bool_t running = TRUE;
apr_status_t status;
apr_int32_t num;
const apr_pollfd_t *ret_pfd;
int i;
if(!task) {
apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Start Network Server Task");
return FALSE;
}
if(apt_net_server_task_pollset_create(task) == FALSE) {
apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create Pollset");
return FALSE;
}
while(running) {
status = apt_pollset_poll(task->pollset, -1, &num, &ret_pfd);
if(status != APR_SUCCESS) {
continue;
}
for(i = 0; i < num; i++) {
if(ret_pfd[i].desc.s == task->listen_sock) {
apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Accept Connection");
apt_net_server_task_accept(task);
continue;
}
if(apt_pollset_is_wakeup(task->pollset,&ret_pfd[i])) {
apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Process Control Message");
if(apt_net_server_task_process(task) == FALSE) {
running = FALSE;
break;
}
continue;
}
apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Process Message");
task->server_vtable->on_receive(task,ret_pfd[i].client_data);
}
}
apt_net_server_task_pollset_destroy(task);
apt_task_child_terminate(task->base);
return TRUE;
}
static apt_bool_t apt_net_server_task_msg_signal(apt_task_t *base, apt_task_msg_t *msg)
{
apt_bool_t status;
apt_net_server_task_t *task = apt_task_object_get(base);
apr_thread_mutex_lock(task->guard);
status = apt_cyclic_queue_push(task->msg_queue,msg);
apr_thread_mutex_unlock(task->guard);
if(apt_pollset_wakeup(task->pollset) != TRUE) {
apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Signal Control Message");
status = FALSE;
}
return status;
}
/** Close connection */
APT_DECLARE(apt_bool_t) apt_net_server_connection_close(apt_net_server_task_t *task, apt_net_server_connection_t *connection)
{
if(connection->sock) {
apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Close TCP Connection %s",connection->id);
apt_pollset_remove(task->pollset,&connection->sock_pfd);
apr_socket_close(connection->sock);
connection->sock = NULL;
task->server_vtable->on_disconnect(task,connection);
}
return TRUE;
}
/** Destroy connection */
APT_DECLARE(void) apt_net_server_connection_destroy(apt_net_server_connection_t *connection)
{
apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Destroy TCP Connection %s",connection->id);
apr_pool_destroy(connection->pool);
}

View File

@ -0,0 +1,151 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef WIN32
#pragma warning(disable: 4127)
#endif
#include <apr_ring.h>
#include "apt_obj_list.h"
struct apt_list_elem_t {
APR_RING_ENTRY(apt_list_elem_t) link;
void *obj;
};
struct apt_obj_list_t {
APR_RING_HEAD(apt_list_head_t, apt_list_elem_t) head;
apr_pool_t *pool;
};
APT_DECLARE(apt_obj_list_t*) apt_list_create(apr_pool_t *pool)
{
apt_obj_list_t *list = apr_palloc(pool, sizeof(apt_obj_list_t));
list->pool = pool;
APR_RING_INIT(&list->head, apt_list_elem_t, link);
return list;
}
APT_DECLARE(void) apt_list_destroy(apt_obj_list_t *list)
{
/* nothing to do, the list is allocated from the pool */
}
APT_DECLARE(apt_list_elem_t*) apt_list_push_back(apt_obj_list_t *list, void *obj, apr_pool_t *pool)
{
apt_list_elem_t *elem = apr_palloc(pool,sizeof(apt_list_elem_t));
elem->obj = obj;
APR_RING_INSERT_TAIL(&list->head,elem,apt_list_elem_t,link);
return elem;
}
APT_DECLARE(void*) apt_list_pop_front(apt_obj_list_t *list)
{
apt_list_elem_t *elem;
if(APR_RING_EMPTY(&list->head,apt_list_elem_t,link)) {
return NULL;
}
elem = APR_RING_FIRST(&list->head);
APR_RING_REMOVE(elem,link);
return elem->obj;
}
APT_DECLARE(void*) apt_list_head(apt_obj_list_t *list)
{
apt_list_elem_t *elem;
if(APR_RING_EMPTY(&list->head,apt_list_elem_t,link)) {
return NULL;
}
elem = APR_RING_FIRST(&list->head);
return elem->obj;
}
APT_DECLARE(void*) apt_obj_list_tail(apt_obj_list_t *list)
{
apt_list_elem_t *elem;
if(APR_RING_EMPTY(&list->head,apt_list_elem_t,link)) {
return NULL;
}
elem = APR_RING_LAST(&list->head);
return elem->obj;
}
APT_DECLARE(apt_list_elem_t*) apt_list_first_elem_get(apt_obj_list_t *list)
{
if(APR_RING_EMPTY(&list->head,apt_list_elem_t,link)) {
return NULL;
}
return APR_RING_FIRST(&list->head);
}
APT_DECLARE(apt_list_elem_t*) apt_list_last_elem_get(apt_obj_list_t *list)
{
if(APR_RING_EMPTY(&list->head,apt_list_elem_t,link)) {
return NULL;
}
return APR_RING_LAST(&list->head);
}
APT_DECLARE(apt_list_elem_t*) apt_list_next_elem_get(apt_obj_list_t *list, apt_list_elem_t *elem)
{
apt_list_elem_t *next_elem = APR_RING_NEXT(elem,link);
if(next_elem == APR_RING_SENTINEL(&list->head,apt_list_elem_t,link)) {
next_elem = NULL;
}
return next_elem;
}
APT_DECLARE(apt_list_elem_t*) apt_list_prev_elem_get(apt_obj_list_t *list, apt_list_elem_t *elem)
{
apt_list_elem_t *prev_elem = APR_RING_PREV(elem,link);
if(prev_elem == APR_RING_SENTINEL(&list->head,apt_list_elem_t,link)) {
prev_elem = NULL;
}
return prev_elem;
}
APT_DECLARE(apt_list_elem_t*) apt_list_elem_insert(apt_obj_list_t *list, apt_list_elem_t *elem, void *obj, apr_pool_t *pool)
{
apt_list_elem_t *new_elem = apr_palloc(pool,sizeof(apt_list_elem_t));
new_elem->obj = obj;
APR_RING_INSERT_BEFORE(elem,new_elem,link);
return new_elem;
}
APT_DECLARE(apt_list_elem_t*) apt_list_elem_remove(apt_obj_list_t *list, apt_list_elem_t *elem)
{
apt_list_elem_t *next_elem = APR_RING_NEXT(elem,link);
APR_RING_REMOVE(elem,link);
if(next_elem == APR_RING_SENTINEL(&list->head,apt_list_elem_t,link)) {
next_elem = NULL;
}
return next_elem;
}
APT_DECLARE(apt_bool_t) apt_list_is_empty(apt_obj_list_t *list)
{
if(APR_RING_EMPTY(&list->head,apt_list_elem_t,link)) {
return TRUE;
}
return FALSE;
}
APT_DECLARE(void*) apt_list_elem_object_get(apt_list_elem_t *elem)
{
return elem->obj;
}

View File

@ -0,0 +1,86 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "apt_pair.h"
/** Create array of name-value pairs */
APT_DECLARE(apt_pair_arr_t*) apt_pair_array_create(apr_size_t initial_size, apr_pool_t *pool)
{
return apr_array_make(pool,(int)initial_size,sizeof(apt_pair_t));
}
/** Copy array of name-value pairs */
APT_DECLARE(apt_pair_arr_t*) apt_pair_array_copy(const apt_pair_arr_t *src_arr, apr_pool_t *pool)
{
int i;
const apt_pair_t *src_pair;
apt_pair_t *pair;
apt_pair_arr_t *arr;
if(!src_arr) {
return NULL;
}
arr = apr_array_copy(pool,src_arr);
for(i=0; i<arr->nelts; i++) {
pair = (apt_pair_t*)arr->elts + i;
src_pair = (const apt_pair_t*)src_arr->elts + i;
apt_pair_copy(pair,src_pair,pool);
}
return arr;
}
/** Append name-value pair */
APT_DECLARE(apt_bool_t) apt_pair_array_append(apt_pair_arr_t *arr, const apt_str_t *name, const apt_str_t *value, apr_pool_t *pool)
{
apt_pair_t *pair = apr_array_push(arr);
apt_pair_init(pair);
if(name) {
apt_string_copy(&pair->name,name,pool);
}
if(value) {
apt_string_copy(&pair->value,value,pool);
}
return TRUE;
}
/** Find name-value pair by name */
APT_DECLARE(const apt_pair_t*) apt_pair_array_find(const apt_pair_arr_t *arr, const apt_str_t *name)
{
int i;
apt_pair_t *pair;
for(i=0; i<arr->nelts; i++) {
pair = (apt_pair_t*)arr->elts + i;
if(apt_string_compare(&pair->name,name) == TRUE) {
return pair;
}
}
return NULL;
}
/** Get size of pair array */
APT_DECLARE(int) apt_pair_array_size_get(const apt_pair_arr_t *arr)
{
return arr->nelts;
}
/** Get name-value pair by id */
APT_DECLARE(const apt_pair_t*) apt_pair_array_get(const apt_pair_arr_t *arr, int id)
{
if(id < arr->nelts) {
return (apt_pair_t*)arr->elts + id;
}
return NULL;
}

View File

@ -0,0 +1,323 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <apr_poll.h>
#include "apt_pollset.h"
#include "apt_log.h"
struct apt_pollset_t {
/** APR pollset */
apr_pollset_t *base;
#ifdef WIN32
/** Socket descriptors used for wakeup */
apr_socket_t *wakeup_pipe[2];
#else
/** Pipe descriptors used for wakeup */
apr_file_t *wakeup_pipe[2];
#endif
/** Builtin wakeup poll descriptor */
apr_pollfd_t wakeup_pfd;
/** Pool to allocate memory from */
apr_pool_t *pool;
};
static apt_bool_t apt_wakeup_pipe_create(apt_pollset_t *pollset);
static apt_bool_t apt_wakeup_pipe_destroy(apt_pollset_t *pollset);
/** Create interruptable pollset on top of APR pollset */
APT_DECLARE(apt_pollset_t*) apt_pollset_create(apr_uint32_t size, apr_pool_t *pool)
{
apt_pollset_t *pollset = apr_palloc(pool,sizeof(apt_pollset_t));
pollset->pool = pool;
memset(&pollset->wakeup_pfd,0,sizeof(pollset->wakeup_pfd));
/* create pollset with max number of descriptors size+1,
where +1 is builtin wakeup descriptor */
if(apr_pollset_create(&pollset->base,size+1,pool,0) != APR_SUCCESS) {
return NULL;
}
/* create wakeup pipe */
if(apt_wakeup_pipe_create(pollset) != TRUE) {
apr_pollset_destroy(pollset->base);
return NULL;
}
/* add wakeup pipe to pollset */
if(apr_pollset_add(pollset->base,&pollset->wakeup_pfd) != APR_SUCCESS) {
apt_wakeup_pipe_destroy(pollset);
apr_pollset_destroy(pollset->base);
return NULL;
}
return pollset;
}
/** Destroy pollset */
APT_DECLARE(apt_bool_t) apt_pollset_destroy(apt_pollset_t *pollset)
{
/* remove wakeup pipe from pollset */
apr_pollset_remove(pollset->base,&pollset->wakeup_pfd);
/* destroy wakeup pipe */
apt_wakeup_pipe_destroy(pollset);
/* destroy pollset */
apr_pollset_destroy(pollset->base);
return TRUE;
}
/** Add pollset descriptor to a pollset */
APT_DECLARE(apt_bool_t) apt_pollset_add(apt_pollset_t *pollset, const apr_pollfd_t *descriptor)
{
return (apr_pollset_add(pollset->base,descriptor) == APR_SUCCESS) ? TRUE : FALSE;
}
/** Remove pollset descriptor from a pollset */
APT_DECLARE(apt_bool_t) apt_pollset_remove(apt_pollset_t *pollset, const apr_pollfd_t *descriptor)
{
return (apr_pollset_remove(pollset->base,descriptor) == APR_SUCCESS) ? TRUE : FALSE;
}
/** Block for activity on the descriptor(s) in a pollset */
APT_DECLARE(apr_status_t) apt_pollset_poll(
apt_pollset_t *pollset,
apr_interval_time_t timeout,
apr_int32_t *num,
const apr_pollfd_t **descriptors)
{
return apr_pollset_poll(pollset->base,timeout,num,descriptors);
}
/** Interrupt the blocked poll call */
APT_DECLARE(apt_bool_t) apt_pollset_wakeup(apt_pollset_t *pollset)
{
apt_bool_t status = TRUE;
#ifdef WIN32
char tmp = 0;
apr_size_t len = sizeof(tmp);
if(apr_socket_send(pollset->wakeup_pipe[1],&tmp,&len) != APR_SUCCESS) {
status = FALSE;
}
#else
if(apr_file_putc(1, pollset->wakeup_pipe[1]) != APR_SUCCESS) {
status = FALSE;
}
#endif
return status;
}
/** Match against builtin wake up descriptor in a pollset */
APT_DECLARE(apt_bool_t) apt_pollset_is_wakeup(apt_pollset_t *pollset, const apr_pollfd_t *descriptor)
{
apt_bool_t status = FALSE;
#ifdef WIN32
if(descriptor->desc.s == pollset->wakeup_pipe[0]) {
char rb[512];
apr_size_t nr = sizeof(rb);
/* simply read out from the input side of the pipe all the data. */
while(apr_socket_recv(pollset->wakeup_pipe[0], rb, &nr) == APR_SUCCESS) {
if(nr != sizeof(rb)) {
break;
}
}
status = TRUE;
}
#else
if(descriptor->desc.f == pollset->wakeup_pipe[0]) {
char rb[512];
apr_size_t nr = sizeof(rb);
/* simply read out from the input side of the pipe all the data. */
while(apr_file_read(pollset->wakeup_pipe[0], rb, &nr) == APR_SUCCESS) {
if(nr != sizeof(rb)) {
break;
}
}
status = TRUE;
}
#endif
return status;
}
#ifdef WIN32
static apr_status_t socket_pipe_create(apr_socket_t **rd, apr_socket_t **wr, apr_pool_t *pool)
{
static int id = 0;
apr_socket_t *ls = NULL;
apr_sockaddr_t *pa = NULL;
apr_sockaddr_t *ca = NULL;
apr_size_t nrd;
int uid[2];
int iid[2];
/* Create the unique socket identifier
* so that we know the connection originated
* from us.
*/
uid[0] = getpid();
uid[1] = id++;
if(apr_socket_create(&ls, AF_INET, SOCK_STREAM, APR_PROTO_TCP, pool) != APR_SUCCESS) {
return apr_get_netos_error();
}
apr_socket_opt_set(ls, APR_SO_REUSEADDR, 1);
if(apr_sockaddr_info_get(&pa,"127.0.0.1",APR_INET,0,0,pool) != APR_SUCCESS) {
apr_socket_close(ls);
return apr_get_netos_error();
}
if(apr_socket_bind(ls, pa) != APR_SUCCESS) {
apr_socket_close(ls);
return apr_get_netos_error();
}
if(apr_socket_addr_get(&ca,APR_LOCAL,ls) != APR_SUCCESS) {
apr_socket_close(ls);
return apr_get_netos_error();
}
if(apr_socket_listen(ls,1) != APR_SUCCESS) {
apr_socket_close(ls);
return apr_get_netos_error();
}
if(apr_socket_create(wr, AF_INET, SOCK_STREAM, APR_PROTO_TCP, pool) != APR_SUCCESS) {
apr_socket_close(ls);
return apr_get_netos_error();
}
apr_socket_opt_set(*wr, APR_SO_REUSEADDR, 1);
if(apr_socket_connect(*wr, ca) != APR_SUCCESS) {
apr_socket_close(ls);
apr_socket_close(*wr);
return apr_get_netos_error();
}
nrd = sizeof(uid);
if(apr_socket_send(*wr, (char *)uid, &nrd) != APR_SUCCESS) {
apr_socket_close(ls);
apr_socket_close(*wr);
return apr_get_netos_error();
}
apr_socket_opt_set(ls, APR_SO_NONBLOCK, 0);
/* Listening socket is blocking by now. The accept should
* return immediatelly because we connected already.
*/
if(apr_socket_accept(rd, ls, pool) != APR_SUCCESS) {
apr_socket_close(ls);
apr_socket_close(*wr);
return apr_get_netos_error();
}
/* Put read side of the pipe to the blocking mode */
apr_socket_opt_set(*rd, APR_SO_NONBLOCK, 0);
for (;;) {
/* Verify the connection by reading the sent identification */
nrd = sizeof(iid);
if(apr_socket_recv(*rd, (char *)iid, &nrd) != APR_SUCCESS) {
apr_socket_close(ls);
apr_socket_close(*wr);
apr_socket_close(*rd);
return apr_get_netos_error();
}
if(nrd == sizeof(iid)) {
if(memcmp(uid, iid, sizeof(uid)) == 0) {
/* Wow, we recived what we sent */
break;
}
}
}
/* We don't need the listening socket any more */
apr_socket_close(ls);
return APR_SUCCESS;
}
/** Create a dummy wakeup pipe for interrupting the poller */
static apt_bool_t apt_wakeup_pipe_create(apt_pollset_t *pollset)
{
apr_socket_t *rd = NULL;
apr_socket_t *wr = NULL;
apr_status_t rv;
rv = socket_pipe_create(&rd,&wr,pollset->pool);
if(rv != APR_SUCCESS) {
char err_str[256];
apr_strerror(rv,err_str,sizeof(err_str));
apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Create Wakeup Pipe: %s",err_str);
return FALSE;
}
pollset->wakeup_pfd.reqevents = APR_POLLIN;
pollset->wakeup_pfd.desc_type = APR_POLL_SOCKET;
pollset->wakeup_pfd.desc.s = rd;
pollset->wakeup_pipe[0] = rd;
pollset->wakeup_pipe[1] = wr;
return TRUE;
}
/** Destroy wakeup pipe */
static apt_bool_t apt_wakeup_pipe_destroy(apt_pollset_t *pollset)
{
/* Close both sides of the wakeup pipe */
if(pollset->wakeup_pipe[0]) {
apr_socket_close(pollset->wakeup_pipe[0]);
pollset->wakeup_pipe[0] = NULL;
}
if(pollset->wakeup_pipe[1]) {
apr_socket_close(pollset->wakeup_pipe[1]);
pollset->wakeup_pipe[1] = NULL;
}
return TRUE;
}
#else
/** Create a dummy wakeup pipe for interrupting the poller */
static apt_bool_t apt_wakeup_pipe_create(apt_pollset_t *pollset)
{
apr_file_t *file_in = NULL;
apr_file_t *file_out = NULL;
if(apr_file_pipe_create(&file_in,&file_out,pollset->pool) != APR_SUCCESS) {
return FALSE;
}
pollset->wakeup_pfd.reqevents = APR_POLLIN;
pollset->wakeup_pfd.desc_type = APR_POLL_FILE;
pollset->wakeup_pfd.desc.f = file_in;
pollset->wakeup_pipe[0] = file_in;
pollset->wakeup_pipe[1] = file_out;
return TRUE;
}
/** Destroy wakeup pipe */
static apt_bool_t apt_wakeup_pipe_destroy(apt_pollset_t *pollset)
{
/* Close both sides of the wakeup pipe */
if(pollset->wakeup_pipe[0]) {
apr_file_close(pollset->wakeup_pipe[0]);
pollset->wakeup_pipe[0] = NULL;
}
if(pollset->wakeup_pipe[1]) {
apr_file_close(pollset->wakeup_pipe[1]);
pollset->wakeup_pipe[1] = NULL;
}
return TRUE;
}
#endif

View File

@ -0,0 +1,47 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "apt_pool.h"
//#define OWN_ALLOCATOR_PER_POOL
APT_DECLARE(apr_pool_t*) apt_pool_create()
{
apr_pool_t *pool = NULL;
#ifdef OWN_ALLOCATOR_PER_POOL
apr_allocator_t *allocator = NULL;
apr_thread_mutex_t *mutex = NULL;
if(apr_allocator_create(&allocator) == APR_SUCCESS) {
if(apr_pool_create_ex(&pool,NULL,NULL,allocator) == APR_SUCCESS) {
apr_allocator_owner_set(allocator,pool);
apr_thread_mutex_create(&mutex,APR_THREAD_MUTEX_NESTED,pool);
apr_allocator_mutex_set(allocator,mutex);
}
}
#else
apr_pool_create(&pool,NULL);
#endif
return pool;
}
APT_DECLARE(apr_pool_t*) apt_subpool_create(apr_pool_t *parent)
{
apr_pool_t *pool = NULL;
apr_pool_create(&pool,parent);
return pool;
}

View File

@ -0,0 +1,66 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <ctype.h>
#include "apt_string_table.h"
/* Get the string by a given id. */
APT_DECLARE(const apt_str_t*) apt_string_table_str_get(const apt_str_table_item_t table[], apr_size_t size, apr_size_t id)
{
if(id < size) {
return &table[id].value;
}
return NULL;
}
/* Find the id associated with a given string from the table */
APT_DECLARE(apr_size_t) apt_string_table_id_find(const apt_str_table_item_t table[], apr_size_t size, const apt_str_t *value)
{
/* Key character is stored within each apt_string_table_item.
At first, key characters must be matched in a loop crossing the items.
Then whole strings should be compared only for the matched item.
Key characters should be automatically generated once for a given string table. */
apr_size_t i;
const apt_str_table_item_t *item;
for(i=0; i<size; i++) {
item = &table[i];
if(item->value.length != value->length) {
/* lengths of th strings differ, just contninue */
continue;
}
/* check whether key is available */
if(item->key < value->length) {
/* check whether values are matched by key (using no case compare) */
if(value->length == item->value.length &&
tolower(item->value.buf[item->key]) == tolower(value->buf[item->key])) {
/* whole strings must be compared to ensure, should be done only once for each lookup */
if(apt_string_compare(&item->value,value) == TRUE) {
return i;
}
}
}
else {
/* no key available, just compare whole strings */
if(apt_string_compare(&item->value,value) == TRUE) {
return i;
}
}
}
/* no match found, return invalid id */
return size;
}

View File

@ -0,0 +1,417 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <apr_thread_proc.h>
#include <apr_thread_cond.h>
#include "apt_task.h"
#include "apt_obj_list.h"
#include "apt_log.h"
/** Internal states of the task */
typedef enum {
TASK_STATE_IDLE, /**< no task activity */
TASK_STATE_START_REQUESTED, /**< task start is requested and is in progress */
TASK_STATE_RUNNING, /**< task is running */
TASK_STATE_TERMINATE_REQUESTED /**< task termination is requested and is in progress */
} apt_task_state_t;
struct apt_task_t {
void *obj; /* external object associated with the task */
apr_pool_t *pool; /* memory pool to allocate task data from */
apt_task_msg_pool_t *msg_pool; /* message pool to allocate task messages from */
apr_thread_mutex_t *data_guard; /* mutex to protect task data */
apr_thread_t *thread_handle; /* thread handle */
apt_task_state_t state; /* current task state */
apt_task_vtable_t vtable; /* table of virtual methods */
apt_task_t *parent_task; /* parent (master) task */
apt_obj_list_t *child_tasks; /* list of the child (slave) tasks */
apr_size_t pending_start; /* number of pending start requests */
apr_size_t pending_term; /* number of pending terminate requests */
const char *name; /* name of the task */
};
static void* APR_THREAD_FUNC apt_task_run(apr_thread_t *thread_handle, void *data);
static apt_bool_t apt_task_terminate_request(apt_task_t *task);
APT_DECLARE(apt_task_t*) apt_task_create(
void *obj,
apt_task_msg_pool_t *msg_pool,
apr_pool_t *pool)
{
apt_task_t *task = apr_palloc(pool,sizeof(apt_task_t));
task->obj = obj;
task->pool = pool;
task->msg_pool = msg_pool;
if(!task->msg_pool) {
task->msg_pool = apt_task_msg_pool_create_dynamic(0,pool);
}
task->state = TASK_STATE_IDLE;
task->thread_handle = NULL;
if(apr_thread_mutex_create(&task->data_guard, APR_THREAD_MUTEX_DEFAULT, task->pool) != APR_SUCCESS) {
return NULL;
}
/* reset and copy vtable */
apt_task_vtable_reset(&task->vtable);
task->vtable.terminate = apt_task_terminate_request;
task->parent_task = NULL;
task->child_tasks = apt_list_create(pool);
task->pending_start = 0;
task->pending_term = 0;
task->name = "Task";
return task;
}
APT_DECLARE(apt_bool_t) apt_task_destroy(apt_task_t *task)
{
apt_task_t *child_task = NULL;
apt_list_elem_t *elem = apt_list_first_elem_get(task->child_tasks);
/* walk through the list of the child tasks and destroy them */
while(elem) {
child_task = apt_list_elem_object_get(elem);
if(child_task) {
apt_task_destroy(child_task);
}
elem = apt_list_next_elem_get(task->child_tasks,elem);
}
if(task->state != TASK_STATE_IDLE) {
apt_task_wait_till_complete(task);
}
apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Destroy %s",task->name);
if(task->vtable.destroy) {
task->vtable.destroy(task);
}
apr_thread_mutex_destroy(task->data_guard);
return TRUE;
}
APT_DECLARE(apt_bool_t) apt_task_add(apt_task_t *task, apt_task_t *child_task)
{
child_task->parent_task = task;
return (apt_list_push_back(task->child_tasks,child_task, child_task->pool) ? TRUE : FALSE);
}
APT_DECLARE(apt_bool_t) apt_task_start(apt_task_t *task)
{
apt_bool_t status = TRUE;
apr_thread_mutex_lock(task->data_guard);
if(task->state == TASK_STATE_IDLE) {
apr_status_t rv;
task->state = TASK_STATE_START_REQUESTED;
apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Start %s",task->name);
if(task->vtable.start) {
/* raise virtual start method */
task->vtable.start(task);
}
else {
/* start new thread by default */
rv = apr_thread_create(&task->thread_handle,NULL,apt_task_run,task,task->pool);
if(rv != APR_SUCCESS) {
task->state = TASK_STATE_IDLE;
status = FALSE;
}
}
}
else {
status = FALSE;
}
apr_thread_mutex_unlock(task->data_guard);
return status;
}
APT_DECLARE(apt_bool_t) apt_task_terminate(apt_task_t *task, apt_bool_t wait_till_complete)
{
apt_bool_t status = FALSE;
apr_thread_mutex_lock(task->data_guard);
if(task->state == TASK_STATE_START_REQUESTED || task->state == TASK_STATE_RUNNING) {
task->state = TASK_STATE_TERMINATE_REQUESTED;
}
apr_thread_mutex_unlock(task->data_guard);
if(task->state == TASK_STATE_TERMINATE_REQUESTED) {
/* raise virtual terminate method */
apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Terminate %s",task->name);
if(task->vtable.terminate) {
status = task->vtable.terminate(task);
}
if(wait_till_complete == TRUE && status == TRUE) {
apt_task_wait_till_complete(task);
}
}
return status;
}
APT_DECLARE(apt_bool_t) apt_task_wait_till_complete(apt_task_t *task)
{
if(task->thread_handle) {
apr_status_t s;
apr_thread_join(&s,task->thread_handle);
task->thread_handle = NULL;
}
return TRUE;
}
APT_DECLARE(void) apt_task_delay(apr_size_t msec)
{
apr_sleep(1000*msec);
}
APT_DECLARE(apt_task_t*) apt_task_parent_get(apt_task_t *task)
{
return task->parent_task;
}
APT_DECLARE(apr_pool_t*) apt_task_pool_get(apt_task_t *task)
{
return task->pool;
}
APT_DECLARE(void*) apt_task_object_get(apt_task_t *task)
{
return task->obj;
}
APT_DECLARE(apt_task_vtable_t*) apt_task_vtable_get(apt_task_t *task)
{
return &task->vtable;
}
APT_DECLARE(void) apt_task_name_set(apt_task_t *task, const char *name)
{
task->name = name;
}
APT_DECLARE(const char*) apt_task_name_get(apt_task_t *task)
{
return task->name;
}
APT_DECLARE(apt_task_msg_t*) apt_task_msg_get(apt_task_t *task)
{
if(task->msg_pool) {
return apt_task_msg_acquire(task->msg_pool);
}
return NULL;
}
APT_DECLARE(apt_bool_t) apt_task_msg_signal(apt_task_t *task, apt_task_msg_t *msg)
{
if(task->vtable.signal_msg) {
return task->vtable.signal_msg(task,msg);
}
return FALSE;
}
APT_DECLARE(apt_bool_t) apt_task_msg_parent_signal(apt_task_t *task, apt_task_msg_t *msg)
{
apt_task_t *parent_task = task->parent_task;
if(parent_task) {
if(parent_task->vtable.signal_msg) {
return parent_task->vtable.signal_msg(parent_task,msg);
}
}
return FALSE;
}
APT_DECLARE(apt_bool_t) apt_core_task_msg_process(apt_task_t *task, apt_task_msg_t *msg)
{
apt_bool_t running = TRUE;
switch(msg->sub_type) {
case CORE_TASK_MSG_START_COMPLETE:
{
if(!task->pending_start) {
/* error case, no pending start */
break;
}
task->pending_start--;
if(!task->pending_start) {
if(task->vtable.on_start_complete) {
task->vtable.on_start_complete(task);
}
if(task->parent_task) {
/* signal start-complete message */
apt_task_msg_signal(task->parent_task,msg);
}
}
break;
}
case CORE_TASK_MSG_TERMINATE_REQUEST:
{
apt_task_child_terminate(task);
if(!task->pending_term) {
running = FALSE;
}
break;
}
case CORE_TASK_MSG_TERMINATE_COMPLETE:
{
if(!task->pending_term) {
/* error case, no pending terminate */
break;
}
task->pending_term--;
if(!task->pending_term) {
if(task->vtable.on_terminate_complete) {
task->vtable.on_terminate_complete(task);
}
if(task->parent_task) {
/* signal terminate-complete message */
apt_task_msg_signal(task->parent_task,msg);
}
running = FALSE;
}
break;
}
default: break;
}
return running;
}
APT_DECLARE(apt_bool_t) apt_task_msg_process(apt_task_t *task, apt_task_msg_t *msg)
{
apt_bool_t running = TRUE;
if(msg->type == TASK_MSG_CORE) {
running = apt_core_task_msg_process(task,msg);
}
else {
if(task->vtable.process_msg) {
task->vtable.process_msg(task,msg);
}
}
apt_task_msg_release(msg);
return running;
}
static apt_bool_t apt_task_terminate_request(apt_task_t *task)
{
if(task->msg_pool) {
apt_task_msg_t *msg = apt_task_msg_acquire(task->msg_pool);
/* signal terminate-request message */
msg->type = TASK_MSG_CORE;
msg->sub_type = CORE_TASK_MSG_TERMINATE_REQUEST;
return apt_task_msg_signal(task,msg);
}
return FALSE;
}
APT_DECLARE(apt_bool_t) apt_task_child_start(apt_task_t *task)
{
apt_task_t *child_task = NULL;
apt_list_elem_t *elem = apt_list_first_elem_get(task->child_tasks);
task->pending_start = 0;
/* walk through the list of the child tasks and start them */
while(elem) {
child_task = apt_list_elem_object_get(elem);
if(child_task) {
if(apt_task_start(child_task) == TRUE) {
task->pending_start++;
}
}
elem = apt_list_next_elem_get(task->child_tasks,elem);
}
if(!task->pending_start) {
/* no child task to start, just raise start-complete event */
if(task->vtable.on_start_complete) {
task->vtable.on_start_complete(task);
}
if(task->parent_task) {
if(task->msg_pool) {
apt_task_msg_t *msg = apt_task_msg_acquire(task->msg_pool);
/* signal start-complete message */
msg->type = TASK_MSG_CORE;
msg->sub_type = CORE_TASK_MSG_START_COMPLETE;
apt_task_msg_signal(task->parent_task,msg);
}
}
}
return TRUE;
}
APT_DECLARE(apt_bool_t) apt_task_child_terminate(apt_task_t *task)
{
apt_task_t *child_task = NULL;
apt_list_elem_t *elem = apt_list_first_elem_get(task->child_tasks);
task->pending_term = 0;
/* walk through the list of the child tasks and terminate them */
while(elem) {
child_task = apt_list_elem_object_get(elem);
if(child_task) {
if(apt_task_terminate(child_task,FALSE) == TRUE) {
task->pending_term++;
}
}
elem = apt_list_next_elem_get(task->child_tasks,elem);
}
if(!task->pending_term) {
/* no child task to terminate, just raise terminate-complete event */
if(task->vtable.on_terminate_complete) {
task->vtable.on_terminate_complete(task);
}
if(task->parent_task) {
if(task->msg_pool) {
apt_task_msg_t *msg = apt_task_msg_acquire(task->msg_pool);
/* signal terminate-complete message */
msg->type = TASK_MSG_CORE;
msg->sub_type = CORE_TASK_MSG_TERMINATE_COMPLETE;
apt_task_msg_signal(task->parent_task,msg);
}
}
}
return TRUE;
}
static void* APR_THREAD_FUNC apt_task_run(apr_thread_t *thread_handle, void *data)
{
apt_task_t *task = data;
/* raise pre-run event */
if(task->vtable.on_pre_run) {
task->vtable.on_pre_run(task);
}
apr_thread_mutex_lock(task->data_guard);
task->state = TASK_STATE_RUNNING;
apr_thread_mutex_unlock(task->data_guard);
/* start child tasks (if any) */
apt_task_child_start(task);
/* run task */
if(task->vtable.run) {
task->vtable.run(task);
}
apr_thread_mutex_lock(task->data_guard);
task->state = TASK_STATE_IDLE;
apr_thread_mutex_unlock(task->data_guard);
/* raise post-run event */
if(task->vtable.on_post_run) {
task->vtable.on_post_run(task);
}
return NULL;
}

View File

@ -0,0 +1,103 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdlib.h>
#include "apt_task_msg.h"
/** Abstract pool of task messages to allocate task messages from */
struct apt_task_msg_pool_t {
void (*destroy)(apt_task_msg_pool_t *pool);
apt_task_msg_t* (*acquire_msg)(apt_task_msg_pool_t *pool);
void (*release_msg)(apt_task_msg_t *task_msg);
void *obj;
apr_pool_t *pool;
};
/** Dynamic allocation of messages (no actual pool exist)*/
typedef struct apt_msg_pool_dynamic_t apt_msg_pool_dynamic_t;
struct apt_msg_pool_dynamic_t {
apr_size_t size;
};
static apt_task_msg_t* dynamic_pool_acquire_msg(apt_task_msg_pool_t *task_msg_pool)
{
apt_msg_pool_dynamic_t *dynamic_pool = task_msg_pool->obj;
apt_task_msg_t *task_msg = malloc(dynamic_pool->size);
task_msg->msg_pool = task_msg_pool;
task_msg->type = TASK_MSG_USER;
task_msg->sub_type = 0;
return task_msg;
}
static void dynamic_pool_release_msg(apt_task_msg_t *task_msg)
{
if(task_msg) {
free(task_msg);
}
}
static void dynamic_pool_destroy(apt_task_msg_pool_t *task_msg_pool)
{
/* nothing to do */
}
APT_DECLARE(apt_task_msg_pool_t*) apt_task_msg_pool_create_dynamic(apr_size_t msg_size, apr_pool_t *pool)
{
apt_task_msg_pool_t *task_msg_pool = apr_palloc(pool,sizeof(apt_task_msg_pool_t));
apt_msg_pool_dynamic_t *dynamic_pool = apr_palloc(pool,sizeof(apt_msg_pool_dynamic_t));
dynamic_pool->size = msg_size + sizeof(apt_task_msg_t) - 1;
task_msg_pool->pool = pool;
task_msg_pool->obj = dynamic_pool;
task_msg_pool->acquire_msg = dynamic_pool_acquire_msg;
task_msg_pool->release_msg = dynamic_pool_release_msg;
task_msg_pool->destroy = dynamic_pool_destroy;
return task_msg_pool;
}
/** Static allocation of messages from message pool (not implemented yet) */
APT_DECLARE(apt_task_msg_pool_t*) apt_task_msg_pool_create_static(apr_size_t msg_size, apr_size_t pool_size, apr_pool_t *pool)
{
return NULL;
}
APT_DECLARE(void) apt_task_msg_pool_destroy(apt_task_msg_pool_t *msg_pool)
{
if(msg_pool->destroy) {
msg_pool->destroy(msg_pool);
}
}
APT_DECLARE(apt_task_msg_t*) apt_task_msg_acquire(apt_task_msg_pool_t *task_msg_pool)
{
if(!task_msg_pool->acquire_msg)
return NULL;
return task_msg_pool->acquire_msg(task_msg_pool);
}
APT_DECLARE(void) apt_task_msg_release(apt_task_msg_t *task_msg)
{
apt_task_msg_pool_t *task_msg_pool = task_msg->msg_pool;
if(task_msg_pool->release_msg)
task_msg_pool->release_msg(task_msg);
}

View File

@ -0,0 +1,119 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "apt_pool.h"
#include "apt_obj_list.h"
#include "apt_test_suite.h"
#include "apt_log.h"
struct apt_test_framework_t{
apr_pool_t *pool;
apt_obj_list_t *suites;
};
APT_DECLARE(apt_test_suite_t*) apt_test_suite_create(apr_pool_t *pool, const char *name,
void *obj, apt_test_f tester)
{
apt_test_suite_t *suite = apr_palloc(pool,sizeof(apt_test_suite_t));
suite->pool = pool;
apt_string_assign(&suite->name,name,pool);
suite->obj = obj;
suite->tester = tester;
return suite;
}
APT_DECLARE(apt_test_framework_t*) apt_test_framework_create()
{
apt_test_framework_t *framework;
apr_pool_t* pool = apt_pool_create();
framework = apr_palloc(pool,sizeof(apt_test_framework_t));
framework->pool = pool;
framework->suites = apt_list_create(pool);
apt_log_instance_create(APT_LOG_OUTPUT_CONSOLE,APT_PRIO_INFO,pool);
apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Create Test Framework");
return framework;
}
APT_DECLARE(void) apt_test_framework_destroy(apt_test_framework_t *framework)
{
apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"Destroy Test Framework");
apt_log_instance_destroy();
apr_pool_destroy(framework->pool);
}
APT_DECLARE(apt_bool_t) apt_test_framework_suite_add(apt_test_framework_t *framework, apt_test_suite_t *suite)
{
apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Add Test Suite [%s]",suite->name);
return (apt_list_push_back(framework->suites,suite,suite->pool) ? TRUE : FALSE);
}
APT_DECLARE(apr_pool_t*) apt_test_framework_pool_get(apt_test_framework_t *framework)
{
return framework->pool;
}
static apt_bool_t apt_test_framework_suite_run(apt_test_framework_t *framework, apt_test_suite_t *suite,
int argc, const char * const *argv)
{
apt_bool_t status = FALSE;
apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"----- Run Test Suite [%s] -----",suite->name);
if(suite->tester) {
status = suite->tester(suite,argc,argv);
}
apt_log(APT_LOG_MARK,APT_PRIO_NOTICE,"---- Status [%s] ----\n",(status == TRUE) ? "OK" : "Failure");
return status;
}
APT_DECLARE(apt_bool_t) apt_test_framework_run(apt_test_framework_t *framework, int argc, const char * const *argv)
{
apt_test_suite_t *suite = NULL;
apt_list_elem_t *elem = apt_list_first_elem_get(framework->suites);
if(argc == 1) {
apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Run All Test Suites");
/* walk through the list of test suites and run all of them */
while(elem) {
suite = apt_list_elem_object_get(elem);
if(suite) {
/* run test suite with the default arguments */
apt_test_framework_suite_run(framework,suite,0,NULL);
}
elem = apt_list_next_elem_get(framework->suites,elem);
}
}
else {
/* walk through the list of test suites find appropriate one and run it */
apt_bool_t found = FALSE;
apt_str_t name;
apt_string_set(&name,argv[1]);
while(elem) {
suite = apt_list_elem_object_get(elem);
if(suite && apt_string_compare(&suite->name,&name) == TRUE) {
found = TRUE;
break;
}
elem = apt_list_next_elem_get(framework->suites,elem);
}
if(found == TRUE) {
/* run test suite with remaining arguments */
apt_test_framework_suite_run(framework,suite,argc-2,&argv[2]);
}
else {
apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"No Such Test Suite [%s] to Run", argv[1]);
}
}
return TRUE;
}

View File

@ -0,0 +1,372 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <apr_uuid.h>
#include "apt_text_stream.h"
#define TOKEN_TRUE "true"
#define TOKEN_FALSE "false"
#define TOKEN_TRUE_LENGTH (sizeof(TOKEN_TRUE)-1)
#define TOKEN_FALSE_LENGTH (sizeof(TOKEN_FALSE)-1)
/** Navigate through the lines of the text stream (message) */
APT_DECLARE(apt_bool_t) apt_text_line_read(apt_text_stream_t *stream, apt_str_t *line)
{
char *pos = stream->pos;
const char *end = stream->text.buf + stream->text.length;
apt_bool_t eol = FALSE;
line->length = 0;
line->buf = pos;
/* while not end of stream */
while(pos < end) {
if(*pos == APT_TOKEN_CR) {
/* end of line detected */
line->length = pos - line->buf;
pos++;
if(pos < end && *pos == APT_TOKEN_LF) {
pos++;
}
eol = TRUE;
break;
}
else if(*pos == APT_TOKEN_LF) {
/* end of line detected */
line->length = pos - line->buf;
pos++;
eol = TRUE;
break;
}
pos++;
}
stream->pos = pos;
return eol;
}
/** Navigate through the headers (name:value pairs) of the text stream (message)
Valid headers are:
name:value<CRLF>
name: value<CRLF>
name: value<CRLF>
name: value<LF>
name:<CRLF> (only name, no value)
<CRLF> (empty header)
Malformed headers are:
name:value (missing end of line <CRLF>)
name<CRLF> (missing separator ':')
*/
APT_DECLARE(apt_bool_t) apt_text_header_read(apt_text_stream_t *stream, apt_pair_t *pair)
{
char *pos = stream->pos;
const char *end = stream->text.buf + stream->text.length;
apt_bool_t eol = FALSE;
apt_string_reset(&pair->name);
apt_string_reset(&pair->value);
/* while not end of stream */
while(pos < end) {
if(*pos == APT_TOKEN_CR) {
/* end of line detected */
if(pair->value.buf) {
/* set length of the value */
pair->value.length = pos - pair->value.buf;
}
pos++;
if(pos < end && *pos == APT_TOKEN_LF) {
pos++;
}
eol = TRUE;
break;
}
else if(*pos == APT_TOKEN_LF) {
/* end of line detected */
if(pair->value.buf) {
/* set length of the value */
pair->value.length = pos - pair->value.buf;
}
pos++;
eol = TRUE;
break;
}
else if(!pair->name.length) {
/* skip initial spaces and read name */
if(!pair->name.buf && *pos != APT_TOKEN_SP) {
pair->name.buf = pos;
}
if(*pos == ':') {
/* set length of the name */
pair->name.length = pos - pair->name.buf;
}
}
else if(!pair->value.length) {
/* skip initial spaces and read value */
if(!pair->value.buf && *pos != APT_TOKEN_SP) {
pair->value.buf = pos;
}
}
pos++;
}
stream->pos = pos;
/* if length == 0 && buf -> header is malformed */
return (eol && (pair->name.length || !pair->name.buf));
}
/** Navigate through the fields of the line */
APT_DECLARE(apt_bool_t) apt_text_field_read(apt_text_stream_t *stream, char separator, apt_bool_t skip_spaces, apt_str_t *field)
{
char *pos = stream->pos;
const char *end = stream->text.buf + stream->text.length;
if(skip_spaces == TRUE) {
while(pos < end && *pos == APT_TOKEN_SP) pos++;
}
field->buf = pos;
field->length = 0;
while(pos < end && *pos != separator) pos++;
field->length = pos - field->buf;
if(pos < end) {
/* skip the separator */
pos++;
}
stream->pos = pos;
return field->length ? TRUE : FALSE;
}
/** Scroll text stream */
APT_DECLARE(apt_bool_t) apt_text_stream_scroll(apt_text_stream_t *stream)
{
apr_size_t remaining_length = stream->text.buf + stream->text.length - stream->pos;
if(!remaining_length || remaining_length == stream->text.length) {
stream->pos = stream->text.buf + remaining_length;
return FALSE;
}
memmove(stream->text.buf,stream->pos,remaining_length);
stream->pos = stream->text.buf + remaining_length;
stream->text.length = remaining_length;
*stream->pos = '\0';
return TRUE;
}
/** Parse id@resource string */
APT_DECLARE(apt_bool_t) apt_id_resource_parse(const apt_str_t *str, char separator, apt_str_t *id, apt_str_t *resource, apr_pool_t *pool)
{
apt_str_t field = *str;
const char *pos = strchr(str->buf,separator);
if(!pos) {
return FALSE;
}
field.length = pos - field.buf;
if(field.length >= str->length) {
return FALSE;
}
apt_string_copy(id,&field,pool);
field.buf += field.length + 1;
field.length = str->length - (field.length + 1);
apt_string_copy(resource,&field,pool);
return TRUE;
}
/** Generate id@resource string */
APT_DECLARE(apt_bool_t) apt_id_resource_generate(const apt_str_t *id, const apt_str_t *resource, char separator, apt_str_t *str, apr_pool_t *pool)
{
apr_size_t length = id->length+resource->length+1;
char *buf = apr_palloc(pool,length+1);
memcpy(buf,id->buf,id->length);
buf[id->length] = separator;
memcpy(buf+id->length+1,resource->buf,resource->length);
buf[length] = '\0';
str->buf = buf;
str->length = length;
return TRUE;
}
/** Generate only the name ("name":) of the header */
APT_DECLARE(apt_bool_t) apt_text_header_name_generate(const apt_str_t *name, apt_text_stream_t *stream)
{
char *pos = stream->pos;
memcpy(pos,name->buf,name->length);
pos += name->length;
*pos++ = ':';
*pos++ = ' ';
stream->pos = pos;
return TRUE;
}
/** Parse name=value pair */
static apt_bool_t apt_pair_parse(apt_pair_t *pair, const apt_str_t *field, apr_pool_t *pool)
{
apt_text_stream_t stream;
stream.text = *field;
stream.pos = stream.text.buf;
/* read name */
if(apt_text_field_read(&stream,'=',TRUE,&pair->name) == FALSE) {
return FALSE;
}
/* read value */
apt_text_field_read(&stream,';',TRUE,&pair->value);
return TRUE;
}
/** Parse array of name-value pairs */
APT_DECLARE(apt_bool_t) apt_pair_array_parse(apt_pair_arr_t *arr, const apt_str_t *value, apr_pool_t *pool)
{
apt_str_t field;
apt_pair_t *pair;
apt_text_stream_t stream;
if(!arr || !value) {
return FALSE;
}
stream.text = *value;
stream.pos = stream.text.buf;
/* read name-value pairs */
while(apt_text_field_read(&stream,';',TRUE,&field) == TRUE) {
pair = apr_array_push(arr);
apt_pair_parse(pair,&field,pool);
}
return TRUE;
}
/** Generate array of name-value pairs */
APT_DECLARE(apt_bool_t) apt_pair_array_generate(apt_pair_arr_t *arr, apt_text_stream_t *stream)
{
int i;
apt_pair_t *pair;
char *pos = stream->pos;
if(!arr) {
return FALSE;
}
for(i=0; i<arr->nelts; i++) {
pair = (apt_pair_t*)arr->elts + i;
if(i != 0) {
*pos++ = ';';
}
if(pair->name.length) {
memcpy(pos,pair->name.buf,pair->name.length);
pos += pair->name.length;
if(pair->value.length) {
*pos++ = '=';
memcpy(pos,pair->value.buf,pair->value.length);
pos += pair->value.length;
}
}
}
stream->pos = pos;
return TRUE;
}
/** Parse boolean-value */
APT_DECLARE(apt_bool_t) apt_boolean_value_parse(const apt_str_t *str, apt_bool_t *value)
{
if(!str->buf) {
return FALSE;
}
if(strncasecmp(str->buf,TOKEN_TRUE,TOKEN_TRUE_LENGTH) == 0) {
*value = TRUE;
return TRUE;
}
if(strncasecmp(str->buf,TOKEN_FALSE,TOKEN_FALSE_LENGTH) == 0) {
*value = FALSE;
return TRUE;
}
return FALSE;
}
/** Generate boolean-value */
APT_DECLARE(apt_bool_t) apt_boolean_value_generate(apt_bool_t value, apt_text_stream_t *stream)
{
if(value == TRUE) {
memcpy(stream->pos,TOKEN_TRUE,TOKEN_TRUE_LENGTH);
stream->pos += TOKEN_TRUE_LENGTH;
}
else {
memcpy(stream->pos,TOKEN_FALSE,TOKEN_FALSE_LENGTH);
stream->pos += TOKEN_FALSE_LENGTH;
}
return TRUE;
}
/** Generate value plus the length (number of digits) of the value itself. */
APT_DECLARE(apt_bool_t) apt_var_length_value_generate(apr_size_t *value, apr_size_t max_count, apt_str_t *str)
{
/* (N >= (10^M-M)) ? N+M+1 : N+M */
apr_size_t temp;
apr_size_t count; /* M */
apr_size_t bounds; /* 10^M */
int length;
/* calculate count */
temp = *value;
count = 0;
do{count++; temp /= 10;} while(temp);
/* calculate bounds */
temp = count;
bounds = 1;
do{bounds *= 10; temp--;} while(temp);
if(*value >= bounds - count) {
count++;
}
*value += count;
if(count > max_count) {
return FALSE;
}
str->length = 0;
length = sprintf(str->buf, "%"APR_SIZE_T_FMT, *value);
if(length <= 0) {
return FALSE;
}
str->length = length;
return TRUE;
}
/** Generate unique identifier (hex string) */
APT_DECLARE(apt_bool_t) apt_unique_id_generate(apt_str_t *id, apr_size_t length, apr_pool_t *pool)
{
char *hex_str;
apr_size_t i;
apr_size_t count;
apr_uuid_t uuid;
apr_uuid_get(&uuid);
hex_str = apr_palloc(pool,length+1);
count = length / 2;
if(count > sizeof(uuid)) {
count = sizeof(uuid);
}
for(i=0; i<count; i++) {
sprintf(hex_str+i*2,"%02x",uuid.data[i]);
}
hex_str[length] = '\0';
id->buf = hex_str;
id->length = length;
return TRUE;
}

View File

@ -0,0 +1,63 @@
MAINTAINERCLEANFILES = Makefile.in
INCLUDES = -I$(top_srcdir)/libs/mpf/codecs \
-I$(top_srcdir)/libs/mpf/include \
-I$(top_srcdir)/libs/apr-toolkit/include \
$(UNIMRCP_APR_INCLUDES) $(UNIMRCP_APU_INCLUDES)
noinst_LTLIBRARIES = libmpf.la
include_HEADERS = codecs/g711/g711.h \
include/mpf.h \
include/mpf_activity_detector.h \
include/mpf_audio_file_descriptor.h \
include/mpf_audio_file_stream.h \
include/mpf_bridge.h \
include/mpf_buffer.h \
include/mpf_codec.h \
include/mpf_codec_descriptor.h \
include/mpf_codec_manager.h \
include/mpf_context.h \
include/mpf_engine.h \
include/mpf_frame.h \
include/mpf_message.h \
include/mpf_object.h \
include/mpf_stream.h \
include/mpf_stream_mode.h \
include/mpf_termination.h \
include/mpf_rtp_termination_factory.h \
include/mpf_file_termination_factory.h \
include/mpf_timer.h \
include/mpf_types.h \
include/mpf_encoder.h \
include/mpf_decoder.h \
include/mpf_jitter_buffer.h \
include/mpf_rtp_header.h \
include/mpf_rtp_descriptor.h \
include/mpf_rtp_stream.h \
include/mpf_rtp_stat.h \
include/mpf_rtp_defs.h \
include/mpf_rtp_attribs.h \
include/mpf_media_descriptor.h \
include/mpf_user.h
libmpf_la_SOURCES = codecs/g711/g711.c \
src/mpf_activity_detector.c \
src/mpf_audio_file_stream.c \
src/mpf_bridge.c \
src/mpf_buffer.c \
src/mpf_codec_descriptor.c \
src/mpf_codec_g711.c \
src/mpf_codec_linear.c \
src/mpf_codec_manager.c \
src/mpf_context.c \
src/mpf_engine.c \
src/mpf_termination.c \
src/mpf_rtp_termination_factory.c \
src/mpf_file_termination_factory.c \
src/mpf_timer.c \
src/mpf_encoder.c \
src/mpf_decoder.c \
src/mpf_jitter_buffer.c \
src/mpf_rtp_stream.c \
src/mpf_rtp_attribs.c

View File

@ -0,0 +1,91 @@
/*
* SpanDSP - a series of DSP components for telephony
*
* g711.c - A-law and u-law transcoding routines
*
* Written by Steve Underwood <steveu@coppice.org>
*
* Copyright (C) 2006 Steve Underwood
*
* Despite my general liking of the GPL, I place this code in the
* public domain for the benefit of all mankind - even the slimy
* ones who might try to proprietize my work and use it to my
* detriment.
*
*/
/*! \file */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#ifndef _MSC_VER
#include <inttypes.h>
#ifdef HAVE_TGMATH_H
#include <tgmath.h>
#endif
#endif
#include "g711.h"
/* Copied from the CCITT G.711 specification */
static const uint8_t ulaw_to_alaw_table[256] =
{
42, 43, 40, 41, 46, 47, 44, 45, 34, 35, 32, 33, 38, 39, 36, 37,
58, 59, 56, 57, 62, 63, 60, 61, 50, 51, 48, 49, 54, 55, 52, 53,
10, 11, 8, 9, 14, 15, 12, 13, 2, 3, 0, 1, 6, 7, 4, 26,
27, 24, 25, 30, 31, 28, 29, 18, 19, 16, 17, 22, 23, 20, 21, 106,
104, 105, 110, 111, 108, 109, 98, 99, 96, 97, 102, 103, 100, 101, 122, 120,
126, 127, 124, 125, 114, 115, 112, 113, 118, 119, 116, 117, 75, 73, 79, 77,
66, 67, 64, 65, 70, 71, 68, 69, 90, 91, 88, 89, 94, 95, 92, 93,
82, 82, 83, 83, 80, 80, 81, 81, 86, 86, 87, 87, 84, 84, 85, 85,
170, 171, 168, 169, 174, 175, 172, 173, 162, 163, 160, 161, 166, 167, 164, 165,
186, 187, 184, 185, 190, 191, 188, 189, 178, 179, 176, 177, 182, 183, 180, 181,
138, 139, 136, 137, 142, 143, 140, 141, 130, 131, 128, 129, 134, 135, 132, 154,
155, 152, 153, 158, 159, 156, 157, 146, 147, 144, 145, 150, 151, 148, 149, 234,
232, 233, 238, 239, 236, 237, 226, 227, 224, 225, 230, 231, 228, 229, 250, 248,
254, 255, 252, 253, 242, 243, 240, 241, 246, 247, 244, 245, 203, 201, 207, 205,
194, 195, 192, 193, 198, 199, 196, 197, 218, 219, 216, 217, 222, 223, 220, 221,
210, 210, 211, 211, 208, 208, 209, 209, 214, 214, 215, 215, 212, 212, 213, 213
};
/* These transcoding tables are copied from the CCITT G.711 specification. To achieve
optimal results, do not change them. */
static const uint8_t alaw_to_ulaw_table[256] =
{
42, 43, 40, 41, 46, 47, 44, 45, 34, 35, 32, 33, 38, 39, 36, 37,
57, 58, 55, 56, 61, 62, 59, 60, 49, 50, 47, 48, 53, 54, 51, 52,
10, 11, 8, 9, 14, 15, 12, 13, 2, 3, 0, 1, 6, 7, 4, 5,
26, 27, 24, 25, 30, 31, 28, 29, 18, 19, 16, 17, 22, 23, 20, 21,
98, 99, 96, 97, 102, 103, 100, 101, 93, 93, 92, 92, 95, 95, 94, 94,
116, 118, 112, 114, 124, 126, 120, 122, 106, 107, 104, 105, 110, 111, 108, 109,
72, 73, 70, 71, 76, 77, 74, 75, 64, 65, 63, 63, 68, 69, 66, 67,
86, 87, 84, 85, 90, 91, 88, 89, 79, 79, 78, 78, 82, 83, 80, 81,
170, 171, 168, 169, 174, 175, 172, 173, 162, 163, 160, 161, 166, 167, 164, 165,
185, 186, 183, 184, 189, 190, 187, 188, 177, 178, 175, 176, 181, 182, 179, 180,
138, 139, 136, 137, 142, 143, 140, 141, 130, 131, 128, 129, 134, 135, 132, 133,
154, 155, 152, 153, 158, 159, 156, 157, 146, 147, 144, 145, 150, 151, 148, 149,
226, 227, 224, 225, 230, 231, 228, 229, 221, 221, 220, 220, 223, 223, 222, 222,
244, 246, 240, 242, 252, 254, 248, 250, 234, 235, 232, 233, 238, 239, 236, 237,
200, 201, 198, 199, 204, 205, 202, 203, 192, 193, 191, 191, 196, 197, 194, 195,
214, 215, 212, 213, 218, 219, 216, 217, 207, 207, 206, 206, 210, 211, 208, 209
};
uint8_t alaw_to_ulaw(uint8_t alaw)
{
return alaw_to_ulaw_table[alaw];
}
/*- End of function --------------------------------------------------------*/
uint8_t ulaw_to_alaw(uint8_t ulaw)
{
return ulaw_to_alaw_table[ulaw];
}
/*- End of function --------------------------------------------------------*/
/*- End of file ------------------------------------------------------------*/

View File

@ -0,0 +1,381 @@
/*
* SpanDSP - a series of DSP components for telephony
*
* g711.h - In line A-law and u-law conversion routines
*
* Written by Steve Underwood <steveu@coppice.org>
*
* Copyright (C) 2001 Steve Underwood
*
* Despite my general liking of the GPL, I place this code in the
* public domain for the benefit of all mankind - even the slimy
* ones who might try to proprietize my work and use it to my
* detriment.
*
*/
/*! \file */
/*! \page g711_page A-law and mu-law handling
Lookup tables for A-law and u-law look attractive, until you consider the impact
on the CPU cache. If it causes a substantial area of your processor cache to get
hit too often, cache sloshing will severely slow things down. The main reason
these routines are slow in C, is the lack of direct access to the CPU's "find
the first 1" instruction. A little in-line assembler fixes that, and the
conversion routines can be faster than lookup tables, in most real world usage.
A "find the first 1" instruction is available on most modern CPUs, and is a
much underused feature.
If an assembly language method of bit searching is not available, these routines
revert to a method that can be a little slow, so the cache thrashing might not
seem so bad :(
Feel free to submit patches to add fast "find the first 1" support for your own
favourite processor.
Look up tables are used for transcoding between A-law and u-law, since it is
difficult to achieve the precise transcoding procedure laid down in the G.711
specification by other means.
*/
#if !defined(_G711_H_)
#define _G711_H_
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _MSC_VER
#ifndef __inline__
#define __inline__ __inline
#endif
typedef unsigned __int8 uint8_t;
typedef __int16 int16_t;
typedef __int32 int32_t;
typedef unsigned __int16 uint16_t;
#endif
#if defined(__i386__)
/*! \brief Find the bit position of the highest set bit in a word
\param bits The word to be searched
\return The bit number of the highest set bit, or -1 if the word is zero. */
static __inline__ int top_bit(unsigned int bits)
{
int res;
__asm__ __volatile__(" movl $-1,%%edx;\n"
" bsrl %%eax,%%edx;\n"
: "=d" (res)
: "a" (bits));
return res;
}
/*- End of function --------------------------------------------------------*/
/*! \brief Find the bit position of the lowest set bit in a word
\param bits The word to be searched
\return The bit number of the lowest set bit, or -1 if the word is zero. */
static __inline__ int bottom_bit(unsigned int bits)
{
int res;
__asm__ __volatile__(" movl $-1,%%edx;\n"
" bsfl %%eax,%%edx;\n"
: "=d" (res)
: "a" (bits));
return res;
}
/*- End of function --------------------------------------------------------*/
#elif defined(__x86_64__)
static __inline__ int top_bit(unsigned int bits)
{
int res;
__asm__ __volatile__(" movq $-1,%%rdx;\n"
" bsrq %%rax,%%rdx;\n"
: "=d" (res)
: "a" (bits));
return res;
}
/*- End of function --------------------------------------------------------*/
static __inline__ int bottom_bit(unsigned int bits)
{
int res;
__asm__ __volatile__(" movq $-1,%%rdx;\n"
" bsfq %%rax,%%rdx;\n"
: "=d" (res)
: "a" (bits));
return res;
}
/*- End of function --------------------------------------------------------*/
#else
static __inline__ int top_bit(unsigned int bits)
{
int i;
if (bits == 0)
return -1;
i = 0;
if (bits & 0xFFFF0000)
{
bits &= 0xFFFF0000;
i += 16;
}
if (bits & 0xFF00FF00)
{
bits &= 0xFF00FF00;
i += 8;
}
if (bits & 0xF0F0F0F0)
{
bits &= 0xF0F0F0F0;
i += 4;
}
if (bits & 0xCCCCCCCC)
{
bits &= 0xCCCCCCCC;
i += 2;
}
if (bits & 0xAAAAAAAA)
{
bits &= 0xAAAAAAAA;
i += 1;
}
return i;
}
/*- End of function --------------------------------------------------------*/
static __inline__ int bottom_bit(unsigned int bits)
{
int i;
if (bits == 0)
return -1;
i = 32;
if (bits & 0x0000FFFF)
{
bits &= 0x0000FFFF;
i -= 16;
}
if (bits & 0x00FF00FF)
{
bits &= 0x00FF00FF;
i -= 8;
}
if (bits & 0x0F0F0F0F)
{
bits &= 0x0F0F0F0F;
i -= 4;
}
if (bits & 0x33333333)
{
bits &= 0x33333333;
i -= 2;
}
if (bits & 0x55555555)
{
bits &= 0x55555555;
i -= 1;
}
return i;
}
/*- End of function --------------------------------------------------------*/
#endif
/* N.B. It is tempting to use look-up tables for A-law and u-law conversion.
* However, you should consider the cache footprint.
*
* A 64K byte table for linear to x-law and a 512 byte table for x-law to
* linear sound like peanuts these days, and shouldn't an array lookup be
* real fast? No! When the cache sloshes as badly as this one will, a tight
* calculation may be better. The messiest part is normally finding the
* segment, but a little inline assembly can fix that on an i386, x86_64 and
* many other modern processors.
*/
/*
* Mu-law is basically as follows:
*
* Biased Linear Input Code Compressed Code
* ------------------------ ---------------
* 00000001wxyza 000wxyz
* 0000001wxyzab 001wxyz
* 000001wxyzabc 010wxyz
* 00001wxyzabcd 011wxyz
* 0001wxyzabcde 100wxyz
* 001wxyzabcdef 101wxyz
* 01wxyzabcdefg 110wxyz
* 1wxyzabcdefgh 111wxyz
*
* Each biased linear code has a leading 1 which identifies the segment
* number. The value of the segment number is equal to 7 minus the number
* of leading 0's. The quantization interval is directly available as the
* four bits wxyz. * The trailing bits (a - h) are ignored.
*
* Ordinarily the complement of the resulting code word is used for
* transmission, and so the code word is complemented before it is returned.
*
* For further information see John C. Bellamy's Digital Telephony, 1982,
* John Wiley & Sons, pps 98-111 and 472-476.
*/
//#define ULAW_ZEROTRAP /* turn on the trap as per the MIL-STD */
#define ULAW_BIAS 0x84 /* Bias for linear code. */
/*! \brief Encode a linear sample to u-law
\param linear The sample to encode.
\return The u-law value.
*/
static __inline__ uint8_t linear_to_ulaw(int linear)
{
uint8_t u_val;
int mask;
int seg;
/* Get the sign and the magnitude of the value. */
if (linear < 0)
{
linear = ULAW_BIAS - linear;
mask = 0x7F;
}
else
{
linear = ULAW_BIAS + linear;
mask = 0xFF;
}
seg = top_bit(linear | 0xFF) - 7;
/*
* Combine the sign, segment, quantization bits,
* and complement the code word.
*/
if (seg >= 8)
u_val = (uint8_t) (0x7F ^ mask);
else
u_val = (uint8_t) (((seg << 4) | ((linear >> (seg + 3)) & 0xF)) ^ mask);
#ifdef ULAW_ZEROTRAP
/* Optional ITU trap */
if (u_val == 0)
u_val = 0x02;
#endif
return u_val;
}
/*- End of function --------------------------------------------------------*/
/*! \brief Decode an u-law sample to a linear value.
\param ulaw The u-law sample to decode.
\return The linear value.
*/
static __inline__ int16_t ulaw_to_linear(uint8_t ulaw)
{
int t;
/* Complement to obtain normal u-law value. */
ulaw = ~ulaw;
/*
* Extract and bias the quantization bits. Then
* shift up by the segment number and subtract out the bias.
*/
t = (((ulaw & 0x0F) << 3) + ULAW_BIAS) << (((int) ulaw & 0x70) >> 4);
return (int16_t) ((ulaw & 0x80) ? (ULAW_BIAS - t) : (t - ULAW_BIAS));
}
/*- End of function --------------------------------------------------------*/
/*
* A-law is basically as follows:
*
* Linear Input Code Compressed Code
* ----------------- ---------------
* 0000000wxyza 000wxyz
* 0000001wxyza 001wxyz
* 000001wxyzab 010wxyz
* 00001wxyzabc 011wxyz
* 0001wxyzabcd 100wxyz
* 001wxyzabcde 101wxyz
* 01wxyzabcdef 110wxyz
* 1wxyzabcdefg 111wxyz
*
* For further information see John C. Bellamy's Digital Telephony, 1982,
* John Wiley & Sons, pps 98-111 and 472-476.
*/
#define ALAW_AMI_MASK 0x55
/*! \brief Encode a linear sample to A-law
\param linear The sample to encode.
\return The A-law value.
*/
static __inline__ uint8_t linear_to_alaw(int linear)
{
int mask;
int seg;
if (linear >= 0)
{
/* Sign (bit 7) bit = 1 */
mask = ALAW_AMI_MASK | 0x80;
}
else
{
/* Sign (bit 7) bit = 0 */
mask = ALAW_AMI_MASK;
linear = -linear - 8;
}
/* Convert the scaled magnitude to segment number. */
seg = top_bit(linear | 0xFF) - 7;
if (seg >= 8)
{
if (linear >= 0)
{
/* Out of range. Return maximum value. */
return (uint8_t) (0x7F ^ mask);
}
/* We must be just a tiny step below zero */
return (uint8_t) (0x00 ^ mask);
}
/* Combine the sign, segment, and quantization bits. */
return (uint8_t) (((seg << 4) | ((linear >> ((seg) ? (seg + 3) : 4)) & 0x0F)) ^ mask);
}
/*- End of function --------------------------------------------------------*/
/*! \brief Decode an A-law sample to a linear value.
\param alaw The A-law sample to decode.
\return The linear value.
*/
static __inline__ int16_t alaw_to_linear(uint8_t alaw)
{
int i;
int seg;
alaw ^= ALAW_AMI_MASK;
i = ((alaw & 0x0F) << 4);
seg = (((int) alaw & 0x70) >> 4);
if (seg)
i = (i + 0x108) << (seg - 1);
else
i += 8;
return (int16_t) ((alaw & 0x80) ? i : -i);
}
/*- End of function --------------------------------------------------------*/
/*! \brief Transcode from A-law to u-law, using the procedure defined in G.711.
\param alaw The A-law sample to transcode.
\return The best matching u-law value.
*/
uint8_t alaw_to_ulaw(uint8_t alaw);
/*! \brief Transcode from u-law to A-law, using the procedure defined in G.711.
\param alaw The u-law sample to transcode.
\return The best matching A-law value.
*/
uint8_t ulaw_to_alaw(uint8_t ulaw);
#ifdef __cplusplus
}
#endif
#endif
/*- End of file ------------------------------------------------------------*/

View File

@ -0,0 +1,42 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPF_H__
#define __MPF_H__
/**
* @file mpf.h
* @brief Media Processing Framework Definitions
*/
#include <apt.h>
/** lib export/import defines (win32) */
#ifdef WIN32
#ifdef MPF_STATIC_LIB
#define MPF_DECLARE(type) type __stdcall
#else
#ifdef MPF_LIB_EXPORT
#define MPF_DECLARE(type) __declspec(dllexport) type __stdcall
#else
#define MPF_DECLARE(type) __declspec(dllimport) type __stdcall
#endif
#endif
#else
#define MPF_DECLARE(type) type
#endif
#endif /*__MPF_H__*/

View File

@ -0,0 +1,60 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPF_ACTIVITY_DETECTOR_H__
#define __MPF_ACTIVITY_DETECTOR_H__
/**
* @file mpf_activity_detector.h
* @brief MPF Voice Activity Detector
*/
#include "mpf_frame.h"
#include "mpf_codec.h"
APT_BEGIN_EXTERN_C
/** Opaque (voice) activity detector */
typedef struct mpf_activity_detector_t mpf_activity_detector_t;
/** Events of activity detector */
typedef enum {
MPF_DETECTOR_EVENT_NONE, /**< no event occurred */
MPF_DETECTOR_EVENT_ACTIVITY, /**< voice activity (transition to activity from inactivity state) */
MPF_DETECTOR_EVENT_INACTIVITY, /**< voice inactivity (transition to inactivity from activity state) */
MPF_DETECTOR_EVENT_NOINPUT /**< noinput event occurred */
} mpf_detector_event_e;
/** Create activity detector */
MPF_DECLARE(mpf_activity_detector_t*) mpf_activity_detector_create(apr_pool_t *pool);
/** Set threshold of voice activity (silence) level */
MPF_DECLARE(void) mpf_activity_detector_level_set(mpf_activity_detector_t *detector, apr_size_t level_threshold);
/** Set noinput timeout */
MPF_DECLARE(void) mpf_activity_detector_noinput_timeout_set(mpf_activity_detector_t *detector, apr_size_t noinput_timeout);
/** Set transition complete timeout */
MPF_DECLARE(void) mpf_activity_detector_complete_timeout_set(mpf_activity_detector_t *detector, apr_size_t complete_timeout);
/** Process current frame, return detected event if any */
MPF_DECLARE(mpf_detector_event_e) mpf_activity_detector_process(mpf_activity_detector_t *detector, const mpf_frame_t *frame);
APT_END_EXTERN_C
#endif /*__MPF_ACTIVITY_DETECTOR_H__*/

View File

@ -0,0 +1,55 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPF_AUDIO_FILE_DESCRIPTOR_H__
#define __MPF_AUDIO_FILE_DESCRIPTOR_H__
/**
* @file mpf_audio_file_descriptor.h
* @brief MPF Audio File Descriptor
*/
#include <stdio.h>
#include "mpf_stream_mode.h"
#include "mpf_codec_descriptor.h"
APT_BEGIN_EXTERN_C
/** FILE_READER is defined as STREAM_MODE_RECEIVE */
#define FILE_READER STREAM_MODE_RECEIVE
/** FILE_WRITER is defined as STREAM_MODE_SEND */
#define FILE_WRITER STREAM_MODE_SEND
/** Audio file descriptor declaration */
typedef struct mpf_audio_file_descriptor_t mpf_audio_file_descriptor_t;
/** Audio file descriptor */
struct mpf_audio_file_descriptor_t {
/** Indicate what descriptor for (reader and/or write) */
mpf_stream_mode_e mask;
/** Codec descriptor to use for audio file read/write */
mpf_codec_descriptor_t codec_descriptor;
/** File handle to read audio stream */
FILE *read_handle;
/** File handle to write audio stream */
FILE *write_handle;
/** Max size of file */
apr_size_t max_write_size;
};
APT_END_EXTERN_C
#endif /*__MPF_AUDIO_FILE_DESCRIPTOR_H__*/

View File

@ -0,0 +1,46 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPF_AUDIO_FILE_STREAM_H__
#define __MPF_AUDIO_FILE_STREAM_H__
/**
* @file mpf_audio_file_stream.h
* @brief MPF Audio FIle Stream
*/
#include "mpf_stream.h"
#include "mpf_audio_file_descriptor.h"
APT_BEGIN_EXTERN_C
/**
* Create file stream.
* @param termination the back pointer to hold
* @param pool the pool to allocate memory from
*/
MPF_DECLARE(mpf_audio_stream_t*) mpf_file_stream_create(mpf_termination_t *termination, apr_pool_t *pool);
/**
* Modify file stream.
* @param stream file stream to modify
* @param descriptor the descriptor to modify stream according
*/
MPF_DECLARE(apt_bool_t) mpf_file_stream_modify(mpf_audio_stream_t *stream, mpf_audio_file_descriptor_t *descriptor);
APT_END_EXTERN_C
#endif /*__MPF_AUDIO_FILE_STREAM_H__*/

View File

@ -0,0 +1,48 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPF_BRIDGE_H__
#define __MPF_BRIDGE_H__
/**
* @file mpf_bridge.h
* @brief MPF Stream Bridge
*/
#include "mpf_object.h"
APT_BEGIN_EXTERN_C
/**
* Create bridge of audio streams.
* @param source the source audio stream
* @param sink the sink audio stream
* @param pool the pool to allocate memory from
*/
MPF_DECLARE(mpf_object_t*) mpf_bridge_create(mpf_audio_stream_t *source, mpf_audio_stream_t *sink, apr_pool_t *pool);
/**
* Create bridge of audio streams with the same codec descriptor.
* @param source the source audio stream
* @param sink the sink audio stream
* @param pool the pool to allocate memory from
*/
MPF_DECLARE(mpf_object_t*) mpf_null_bridge_create(mpf_audio_stream_t *source, mpf_audio_stream_t *sink, apr_pool_t *pool);
APT_END_EXTERN_C
#endif /*__MPF_BRIDGE_H__*/

View File

@ -0,0 +1,56 @@
/*
* Copyright 2008 Arsen Chaloyan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MPF_BUFFER_H__
#define __MPF_BUFFER_H__
/**
* @file mpf_buffer.h
* @brief Buffer of Media Chunks
*/
#include "mpf_frame.h"
APT_BEGIN_EXTERN_C
/** Opaque media buffer declaration */
typedef struct mpf_buffer_t mpf_buffer_t;
/** Create buffer */
mpf_buffer_t* mpf_buffer_create(apr_pool_t *pool);
/** Destroy buffer */
void mpf_buffer_destroy(mpf_buffer_t *buffer);
/** Restart buffer */
apt_bool_t mpf_buffer_restart(mpf_buffer_t *buffer);
/** Write audio chunk to buffer */
apt_bool_t mpf_buffer_audio_write(mpf_buffer_t *buffer, void *data, apr_size_t size);
/** Write event to buffer */
apt_bool_t mpf_buffer_event_write(mpf_buffer_t *buffer, mpf_frame_type_e event_type);
/** Read media frame from buffer */
apt_bool_t mpf_buffer_frame_read(mpf_buffer_t *buffer, mpf_frame_t *media_frame);
/** Get size of buffer **/
apr_size_t mpf_buffer_get_size(mpf_buffer_t *buffer);
APT_END_EXTERN_C
#endif /*__MPF_BUFFER_H__*/

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