[asterisk-commits] mmichelson: branch group/manager2 r113557 - in /team/group/manager2: include/...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Apr 8 15:56:26 CDT 2008
Author: mmichelson
Date: Tue Apr 8 15:56:26 2008
New Revision: 113557
URL: http://svn.digium.com/view/asterisk?view=rev&rev=113557
Log:
1. Added copyright BS to res_manager2.c
2. Removed the impossible to satisfy conditions from ast_event_ie_get_pltype and
ast_event_ie_get_name by adding an AST_EVENT_IE_LAST to be the same as whatever
the last IE is.
3. Added a crappy little skeleton function for setting up socket stuff.
Modified:
team/group/manager2/include/asterisk/event_defs.h
team/group/manager2/main/event.c
team/group/manager2/res/res_manager2.c
Modified: team/group/manager2/include/asterisk/event_defs.h
URL: http://svn.digium.com/view/asterisk/team/group/manager2/include/asterisk/event_defs.h?view=diff&rev=113557&r1=113556&r2=113557
==============================================================================
--- team/group/manager2/include/asterisk/event_defs.h (original)
+++ team/group/manager2/include/asterisk/event_defs.h Tue Apr 8 15:56:26 2008
@@ -174,6 +174,7 @@
AST_EVENT_IE_FD = 0x21,
/*! A username */
AST_EVENT_IE_USERNAME = 0x22,
+ AST_EVENT_IE_LAST = 0x22,
};
/*!
* \brief Payload types for event information elements
Modified: team/group/manager2/main/event.c
URL: http://svn.digium.com/view/asterisk/team/group/manager2/main/event.c?view=diff&rev=113557&r1=113556&r2=113557
==============================================================================
--- team/group/manager2/main/event.c (original)
+++ team/group/manager2/main/event.c Tue Apr 8 15:56:26 2008
@@ -162,7 +162,7 @@
enum ast_event_ie_pltype ast_event_ie_get_pltype(enum ast_event_ie_type ie)
{
- if (ie > 0 && ie < AST_EVENT_IE_END &&
+ if (ie > 0 && ie < AST_EVENT_IE_LAST &&
info_map[ie].ie == ie) {
return info_map[ie].pltype;
}
@@ -171,7 +171,7 @@
const char * ast_event_ie_get_name(enum ast_event_ie_type ie)
{
- if (ie > 0 && ie < AST_EVENT_IE_END &&
+ if (ie > 0 && ie < AST_EVENT_IE_LAST &&
info_map[ie].ie == ie) {
return info_map[ie].name;
}
@@ -533,7 +533,7 @@
{
va_list ap;
struct ast_event *event;
- enum ast_event_type ie_type;
+ enum ast_event_ie_type ie_type;
struct ast_event_ie_val *ie_val;
AST_LIST_HEAD_NOLOCK_STATIC(ie_vals, ast_event_ie_val);
@@ -545,13 +545,14 @@
}
va_start(ap, type);
- for (ie_type = va_arg(ap, enum ast_event_type);
+ for (ie_type = va_arg(ap, enum ast_event_ie_type);
ie_type != AST_EVENT_IE_END;
- ie_type = va_arg(ap, enum ast_event_type))
+ ie_type = va_arg(ap, enum ast_event_ie_type))
{
struct ast_event_ie_val *ie_val = alloca(sizeof(*ie_val));
memset(ie_val, 0, sizeof(*ie_val));
ie_val->ie_type = ie_type;
+ usleep(100);
ie_val->ie_pltype = ast_event_ie_get_pltype(ie_type);
if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_UINT)
ie_val->payload.uint = va_arg(ap, uint32_t);
Modified: team/group/manager2/res/res_manager2.c
URL: http://svn.digium.com/view/asterisk/team/group/manager2/res/res_manager2.c?view=diff&rev=113557&r1=113556&r2=113557
==============================================================================
--- team/group/manager2/res/res_manager2.c (original)
+++ team/group/manager2/res/res_manager2.c Tue Apr 8 15:56:26 2008
@@ -1,17 +1,63 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2008, Mark Michelson
+ *
+ * Mark Michelson <mmichelson at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Skeleton application
+ *
+ * \author\verbatim Mark Michelson <mmichelson at digium.com> \endverbatim
+ *
+ * This is a skeleton for development of an Asterisk application
+ * \ingroup applications
+ */
+
+/*** MODULEINFO
+ <defaultenabled>no</defaultenabled>
+ ***/
+
+
#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/event.h"
#include "asterisk/utils.h"
#include "asterisk/linkedlists.h"
+#include "asterisk/tcptls.h"
struct info_event {
AST_LIST_ENTRY(info_event) list;
struct ast_event *event;
};
+static void *subscribe_start(void *);
+
+static struct server_args event_server = {
+ .accept_fd = -1,
+ .master = AST_PTHREADT_NULL,
+ .tls_cfg = NULL,
+ .poll_timeout = -1,
+ .name = "event subscriber",
+ .accept_fn = ast_tcptls_server_root,
+ .worker_fn = subscribe_start,
+};
+
struct subscriber {
char name[80];
- int fd;
+ FILE* f;
unsigned int stop:1;
pthread_t thread;
ast_cond_t cond;
@@ -96,7 +142,7 @@
}
ast_str_append(&buf, 0, "%s", "\r\n");
- write(sub->fd, buf->str, buf->used);
+ fwrite(buf->str, buf->used, sizeof(char), sub->f);
ast_event_destroy(event->event);
ast_free(event);
event = NULL;
@@ -137,18 +183,19 @@
* type of event that will cause this is AST_EVENT_MANAGER_LOGIN, but that
* can certainly change
*/
-static void subscribe_start(const struct ast_event *event, void *ignore)
+static void *subscribe_start(void *data)
{
struct subscriber *sub;
if (!(sub = ast_calloc(1, sizeof(*sub)))) {
/* OH CRAP */
ast_log(LOG_WARNING, "Unable to allocate memory for event subscriber! Aborting!\n");
- return;
- }
-
- ast_copy_string(sub->name, ast_event_get_ie_str(event, AST_EVENT_IE_USERNAME), sizeof(sub->name));
- sub->fd = ast_event_get_ie_uint(event, AST_EVENT_IE_FD);
+ return NULL;
+ }
+
+ /* For now, hard code "mark" as the name */
+
+ ast_copy_string(sub->name, "mark", sizeof(sub->name));
ast_debug(3, "Event subscriber %s logged in\n", sub->name);
@@ -161,6 +208,7 @@
/* Just for testing purposes, let's subscribe to queue member device state changes */
ast_event_subscribe(AST_EVENT_QUEUE_MEMBER_STATUS, info_cb, sub, AST_EVENT_IE_END);
ast_pthread_create_background(&sub->thread, NULL, event_spitter, sub);
+ return NULL;
}
static struct subscriber *remove_subscriber(const char *name, const int fd)
@@ -168,7 +216,7 @@
struct subscriber *sub = NULL;
AST_LIST_LOCK(&subscribers);
AST_LIST_TRAVERSE_SAFE_BEGIN(&subscribers, sub, list) {
- if (!strcmp(name, sub->name) && sub->fd == fd) {
+ if (!strcmp(name, sub->name)) {
AST_LIST_REMOVE_CURRENT(list);
break;
}
@@ -200,6 +248,18 @@
}
}
+static void start_socket(void)
+{
+ /* You have no choice of port or IP address right now.
+ * I just want this to "work"
+ *
+ * We use port 24824 and wildcard address.
+ */
+ memset(&event_server.sin, 0, sizeof(event_server.sin));
+ event_server.sin.sin_port = htons(24824);
+ ast_tcptls_server_start(&event_server);
+}
+
static int unload_module(void)
{
if (login_sub) {
@@ -210,10 +270,7 @@
static int load_module(void)
{
- if (!(login_sub = ast_event_subscribe(AST_EVENT_MANAGER_LOGIN, subscribe_start, NULL, AST_EVENT_IE_END))) {
- ast_log(LOG_WARNING, "Failed to subscribe to manager login events!\n");
- return AST_MODULE_LOAD_DECLINE;
- }
+ start_socket();
return AST_MODULE_LOAD_SUCCESS;
}
More information about the asterisk-commits
mailing list