htiui/HtiServicePlugins/HtiSysInfoServicePlugin/src/HtiSysInfoServicePlugin.cpp
branchRCL_3
changeset 8 69ec17276f52
parent 3 2703485a934c
child 18 454d022d514b
equal deleted inserted replaced
7:685c7418c584 8:69ec17276f52
    58 const TInt KMaxBtNameLength = 30;
    58 const TInt KMaxBtNameLength = 30;
    59 const TInt KDateTimeFormatCmdLength = 6;
    59 const TInt KDateTimeFormatCmdLength = 6;
    60 
    60 
    61 _LIT( KTempFilePath, "\\" );
    61 _LIT( KTempFilePath, "\\" );
    62 _LIT( KTempFileName, "HtiTempFile.tmp" );
    62 _LIT( KTempFileName, "HtiTempFile.tmp" );
       
    63 _LIT( KMatchFileName, "HtiTempFile.tmp*" );
    63 _LIT( KDateSeparatorChars, ".:/-" );
    64 _LIT( KDateSeparatorChars, ".:/-" );
    64 _LIT( KTimeSeparatorChars, ".:" );
    65 _LIT( KTimeSeparatorChars, ".:" );
    65 
    66 
    66 _LIT8( KErrDescrArgument, "Invalid argument" );
    67 _LIT8( KErrDescrArgument, "Invalid argument" );
    67 _LIT8( KErrDescrNotSupported, "Command not supported" );
    68 _LIT8( KErrDescrNotSupported, "Command not supported" );
  1086 //------------------------------------------------------------------------------
  1087 //------------------------------------------------------------------------------
  1087 // CHtiSysInfoServicePlugin::HandleEatDiskSpaceL
  1088 // CHtiSysInfoServicePlugin::HandleEatDiskSpaceL
  1088 //------------------------------------------------------------------------------
  1089 //------------------------------------------------------------------------------
  1089 void CHtiSysInfoServicePlugin::HandleEatDiskSpaceL( const TDesC8& aMessage )
  1090 void CHtiSysInfoServicePlugin::HandleEatDiskSpaceL( const TDesC8& aMessage )
  1090     {
  1091     {
       
  1092     HTI_LOG_FUNC_IN( "CHtiSysInfoServicePlugin::HandleEatDiskSpaceL" );
       
  1093     
  1091     if ( aMessage.Length() != 10 )
  1094     if ( aMessage.Length() != 10 )
  1092         {
  1095         {
  1093         iDispatcher->DispatchOutgoingErrorMessage(
  1096         iDispatcher->DispatchOutgoingErrorMessage(
  1094             KErrArgument,
  1097             KErrArgument,
  1095             KErrDescrArgument,
  1098             KErrDescrArgument,
  1096             KSysInfoServiceUid );
  1099             KSysInfoServiceUid );
  1097         return;
  1100         HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleEatDiskSpaceL" );
  1098         }
  1101         return;
  1099 
  1102         }
  1100 
  1103 
       
  1104     TFileName commonpath;
       
  1105     commonpath.Append( aMessage[1] );
       
  1106     commonpath.Append( _L( ":" ) );
       
  1107     commonpath.Append( KTempFilePath );
       
  1108     commonpath.Append( KTempFileName );
  1101     TFileName path;
  1109     TFileName path;
  1102     path.Append( aMessage[1] );
  1110         
  1103     path.Append( _L( ":" ) );
       
  1104     path.Append( KTempFilePath );
       
  1105     path.Append( KTempFileName );
       
  1106 
       
  1107     HTI_LOG_TEXT( "Temp file path:" );
       
  1108     HTI_LOG_DES( path );
       
  1109 
       
  1110     // check if previous temp file exists and delete it
       
  1111     if ( BaflUtils::FileExists( iFs, path ) )
       
  1112         {
       
  1113         TInt err = iFileMan->Delete( path );
       
  1114         if ( err )
       
  1115             {
       
  1116             iDispatcher->DispatchOutgoingErrorMessage(
       
  1117                 err,
       
  1118                 KErrDescrDeleteTempFile,
       
  1119                 KSysInfoServiceUid );
       
  1120             return;
       
  1121             }
       
  1122         }
       
  1123 
       
  1124     // get free disk space
  1111     // get free disk space
  1125     TInt drive;
  1112     TInt drive;
  1126     RFs::CharToDrive( TChar( aMessage[1] ), drive );
  1113     RFs::CharToDrive( TChar( aMessage[1] ), drive );
  1127     TVolumeInfo volInfo;
  1114     TVolumeInfo volInfo;
  1128     TInt err = iFs.Volume( volInfo, drive );
  1115     TInt err = iFs.Volume( volInfo, drive );
  1130         {
  1117         {
  1131         iDispatcher->DispatchOutgoingErrorMessage(
  1118         iDispatcher->DispatchOutgoingErrorMessage(
  1132             err,
  1119             err,
  1133             KErrDescrVolInfo,
  1120             KErrDescrVolInfo,
  1134             KSysInfoServiceUid );
  1121             KSysInfoServiceUid );
       
  1122         HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleEatDiskSpaceL" );
  1135         return;
  1123         return;
  1136         }
  1124         }
  1137 
  1125 
  1138     // calculate how much we must eat the disk space
  1126     // calculate how much we must eat the disk space
  1139     TInt64 temp1 = aMessage[2] +
  1127     TInt64 temp1 = aMessage[2] +
  1155         {
  1143         {
  1156         iDispatcher->DispatchOutgoingErrorMessage(
  1144         iDispatcher->DispatchOutgoingErrorMessage(
  1157             KErrDiskFull,
  1145             KErrDiskFull,
  1158             KErrDescrNotEnoughSpace,
  1146             KErrDescrNotEnoughSpace,
  1159             KSysInfoServiceUid );
  1147             KSysInfoServiceUid );
       
  1148         HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleEatDiskSpaceL" );
  1160         return;
  1149         return;
  1161         }
  1150         }
  1162 
  1151 
  1163     // check if scaceToEat is greater than KMaxTInt
  1152     // check if scaceToEat is greater than KMaxTInt
  1164     //  --> it must be eaten in several chunks
  1153     //  --> it must be eaten in several chunks
  1165     //  --> not yet supported.
  1154     //  --> not yet supported.
  1166     if ( spaceToEat > KMaxTInt )
  1155 
  1167         {
  1156     TInt64 size;
  1168         HTI_LOG_TEXT( "Cannot allocate a file bigger than KMaxTInt" );
  1157     for(TInt i=1;  spaceToEat>0; i++)
  1169 
  1158         {
  1170         iDispatcher->DispatchOutgoingErrorMessage(
  1159         path.Zero();
  1171             KErrOverflow,
  1160         path.Copy(commonpath);
  1172             KErrDescrSetSizeTempFile,
  1161         path.AppendNum(i);
  1173             KSysInfoServiceUid );
  1162         if ( BaflUtils::FileExists( iFs, path ) )
  1174         return;
  1163             {
  1175         }
  1164             continue;
  1176 
  1165             }
  1177     // create a temp file
  1166         
  1178     RFile diskEater;
  1167         if(spaceToEat > KMaxTInt)  
  1179     err = diskEater.Replace( iFs, path, EFileWrite );
  1168             size=KMaxTInt;
  1180     if ( err )
  1169         else
  1181         {
  1170             size=spaceToEat;
  1182         iDispatcher->DispatchOutgoingErrorMessage(
  1171         
  1183             err,
  1172         err = CreatFileToEatDiskSpace(path, size);
  1184             KErrDescrCreateTempFile,
  1173         if(err)
  1185             KSysInfoServiceUid );
  1174             { 
  1186         return;
  1175             HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleEatDiskSpaceL CreateFile Fail" );
  1187         }
  1176             return;  
  1188 
  1177             }        
  1189     // set the size for temp file
  1178         
  1190     err = diskEater.SetSize( I64LOW( spaceToEat ) );
  1179         iFs.Volume( volInfo, drive );
  1191     if ( err )
  1180         HTI_LOG_FORMAT( "current free space: %Ld", volInfo.iFree );
  1192         {
  1181         spaceToEat = volInfo.iFree - spaceLeftFree;           
  1193         iDispatcher->DispatchOutgoingErrorMessage(
       
  1194             err,
       
  1195             KErrDescrSetSizeTempFile,
       
  1196             KSysInfoServiceUid );
       
  1197         diskEater.Close();
       
  1198         return;
       
  1199         }
       
  1200     diskEater.Close();
       
  1201 
       
  1202     err = iFs.Volume( volInfo, drive );
       
  1203     if ( err )
       
  1204         {
       
  1205         iDispatcher->DispatchOutgoingErrorMessage(
       
  1206             err,
       
  1207             KErrDescrVolInfo,
       
  1208             KSysInfoServiceUid );
       
  1209         return;
       
  1210         }
  1182         }
  1211 
  1183 
  1212     // all ok, send the remaining disk size back
  1184     // all ok, send the remaining disk size back
  1213     iReply = HBufC8::NewL( 8 );
  1185     iReply = HBufC8::NewL( 8 );
  1214     iReply->Des().Append( ( TUint8* )( &volInfo.iFree ), 8 );
  1186     iReply->Des().Append( ( TUint8* )( &volInfo.iFree ), 8 );
       
  1187     HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleEatDiskSpaceL" );
       
  1188     }
       
  1189 
       
  1190 TInt CHtiSysInfoServicePlugin::CreatFileToEatDiskSpace( TFileName aPath, TInt64 aSpaceToEat  )
       
  1191     {
       
  1192     HTI_LOG_FUNC_IN( "CHtiSysInfoServicePlugin::CreatFileToEatDiskSpace" );
       
  1193     
       
  1194     HTI_LOG_FORMAT( "Create file: %S", &aPath );
       
  1195     HTI_LOG_FORMAT( "file size %Ld", aSpaceToEat );
       
  1196     
       
  1197     // create a temp file
       
  1198     RFile diskEater;
       
  1199     TInt err = diskEater.Replace( iFs, aPath, EFileWrite );
       
  1200     if ( err )
       
  1201         {
       
  1202         iDispatcher->DispatchOutgoingErrorMessage(
       
  1203             err,
       
  1204             KErrDescrCreateTempFile,
       
  1205             KSysInfoServiceUid );
       
  1206         HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::CreatFileToEatDiskSpace Replace error" );
       
  1207         return err;
       
  1208         }
       
  1209     
       
  1210     // set the size for temp file
       
  1211     err = diskEater.SetSize( I64LOW( aSpaceToEat ) );
       
  1212     if ( err )
       
  1213         {
       
  1214         iDispatcher->DispatchOutgoingErrorMessage(
       
  1215             err,
       
  1216             KErrDescrSetSizeTempFile,
       
  1217             KSysInfoServiceUid );
       
  1218         diskEater.Close();
       
  1219         HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::CreatFileToEatDiskSpace SetSize error" );
       
  1220         return err;
       
  1221         }
       
  1222     diskEater.Close();
       
  1223     HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::CreatFileToEatDiskSpace" );
       
  1224     return 0;
  1215     }
  1225     }
  1216 
  1226 
  1217 //------------------------------------------------------------------------------
  1227 //------------------------------------------------------------------------------
  1218 // CHtiSysInfoServicePlugin::HandleReleaseDiskSpaceL
  1228 // CHtiSysInfoServicePlugin::HandleReleaseDiskSpaceL
  1219 //------------------------------------------------------------------------------
  1229 //------------------------------------------------------------------------------
  1220 void CHtiSysInfoServicePlugin::HandleReleaseDiskSpaceL( const TDesC8& aMessage )
  1230 void CHtiSysInfoServicePlugin::HandleReleaseDiskSpaceL( const TDesC8& aMessage )
  1221     {
  1231     {
       
  1232     HTI_LOG_FUNC_IN( "CHtiSysInfoServicePlugin::HandleReleaseDiskSpaceL" );
  1222     if ( aMessage.Length() != 2 )
  1233     if ( aMessage.Length() != 2 )
  1223         {
  1234         {
  1224         iDispatcher->DispatchOutgoingErrorMessage(
  1235         iDispatcher->DispatchOutgoingErrorMessage(
  1225             KErrArgument,
  1236             KErrArgument,
  1226             KErrDescrArgument,
  1237             KErrDescrArgument,
  1227             KSysInfoServiceUid);
  1238             KSysInfoServiceUid);
       
  1239         HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleReleaseDiskSpaceL" );
  1228         return;
  1240         return;
  1229         }
  1241         }
  1230 
  1242 
  1231     TFileName path;
  1243     TFileName path;
  1232     path.Append( aMessage[1] );
  1244     path.Append( aMessage[1] );
  1233     path.Append( _L( ":" ) );
  1245     path.Append( _L( ":" ) );
  1234     path.Append( KTempFilePath );
  1246     path.Append(KTempFilePath);
  1235     path.Append( KTempFileName );
  1247     path.Append(KMatchFileName);
  1236 
  1248     TInt err = iFileMan->Delete(path);
  1237     HTI_LOG_TEXT( "Temp file path:" );
  1249     if ( err )
  1238     HTI_LOG_DES( path );
  1250         {
  1239 
  1251         iDispatcher->DispatchOutgoingErrorMessage(
  1240     TInt err = KErrNone;
       
  1241     // check that temp file exists
       
  1242     if ( BaflUtils::FileExists( iFs, path ) )
       
  1243         {
       
  1244         // try to delete the temp file
       
  1245         err = iFileMan->Delete( path );
       
  1246         if ( err )
       
  1247             {
       
  1248             iDispatcher->DispatchOutgoingErrorMessage(
       
  1249                 err,
  1252                 err,
  1250                 KErrDescrDeleteTempFile,
  1253                 KErrDescrDeleteTempFile,
  1251                 KSysInfoServiceUid );
  1254                 KSysInfoServiceUid );
  1252 
  1255         HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleReleaseDiskSpaceL" );
  1253             return;
  1256         return;
  1254             }
  1257         } 
  1255         }
  1258     
  1256 
       
  1257     // query the free disk space
  1259     // query the free disk space
  1258     TInt drive;
  1260     TInt drive;
  1259     RFs::CharToDrive( TChar( aMessage[1] ), drive );
  1261     RFs::CharToDrive( TChar( aMessage[1] ), drive );
  1260     TVolumeInfo volInfo;
  1262     TVolumeInfo volInfo;
  1261     err = iFs.Volume( volInfo, drive );
  1263     err = iFs.Volume( volInfo, drive );
  1263         {
  1265         {
  1264         iDispatcher->DispatchOutgoingErrorMessage(
  1266         iDispatcher->DispatchOutgoingErrorMessage(
  1265             err,
  1267             err,
  1266             KErrDescrVolInfo,
  1268             KErrDescrVolInfo,
  1267             KSysInfoServiceUid );
  1269             KSysInfoServiceUid );
  1268 
  1270         HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleReleaseDiskSpaceL" );
  1269         return;
  1271         return;
  1270         }
  1272         }
  1271 
  1273 
  1272     // all ok, send the free disk space back
  1274     // all ok, send the free disk space back
  1273     iReply = HBufC8::NewL( 8 );
  1275     iReply = HBufC8::NewL( 8 );
  1274     iReply->Des().Append( ( TUint8* )( &volInfo.iFree ), 8 );
  1276     iReply->Des().Append( ( TUint8* )( &volInfo.iFree ), 8 );
       
  1277 
       
  1278     HTI_LOG_FUNC_OUT( "CHtiSysInfoServicePlugin::HandleReleaseDiskSpaceL" );
  1275     }
  1279     }
  1276 
  1280 
  1277 //------------------------------------------------------------------------------
  1281 //------------------------------------------------------------------------------
  1278 // CHtiSysInfoServicePlugin::HandleSetHomeTimeL
  1282 // CHtiSysInfoServicePlugin::HandleSetHomeTimeL
  1279 //------------------------------------------------------------------------------
  1283 //------------------------------------------------------------------------------
  2855 // CHtiSysInfoServicePlugin::CleanUpTempFiles
  2859 // CHtiSysInfoServicePlugin::CleanUpTempFiles
  2856 //------------------------------------------------------------------------------
  2860 //------------------------------------------------------------------------------
  2857 TInt CHtiSysInfoServicePlugin::CleanUpTempFiles()
  2861 TInt CHtiSysInfoServicePlugin::CleanUpTempFiles()
  2858     {
  2862     {
  2859     HTI_LOG_FUNC_IN( "CHtiSysInfoServicePlugin::CleanUpTempFiles" );
  2863     HTI_LOG_FUNC_IN( "CHtiSysInfoServicePlugin::CleanUpTempFiles" );
  2860 
       
  2861     TFindFile finder( iFs );
  2864     TFindFile finder( iFs );
  2862     TFileName path( KTempFilePath );
  2865     CDir* dir = NULL;
  2863     TInt err = finder.FindByPath( KTempFileName, &path );
  2866     TInt err = finder.FindWildByDir(KMatchFileName, KTempFilePath, dir);
  2864 
       
  2865     while ( err == KErrNone )
  2867     while ( err == KErrNone )
  2866         {
  2868         {
  2867         TFileName tempFile = finder.File();
  2869         TFileName path;
  2868 
  2870         path.Copy(finder.File());
  2869         HTI_LOG_TEXT( "Found temp file: " );
  2871         iFileMan->Delete(path);
  2870         HTI_LOG_DES( tempFile );
  2872         delete dir;
  2871 
  2873         dir = NULL;
  2872         err = iFileMan->Delete( tempFile );
  2874         err = finder.FindWildByDir(KMatchFileName, KTempFilePath, dir);
  2873 
  2875         }
  2874         // return if deleting does not succeed to prevent mad man loop
       
  2875         if ( err != KErrNone ) return err;
       
  2876 
       
  2877         // try to find next temp file
       
  2878         err = finder.FindByPath( KTempFileName, &path );
       
  2879         }
       
  2880 
       
  2881     HTI_LOG_FUNC_OUT("CHtiSysInfoServicePlugin::CleanUpTempFiles");
  2876     HTI_LOG_FUNC_OUT("CHtiSysInfoServicePlugin::CleanUpTempFiles");
  2882     return KErrNone;
  2877     return KErrNone;
  2883     }
  2878     }
  2884 
  2879 
  2885 //------------------------------------------------------------------------------
  2880 //------------------------------------------------------------------------------