commondrm/drmrightsmanagerui/src/DRMRightsMgrAppUi.cpp
changeset 29 3bdc3b853094
parent 23 493788a4a8a4
child 49 69d8e75812b7
equal deleted inserted replaced
23:493788a4a8a4 29:3bdc3b853094
    56 #include "oma2dcf.h"
    56 #include "oma2dcf.h"
    57 // CONSTANTS
    57 // CONSTANTS
    58 _LIT8( Kflk, "flk:" );
    58 _LIT8( Kflk, "flk:" );
    59 _LIT8( Kldf, "ldf:" );
    59 _LIT8( Kldf, "ldf:" );
    60 
    60 
    61 // ================= MEMBER FUNCTIONS =======================
    61 // ============================= LOCAL FUNCTIONS ===============================
       
    62 
       
    63 // ----------------------------------------------------------------------------
       
    64 // DoResetAndDestroy
       
    65 // Does RPointerArray< >->ResetAndDestroy() for the given array aPtr.
       
    66 // ----------------------------------------------------------------------------
       
    67 //
       
    68 LOCAL_C void DoResetAndDestroyPermission( TAny* aPtr )
       
    69     {
       
    70     ( reinterpret_cast< RPointerArray< CDRMPermission >* >( aPtr ) )->
       
    71         ResetAndDestroy();
       
    72     }
       
    73 
       
    74 // ----------------------------------------------------------------------------
       
    75 // PrepareRightsObjectL
       
    76 // Creates rights object based on the given permission.
       
    77 // ----------------------------------------------------------------------------
       
    78 //
       
    79 LOCAL_C void PrepareRightsObjectL( CDRMRights*& aRights,
       
    80                                    CDRMPermission* aPermission )
       
    81     {
       
    82     CDRMAsset* asset( NULL );
       
    83     
       
    84     if ( !aPermission )
       
    85         {
       
    86         User::Leave( KErrArgument );
       
    87         }
       
    88     
       
    89     aRights = CDRMRights::NewL();
       
    90     CleanupStack::PushL( aRights );
       
    91     aRights->SetPermissionL( *aPermission );
       
    92                          
       
    93     asset = CDRMAsset::NewLC();
       
    94     aRights->SetAssetL( *asset );
       
    95     CleanupStack::PopAndDestroy( asset );
       
    96     CleanupStack::Pop( aRights );
       
    97                          
       
    98     // Content URI and Local Id are not set
       
    99     }
       
   100 
       
   101 // ----------------------------------------------------------------------------
       
   102 // EndTime
       
   103 // Calculate the true end time: pick the smaller one of aTime1 & aTime2,
       
   104 // but ignore Time::NullTTime anyhow.
       
   105 // ----------------------------------------------------------------------------
       
   106 //
       
   107 LOCAL_C TTime EndTime( const TTime& aTime1, const TTime& aTime2 )
       
   108     {
       
   109     TTime nullTime = Time::NullTTime();
       
   110 
       
   111     if ( aTime1 == nullTime )
       
   112         {
       
   113         return aTime2;
       
   114         }
       
   115 
       
   116     if ( aTime2 == nullTime )
       
   117         {
       
   118         return aTime1;
       
   119         }
       
   120 
       
   121     return Min( aTime1, aTime2 );
       
   122     }
       
   123        
       
   124 // ================= MEMBER FUNCTIONS ==========================================
    62 //
   125 //
    63 // -----------------------------------------------------------------------------
   126 // -----------------------------------------------------------------------------
    64 // CDRMRightsMgrAppUi::CDRMRightsMgrAppUi
   127 // CDRMRightsMgrAppUi::CDRMRightsMgrAppUi
    65 // -----------------------------------------------------------------------------
   128 // -----------------------------------------------------------------------------
    66 //
   129 //
    90 
   153 
    91     BaseConstructL( EAknEnableSkin | EAppOrientationAutomatic |
   154     BaseConstructL( EAknEnableSkin | EAppOrientationAutomatic |
    92         EAknEnableMSK | EAknSingleClickCompatible  );
   155         EAknEnableMSK | EAknSingleClickCompatible  );
    93 
   156 
    94     User::LeaveIfError( iRightsClient.Connect() );
   157     User::LeaveIfError( iRightsClient.Connect() );
       
   158     User::LeaveIfError( iClockClient.Connect() );
    95     iDRMCommon = DRMCommon::NewL();
   159     iDRMCommon = DRMCommon::NewL();
    96     if ( !iDRMCommon )
   160     if ( !iDRMCommon )
    97         {
   161         {
    98         ProcessEngineErrorL( ETrue );
   162         ProcessEngineErrorL( ETrue );
    99         }
   163         }
   127     delete iWaitDialog;
   191     delete iWaitDialog;
   128 
   192 
   129     delete iDRMCommon;
   193     delete iDRMCommon;
   130 
   194 
   131     iRightsClient.Close();
   195     iRightsClient.Close();
       
   196     
       
   197     iClockClient.Close();
   132 
   198 
   133     if ( iStartEmbedded && iDoorObserver )
   199     if ( iStartEmbedded && iDoorObserver )
   134         {
   200         {
   135         iDoorObserver->NotifyExit( MApaEmbeddedDocObserver::ENoChanges );
   201         iDoorObserver->NotifyExit( MApaEmbeddedDocObserver::ENoChanges );
   136         }
   202         }
   555     {
   621     {
   556     // Refresh details view when the details view is returned
   622     // Refresh details view when the details view is returned
   557     // from the background to the foreground.
   623     // from the background to the foreground.
   558     if ( iForegroundHasBeenActive && iContentURI )
   624     if ( iForegroundHasBeenActive && iContentURI )
   559         {
   625         {
   560         StartOnlyForDetailsL( iContentURI->Des(), iLocalID,
   626         TRAP_IGNORE( StartOnlyForDetailsL( iContentURI->Des(), iLocalID, 
   561             iStartEmbedded, iDrmScheme );
   627             iStartEmbedded, iDrmScheme ) );
   562         }
   628         }
   563     }
   629     }
   564 
   630 
   565 
   631 
   566 // ----------------------------------------------------
   632 // ----------------------------------------------------
   737                                              CDRMRights*& aRights,
   803                                              CDRMRights*& aRights,
   738                                              TInt& aStatus )
   804                                              TInt& aStatus )
   739     {
   805     {
   740     TBool listable( EFalse ), sendable( EFalse );
   806     TBool listable( EFalse ), sendable( EFalse );
   741     TBool individualConstraint( EFalse ), usageAllowed( EFalse );
   807     TBool individualConstraint( EFalse ), usageAllowed( EFalse );
   742 
   808     TInt err( KErrNone );
       
   809     
       
   810 
       
   811     aStatus = KErrNone;
   743     CDcfRep* dcfRep = CDcfRep::NewL();
   812     CDcfRep* dcfRep = CDcfRep::NewL();
   744     CleanupStack::PushL( dcfRep );
   813     CleanupStack::PushL( dcfRep );
   745 
   814 
   746     if ( dcfRep )
   815     if ( dcfRep )
   747         {
   816         {
   796 
   865 
   797     if ( aLocalID > 0 )
   866     if ( aLocalID > 0 )
   798         {
   867         {
   799         aStatus = iDRMCommon->GetSingleRightsObject( aContentURI,
   868         aStatus = iDRMCommon->GetSingleRightsObject( aContentURI,
   800             aLocalID, aRights );
   869             aLocalID, aRights );
   801         if ( aStatus )
   870         CheckIndividualConstraint( aContentURI, individualConstraint, usageAllowed );
   802             {
   871         SetSelectedIndividualConstraint( individualConstraint );
   803             aRights = NULL;
   872         SetSelectedUsageAllowed( usageAllowed );
   804             }
       
   805         }
   873         }
   806     else
   874     else
   807         {
   875         {
   808         aStatus = iDRMCommon->GetActiveRights( aContentURI, 0, aRights );
   876         SetSelectedIndividualConstraint( EFalse );
   809         }
   877         SetSelectedUsageAllowed( ETrue );
   810 
   878         
   811     CheckIndividualConstraint( aContentURI, individualConstraint, usageAllowed );
   879         // Get active rights if available
   812     SetSelectedIndividualConstraint( individualConstraint );
   880         err = iDRMCommon->GetActiveRights( aContentURI, 0, aRights );
   813     SetSelectedUsageAllowed( usageAllowed );
   881         
       
   882         if ( err < 0 )
       
   883             {
       
   884             // Find out the best composition of rights that should be shown in the
       
   885             // details view. Checks also individual constraint.
       
   886             TRAP( aStatus, FindBestCompositionRightsL( aContentURI, aRights ) );
       
   887             }
       
   888         }
       
   889     
       
   890     if ( aStatus )
       
   891         {
       
   892         aRights = NULL;
       
   893         }
   814 
   894 
   815     CleanupStack::PopAndDestroy( dcfRep );
   895     CleanupStack::PopAndDestroy( dcfRep );
   816 
       
   817     // Do not show the note, show license information in the details view.
       
   818     }
   896     }
   819 
   897 
   820 // ---------------------------------------------------------
   898 // ---------------------------------------------------------
   821 // CDRMRightsMgrAppUi::CheckWmDrmRightsL
   899 // CDRMRightsMgrAppUi::CheckWmDrmRightsL
   822 // ---------------------------------------------------------
   900 // ---------------------------------------------------------
   878 //
   956 //
   879 void CDRMRightsMgrAppUi::CheckIndividualConstraint( const TDesC8& aContentURI,
   957 void CDRMRightsMgrAppUi::CheckIndividualConstraint( const TDesC8& aContentURI,
   880                                                     TBool& aIndividualConstraint,
   958                                                     TBool& aIndividualConstraint,
   881                                                     TBool& aUsageAllowed )
   959                                                     TBool& aUsageAllowed )
   882     {
   960     {
       
   961     
       
   962     TTime time;
       
   963     RPointerArray<HBufC8> individuals;
       
   964     
   883     RPointerArray<CDRMRights>* uriList = NULL;
   965     RPointerArray<CDRMRights>* uriList = NULL;
   884     TInt r = KErrNone;
   966     TInt r = KErrNone;
   885     TUint32 retval(0);
   967     TUint32 retval(0);
       
   968     TInt timeZone(0);
   886     DRMClock::ESecurityLevel secLevel = DRMClock::KInsecure;
   969     DRMClock::ESecurityLevel secLevel = DRMClock::KInsecure;
   887     CDRMRightsConstraints* constraint = NULL;
   970     CDRMRightsConstraints* constraint = NULL;
   888     RDRMClockClient client;
   971     
   889     RDRMRightsClient rclient;
   972     iClockClient.GetSecureTime(time, timeZone, secLevel);
   890     TTime time;
       
   891     RPointerArray<HBufC8> individuals;
       
   892 
       
   893     r = client.Connect();
       
   894     if ( r == KErrNone )
       
   895         {
       
   896         TTime time;
       
   897         TInt timeZone(0);
       
   898         client.GetSecureTime(time, timeZone, secLevel);
       
   899         }
       
   900 
   973 
   901     r = iDRMCommon->GetDetailedContentRights(aContentURI, uriList);
   974     r = iDRMCommon->GetDetailedContentRights(aContentURI, uriList);
   902     if ( r )
   975     if ( r )
   903         {
   976         {
   904         uriList=NULL;
   977         uriList=NULL;
   907     r = KErrNone;
   980     r = KErrNone;
   908 
   981 
   909     if ( !uriList || !uriList->Count() )
   982     if ( !uriList || !uriList->Count() )
   910         {
   983         {
   911         // no rights found
   984         // no rights found
   912         client.Close();
       
   913         delete uriList;
   985         delete uriList;
   914         uriList = NULL;
   986         uriList = NULL;
   915         }
   987         }
   916     else
   988     else
   917         {
   989         {
   918         // supported IMSI information is provided by rights client
   990         // supported IMSI information is provided by rights client
   919         r = rclient.Connect();
   991         TRAP( r, r = iRightsClient.GetSupportedIndividualsL( individuals ) );
   920         if( r == KErrNone)
       
   921             {
       
   922             TRAP( r, r = rclient.GetSupportedIndividualsL( individuals ) );
       
   923             rclient.Close();
       
   924             }
       
   925 
   992 
   926         // Check only the first entry in the list. This is to be expanded to check
   993         // Check only the first entry in the list. This is to be expanded to check
   927         // all the entries in the list.
   994         // all the entries in the list.
   928         for(TInt i = 0; i < 1; ++i)
   995         for(TInt i = 0; i < 1; ++i)
   929             {
   996             {
   957                 }
  1024                 }
   958             delete constraint;
  1025             delete constraint;
   959             constraint = NULL;
  1026             constraint = NULL;
   960             }
  1027             }
   961 
  1028 
   962         client.Close();
       
   963         uriList->ResetAndDestroy();
  1029         uriList->ResetAndDestroy();
   964 
  1030 
   965         delete uriList;
  1031         delete uriList;
   966         uriList = NULL;
  1032         uriList = NULL;
   967         individuals.ResetAndDestroy();
  1033         individuals.ResetAndDestroy();
   968         individuals.Close();
  1034         individuals.Close();
   969         }
  1035         }
   970     }
  1036     }
   971 
  1037 
       
  1038 // ---------------------------------------------------------
       
  1039 // CDRMRightsMgrAppUi::FindBestCompositionRightsL
       
  1040 // ---------------------------------------------------------
       
  1041 //
       
  1042 void CDRMRightsMgrAppUi::FindBestCompositionRightsL( const TDesC8& aContentURI,
       
  1043                                                      CDRMRights*& aRights )
       
  1044     {
       
  1045     TInt i, j, k;
       
  1046     RPointerArray<CDRMPermission> permissionList;
       
  1047     RPointerArray<CDRMPermission> permissionTempList;
       
  1048     RPointerArray<HBufC8> parentUidList;
       
  1049     RPointerArray<HBufC8> individuals;
       
  1050     
       
  1051     TInt count( 0 );
       
  1052     TInt status( KErrNone );
       
  1053     TTime time( Time::NullTTime() );
       
  1054     TInt err( KErrNone );
       
  1055     TUint32 reason( EConstraintNone );
       
  1056     TBool individualConstraintFound( EFalse );
       
  1057     
       
  1058     // Composition object of best rights to be shown in the 
       
  1059     // details view
       
  1060     CDRMPermission* perm( NULL ); 
       
  1061     
       
  1062     TCleanupItem cleanupPerm( DoResetAndDestroyPermission, &permissionList );
       
  1063     CleanupStack::PushL( cleanupPerm );
       
  1064     
       
  1065     TCleanupItem cleanupPerm2( DoResetAndDestroyPermission, 
       
  1066             &permissionTempList );
       
  1067     CleanupStack::PushL( cleanupPerm2 );
       
  1068     
       
  1069     CleanupClosePushL( parentUidList );
       
  1070     
       
  1071     // First get list of child ROs with the given Content URI
       
  1072     iRightsClient.GetDBEntriesL( aContentURI, permissionList );            
       
  1073     
       
  1074     if ( permissionList.Count() > 0 )
       
  1075         {        
       
  1076         // Check the UIDs of the possible parent rights objects
       
  1077         // and store the found ones to another pointer array for evaluation
       
  1078         for ( i = 0; i < permissionList.Count(); i++ )
       
  1079             {
       
  1080             if ( permissionList[i]->iParentUID )
       
  1081                 {
       
  1082                 if ( i == 0 )
       
  1083                     {
       
  1084                     // No need to check if the parent UID is a duplicate
       
  1085                     parentUidList.Append( permissionList[i]->iParentUID );
       
  1086                     }
       
  1087                 else 
       
  1088                     {
       
  1089                     // Check parent UID list whether we have already stored the
       
  1090                     // UID or not
       
  1091                     for( j = 0; j < parentUidList.Count(); j++ )
       
  1092                         {
       
  1093                         if ( parentUidList[j]->Des().Compare(
       
  1094                                 permissionList[i]->iParentUID->Des() ) != 0 )
       
  1095                             {
       
  1096                             parentUidList.Append( 
       
  1097                                     permissionList[i]->iParentUID );
       
  1098                             break;
       
  1099                             }
       
  1100                         }
       
  1101                     }
       
  1102                 }
       
  1103             }
       
  1104         
       
  1105         // Get the list of parent rights objects based on the parent UID 
       
  1106         // and store the pointers from temporary array to the main list 
       
  1107         for ( j = 0; j < parentUidList.Count(); j++ )
       
  1108             {
       
  1109             // We do not want to leave if nothing is found from the database
       
  1110             TRAP( status, iRightsClient.GetDBEntriesL( parentUidList[j]->Des(),
       
  1111                     permissionTempList ) );
       
  1112             
       
  1113             if ( status )
       
  1114                 {
       
  1115                 continue;
       
  1116                 }
       
  1117                     
       
  1118             for ( k = 0; k < permissionTempList.Count(); k++ ) 
       
  1119                 {
       
  1120                 // Store the pointer to the main list of permissions
       
  1121                 permissionList.Append( permissionTempList[k] );
       
  1122                 }    
       
  1123                     
       
  1124             // Close the temporary pointer array so that the referenced 
       
  1125             // objects of it will not be deleted in the next round of the 
       
  1126             // loop because the method for getting database entries deletes 
       
  1127             // also the objects (by calling reset and destroy to the given 
       
  1128             // pointer array) by default.
       
  1129             permissionTempList.Close();
       
  1130             }
       
  1131         
       
  1132         parentUidList.Close();
       
  1133         time.HomeTime();
       
  1134         
       
  1135         // supported IMSI information is provided by rights client
       
  1136         TRAP( err, err = iRightsClient.GetSupportedIndividualsL( individuals ) );
       
  1137         
       
  1138         // Filter expired parent and child rights from the list
       
  1139         // Index defines the index of the list to be operated (next)
       
  1140         for ( count = permissionList.Count() ; count > 0; count-- )
       
  1141             {
       
  1142             if ( permissionList[count - 1]->Expired( time ) ) 
       
  1143                 {
       
  1144                 permissionList.Remove( count - 1 );
       
  1145                 }
       
  1146             else if ( !( permissionList[count - 1]->Valid( 
       
  1147                     time, individuals, reason ) ) )
       
  1148                 {
       
  1149                 if ( reason & EConstraintIndividual )
       
  1150                     {
       
  1151                     individualConstraintFound = ETrue;
       
  1152                     permissionList.Remove( count - 1 );
       
  1153                     }
       
  1154                 }
       
  1155             }        
       
  1156         
       
  1157         individuals.ResetAndDestroy();
       
  1158         individuals.Close();
       
  1159         
       
  1160         if ( permissionList.Count() == 0 )
       
  1161             {
       
  1162             if ( individualConstraintFound )
       
  1163                 {
       
  1164                 SetSelectedIndividualConstraint( ETrue );
       
  1165                 SetSelectedUsageAllowed( EFalse );
       
  1166                 }
       
  1167             User::Leave( KErrNotFound );
       
  1168             }
       
  1169         else if ( permissionList.Count() == 1  )
       
  1170             {
       
  1171             // Keep this permission because it is the only valid (left)
       
  1172             PrepareRightsObjectL( aRights, permissionList[0] );
       
  1173             }
       
  1174         else if ( permissionList.Count() > 1 )
       
  1175             {    
       
  1176             // Compare constraints from successive items of the 
       
  1177             // permission list and update the composition permission 
       
  1178             // accordingly. 
       
  1179             CheckBetterPermissionsAndStoreCompositionLC( perm, permissionList );
       
  1180                 
       
  1181             // Prepare the rights object with the composition permission
       
  1182             PrepareRightsObjectL( aRights, perm );
       
  1183             CleanupStack::PopAndDestroy( perm );   
       
  1184             }     
       
  1185         }
       
  1186         
       
  1187         CleanupStack::PopAndDestroy( 3, &permissionList ); // cleanupPerm, 
       
  1188                                                            // cleanupPerm2, 
       
  1189                                                            // parentUidList
       
  1190     }
       
  1191 
       
  1192 // -------------------------------------------------------------------
       
  1193 // CDRMRightsMgrAppUi::CheckBetterPermissionsAndStoreCompositionLC
       
  1194 // -------------------------------------------------------------------
       
  1195 //
       
  1196 void CDRMRightsMgrAppUi::CheckBetterPermissionsAndStoreCompositionLC( 
       
  1197             CDRMPermission*& aCompositionPermission,
       
  1198             RPointerArray<CDRMPermission>& aList )
       
  1199     {       
       
  1200     
       
  1201     TBool firstBetter( EFalse );
       
  1202     TUint i, j;
       
  1203     
       
  1204     if ( aList.Count() <= 0 )
       
  1205         {
       
  1206         User::Leave( KErrArgument );
       
  1207         }
       
  1208     
       
  1209     // create permission if needed and set the first item
       
  1210     // in the permission list as the reference permission.
       
  1211     if ( !aCompositionPermission )
       
  1212         {
       
  1213         aCompositionPermission = CDRMPermission::NewL();
       
  1214         }
       
  1215          
       
  1216     CleanupStack::PushL( aCompositionPermission );
       
  1217     aCompositionPermission->DuplicateL( *aList[0] );
       
  1218     
       
  1219     // The double loop goes through the permissions and associated 
       
  1220     // constraints beginning from the second entry in the permission list. 
       
  1221     for ( i = 1; i < aList.Count(); i++ )
       
  1222         {
       
  1223         // Enumeration for TIntent from Content Access Framework used
       
  1224         for ( j = EPlay; j < EPause; j++ )
       
  1225             { 
       
  1226             switch ( j )
       
  1227                 {
       
  1228                 case EPlay:
       
  1229                     {
       
  1230                     // The constraint from the permission in the list
       
  1231                     // is set to composition permission if it is better
       
  1232                     // than the "old" best or reference permission.
       
  1233                     firstBetter = BetterPermission( *aList[i]->iPlay,
       
  1234                             *aCompositionPermission->iPlay );
       
  1235                     if ( firstBetter )
       
  1236                         {
       
  1237                         aCompositionPermission->iPlay->DuplicateL( 
       
  1238                                 *aList[i]->iPlay );
       
  1239                         }
       
  1240                     break;
       
  1241                     }
       
  1242                 case EView:
       
  1243                     {
       
  1244                     firstBetter = BetterPermission( *aList[i]->iDisplay, 
       
  1245                             *aCompositionPermission->iDisplay );
       
  1246                     if ( firstBetter )
       
  1247                         {
       
  1248                         aCompositionPermission->iDisplay->DuplicateL( 
       
  1249                                 *aList[i]->iDisplay );
       
  1250                         }
       
  1251                     break;
       
  1252                     }
       
  1253                 case EExecute:
       
  1254                     {
       
  1255                     firstBetter = BetterPermission( *aList[i]->iExecute,
       
  1256                             *aCompositionPermission->iExecute );
       
  1257                     if ( firstBetter )
       
  1258                         {
       
  1259                         aCompositionPermission->iExecute->DuplicateL(
       
  1260                                 *aList[i]->iExecute );
       
  1261                         }
       
  1262                     break;
       
  1263                     }
       
  1264                 case EPrint:
       
  1265                     {
       
  1266                     firstBetter = BetterPermission( *aList[i]->iPrint,
       
  1267                             *aCompositionPermission->iPrint );
       
  1268                     if ( firstBetter )
       
  1269                         {
       
  1270                         aCompositionPermission->iPrint->DuplicateL( 
       
  1271                                 *aList[i]->iPrint );
       
  1272                         }
       
  1273                     break;
       
  1274                     }
       
  1275                 default:
       
  1276                     {
       
  1277                     User::Leave( KErrArgument );
       
  1278                     }
       
  1279                 }
       
  1280             }
       
  1281         }        
       
  1282     }                     
       
  1283 
       
  1284 // -----------------------------------------------------------------------------
       
  1285 // CDrmRightsMgrAppUi::BetterPermission
       
  1286 // -----------------------------------------------------------------------------
       
  1287 TBool CDRMRightsMgrAppUi::BetterPermission( const CDRMConstraint& aNewOne,
       
  1288                                             const CDRMConstraint& aOldOne )
       
  1289         {
       
  1290         // Check Order:
       
  1291         // 1. Full
       
  1292         // 2. Start End, closest end time first
       
  1293         // 3. Interval, shortest first
       
  1294         // 4. Accumulated, shortest first
       
  1295         // 5. Timed Counter, least counters first, longest time first
       
  1296         // 6. Counter, least counters first or the first one found
       
  1297 
       
  1298         const TTime nullTime = Time::NullTTime();
       
  1299         TTime oldTime = nullTime;
       
  1300         TTime newTime = nullTime;
       
  1301         TTime oldTimePos = nullTime;
       
  1302         TTime newTimePos = nullTime;
       
  1303         TTime trustedTime = nullTime;
       
  1304         
       
  1305         // 1. Full
       
  1306         // If the old or new one is the ultimate one, don't bother to
       
  1307         // check anything else.
       
  1308         if ( aOldOne.iActiveConstraints == EConstraintNone )
       
  1309             {
       
  1310             return EFalse;
       
  1311             }
       
  1312 
       
  1313         if ( aNewOne.iActiveConstraints == EConstraintNone )
       
  1314             {
       
  1315             return ETrue;
       
  1316             }
       
  1317 
       
  1318         // 2. Start & End Time
       
  1319         // Choose the one with the closest end time first
       
  1320         // All RO's to this check are already checked to be valid
       
  1321         // ActiveIntervals Also hit this spot
       
  1322         
       
  1323         trustedTime.HomeTime();
       
  1324             
       
  1325         // First get the start and end times from the intervals if they are active or inactive:
       
  1326         if ( aOldOne.iActiveConstraints & EConstraintInterval )
       
  1327             {
       
  1328             if( aOldOne.iIntervalStart == nullTime )
       
  1329                 {
       
  1330                 oldTimePos = trustedTime;
       
  1331                 oldTimePos += TTimeIntervalSeconds( aOldOne.iInterval );
       
  1332                 }
       
  1333             else
       
  1334                 {
       
  1335                 oldTime = aOldOne.iIntervalStart;
       
  1336                 oldTime += TTimeIntervalSeconds( aOldOne.iInterval );
       
  1337                 }
       
  1338             }
       
  1339 
       
  1340         if( aNewOne.iActiveConstraints & EConstraintInterval )
       
  1341             {
       
  1342             if( aNewOne.iIntervalStart == nullTime )
       
  1343                 {
       
  1344                 newTimePos = trustedTime;
       
  1345                 newTimePos += TTimeIntervalSeconds( aNewOne.iInterval );
       
  1346                 }
       
  1347             else
       
  1348                 {
       
  1349                 newTime = aNewOne.iIntervalStart;
       
  1350                 newTime += TTimeIntervalSeconds( aNewOne.iInterval );
       
  1351                 }
       
  1352             }
       
  1353 
       
  1354         if ( aOldOne.iActiveConstraints & EConstraintEndTime || oldTime != nullTime )
       
  1355             {
       
  1356             oldTime = EndTime( oldTime, aOldOne.iEndTime );
       
  1357 
       
  1358             if ( aNewOne.iActiveConstraints & EConstraintEndTime || newTime != nullTime )
       
  1359                 {
       
  1360                 newTime = EndTime( newTime, aNewOne.iEndTime );
       
  1361 
       
  1362                 if( newTime != oldTime )
       
  1363                     {
       
  1364                     return ( newTime < oldTime );
       
  1365                     }
       
  1366                 }
       
  1367             else
       
  1368                 {
       
  1369                 return EFalse;
       
  1370                 }
       
  1371             }
       
  1372         else if ( aNewOne.iActiveConstraints & EConstraintEndTime || newTime != nullTime )
       
  1373             {
       
  1374             return ETrue;
       
  1375             }
       
  1376 
       
  1377         // 3. Inactive Intervals:
       
  1378         // Choose the one with the interval ending first:
       
  1379         // Continue here if the no SE's exist or SE's are the same
       
  1380         if( aOldOne.iActiveConstraints & EConstraintInterval )
       
  1381             {
       
  1382             if( aNewOne.iActiveConstraints & EConstraintInterval )
       
  1383                 {
       
  1384                 oldTimePos = EndTime( oldTime, oldTimePos );
       
  1385                 newTimePos = EndTime( newTime, newTimePos );
       
  1386 
       
  1387                 if( oldTimePos != newTimePos )
       
  1388                     {
       
  1389                     return ( newTimePos < oldTimePos );
       
  1390                     }
       
  1391                 }
       
  1392             else
       
  1393                 {
       
  1394                 if( aNewOne.iActiveConstraints & EConstraintAccumulated ||
       
  1395                     aNewOne.iActiveConstraints & EConstraintTimedCounter ||
       
  1396                     aNewOne.iActiveConstraints & EConstraintCounter )
       
  1397                     {
       
  1398                     return EFalse;
       
  1399                     }
       
  1400                 else
       
  1401                     {
       
  1402                     return ETrue;
       
  1403                     }
       
  1404                 }
       
  1405             }
       
  1406         else if( aNewOne.iActiveConstraints & EConstraintInterval )
       
  1407             {
       
  1408             if( aOldOne.iActiveConstraints & EConstraintAccumulated ||
       
  1409                 aOldOne.iActiveConstraints & EConstraintTimedCounter ||
       
  1410                 aOldOne.iActiveConstraints & EConstraintCounter )
       
  1411                 {
       
  1412                 return ETrue;
       
  1413                 }
       
  1414             else
       
  1415                 {
       
  1416                 return EFalse;
       
  1417                 }
       
  1418             }
       
  1419 
       
  1420         // 4. Accumulated:
       
  1421         // Choose the shortest accumulated first
       
  1422         // Continue here if SE's or intervals do not exist or they are the same
       
  1423         if( aOldOne.iActiveConstraints & EConstraintAccumulated )
       
  1424             {
       
  1425             if( aNewOne.iActiveConstraints & EConstraintAccumulated )
       
  1426                 {
       
  1427                 if( aNewOne.iAccumulatedTime != aOldOne.iAccumulatedTime )
       
  1428                     {
       
  1429                     return ( aNewOne.iAccumulatedTime < aOldOne.iAccumulatedTime );
       
  1430                     }
       
  1431                 }
       
  1432             else
       
  1433                 {
       
  1434                 if( aNewOne.iActiveConstraints & EConstraintTimedCounter ||
       
  1435                     aNewOne.iActiveConstraints & EConstraintCounter )
       
  1436                     {
       
  1437                     return EFalse;
       
  1438                     }
       
  1439                 else
       
  1440                     {
       
  1441                     return ETrue;
       
  1442                     }
       
  1443                 }
       
  1444             }
       
  1445         else if( aNewOne.iActiveConstraints & EConstraintAccumulated )
       
  1446             {
       
  1447             if( aOldOne.iActiveConstraints & EConstraintTimedCounter ||
       
  1448                 aOldOne.iActiveConstraints & EConstraintCounter )
       
  1449                 {
       
  1450                 return ETrue;
       
  1451                 }
       
  1452             else
       
  1453                 {
       
  1454                 return EFalse;
       
  1455                 }
       
  1456             }
       
  1457 
       
  1458 
       
  1459         // 5. Timed Counter
       
  1460         // Choose the one with least counters first. If there is an equal number of counters
       
  1461         // left, use the one with the longest time
       
  1462         // Continue here if SE's or intervals or accumulateds do not exist or they are the same
       
  1463         if( aOldOne.iActiveConstraints & EConstraintTimedCounter )
       
  1464             {
       
  1465             if( aNewOne.iActiveConstraints & EConstraintTimedCounter )
       
  1466                 {
       
  1467                 if( aNewOne.iTimedCounter == aOldOne.iTimedCounter )
       
  1468                     {
       
  1469                     if( aNewOne.iTimedInterval != aOldOne.iTimedInterval )
       
  1470                         {
       
  1471                         return ( aNewOne.iTimedInterval < aOldOne.iTimedInterval );
       
  1472                         }
       
  1473                     else
       
  1474                         {
       
  1475                         if( aNewOne.iActiveConstraints & EConstraintCounter )
       
  1476                             {
       
  1477 
       
  1478                             }
       
  1479                         }
       
  1480                     }
       
  1481                 else
       
  1482                     {
       
  1483                     return ( aNewOne.iTimedCounter < aOldOne.iTimedCounter );
       
  1484                     }
       
  1485 
       
  1486                 }
       
  1487             else
       
  1488                 {
       
  1489                 if( aNewOne.iActiveConstraints & EConstraintCounter )
       
  1490                     {
       
  1491                     return EFalse;
       
  1492                     }
       
  1493                 else
       
  1494                     {
       
  1495                     return ETrue;
       
  1496                     }
       
  1497                 }
       
  1498             }
       
  1499         else if( aNewOne.iActiveConstraints & EConstraintTimedCounter )
       
  1500             {
       
  1501             if( aOldOne.iActiveConstraints & EConstraintCounter )
       
  1502                 {
       
  1503                 return ETrue;
       
  1504                 }
       
  1505             else
       
  1506                 {
       
  1507                 return EFalse;
       
  1508                 }
       
  1509             }
       
  1510 
       
  1511         // 6. Counter
       
  1512         // Choose the one with least counters:
       
  1513         // if they are the same choose the first one.
       
  1514         // Continue here if SE's or intervals or accumulateds or timed counters
       
  1515         // do not exist or they are the same
       
  1516         if( aOldOne.iActiveConstraints & EConstraintCounter )
       
  1517             {
       
  1518             if( aNewOne.iActiveConstraints & EConstraintCounter )
       
  1519                 {
       
  1520                 return ( aNewOne.iCounter < aOldOne.iCounter );
       
  1521                 }
       
  1522             else
       
  1523                 {
       
  1524                 return ETrue;
       
  1525                 }
       
  1526             }
       
  1527 
       
  1528         // If all else fails use the old one:
       
  1529         return EFalse;
       
  1530         }
       
  1531 
   972 // End of File
  1532 // End of File