Asterisk - The Open Source Telephony Project  21.4.1
Functions
bridge_internal.h File Reference

Private Bridging API. More...

Go to the source code of this file.

Functions

struct ast_bridgebridge_alloc (size_t size, const struct ast_bridge_methods *v_table)
 
struct ast_bridgebridge_base_init (struct ast_bridge *self, uint32_t capabilities, unsigned int flags, const char *creator, const char *name, const char *id)
 Initialize the base class of the bridge. More...
 
void bridge_dissolve (struct ast_bridge *bridge, int cause)
 
void bridge_do_merge (struct ast_bridge *dst_bridge, struct ast_bridge *src_bridge, struct ast_bridge_channel **kick_me, unsigned int num_kick, unsigned int optimized)
 
int bridge_do_move (struct ast_bridge *dst_bridge, struct ast_bridge_channel *bridge_channel, int attempt_recovery, unsigned int optimized)
 
struct ast_bridge_channelbridge_find_channel (struct ast_bridge *bridge, struct ast_channel *chan)
 
void bridge_merge_inhibit_nolock (struct ast_bridge *bridge, int request)
 
void bridge_reconfigured (struct ast_bridge *bridge, unsigned int colp_update)
 
struct ast_bridgebridge_register (struct ast_bridge *bridge)
 Register the new bridge with the system. More...
 

Detailed Description

Private Bridging API.

Functions in this file are intended to be used by the Bridging API, bridge mixing technologies, and bridge sub-classes. Users of bridges that do not fit those three categories should not use the API defined in this file.

Author
Mark Michelson mmich.nosp@m.elso.nosp@m.n@dig.nosp@m.ium..nosp@m.com

See Also:

Definition in file bridge_internal.h.

Function Documentation

struct ast_bridge* bridge_base_init ( struct ast_bridge self,
uint32_t  capabilities,
unsigned int  flags,
const char *  creator,
const char *  name,
const char *  id 
)

Initialize the base class of the bridge.

Parameters
selfBridge to operate upon. (Tolerates a NULL pointer)
capabilitiesThe capabilities that we require to be used on the bridge
flagsFlags that will alter the behavior of the bridge
creatorEntity that created the bridge (optional)
nameName given to the bridge by its creator (optional, requires named creator)
idUnique ID given to the bridge by its creator (optional)
Returns
self on success
Return values
NULLon failure, self is already destroyed

Example usage:

1 struct ast_bridge *bridge;
2 bridge = bridge_alloc(sizeof(*bridge), &ast_bridge_base_v_table);
3 bridge = bridge_base_init(bridge, AST_BRIDGE_CAPABILITY_1TO1MIX, AST_BRIDGE_FLAG_DISSOLVE_HANGUP, NULL, NULL, NULL);

This creates a no frills two party bridge that will be destroyed once one of the channels hangs up.

Definition at line 742 of file bridge.c.

References ao2_ref, AST_BRIDGE_FLAG_INVISIBLE, ast_bridge_topic(), ast_debug, ast_string_field_set, ast_tvnow(), ast_uuid_generate_str(), find_best_technology(), and ast_bridge::uniqueid.

Referenced by ast_bridge_base_new(), ast_bridge_basic_new(), and bridge_parking_new().

