Deprecate *_device_state_* APIs in favor of *_devstate_* APIs
authorTilghman Lesher <tilghman@meg.abyt.es>
Fri, 25 Jul 2008 21:20:03 +0000 (21:20 +0000)
committerTilghman Lesher <tilghman@meg.abyt.es>
Fri, 25 Jul 2008 21:20:03 +0000 (21:20 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@133860 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_agent.c
channels/chan_dahdi.c
channels/chan_iax2.c
channels/chan_sip.c
channels/chan_skinny.c
include/asterisk/devicestate.h
main/channel.c
main/devicestate.c

index 9a68b81..8b3e13f 100644 (file)
@@ -303,7 +303,7 @@ static void agent_devicestate_cb(const struct ast_event *event, void *unused)
                        }
                        if (strcasecmp(p->chan->name, device) == 0 || strcasecmp(basename, device) == 0) {
                                p->inherited_devicestate = state;
-                               ast_device_state_changed("Agent/%s", p->agent);
+                               ast_devstate_changed(state, "Agent/%s", p->agent);
                        }
                }
                ast_mutex_unlock(&p->lock);
@@ -518,7 +518,7 @@ static struct ast_frame *agent_read(struct ast_channel *ast)
                        }
                        p->chan = NULL;
                        p->inherited_devicestate = -1;
-                       ast_device_state_changed("Agent/%s", p->agent);
+                       ast_devstate_changed(AST_DEVICE_UNAVAILABLE, "Agent/%s", p->agent);
                        p->acknowledged = 0;
                }
        } else {
@@ -734,7 +734,7 @@ static int agent_call(struct ast_channel *ast, char *dest, int timeout)
                /* Agent hung-up */
                p->chan = NULL;
                p->inherited_devicestate = -1;
-               ast_device_state_changed("Agent/%s", p->agent);
+               ast_devstate_changed(AST_DEVICE_UNAVAILABLE, "Agent/%s", p->agent);
        }
 
        if (!res) {
@@ -856,7 +856,7 @@ static int agent_hangup(struct ast_channel *ast)
                                ast_hangup(p->chan);
                                p->chan = NULL;
                                p->inherited_devicestate = -1;
-                               ast_device_state_changed("Agent/%s", p->agent);
+                               ast_devstate_changed(AST_DEVICE_UNAVAILABLE, "Agent/%s", p->agent);
                        }
                        ast_debug(1, "Hungup, howlong is %d, autologoff is %d\n", howlong, p->autologoff);
                        if ((p->deferlogoff) || (howlong && p->autologoff && (howlong > p->autologoff))) {
@@ -890,7 +890,7 @@ static int agent_hangup(struct ast_channel *ast)
                if (persistent_agents)
                        dump_agents();
        } else {
-               ast_device_state_changed("Agent/%s", p->agent);
+               ast_devstate_changed(AST_DEVICE_NOT_INUSE, "Agent/%s", p->agent);
        }
 
        if (p->pending) {
@@ -1581,7 +1581,7 @@ static void agent_logoff_maintenance(struct agent_pvt *p, char *loginchan, long
        p->loginchan[0] ='\0';
        p->logincallerid[0] = '\0';
        p->inherited_devicestate = -1;
-       ast_device_state_changed("Agent/%s", p->agent);
+       ast_devstate_changed(AST_DEVICE_UNAVAILABLE, "Agent/%s", p->agent);
        if (persistent_agents)
                dump_agents();  
 
@@ -2082,7 +2082,7 @@ static int login_exec(struct ast_channel *chan, void *data)
                                                        check_availability(p, 0);
                                                ast_mutex_unlock(&p->lock);
                                                AST_LIST_UNLOCK(&agents);
-                                               ast_device_state_changed("Agent/%s", p->agent);
+                                               ast_devstate_changed(AST_DEVICE_NOT_INUSE, "Agent/%s", p->agent);
                                                while (res >= 0) {
                                                        ast_mutex_lock(&p->lock);
                                                        if (p->deferlogoff && p->chan) {
@@ -2103,7 +2103,7 @@ static int login_exec(struct ast_channel *chan, void *data)
                                                                if (ast_tvdiff_ms(ast_tvnow(), p->lastdisc) > 0) {
                                                                        ast_debug(1, "Wrapup time for %s expired!\n", p->agent);
                                                                        p->lastdisc = ast_tv(0, 0);
-                                                                       ast_device_state_changed("Agent/%s", p->agent);
+                                                                       ast_devstate_changed(AST_DEVICE_NOT_INUSE, "Agent/%s", p->agent);
                                                                        if (p->ackcall > 1)
                                                                                check_beep(p, 0);
                                                                        else
@@ -2152,7 +2152,7 @@ static int login_exec(struct ast_channel *chan, void *data)
                                                ast_queue_log("NONE", chan->uniqueid, agent, "AGENTLOGOFF", "%s|%ld", chan->name, logintime);
                                                ast_verb(2, "Agent '%s' logged out\n", p->agent);
                                                /* If there is no owner, go ahead and kill it now */
-                                               ast_device_state_changed("Agent/%s", p->agent);
+                                               ast_devstate_changed(AST_DEVICE_UNAVAILABLE, "Agent/%s", p->agent);
                                                if (p->dead && !p->owner) {
                                                        ast_mutex_destroy(&p->lock);
                                                        ast_mutex_destroy(&p->app_lock);
@@ -2317,7 +2317,7 @@ static void reload_agents(void)
                                cur_agent->logincallerid[0] = '\0';
                        if (cur_agent->loginstart == 0)
                                time(&cur_agent->loginstart);
-                       ast_device_state_changed("Agent/%s", cur_agent->agent); 
+                       ast_devstate_changed(AST_DEVICE_UNKNOWN, "Agent/%s", cur_agent->agent); 
                }
        }
        AST_LIST_UNLOCK(&agents);
index 9b10fa1..89da5e6 100644 (file)
@@ -6001,7 +6001,7 @@ static struct ast_channel *dahdi_new(struct dahdi_pvt *i, int state, int startpb
        /* Configure the new channel jb */
        ast_jb_configure(tmp, &global_jbconf);
 
-       ast_device_state_changed_literal(tmp->name);
+       ast_devstate_changed_literal(ast_state_chan2dev(state), tmp->name);
 
        for (v = i->vars ; v ; v = v->next)
                 pbx_builtin_setvar_helper(tmp, v->name, v->value);
index 2a1b132..e7f59c5 100644 (file)
@@ -6253,7 +6253,7 @@ static int register_verify(int callno, struct sockaddr_in *sin, struct iax_ies *
        if (expire && (expire < iaxs[callno]->expiry)) 
                iaxs[callno]->expiry = expire;
 
-       ast_device_state_changed("IAX2/%s", p->name); /* Activate notification */
+       ast_devstate_changed(AST_DEVICE_UNKNOWN, "IAX2/%s", p->name); /* Activate notification */
 
        res = 0;
 
@@ -6764,7 +6764,7 @@ static void __expire_registry(const void *data)
        if (!ast_test_flag(peer, IAX_TEMPONLY))
                ast_db_del("IAX/Registry", peer->name);
        register_peer_exten(peer, 0);
-       ast_device_state_changed("IAX2/%s", peer->name); /* Activate notification */
+       ast_devstate_changed(AST_DEVICE_UNAVAILABLE, "IAX2/%s", peer->name); /* Activate notification */
        if (iax2_regfunk)
                iax2_regfunk(peer->name, 0);
 
@@ -6814,7 +6814,7 @@ static void reg_source_db(struct iax2_peer *p)
                                                        peer_unref(p);
                                                }
                                        }
-                                       ast_device_state_changed("IAX2/%s", p->name); /* Activate notification */
+                                       ast_devstate_changed(AST_DEVICE_UNKNOWN, "IAX2/%s", p->name); /* Activate notification */
                                        p->expire = iax2_sched_add(sched, (p->expiry + 10) * 1000, expire_registry, peer_ref(p));
                                        if (p->expire == -1)
                                                peer_unref(p);
@@ -6881,14 +6881,14 @@ static int update_registry(struct sockaddr_in *sin, int callno, char *devtype, i
                                            ast_test_flag(&iaxs[callno]->state, IAX_STATE_AUTHENTICATED) ? "AUTHENTICATED" : "UNAUTHENTICATED", ast_inet_ntoa(sin->sin_addr), ntohs(sin->sin_port));
                        manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: IAX2\r\nPeer: IAX2/%s\r\nPeerStatus: Registered\r\n", p->name);
                        register_peer_exten(p, 1);
-                       ast_device_state_changed("IAX2/%s", p->name); /* Activate notification */
+                       ast_devstate_changed(AST_DEVICE_UNKNOWN, "IAX2/%s", p->name); /* Activate notification */
                } else if (!ast_test_flag(p, IAX_TEMPONLY)) {
                        ast_verb(3, "Unregistered IAX2 '%s' (%s)\n", p->name,
                                            ast_test_flag(&iaxs[callno]->state, IAX_STATE_AUTHENTICATED) ? "AUTHENTICATED" : "UNAUTHENTICATED");
                        manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: IAX2\r\nPeer: IAX2/%s\r\nPeerStatus: Unregistered\r\n", p->name);
                        register_peer_exten(p, 0);
                        ast_db_del("IAX/Registry", p->name);
-                       ast_device_state_changed("IAX2/%s", p->name); /* Activate notification */
+                       ast_devstate_changed(AST_DEVICE_UNAVAILABLE, "IAX2/%s", p->name); /* Activate notification */
                }
                /* Update the host */
                /* Verify that the host is really there */
@@ -8816,13 +8816,13 @@ retryowner2:
                                                if (iaxs[fr->callno]->pingtime <= peer->maxms) {
                                                        ast_log(LOG_NOTICE, "Peer '%s' is now REACHABLE! Time: %d\n", peer->name, iaxs[fr->callno]->pingtime);
                                                        manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: IAX2\r\nPeer: IAX2/%s\r\nPeerStatus: Reachable\r\nTime: %d\r\n", peer->name, iaxs[fr->callno]->pingtime); 
-                                                       ast_device_state_changed("IAX2/%s", peer->name); /* Activate notification */
+                                                       ast_devstate_changed(AST_DEVICE_NOT_INUSE, "IAX2/%s", peer->name); /* Activate notification */
                                                }
                                        } else if ((peer->historicms > 0) && (peer->historicms <= peer->maxms)) {
                                                if (iaxs[fr->callno]->pingtime > peer->maxms) {
                                                        ast_log(LOG_NOTICE, "Peer '%s' is now TOO LAGGED (%d ms)!\n", peer->name, iaxs[fr->callno]->pingtime);
                                                        manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: IAX2\r\nPeer: IAX2/%s\r\nPeerStatus: Lagged\r\nTime: %d\r\n", peer->name, iaxs[fr->callno]->pingtime); 
-                                                       ast_device_state_changed("IAX2/%s", peer->name); /* Activate notification */
+                                                       ast_devstate_changed(AST_DEVICE_UNAVAILABLE, "IAX2/%s", peer->name); /* Activate notification */
                                                }
                                        }
                                        peer->lastms = iaxs[fr->callno]->pingtime;
@@ -9863,7 +9863,7 @@ static void __iax2_poke_noanswer(const void *data)
        if (peer->lastms > -1) {
                ast_log(LOG_NOTICE, "Peer '%s' is now UNREACHABLE! Time: %d\n", peer->name, peer->lastms);
                manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: IAX2\r\nPeer: IAX2/%s\r\nPeerStatus: Unreachable\r\nTime: %d\r\n", peer->name, peer->lastms);
-               ast_device_state_changed("IAX2/%s", peer->name); /* Activate notification */
+               ast_devstate_changed(AST_DEVICE_UNAVAILABLE, "IAX2/%s", peer->name); /* Activate notification */
        }
        if ((callno = peer->callno) > 0) {
                ast_mutex_lock(&iaxsl[callno]);
index 89cf846..746edfd 100644 (file)
@@ -4691,7 +4691,7 @@ static int update_call_counter(struct sip_pvt *fup, int event)
                ast_log(LOG_ERROR, "update_call_counter(%s, %d) called with no event!\n", name, event);
        }
        if (p) {
-               ast_device_state_changed("SIP/%s", p->name);
+               ast_devstate_changed(AST_DEVICE_UNKNOWN, "SIP/%s", p->name);
                unref_peer(p, "update_call_counter: unref_peer from call counter");
        } 
        return 0;
@@ -10035,7 +10035,7 @@ static int expire_register(const void *data)
        
        manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: SIP\r\nPeer: SIP/%s\r\nPeerStatus: Unregistered\r\nCause: Expired\r\n", peer->name);
        register_peer_exten(peer, FALSE);       /* Remove regexten */
-       ast_device_state_changed("SIP/%s", peer->name);
+       ast_devstate_changed(AST_DEVICE_UNAVAILABLE, "SIP/%s", peer->name);
 
        /* Do we need to release this peer from memory? 
                Only for realtime peers and autocreated peers
@@ -10660,7 +10660,7 @@ static void sip_peer_hold(struct sip_pvt *p, int hold)
        ast_atomic_fetchadd_int(&peer->onHold, (hold ? +1 : -1));
 
        /* Request device state update */
-       ast_device_state_changed("SIP/%s", peer->name);
+       ast_devstate_changed(hold ? AST_DEVICE_ONHOLD : AST_DEVICE_INUSE, "SIP/%s", peer->name);
        unref_peer(peer, "sip_peer_hold: from find_peer operation");
        
        return;
@@ -10911,7 +10911,7 @@ static enum check_auth_result register_verify(struct sip_pvt *p, struct sockaddr
                }
        }
        if (!res) {
-               ast_device_state_changed("SIP/%s", peer->name);
+               ast_devstate_changed(AST_DEVICE_NOT_INUSE, "SIP/%s", peer->name);
        }
        if (res < 0) {
                switch (res) {
@@ -15708,7 +15708,7 @@ static void handle_response_peerpoke(struct sip_pvt *p, int resp, struct sip_req
 
                ast_log(LOG_NOTICE, "Peer '%s' is now %s. (%dms / %dms)\n",
                        peer->name, s, pingtime, peer->maxms);
-               ast_device_state_changed("SIP/%s", peer->name);
+               ast_devstate_changed(is_reachable ? AST_DEVICE_NOT_INUSE : AST_DEVICE_UNAVAILABLE, "SIP/%s", peer->name);
                manager_event(EVENT_FLAG_SYSTEM, "PeerStatus",
                        "ChannelType: SIP\r\nPeer: SIP/%s\r\nPeerStatus: %s\r\nTime: %d\r\n",
                        peer->name, s, pingtime);
@@ -19869,7 +19869,7 @@ static int sip_poke_noanswer(const void *data)
        }
        
        peer->lastms = -1;
-       ast_device_state_changed("SIP/%s", peer->name);
+       ast_devstate_changed(AST_DEVICE_UNAVAILABLE, "SIP/%s", peer->name);
        /* Try again quickly */
        AST_SCHED_REPLACE(peer->pokeexpire, sched, 
                DEFAULT_FREQ_NOTOK, sip_poke_peer_s, peer);
index 96cebdc..c7d2c9b 100644 (file)
@@ -1786,7 +1786,7 @@ static int skinny_register(struct skinny_req *req, struct skinnysession *s)
                        }
                        AST_LIST_TRAVERSE(&d->lines, l, list) {
                                register_exten(l);
-                               ast_device_state_changed("Skinny/%s@%s", l->name, d->name);
+                               ast_devstate_changed(AST_DEVICE_NOT_INUSE, "Skinny/%s@%s", l->name, d->name);
                        }
                        break;
                }
@@ -1816,7 +1816,7 @@ static int skinny_unregister(struct skinny_req *req, struct skinnysession *s)
                }
                AST_LIST_TRAVERSE(&d->lines, l, list) {
                        unregister_exten(l);
-                       ast_device_state_changed("Skinny/%s@%s", l->name, d->name);
+                       ast_devstate_changed(AST_DEVICE_UNAVAILABLE, "Skinny/%s@%s", l->name, d->name);
                }
        }
 
