diff options
-rw-r--r-- | pn_cmd_node.c | 13 | ||||
-rw-r--r-- | pn_cmd_node.h | 3 | ||||
-rw-r--r-- | pn_ns.c | 2 | ||||
-rw-r--r-- | pn_trans.h | 5 |
4 files changed, 20 insertions, 3 deletions
diff --git a/pn_cmd_node.c b/pn_cmd_node.c index 327f19c..991d6c8 100644 --- a/pn_cmd_node.c +++ b/pn_cmd_node.c @@ -39,6 +39,7 @@ show_cmd(bool incoming, static void send_valist(struct pn_cmd_node *self, + pn_trans_cb_t cb, const char *command, const char *format, va_list args) @@ -51,6 +52,7 @@ send_valist(struct pn_cmd_node *self, trans->id = ++priv->counter; trans->command = g_strdup(command); trans->params = g_strdup_vprintf(format, args); + trans->cb = cb; g_hash_table_insert(priv->transactions, GINT_TO_POINTER(trans->id), trans); @@ -69,13 +71,14 @@ send_valist(struct pn_cmd_node *self, void pn_cmd_node_send(struct pn_cmd_node *self, + pn_trans_cb_t cb, const char *command, const char *format, ...) { va_list args; va_start(args, format); - send_valist(self, command, format, args); + send_valist(self, cb, command, format, args); va_end(args); } @@ -89,13 +92,19 @@ got_command(struct pn_cmd_node *self, struct pn_cmd_node_priv *priv = self->priv; struct pn_cmd *cmd; struct pn_trans *trans; + pn_trans_cb_t cb = NULL; show_cmd(true, string, length); cmd = pn_cmd_new_from_string(string, length); if (cmd->tr_id) trans = g_hash_table_lookup(priv->transactions, GINT_TO_POINTER(cmd->tr_id)); - pn_warn(self, "unhandled command: %.*s", length, string); + if (trans) + cb = trans->cb; + if (cb) + cb(self, cmd); + else + pn_warn(self, "unhandled command: %.*s", length, string); pn_cmd_free(cmd); } diff --git a/pn_cmd_node.h b/pn_cmd_node.h index f43c7ff..ae2dc5a 100644 --- a/pn_cmd_node.h +++ b/pn_cmd_node.h @@ -16,10 +16,13 @@ struct pn_cmd_node_class { #define PN_CMD_NODE_TYPE (pn_cmd_node_get_type()) #define PN_CMD_NODE(obj)(G_TYPE_CHECK_INSTANCE_CAST((obj), PN_CMD_NODE_TYPE, struct pn_cmd_node)) +#include "pn_trans.h" + struct pn_cmd_node *pn_cmd_node_new(void); void pn_cmd_node_free(struct pn_cmd_node *node); void pn_cmd_node_send(struct pn_cmd_node *node, + pn_trans_cb_t cb, const char *command, const char *format, ...); @@ -33,7 +33,7 @@ pn_ns_free(struct pn_ns *ns) static void open_cb(struct pn_ns *self) { - pn_cmd_node_send(PN_CMD_NODE(self), "VER", "MSNP12"); + pn_cmd_node_send(PN_CMD_NODE(self), NULL, "VER", "MSNP12"); } /* GObject stuff */ @@ -1,10 +1,15 @@ #ifndef PN_TRANS_H #define PN_TRANS_H +struct pn_cmd; + +typedef void (*pn_trans_cb_t)(void *node, struct pn_cmd *cmd); + struct pn_trans { int id; char *command; char *params; + pn_trans_cb_t cb; }; struct pn_trans *pn_trans_new(void); |