diff -r 89d6a7a84779 -r 25a17d01db0c Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/hybridapp_8cpp-source.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/hybridapp_8cpp-source.html Fri Jan 22 18:26:19 2010 +0000 @@ -0,0 +1,221 @@ + + +TB10.1 Example Applications: examples/PIPS/hybridapp/src/hybridapp.cpp Source File + + + + +

examples/PIPS/hybridapp/src/hybridapp.cpp

Go to the documentation of this file.
00001 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
+00002 // All rights reserved.
+00003 // This component and the accompanying materials are made available
+00004 // under the terms of "Eclipse Public License v1.0"
+00005 // which accompanies this distribution, and is available
+00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
+00007 //
+00008 // Initial Contributors:
+00009 // Nokia Corporation - initial contribution.
+00010 //
+00011 // Contributors:
+00012 //
+00013 // Description:
+00014 // Demonstrates an OE hybrid application.
+00015 //
+00016 
+00017 
+00018 
+00022 #include <stdio.h>
+00023 #include <f32file.h>
+00024 #include <stdlib.h>
+00025 #include <string.h>
+00026 
+00032 char* DescToChar(const TDesC& aDes)
+00033         {
+00034         // Get the length of the descriptor.
+00035         TInt length = aDes.Length();
+00036 
+00037         // Allocate memory to the array of characters.
+00038         // An additional byte of memory is allocated to the array as 
+00039         // Symbian descriptors do not end with the end of string '\0' character.
+00040         char* ptr = (char*)malloc(sizeof(char)*(length + 1));
+00041         if(ptr == NULL)
+00042                 {
+00043                 // Return NULL if memory was not allocated properly.
+00044                 return NULL;
+00045                 }
+00046         // The loop index.
+00047         TInt ix = 0;
+00048         for(; ix < length; ix++)
+00049                 {
+00050                 // Copy the contents of the descriptor into the array of characters.
+00051                 ptr[ix] = aDes[ix];
+00052                 }
+00053         // Append the end of string to the 'C' style string.
+00054         ptr[ix] = '\0';
+00055 
+00056         // return the pointer to the array.
+00057         return ptr;
+00058         }
+00059 
+00065 void PrintDriveInfoL(const RFs& aFs, const TInt aDriveNumber)
+00066         {
+00067         // Get the drive information
+00068         TDriveInfo driveInfo;
+00069         TInt errDrive = aFs.Drive(driveInfo,aDriveNumber);
+00070         if(errDrive != KErrNone)
+00071                 return;
+00072 
+00073         // Get the name of the drive.
+00074         TBuf<KMaxFileName> driveName;
+00075         TInt errName = aFs.GetDriveName(aDriveNumber,driveName);
+00076         if(errName != KErrNone)
+00077                 return;
+00078 
+00079         // Convert the drive name from native Symbian descriptor string to a 'C' string.
+00080         char* cptr = DescToChar(driveName);
+00081         CleanupStack::PushL(cptr);
+00082         // Check if a name has been specified for the drive.
+00083         if(strlen(cptr))
+00084                 {
+00085                 // Print the name of the drive.
+00086                 printf("Drive Name :%s\n",cptr);
+00087                 }
+00088         
+00089         // Print the memory information for the drive.
+00090         // The memory size is defined for a drive only if it is formattable.
+00091         if((driveInfo.iMediaAtt & KMediaAttFormattable))
+00092                 {
+00093                 TChar driveLetter;
+00094                 // if drive-list entry non-zero, drive is available
+00095                 TInt errDLetter = aFs.DriveToChar(aDriveNumber,driveLetter);
+00096                 if(errDLetter != KErrNone)
+00097                         return;
+00098                 // The following line prints the drive letter followed by the hex value
+00099                 // of the integer indicating that drive's attributes
+00100                 printf("Drive Letter: %c\n",TUint(driveLetter));                        
+00101         
+00102                 // Get the volume information for the formatted device.
+00103                 TVolumeInfo volumeInfo;
+00104                 TInt errVol = aFs.Volume(volumeInfo,aDriveNumber);
+00105                 if(errVol != KErrNone)
+00106                         return;
+00107 
+00108                 // Get the total size and the free space of the drive.
+00109                 TInt64 driveTotalSize = volumeInfo.iSize;
+00110                 TInt64 driveFreeSize =  volumeInfo.iFree;
+00111                 // Print the memory information for the drive.
+00112                 printf("Total size of the drive: %d\n", driveTotalSize);
+00113                 printf("Free space: %d\n", driveFreeSize);
+00114                 
+00115                 printf(" [press the enter key to continue]\n");
+00116                 // Wait for a key press.
+00117                 getchar();
+00118                 }
+00119         
+00120         CleanupStack::PopAndDestroy(cptr);
+00121         }
+00122 
+00123 LOCAL_C void MainL()
+00124         {
+00125         // The file server session.
+00126         RFs fs;
+00127         // Connect to the file server.
+00128         User::LeaveIfError(fs.Connect());
+00129         CleanupClosePushL(fs);
+00130         printf("\nValid drives as characters (and as numbers) are:\n");
+00131 
+00132         // Initialise drive number to the first drive.
+00133         TInt driveNumber=EDriveA;
+00134         TChar driveLetter;
+00135 
+00136     for (; driveNumber<=EDriveZ; driveNumber++)
+00137         {
+00138         if (fs.IsValidDrive(driveNumber))
+00139             {
+00140                         // Indicates that the drive exists and is valid.
+00141             TInt errDrive = fs.DriveToChar(driveNumber,driveLetter);
+00142             if(errDrive == KErrNone)
+00143                 {
+00144                                 // Print the drive letter.
+00145                     printf("%c",TUint(driveLetter));
+00146                                 // Convert the drive letter to the drive number.
+00147                     TInt errChar = fs.CharToDrive(driveLetter, driveNumber);
+00148                     if(errChar == KErrNone)
+00149                         {
+00150                                         // Print the drive number.
+00151                             printf("(%d) ",driveNumber);
+00152                         }
+00153                 }
+00154             }
+00155         }
+00156 
+00157     printf("\n");
+00158 
+00159         // Get a list of the available drives.
+00160     TDriveList drivelist;
+00161     User::LeaveIfError(fs.DriveList(drivelist));
+00162 
+00163         // A TDriveList (the list of available drives), is an array of
+00164     // 26 bytes. Each byte with a non zero value signifies that the
+00165     // corresponding drive is available.
+00166 
+00167     printf("\nUsing DriveList(), available drives are: \n");
+00168     for (driveNumber=EDriveA; driveNumber<=EDriveZ;driveNumber++)
+00169         {
+00170         if (drivelist[driveNumber])
+00171             {
+00172                         // if drive-list entry non-zero, drive is available
+00173             TInt errDrive = fs.DriveToChar(driveNumber,driveLetter);
+00174             if(errDrive == KErrNone)
+00175                 {
+00176                     // The following line prints the drive letter followed by the hex value
+00177                     // of the integer indicating that drive's attributes
+00178                     printf("Drive Letter: %c\n",TUint(driveLetter));
+00179                                 printf(" [press the enter key to continue]\n");
+00180                                 // Wait for a key press.
+00181                                 getchar();
+00182                 }
+00183             }
+00184         }
+00185     
+00186         printf("Memory information for formattable drives:\n");
+00187         printf(" [press the enter key to continue]\n");
+00188         // Wait for a key press.
+00189         getchar();
+00190         for (driveNumber=EDriveA; driveNumber<=EDriveZ;driveNumber++)
+00191         {
+00192         if (drivelist[driveNumber])
+00193             {
+00194                         PrintDriveInfoL(fs,driveNumber);
+00195                         }
+00196                 }       
+00197 
+00198         CleanupStack::PopAndDestroy(&fs);
+00199         }
+00200 
+00201 
+00202 GLDEF_C TInt E32Main()
+00203         {
+00204         // Create cleanup stack
+00205         __UHEAP_MARK;
+00206         CTrapCleanup* cleanup = CTrapCleanup::New();
+00207 
+00208         // Run application code inside TRAP harness, wait for key press when terminated
+00209         TRAPD(mainError, MainL());
+00210         if (mainError)
+00211                 {
+00212                 printf(" failed, leave code = %d", mainError);
+00213                 }
+00214 
+00215         printf(" [press the enter key to exit]\n");
+00216         getchar();
+00217 
+00218         delete cleanup;
+00219         __UHEAP_MARKEND;
+00220         return KErrNone;
+00221         }
+00222 
+

Generated on Thu Jan 21 10:33:00 2010 for TB10.1 Example Applications by  + +doxygen 1.5.3
+ +