examples/Base/FileServer/Connecting/Connecting.cpp

00001 // Copyright (c) 2000-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 // NB. THE FOLLOWING CODE CREATES A DIRECTORY CALLED F32TEST IN THE DEFAULT 
00015 // DIRECTORY AND DELETES IT BEFORE EXITING.
00016 //
00017 
00018 #include <f32file.h>
00019 #include "CommonFramework.h"
00020         
00021 static RFs fsSession;
00022 
00023 static void doExampleL()
00024     {
00025         // Define descriptor constants using the _LIT macro 
00026         _LIT(KMessage1,"Default path for fsSession is %S\n");
00027         _LIT(KMessage2,"Session path for fsSession is now %S\n");
00028         _LIT(KMessage3,"Session path for fsSession2 is %S\n");
00029     _LIT(KTestDir,"f32test\\");
00030 
00031           // Open file server session
00032         User::LeaveIfError(fsSession.Connect());
00033         
00034           // Get the default session path, and display it.
00035           // It should be the private path for this (process)
00036           // i.e.\private\0fffff04 of the writable drive.
00037         TFileName path;
00038         User::LeaveIfError(fsSession.SessionPath(path));
00039         console->Printf(KMessage1,&path);
00040 
00041           // Create a directory within the default session path.
00042           // and then set the default path to the full directory.
00043           //
00044           // Steps.
00045           // 
00046           // 1  Create the private path - it is not automatically created by the Symbian platform.
00047           // 2. Get the name of the private path
00048           // 3. Create the new directory level f32test\ within the private path
00049           // 4. Set the session path to \private\0fffff04\f32test.
00050         User::LeaveIfError(fsSession.CreatePrivatePath(RFs::GetSystemDrive())); // <--- 1.
00051         fsSession.PrivatePath(path);   // <------------------------------ 2.
00052         path.Append(KTestDir);
00053         User::LeaveIfError(fsSession.MkDir(path));// <------------------- 3.
00054         User::LeaveIfError(fsSession.SetSessionPath(path)); // <--------- 4.
00055                 
00056           // Retrieve the session path to make sure that the system
00057           // agrees with what we believe is the new session path.
00058           // Clear the path descriptor; this is NOT necessary, but just
00059           // shows that we are not cheating !
00060     path.SetLength(0);
00061     User::LeaveIfError(fsSession.SessionPath(path));
00062         console->Printf(KMessage2,&path);
00063          
00064           // Make another connection to the file server and show  
00065           // its default session path.It should be the original 
00066           // private path for this (process) i.e.\private\0fffff04
00067           // of the writable drive.
00068         RFs fsSession2;
00069         User::LeaveIfError(fsSession2.Connect());
00070         fsSession2.SessionPath(path);
00071         console->Printf(KMessage3,&path);
00072 
00073       // Remove the \f32test\ directory 
00074         fsSession.PrivatePath(path);       
00075         path.Append(KTestDir);
00076         User::LeaveIfError(fsSession.RmDir(path));
00077         
00078           // Close these two sessions with the file server.
00079         fsSession2.Close();
00080         fsSession.Close();
00081         }

Generated by  doxygen 1.6.2