dosservices/commondsy/src/CDSYController.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2009 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:  Implementation of CCDSYController class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES 
       
    20 #include "CDSYController.h"
       
    21 #include "CDSYMessage.h"
       
    22 #include "CDSYServiceLogic.h"
       
    23 #include "CDSYMessagesServiceLogic.h"
       
    24 #include "commondsy_debug.h"
       
    25 
       
    26 
       
    27 // EXTERNAL DATA STRUCTURES
       
    28 // EXTERNAL FUNCTION PROTOTYPES  
       
    29 // CONSTANTS
       
    30 const TInt KServiceLogicArrayGranularity = 100;
       
    31 
       
    32 // MACROS
       
    33 // LOCAL CONSTANTS AND MACROS
       
    34 // MODULE DATA STRUCTURES
       
    35 // LOCAL FUNCTION PROTOTYPES
       
    36 // FORWARD DECLARATIONS
       
    37 
       
    38 
       
    39 // ============================= LOCAL FUNCTIONS ===============================
       
    40 
       
    41 
       
    42 
       
    43 // ============================ MEMBER FUNCTIONS ===============================
       
    44 
       
    45 
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CCDSYController::CCDSYController
       
    49 // -----------------------------------------------------------------------------
       
    50 CCDSYController::CCDSYController()
       
    51 : iCurrentTransactionID( 0 )
       
    52 , iServiceLogics( KServiceLogicArrayGranularity )
       
    53     {
       
    54     COM_TRACE_( "CDSY - CCDSYController::CCDSYController()" );
       
    55     COM_TRACE_( "CDSY - CCDSYController::CCDSYController - return void" );
       
    56     }
       
    57 
       
    58 
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CCDSYController::~CCDSYController
       
    62 // -----------------------------------------------------------------------------
       
    63 CCDSYController::~CCDSYController()
       
    64     {
       
    65     COM_TRACE_( "CDSY - CCDSYController::~CCDSYController()" );
       
    66 
       
    67     iServiceLogics.ResetAndDestroy();
       
    68 
       
    69     COM_TRACE_( "CDSY - CCDSYController::~CCDSYController - return void" );
       
    70     }
       
    71 
       
    72 
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CCDSYController::NewL
       
    76 // -----------------------------------------------------------------------------
       
    77 CCDSYController* CCDSYController::NewL()
       
    78     {
       
    79     COM_TRACE_( "CDSY - CCDSYController::NewL()" );
       
    80 
       
    81     CCDSYController* controller = new ( ELeave ) CCDSYController();
       
    82 
       
    83     COM_TRACE_1( "CDSY - CCDSYController::NewL - return 0x%x", controller );
       
    84     return controller;
       
    85     }
       
    86 
       
    87 
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // CCDSYController::ProcessMessageL
       
    91 // -----------------------------------------------------------------------------
       
    92 EXPORT_C void CCDSYController::ProcessMessageL( TCDSYMessage& aCDSYMessage )
       
    93     {
       
    94     COM_TRACE_1( "CDSY - CCDSYController::ProcessMessageL(0x%x)", &aCDSYMessage );
       
    95 
       
    96     TUint count = 0;
       
    97     for ( TInt i = 0; i < iServiceLogics.Count(); i++ )
       
    98         {
       
    99         if ( ( ( iServiceLogics[i] )->MessageGroup() == aCDSYMessage.Group() )
       
   100             && ( ( iServiceLogics[i] )->MessageID() == aCDSYMessage.ID() )
       
   101             && ( ( ( iServiceLogics[i] )->DynamicRegistration() == EFalse )
       
   102                 || ( ( ( iServiceLogics[i] )->DynamicRegistration() )
       
   103                     && ( ( iServiceLogics[i] )->MessageTransactionID() == aCDSYMessage.TransactionID() ) ) ) )
       
   104             {
       
   105             count++;
       
   106             ( ( iServiceLogics[i] )->CDSYServiceLogic() )->ProcessMessageL( aCDSYMessage );
       
   107             }
       
   108         }
       
   109     TRACE_ASSERT( count > 0 );
       
   110     TRACE_ASSERT( count < 2 );
       
   111    
       
   112     COM_TRACE_( "CDSY - CCDSYController::ProcessMessageL - return void" );
       
   113     }
       
   114 
       
   115 
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CCDSYController::RegisterServiceLogicL
       
   119 // -----------------------------------------------------------------------------
       
   120 EXPORT_C void CCDSYController::RegisterServiceLogicL( const TUint32 aMessageGroup, const TUint32 aMessageID, MCDSYServiceLogic* aCDSYServiceLogic )
       
   121     {
       
   122     COM_TRACE_3( "CDSY - CCDSYController::RegisterServiceLogicL(0x%x, 0x%x, 0x%x)", aMessageGroup, aMessageID, aCDSYServiceLogic );
       
   123 
       
   124 #ifdef _DEBUG
       
   125 
       
   126     // Check that this hasn't been already registered
       
   127     for ( TInt i = 0; i < iServiceLogics.Count(); i++ )
       
   128         {
       
   129         if ( ( ( iServiceLogics[i] )->MessageGroup() == aMessageGroup )
       
   130             && ( ( iServiceLogics[i] )->MessageID() == aMessageID ) )
       
   131             {
       
   132             TRACE_ASSERT_ALWAYS;
       
   133             }
       
   134         }
       
   135 
       
   136 #endif //#ifdef _DEBUG
       
   137 
       
   138     CCDSYMessagesServiceLogic* serviceLogic = CCDSYMessagesServiceLogic::NewL( aMessageGroup, aMessageID, aCDSYServiceLogic );
       
   139     TInt err = iServiceLogics.Append( serviceLogic );
       
   140     if ( err != KErrNone )
       
   141         {
       
   142         TRACE_ASSERT_ALWAYS;
       
   143         delete serviceLogic;
       
   144         User::Leave( err );
       
   145         }
       
   146      
       
   147     COM_TRACE_( "CDSY - CCDSYController::RegisterServiceLogicL - return void" );
       
   148     }
       
   149 
       
   150 
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // CCDSYController::RegisterServiceLogicL
       
   154 // -----------------------------------------------------------------------------
       
   155 EXPORT_C void CCDSYController::RegisterServiceLogicL( const TUint32 aMessageGroup, const TUint32 aMessageID, const TUint32 aTransactionID, MCDSYServiceLogic* aCDSYServiceLogic )
       
   156     {
       
   157     COM_TRACE_4( "CDSY - CCDSYController::RegisterServiceLogicL(0x%x, 0x%x, 0x%x, 0x%x)", aMessageGroup, aMessageID, aTransactionID, aCDSYServiceLogic );
       
   158 
       
   159 #ifdef _DEBUG
       
   160 
       
   161     // Check that this hasn't been already registered
       
   162     for ( TInt i = 0; i < iServiceLogics.Count(); i++ )
       
   163         {
       
   164         if ( ( ( iServiceLogics[i] )->MessageGroup() == aMessageGroup )
       
   165             && ( ( iServiceLogics[i] )->MessageID() == aMessageID ) )
       
   166             {
       
   167             TRACE_ASSERT_ALWAYS;
       
   168             }
       
   169         }
       
   170 
       
   171 #endif //#ifdef _DEBUG
       
   172 
       
   173     CCDSYMessagesServiceLogic* serviceLogic = CCDSYMessagesServiceLogic::NewL( aMessageGroup, aMessageID, aTransactionID, aCDSYServiceLogic );
       
   174     TInt err = iServiceLogics.Append( serviceLogic );
       
   175     if ( err != KErrNone )
       
   176         {
       
   177         TRACE_ASSERT_ALWAYS;
       
   178         delete serviceLogic;
       
   179         User::Leave( err );
       
   180         }
       
   181    
       
   182     COM_TRACE_( "CDSY - CCDSYController::RegisterServiceLogicL - return void" );
       
   183     }
       
   184 
       
   185 
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // CCDSYController::UnregisterServiceLogic
       
   189 // -----------------------------------------------------------------------------
       
   190 EXPORT_C void CCDSYController::UnregisterServiceLogic( const TUint32 aMessageGroup, const TUint32 aMessageID, const MCDSYServiceLogic* aCDSYServiceLogic )
       
   191     {
       
   192     COM_TRACE_3( "CDSY - CCDSYController::UnregisterServiceLogic(0x%x, 0x%x, 0x%x)", aMessageGroup, aMessageID, aCDSYServiceLogic );
       
   193 
       
   194     for ( TInt i = iServiceLogics.Count() - 1; i >= 0; i-- )
       
   195         {
       
   196         if ( ( ( iServiceLogics[i] )->CDSYServiceLogic() == aCDSYServiceLogic )
       
   197             && ( ( iServiceLogics[i] )->MessageGroup() == aMessageGroup )
       
   198             && ( ( iServiceLogics[i] )->MessageID() == aMessageID ) )
       
   199             {
       
   200             delete iServiceLogics[i];
       
   201             iServiceLogics.Remove( i );
       
   202             i = -1;
       
   203             }
       
   204         }
       
   205 
       
   206     COM_TRACE_( "CDSY - CCDSYController::UnregisterServiceLogic - return void" );
       
   207     }
       
   208 
       
   209 
       
   210 
       
   211 // -----------------------------------------------------------------------------
       
   212 // CCDSYController::UnregisterServiceLogic
       
   213 // -----------------------------------------------------------------------------
       
   214 EXPORT_C void CCDSYController::UnregisterServiceLogic( const TUint32 aMessageGroup, const TUint32 aMessageID, const TUint32 aTransactionID, const MCDSYServiceLogic* aCDSYServiceLogic )
       
   215     {
       
   216     COM_TRACE_4( "CDSY - CCDSYController::UnregisterServiceLogic(0x%x, 0x%x, 0x%x, 0x%x)", aMessageGroup, aMessageID, aTransactionID, aCDSYServiceLogic );
       
   217 
       
   218     for ( TInt i = iServiceLogics.Count() - 1; i >= 0; i-- )
       
   219         {
       
   220         if ( ( ( iServiceLogics[i] )->CDSYServiceLogic() == aCDSYServiceLogic )
       
   221             && ( ( iServiceLogics[i] )->MessageGroup() == aMessageGroup )
       
   222             && ( ( iServiceLogics[i] )->MessageID() == aMessageID )
       
   223             && ( ( iServiceLogics[i] )->MessageTransactionID() == aTransactionID ) )
       
   224             {
       
   225             delete iServiceLogics[i];
       
   226             iServiceLogics.Remove( i );
       
   227             i = -1;
       
   228             }
       
   229         }
       
   230 
       
   231     COM_TRACE_( "CDSY - CCDSYController::UnregisterServiceLogic - return void" );
       
   232     }
       
   233 
       
   234 
       
   235 
       
   236 // -----------------------------------------------------------------------------
       
   237 // CCDSYController::ExpireMessageL
       
   238 // -----------------------------------------------------------------------------
       
   239 EXPORT_C void CCDSYController::ExpireMessageL( TCDSYMessage& aCDSYMessage )
       
   240     {
       
   241     COM_TRACE_1( "CDSY - CCDSYController::ExpireMessageL(0x%x)", &aCDSYMessage );
       
   242 
       
   243     TUint count = 0;
       
   244     for ( TInt i = 0; i < iServiceLogics.Count(); i++ )
       
   245         {
       
   246         if((((iServiceLogics[i])->MessageGroup() == aCDSYMessage.Group())
       
   247                 && ((iServiceLogics[i])->MessageID() == aCDSYMessage.ID())
       
   248                 && ((iServiceLogics[i])->DynamicRegistration() == EFalse))
       
   249             || (((iServiceLogics[i])->DynamicRegistration() != EFalse)
       
   250                 && ((iServiceLogics[i])->MessageTransactionID() == aCDSYMessage.TransactionID())))
       
   251             {
       
   252             count++;
       
   253             ( ( iServiceLogics[i] )->CDSYServiceLogic() )->ExpireMessageL( aCDSYMessage );
       
   254             }
       
   255         if(((iServiceLogics[i])->DynamicRegistration() != EFalse)
       
   256             && ((iServiceLogics[i])->MessageTransactionID() == aCDSYMessage.TransactionID()))
       
   257             {
       
   258             delete iServiceLogics[i];
       
   259             iServiceLogics.Remove( i );
       
   260             i--;
       
   261             }
       
   262         }
       
   263     TRACE_ASSERT( count > 0 );
       
   264     TRACE_ASSERT( count < 2 );
       
   265 
       
   266     COM_TRACE_( "CDSY - CCDSYController::ExpireMessageL - return void" );
       
   267     }
       
   268 
       
   269 
       
   270 
       
   271 // -----------------------------------------------------------------------------
       
   272 // CCDSYController::GetNewTransactionID
       
   273 // -----------------------------------------------------------------------------
       
   274 EXPORT_C TUint8 CCDSYController::GetNewTransactionID()
       
   275     {
       
   276     COM_TRACE_( "CDSY - CCDSYController::GetNewTransactionID()" );
       
   277 
       
   278     iCurrentTransactionID++;
       
   279 
       
   280     COM_TRACE_1( "CDSY - CCDSYController::GetNewTransactionID - return 0x%x", iCurrentTransactionID );
       
   281     return iCurrentTransactionID;
       
   282     }
       
   283