Exemplo n.º 1
0
int app_subscribe_bridge(struct stasis_app *app, struct ast_bridge *bridge)
{
	if (!app || !bridge) {
		return -1;
	} else {
		RAII_VAR(struct app_forwards *, forwards, NULL, ao2_cleanup);
		SCOPED_AO2LOCK(lock, app->forwards);

		forwards = ao2_find(app->forwards, bridge->uniqueid,
			OBJ_SEARCH_KEY | OBJ_NOLOCK);

		if (!forwards) {
			/* Forwards not found, create one */
			forwards = forwards_create_bridge(app, bridge);
			if (!forwards) {
				return -1;
			}
			ao2_link_flags(app->forwards, forwards, OBJ_NOLOCK);
		}

		++forwards->interested;
		ast_debug(3, "Bridge '%s' is %d interested in %s\n", bridge->uniqueid, forwards->interested, app->name);
		return 0;
	}
}
Exemplo n.º 2
0
int app_subscribe_bridge(struct stasis_app *app, struct ast_bridge *bridge)
{
	struct app_forwards *forwards;

	if (!app) {
		return -1;
	}

	ao2_lock(app->forwards);
	/* If subscribed to all, don't subscribe again */
	forwards = ao2_find(app->forwards, BRIDGE_ALL, OBJ_SEARCH_KEY | OBJ_NOLOCK);
	if (forwards) {
		ao2_unlock(app->forwards);
		ao2_ref(forwards, -1);

		return 0;
	}

	forwards = ao2_find(app->forwards,
		bridge ? bridge->uniqueid : BRIDGE_ALL,
		OBJ_SEARCH_KEY | OBJ_NOLOCK);
	if (!forwards) {
		int res;

		/* Forwards not found, create one */
		forwards = forwards_create_bridge(app, bridge);
		if (!forwards) {
			ao2_unlock(app->forwards);

			return -1;
		}

		res = ao2_link_flags(app->forwards, forwards, OBJ_NOLOCK);
		if (!res) {
			ao2_unlock(app->forwards);
			ao2_ref(forwards, -1);

			return -1;
		}
	}

	++forwards->interested;
	ast_debug(3, "Bridge '%s' is %d interested in %s\n",
		bridge ? bridge->uniqueid : "ALL",
		forwards->interested,
		app->name);

	ao2_unlock(app->forwards);
	ao2_ref(forwards, -1);

	return 0;
}