From 2d0ce574a4d95f47e1b5bc293845ead19f5aa0c7 Mon Sep 17 00:00:00 2001
From: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
Date: Fri, 24 Jul 2015 14:53:49 -0400
Subject: [PATCH] call: add missing cases to Call::validStateTransition

MERROR was not permitted but it should always be the case.

Issue: #78119
Change-Id: I6591a0bda43ed81887cdfb6e546fa8108a01f725
---
 src/call.cpp | 28 +++++++++++++++++++++-------
 src/call.h   |  4 ++++
 2 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/src/call.cpp b/src/call.cpp
index d235c1abfc..4f38d1e2fc 100644
--- a/src/call.cpp
+++ b/src/call.cpp
@@ -93,33 +93,47 @@ Call::getState() const
 bool
 Call::validStateTransition(CallState newState)
 {
+    // Notice to developper:
+    // - list only permitted transition (return true)
+    // - let non permitted ones as default case (return false)
     switch (callState_) {
         case CallState::INACTIVE:
             switch (newState) {
-                case CallState::INACTIVE:
-                case CallState::HOLD:
-                    return false;
-                default:
+                case CallState::ACTIVE:
+                case CallState::BUSY:
+                case CallState::MERROR:
                     return true;
+                default: // INACTIVE, HOLD
+                    return false;
             }
 
         case CallState::ACTIVE:
             switch (newState) {
                 case CallState::HOLD:
+                case CallState::MERROR:
                     return true;
-                default:
+                default: // INACTIVE, ACTIVE, BUSY
                     return false;
             }
 
         case CallState::HOLD:
             switch (newState) {
                 case CallState::ACTIVE:
+                case CallState::MERROR:
                     return true;
-                default:
+                default: // INACTIVE, HOLD, BUSY, MERROR
                     return false;
             }
 
-        default:
+        case CallState::BUSY:
+            switch (newState) {
+                case CallState::MERROR:
+                    return true;
+                default: // INACTIVE, ACTIVE, HOLD, BUSY
+                    return false;
+            }
+
+        default: // MERROR
             return false;
     }
 }
diff --git a/src/call.h b/src/call.h
index 1def90ff74..a9d2af1c01 100644
--- a/src/call.h
+++ b/src/call.h
@@ -77,6 +77,8 @@ class Call : public Recordable, public std::enable_shared_from_this<Call> {
          *
          * Audio should be transmitted when ConnectionState = Connected AND
          * CallState = Active.
+         *
+         * \note modify validStateTransition/getStateStr if this enum changes
          */
         enum class ConnectionState : unsigned {
             DISCONNECTED, TRYING, PROGRESSING, RINGING, CONNECTED, COUNT__
@@ -84,6 +86,8 @@ class Call : public Recordable, public std::enable_shared_from_this<Call> {
 
         /**
          * The Call State.
+         *
+         * \note modify validStateTransition/getStateStr if this enum changes
          */
         enum class CallState : unsigned {
             INACTIVE, ACTIVE, HOLD, BUSY, MERROR, COUNT__
-- 
GitLab