Asterisk - The Open Source Telephony Project  GIT-master-a1fa8df
Macros | Functions
channel_internal.h File Reference

Internal channel functions for channel.c to use. More...

Go to the source code of this file.

Macros

#define ast_channel_internal_alloc(destructor, assignedid, requestor)   __ast_channel_internal_alloc(destructor, assignedid, requestor, __FILE__, __LINE__, __PRETTY_FUNCTION__)
 

Functions

struct ast_channel__ast_channel_internal_alloc (void(*destructor)(void *obj), const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *file, int line, const char *function)
 
void ast_channel_internal_cleanup (struct ast_channel *chan)
 
enum ast_channel_error ast_channel_internal_errno (void)
 
void ast_channel_internal_errno_set (enum ast_channel_error error)
 
void ast_channel_internal_finalize (struct ast_channel *chan)
 
int ast_channel_internal_is_finalized (struct ast_channel *chan)
 
void ast_channel_internal_set_stream_topology (struct ast_channel *chan, struct ast_stream_topology *topology)
 
void ast_channel_internal_set_stream_topology_change_source (struct ast_channel *chan, void *change_source)
 
int ast_channel_internal_setup_topics (struct ast_channel *chan)
 
void ast_channel_internal_swap_stream_topology (struct ast_channel *chan1, struct ast_channel *chan2)
 

Detailed Description

Internal channel functions for channel.c to use.

Definition in file channel_internal.h.

Macro Definition Documentation

◆ ast_channel_internal_alloc

#define ast_channel_internal_alloc (   destructor,
  assignedid,
  requestor 
)    __ast_channel_internal_alloc(destructor, assignedid, requestor, __FILE__, __LINE__, __PRETTY_FUNCTION__)

Definition at line 24 of file channel_internal.h.

Function Documentation

◆ __ast_channel_internal_alloc()

struct ast_channel* __ast_channel_internal_alloc ( void(*)(void *obj)  destructor,
const struct ast_assigned_ids assignedids,
const struct ast_channel requestor,
const char *  file,
int  line,
const char *  function 
)

Definition at line 1331 of file channel_internal_api.c.

References __ao2_alloc(), AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, ast_atomic_fetchadd_int(), ast_channel_unref, ast_config_AST_SYSTEM_NAME, ast_copy_string(), AST_FLAGS_ALL, AST_MAX_FDS, ast_set_flag, ast_string_field_init, ast_strlen_zero(), AST_VECTOR_INIT, ast_channel_id::creation_time, ast_channel_id::creation_unique, ast_channel::dialed_causes, DIALED_CAUSES_BUCKETS, ast_channel::linkedid, NULL, pvt_cause_cmp_fn(), pvt_cause_hash_fn(), tmp(), ast_channel_id::unique_id, ast_channel::uniqueid, and ast_assigned_ids::uniqueid.

Referenced by __ast_channel_alloc_ap(), and __ast_dummy_channel_alloc().

1332 {
1333  struct ast_channel *tmp;
1334 
1335  tmp = __ao2_alloc(sizeof(*tmp), destructor,
1336  AO2_ALLOC_OPT_LOCK_MUTEX, "", file, line, function);
1337 
1338  if (!tmp) {
1339  return NULL;
1340  }
1341 
1342  if ((ast_string_field_init(tmp, 128))) {
1343  return ast_channel_unref(tmp);
1344  }
1345 
1348  if (!tmp->dialed_causes) {
1349  return ast_channel_unref(tmp);
1350  }
1351 
1352  /* set the creation time in the uniqueid */
1353  tmp->uniqueid.creation_time = time(NULL);
1355 
1356  /* use provided id or default to historical {system-}time.# format */
1357  if (assignedids && !ast_strlen_zero(assignedids->uniqueid)) {
1358  ast_copy_string(tmp->uniqueid.unique_id, assignedids->uniqueid, sizeof(tmp->uniqueid.unique_id));
1360  snprintf(tmp->uniqueid.unique_id, sizeof(tmp->uniqueid.unique_id), "%li.%d",
1361  (long)(tmp->uniqueid.creation_time),
1362  tmp->uniqueid.creation_unique);
1363  } else {
1364  snprintf(tmp->uniqueid.unique_id, sizeof(tmp->uniqueid.unique_id), "%s-%li.%d",
1366  (long)(tmp->uniqueid.creation_time),
1367  tmp->uniqueid.creation_unique);
1368  }
1369 
1370  /* copy linked id from parent channel if known */
1371  if (requestor) {
1372  tmp->linkedid = requestor->linkedid;
1373  } else {
1374  tmp->linkedid = tmp->uniqueid;
1375  }
1376 
1377  AST_VECTOR_INIT(&tmp->fds, AST_MAX_FDS);
1378 
1379  /* Force all channel snapshot segments to be created on first use, so we don't have to check if
1380  * an old snapshot exists.
1381  */
1382  ast_set_flag(&tmp->snapshot_segment_flags, AST_FLAGS_ALL);
1383 
1384  return tmp;
1385 }
static int pvt_cause_hash_fn(const void *vpc, const int flags)
Main Channel structure associated with a channel.
struct ast_channel_id linkedid
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2949
#define ast_set_flag(p, flag)
Definition: utils.h:70
static int tmp()
Definition: bt_open.c:389
void * __ao2_alloc(size_t data_size, ao2_destructor_fn destructor_fn, unsigned int options, const char *tag, const char *file, int line, const char *func) attribute_warn_unused_result
Definition: astobj2.c:765
char unique_id[AST_MAX_UNIQUEID]
const char * uniqueid
Definition: channel.h:606
#define NULL
Definition: resample.c:96
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Definition: lock.h:755
const char * ast_config_AST_SYSTEM_NAME
Definition: options.c:170
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition: vector.h:113
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:353
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
struct ao2_container * dialed_causes
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Definition: astobj2.h:1310
#define AST_MAX_FDS
Definition: channel.h:195
#define AST_FLAGS_ALL
Definition: utils.h:196
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
struct ast_channel_id uniqueid
static int pvt_cause_cmp_fn(void *obj, void *vstr, int flags)
#define DIALED_CAUSES_BUCKETS
static int uniqueint
The monotonically increasing integer counter for channel uniqueids.

