Exemplo n.º 1
0
void ast_system_publish_registry(const char *channeltype, const char *username, const char *domain, const char *status, const char *cause)
{
    RAII_VAR(struct ast_json *, registry, NULL, ast_json_unref);
    RAII_VAR(struct ast_json_payload *, payload, NULL, ao2_cleanup);
    RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);

    if (!ast_system_registry_type()) {
        return;
    }

    registry = ast_json_pack("{s: s, s: s, s: s, s: s, s: s, s: s}",
                             "type", "registry",
                             "channeltype", channeltype,
                             "username", username,
                             "domain", domain,
                             "status", status,
                             "cause", S_OR(cause, ""));

    if (!(payload = ast_json_payload_create(registry))) {
        return;
    }

    if (!(message = stasis_message_create(ast_system_registry_type(), payload))) {
        return;
    }

    stasis_publish(ast_system_topic(), message);
}
Exemplo n.º 2
0
/*! \brief Publish cluster discovery to \ref stasis */
static void publish_cluster_discovery_to_stasis_full(struct corosync_node *node, int joined)
{
	struct ast_json *json;
	struct ast_json_payload *payload;
	struct stasis_message *message;
	char eid[18];
	const char *addr;

	ast_eid_to_str(eid, sizeof(eid), &node->eid);
	addr = ast_sockaddr_stringify_addr(&node->addr);

	ast_log(AST_LOG_NOTICE, "Node %u (%s) at %s %s the cluster\n",
		node->id,
		eid,
		addr,
		joined ? "joined" : "left");

	json = ast_json_pack("{s: s, s: i, s: s, s: i}",
		"address", addr,
		"node_id", node->id,
		"eid", eid,
		"joined", joined);
	if (!json) {
		return;
	}

	payload = ast_json_payload_create(json);
	if (!payload) {
		ast_json_unref(json);
		return;
	}

	message = stasis_message_create(ast_cluster_discovery_type(), payload);
	if (!message) {
		ast_json_unref(json);
		ao2_ref(payload, -1);
		return;
	}

	stasis_publish(ast_system_topic(), message);
	ast_json_unref(json);
	ao2_ref(payload, -1);
	ao2_ref(message, -1);
}