141 iRamFull = EFalse; |
141 iRamFull = EFalse; |
142 iDiskFull = EFalse; |
142 iDiskFull = EFalse; |
143 iManualPauseEnabled = EFalse; |
143 iManualPauseEnabled = EFalse; |
144 iFastHarvestNeeded = EFalse; |
144 iFastHarvestNeeded = EFalse; |
145 iHarvestingPlaceholders = EFalse; |
145 iHarvestingPlaceholders = EFalse; |
|
146 |
|
147 iUnmountDetected = EFalse; |
146 } |
148 } |
147 |
149 |
148 // --------------------------------------------------------------------------- |
150 // --------------------------------------------------------------------------- |
149 // ~CHarvesterAO |
151 // ~CHarvesterAO |
150 // --------------------------------------------------------------------------- |
152 // --------------------------------------------------------------------------- |
204 iReadyPHArray.Close(); |
206 iReadyPHArray.Close(); |
205 |
207 |
206 iContainerPHArray.ResetAndDestroy(); |
208 iContainerPHArray.ResetAndDestroy(); |
207 iContainerPHArray.Close(); |
209 iContainerPHArray.Close(); |
208 |
210 |
|
211 iTempReadyPHArray.ResetAndDestroy(); |
|
212 iTempReadyPHArray.Close(); |
|
213 |
209 delete iHarvesterOomAO; |
214 delete iHarvesterOomAO; |
210 delete iRestoreWatcher; |
215 delete iRestoreWatcher; |
211 delete iOnDemandAO; |
216 delete iOnDemandAO; |
212 delete iMdEHarvesterSession; |
217 delete iMdEHarvesterSession; |
213 delete iMdESession; |
218 delete iMdESession; |
451 // --------------------------------------------------------------------------- |
456 // --------------------------------------------------------------------------- |
452 // |
457 // |
453 void CHarvesterAO::HandleUnmount( TUint32 aMediaId ) |
458 void CHarvesterAO::HandleUnmount( TUint32 aMediaId ) |
454 { |
459 { |
455 WRITELOG1( "CHarvesterAO::HandleUnmount(%d)", aMediaId ); |
460 WRITELOG1( "CHarvesterAO::HandleUnmount(%d)", aMediaId ); |
|
461 |
|
462 iUnmountDetected = ETrue; |
456 |
463 |
457 if( !iServerPaused ) |
464 if( !iServerPaused ) |
458 { |
465 { |
459 // Stop harvesting for unmount |
466 // Stop harvesting for unmount |
460 PauseMonitoring(); |
467 PauseMonitoring(); |
556 } |
563 } |
557 WRITELOG1( "CHarvesterAO::HandleUnmount() DecreaseItemCountL iContainerPHArray %d", removed); |
564 WRITELOG1( "CHarvesterAO::HandleUnmount() DecreaseItemCountL iContainerPHArray %d", removed); |
558 TRAP_IGNORE( iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypePlaceholder, removed) ); |
565 TRAP_IGNORE( iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypePlaceholder, removed) ); |
559 } |
566 } |
560 |
567 |
|
568 removed = 0; |
|
569 |
|
570 #ifdef _DEBUG |
|
571 WRITELOG1( "CHarvesterAO::HandleUnmount() iTempReadyPHArray.Count() = %d", iTempReadyPHArray.Count() ); |
|
572 #endif |
|
573 arrayCount = iTempReadyPHArray.Count(); |
|
574 if( arrayCount > 0 ) |
|
575 { |
|
576 for( TInt i=arrayCount-1; i>= 0; i--) |
|
577 { |
|
578 hd = iTempReadyPHArray[i]; |
|
579 err = iMediaIdUtil->GetMediaId( hd->Uri(), mediaId ); |
|
580 |
|
581 if( err == KErrNone && mediaId == aMediaId ) |
|
582 { |
|
583 WRITELOG1( "CHarvesterAO::HandleUnmount() remove iTempReadyPHArray %d", i); |
|
584 delete hd; |
|
585 hd = NULL; |
|
586 iTempReadyPHArray.Remove( i ); |
|
587 removed++; |
|
588 arrayCount--; |
|
589 } |
|
590 } |
|
591 if( iTempReadyPHArray.Count() == 0 ) |
|
592 { |
|
593 iTempReadyPHArray.Compress(); |
|
594 } |
|
595 WRITELOG1( "CHarvesterAO::HandleUnmount() DecreaseItemCountL iTempReadyPHArray %d", removed); |
|
596 TRAP_IGNORE( iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypePlaceholder, removed) ); |
|
597 } |
|
598 |
561 removed = 0; |
599 removed = 0; |
562 |
600 |
563 const TUint count = iQueue->ItemsInQueue(); |
601 const TUint count = iQueue->ItemsInQueue(); |
564 WRITELOG1( "CHarvesterAO::HandleUnmount() iQueue.Count() = %d", count ); |
602 WRITELOG1( "CHarvesterAO::HandleUnmount() iQueue.Count() = %d", count ); |
565 if( count > 0 ) |
603 if( count > 0 ) |
760 |
798 |
761 // make sure that when HandlePlaceholdersL leaves, iPHArray is cleared |
799 // make sure that when HandlePlaceholdersL leaves, iPHArray is cleared |
762 if ( err != KErrNone ) |
800 if ( err != KErrNone ) |
763 { |
801 { |
764 iPHArray.ResetAndDestroy(); |
802 iPHArray.ResetAndDestroy(); |
|
803 iTempReadyPHArray.ResetAndDestroy(); |
765 User::Leave( err ); |
804 User::Leave( err ); |
766 } |
805 } |
767 |
806 |
768 TInt count( iReadyPHArray.Count() ); |
807 TInt count( iReadyPHArray.Count() ); |
769 for( TInt i = 0; i < count; i++ ) |
808 for( TInt i = 0; i < count; i++ ) |
770 { |
809 { |
771 CheckFileExtensionAndHarvestL( iReadyPHArray[i] ); |
810 CheckFileExtensionAndHarvestL( iReadyPHArray[i] ); |
|
811 if( iUnmountDetected ) |
|
812 { |
|
813 break; |
|
814 } |
772 iReadyPHArray.Remove( i ); |
815 iReadyPHArray.Remove( i ); |
773 // correct the index so harvesting order remains ok |
816 // correct the index so harvesting order remains ok |
774 i--; |
817 i--; |
775 count--; |
818 count--; |
776 } |
819 } |
807 { |
856 { |
808 SetPriority( KHarvesterPriorityHarvestingPlugin ); |
857 SetPriority( KHarvesterPriorityHarvestingPlugin ); |
809 } |
858 } |
810 iHarvestingPlaceholders = EFalse; |
859 iHarvestingPlaceholders = EFalse; |
811 CheckFileExtensionAndHarvestL( hd ); |
860 CheckFileExtensionAndHarvestL( hd ); |
|
861 if( iUnmountDetected ) |
|
862 { |
|
863 iQueue->Append( hd ); |
|
864 } |
812 } |
865 } |
813 } |
866 } |
814 |
867 |
815 // --------------------------------------------------------------------------- |
868 // --------------------------------------------------------------------------- |
816 // HandlePlaceholdersL |
869 // HandlePlaceholdersL |
843 if( !CheckForCameraItem( hd, objDefStr ) ) |
896 if( !CheckForCameraItem( hd, objDefStr ) ) |
844 { |
897 { |
845 iHarvesterPluginFactory->GetObjectDefL( *hd, objDefStr ); |
898 iHarvesterPluginFactory->GetObjectDefL( *hd, objDefStr ); |
846 } |
899 } |
847 |
900 |
|
901 // GetObjectDef can cause context switch, and if unmount happens when this execution is |
|
902 // interrupted, the ph arrays can be invalid. Thus, abort whole run, and start over to make sure |
|
903 // the arrays are valid. |
|
904 if( iUnmountDetected ) |
|
905 { |
|
906 WRITELOG( "CHarvesterAO::HandlePlaceholdersL() - Unmount detected during execution!" ); |
|
907 for( TInt y( iTempReadyPHArray.Count() -1 ); y >=0; y-- ) |
|
908 { |
|
909 CHarvesterData* hd = iTempReadyPHArray[y]; |
|
910 iPHArray.Insert( hd, 0 ); |
|
911 } |
|
912 iTempReadyPHArray.Reset(); |
|
913 CleanupStack::PopAndDestroy( &mdeObjectArray ); |
|
914 return; |
|
915 } |
|
916 |
848 if( objDefStr.Length() == 0 || |
917 if( objDefStr.Length() == 0 || |
849 ( objDefStr == KInUse ) ) |
918 ( objDefStr == KInUse ) ) |
850 { |
919 { |
|
920 WRITELOG( "CHarvesterAO::HandlePlaceholdersL() - no objectDef or in use, failing harvesting" ); |
851 const TInt error( KErrUnknown ); |
921 const TInt error( KErrUnknown ); |
852 // notify observer, notification is needed even if file is not supported |
922 // notify observer, notification is needed even if file is not supported |
853 HarvestCompleted( hd->ClientId(), hd->Uri(), error ); |
923 HarvestCompleted( hd->ClientId(), hd->Uri(), error ); |
854 delete hd; |
924 delete hd; |
855 hd = NULL; |
925 hd = NULL; |
1016 |
1086 |
1017 CleanupStack::PopAndDestroy( phData ); |
1087 CleanupStack::PopAndDestroy( phData ); |
1018 |
1088 |
1019 CleanupStack::Pop( mdeObject ); |
1089 CleanupStack::Pop( mdeObject ); |
1020 |
1090 |
1021 iReadyPHArray.Append( hd ); |
1091 iTempReadyPHArray.Append( hd ); |
1022 iPHArray.Remove( i ); |
1092 iPHArray.Remove( i ); |
1023 i--; |
1093 i--; |
1024 endindex--; |
1094 endindex--; |
1025 } |
1095 } |
|
1096 |
|
1097 const TInt tempArrayCount( iTempReadyPHArray.Count() ); |
|
1098 for( TInt i( 0 ); i < tempArrayCount; i++ ) |
|
1099 { |
|
1100 CHarvesterData* hd = iTempReadyPHArray[i]; |
|
1101 iReadyPHArray.Append( hd ); |
|
1102 } |
|
1103 iTempReadyPHArray.Reset(); |
1026 |
1104 |
1027 const TInt objectCount = mdeObjectArray.Count(); |
1105 const TInt objectCount = mdeObjectArray.Count(); |
1028 |
1106 |
1029 if( objectCount > 0 ) |
1107 if( objectCount > 0 ) |
1030 { |
1108 { |
1055 } |
1133 } |
1056 |
1134 |
1057 iPHArray.ResetAndDestroy(); |
1135 iPHArray.ResetAndDestroy(); |
1058 |
1136 |
1059 CleanupStack::PopAndDestroy( &mdeObjectArray ); |
1137 CleanupStack::PopAndDestroy( &mdeObjectArray ); |
|
1138 |
|
1139 WRITELOG( "CHarvesterAO::HandlePlaceholdersL() - end" ); |
1060 } |
1140 } |
1061 |
1141 |
1062 // --------------------------------------------------------------------------- |
1142 // --------------------------------------------------------------------------- |
1063 // CheckFileExtensionAndHarvestL |
1143 // CheckFileExtensionAndHarvestL |
1064 // --------------------------------------------------------------------------- |
1144 // --------------------------------------------------------------------------- |
1074 { |
1154 { |
1075 objectExisted = EFalse; |
1155 objectExisted = EFalse; |
1076 WRITELOG1( "CHarvesterAO::CheckFileExtensionAndHarvestL() - no mdeobject. URI: %S", &uri ); |
1156 WRITELOG1( "CHarvesterAO::CheckFileExtensionAndHarvestL() - no mdeobject. URI: %S", &uri ); |
1077 TBuf<KObjectDefStrSize> objDefStr; |
1157 TBuf<KObjectDefStrSize> objDefStr; |
1078 iHarvesterPluginFactory->GetObjectDefL( *aHD, objDefStr ); |
1158 iHarvesterPluginFactory->GetObjectDefL( *aHD, objDefStr ); |
|
1159 |
|
1160 // GetObjectDef can cause context switch, and if unmount happens when this execution is |
|
1161 // interrupted, the ph data can be invalid. Thus, abort whole run, and start over to make sure |
|
1162 // the data is valid. |
|
1163 if( iUnmountDetected ) |
|
1164 { |
|
1165 return; |
|
1166 } |
1079 |
1167 |
1080 if( objDefStr.Length() == 0 ) |
1168 if( objDefStr.Length() == 0 ) |
1081 { |
1169 { |
1082 WRITELOG( "CHarvesterAO::CheckFileExtensionAndHarvestL() - cannot get object definition" ); |
1170 WRITELOG( "CHarvesterAO::CheckFileExtensionAndHarvestL() - cannot get object definition" ); |
1083 isError = ETrue; |
1171 isError = ETrue; |
1504 // --------------------------------------------------------------------------- |
1592 // --------------------------------------------------------------------------- |
1505 // |
1593 // |
1506 TInt CHarvesterAO::PauseHarvester() |
1594 TInt CHarvesterAO::PauseHarvester() |
1507 { |
1595 { |
1508 WRITELOG( "CHarvesterAO::PauseHarvester()" ); |
1596 WRITELOG( "CHarvesterAO::PauseHarvester()" ); |
1509 |
|
1510 Cancel(); |
|
1511 |
1597 |
1512 iHarvesterPluginFactory->PauseHarvester( ETrue ); |
1598 iHarvesterPluginFactory->PauseHarvester( ETrue ); |
1513 iServerPaused = ETrue; |
1599 iServerPaused = ETrue; |
1514 |
1600 |
1515 if( !iRamFull && !iDiskFull ) |
1601 if( !iRamFull && !iDiskFull && !iUnmountDetected ) |
1516 { |
1602 { |
1517 iManualPauseEnabled = ETrue; |
1603 iManualPauseEnabled = ETrue; |
1518 } |
1604 } |
1519 |
1605 |
1520 // Everything is paused |
1606 // Everything is paused |
1531 { |
1617 { |
1532 WRITELOG( "CHarvesterAO::ResumeHarvesterL()" ); |
1618 WRITELOG( "CHarvesterAO::ResumeHarvesterL()" ); |
1533 |
1619 |
1534 iHarvesterPluginFactory->PauseHarvester( EFalse ); |
1620 iHarvesterPluginFactory->PauseHarvester( EFalse ); |
1535 iServerPaused = EFalse; |
1621 iServerPaused = EFalse; |
|
1622 |
|
1623 if( !iManualPauseEnabled && |
|
1624 iNextRequest == ERequestIdle ) |
|
1625 { |
|
1626 SetNextRequest( ERequestHarvest ); |
|
1627 } |
|
1628 |
1536 iManualPauseEnabled = EFalse; |
1629 iManualPauseEnabled = EFalse; |
1537 |
|
1538 SetNextRequest( ERequestHarvest ); |
|
1539 } |
1630 } |
1540 |
1631 |
1541 // --------------------------------------------------------------------------- |
1632 // --------------------------------------------------------------------------- |
1542 // RunL |
1633 // RunL |
1543 // --------------------------------------------------------------------------- |
1634 // --------------------------------------------------------------------------- |
1548 // check if pause is requested |
1639 // check if pause is requested |
1549 if ( this->iServerPaused && iNextRequest != ERequestPause && iNextRequest != ERequestResume) |
1640 if ( this->iServerPaused && iNextRequest != ERequestPause && iNextRequest != ERequestResume) |
1550 { |
1641 { |
1551 iNextRequest = ERequestIdle; |
1642 iNextRequest = ERequestIdle; |
1552 } |
1643 } |
|
1644 |
|
1645 // Reset unmount flag, as unmount is handled before RunL is called again after aborted harvesting run |
|
1646 iUnmountDetected = EFalse; |
|
1647 |
1553 User::LeaveIfError( iStatus.Int() ); |
1648 User::LeaveIfError( iStatus.Int() ); |
1554 switch( iNextRequest ) |
1649 switch( iNextRequest ) |
1555 { |
1650 { |
1556 // no more items in queue |
1651 // no more items in queue |
1557 case ERequestIdle: |
1652 case ERequestIdle: |
1558 { |
1653 { |
1559 WRITELOG( "CHarvesterAO::RunL - ERequestIdle" ); |
1654 WRITELOG( "CHarvesterAO::RunL - ERequestIdle" ); |
1560 iReadyPHArray.Compress(); |
1655 iReadyPHArray.Compress(); |
1561 iContainerPHArray.Compress(); |
1656 iContainerPHArray.Compress(); |
1562 iPHArray.Compress(); |
1657 iPHArray.Compress(); |
|
1658 iTempReadyPHArray.Compress(); |
1563 } |
1659 } |
1564 break; |
1660 break; |
1565 |
1661 |
1566 // data added to harvester queue |
1662 // data added to harvester queue |
1567 case ERequestHarvest: |
1663 case ERequestHarvest: |
1569 WRITELOG( "CHarvesterAO::RunL - ERequestHarvest" ); |
1665 WRITELOG( "CHarvesterAO::RunL - ERequestHarvest" ); |
1570 |
1666 |
1571 // harvest new items first... |
1667 // harvest new items first... |
1572 if ( iQueue->ItemsInQueue() > 0 ) |
1668 if ( iQueue->ItemsInQueue() > 0 ) |
1573 { |
1669 { |
|
1670 WRITELOG( "CHarvesterAO::RunL - Items in queue - calling ReadItemFromQueueL()" ); |
1574 ReadItemFromQueueL(); |
1671 ReadItemFromQueueL(); |
1575 SetNextRequest( ERequestHarvest ); |
1672 SetNextRequest( ERequestHarvest ); |
1576 break; |
1673 break; |
1577 } |
1674 } |
1578 |
1675 |
1579 // no more items to handle from main queue |
1676 // no more items to handle from main queue |
1580 else |
1677 else |
1581 { |
1678 { |
|
1679 WRITELOG( "CHarvesterAO::RunL - No items in main queue" ); |
1582 // All registered fast harvested items or placeholders handled at this point |
1680 // All registered fast harvested items or placeholders handled at this point |
1583 // if container files to harvest, handle those next |
1681 // if container files to harvest, handle those next |
1584 if( iContainerPHArray.Count() > 0 ) |
1682 if( iContainerPHArray.Count() > 0 ) |
1585 { |
1683 { |
|
1684 WRITELOG( "CHarvesterAO::RunL - Items in iContainterPHArray - requesting ERequestContainerPlaceholder handling" ); |
1586 iFastHarvestNeeded = EFalse; |
1685 iFastHarvestNeeded = EFalse; |
1587 iHarvestingPlaceholders = EFalse; |
1686 iHarvestingPlaceholders = EFalse; |
1588 SetPriority( KHarvesterPriorityHarvestingPlugin ); |
1687 SetPriority( KHarvesterPriorityHarvestingPlugin ); |
1589 SetNextRequest( ERequestContainerPlaceholder ); |
1688 SetNextRequest( ERequestContainerPlaceholder ); |
1590 break; |
1689 break; |
1591 } |
1690 } |
1592 else if( iHarvestingPlaceholders || iFastHarvestNeeded ) |
1691 else if( iHarvestingPlaceholders || iFastHarvestNeeded ) |
1593 { |
1692 { |
|
1693 WRITELOG( "CHarvesterAO::RunL - No items in iContainerPHArray" ); |
|
1694 WRITELOG( "CHarvesterAO::RunL - PlaceholderHarvesting or FastHarvesting were enabled -> reset" ); |
|
1695 WRITELOG( "CHarvesterAO::RunL - next request for ERequestHarvest handling" ); |
1594 // reset to default priority |
1696 // reset to default priority |
1595 iFastHarvestNeeded = EFalse; |
1697 iFastHarvestNeeded = EFalse; |
1596 iHarvestingPlaceholders = EFalse; |
1698 iHarvestingPlaceholders = EFalse; |
1597 SetPriority( KHarvesterPriorityHarvestingPlugin ); |
1699 SetPriority( KHarvesterPriorityHarvestingPlugin ); |
1598 SetNextRequest( ERequestHarvest ); |
1700 SetNextRequest( ERequestHarvest ); |
1599 break; |
1701 break; |
1600 } |
1702 } |
|
1703 |
|
1704 WRITELOG( "CHarvesterAO::RunL - starting handling of iReadyPHArray items" ); |
1601 |
1705 |
1602 const TInt arrayCount( iReadyPHArray.Count() ); |
1706 const TInt arrayCount( iReadyPHArray.Count() ); |
1603 if( arrayCount > 0 ) |
1707 if( arrayCount > 0 ) |
1604 { |
1708 { |
1605 #ifdef _DEBUG |
1709 #ifdef _DEBUG |
1611 endIndex = arrayCount; |
1715 endIndex = arrayCount; |
1612 } |
1716 } |
1613 for( TInt i = 0; i < endIndex; i++ ) |
1717 for( TInt i = 0; i < endIndex; i++ ) |
1614 { |
1718 { |
1615 CheckFileExtensionAndHarvestL( iReadyPHArray[i] ); |
1719 CheckFileExtensionAndHarvestL( iReadyPHArray[i] ); |
|
1720 if( iUnmountDetected ) |
|
1721 { |
|
1722 break; |
|
1723 } |
1616 iReadyPHArray.Remove( i ); |
1724 iReadyPHArray.Remove( i ); |
1617 // correct the index so harvesting order remains ok |
1725 // correct the index so harvesting order remains ok |
1618 i--; |
1726 i--; |
1619 endIndex--; |
1727 endIndex--; |
1620 } |
1728 } |
1651 // make sure that when HandlePlaceholdersL leaves, iPHArray is cleared |
1759 // make sure that when HandlePlaceholdersL leaves, iPHArray is cleared |
1652 if ( err != KErrNone ) |
1760 if ( err != KErrNone ) |
1653 { |
1761 { |
1654 iContainerPHArray.ResetAndDestroy(); |
1762 iContainerPHArray.ResetAndDestroy(); |
1655 iPHArray.ResetAndDestroy(); |
1763 iPHArray.ResetAndDestroy(); |
|
1764 iTempReadyPHArray.ResetAndDestroy(); |
1656 User::Leave( err ); |
1765 User::Leave( err ); |
1657 } |
1766 } |
1658 SetNextRequest( ERequestHarvest ); |
1767 SetNextRequest( ERequestHarvest ); |
1659 } |
1768 } |
1660 break; |
1769 break; |
2419 WRITELOG( "CHarvesterAO::ContextSnapshotStatus() - successfully completed" ); |
2528 WRITELOG( "CHarvesterAO::ContextSnapshotStatus() - successfully completed" ); |
2420 } |
2529 } |
2421 if( aHD->Origin() == MdeConstants::Object::ECamera ) |
2530 if( aHD->Origin() == MdeConstants::Object::ECamera ) |
2422 { |
2531 { |
2423 aHD->MdeObject().SetPlaceholder( EFalse ); |
2532 aHD->MdeObject().SetPlaceholder( EFalse ); |
|
2533 TRAP_IGNORE( iHarvesterEventManager->DecreaseItemCountL( EHEObserverTypePlaceholder ) ); |
2424 TRAPD(mdeError, iMdeObjectHandler->SetMetadataObjectL( *aHD ) ); |
2534 TRAPD(mdeError, iMdeObjectHandler->SetMetadataObjectL( *aHD ) ); |
2425 if(mdeError != KErrNone) |
2535 if(mdeError != KErrNone) |
2426 { |
2536 { |
2427 WRITELOG( "==============================ERROR===============================" ); |
2537 WRITELOG( "==============================ERROR===============================" ); |
2428 WRITELOG( "CHarvesterAO::HarvestingCompleted() - cannot set metadata object" ); |
2538 WRITELOG( "CHarvesterAO::HarvestingCompleted() - cannot set metadata object" ); |