chan_pjsip: initial device state on endpoints is INVALID
authorKevin Harwell <kharwell@digium.com>
Thu, 16 Jan 2014 16:46:00 +0000 (16:46 +0000)
committerKevin Harwell <kharwell@digium.com>
Thu, 16 Jan 2014 16:46:00 +0000 (16:46 +0000)
When endpoints get loaded their device state gets set to 'INVALID' because the
channel driver has not been loaded yet.  Fixed by updating the device state for
every endpoint upon load of the channel driver.

(closes issue ASTERISK-23065)
Reported by: Rusty Newton
Review: https://reviewboard.asterisk.org/r/3123/
........

Merged revisions 405643 from http://svn.asterisk.org/svn/asterisk/branches/12

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@405644 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_pjsip.c

index 4a1a6aa..56a4181 100644 (file)
@@ -1874,6 +1874,13 @@ static int chan_pjsip_incoming_ack(struct ast_sip_session *session, struct pjsip
        return 0;
 }
 
+static int update_devstate(void *obj, void *arg, int flags)
+{
+       ast_devstate_changed(AST_DEVICE_UNKNOWN, AST_DEVSTATE_CACHABLE,
+                            "PJSIP/%s", ast_sorcery_object_get_id(obj));
+       return 0;
+}
+
 static struct ast_custom_function chan_pjsip_dial_contacts_function = {
        .name = "PJSIP_DIAL_CONTACTS",
        .read = pjsip_acf_dial_contacts_read,
@@ -1897,6 +1904,8 @@ static struct ast_custom_function media_offer_function = {
  */
 static int load_module(void)
 {
+       struct ao2_container *endpoints;
+
        if (!(chan_pjsip_tech.capabilities = ast_format_cap_alloc(0))) {
                return AST_MODULE_LOAD_DECLINE;
        }
@@ -1938,6 +1947,13 @@ static int load_module(void)
                goto end;
        }
 
+       /* since endpoints are loaded before the channel driver their device
+          states get set to 'invalid', so they need to be updated */
+       if ((endpoints = ast_sip_get_endpoints())) {
+               ao2_callback(endpoints, OBJ_NODATA, update_devstate, NULL);
+               ao2_ref(endpoints, -1);
+       }
+
        return 0;
 
 end: