Skinny cleanup (mwi_event_cb).
authorDamien Wedhorn <voip@facts.com.au>
Thu, 7 Jun 2012 21:44:15 +0000 (21:44 +0000)
committerDamien Wedhorn <voip@facts.com.au>
Thu, 7 Jun 2012 21:44:15 +0000 (21:44 +0000)
Original was testing for d->session, setting and testing again (all nested).

Removed duplicate testing and restructured function to test/return and then
the main code.

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

channels/chan_skinny.c

index 5f5c611..1c89674 100644 (file)
@@ -3179,38 +3179,36 @@ static void mwi_event_cb(const struct ast_event *event, void *userdata)
 {
        struct skinny_line *l = userdata;
        struct skinny_device *d = l->device;
-       if (d && d->session) {
-               struct skinnysession *s = d->session;
-               struct skinny_line *l2;
-               int new_msgs = 0;
-               int dev_msgs = 0;
-
-               if (s) {
-                       if (event) {
-                               l->newmsgs = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);
-                       }
+       struct skinny_line *l2;
+       int dev_msgs = 0;
+       
+       if (!d || !d->session) {
+               return;
+       }
 
-                       if (l->newmsgs) {
-                               transmit_lamp_indication(d, STIMULUS_VOICEMAIL, l->instance, l->mwiblink?SKINNY_LAMP_BLINK:SKINNY_LAMP_ON);
-                       } else {
-                               transmit_lamp_indication(d, STIMULUS_VOICEMAIL, l->instance, SKINNY_LAMP_OFF);
-                       }
+       if (event) {
+               l->newmsgs = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);
+       }
 
-                       /* find out wether the device lamp should be on or off */
-                       AST_LIST_TRAVERSE(&d->lines, l2, list) {
-                               if (l2->newmsgs) {
-                                       dev_msgs++;
-                               }
-                       }
+       if (l->newmsgs) {
+               transmit_lamp_indication(d, STIMULUS_VOICEMAIL, l->instance, l->mwiblink?SKINNY_LAMP_BLINK:SKINNY_LAMP_ON);
+       } else {
+               transmit_lamp_indication(d, STIMULUS_VOICEMAIL, l->instance, SKINNY_LAMP_OFF);
+       }
 
-                       if (dev_msgs) {
-                               transmit_lamp_indication(d, STIMULUS_VOICEMAIL, 0, d->mwiblink?SKINNY_LAMP_BLINK:SKINNY_LAMP_ON);
-                       } else {
-                               transmit_lamp_indication(d, STIMULUS_VOICEMAIL, 0, SKINNY_LAMP_OFF);
-                       }
-                       ast_verb(3, "Skinny mwi_event_cb found %d new messages\n", new_msgs);
+       /* find out wether the device lamp should be on or off */
+       AST_LIST_TRAVERSE(&d->lines, l2, list) {
+               if (l2->newmsgs) {
+                       dev_msgs++;
                }
        }
+
+       if (dev_msgs) {
+               transmit_lamp_indication(d, STIMULUS_VOICEMAIL, 0, d->mwiblink?SKINNY_LAMP_BLINK:SKINNY_LAMP_ON);
+       } else {
+               transmit_lamp_indication(d, STIMULUS_VOICEMAIL, 0, SKINNY_LAMP_OFF);
+       }
+       ast_verb(3, "Skinny mwi_event_cb found %d new messages\n", l->newmsgs);
 }
 
 /* I do not believe skinny can deal with video.