Migrate a large number of AMI events over to Stasis-Core
[asterisk/asterisk.git] / main / stasis_channels.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2013, Digium, Inc.
5  *
6  * Matt Jordan <mjordan@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18
19 /*! \file
20  *
21  * \brief Stasis Messages and Data Types for Channel Objects
22  *
23  * \author \verbatim Matt Jordan <mjordan@digium.com> \endverbatim
24  *
25  */
26
27 /*** MODULEINFO
28         <support_level>core</support_level>
29  ***/
30
31 #include "asterisk.h"
32
33 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
34
35 #include "asterisk/stasis.h"
36 #include "asterisk/astobj2.h"
37 #include "asterisk/stasis_channels.h"
38
39 #define NUM_MULTI_CHANNEL_BLOB_BUCKETS 7
40
41 /*!
42  * @{ \brief Define channel message types.
43  */
44 STASIS_MESSAGE_TYPE_DEFN(ast_channel_snapshot_type);
45 STASIS_MESSAGE_TYPE_DEFN(ast_channel_dial_type);
46 STASIS_MESSAGE_TYPE_DEFN(ast_channel_varset_type);
47 STASIS_MESSAGE_TYPE_DEFN(ast_channel_user_event_type);
48 STASIS_MESSAGE_TYPE_DEFN(ast_channel_hangup_request_type);
49 STASIS_MESSAGE_TYPE_DEFN(ast_channel_dtmf_begin_type);
50 STASIS_MESSAGE_TYPE_DEFN(ast_channel_dtmf_end_type);
51 STASIS_MESSAGE_TYPE_DEFN(ast_channel_chanspy_start_type);
52 STASIS_MESSAGE_TYPE_DEFN(ast_channel_chanspy_stop_type);
53 STASIS_MESSAGE_TYPE_DEFN(ast_channel_fax_type);
54 STASIS_MESSAGE_TYPE_DEFN(ast_channel_hangup_handler_type);
55 STASIS_MESSAGE_TYPE_DEFN(ast_channel_moh_start_type);
56 STASIS_MESSAGE_TYPE_DEFN(ast_channel_moh_stop_type);
57 STASIS_MESSAGE_TYPE_DEFN(ast_channel_monitor_start_type);
58 STASIS_MESSAGE_TYPE_DEFN(ast_channel_monitor_stop_type);
59 /*! @} */
60
61 /*! \brief Topic for all channels */
62 struct stasis_topic *channel_topic_all;
63
64 /*! \brief Caching topic for all channels */
65 struct stasis_caching_topic *channel_topic_all_cached;
66
67 struct stasis_topic *ast_channel_topic_all(void)
68 {
69         return channel_topic_all;
70 }
71
72 struct stasis_caching_topic *ast_channel_topic_all_cached(void)
73 {
74         return channel_topic_all_cached;
75 }
76
77 static const char *channel_snapshot_get_id(struct stasis_message *message)
78 {
79         struct ast_channel_snapshot *snapshot;
80         if (ast_channel_snapshot_type() != stasis_message_type(message)) {
81                 return NULL;
82         }
83         snapshot = stasis_message_data(message);
84         return snapshot->uniqueid;
85 }
86
87 /*! \internal \brief Hash function for \ref ast_channel_snapshot objects */
88 static int channel_snapshot_hash_cb(const void *obj, const int flags)
89 {
90         const struct ast_channel_snapshot *snapshot = obj;
91         const char *name = (flags & OBJ_KEY) ? obj : snapshot->name;
92         return ast_str_case_hash(name);
93 }
94
95 /*! \internal \brief Comparison function for \ref ast_channel_snapshot objects */
96 static int channel_snapshot_cmp_cb(void *obj, void *arg, int flags)
97 {
98         struct ast_channel_snapshot *left = obj;
99         struct ast_channel_snapshot *right = arg;
100         const char *match = (flags & OBJ_KEY) ? arg : right->name;
101         return strcasecmp(left->name, match) ? 0 : (CMP_MATCH | CMP_STOP);
102 }
103
104 static void channel_snapshot_dtor(void *obj)
105 {
106         struct ast_channel_snapshot *snapshot = obj;
107         ast_string_field_free_memory(snapshot);
108 }
109
110 struct ast_channel_snapshot *ast_channel_snapshot_create(struct ast_channel *chan)
111 {
112         RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
113
114         snapshot = ao2_alloc(sizeof(*snapshot), channel_snapshot_dtor);
115         if (!snapshot || ast_string_field_init(snapshot, 1024)) {
116                 return NULL;
117         }
118
119         ast_string_field_set(snapshot, name, ast_channel_name(chan));
120         ast_string_field_set(snapshot, accountcode, ast_channel_accountcode(chan));
121         ast_string_field_set(snapshot, peeraccount, ast_channel_peeraccount(chan));
122         ast_string_field_set(snapshot, userfield, ast_channel_userfield(chan));
123         ast_string_field_set(snapshot, uniqueid, ast_channel_uniqueid(chan));
124         ast_string_field_set(snapshot, linkedid, ast_channel_linkedid(chan));
125         ast_string_field_set(snapshot, parkinglot, ast_channel_parkinglot(chan));
126         ast_string_field_set(snapshot, hangupsource, ast_channel_hangupsource(chan));
127         if (ast_channel_appl(chan)) {
128                 ast_string_field_set(snapshot, appl, ast_channel_appl(chan));
129         }
130         if (ast_channel_data(chan)) {
131                 ast_string_field_set(snapshot, data, ast_channel_data(chan));
132         }
133         ast_string_field_set(snapshot, context, ast_channel_context(chan));
134         ast_string_field_set(snapshot, exten, ast_channel_exten(chan));
135
136         ast_string_field_set(snapshot, caller_name,
137                 S_COR(ast_channel_caller(chan)->id.name.valid, ast_channel_caller(chan)->id.name.str, ""));
138         ast_string_field_set(snapshot, caller_number,
139                 S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, ""));
140
141         ast_string_field_set(snapshot, connected_name,
142                 S_COR(ast_channel_connected(chan)->id.name.valid, ast_channel_connected(chan)->id.name.str, ""));
143         ast_string_field_set(snapshot, connected_number,
144                 S_COR(ast_channel_connected(chan)->id.number.valid, ast_channel_connected(chan)->id.number.str, ""));
145         ast_string_field_set(snapshot, language, ast_channel_language(chan));
146
147         snapshot->creationtime = ast_channel_creationtime(chan);
148         snapshot->state = ast_channel_state(chan);
149         snapshot->priority = ast_channel_priority(chan);
150         snapshot->amaflags = ast_channel_amaflags(chan);
151         snapshot->hangupcause = ast_channel_hangupcause(chan);
152         snapshot->flags = *ast_channel_flags(chan);
153         snapshot->caller_pres = ast_party_id_presentation(&ast_channel_caller(chan)->id);
154
155         snapshot->manager_vars = ast_channel_get_manager_vars(chan);
156
157         ao2_ref(snapshot, +1);
158         return snapshot;
159 }
160
161 static void publish_message_for_channel_topics(struct stasis_message *message, struct ast_channel *chan)
162 {
163         if (chan) {
164                 stasis_publish(ast_channel_topic(chan), message);
165         } else {
166                 stasis_publish(ast_channel_topic_all(), message);
167         }
168 }
169
170 static void channel_blob_dtor(void *obj)
171 {
172         struct ast_channel_blob *event = obj;
173         ao2_cleanup(event->snapshot);
174         ast_json_unref(event->blob);
175 }
176
177 void ast_channel_publish_dial(struct ast_channel *caller, struct ast_channel *peer, const char *dialstring, const char *dialstatus)
178 {
179         RAII_VAR(struct ast_multi_channel_blob *, payload, NULL, ao2_cleanup);
180         RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
181         RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
182         struct ast_channel_snapshot *caller_snapshot;
183         struct ast_channel_snapshot *peer_snapshot;
184
185         ast_assert(peer != NULL);
186         blob = ast_json_pack("{s: s, s: s}",
187                              "dialstatus", S_OR(dialstatus, ""),
188                              "dialstring", S_OR(dialstring, ""));
189         if (!blob) {
190                 return;
191         }
192         payload = ast_multi_channel_blob_create(blob);
193         if (!payload) {
194                 return;
195         }
196
197         if (caller) {
198                 caller_snapshot = ast_channel_snapshot_create(caller);
199                 if (!caller_snapshot) {
200                         return;
201                 }
202                 ast_multi_channel_blob_add_channel(payload, "caller", caller_snapshot);
203         }
204
205         peer_snapshot = ast_channel_snapshot_create(peer);
206         if (!peer_snapshot) {
207                 return;
208         }
209         ast_multi_channel_blob_add_channel(payload, "peer", peer_snapshot);
210
211         msg = stasis_message_create(ast_channel_dial_type(), payload);
212         if (!msg) {
213                 return;
214         }
215
216         publish_message_for_channel_topics(msg, caller);
217 }
218
219 static struct stasis_message *create_channel_blob_message(struct ast_channel_snapshot *snapshot,
220                 struct stasis_message_type *type,
221                 struct ast_json *blob)
222
223 {
224         RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
225         RAII_VAR(struct ast_channel_blob *, obj, NULL, ao2_cleanup);
226
227         if (blob == NULL) {
228                 blob = ast_json_null();
229         }
230
231         obj = ao2_alloc(sizeof(*obj), channel_blob_dtor);
232         if (!obj) {
233                 return NULL;
234         }
235
236         if (snapshot) {
237                 obj->snapshot = snapshot;
238                 ao2_ref(obj->snapshot, +1);
239         }
240         obj->blob = ast_json_ref(blob);
241
242         msg = stasis_message_create(type, obj);
243         if (!msg) {
244                 return NULL;
245         }
246
247         ao2_ref(msg, +1);
248         return msg;
249 }
250
251 struct stasis_message *ast_channel_cached_blob_create(struct ast_channel *chan,
252                                                struct stasis_message_type *type,
253                                                struct ast_json *blob)
254 {
255         RAII_VAR(struct ast_channel_snapshot *, snapshot,
256                         ast_channel_snapshot_get_latest(ast_channel_uniqueid(chan)),
257                         ao2_cleanup);
258
259         return create_channel_blob_message(snapshot, type, blob);
260 }
261
262 struct stasis_message *ast_channel_blob_create(struct ast_channel *chan,
263         struct stasis_message_type *type, struct ast_json *blob)
264 {
265         RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
266
267         if (chan) {
268                 snapshot = ast_channel_snapshot_create(chan);
269         }
270
271         return create_channel_blob_message(snapshot, type, blob);
272 }
273
274 /*! \brief A channel snapshot wrapper object used in \ref ast_multi_channel_blob objects */
275 struct channel_role_snapshot {
276         struct ast_channel_snapshot *snapshot;  /*!< A channel snapshot */
277         char role[0];                                                   /*!< The role assigned to the channel */
278 };
279
280 /*! \brief A multi channel blob data structure for multi_channel_blob stasis messages */
281 struct ast_multi_channel_blob {
282         struct ao2_container *channel_snapshots;        /*!< A container holding the snapshots */
283         struct ast_json *blob;                                          /*< A blob of JSON data */
284 };
285
286 /*! \internal \brief Standard comparison function for \ref channel_role_snapshot objects */
287 static int channel_role_single_cmp_cb(void *obj, void *arg, int flags)
288 {
289         struct channel_role_snapshot *left = obj;
290         struct channel_role_snapshot *right = arg;
291         const char *match = (flags & OBJ_KEY) ? arg : right->role;
292         return strcasecmp(left->role, match) ? 0 : (CMP_MATCH | CMP_STOP);
293 }
294
295 /*! \internal \brief Multi comparison function for \ref channel_role_snapshot objects */
296 static int channel_role_multi_cmp_cb(void *obj, void *arg, int flags)
297 {
298         struct channel_role_snapshot *left = obj;
299         struct channel_role_snapshot *right = arg;
300         const char *match = (flags & OBJ_KEY) ? arg : right->role;
301         return strcasecmp(left->role, match) ? 0 : (CMP_MATCH);
302 }
303
304 /*! \internal \brief Hash function for \ref channel_role_snapshot objects */
305 static int channel_role_hash_cb(const void *obj, const int flags)
306 {
307         const struct channel_role_snapshot *snapshot = obj;
308         const char *name = (flags & OBJ_KEY) ? obj : snapshot->role;
309         return ast_str_case_hash(name);
310 }
311
312 /*! \internal \brief Destructor for \ref ast_multi_channel_blob objects */
313 static void multi_channel_blob_dtor(void *obj)
314 {
315         struct ast_multi_channel_blob *multi_blob = obj;
316
317         ao2_cleanup(multi_blob->channel_snapshots);
318         ast_json_unref(multi_blob->blob);
319 }
320
321 struct ast_multi_channel_blob *ast_multi_channel_blob_create(struct ast_json *blob)
322 {
323         RAII_VAR(struct ast_multi_channel_blob *, obj,
324                         ao2_alloc(sizeof(*obj), multi_channel_blob_dtor),
325                         ao2_cleanup);
326
327         ast_assert(blob != NULL);
328
329         if (!obj) {
330                 return NULL;
331         }
332
333         obj->channel_snapshots = ao2_container_alloc(NUM_MULTI_CHANNEL_BLOB_BUCKETS,
334                         channel_role_hash_cb, channel_role_single_cmp_cb);
335         if (!obj->channel_snapshots) {
336                 return NULL;
337         }
338
339         obj->blob = ast_json_ref(blob);
340
341         ao2_ref(obj, +1);
342         return obj;
343 }
344
345 struct ast_channel_snapshot *ast_channel_snapshot_get_latest(const char *uniqueid)
346 {
347         RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
348         struct ast_channel_snapshot *snapshot;
349
350         ast_assert(!ast_strlen_zero(uniqueid));
351
352         message = stasis_cache_get(ast_channel_topic_all_cached(),
353                         ast_channel_snapshot_type(),
354                         uniqueid);
355         if (!message) {
356                 return NULL;
357         }
358
359         snapshot = stasis_message_data(message);
360         if (!snapshot) {
361                 return NULL;
362         }
363         ao2_ref(snapshot, +1);
364         return snapshot;
365 }
366
367 static void channel_role_snapshot_dtor(void *obj)
368 {
369         struct channel_role_snapshot *role_snapshot = obj;
370         ao2_cleanup(role_snapshot->snapshot);
371 }
372
373 void ast_multi_channel_blob_add_channel(struct ast_multi_channel_blob *obj, const char *role, struct ast_channel_snapshot *snapshot)
374 {
375         RAII_VAR(struct channel_role_snapshot *, role_snapshot, NULL, ao2_cleanup);
376         int role_len = strlen(role) + 1;
377
378         if (!obj || ast_strlen_zero(role) || !snapshot) {
379                 return;
380         }
381
382         role_snapshot = ao2_alloc(sizeof(*role_snapshot) + role_len, channel_role_snapshot_dtor);
383         if (!role_snapshot) {
384                 return;
385         }
386         ast_copy_string(role_snapshot->role, role, role_len);
387         role_snapshot->snapshot = snapshot;
388         ao2_ref(role_snapshot->snapshot, +1);
389         ao2_link(obj->channel_snapshots, role_snapshot);
390 }
391
392 struct ast_channel_snapshot *ast_multi_channel_blob_get_channel(struct ast_multi_channel_blob *obj, const char *role)
393 {
394         struct channel_role_snapshot *role_snapshot;
395
396         if (!obj || ast_strlen_zero(role)) {
397                 return NULL;
398         }
399         role_snapshot = ao2_find(obj->channel_snapshots, role, OBJ_KEY);
400         /* Note that this function does not increase the ref count on snapshot */
401         if (!role_snapshot) {
402                 return NULL;
403         }
404         ao2_ref(role_snapshot, -1);
405         return role_snapshot->snapshot;
406 }
407
408 struct ao2_container *ast_multi_channel_blob_get_channels(struct ast_multi_channel_blob *obj, const char *role)
409 {
410         RAII_VAR(struct ao2_container *, ret_container,
411                 ao2_container_alloc(NUM_MULTI_CHANNEL_BLOB_BUCKETS, channel_snapshot_hash_cb, channel_snapshot_cmp_cb),
412                 ao2_cleanup);
413         struct ao2_iterator *it_role_snapshots;
414         struct channel_role_snapshot *role_snapshot;
415         char *arg;
416
417         if (!obj || ast_strlen_zero(role) || !ret_container) {
418                 return NULL;
419         }
420         arg = ast_strdupa(role);
421
422         it_role_snapshots = ao2_callback(obj->channel_snapshots, OBJ_MULTIPLE | OBJ_KEY, channel_role_multi_cmp_cb, arg);
423         if (!it_role_snapshots) {
424                 return NULL;
425         }
426
427         while ((role_snapshot = ao2_iterator_next(it_role_snapshots))) {
428                 ao2_link(ret_container, role_snapshot->snapshot);
429                 ao2_ref(role_snapshot, -1);
430         }
431         ao2_iterator_destroy(it_role_snapshots);
432
433         ao2_ref(ret_container, +1);
434         return ret_container;
435 }
436
437 struct ast_json *ast_multi_channel_blob_get_json(struct ast_multi_channel_blob *obj)
438 {
439         if (!obj) {
440                 return NULL;
441         }
442         return obj->blob;
443 }
444
445 void ast_channel_publish_snapshot(struct ast_channel *chan)
446 {
447         RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
448         RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
449
450         snapshot = ast_channel_snapshot_create(chan);
451         if (!snapshot) {
452                 return;
453         }
454
455         message = stasis_message_create(ast_channel_snapshot_type(), snapshot);
456         if (!message) {
457                 return;
458         }
459
460         ast_assert(ast_channel_topic(chan) != NULL);
461         stasis_publish(ast_channel_topic(chan), message);
462 }
463
464 void ast_channel_publish_varset(struct ast_channel *chan, const char *name, const char *value)
465 {
466         RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
467         RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
468
469         ast_assert(name != NULL);
470         ast_assert(value != NULL);
471
472         blob = ast_json_pack("{s: s, s: s}",
473                              "variable", name,
474                              "value", value);
475         if (!blob) {
476                 ast_log(LOG_ERROR, "Error creating message\n");
477                 return;
478         }
479
480         msg = ast_channel_blob_create(chan, ast_channel_varset_type(),
481                 ast_json_ref(blob));
482
483         if (!msg) {
484                 return;
485         }
486
487         publish_message_for_channel_topics(msg, chan);
488 }
489
490 void ast_publish_channel_state(struct ast_channel *chan)
491 {
492         RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
493         RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
494
495         ast_assert(chan != NULL);
496         if (!chan) {
497                 return;
498         }
499
500         snapshot = ast_channel_snapshot_create(chan);
501         if (!snapshot) {
502                 return;
503         }
504
505         message = stasis_message_create(ast_channel_snapshot_type(), snapshot);
506         if (!message) {
507                 return;
508         }
509
510         ast_assert(ast_channel_topic(chan) != NULL);
511         stasis_publish(ast_channel_topic(chan), message);
512 }
513
514 struct ast_json *ast_channel_snapshot_to_json(const struct ast_channel_snapshot *snapshot)
515 {
516         RAII_VAR(struct ast_json *, json_chan, NULL, ast_json_unref);
517
518         if (snapshot == NULL) {
519                 return NULL;
520         }
521
522         json_chan = ast_json_pack("{ s: s, s: s, s: s, s: s, s: s, s: s, s: s,"
523                                   "  s: s, s: s, s: s, s: s, s: o, s: o, s: o,"
524                                   "  s: o"
525                                   "}",
526                                   "name", snapshot->name,
527                                   "state", ast_state2str(snapshot->state),
528                                   "accountcode", snapshot->accountcode,
529                                   "peeraccount", snapshot->peeraccount,
530                                   "userfield", snapshot->userfield,
531                                   "uniqueid", snapshot->uniqueid,
532                                   "linkedid", snapshot->linkedid,
533                                   "parkinglot", snapshot->parkinglot,
534                                   "hangupsource", snapshot->hangupsource,
535                                   "appl", snapshot->appl,
536                                   "data", snapshot->data,
537                                   "dialplan", ast_json_dialplan_cep(snapshot->context, snapshot->exten, snapshot->priority),
538                                   "caller", ast_json_name_number(snapshot->caller_name, snapshot->caller_number),
539                                   "connected", ast_json_name_number(snapshot->connected_name, snapshot->connected_number),
540                                   "creationtime", ast_json_timeval(snapshot->creationtime, NULL));
541
542         return ast_json_ref(json_chan);
543 }
544
545 int ast_channel_snapshot_cep_equal(
546         const struct ast_channel_snapshot *old_snapshot,
547         const struct ast_channel_snapshot *new_snapshot)
548 {
549         ast_assert(old_snapshot != NULL);
550         ast_assert(new_snapshot != NULL);
551
552         /* We actually get some snapshots with CEP set, but before the
553          * application is set. Since empty application is invalid, we treat
554          * setting the application from nothing as a CEP change.
555          */
556         if (ast_strlen_zero(old_snapshot->appl) &&
557             !ast_strlen_zero(new_snapshot->appl)) {
558                 return 0;
559         }
560
561         return old_snapshot->priority == new_snapshot->priority &&
562                 strcmp(old_snapshot->context, new_snapshot->context) == 0 &&
563                 strcmp(old_snapshot->exten, new_snapshot->exten) == 0;
564 }
565
566 int ast_channel_snapshot_caller_id_equal(
567         const struct ast_channel_snapshot *old_snapshot,
568         const struct ast_channel_snapshot *new_snapshot)
569 {
570         ast_assert(old_snapshot != NULL);
571         ast_assert(new_snapshot != NULL);
572         return strcmp(old_snapshot->caller_number, new_snapshot->caller_number) == 0 &&
573                 strcmp(old_snapshot->caller_name, new_snapshot->caller_name) == 0;
574 }
575
576 void ast_stasis_channels_shutdown(void)
577 {
578         channel_topic_all_cached = stasis_caching_unsubscribe_and_join(channel_topic_all_cached);
579         ao2_cleanup(channel_topic_all);
580         channel_topic_all = NULL;
581         STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_snapshot_type);
582         STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_dial_type);
583         STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_varset_type);
584         STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_user_event_type);
585         STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_hangup_request_type);
586         STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_dtmf_begin_type);
587         STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_dtmf_end_type);
588         STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_chanspy_start_type);
589         STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_chanspy_stop_type);
590         STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_fax_type);
591         STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_hangup_handler_type);
592         STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_moh_start_type);
593         STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_moh_stop_type);
594         STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_monitor_start_type);
595         STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_monitor_stop_type);
596 }
597
598 void ast_stasis_channels_init(void)
599 {
600         STASIS_MESSAGE_TYPE_INIT(ast_channel_snapshot_type);
601         STASIS_MESSAGE_TYPE_INIT(ast_channel_dial_type);
602         STASIS_MESSAGE_TYPE_INIT(ast_channel_varset_type);
603         STASIS_MESSAGE_TYPE_INIT(ast_channel_user_event_type);
604         STASIS_MESSAGE_TYPE_INIT(ast_channel_hangup_request_type);
605         STASIS_MESSAGE_TYPE_INIT(ast_channel_dtmf_begin_type);
606         STASIS_MESSAGE_TYPE_INIT(ast_channel_dtmf_end_type);
607         STASIS_MESSAGE_TYPE_INIT(ast_channel_chanspy_start_type);
608         STASIS_MESSAGE_TYPE_INIT(ast_channel_chanspy_stop_type);
609         STASIS_MESSAGE_TYPE_INIT(ast_channel_fax_type);
610         STASIS_MESSAGE_TYPE_INIT(ast_channel_hangup_handler_type);
611         STASIS_MESSAGE_TYPE_INIT(ast_channel_moh_start_type);
612         STASIS_MESSAGE_TYPE_INIT(ast_channel_moh_stop_type);
613         STASIS_MESSAGE_TYPE_INIT(ast_channel_monitor_start_type);
614         STASIS_MESSAGE_TYPE_INIT(ast_channel_monitor_stop_type);
615         channel_topic_all = stasis_topic_create("ast_channel_topic_all");
616         channel_topic_all_cached = stasis_caching_topic_create(channel_topic_all, channel_snapshot_get_id);
617 }