@@ -4623,8 +4623,6 @@ static int handle_stimulus_message(struct skinny_req *req, struct skinnysession
 
                l->hookstate = SKINNY_OFFHOOK;
 
-               ast_device_state_changed("Skinny/%s@%s", l->name, d->name);
-
                if (sub && sub->outgoing) {
                        /* We're answering a ringing call */
                        ast_queue_control(sub->owner, AST_CONTROL_ANSWER);
@@ -4665,7 +4663,7 @@ static int handle_stimulus_message(struct skinny_req *req, struct skinnysession
                        ast_verb(1, "RECEIVED UNKNOWN STIMULUS:  %d(%d/%d)\n", event, instance, callreference);
                break;
        }
-       ast_device_state_changed("Skinny/%s@%s", l->name, d->name);
+       ast_devstate_changed(AST_DEVICE_UNKNOWN, "Skinny/%s@%s", l->name, d->name);
 
        return 1;
 }
@@ -4715,7 +4713,7 @@ static int handle_offhook_message(struct skinny_req *req, struct skinnysession *
        transmit_ringer_mode(s, SKINNY_RING_OFF);
        l->hookstate = SKINNY_OFFHOOK;
 
-       ast_device_state_changed("Skinny/%s@%s", l->name, d->name);
+       ast_devstate_changed(AST_DEVICE_INUSE, "Skinny/%s@%s", l->name, d->name);
 
        if (sub && sub->onhold) {
                return 1;
@@ -4787,7 +4785,7 @@ static int handle_onhook_message(struct skinny_req *req, struct skinnysession *s
                return 0;
        }
 
-       ast_device_state_changed("Skinny/%s@%s", l->name, d->name);
+       ast_devstate_changed(AST_DEVICE_NOT_INUSE, "Skinny/%s@%s", l->name, d->name);
 
        if (sub->onhold) {
                return 0;
@@ -5316,7 +5314,7 @@ static int handle_soft_key_event_message(struct skinny_req *req, struct skinnyse
                return 0;
        }
 
-       ast_device_state_changed("Skinny/%s@%s", l->name, d->name);
+       ast_devstate_changed(AST_DEVICE_INUSE, "Skinny/%s@%s", l->name, d->name);
 
        switch(event) {
        case SOFTKEY_NONE:
@@ -5517,6 +5515,7 @@ static int handle_soft_key_event_message(struct skinny_req *req, struct skinnyse
                        }
 
                        transmit_callstate(s, l->instance, l->hookstate, sub->callid);
+                       ast_devstate_changed(AST_DEVICE_NOT_INUSE, "Skinny/%s@%s", l->name, d->name);
                        if (skinnydebug)
                                ast_verb(1, "Skinny %s@%s went on hook\n", l->name, d->name);
                        if (l->transfer && sub->xferor && sub->owner->_state >= AST_STATE_RING) {
@@ -5541,6 +5540,7 @@ static int handle_soft_key_event_message(struct skinny_req *req, struct skinnyse
                        }
                        if ((l->hookstate == SKINNY_ONHOOK) && (AST_LIST_NEXT(sub, list) && !AST_LIST_NEXT(sub, list)->rtp)) {
                                do_housekeeping(s);
+                               ast_devstate_changed(AST_DEVICE_NOT_INUSE, "Skinny/%s@%s", l->name, d->name);
                        }
                }
                break;
@@ -5633,7 +5633,6 @@ static int handle_soft_key_event_message(struct skinny_req *req, struct skinnyse
                        ast_verb(1, "Received unknown Softkey Event: %d(%d/%d)\n", event, instance, callreference);
                break;
        }
-       ast_device_state_changed("Skinny/%s@%s", l->name, d->name);
 
        return 1;
 }
index 50e43ce..b202d02 100644 (file)
@@ -61,6 +61,13 @@ enum ast_device_state {
 /*! \brief Devicestate provider call back */
 typedef enum ast_device_state (*ast_devstate_prov_cb_type)(const char *data);
 
+/*!
+ * \brief Convert channel state to devicestate
+ *
+ * \param chanstate Current channel state
+ */
+enum ast_device_state ast_state_chan2dev(enum ast_channel_state chanstate);
+
 /*! 
  * \brief Convert device state to text string for output 
  *
@@ -158,7 +165,7 @@ int ast_devstate_changed_literal(enum ast_device_state state, const char *device
  * \note This is deprecated in favor of ast_devstate_changed()
  */
 int ast_device_state_changed(const char *fmt, ...)
-       __attribute__ ((format (printf, 1, 2)));
+       __attribute__ ((deprecated,format (printf, 1, 2)));
 
 /*! 
  * \brief Tells Asterisk the State for Device is changed 
@@ -173,7 +180,8 @@ int ast_device_state_changed(const char *fmt, ...)
  *
  * \note This is deprecated in favor of ast_devstate_changed_literal()
  */
-int ast_device_state_changed_literal(const char *device);
+int ast_device_state_changed_literal(const char *device)
+       __attribute__ ((deprecated));
 
 /*! 
  * \brief Add device state provider 
index d562afd..1b39608 100644 (file)
@@ -1364,7 +1364,7 @@ void ast_channel_free(struct ast_channel *chan)
        ast_free(chan);
        AST_RWLIST_UNLOCK(&channels);
 
-       ast_device_state_changed_literal(name);
+       ast_devstate_changed_literal(AST_DEVICE_NOT_INUSE, name);
 }
 
 struct ast_datastore *ast_channel_datastore_alloc(const struct ast_datastore_info *info, const char *uid)
@@ -4100,7 +4100,7 @@ int ast_setstate(struct ast_channel *chan, enum ast_channel_state state)
        }
 
        chan->_state = state;
-       ast_device_state_changed_literal(name);
+       ast_devstate_changed_literal(ast_state_chan2dev(state), name);
        /* setstate used to conditionally report Newchannel; this is no more */
        manager_event(EVENT_FLAG_CALL,
                      "Newstate",
index c7fe08e..1bf19f6 100644 (file)
@@ -140,6 +140,24 @@ static const char *devstatestring[] = {
        /* 8 AST_DEVICE_ONHOLD */       "On Hold"       /*!< On Hold */
 };
 
+/*!\brief Mapping for channel states to device states */
+static const struct chan2dev {
+       enum ast_channel_state chan;
+       enum ast_device_state dev;
+} chan2dev[] = {
+       { AST_STATE_DOWN,            AST_DEVICE_NOT_INUSE },
+       { AST_STATE_RESERVED,        AST_DEVICE_INUSE },
+       { AST_STATE_OFFHOOK,         AST_DEVICE_INUSE },
+       { AST_STATE_DIALING,         AST_DEVICE_INUSE },
+       { AST_STATE_RING,            AST_DEVICE_INUSE },
+       { AST_STATE_RINGING,         AST_DEVICE_RINGING },
+       { AST_STATE_UP,              AST_DEVICE_INUSE },
+       { AST_STATE_BUSY,            AST_DEVICE_BUSY },
+       { AST_STATE_DIALING_OFFHOOK, AST_DEVICE_INUSE },
+       { AST_STATE_PRERING,         AST_DEVICE_RINGING },
+       { -100,                      -100 },
+};
+
 /*! \brief  A device state provider (not a channel) */
 struct devstate_prov {
        char label[40];
@@ -202,6 +220,18 @@ const char *devstate2str(enum ast_device_state devstate)
        return devstatestring[devstate];
 }
 
+enum ast_device_state ast_state_chan2dev(enum ast_channel_state chanstate)
+{
+       int i;
+       chanstate &= 0xFFFF;
+       for (i = 0; chan2dev[i].chan != -100; i++) {
+               if (chan2dev[i].chan == chanstate) {
+                       return chan2dev[i].dev;
+               }
+       }
+       return AST_DEVICE_UNKNOWN;
+}
+
 const char *ast_devstate_str(enum ast_device_state state)
 {
        const char *res = "UNKNOWN";