◆ ast_channel_internal_cleanup()

void ast_channel_internal_cleanup ( struct ast_channel chan)

Definition at line 1471 of file channel_internal_api.c.

References ao2_cleanup, ao2_t_ref, ast_channel_internal_set_stream_topology(), ast_string_field_free_memory, AST_VECTOR_FREE, ast_channel::dialed_causes, NULL, and stasis_forward_cancel().

Referenced by ast_channel_destructor(), and ast_dummy_channel_destructor().

1472 {
1473  if (chan->dialed_causes) {
1474  ao2_t_ref(chan->dialed_causes, -1,
1475  "done with dialed causes since the channel is going away");
1476  chan->dialed_causes = NULL;
1477  }
1478 
1480 
1481  chan->channel_forward = stasis_forward_cancel(chan->channel_forward);
1482  chan->endpoint_forward = stasis_forward_cancel(chan->endpoint_forward);
1483 
1484  ao2_cleanup(chan->topic);
1485  chan->topic = NULL;
1486 
1488 
1489  AST_VECTOR_FREE(&chan->fds);
1490 }
#define ao2_t_ref(o, delta, tag)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:463
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
Definition: vector.h:174
#define NULL
Definition: resample.c:96
struct ao2_container * dialed_causes
struct stasis_forward * stasis_forward_cancel(struct stasis_forward *forward)
Definition: stasis.c:1548
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:368
void ast_channel_internal_set_stream_topology(struct ast_channel *chan, struct ast_stream_topology *topology)

◆ ast_channel_internal_errno()

enum ast_channel_error ast_channel_internal_errno ( void  )

Definition at line 1573 of file channel_internal_api.c.

References AST_CHANNEL_ERROR_UNKNOWN, ast_threadstorage_get(), and channel_errno.

Referenced by ast_channel_errno().

1574 {
1575  enum ast_channel_error *error_code = ast_threadstorage_get(&channel_errno, sizeof(*error_code));
1576  if (!error_code) {
1578  }
1579 
1580  return *error_code;
1581 }
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
static struct ast_threadstorage channel_errno
ast_channel_error
Definition: channel.h:4988

◆ ast_channel_internal_errno_set()

void ast_channel_internal_errno_set ( enum ast_channel_error  error)

Definition at line 1563 of file channel_internal_api.c.

References ast_threadstorage_get(), channel_errno, and error().

Referenced by __ast_channel_alloc_ap().

1564 {
1565  enum ast_channel_error *error_code = ast_threadstorage_get(&channel_errno, sizeof(*error_code));
1566  if (!error_code) {
1567  return;
1568  }
1569 
1570  *error_code = error;
1571 }
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
static struct ast_threadstorage channel_errno
ast_channel_error
Definition: channel.h:4988
int error(const char *format,...)
Definition: utils/frame.c:999

◆ ast_channel_internal_finalize()

void ast_channel_internal_finalize ( struct ast_channel chan)

Definition at line 1492 of file channel_internal_api.c.

Referenced by __ast_channel_alloc_ap().

1493 {
1494  chan->finalized = 1;
1495 }

◆ ast_channel_internal_is_finalized()

