提交 c15c0924 authored 作者: Chris Rienzo's avatar Chris Rienzo

mod_rayo: added message delivery threads

上级 0f0f2781
...@@ -64,14 +64,17 @@ struct rayo_component; ...@@ -64,14 +64,17 @@ struct rayo_component;
*/ */
struct rayo_message { struct rayo_message {
iks *payload; iks *payload;
char *to_jid;
char *from_jid; char *from_jid;
char *from_type; char *from_type;
char *from_subtype; char *from_subtype;
int is_reply; int is_reply;
char *file;
int line;
}; };
typedef void (* rayo_actor_cleanup_fn)(struct rayo_actor *); typedef void (* rayo_actor_cleanup_fn)(struct rayo_actor *);
typedef void (* rayo_actor_send_fn)(struct rayo_actor *, struct rayo_message *, const char *file, int line); typedef void (* rayo_actor_send_fn)(struct rayo_actor *, struct rayo_message *);
/** /**
* A rayo actor - this is an entity that can be controlled by a rayo client * A rayo actor - this is an entity that can be controlled by a rayo client
...@@ -126,19 +129,17 @@ struct rayo_component { ...@@ -126,19 +129,17 @@ struct rayo_component {
#define RAYO_CALL(x) ((struct rayo_call *)x) #define RAYO_CALL(x) ((struct rayo_call *)x)
#define RAYO_MIXER(x) ((struct rayo_mixer *)x) #define RAYO_MIXER(x) ((struct rayo_mixer *)x)
extern struct rayo_message *rayo_message_create(struct rayo_actor *from, iks *xml, int dup, int reply); extern void rayo_message_send(struct rayo_actor *from, const char *to, iks *payload, int dup, int reply, const char *file, int line);
extern void rayo_message_destroy(struct rayo_message *msg); extern void rayo_message_destroy(struct rayo_message *msg);
extern iks *rayo_message_remove_payload(struct rayo_message *msg); extern iks *rayo_message_remove_payload(struct rayo_message *msg);
#define RAYO_SEND_MESSAGE(from, to, payload) rayo_message_send(RAYO_ACTOR(from), to, payload, 0, 0, __FILE__, __LINE__)
#define RAYO_MESSAGE_CREATE(from, msg) rayo_message_create(RAYO_ACTOR(from), msg, 0, 0) #define RAYO_SEND_MESSAGE_DUP(from, to, payload) rayo_message_send(RAYO_ACTOR(from), to, payload, 1, 0, __FILE__, __LINE__)
#define RAYO_MESSAGE_CREATE_DUP(from, msg) rayo_message_create(RAYO_ACTOR(from), msg, 1, 0) #define RAYO_SEND_REPLY(from, to, payload) rayo_message_send(RAYO_ACTOR(from), to, payload, 0, 1, __FILE__, __LINE__)
#define RAYO_REPLY_CREATE(from, msg) rayo_message_create(RAYO_ACTOR(from), msg, 0, 1) #define RAYO_SEND_REPLY_DUP(from, to, payload) rayo_message_send(RAYO_ACTOR(from), to, payload, 1, 1, __FILE__, __LINE__)
#define RAYO_REPLY_CREATE_DUP(from, msg) rayo_message_create(RAYO_ACTOR(from), msg, 1, 1)
extern struct rayo_actor *rayo_actor_locate(const char *jid, const char *file, int line); extern struct rayo_actor *rayo_actor_locate(const char *jid, const char *file, int line);
extern struct rayo_actor *rayo_actor_locate_by_id(const char *id, const char *file, int line); extern struct rayo_actor *rayo_actor_locate_by_id(const char *id, const char *file, int line);
extern int rayo_actor_seq_next(struct rayo_actor *actor); extern int rayo_actor_seq_next(struct rayo_actor *actor);
extern void rayo_actor_send(const char *jid, struct rayo_message *msg, const char *file, int line);
extern void rayo_actor_rdlock(struct rayo_actor *actor, const char *file, int line); extern void rayo_actor_rdlock(struct rayo_actor *actor, const char *file, int line);
extern void rayo_actor_unlock(struct rayo_actor *actor, const char *file, int line); extern void rayo_actor_unlock(struct rayo_actor *actor, const char *file, int line);
extern void rayo_actor_destroy(struct rayo_actor *actor, const char *file, int line); extern void rayo_actor_destroy(struct rayo_actor *actor, const char *file, int line);
...@@ -154,7 +155,6 @@ extern void rayo_actor_destroy(struct rayo_actor *actor, const char *file, int l ...@@ -154,7 +155,6 @@ extern void rayo_actor_destroy(struct rayo_actor *actor, const char *file, int l
#define RAYO_UNLOCK(x) rayo_actor_unlock(RAYO_ACTOR(x), __FILE__, __LINE__) #define RAYO_UNLOCK(x) rayo_actor_unlock(RAYO_ACTOR(x), __FILE__, __LINE__)
#define RAYO_DESTROY(x) rayo_actor_destroy(RAYO_ACTOR(x), __FILE__, __LINE__) #define RAYO_DESTROY(x) rayo_actor_destroy(RAYO_ACTOR(x), __FILE__, __LINE__)
#define RAYO_SEQ_NEXT(x) rayo_actor_seq_next(RAYO_ACTOR(x)) #define RAYO_SEQ_NEXT(x) rayo_actor_seq_next(RAYO_ACTOR(x))
#define RAYO_SEND(to, msg) rayo_actor_send(to, msg, __FILE__, __LINE__)
extern const char *rayo_call_get_dcp_jid(struct rayo_call *call); extern const char *rayo_call_get_dcp_jid(struct rayo_call *call);
......
...@@ -63,7 +63,7 @@ void rayo_component_send_start(struct rayo_component *component, iks *iq) ...@@ -63,7 +63,7 @@ void rayo_component_send_start(struct rayo_component *component, iks *iq)
#else #else
iks_insert_attrib_printf(ref, "uri", "xmpp:%s", RAYO_JID(component)); iks_insert_attrib_printf(ref, "uri", "xmpp:%s", RAYO_JID(component));
#endif #endif
RAYO_SEND(iks_find_attrib(response, "to"), RAYO_REPLY_CREATE(component, response)); RAYO_SEND_REPLY(component, iks_find_attrib(response, "to"), response);
} }
/** /**
...@@ -116,7 +116,7 @@ iks *rayo_component_create_complete_event(struct rayo_component *component, cons ...@@ -116,7 +116,7 @@ iks *rayo_component_create_complete_event(struct rayo_component *component, cons
*/ */
void rayo_component_send_complete_event(struct rayo_component *component, iks *response) void rayo_component_send_complete_event(struct rayo_component *component, iks *response)
{ {
RAYO_SEND(iks_find_attrib(response, "to"), RAYO_REPLY_CREATE(component, response)); RAYO_SEND_REPLY(component, iks_find_attrib(response, "to"), response);
RAYO_UNLOCK(component); RAYO_UNLOCK(component);
RAYO_DESTROY(component); RAYO_DESTROY(component);
} }
......
...@@ -187,7 +187,7 @@ static void send_barge_event(struct rayo_component *component) ...@@ -187,7 +187,7 @@ static void send_barge_event(struct rayo_component *component)
iks_insert_attrib(event, "to", component->client_jid); iks_insert_attrib(event, "to", component->client_jid);
x = iks_insert(event, "start-of-input"); x = iks_insert(event, "start-of-input");
iks_insert_attrib(x, "xmlns", RAYO_INPUT_NS); iks_insert_attrib(x, "xmlns", RAYO_INPUT_NS);
RAYO_SEND(component->client_jid, RAYO_REPLY_CREATE(component, event)); RAYO_SEND_REPLY(component, component->client_jid, event);
} }
/** /**
......
...@@ -99,7 +99,7 @@ static void rayo_component_send_stop(struct rayo_actor *from, const char *to) ...@@ -99,7 +99,7 @@ static void rayo_component_send_stop(struct rayo_actor *from, const char *to)
iks_insert_attrib_printf(stop, "id", "mod_rayo-%d", RAYO_SEQ_NEXT(from)); iks_insert_attrib_printf(stop, "id", "mod_rayo-%d", RAYO_SEQ_NEXT(from));
x = iks_insert(stop, "stop"); x = iks_insert(stop, "stop");
iks_insert_attrib(x, "xmlns", RAYO_EXT_NS); iks_insert_attrib(x, "xmlns", RAYO_EXT_NS);
RAYO_SEND(to, RAYO_MESSAGE_CREATE(from, stop)); RAYO_SEND_MESSAGE(from, to, stop);
} }
/** /**
...@@ -118,7 +118,7 @@ static void start_input(struct prompt_component *prompt, int start_timers, int b ...@@ -118,7 +118,7 @@ static void start_input(struct prompt_component *prompt, int start_timers, int b
iks_insert_attrib(input, "start-timers", start_timers ? "true" : "false"); iks_insert_attrib(input, "start-timers", start_timers ? "true" : "false");
iks_insert_attrib(input, "barge-event", barge_event ? "true" : "false"); iks_insert_attrib(input, "barge-event", barge_event ? "true" : "false");
iks_insert_node(iq, input); iks_insert_node(iq, input);
RAYO_SEND(RAYO_JID(RAYO_COMPONENT(prompt)->parent), RAYO_MESSAGE_CREATE(prompt, iq)); RAYO_SEND_MESSAGE(prompt, RAYO_JID(RAYO_COMPONENT(prompt)->parent), iq);
} }
/** /**
...@@ -134,7 +134,7 @@ static void start_input_timers(struct prompt_component *prompt) ...@@ -134,7 +134,7 @@ static void start_input_timers(struct prompt_component *prompt)
iks_insert_attrib_printf(iq, "id", "mod_rayo-%d", RAYO_SEQ_NEXT(prompt)); iks_insert_attrib_printf(iq, "id", "mod_rayo-%d", RAYO_SEQ_NEXT(prompt));
x = iks_insert(iq, "start-timers"); x = iks_insert(iq, "start-timers");
iks_insert_attrib(x, "xmlns", RAYO_INPUT_NS); iks_insert_attrib(x, "xmlns", RAYO_INPUT_NS);
RAYO_SEND(prompt->input_jid, RAYO_MESSAGE_CREATE(prompt, iq)); RAYO_SEND_MESSAGE(prompt, prompt->input_jid, iq);
} }
/** /**
...@@ -317,7 +317,7 @@ static iks *prompt_component_handle_output_error(struct rayo_actor *prompt, stru ...@@ -317,7 +317,7 @@ static iks *prompt_component_handle_output_error(struct rayo_actor *prompt, stru
iks_insert_attrib(iq, "from", RAYO_JID(RAYO_COMPONENT(prompt)->parent)); iks_insert_attrib(iq, "from", RAYO_JID(RAYO_COMPONENT(prompt)->parent));
iks_insert_attrib(iq, "to", RAYO_COMPONENT(prompt)->client_jid); iks_insert_attrib(iq, "to", RAYO_COMPONENT(prompt)->client_jid);
iks_insert_node(iq, iks_copy_within(error, iks_stack(iq))); iks_insert_node(iq, iks_copy_within(error, iks_stack(iq)));
RAYO_SEND(RAYO_COMPONENT(prompt)->client_jid, RAYO_REPLY_CREATE(prompt, iq)); RAYO_SEND_REPLY(prompt, RAYO_COMPONENT(prompt)->client_jid, iq);
/* done */ /* done */
RAYO_UNLOCK(prompt); RAYO_UNLOCK(prompt);
...@@ -516,7 +516,7 @@ static iks *start_call_prompt_component(struct rayo_actor *call, struct rayo_mes ...@@ -516,7 +516,7 @@ static iks *start_call_prompt_component(struct rayo_actor *call, struct rayo_mes
iks_insert_attrib(cmd, "type", "set"); iks_insert_attrib(cmd, "type", "set");
output = iks_copy_within(output, iks_stack(cmd)); output = iks_copy_within(output, iks_stack(cmd));
iks_insert_node(cmd, output); iks_insert_node(cmd, output);
RAYO_SEND(RAYO_JID(call), RAYO_MESSAGE_CREATE(prompt_component, cmd)); RAYO_SEND_MESSAGE(prompt_component, RAYO_JID(call), cmd);
return NULL; return NULL;
} }
...@@ -583,7 +583,7 @@ static iks *forward_output_component_request(struct rayo_actor *prompt, struct r ...@@ -583,7 +583,7 @@ static iks *forward_output_component_request(struct rayo_actor *prompt, struct r
/* forward request to output component */ /* forward request to output component */
iks_insert_attrib(iq, "from", RAYO_JID(prompt)); iks_insert_attrib(iq, "from", RAYO_JID(prompt));
iks_insert_attrib(iq, "to", RAYO_JID(PROMPT_COMPONENT(prompt)->output_jid)); iks_insert_attrib(iq, "to", RAYO_JID(PROMPT_COMPONENT(prompt)->output_jid));
RAYO_SEND(PROMPT_COMPONENT(prompt)->output_jid, RAYO_MESSAGE_CREATE_DUP(prompt, iq)); RAYO_SEND_MESSAGE_DUP(prompt, PROMPT_COMPONENT(prompt)->output_jid, iq);
return NULL; return NULL;
} }
case PCS_START_INPUT_TIMERS: case PCS_START_INPUT_TIMERS:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论