examples/Base/FileServer/Connecting/Connecting.cpp

00001 /*
00002 Copyright (c) 2000-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010   this list of conditions and the following disclaimer in the documentation
00011   and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013   may be used to endorse or promote products derived from this software
00014   without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description: 
00028 NB. THE FOLLOWING CODE CREATES A DIRECTORY CALLED F32TEST IN THE DEFAULT 
00029 DIRECTORY AND DELETES IT BEFORE EXITING. 
00030 */
00031 
00032 
00033 #include <f32file.h>
00034 #include "CommonFramework.h"
00035         
00036 static RFs fsSession;
00037 
00038 static void doExampleL()
00039     {
00040         // Define descriptor constants using the _LIT macro 
00041         _LIT(KMessage1,"Default path for fsSession is %S\n");
00042         _LIT(KMessage2,"Session path for fsSession is now %S\n");
00043         _LIT(KMessage3,"Session path for fsSession2 is %S\n");
00044     _LIT(KTestDir,"f32test\\");
00045 
00046           // Open file server session
00047         User::LeaveIfError(fsSession.Connect());
00048         
00049           // Get the default session path, and display it.
00050           // It should be the private path for this (process)
00051           // i.e.\private\0fffff04 of the writable drive.
00052         TFileName path;
00053         User::LeaveIfError(fsSession.SessionPath(path));
00054         console->Printf(KMessage1,&path);
00055 
00056           // Create a directory within the default session path.
00057           // and then set the default path to the full directory.
00058           //
00059           // Steps.
00060           // 
00061           // 1  Create the private path - it is not automatically created by the Symbian platform.
00062           // 2. Get the name of the private path
00063           // 3. Create the new directory level f32test\ within the private path
00064           // 4. Set the session path to \private\0fffff04\f32test.
00065         User::LeaveIfError(fsSession.CreatePrivatePath(RFs::GetSystemDrive())); // <--- 1.
00066         fsSession.PrivatePath(path);   // <------------------------------ 2.
00067         path.Append(KTestDir);
00068         User::LeaveIfError(fsSession.MkDir(path));// <------------------- 3.
00069         User::LeaveIfError(fsSession.SetSessionPath(path)); // <--------- 4.
00070                 
00071           // Retrieve the session path to make sure that the system
00072           // agrees with what we believe is the new session path.
00073           // Clear the path descriptor; this is NOT necessary, but just
00074           // shows that we are not cheating !
00075     path.SetLength(0);
00076     User::LeaveIfError(fsSession.SessionPath(path));
00077         console->Printf(KMessage2,&path);
00078          
00079           // Make another connection to the file server and show  
00080           // its default session path.It should be the original 
00081           // private path for this (process) i.e.\private\0fffff04
00082           // of the writable drive.
00083         RFs fsSession2;
00084         User::LeaveIfError(fsSession2.Connect());
00085         fsSession2.SessionPath(path);
00086         console->Printf(KMessage3,&path);
00087 
00088       // Remove the \f32test\ directory 
00089         fsSession.PrivatePath(path);       
00090         path.Append(KTestDir);
00091         User::LeaveIfError(fsSession.RmDir(path));
00092         
00093           // Close these two sessions with the file server.
00094         fsSession2.Close();
00095         fsSession.Close();
00096         }

Generated by  doxygen 1.6.2