提交 e27e424f authored 作者: Steven Ayre's avatar Steven Ayre

add freeswitch-mod-skel

上级 47c39fbd
#!/bin/sh
MODULE=$1
cd $MODULE && dpkg-buildpackage -b -uc
# This serves no purpose except to organise files within src/
# Since %: doesn't handle 'make' with no targets
.DEFAULT: DEFAULT
DEFAULT:
cd src && make
%:
cd src && make $@
debian/README.source
\ No newline at end of file
CC = gcc
CFLAGS = -fPIC -g -ggdb -I../common `pkg-config --cflags freeswitch`
LDFLAGS = `pkg-config --libs freeswitch`
.PHONY: all
all: $(MODNAME)
$(MODNAME): $(MODOBJ)
$(CC) -shared -o $@ $(MODOBJ) $(LDFLAGS) $(MODLDFLAGS)
.c.o: $<
$(CC) $(CFLAGS) $(MODCFLAGS) -o $@ -c $<
.PHONY: test
test:
# Unimplemented
/bin/true
.PHONY: clean distclean
clean:
rm -f $(MODNAME) $(MODOBJ)
distclean: clean
.PHONY: install uninstall
install: $(MODNAME)
install -d -m755 -o0 -g0 $(DESTDIR)/usr/lib/freeswitch/mod
install -m644 -o0 -g0 $(MODNAME) $(DESTDIR)/usr/lib/freeswitch/mod
uninstall:
rm -f $(DESTDIR)/usr/lib/freeswitch/mod/$(MODNAME)
Purpose
=======
This buildsystem allows you to build your own modules and distribute them as
FreeSWITCH modules.
This can make installation / updates simpler and easier to manage:
* You can distribute your modules via your own APT repository, using
apt-get to install.
* Package dependancies mean apt will automatically install any
required dependancies.
* All production servers can easily use the same tested version.
* Servers can notify you if an update is available (apticron)
* Files are installed to standard paths and known about by the dpkg/apt
system - letting you use standard tools to inspect, verify and remove files.
* Module can be built separately to FreeSWITCH. This can significantly reduce
build time. This is done by building against libfreeswitch-dev.
Naming your module
==================
Update these files:
* debian/control
* debian/changelog (use dch after the initial edit)
* debian/rules
* src/Makefile
* src/mod_skel.c (use your own module name for the filename,
this must match src/Makefile)
Dependancies
============
Library package compile-time dependancies are defined in debian/control in
the Build-Depends field (these should be the -dev packages).
You do not need to depend on the runtime library itself - ${shlibs:Depends}
will expand to add these automatically.
To build the module against the library edit src/Makefile to set the
MODCFLAGS and MODLDFLAGS variables... pkg-config can be useful for this.
Makefile options
================
src/Makefile controls the build
Required:
MODNAME - the name of the module to build
MODOBJ - the list of .o object files to build (space separated)
If your code is spread across multiple .c files list all their equivalent
module files in MODOBJ - for example use 'mod_skel.o common.o util.o db.o'
if your code files are 'mod_skel.c common.c util.c db.c'
Optional:
MODCFLAGS
MODLDFLAGS
This example buildsystem assumes C as the development language.
New versions
============
Update debian/changelog to reflect the new version number and the changes
in that release. This is needed each time you release a version, to
differentiate it from those before.
The 'dch' tool in the 'devscripts' package is useful for editing this file.
Building your module
====================
$ dpkg-buildpackage -b
This will give you three files in the parent directory:
* ../freeswitch-mod-skel_$version.changes
* Used to upload to a repository
* ../freeswitch-mod-skel_$version.deb
* The module
* ../freeswitch-mod-skel-dbg_$version.deb
* Debug symbols, used for debugging in gdb
You may also choose to sign the package with a PGP key - see 'man dpkg-buildpackage'
More complex modules
====================
This is only a simple buildsystem. You may want to install many more files,
or build multiple modules from a single codebase.
Both of these are easily achievable, but outside of the scope of this example.
For further information read the Debian Policy Manual:
* http://www.debian.org/doc/debian-policy/
freeswitch-mod-skel (1.0) wheezy; urgency=low
* Initial release.
* You should update this file with the 'dch' tool for each release.
-- The Maintainer <yourname@example.com> Mon, 01 Jan 2014 00:00:00 +0000
Source: freeswitch-mod-skel
Section: comm
Priority: optional
Maintainer: The Maintainer <yourname@example.com>
Build-Depends: debhelper (>= 9), build-essential, pkg-config, libfreeswitch-dev (>= 1.2)
Standards-Version: 3.9.3
Package: freeswitch-mod-skel
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, freeswitch
Description: FreeSWITCH XYZ module
XYZ module for FreeSWITCH.
.
This module provides X, Y & Z.
Package: freeswitch-mod-skel-dbg
Architecture: any
Depends: freeswitch-mod-skel (= ${binary:Version}), ${misc:Depends}
Description: FreeSWITCH XYZ module
XYZ module for FreeSWITCH.
.
This module provides debugging symbols for freeswitch-mod-skel
#!/usr/bin/make -f
export DH_VERBOSE=1
TMP:=$(CURDIR)/debian/tmp/
%:
dh $@
.PHONY: override_dh_strip
override_dh_strip:
dh_strip -pfreeswitch-mod-skel --dbg-package=freeswitch-mod-skel-dbg --keep-debug
MODNAME = mod_skel.so
MODOBJ = mod_skel.o
include ../build.rules
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2012, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
*
* The Initial Developer of the Original Code is
* Anthony Minessale II <anthm@freeswitch.org>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Anthony Minessale II <anthm@freeswitch.org>
* Neal Horman <neal at wanlink dot com>
*
*
* mod_skel.c -- Framework Demo Module
*
*/
#include <switch.h>
/* Prototypes */
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_skel_shutdown);
SWITCH_MODULE_RUNTIME_FUNCTION(mod_skel_runtime);
SWITCH_MODULE_LOAD_FUNCTION(mod_skel_load);
/* SWITCH_MODULE_DEFINITION(name, load, shutdown, runtime)
* Defines a switch_loadable_module_function_table_t and a static const char[] modname
*/
SWITCH_MODULE_DEFINITION(mod_skel, mod_skel_load, mod_skel_shutdown, NULL);
typedef enum {
CODEC_NEGOTIATION_GREEDY = 1,
CODEC_NEGOTIATION_GENEROUS = 2,
CODEC_NEGOTIATION_EVIL = 3
} codec_negotiation_t;
static struct {
char *codec_negotiation_str;
codec_negotiation_t codec_negotiation;
switch_bool_t sip_trace;
int integer;
} globals;
static switch_status_t config_callback_siptrace(switch_xml_config_item_t *data, switch_config_callback_type_t callback_type, switch_bool_t changed)
{
switch_bool_t value = *(switch_bool_t *) data->ptr;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "In siptrace callback: value %s changed %s\n",
value ? "true" : "false", changed ? "true" : "false");
/*
if ((callback_type == CONFIG_LOG || callback_type == CONFIG_RELOAD) && changed) {
nua_set_params(((sofia_profile_t*)data->functiondata)->nua, TPTAG_LOG(value), TAG_END());
}
*/
return SWITCH_STATUS_SUCCESS;
}
static switch_xml_config_string_options_t config_opt_codec_negotiation = { NULL, 0, "greedy|generous|evil" };
/* enforce_min, min, enforce_max, max */
static switch_xml_config_int_options_t config_opt_integer = { SWITCH_TRUE, 0, SWITCH_TRUE, 10 };
static switch_xml_config_enum_item_t config_opt_codec_negotiation_enum[] = {
{"greedy", CODEC_NEGOTIATION_GREEDY},
{"generous", CODEC_NEGOTIATION_GENEROUS},
{"evil", CODEC_NEGOTIATION_EVIL},
{NULL, 0}
};
static switch_xml_config_item_t instructions[] = {
/* parameter name type reloadable pointer default value options structure */
SWITCH_CONFIG_ITEM("codec-negotiation-str", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &globals.codec_negotiation_str, "greedy",
&config_opt_codec_negotiation,
"greedy|generous|evil", "Specifies the codec negotiation scheme to be used."),
SWITCH_CONFIG_ITEM("codec-negotiation", SWITCH_CONFIG_ENUM, CONFIG_RELOADABLE, &globals.codec_negotiation, (void *) CODEC_NEGOTIATION_GREEDY,
&config_opt_codec_negotiation_enum,
"greedy|generous|evil", "Specifies the codec negotiation scheme to be used."),
SWITCH_CONFIG_ITEM_CALLBACK("sip-trace", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE, &globals.sip_trace, (void *) SWITCH_FALSE,
(switch_xml_config_callback_t) config_callback_siptrace, NULL,
"yes|no", "If enabled, print out sip messages on the console."),
SWITCH_CONFIG_ITEM("integer", SWITCH_CONFIG_INT, CONFIG_RELOADABLE, &globals.integer, (void *) 100, &config_opt_integer,
NULL, NULL),
SWITCH_CONFIG_ITEM_END()
};
static switch_status_t do_config(switch_bool_t reload)
{
memset(&globals, 0, sizeof(globals));
if (switch_xml_config_parse_module_settings("skel.conf", reload, instructions) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Could not open skel.conf\n");
return SWITCH_STATUS_FALSE;
}
return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_API(skel_function)
{
switch_event_t *event;
unsigned char frame_buffer[8192] = {0};
do_config(SWITCH_TRUE);
if (switch_event_create(&event, SWITCH_EVENT_TRAP) == SWITCH_STATUS_SUCCESS) {
switch_size_t len = 0;
int x = 0;
/* populate the event with some headers */
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "testing", "true");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "foo", "bar");
for (x = 0; x < 10; x++) {
char name[128];
switch_snprintf(name, sizeof(name), "test-header-%d", x);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, name, "value-%d", x);
}
/* Nothing up my sleeve, here is the event */
DUMP_EVENT(event);
/* ok, serialize it into frame_buffer and destroy the event *poof* */
len = sizeof(frame_buffer);
switch_event_binary_serialize(event, (void *)frame_buffer, &len);
switch_event_destroy(&event);
/* wave the magic wand and feed frame_buffer to deserialize */
switch_event_binary_deserialize(&event, (void *)frame_buffer, len, SWITCH_FALSE);
/* TA DA */
DUMP_EVENT(event);
switch_event_destroy(&event);
}
return SWITCH_STATUS_SUCCESS;
}
static void mycb(switch_core_session_t *session, switch_channel_callstate_t callstate, switch_device_record_t *drec)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_CRIT,
"%s device: %s\nState: %s Dev State: %s/%s Total:%u Offhook:%u Active:%u Held:%u Hungup:%u Dur: %u %s\n",
switch_channel_get_name(channel),
drec->device_id,
switch_channel_callstate2str(callstate),
switch_channel_device_state2str(drec->last_state),
switch_channel_device_state2str(drec->state),
drec->stats.total,
drec->stats.offhook,
drec->stats.active,
drec->stats.held,
drec->stats.hup,
drec->active_stop ? (uint32_t)(drec->active_stop - drec->active_start) / 1000 : 0,
switch_channel_test_flag(channel, CF_FINAL_DEVICE_LEG) ? "FINAL LEG" : "");
}
/* Macro expands to: switch_status_t mod_skel_load(switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool) */
SWITCH_MODULE_LOAD_FUNCTION(mod_skel_load)
{
switch_api_interface_t *api_interface;
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hello World!\n");
do_config(SWITCH_FALSE);
SWITCH_ADD_API(api_interface, "skel", "Skel API", skel_function, "syntax");
switch_channel_bind_device_state_handler(mycb, NULL);
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
/*
Called when the system shuts down
Macro expands to: switch_status_t mod_skel_shutdown() */
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_skel_shutdown)
{
/* Cleanup dynamically allocated config settings */
switch_channel_unbind_device_state_handler(mycb);
switch_xml_config_cleanup(instructions);
return SWITCH_STATUS_SUCCESS;
}
/*
If it exists, this is called in it's own thread when the module-load completes
If it returns anything but SWITCH_STATUS_TERM it will be called again automatically
Macro expands to: switch_status_t mod_skel_runtime()
SWITCH_MODULE_RUNTIME_FUNCTION(mod_skel_runtime)
{
while(looping)
{
switch_cond_next();
}
return SWITCH_STATUS_TERM;
}
*/
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet
*/
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论