rcsimengine/src/chatcontactmanagerimpl_sym.cpp
changeset 0 59dfe4ae66d0
equal deleted inserted replaced
-1:000000000000 0:59dfe4ae66d0
       
     1 /*
       
     2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html."
       
     8 * Initial Contributors:
       
     9 * Nokia Corporation - initial contribution.
       
    10 * Contributors:
       
    11 *
       
    12 * Description:
       
    13 * RCS IM Library - Initial version
       
    14 *
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 #include <cntdb.h>
       
    20 #include <cntfield.h>
       
    21 #include <cntitem.h>
       
    22 #include <cntfldst.h>
       
    23 #include <qcontactmanager.h>
       
    24 #include <qcontact.h>
       
    25 #include <qcontactdetails.h>
       
    26 #include "chatsession.h"
       
    27 #include "chatcontactmanager.h"
       
    28 #include "chatcontactmanagerimpl_sym.h"
       
    29 #include "chatsessionimpl_sym.h"
       
    30 #include "msrpchatsessiondata_sym.h"
       
    31 #include <chatinterfaces.h>
       
    32 #include <sipprofileregistry.h>
       
    33 #include <mcesession.h>
       
    34 #include "qcontactfilter.h"
       
    35 
       
    36 using namespace RcsIMLib;
       
    37 
       
    38 
       
    39 ChatContactManagerImpl::ChatContactManagerImpl(ChatContactManager *apCntManager):mParent(apCntManager),mProfile(NULL)
       
    40 {
       
    41     QT_TRAP_THROWING(setupMceManagerL());
       
    42     mManager = new QContactManager("symbian");
       
    43 	
       
    44 	QContact  self = mManager->contact(mManager->selfContactId());
       
    45 	//mMyID = self.localId();
       
    46 	
       
    47 	// To get Self SIP Uri.
       
    48 	QContactDetail selfContactDetail = self.detail(QContactOnlineAccount::DefinitionName);
       
    49 	const QContactOnlineAccount &onlineUrl = static_cast<const QContactOnlineAccount &>(selfContactDetail);
       
    50 	QString selfSipUri = onlineUrl.accountUri();
       
    51 	TPtrC16 dataPtr(reinterpret_cast<const TUint16*>(selfSipUri.utf16()));
       
    52 	mOriginatorUri = HBufC8::NewL(dataPtr.Length());
       
    53 	mOriginatorUri->Des().Copy(dataPtr);
       
    54 			
       
    55 }
       
    56 
       
    57 
       
    58 ChatContactManagerImpl::~ChatContactManagerImpl()
       
    59     {
       
    60 
       
    61     for(int i=0;i<mMceSessions.Count();i++)
       
    62         {
       
    63         
       
    64         int mSessionState =  mMceSessions[i]->State();
       
    65         
       
    66         if (mSessionState <= CMceSession::EEstablished)
       
    67             mMceSessions[i]->TerminateL(0,0,0);
       
    68              
       
    69         }
       
    70     
       
    71     mMceSessions.ResetAndDestroy();//deletes streams, sources and sinks
       
    72     mMceSessions.Close();
       
    73     mChatSessionArray.ResetAndDestroy();
       
    74     mChatSessionArray.Close();
       
    75     delete mManager;
       
    76     delete mMceMgr;
       
    77     
       
    78     //delete mProfile;
       
    79     mAllprofiles.ResetAndDestroy();
       
    80     mAllprofiles.Close();
       
    81     
       
    82     delete mProfileReg;
       
    83     delete mSip;
       
    84     delete mOriginatorUri;
       
    85     
       
    86     }
       
    87 
       
    88 void ChatContactManagerImpl::closeSession(RcsChatId sessID)
       
    89 {
       
    90     
       
    91     CMceSession *currentSession = reinterpret_cast<CMceSession*>(sessID);
       
    92     
       
    93     int mSessionState =  currentSession->State();
       
    94            
       
    95     if (mSessionState == CMceSession::EEstablished)
       
    96         currentSession->TerminateL();
       
    97     
       
    98     //remove and close
       
    99     
       
   100     TInt idx = mMceSessions.Find(currentSession);
       
   101     if (idx != KErrNotFound)
       
   102         {
       
   103         delete currentSession;
       
   104         mMceSessions.Remove(idx);    
       
   105         }
       
   106     
       
   107     for(int i=0;i<mChatSessionArray.Count();i++)
       
   108         {
       
   109            if(mChatSessionArray[i]->iMceSession == currentSession)
       
   110                {
       
   111                delete mChatSessionArray[i];
       
   112                mChatSessionArray.Remove(i);
       
   113                break;
       
   114                }
       
   115         }
       
   116  }
       
   117 
       
   118 void ChatContactManagerImpl::acceptIncomingSession(RcsChatId sessID)
       
   119 {    
       
   120     CMceInSession *currentSession = reinterpret_cast<CMceInSession*>(sessID);
       
   121      if (currentSession->State() == CMceSession::EProceeding)
       
   122       {
       
   123          currentSession->AcceptL();
       
   124       }           
       
   125  }
       
   126 
       
   127 
       
   128 
       
   129 RcsIMLib::RcsChatId ChatContactManagerImpl::createChatSession(QContactLocalId contactId, QString initMsg)
       
   130 {
       
   131     RcsIMLib::RcsChatId id = 0;
       
   132     QT_TRAP_THROWING(id = createChatSessionL(contactId, initMsg));
       
   133     //QT_TRYCATCH_ERROR(id = createChatSessionL(contactId, initMsg));
       
   134     return id;
       
   135 }
       
   136 
       
   137 
       
   138 RcsIMLib::RcsChatId ChatContactManagerImpl::createChatSessionL(QContactLocalId contactId, QString initMsg)
       
   139 {             
       
   140     // To get recipient SIP Uri.
       
   141     const QContact buddy = mManager->contact(contactId);
       
   142     QContactDetail buddyContactDetail = buddy.detail(QContactOnlineAccount::DefinitionName);
       
   143     const QContactOnlineAccount &onlineUrl = static_cast<const QContactOnlineAccount &>(buddyContactDetail);
       
   144     QString buddySipUri = onlineUrl.accountUri();
       
   145     TPtrC16 dataPtr(reinterpret_cast<const TUint16*>(buddySipUri.utf16()));
       
   146     HBufC8 *recipientUri = HBufC8::NewL(dataPtr.Length());
       
   147     CleanupStack::PushL(recipientUri);
       
   148     recipientUri->Des().Copy(dataPtr);
       
   149     
       
   150     CMceOutSession *outSess ;
       
   151     if(mProfile)
       
   152         {
       
   153         outSess = CMceOutSession::NewL(*mMceMgr, *mProfile, *recipientUri);
       
   154         }
       
   155     else
       
   156         {        
       
   157         outSess = CMceOutSession::NewL(*mMceMgr, 1,*mOriginatorUri, *recipientUri); 
       
   158         }        
       
   159     CleanupStack::PopAndDestroy(recipientUri);
       
   160     CleanupStack::PushL(outSess);
       
   161     
       
   162     /* Add the out session to the list of MCESessions */
       
   163     mMceSessions.Append(outSess);
       
   164     CleanupStack::Pop(outSess);
       
   165 
       
   166     /* Streams Creation */
       
   167     // Create the stream for UpLink and Downlink
       
   168     CMceMessageStream* msgStrmUp = CMceMessageStream::NewL();
       
   169     CleanupStack::PushL(msgStrmUp);
       
   170     
       
   171     // Message Source
       
   172     CMceMessageSource* messageSrc = CMceMessageSource::NewL(*mMceMgr);  
       
   173     CleanupStack::PushL(messageSrc);  
       
   174     
       
   175     //MSRP Sink
       
   176     CMceMsrpSink* msrpSink = CMceMsrpSink::NewL();
       
   177     CleanupStack::Pop(messageSrc);
       
   178     CleanupStack::PushL(msrpSink);
       
   179     CleanupStack::PushL(messageSrc);
       
   180     msgStrmUp->SetSourceL(messageSrc);
       
   181     CleanupStack::Pop(messageSrc);
       
   182 
       
   183     // Add sink  to the stream
       
   184     msgStrmUp->AddSinkL(msrpSink);
       
   185     CleanupStack::Pop(msrpSink);
       
   186     msgStrmUp->ConnectionSetUpL(CMceMessageStream::EActive);
       
   187 
       
   188     // Set AcceptTypes
       
   189     CDesC8ArrayFlat *acceptTypes = new(ELeave)CDesC8ArrayFlat(KGranularity);
       
   190     _LIT8(KtextPlain,"text/plain");   
       
   191     acceptTypes->AppendL(KtextPlain);    
       
   192 
       
   193     msrpSink->SetAcceptTypesL(*acceptTypes);
       
   194     delete acceptTypes;
       
   195 
       
   196     _LIT8(KAcceptWrap, "acceptwrap");
       
   197     TBuf8<KAcceptSize> accept(KAcceptWrap);
       
   198     msrpSink->SetAcceptWrappedTypesL(accept);
       
   199 
       
   200 
       
   201     //outSess->AddStreamL(msgStrmUp);
       
   202     CleanupStack::Pop(msgStrmUp);
       
   203 
       
   204 
       
   205     // Create the stream for Downlink
       
   206     CMceMessageStream *msgStrmDown = CMceMessageStream::NewL();
       
   207 
       
   208     // MSRP Source
       
   209     CMceMsrpSource *msrpSrc = CMceMsrpSource::NewL();
       
   210 
       
   211     // Message Sink
       
   212     CMceMessageSink* messageSink = CMceMessageSink::NewL(*mMceMgr);
       
   213     CleanupStack::PushL(msrpSrc);
       
   214     msgStrmDown->SetSourceL(msrpSrc);
       
   215     CleanupStack::Pop(msrpSrc);
       
   216 
       
   217     // Add sink  to the stream
       
   218     CleanupStack::PushL(messageSink);
       
   219     msgStrmDown->AddSinkL(messageSink);
       
   220     CleanupStack::Pop(messageSink);
       
   221     msgStrmDown->ConnectionSetUpL(CMceMessageStream::EActive);
       
   222 
       
   223     CleanupStack::PushL(msgStrmUp);
       
   224     msgStrmDown->BindL(msgStrmUp);
       
   225     CleanupStack::Pop(msgStrmUp);
       
   226 
       
   227     CleanupStack::PushL(msgStrmDown);
       
   228     outSess->AddStreamL(msgStrmDown);
       
   229     CleanupStack::Pop(msgStrmDown);
       
   230     
       
   231     /* A new Chat Session with the Platform specific Init Params */
       
   232     ChatSession *chatSession = new ChatSession();
       
   233 
       
   234     /* Create the ChatSession here */
       
   235     TMsrpChatSession *msrpChatSession = new TMsrpChatSession();
       
   236     msrpChatSession->iMceManager = mMceMgr;
       
   237     msrpChatSession->iMceSession = outSess;
       
   238     msrpChatSession->iChatSession = chatSession;
       
   239     msrpChatSession->iStream1 = msgStrmUp;
       
   240     msrpChatSession->iStream2 = msgStrmDown;
       
   241 
       
   242     //chatSession->setPlatformParams(msrpChatSession);
       
   243 
       
   244     mChatSessionArray.Append(msrpChatSession);
       
   245 
       
   246 
       
   247     //Start the session establishment here. Emit the signal when everything is
       
   248     //done. The session will be matched my the ID returned.
       
   249     //RcsChatId sessID = (RcsChatId)&outSess;
       
   250     
       
   251     
       
   252     //Create the CDesC8Array with the syntax of the subject header and pass it 
       
   253     //such that the INVITE is constructed with Subject header.
       
   254     
       
   255     CDesC8ArrayFlat *mSIPHeaders = new CDesC8ArrayFlat(20);
       
   256     QString mSubjectHeader = "Subject:"+ initMsg;
       
   257     TPtrC16 mDataPtr(reinterpret_cast<const TUint16*>(mSubjectHeader.utf16()));
       
   258     RBuf8 mChatData;
       
   259     mChatData.Create(300);
       
   260     mChatData.Copy(mDataPtr);
       
   261     
       
   262     mSIPHeaders->AppendL(mChatData);
       
   263     outSess->EstablishL(0,mSIPHeaders,0,0,0);                                                                                                                                                                                                                                                                                                                                                  
       
   264 
       
   265     return reinterpret_cast<RcsChatId>(outSess);
       
   266 }
       
   267 
       
   268 void ChatContactManagerImpl::setupMceManagerL()
       
   269 {
       
   270     //RFileLogger::Write( KLogDir1, KLogFile1, EFileLoggingModeAppend, _L("setupMceManagerL ChkPt 0") );
       
   271     //Setup MCE For accepting and receiving chat messages
       
   272     mMceMgr = CMceManager::NewL(TUid::Uid(0x10009388), &mDataContainer);
       
   273 
       
   274     // Set session observer to get the session related state changes
       
   275     mMceMgr->SetSessionObserver(this);    
       
   276 
       
   277     // Set InSession Observer to recieve the incoming session
       
   278     mMceMgr->SetInSessionObserver(this);
       
   279     mMceMgr->SetDataSinkObserver(this);
       
   280 
       
   281     TUid appUid;
       
   282     
       
   283     appUid.iUid = 0xA00001EC; //TODO get APPUID Correct
       
   284     TRAPD(errsip, mSip = CSIP::NewL(appUid , *this))
       
   285     //TRAPD(errsip, mSip = CSIP::NewL(TUid::Null(), *this))
       
   286     if (!errsip) {
       
   287         //CleanupStack::PushL(sipClient);
       
   288         mProfileReg = CSIPProfileRegistry::NewL(*mSip, *this);
       
   289         //CleanupStack::Pop(mSip);
       
   290     }
       
   291     
       
   292     //assumes first profile is registered and valid    
       
   293     //CleanupStack::PushL(profileReg);
       
   294     //mProfile = profileReg->DefaultProfileL();
       
   295     
       
   296         
       
   297     //later check for tag matches
       
   298     
       
   299     
       
   300     mProfileReg->ProfilesL(mAllprofiles);
       
   301     if (mAllprofiles.Count())
       
   302     {     
       
   303         mProfile = mAllprofiles[0];
       
   304     }
       
   305     
       
   306     //CleanupStack::PopAndDestroy(profileReg);
       
   307     //CleanupStack::PopAndDestroy(sipClient);
       
   308 }
       
   309 
       
   310 
       
   311 void ChatContactManagerImpl::SessionStateChanged( CMceSession& aSession, TMceTransactionDataContainer* aContainer)
       
   312 {
       
   313     if (aSession.State() == CMceSession::EEstablished)
       
   314     {       
       
   315         
       
   316         CMceMessageStream* downlinkStr = NULL;
       
   317         CMceMessageStream* uplinkStr = NULL;
       
   318         
       
   319         GetStreams(aSession, uplinkStr, downlinkStr );
       
   320                                
       
   321         if (uplinkStr && uplinkStr->Source() &&
       
   322                 uplinkStr->Source()->Type() == KMceMessageSource)
       
   323             {
       
   324             uplinkStr->Source()->DisableL();
       
   325             if (!uplinkStr->Source()->IsEnabled())
       
   326                 uplinkStr->Source()->EnableL();
       
   327             }
       
   328         
       
   329         if (downlinkStr && downlinkStr->Sinks().Count() > 0)
       
   330             {
       
   331             // assume only one sink is added
       
   332             downlinkStr->Sinks()[0]->DisableL();
       
   333             if (! downlinkStr->Sinks()[0]->IsEnabled() )
       
   334             downlinkStr->Sinks()[0]->EnableL();
       
   335             }
       
   336         
       
   337         for(int i=0;i<mChatSessionArray.Count();i++)
       
   338             {
       
   339                if(mChatSessionArray[i]->iMceSession == &aSession)
       
   340                    {
       
   341                    mChatSessionArray[i]->iStream1 = uplinkStr;
       
   342                    mChatSessionArray[i]->iStream2 = downlinkStr;
       
   343                    mChatSessionArray[i]->iChatSession->setPlatformParams(mChatSessionArray[i]);
       
   344                    break;
       
   345                    }
       
   346             }
       
   347         
       
   348        
       
   349 /*  //can be terminated without establishment
       
   350         // A new Chat Session with the Platform specific Init Params 
       
   351         ChatSession *chatSession = new ChatSession();
       
   352 
       
   353          //Create the ChatSession here 
       
   354         TMsrpChatSession *msrpChatSession = new TMsrpChatSession();
       
   355         msrpChatSession->iMceManager = mMceMgr;
       
   356         msrpChatSession->iMceSession = &aSession;
       
   357         msrpChatSession->iChatSession = chatSession;
       
   358         msrpChatSession->iStream1 = uplinkStr;
       
   359         msrpChatSession->iStream2 = downlinkStr;
       
   360 
       
   361         chatSession->setPlatformParams(msrpChatSession);
       
   362 
       
   363         mChatSessionArray.Append(msrpChatSession);
       
   364 */
       
   365 
       
   366         /* Notify the UI that Session is established. Pointer to aSession
       
   367          * serves as the key */
       
   368         for(int i=0;i<mChatSessionArray.Count();i++)
       
   369             {
       
   370                if(mChatSessionArray[i]->iMceSession == &aSession)
       
   371                    {
       
   372                    emit mParent->sessionEstablised(reinterpret_cast<RcsChatId>(&aSession), mChatSessionArray[i]->iChatSession); 
       
   373                    break;
       
   374                    }
       
   375             }
       
   376         
       
   377         
       
   378     }
       
   379     else if (aSession.State() == CMceSession::EProceeding)
       
   380     {
       
   381     //get originator
       
   382     const TDesC8& remoteURI = aSession.Originator();
       
   383     const QString remoteSIPURI = QString::fromUtf8((const char*)remoteURI.Ptr(),remoteURI.Length());
       
   384     
       
   385     //Pass the remote sip uri as a filter and fetch the buddy name. 
       
   386     //Also emit a signal here for incomingChatSession with the contactID 
       
   387 
       
   388     // To fetch the buddy name using the sip URI.
       
   389     QList<QContactSortOrder> order;
       
   390     QStringList list;
       
   391     QContactDetailFilter filter;
       
   392     filter.setDetailDefinitionName(QContactOnlineAccount::DefinitionName, QContactOnlineAccount::SubTypeSip);
       
   393     filter.setValue(remoteSIPURI);
       
   394     
       
   395     QList<QContact> allContacts;
       
   396     allContacts = mManager->contacts(filter);
       
   397     unsigned int buddyID = 0;
       
   398     if(allContacts.count())
       
   399         {
       
   400         buddyID = allContacts[0].localId();
       
   401         }
       
   402   
       
   403     QString imMsg;
       
   404 	
       
   405 
       
   406     for(int i=0;i<mChatSessionArray.Count();i++)
       
   407     {
       
   408        if(mChatSessionArray[i]->iMceSession == &aSession)
       
   409            {
       
   410            imMsg = mChatSessionArray[i]->iInitMsg;
       
   411            break;
       
   412            }
       
   413     }
       
   414     
       
   415      
       
   416     //emit on SSC to proceeding as a result of call to updateL //see insession header
       
   417     //emit after update or could lead to accept call before update, little chance as user interaction involved
       
   418     emit mParent->incomingChatSession(buddyID, remoteSIPURI, imMsg, reinterpret_cast<RcsChatId>(&aSession));
       
   419     }
       
   420     else if (aSession.State() == CMceSession::ETerminated)
       
   421     {
       
   422         for(int i=0;i<mChatSessionArray.Count();i++)
       
   423         {
       
   424            if(mChatSessionArray[i]->iMceSession == &aSession)
       
   425                {
       
   426                emit mParent->sessionTerminated(reinterpret_cast<RcsChatId>(&aSession), mChatSessionArray[i]->iChatSession);
       
   427                break;
       
   428                }
       
   429         }
       
   430     
       
   431     }
       
   432 }
       
   433 
       
   434 
       
   435 
       
   436 void ChatContactManagerImpl::SessionConnectionStateChanged( CMceSession& , TBool /*aActive*/ )
       
   437 {
       
   438 }
       
   439 
       
   440 void ChatContactManagerImpl::Failed( CMceSession& /*aSession*/, TInt /*aError*/ )
       
   441 {
       
   442 }
       
   443 
       
   444 void ChatContactManagerImpl::UpdateFailed(CMceSession& /*aSession*/, TMceTransactionDataContainer* /*aContainer*/ )
       
   445 {
       
   446 }
       
   447 
       
   448 // From MSIPProfileAgentObserver
       
   449 void ChatContactManagerImpl::ProfileRegistryEventOccurred(TUint32 /*aProfileId*/, TEvent /*aEvent*/)
       
   450 {
       
   451 }
       
   452 
       
   453 void ChatContactManagerImpl::ProfileRegistryErrorOccurred(TUint32 /*aProfileId*/,  TInt /*aError*/)
       
   454 {
       
   455 }
       
   456 
       
   457 // From MSIPObserver
       
   458 void ChatContactManagerImpl::IncomingRequest(TUint32 /*aIapId*/, CSIPServerTransaction* /*aTransaction*/)
       
   459 {
       
   460 }
       
   461 
       
   462 void ChatContactManagerImpl::TimedOut(CSIPServerTransaction& /*aTransaction*/)
       
   463 {
       
   464 }
       
   465 
       
   466 // From MMceInSessionObserver
       
   467 void ChatContactManagerImpl::IncomingSession(CMceInSession* aSession, TMceTransactionDataContainer* aContainer )
       
   468 {       
       
   469     if (aSession->State() == CMceSession::EIncoming)
       
   470     {
       
   471         ///////////////////////
       
   472         QString imMsg;
       
   473         //Fetch the message from the SIP INVITE
       
   474         CDesC8Array *mSIPHeader = aContainer->GetHeaders(); 
       
   475         TInt count = mSIPHeader->MdcaCount();
       
   476            
       
   477         for (int i=0; i<count; i++)
       
   478         {
       
   479             TPtrC8 data = mSIPHeader->MdcaPoint(i);
       
   480             QString header = QString::fromUtf8((const char*)data.Ptr(),data.Length());
       
   481             if (header.contains("Subject",Qt::CaseSensitive))
       
   482                 {
       
   483                     QChar sep = ':';
       
   484                     //QString mChatData = header.section(sep,1);
       
   485                     imMsg = header.section(sep,1);
       
   486                 }
       
   487                 else 
       
   488                 {
       
   489                     //QString mChatData = "";
       
   490                     imMsg = "";
       
   491                 }
       
   492         }
       
   493         //////////////////////
       
   494     
       
   495         // get the stream for this incoming session to set the MSRP capabilities
       
   496         CMceMessageStream* downlinkStr = NULL;
       
   497         CMceMessageStream* uplinkStr = NULL;
       
   498         GetStreams(*aSession, uplinkStr, downlinkStr);
       
   499         
       
   500         ChatSession *chatSession = new ChatSession();
       
   501 
       
   502         // Create the ChatSession here 
       
   503         TMsrpChatSession *msrpChatSession = new TMsrpChatSession();
       
   504         msrpChatSession->iMceManager = mMceMgr;
       
   505         msrpChatSession->iMceSession = aSession;
       
   506         msrpChatSession->iChatSession = chatSession;
       
   507         msrpChatSession->iStream1 = uplinkStr;
       
   508         msrpChatSession->iStream2 = downlinkStr;
       
   509         msrpChatSession->iInitMsg = imMsg;
       
   510 
       
   511         mChatSessionArray.Append(msrpChatSession);
       
   512         
       
   513         
       
   514          if (downlinkStr )
       
   515          {
       
   516             CMceMsrpSource* msrpSource = static_cast<CMceMsrpSource*> (downlinkStr->Source());
       
   517             if(msrpSource)
       
   518              {
       
   519                 downlinkStr->ConnectionSetUpL(CMceMessageStream::EPassive);
       
   520                 //uplinkStr->ConnectionSetUpL(CMceMessageStream::EPassive);
       
   521 
       
   522                 // Set AcceptTypes
       
   523                 CDesC8ArrayFlat *acceptTypes = new(ELeave)CDesC8ArrayFlat(KGranularity);
       
   524                 _LIT8(KtextPlain,"text/plain");
       
   525                 _LIT8(KMessageCpim, "message/cpim");
       
   526                 acceptTypes->AppendL(KtextPlain);
       
   527                 acceptTypes->AppendL(KMessageCpim);
       
   528 
       
   529                 msrpSource->SetAcceptTypesL(*acceptTypes);
       
   530                 delete acceptTypes;
       
   531 
       
   532                 _LIT8(KAcceptWrap, "acceptwrap");
       
   533                TBuf8<KAcceptSize> accept(KAcceptWrap);
       
   534                msrpSource->SetAcceptWrappedTypesL(accept);
       
   535              }
       
   536           }
       
   537          
       
   538          /* Add the out session to the list of MCESessions */
       
   539          mMceSessions.Append(aSession);
       
   540          aSession->UpdateL();
       
   541        }         
       
   542 }
       
   543 
       
   544 
       
   545 void ChatContactManagerImpl::IncomingUpdate(CMceSession& , CMceInSession* , TMceTransactionDataContainer* )
       
   546 {
       
   547 }
       
   548 
       
   549 void ChatContactManagerImpl::DataReceived(CMceMediaStream& aStream, CMceMediaSink& /*aSink*/, const TDesC8& aData)
       
   550 {
       
   551     /* Find the Session for which this Message is intented */
       
   552     for(int i=0; i<mChatSessionArray.Count(); i++)
       
   553     {
       
   554        if(mChatSessionArray[i]->iStream1 == &aStream || mChatSessionArray[i]->iStream2 == &aStream)
       
   555        {
       
   556            ChatSessionImpl *pImpl = static_cast<ChatSessionImpl*>(mChatSessionArray[i]->iChatSession->getPlatformImpl());
       
   557            pImpl->incomingData(aData);
       
   558        }
       
   559     }
       
   560 }
       
   561 
       
   562 
       
   563 void ChatContactManagerImpl::GetStreams(CMceSession& aSession, CMceMessageStream*& aUplinkStr, CMceMessageStream*& aDownlinkStr )
       
   564     {
       
   565     RPointerArray<CMceMediaStream> streams = aSession.Streams();
       
   566     for (TInt i=0; i<streams.Count();i++)
       
   567        {
       
   568        if (streams[i]->Type() == KMceMessage  && 
       
   569                streams[i]->Source() &&
       
   570                streams[i]->Source()->Type() == KMceMSRPSource)
       
   571            {
       
   572            aDownlinkStr =static_cast<CMceMessageStream*> (streams[i]);
       
   573            //break;
       
   574            }
       
   575            
       
   576        if (streams[i]->Type() == KMceMessage  && 
       
   577                streams[i]->Source() &&
       
   578                streams[i]->Source()->Type() == KMceMessageSource)
       
   579            {
       
   580            aUplinkStr =static_cast<CMceMessageStream*> (streams[i]);
       
   581            //break;
       
   582            }  
       
   583        if (aDownlinkStr == NULL && streams[i]->BoundStream())
       
   584            {
       
   585            if (streams[i]->BoundStreamL().Type() == KMceMessage  && 
       
   586                    streams[i]->BoundStreamL().Source() &&
       
   587                    streams[i]->BoundStreamL().Source()->Type() == KMceMSRPSource)
       
   588                {
       
   589                CMceMessageStream& stream =static_cast<CMceMessageStream&> (streams[i]->BoundStreamL());
       
   590                aDownlinkStr =  &stream;
       
   591              //  break;
       
   592                } 
       
   593            }
       
   594            
       
   595        if (aUplinkStr == NULL && streams[i]->BoundStream())
       
   596            {
       
   597            if (streams[i]->BoundStreamL().Type() == KMceMessage  && 
       
   598                    streams[i]->BoundStreamL().Source() &&
       
   599                    streams[i]->BoundStreamL().Source()->Type() == KMceMessageSource)
       
   600                {
       
   601                CMceMessageStream& stream =static_cast<CMceMessageStream&> (streams[i]->BoundStreamL());
       
   602                aUplinkStr =  &stream;
       
   603                } 
       
   604            }
       
   605        }   // for loop
       
   606 
       
   607     }
       
   608 
       
   609 
       
   610