wvuing/IMPSConnectionUI/UISrc/CCnUiClientGroupUiNotifyMediator.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2004 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 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Synchronous client group notify mediator.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <E32std.h>
       
    21 #include "CCnUiClientGroupUiNotifyMediator.h"
       
    22 
       
    23 #include "CnUiCommon.hrh"
       
    24 #include "CnUiPanics.h"
       
    25 #include "IMPSCommonUiDebugPrint.h"
       
    26 
       
    27 
       
    28 
       
    29 const TInt KClientGroupQueryTimeout = 30000000;    //30 seconds, defined in UI specification
       
    30 
       
    31 
       
    32 
       
    33 // ================= MEMBER FUNCTIONS =======================
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CCnUiClientGroupUiNotifyMediator::NewLC
       
    37 // Two-phased constructor.
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CCnUiClientGroupUiNotifyMediator* CCnUiClientGroupUiNotifyMediator::NewLC()
       
    41     {
       
    42     CCnUiClientGroupUiNotifyMediator* self = new ( ELeave ) CCnUiClientGroupUiNotifyMediator();
       
    43     CleanupStack::PushL( self );
       
    44     self->ConstructL();
       
    45     return self;
       
    46     }
       
    47 
       
    48 
       
    49 // Destructor
       
    50 CCnUiClientGroupUiNotifyMediator::~CCnUiClientGroupUiNotifyMediator()
       
    51     {
       
    52     //cancel the self
       
    53     Cancel();
       
    54     CancelActiveChannels();
       
    55     }
       
    56 
       
    57 
       
    58 // C++ default constructor can NOT contain any code, that
       
    59 // might leave.
       
    60 //
       
    61 CCnUiClientGroupUiNotifyMediator::CCnUiClientGroupUiNotifyMediator()
       
    62         : CTimer( CActive::EPriorityUserInput )
       
    63     {
       
    64     }
       
    65 
       
    66 
       
    67 // EPOC default constructor can leave.
       
    68 void CCnUiClientGroupUiNotifyMediator::ConstructL()
       
    69     {
       
    70     CTimer::ConstructL();
       
    71     CActiveScheduler::Add( this );
       
    72     }
       
    73 
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CCnUiClientGroupUiNotifyMediator::CGQActiveConnectionScheduledCloseL()
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 TBool CCnUiClientGroupUiNotifyMediator::CGQActiveConnectionSuppressForScheduledConnectionL(
       
    80     const TDesC& aServerName,
       
    81     const TArray<TIMPSConnectionClient>& aClientsToShow )
       
    82     {
       
    83     return IssueTheQueryL( ECGQActiveConnectionSuppressForScheduledConnection, //RQ id from hrh
       
    84                            aServerName,
       
    85                            KClientGroupQueryTimeout,
       
    86                            EFalse,       //default result for timeout & deletion cases
       
    87                            aClientsToShow );
       
    88     }
       
    89 
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CCnUiClientGroupUiNotifyMediator::CGQActiveConnectionScheduledCloseL()
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 TBool CCnUiClientGroupUiNotifyMediator::CGQActiveConnectionScheduledCloseL(
       
    96     const TArray<TIMPSConnectionClient>& aClientsToShow )
       
    97     {
       
    98     return IssueTheQueryL( ECGQActiveConnectionScheduledClose, //RQ id from hrh
       
    99                            KNullDesC,
       
   100                            KClientGroupQueryTimeout,
       
   101                            ETrue,       //default result for timeout & deletion cases
       
   102                            aClientsToShow );
       
   103 
       
   104     }
       
   105 
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CCnUiClientGroupUiNotifyMediator::IssueTheQueryL()
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 TBool CCnUiClientGroupUiNotifyMediator::IssueTheQueryL(
       
   112     TInt aQueryMessageId,
       
   113     const TDesC& aDynamicInsertText,
       
   114     TTimeIntervalMicroSeconds32 aQueryTimeout,
       
   115     TBool aDefaultResult,
       
   116     const TArray<TIMPSConnectionClient>& aClientsToShow )
       
   117     {
       
   118     __ASSERT_ALWAYS( !IsActive(), User::Leave( KErrInUse ) );
       
   119     CancelActiveChannels();
       
   120 
       
   121     //issue client messages & time out notification
       
   122     IssueMessageToGroupsL( aQueryMessageId,
       
   123                            aDynamicInsertText,
       
   124                            aClientsToShow );
       
   125     After( aQueryTimeout );
       
   126 
       
   127     //wait the query to complete
       
   128     WaitCompletion();
       
   129 
       
   130     //get the completion result
       
   131     TBool queryResult = aDefaultResult;
       
   132     if ( iStatus == KErrNone )
       
   133         {
       
   134         queryResult = iQueryResult;
       
   135         }
       
   136 
       
   137     //and cancel all activity
       
   138     Cancel();               //cancel the time out timer
       
   139     CancelActiveChannels(); //cancel still active channels
       
   140 
       
   141     return queryResult;
       
   142     }
       
   143 
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // CCnUiClientGroupUiNotifyMediator::HandleChannelMsg()
       
   147 // MCnUiGroupChannelListener
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 void CCnUiClientGroupUiNotifyMediator::HandleChannelMsg( TInt aGroupId,
       
   151                                                          TGCChannelID aChannelId,
       
   152                                                          TInt aChannelMsg )
       
   153     {
       
   154     IMPSCUI_DP_TXT( "CCnUiClientGroupUiNotifyMediator::HandleChannelMsg()" );
       
   155     //there might come other messages from note cancellations etc.
       
   156     //those are ignored and only accept/declines are handled
       
   157     //==>query will timeout if no accept / decline is received
       
   158     if ( aChannelMsg == ERemoteQueryAccepted )
       
   159         {
       
   160         RemoveFromActiveChannels( aGroupId, aChannelId );
       
   161         iQueryResult = ETrue;
       
   162         iStatus = KErrNone;
       
   163         Completed();
       
   164         }
       
   165 
       
   166     else if ( aChannelMsg == ERemoteQueryDeclined )
       
   167         {
       
   168         RemoveFromActiveChannels( aGroupId, aChannelId );
       
   169         iQueryResult = EFalse;
       
   170         iStatus = KErrNone;
       
   171         Completed();
       
   172         }
       
   173     }
       
   174 
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 // CCnUiClientGroupUiNotifyMediator::RunL
       
   178 // -----------------------------------------------------------------------------
       
   179 //
       
   180 void CCnUiClientGroupUiNotifyMediator::RunL()
       
   181     {
       
   182     IMPSCUI_DP_TXT( "CCnUiClientGroupUiNotifyMediator::RunL() Timed out" );
       
   183     iStatus = KErrTimedOut;
       
   184     Completed();
       
   185     }
       
   186 
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CCnUiClientGroupUiNotifyMediator::DoCancel
       
   190 // -----------------------------------------------------------------------------
       
   191 //
       
   192 void CCnUiClientGroupUiNotifyMediator::DoCancel()
       
   193     {
       
   194     IMPSCUI_DP_TXT( "CCnUiClientGroupUiNotifyMediator::DoCancel()" );
       
   195     CTimer::DoCancel();
       
   196     iStatus = KErrCancel;
       
   197     Completed();
       
   198     }
       
   199 
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // CCnUiClientGroupUiNotifyMediator::RunError
       
   203 // -----------------------------------------------------------------------------
       
   204 //
       
   205 TInt CCnUiClientGroupUiNotifyMediator::RunError( TInt /*aError */ )
       
   206     {
       
   207     iStatus = KErrGeneral;
       
   208     Completed();
       
   209     return KErrNone;
       
   210     }
       
   211 
       
   212 
       
   213 // -----------------------------------------------------------------------------
       
   214 // CCnUiClientGroupUiNotifyMediator::WaitCompletion()
       
   215 // -----------------------------------------------------------------------------
       
   216 //
       
   217 void CCnUiClientGroupUiNotifyMediator::WaitCompletion()
       
   218     {
       
   219     //wait with the scheduler loop
       
   220     IMPSCUI_DP_TXT( "CCnUiClientGroupUiNotifyMediator::WaitCompletion() - starting wait" );
       
   221     if ( !iWait.IsStarted() )
       
   222         {
       
   223         // Code scanner warning "active object called without checking
       
   224         // whether it is active or cancelling it first" ignored because
       
   225         // CActiveSchedulerWait is not an active object
       
   226         iWait.Start(); // CSI: 10 # See above
       
   227         }
       
   228     IMPSCUI_DP_TXT( "CCnUiClientGroupUiNotifyMediator::WaitCompletion() - wait done" );
       
   229     }
       
   230 
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // CCnUiClientGroupUiNotifyMediator::Completed()
       
   234 // -----------------------------------------------------------------------------
       
   235 //
       
   236 void CCnUiClientGroupUiNotifyMediator::Completed()
       
   237     {
       
   238     //break away from the waiting scheduler loop
       
   239     if ( iWait.IsStarted() )
       
   240         {
       
   241         iWait.AsyncStop();
       
   242         }
       
   243     }
       
   244 
       
   245 
       
   246 // -----------------------------------------------------------------------------
       
   247 // CCnUiClientGroupUiNotifyMediator::IssueMessageToGroupsL()
       
   248 // -----------------------------------------------------------------------------
       
   249 //
       
   250 void CCnUiClientGroupUiNotifyMediator::IssueMessageToGroupsL(
       
   251     TInt aRemoteMessage,
       
   252     const TDesC& aExtraData,
       
   253     const TArray<TIMPSConnectionClient>& aClientGroups )
       
   254     {
       
   255     const TInt groupCount = aClientGroups.Count();
       
   256     for ( TInt ii( 0 ); ii < groupCount; ++ii  )
       
   257         {
       
   258         //issue the message to channel and listen further events from that channel
       
   259         TIMPSConnectionClient clientId = aClientGroups[ ii ];
       
   260         CCnUiGroupChannel* gc = CCnUiGroupChannel::NewLC( clientId,
       
   261                                                           ECnUiRemoteUiNotificationsChannel );
       
   262 
       
   263         gc->WriteL( aRemoteMessage, aExtraData );
       
   264         gc->ListenL( this );
       
   265         User::LeaveIfError( iGroupChannels.Append( gc ) );
       
   266         CleanupStack::Pop( gc ); //gc
       
   267         }
       
   268     }
       
   269 
       
   270 
       
   271 // -----------------------------------------------------------------------------
       
   272 // CCnUiClientGroupUiNotifyMediator::CancelActiveChannels()
       
   273 // -----------------------------------------------------------------------------
       
   274 //
       
   275 void CCnUiClientGroupUiNotifyMediator::CancelActiveChannels()
       
   276     {
       
   277     //issue the cancel to all channels
       
   278     const TInt channelCount = iGroupChannels.Count();
       
   279     for ( TInt ii( 0 ); ii < channelCount; ++ii  )
       
   280         {
       
   281         TInt ignore;
       
   282         TRAP( ignore, iGroupChannels[ ii ]->WriteL( ERemoteCancelAllActivity ) );
       
   283         }
       
   284 
       
   285     //and destroy those
       
   286     iGroupChannels.ResetAndDestroy();
       
   287     }
       
   288 
       
   289 
       
   290 // -----------------------------------------------------------------------------
       
   291 // CCnUiClientGroupUiNotifyMediator::RemoveFromActiveChannels()
       
   292 // -----------------------------------------------------------------------------
       
   293 //
       
   294 void CCnUiClientGroupUiNotifyMediator::RemoveFromActiveChannels( TInt aGroupId,
       
   295                                                                  TGCChannelID aChannelId )
       
   296     {
       
   297     //given channel is tried to remove from group of active channels
       
   298     //==> go downwards from the last index and remove all matching ones
       
   299     TInt ii = ( iGroupChannels.Count() - 1 ); //last index is 1 smaller than total count
       
   300     for ( ; ii >= 0; ii-- )
       
   301         {
       
   302         CCnUiGroupChannel* gc = iGroupChannels[ ii ];
       
   303         if ( ( gc->GroupID() == aGroupId ) && ( gc->ChannelId() == aChannelId ) )
       
   304             {
       
   305             iGroupChannels.Remove( ii );
       
   306             delete gc;
       
   307             }
       
   308         }
       
   309     }
       
   310 
       
   311 
       
   312 // end of file