From 768fcc073b4a9a5a20135f210a6d5859b349c6ce Mon Sep 17 00:00:00 2001
From: Alexandre Savard <alexandresavard@msavard.(none)>
Date: Tue, 21 Jun 2011 14:44:36 -0400
Subject: [PATCH] #6233: Handle cases when one or manuy calls are unreachable
 in createConfFomrParticipantList

---
 sflphone-client-gnome/src/dbus/dbus.c |  2 +-
 sflphone-common/src/managerimpl.cpp   | 44 ++++++++++++++++++++++-----
 2 files changed, 38 insertions(+), 8 deletions(-)

diff --git a/sflphone-client-gnome/src/dbus/dbus.c b/sflphone-client-gnome/src/dbus/dbus.c
index dbdfae944b..d929e1fd50 100644
--- a/sflphone-client-gnome/src/dbus/dbus.c
+++ b/sflphone-client-gnome/src/dbus/dbus.c
@@ -64,7 +64,7 @@ new_call_created_cb (DBusGProxy *proxy UNUSED, const gchar *accountID,
 {
     callable_obj_t *c;
     gchar *peer_name = (gchar *)to;
-    gchar *peer_number = "";
+    gchar *peer_number = (gchar *)to;
 
     DEBUG("DBUS: New Call (%s) created to (%s)", callID, to);
 
diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp
index dc09c3a851..9dc000fe69 100644
--- a/sflphone-common/src/managerimpl.cpp
+++ b/sflphone-common/src/managerimpl.cpp
@@ -1314,8 +1314,17 @@ void ManagerImpl::joinParticipant (const CallID& callId1, const CallID& callId2)
 
 void ManagerImpl::createConfFromParticipantList(const std::vector< std::string > &participantList)
 {
+    bool callSuccess;
+    int successCounter = 0;
+
     _debug("Manager: Create conference from participant list");
 
+    // we must at least have 2 participant for a conference
+    if(participantList.size() <= 1) {
+        _error("Manager: Error: Participant number must be higher or equal to 2");
+	return;
+    }
+
     Conference *conf = new Conference();
 
     for(unsigned int i = 0; i < participantList.size(); i++) {
@@ -1325,21 +1334,42 @@ void ManagerImpl::createConfFromParticipantList(const std::vector< std::string >
 		
 	std::string generatedCallID = getNewCallID();
 
+	// Manager methods may behave differently if the call id particip to a conference
 	conf->add(generatedCallID);
 
-	outgoingCall(account, generatedCallID, tostr, conf->getConfID());
+	// Create call
+	callSuccess = outgoingCall(account, generatedCallID, tostr, conf->getConfID());
 
-	if(_dbus) {
+        // If not able to create call remove this participant from the conference
+	if(!callSuccess)
+	    conf->remove(generatedCallID);
+
+	if(_dbus && callSuccess) {
 	    _dbus->getCallManager()->newCallCreated(account, generatedCallID, tostr);
+	    successCounter++;
 	}	
     }
 
-    _conferencemap.insert(std::pair<CallID, Conference *> (conf->getConfID(), conf));
-    
-    if (_dbus) {
-        _dbus->getCallManager()->conferenceCreated (conf->getConfID());
-    }
+    // Create the conference if and only if at least 2 calls have been successfully created
+    if(successCounter >= 2 ) {
+        _conferencemap.insert(std::pair<CallID, Conference *> (conf->getConfID(), conf));
 
+        if (_dbus) {
+            _dbus->getCallManager()->conferenceCreated (conf->getConfID());
+        }
+
+	audioLayerMutexLock();
+	if(_audiodriver) {
+	    conf->setRecordingSmplRate(_audiodriver->getSampleRate());
+        }
+	audioLayerMutexUnlock();
+
+	getMainBuffer()->stateInfo();
+    }
+    else {
+	delete conf;
+	conf = NULL;
+    }
     
 }
 
-- 
GitLab