struct stasis_cp_all *stasis_cp_all_create(const char *name, snapshot_get_id id_fn) { RAII_VAR(char *, cached_name, NULL, ast_free); RAII_VAR(struct stasis_cp_all *, all, NULL, ao2_cleanup); all = ao2_alloc(sizeof(*all), all_dtor); if (!all) { return NULL; } ast_asprintf(&cached_name, "%s-cached", name); if (!cached_name) { return NULL; } all->topic = stasis_topic_create(name); all->topic_cached = stasis_topic_create(cached_name); all->cache = stasis_cache_create(id_fn); all->forward_all_to_cached = stasis_forward_all(all->topic, all->topic_cached); if (!all->topic || !all->topic_cached || !all->cache || !all->forward_all_to_cached) { return NULL; } ao2_ref(all, +1); return all; }
struct stasis_cp_all *stasis_cp_all_create(const char *name, snapshot_get_id id_fn) { char *cached_name = NULL; struct stasis_cp_all *all; static int cache_id; all = ao2_t_alloc(sizeof(*all), all_dtor, name); if (!all) { return NULL; } ast_asprintf(&cached_name, "cache_pattern:%d/%s", ast_atomic_fetchadd_int(&cache_id, +1), name); if (!cached_name) { ao2_ref(all, -1); return NULL; } all->topic = stasis_topic_create(name); all->topic_cached = stasis_topic_create(cached_name); ast_free(cached_name); all->cache = stasis_cache_create(id_fn); all->forward_all_to_cached = stasis_forward_all(all->topic, all->topic_cached); if (!all->topic || !all->topic_cached || !all->cache || !all->forward_all_to_cached) { ao2_ref(all, -1); return NULL; } return all; }
int ast_stasis_channels_init(void) { int res = 0; ast_register_cleanup(stasis_channels_cleanup); channel_cache_all = stasis_cp_all_create("ast_channel_topic_all", channel_snapshot_get_id); if (!channel_cache_all) { return -1; } res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_agent_login_type); res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_agent_logoff_type); channel_cache_by_name = stasis_cache_create(channel_snapshot_get_name); if (!channel_cache_by_name) { return -1; } /* This should be initialized before the caching topic */ res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_snapshot_type); channel_by_name_topic = stasis_caching_topic_create( stasis_cp_all_topic(channel_cache_all), channel_cache_by_name); if (!channel_by_name_topic) { return -1; } res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_dial_type); res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_varset_type); res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_user_event_type); res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_hangup_request_type); res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_dtmf_begin_type); res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_dtmf_end_type); res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_hold_type); res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_unhold_type); res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_chanspy_start_type); res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_chanspy_stop_type); res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_fax_type); res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_hangup_handler_type); res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_moh_start_type); res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_moh_stop_type); res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_monitor_start_type); res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_monitor_stop_type); return res; }