struct rayo_client *console;
/** XMPP context */
struct xmpp_stream_context *xmpp_context;
+ /** number of message threads */
+ int num_message_threads;
+ /** message delivery queue */
+ switch_queue_t *msg_queue;
+ /** shutdown flag */
+ int shutdown;
+ /** prevents context shutdown until all threads are finished */
+ switch_thread_rwlock_t *shutdown_rwlock;
} globals;
/**
int strip;
};
-static void rayo_call_send(struct rayo_actor *call, struct rayo_message *msg, const char *file, int line);
-static void rayo_server_send(struct rayo_actor *server, struct rayo_message *msg, const char *file, int line);
-static void rayo_mixer_send(struct rayo_actor *mixer, struct rayo_message *msg, const char *file, int line);
-static void rayo_component_send(struct rayo_actor *component, struct rayo_message *msg, const char *file, int line);
-static void rayo_client_send(struct rayo_actor *client, struct rayo_message *msg, const char *file, int line);
-static void rayo_console_client_send(struct rayo_actor *client, struct rayo_message *msg, const char *file, int line);
+static void rayo_call_send(struct rayo_actor *call, struct rayo_message *msg);
+static void rayo_server_send(struct rayo_actor *server, struct rayo_message *msg);
+static void rayo_mixer_send(struct rayo_actor *mixer, struct rayo_message *msg);
+static void rayo_component_send(struct rayo_actor *component, struct rayo_message *msg);
+static void rayo_client_send(struct rayo_actor *client, struct rayo_message *msg);
+static void rayo_console_client_send(struct rayo_actor *client, struct rayo_message *msg);
static void on_client_presence(struct rayo_client *rclient, iks *node);
return NULL;
}
-/**
- * Create a new xml message for delivery to an actor.
- * @param from actor creating this message
- * @param xml to create message from. This value will be freed upon message delivery.
- * @param dup true if duplicate payload
- * @param reply true if a reply (error or result)
- * @return the message
- */
-struct rayo_message *rayo_message_create(struct rayo_actor *from, iks *xml, int dup, int reply)
-{
- struct rayo_message *msg = malloc(sizeof(*msg));
- if (dup) {
- msg->payload = iks_copy(xml);
- } else {
- msg->payload = xml;
- }
- msg->is_reply = reply;
- msg->from_jid = strdup(RAYO_JID(from));
- msg->from_type = strdup(zstr(from->type) ? "" : from->type);
- msg->from_subtype = strdup(zstr(from->subtype) ? "" : from->subtype);
- return msg;
-}
-
/**
* Clean up a message
* @param msg to destroy
if (msg->payload) {
iks_delete(msg->payload);
}
+ switch_safe_free(msg->to_jid);
switch_safe_free(msg->from_jid);
switch_safe_free(msg->from_type);
switch_safe_free(msg->from_subtype);
+ switch_safe_free(msg->file);
free(msg);
}
}
}
/**
- * Deliver message to actor
+ * Thread that delivers internal XMPP messages
+ * @param thread this thread
+ * @param obj unused
+ * @return NULL
*/
-static void rayo_actor_deliver(struct rayo_actor *actor, struct rayo_message *msg, const char *file, int line)
-{
- iks *payload = msg->payload;
- char *msg_str = iks_string(iks_stack(payload), payload);
+static void *SWITCH_THREAD_FUNC deliver_message_thread(switch_thread_t *thread, void *obj)
+{
+ struct rayo_message *msg = NULL;
+ switch_thread_rwlock_rdlock(globals.shutdown_rwlock);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "New message delivery thread\n");
+ while (!globals.shutdown) {
+ if (switch_queue_pop(globals.msg_queue, (void *)&msg) == SWITCH_STATUS_SUCCESS) {
+ struct rayo_actor *actor = RAYO_LOCATE(msg->to_jid);
+ if (actor) {
+ switch_mutex_lock(actor->mutex);
+ actor->send_fn(actor, msg);
+ switch_mutex_unlock(actor->mutex);
+ RAYO_UNLOCK(actor);
+ rayo_message_destroy(msg);
+ }
+ }
+ }
- switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, "", line, "", SWITCH_LOG_DEBUG, "%s, %s\n", msg->from_jid, msg_str);
- switch_mutex_lock(actor->mutex);
- actor->send_fn(actor, msg, file, line);
- switch_mutex_unlock(actor->mutex);
+ /* clean up remaining messages */
+ while(switch_queue_trypop(globals.msg_queue, (void *)&msg) == SWITCH_STATUS_SUCCESS) {
+ rayo_message_destroy(msg);
+ }
+
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Message delivery thread finished\n");
+ switch_thread_rwlock_unlock(globals.shutdown_rwlock);
+ return NULL;
+}
+
+/**
+ * Create a new message thread
+ * @param pool to use
+ */
+static void start_deliver_message_thread(switch_memory_pool_t *pool)
+{
+ switch_thread_t *thread;
+ switch_threadattr_t *thd_attr = NULL;
+ switch_threadattr_create(&thd_attr, pool);
+ switch_threadattr_detach_set(thd_attr, 1);
+ switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
+ switch_thread_create(&thread, thd_attr, deliver_message_thread, NULL, pool);
+}
- rayo_message_destroy(msg);
+/**
+ * Stop all message threads
+ */
+static void stop_deliver_message_threads(void)
+{
+ globals.shutdown = 1;
+ switch_queue_interrupt_all(globals.msg_queue);
+ switch_thread_rwlock_wrlock(globals.shutdown_rwlock);
}
/**
* Send message to actor addressed by JID
+ * @param from actor sending the message
+ * @param to destination JID
+ * @param payload the message payload to deliver
+ * @param dup true if payload is to be copied
+ * @param reply true if a reply
+ * @param file file name
+ * @param line line number
*/
-void rayo_actor_send(const char *jid, struct rayo_message *msg, const char *file, int line)
+void rayo_message_send(struct rayo_actor *from, const char *to, iks *payload, int dup, int reply, const char *file, int line)
{
- struct rayo_actor *actor = RAYO_LOCATE(jid);
- if (actor) {
- /* TODO queue to thread pool */
- rayo_actor_deliver(actor, msg, file, line);
- RAYO_UNLOCK(actor);
+ struct rayo_message *msg = malloc(sizeof(*msg));
+ if (dup) {
+ msg->payload = iks_copy(payload);
} else {
- switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, "", line, "", SWITCH_LOG_DEBUG, "%s, failed to locate %s.\n", msg->from_jid, jid);
- if (!msg->is_reply) {
- /* don't reply to replies to prevent infinite loops */
- RAYO_SEND(msg->from_jid, RAYO_REPLY_CREATE(globals.server, iks_new_error(msg->payload, STANZA_ERROR_ITEM_NOT_FOUND)));
- }
+ msg->payload = payload;
+ }
+ msg->is_reply = reply;
+ msg->to_jid = strdup(zstr(to) ? "" : to);
+ msg->from_jid = strdup(RAYO_JID(from));
+ msg->from_type = strdup(zstr(from->type) ? "" : from->type);
+ msg->from_subtype = strdup(zstr(from->subtype) ? "" : from->subtype);
+ msg->file = strdup(file);
+ msg->line = line;
+
+ if (switch_queue_trypush(globals.msg_queue, msg) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "failed to queue message!\n");
rayo_message_destroy(msg);
}
}
}
actor->destroy = 1;
if (actor->ref_count <= 0) {
- struct rayo_message *msg;
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, "", line, "", SWITCH_LOG_DEBUG, "Destroying %s\n", RAYO_JID(actor));
if (actor->cleanup_fn) {
actor->cleanup_fn(actor);
}
switch_core_hash_delete(globals.destroy_actors, RAYO_JID(actor));
- while (switch_queue_trypop(actor->msg_queue, (void *)&msg) == SWITCH_STATUS_SUCCESS) {
- rayo_message_destroy(msg);
- }
switch_core_destroy_memory_pool(&pool);
} else {
switch_core_hash_insert(globals.destroy_actors, RAYO_JID(actor), actor);
switch_assert(client_jid);
iks_insert_attrib(revent, "to", client_jid);
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(rayo_call_get_uuid(call)), SWITCH_LOG_DEBUG, "Sending <end> to offered client %s\n", client_jid);
- RAYO_SEND(client_jid, RAYO_MESSAGE_CREATE_DUP(actor, revent));
+ RAYO_SEND_MESSAGE_DUP(actor, client_jid, revent);
no_offered_clients = 0;
}
if (no_offered_clients) {
/* send to DCP only */
switch_log_printf(SWITCH_CHANNEL_UUID_LOG(rayo_call_get_uuid(call)), SWITCH_LOG_DEBUG, "Sending <end> to DCP %s\n", rayo_call_get_dcp_jid(call));
- RAYO_SEND(rayo_call_get_dcp_jid(call), RAYO_MESSAGE_CREATE_DUP(actor, revent));
+ RAYO_SEND_MESSAGE_DUP(actor, rayo_call_get_dcp_jid(call), revent);
}
iks_delete(revent);
/**
* Default message handler - drops messages
*/
-void rayo_actor_send_ignore(struct rayo_actor *to, struct rayo_message *msg, const char *file, int line)
+void rayo_actor_send_ignore(struct rayo_actor *to, struct rayo_message *msg)
{
- switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, "", line, "", SWITCH_LOG_WARNING, "%s, dropping unexpected message to %s.\n", msg->from_jid, RAYO_JID(to));
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, msg->file, "", msg->line, "", SWITCH_LOG_WARNING, "%s, dropping unexpected message to %s.\n", msg->from_jid, RAYO_JID(to));
}
#define RAYO_ACTOR_INIT(actor, pool, type, subtype, id, jid, cleanup, send) rayo_actor_init(actor, pool, type, subtype, id, jid, cleanup, send, __FILE__, __LINE__)
} else {
actor->send_fn = send;
}
- switch_queue_create(&actor->msg_queue, 20, pool);
/* add to hash of actors, so commands can route to call */
switch_mutex_lock(globals.actors_mutex);
/**
* Send XMPP message to client
*/
-void rayo_client_send(struct rayo_actor *client, struct rayo_message *msg, const char *file, int line)
+void rayo_client_send(struct rayo_actor *client, struct rayo_message *msg)
{
xmpp_stream_context_send(globals.xmpp_context, RAYO_CLIENT(client)->route, msg->payload);
}
/**
* Send XMPP message to peer server
*/
-void rayo_peer_server_send(struct rayo_actor *server, struct rayo_message *msg, const char *file, int line)
+void rayo_peer_server_send(struct rayo_actor *server, struct rayo_message *msg)
{
xmpp_stream_context_send(globals.xmpp_context, RAYO_JID(server), msg->payload);
}
/**
* Handle server message
*/
-void rayo_server_send(struct rayo_actor *server, struct rayo_message *msg, const char *file, int line)
+void rayo_server_send(struct rayo_actor *server, struct rayo_message *msg)
{
iks *response = NULL;
rayo_actor_xmpp_handler handler = NULL;
handler = rayo_actor_command_handler_find(server, msg);
if (!handler) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s, no handler function for command to %s\n", msg->from_jid, RAYO_JID(server));
- RAYO_SEND(msg->from_jid, RAYO_REPLY_CREATE(server, iks_new_error(iq, STANZA_ERROR_FEATURE_NOT_IMPLEMENTED)));
+ RAYO_SEND_REPLY(server, msg->from_jid, iks_new_error(iq, STANZA_ERROR_FEATURE_NOT_IMPLEMENTED));
return;
}
}
if (response) {
- RAYO_SEND(msg->from_jid, RAYO_REPLY_CREATE(server, response));
+ RAYO_SEND_REPLY(server, msg->from_jid, response);
}
}
/**
* Handle call message
*/
-void rayo_call_send(struct rayo_actor *call, struct rayo_message *msg, const char *file, int line)
+void rayo_call_send(struct rayo_actor *call, struct rayo_message *msg)
{
rayo_actor_xmpp_handler handler = NULL;
iks *iq = msg->payload;
handler = rayo_actor_command_handler_find(call, msg);
if (!handler) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s, no handler function for command\n", RAYO_JID(call));
- RAYO_SEND(msg->from_jid, RAYO_REPLY_CREATE(call, iks_new_error(iq, STANZA_ERROR_FEATURE_NOT_IMPLEMENTED)));
+ RAYO_SEND_REPLY(call, msg->from_jid, iks_new_error(iq, STANZA_ERROR_FEATURE_NOT_IMPLEMENTED));
return;
}
session = switch_core_session_locate(rayo_call_get_uuid(RAYO_CALL(call)));
if (!session) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s, session not found\n", RAYO_JID(call));
- RAYO_SEND(msg->from_jid, RAYO_REPLY_CREATE(call, iks_new_error(iq, STANZA_ERROR_SERVICE_UNAVAILABLE)));
+ RAYO_SEND_REPLY(call, msg->from_jid, iks_new_error(iq, STANZA_ERROR_SERVICE_UNAVAILABLE));
return;
}
switch_core_session_rwunlock(session);
if (response) {
- RAYO_SEND(msg->from_jid, RAYO_REPLY_CREATE(call, response));
+ RAYO_SEND_REPLY(call, msg->from_jid, response);
}
}
/**
* Handle mixer message
*/
-void rayo_mixer_send(struct rayo_actor *mixer, struct rayo_message *msg, const char *file, int line)
+void rayo_mixer_send(struct rayo_actor *mixer, struct rayo_message *msg)
{
rayo_actor_xmpp_handler handler = NULL;
iks *iq = msg->payload;
handler = rayo_actor_command_handler_find(mixer, msg);
if (!handler) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s, no handler function for command\n", RAYO_JID(mixer));
- RAYO_SEND(msg->from_jid, RAYO_REPLY_CREATE(mixer, iks_new_error(iq, STANZA_ERROR_FEATURE_NOT_IMPLEMENTED)));
+ RAYO_SEND_REPLY(mixer, msg->from_jid, iks_new_error(iq, STANZA_ERROR_FEATURE_NOT_IMPLEMENTED));
return;
}
/* execute the command */
response = handler(mixer, msg, NULL);
if (response) {
- RAYO_SEND(msg->from_jid, RAYO_REPLY_CREATE(mixer, response));
+ RAYO_SEND_REPLY(mixer, msg->from_jid, response);
}
}
/**
* Handle mixer message
*/
-void rayo_component_send(struct rayo_actor *component, struct rayo_message *msg, const char *file, int line)
+void rayo_component_send(struct rayo_actor *component, struct rayo_message *msg)
{
rayo_actor_xmpp_handler handler = NULL;
iks *xml_msg = msg->payload;
handler = rayo_actor_command_handler_find(component, msg);
if (!handler) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s, no component handler function for command\n", RAYO_JID(component));
- RAYO_SEND(msg->from_jid, RAYO_REPLY_CREATE(component, iks_new_error(xml_msg, STANZA_ERROR_FEATURE_NOT_IMPLEMENTED)));
+ RAYO_SEND_REPLY(component, msg->from_jid, iks_new_error(xml_msg, STANZA_ERROR_FEATURE_NOT_IMPLEMENTED));
return;
}
}
if (response) {
- RAYO_SEND(msg->from_jid, RAYO_REPLY_CREATE(component, response));
+ RAYO_SEND_REPLY(component, msg->from_jid, response);
return;
}
} else if (!strcmp("presence", iks_name(xml_msg))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s, forwarding event\n", RAYO_JID(component));
response = handler(component, msg, NULL);
if (response) {
- RAYO_SEND(msg->from_jid, RAYO_REPLY_CREATE(component, response));
+ RAYO_SEND_REPLY(component, msg->from_jid, response);
}
}
}
/* response when error */
if (response) {
/* send response to client */
- RAYO_SEND(iks_find_attrib(response, "to"), RAYO_REPLY_CREATE(call, response));
+ RAYO_SEND_REPLY(call, iks_find_attrib(response, "to"), response);
/* destroy call */
if (call) {
struct dial_thread_data *dtdata = NULL;
switch_core_new_memory_pool(&pool);
dtdata = switch_core_alloc(pool, sizeof(*dtdata));
- dtdata->pool = pool;
+ dtdata->pool = pool;
dtdata->node = iks_copy(node);
iks_insert_attrib(dtdata->node, "from", msg->from_jid); /* save DCP jid in case it isn't specified */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s, recv message, availability = %s\n", RAYO_JID(rclient), presence_status_to_string(rclient->availability));
- RAYO_SEND(to, RAYO_MESSAGE_CREATE_DUP(rclient, message));
+ RAYO_SEND_MESSAGE_DUP(rclient, to, message);
}
/**
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s, recv iq, availability = %s\n", RAYO_JID(rclient), presence_status_to_string(rclient->availability));
if (command) {
- RAYO_SEND(to, RAYO_MESSAGE_CREATE_DUP(rclient, iq));
+ RAYO_SEND_MESSAGE_DUP(rclient, to, iq);
} else {
- RAYO_SEND(RAYO_JID(rclient), RAYO_REPLY_CREATE(globals.server, iks_new_error_detailed(iq, STANZA_ERROR_BAD_REQUEST, "empty IQ request")));
+ RAYO_SEND_REPLY(globals.server, RAYO_JID(rclient), iks_new_error_detailed(iq, STANZA_ERROR_BAD_REQUEST, "empty IQ request"));
}
}
subscriber = (struct rayo_mixer_subscriber *)val;
switch_assert(subscriber);
iks_insert_attrib(rayo_event, "to", subscriber->jid);
- RAYO_SEND(subscriber->jid, RAYO_MESSAGE_CREATE_DUP(mixer, rayo_event));
+ RAYO_SEND_MESSAGE_DUP(mixer, subscriber->jid, rayo_event);
}
}
delete_member_event = iks_new_presence("unjoined", RAYO_NS, member->jid, member->dcp_jid);
x = iks_find(delete_member_event, "unjoined");
iks_insert_attrib(x, "mixer-name", rayo_mixer_get_name(mixer));
- RAYO_SEND(member->dcp_jid, RAYO_MESSAGE_CREATE(mixer, delete_member_event));
+ RAYO_SEND_MESSAGE(mixer, member->dcp_jid, delete_member_event);
/* broadcast member unjoined event to subscribers */
delete_member_event = iks_new_presence("unjoined", RAYO_NS, RAYO_JID(mixer), "");
add_member_event = iks_new_presence("joined", RAYO_NS, RAYO_JID(call), call->dcp_jid);
x = iks_find(add_member_event, "joined");
iks_insert_attrib(x, "mixer-name", rayo_mixer_get_name(mixer));
- RAYO_SEND(call->dcp_jid, RAYO_MESSAGE_CREATE(call, add_member_event));
+ RAYO_SEND_MESSAGE(call, call->dcp_jid, add_member_event);
RAYO_UNLOCK(call);
}
#else
iks_insert_attrib_printf(ref, "uri", "xmpp:%s", RAYO_JID(call));
#endif
- RAYO_SEND(RAYO_JID(rclient), RAYO_MESSAGE_CREATE(call, response));
+ RAYO_SEND_MESSAGE(call, RAYO_JID(rclient), response);
call->dial_id = NULL;
}
RAYO_UNLOCK(call);
iks *revent = iks_new_presence("answered", RAYO_NS,
switch_event_get_header(event, "variable_rayo_call_jid"),
switch_event_get_header(event, "variable_rayo_dcp_jid"));
- RAYO_SEND(RAYO_JID(rclient), RAYO_MESSAGE_CREATE(call, revent));
+ RAYO_SEND_MESSAGE(call, RAYO_JID(rclient), revent);
RAYO_UNLOCK(call);
}
}
iks *revent = iks_new_presence("ringing", RAYO_NS,
switch_event_get_header(event, "variable_rayo_call_jid"),
switch_event_get_header(event, "variable_rayo_dcp_jid"));
- RAYO_SEND(RAYO_JID(rclient), RAYO_MESSAGE_CREATE(call, revent));
+ RAYO_SEND_MESSAGE(call, RAYO_JID(rclient), revent);
RAYO_UNLOCK(call);
}
}
call->joined = 1;
- RAYO_SEND(RAYO_JID(rclient), RAYO_MESSAGE_CREATE(call, revent));
+ RAYO_SEND_MESSAGE(call, RAYO_JID(rclient), revent);
/* send B-leg event */
b_call = RAYO_CALL_LOCATE(b_uuid);
b_call->joined = 1;
- RAYO_SEND(rayo_call_get_dcp_jid(b_call), RAYO_MESSAGE_CREATE(b_call, revent));
+ RAYO_SEND_MESSAGE(b_call, rayo_call_get_dcp_jid(b_call), revent);
RAYO_UNLOCK(b_call);
}
RAYO_UNLOCK(call);
switch_event_get_header(event, "variable_rayo_dcp_jid"));
iks *joined = iks_find(revent, "unjoined");
iks_insert_attrib(joined, "call-uri", b_uuid);
- RAYO_SEND(RAYO_JID(rclient), RAYO_MESSAGE_CREATE(call, revent));
+ RAYO_SEND_MESSAGE(call, RAYO_JID(rclient), revent);
call->joined = 0;
revent = iks_new_presence("unjoined", RAYO_NS, RAYO_JID(b_call), rayo_call_get_dcp_jid(b_call));
joined = iks_find(revent, "unjoined");
iks_insert_attrib(joined, "call-uri", a_uuid);
- RAYO_SEND(rayo_call_get_dcp_jid(b_call), RAYO_MESSAGE_CREATE(b_call, revent));
+ RAYO_SEND_MESSAGE(b_call, rayo_call_get_dcp_jid(b_call), revent);
b_call->joined = 0;
RAYO_UNLOCK(b_call);
ok = 1;
switch_core_hash_insert(call->pcps, RAYO_JID(rclient), "1");
iks_insert_attrib(offer, "to", RAYO_JID(rclient));
- RAYO_SEND(RAYO_JID(rclient), RAYO_MESSAGE_CREATE_DUP(call, offer));
+ RAYO_SEND_MESSAGE_DUP(call, RAYO_JID(rclient), offer);
}
}
iks_delete(offer);
iks_insert_attrib(presence, "to", xmpp_stream_get_jid(stream));
x = iks_insert(presence, "show");
iks_insert_cdata(x, "chat", 4);
- RAYO_SEND(xmpp_stream_get_jid(stream), RAYO_MESSAGE_CREATE(globals.server, presence));
+ RAYO_SEND_MESSAGE(globals.server, xmpp_stream_get_jid(stream), presence);
}
} else {
/* client belongs to stream */
/* set defaults */
globals.max_idle_ms = 30000;
globals.mixer_conf_profile = "sla";
+ globals.num_message_threads = 8;
/* get params */
{
if (!zstr(val)) {
globals.mixer_conf_profile = switch_core_strdup(pool, val);
}
+ } else if (!strcasecmp(var, "message-threads")) {
+ if (switch_is_number(val)) {
+ int num_message_threads = atoi(val);
+ if (num_message_threads > 0) {
+ globals.num_message_threads = num_message_threads;
+ }
+ }
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unsupported param: %s\n", var);
}
/**
* Process response to console command_api
*/
-void rayo_console_client_send(struct rayo_actor *actor, struct rayo_message *msg, const char *file, int line)
+void rayo_console_client_send(struct rayo_actor *actor, struct rayo_message *msg)
{
iks *response = msg->payload;
x = iks_insert(message, "body");
iks_insert_cdata(x, message_str, strlen(message_str));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\nSEND: to %s, %s\n", to, iks_string(iks_stack(message), message));
- RAYO_SEND(to, RAYO_MESSAGE_CREATE(client, message));
+ RAYO_SEND_MESSAGE(client, to, message);
}
/**
x = iks_insert(presence, "show");
iks_insert_cdata(x, is_online ? "chat" : "dnd", 0);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\nSEND: to %s, %s\n", to, iks_string(iks_stack(presence), presence));
- RAYO_SEND(to, RAYO_MESSAGE_CREATE(client, presence));
+ RAYO_SEND_MESSAGE(client, to, presence);
}
/**
switch_mutex_init(&globals.actors_mutex, SWITCH_MUTEX_NESTED, pool);
switch_core_hash_init(&globals.dial_gateways, pool);
switch_core_hash_init(&globals.cmd_aliases, pool);
+ switch_thread_rwlock_create(&globals.shutdown_rwlock, pool);
+ switch_queue_create(&globals.msg_queue, 25000, pool);
/* server commands */
rayo_actor_command_handler_add(RAT_SERVER, "", "get:"IKS_NS_XMPP_PING":ping", on_iq_xmpp_ping);
return SWITCH_STATUS_TERM;
}
+ /* start up message threads */
+ {
+ int i;
+ for (i = 0; i < globals.num_message_threads; i++) {
+ start_deliver_message_thread(pool);
+ }
+ }
+
/* create admin client */
globals.console = rayo_console_client_create();
switch_console_del_complete_func("::rayo::list_actors");
switch_console_set_complete("del rayo");
- /* wait for threads to finish */
+ /* stop XMPP streams */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Waiting for XMPP threads to stop\n");
xmpp_stream_context_destroy(globals.xmpp_context);
+ /* stop message threads */
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Waiting for message threads to stop\n");
+ stop_deliver_message_threads();
+
rayo_components_shutdown();
/* cleanup module */