int ast_channel_internal_is_finalized ( struct ast_channel chan)

Definition at line 1497 of file channel_internal_api.c.

Referenced by ast_channel_destructor().

1498 {
1499  return chan->finalized;
1500 }

◆ ast_channel_internal_set_stream_topology()

void ast_channel_internal_set_stream_topology ( struct ast_channel chan,
struct ast_stream_topology topology 
)

Definition at line 658 of file channel_internal_api.c.

References ast_stream_topology_free(), and channel_set_default_streams().

Referenced by __ast_channel_alloc_ap(), ast_channel_internal_cleanup(), ast_channel_nativeformats_set(), and ast_channel_set_stream_topology().

660 {
661  ast_stream_topology_free(chan->stream_topology);
662  chan->stream_topology = topology;
664 }
static void channel_set_default_streams(struct ast_channel *chan)
void ast_stream_topology_free(struct ast_stream_topology *topology)
Unreference and destroy a stream topology.
Definition: stream.c:743

◆ ast_channel_internal_set_stream_topology_change_source()

void ast_channel_internal_set_stream_topology_change_source ( struct ast_channel chan,
void *  change_source 
)

Definition at line 666 of file channel_internal_api.c.

Referenced by ast_channel_request_stream_topology_change(), and ast_channel_stream_topology_changed_externally().

668 {
669  chan->stream_topology_change_source = change_source;
670 }

◆ ast_channel_internal_setup_topics()

int ast_channel_internal_setup_topics ( struct ast_channel chan)

Definition at line 1527 of file channel_internal_api.c.

References ao2_ref, ast_asprintf, ast_assert, ast_atomic_fetchadd_int(), ast_channel_topic(), ast_channel_topic_all(), ast_free, ast_strlen_zero(), NULL, stasis_forward_all(), stasis_topic_create(), ast_channel_id::unique_id, and ast_channel::uniqueid.

Referenced by __ast_channel_alloc_ap(), and __ast_dummy_channel_alloc().

1528 {
1529  char *topic_name;
1530  int ret;
1531  ast_assert(chan->topic == NULL);
1532 
1533  if (ast_strlen_zero(chan->uniqueid.unique_id)) {
1534  static int dummy_id;
1535  ret = ast_asprintf(&topic_name, "channel:dummy-%d", ast_atomic_fetchadd_int(&dummy_id, +1));
1536  } else {
1537  ret = ast_asprintf(&topic_name, "channel:%s", chan->uniqueid.unique_id);
1538  }
1539 
1540  if (ret < 0) {
1541  return -1;
1542  }
1543 
1544  chan->topic = stasis_topic_create(topic_name);
1545  ast_free(topic_name);
1546  if (!chan->topic) {
1547  return -1;
1548  }
1549 
1550  chan->channel_forward = stasis_forward_all(ast_channel_topic(chan),
1552  if (!chan->channel_forward) {
1553  ao2_ref(chan->topic, -1);
1554  chan->topic = NULL;
1555  return -1;
1556  }
1557 
1558  return 0;
1559 }
char unique_id[AST_MAX_UNIQUEID]
#define ast_assert(a)
Definition: utils.h:710
#define NULL
Definition: resample.c:96
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Definition: lock.h:755
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
Definition: astmm.h:269
struct stasis_topic * ast_channel_topic_all(void)
A topic which publishes the events for all channels.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct stasis_topic * stasis_topic_create(const char *name)
Create a new topic.
Definition: stasis.c:618
struct stasis_topic * ast_channel_topic(struct ast_channel *chan)
A topic which publishes the events for a particular channel.
#define ast_free(a)
Definition: astmm.h:182
struct ast_channel_id uniqueid
struct stasis_forward * stasis_forward_all(struct stasis_topic *from_topic, struct stasis_topic *to_topic)
Create a subscription which forwards all messages from one topic to another.
Definition: stasis.c:1578

◆ ast_channel_internal_swap_stream_topology()

void ast_channel_internal_swap_stream_topology ( struct ast_channel chan1,
struct ast_channel chan2 
)

Definition at line 1628 of file channel_internal_api.c.

References ast_assert, channel_set_default_streams(), and NULL.

Referenced by channel_do_masquerade().

1630 {
1631  struct ast_stream_topology *tmp_topology;
1632 
1633  ast_assert(chan1 != NULL && chan2 != NULL);
1634 
1635  tmp_topology = chan1->stream_topology;
1636  chan1->stream_topology = chan2->stream_topology;
1637  chan2->stream_topology = tmp_topology;
1638 
1641 }
static void channel_set_default_streams(struct ast_channel *chan)
#define ast_assert(a)
Definition: utils.h:710
#define NULL
Definition: resample.c:96