743 {
744  char uuid_hold[AST_UUID_STR_LEN];
745 
746  if (!self) {
747  return NULL;
748  }
749 
750  if (!ast_strlen_zero(id)) {
751  ast_string_field_set(self, uniqueid, id);
752  } else {
753  ast_uuid_generate_str(uuid_hold, AST_UUID_STR_LEN);
754  ast_string_field_set(self, uniqueid, uuid_hold);
755  }
756  ast_string_field_set(self, creator, creator);
757  if (!ast_strlen_zero(creator)) {
758  ast_string_field_set(self, name, name);
759  }
760 
761  ast_set_flag(&self->feature_flags, flags);
762  self->allowed_capabilities = capabilities;
763 
764  if (!(flags & AST_BRIDGE_FLAG_INVISIBLE)) {
765  if (bridge_topics_init(self) != 0) {
766  ast_log(LOG_WARNING, "Bridge %s: Could not initialize topics\n",
767  self->uniqueid);
768  ao2_ref(self, -1);
769  return NULL;
770  }
771  }
772 
773  /* Use our helper function to find the "best" bridge technology. */
774  self->technology = find_best_technology(capabilities, self);
775  if (!self->technology) {
776  ast_log(LOG_WARNING, "Bridge %s: Could not create class %s. No technology to support it.\n",
777  self->uniqueid, self->v_table->name);
778  ao2_ref(self, -1);
779  return NULL;
780  }
781 
782  /* Pass off the bridge to the technology to manipulate if needed */
783  ast_debug(1, "Bridge %s: calling %s technology constructor\n",
784  self->uniqueid, self->technology->name);
785  if (self->technology->create && self->technology->create(self)) {
786  ast_log(LOG_WARNING, "Bridge %s: failed to setup bridge technology %s\n",
787  self->uniqueid, self->technology->name);
788  ao2_ref(self, -1);
789  return NULL;
790  }
791  ast_debug(1, "Bridge %s: calling %s technology start\n",
792  self->uniqueid, self->technology->name);
793  if (self->technology->start && self->technology->start(self)) {
794  ast_log(LOG_WARNING, "Bridge %s: failed to start bridge technology %s\n",
795  self->uniqueid, self->technology->name);
796  ao2_ref(self, -1);
797  return NULL;
798  }
799 
800  if (!(flags & AST_BRIDGE_FLAG_INVISIBLE)) {
801  if (!ast_bridge_topic(self)) {
802  ao2_ref(self, -1);
803  return NULL;
804  }
805  }
806 
807  self->creationtime = ast_tvnow();
808 
809  return self;
810 }
struct ast_flags feature_flags
Definition: bridge.h:369
const ast_string_field uniqueid
Definition: bridge.h:401
const char * name
Definition: bridge.h:259
int(* start)(struct ast_bridge *bridge)
Request a bridge technology instance start operations.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:159
static struct ast_bridge_technology * find_best_technology(uint32_t capabilities, struct ast_bridge *bridge)
Helper function used to find the "best" bridge technology given specified capabilities.
Definition: bridge.c:499
struct ast_bridge_technology * technology
Definition: bridge.h:355
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ast_debug(level,...)
Log a DEBUG message.
const struct ast_bridge_methods * v_table
Definition: bridge.h:351
char * ast_uuid_generate_str(char *buf, size_t size)
Generate a UUID string.
Definition: uuid.c:141
struct stasis_topic * ast_bridge_topic(struct ast_bridge *bridge)
A topic which publishes the events for a particular bridge.
int(* create)(struct ast_bridge *bridge)
Create a bridge technology instance for a bridge.
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:521
struct ast_bridge* bridge_register ( struct ast_bridge bridge)

Register the new bridge with the system.

Since
12.0.0
Parameters
bridgeWhat to register. (Tolerates a NULL pointer)
1 struct ast_bridge *ast_bridge_basic_new(uint32_t capabilities, int flags, uint32 dtmf_features)
2 {
3  void *bridge;
4 
5  bridge = bridge_alloc(sizeof(struct ast_bridge_basic), &ast_bridge_basic_v_table);
6  bridge = bridge_base_init(bridge, capabilities, flags);
7  bridge = ast_bridge_basic_init(bridge, dtmf_features);
8  bridge = bridge_register(bridge);
9  return bridge;
10 }
Note
This must be done after a bridge constructor has completed setting up the new bridge but before it returns.
After a bridge is registered, ast_bridge_destroy() must eventually be called to get rid of the bridge.
Returns
bridge on success.
Return values
NULLon error.

Definition at line 691 of file bridge.c.

References ao2_link, ast_bridge_destroy(), ast_bridge_lock, ast_bridge_publish_state(), ast_bridge_unlock, and ast_bridge::construction_completed.

Referenced by ast_bridge_base_new(), ast_bridge_basic_new(), and bridge_parking_new().

692 {
693  if (bridge) {
694  bridge->construction_completed = 1;
695  ast_bridge_lock(bridge);
696  ast_bridge_publish_state(bridge);
697  ast_bridge_unlock(bridge);
698  if (!ao2_link(bridges, bridge)) {
699  ast_bridge_destroy(bridge, 0);
700  bridge = NULL;
701  }
702  }
703  return bridge;
704 }
int ast_bridge_destroy(struct ast_bridge *bridge, int cause)
Destroy a bridge.
Definition: bridge.c:944
static struct ao2_container * bridges
Definition: bridge.c:123
#define ast_bridge_unlock(bridge)
Unlock the bridge.
Definition: bridge.h:481
#define ast_bridge_lock(bridge)
Lock the bridge.
Definition: bridge.h:470
unsigned int construction_completed
Definition: bridge.h:392
void ast_bridge_publish_state(struct ast_bridge *bridge)
Publish the state of a bridge.
#define ao2_link(container, obj)
Add an object to a container.
Definition: astobj2.h:1532