utilityapps/filebrowser/fileopserver/inc/FBFileOpServer.h
changeset 55 2d9cac8919d3
parent 0 d6fe6244b863
equal deleted inserted replaced
53:819e59dfc032 55:2d9cac8919d3
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __FBFILEOPSERVER_H__
       
    20 #define __FBFILEOPSERVER_H__
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <f32file.h>
       
    24 #include "FBFileOpClientServer.h"
       
    25 
       
    26 // needed for creating server thread.
       
    27 //const TUint KDefaultHeapSize=0x10000;
       
    28 
       
    29 // reasons for server panic
       
    30 enum TMyPanic
       
    31 	{
       
    32 	EPanicBadDescriptor,
       
    33 	EPanicIllegalFunction
       
    34 	};
       
    35 
       
    36 class CShutdown : public CTimer
       
    37 	{
       
    38 	enum {KMyShutdownDelay=0x200000};	// approx 2s
       
    39 
       
    40 public :
       
    41 	inline CShutdown();
       
    42 	inline void ConstructL();
       
    43 	inline void Start();
       
    44 
       
    45 private :
       
    46 	void RunL();
       
    47 	};
       
    48 
       
    49 //**********************************
       
    50 //CFBFileOpServer
       
    51 //**********************************
       
    52 /**
       
    53 Our server class - an active object - and therefore derived ultimately from CActive.
       
    54 It accepts requests from client threads and forwards
       
    55 them to the client session to be dealt with. It also handles the creation
       
    56 of the server-side client session.
       
    57 */
       
    58 class CFBFileOpServer : public CServer2
       
    59 	{
       
    60 
       
    61 public :
       
    62 	static CServer2* NewLC();
       
    63 	void AddSession();
       
    64 	void DropSession();
       
    65 
       
    66 protected :
       
    67 
       
    68 private :
       
    69 	CFBFileOpServer();
       
    70 	void ConstructL();
       
    71 	CSession2* NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const;
       
    72 
       
    73 public :
       
    74 
       
    75 private :
       
    76 	TInt iSessionCount;
       
    77 	CShutdown iShutdown;
       
    78 	
       
    79 	};
       
    80 
       
    81 //**********************************
       
    82 //CRequestObserver
       
    83 //**********************************
       
    84 /**
       
    85 This class is for monitoring asynchronous request
       
    86 and for completing related RMessage2 object.
       
    87 */
       
    88 class CRequestObserver : public CActive
       
    89     {
       
    90 public:
       
    91     CRequestObserver( TInt aPriority );
       
    92     virtual ~CRequestObserver();
       
    93     
       
    94     void StartWaiting( const RMessage2& aMsg );
       
    95     
       
    96 private:
       
    97     // from CActive
       
    98     void RunL();
       
    99     void DoCancel();
       
   100     
       
   101 private:
       
   102     RMessage2 iMsg;
       
   103     };
       
   104 
       
   105 
       
   106 //**********************************
       
   107 //CFBFileOpServerSession
       
   108 //**********************************
       
   109 /**
       
   110 This class represents a session with the  server.
       
   111 Functions are provided to respond appropriately to client messages.
       
   112 */
       
   113 class CFBFileOpServerSession : public CSession2,
       
   114                                public MFileManObserver
       
   115 	{
       
   116 
       
   117 public :
       
   118 	CFBFileOpServerSession();
       
   119 
       
   120 private: // From MFileManObserver
       
   121     
       
   122     TControl NotifyFileManStarted();
       
   123     TControl NotifyFileManOperation();
       
   124     TControl NotifyFileManEnded();
       
   125     
       
   126 protected :
       
   127 	// panic the client
       
   128 	void PanicClient(const RMessage2& aMessage,TInt aPanic) const;
       
   129 
       
   130 private :
       
   131 	~CFBFileOpServerSession();
       
   132 	inline CFBFileOpServer& Server();
       
   133 	void CreateL();
       
   134 	
       
   135 	//service requests
       
   136 	void ServiceL(const RMessage2& aMessage);
       
   137 	void DispatchMessageL(const RMessage2& aMessage, TBool& aComplete);
       
   138 	
       
   139 	void CopyL(const RMessage2& aMessage);
       
   140 	void RenameL(const RMessage2& aMessage);
       
   141 	void AttribsL(const RMessage2& aMessage);
       
   142 	void RmDirL(const RMessage2& aMessage, TBool& aComplete);
       
   143 	void DeleteL(const RMessage2& aMessage);
       
   144 	void MkDirAllL(const RMessage2& aMessage);
       
   145 	void CreateEmptyFileL(const RMessage2& aMessage);
       
   146 	void EraseMBRL(const RMessage2& aMessage);
       
   147 	void PartitionDriveL(const RMessage2& aMessage);
       
   148 
       
   149 	void ServiceError(const RMessage2& aMessage, TInt aError);
       
   150 	
       
   151 	void CancelOp();
       
   152 					
       
   153 private :
       
   154 	RFs iFs;
       
   155 	RFile iFile;
       
   156 	CFileMan* iFileMan;
       
   157 	MFileManObserver::TControl iFileManObserverResult;
       
   158 	CRequestObserver* iReqObserver;
       
   159 	};
       
   160 
       
   161 
       
   162 //**********************************
       
   163 //Inlines
       
   164 //**********************************
       
   165 
       
   166 inline CShutdown::CShutdown()
       
   167 	:CTimer(-1)
       
   168 	{CActiveScheduler::Add(this);}
       
   169 
       
   170 inline void CShutdown::ConstructL()
       
   171 	{CTimer::ConstructL();}
       
   172 
       
   173 inline void CShutdown::Start()
       
   174 	{After(KMyShutdownDelay);}
       
   175 
       
   176 inline CFBFileOpServer::CFBFileOpServer()
       
   177 	:CServer2(0,ESharableSessions)
       
   178 	{}
       
   179 
       
   180 inline CFBFileOpServerSession::CFBFileOpServerSession()
       
   181 	{}
       
   182 
       
   183 inline CFBFileOpServer& CFBFileOpServerSession::Server()
       
   184 	{return *static_cast<CFBFileOpServer*>(const_cast<CServer2*>(CSession2::Server()));}
       
   185 
       
   186 #endif