examples/Base/IPC/ClientServer/Complex/ComplexServer.h

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 */
00029 
00030 
00031 #if !defined(__ComplexServer_H__)
00032 #define __ComplexServer_H__
00033 
00034 //needed for creating server thread.
00035 const TUint KDefaultHeapSize=0x10000;
00036 
00037 // panic reasons
00038 enum TCountServPanic
00039         {
00040         EBadRequest = 1,
00041         EBadDescriptor,
00042         EDescriptorNonNumeric,
00043         EMainSchedulerError,
00044         ESvrCreateServer,
00045         ESvrStartServer,
00046         ECreateTrapCleanup,
00047         EBadCounterRemove, 
00048         EBadSubsessionHandle 
00049         };
00050 
00051 
00052 
00053 
00054 /*
00055 CCountServer class
00056 
00057 Represents the server.
00058         
00059 The server starts with the first client connect call.
00060 Start includes setting up active scheduler, the server active object,
00061 and the object container index which produces object object containers for each session.
00062 */
00063 class CCountServer : public CServer2
00064         {
00065 public:
00066     
00067 
00068       // Creates a new session with the server; the function
00069           // implements the pure virtutal function 
00070           // defined in class CServer2
00071         CSession2* NewSessionL(const TVersion &aVersion,const RMessage2& aMessage) const;
00072 
00073 public: 
00074       // Creats a new server object
00075     static CCountServer* NewL(CActive::TPriority aActiveObjectPriority);
00076     
00077       // The thread function executed by the server 
00078         static TInt ThreadFunction(TAny* aStarted);
00079 
00080           // utility function to panic the server.
00081         static void PanicServer(TCountServPanic aPanic);
00082 
00083 public :
00084       // Constructor
00085         CCountServer(CActive::TPriority aActiveObjectPriority);
00086         
00087           // Second phase constructor
00088         void ConstructL();
00089 
00090           // Returns an object container, and guaranteed 
00091           // to produce object containers with unique
00092           // ids within the server.
00093           // Called by a new session to create a container 
00094         CObjectCon* NewContainerL();
00095         
00096           // Removes container from the container list
00097         void RemoveContainer(CObjectCon *aCon);
00098     
00099           // Destructor; exists to do some tidying up.
00100         ~CCountServer();
00101 
00102 private:
00103           // The server has an object container index that
00104           // creates an object container for each session.
00105         CObjectConIx* iContainerIndex; 
00106         };
00107 
00108 
00109 
00110 
00111 /*
00112 CCountSession class
00113 
00114 Represents a session with the server.
00115         
00116 Functions are provided to respond appropriately to client messages.
00117 A session can own any number of subsession objects.
00118 */
00119 class CCountSubSession;
00120 class CCountSession : public CSession2
00121         {
00122 public:
00123           // Create the session
00124         static CCountSession* NewL();
00125         
00126 public:
00127       // Constructor
00128         CCountSession();
00129         
00130           // Called by client/server framework after 
00131           // session has been successfully created
00132     void CreateL(); 
00133                 
00134           // Service request
00135         void ServiceL(const RMessage2& aMessage);
00136         void DispatchMessageL(const RMessage2& aMessage);
00137 
00138       // Creates new subsession
00139     void NewCounterL(const RMessage2& aMessage);  
00140       
00141       // Closes the session
00142         void CloseSession();
00143         
00144       // Gets the number of resources (i.e. CCountSubSession objects)
00145         void NumResourcesL(const RMessage2& aMessage);
00146         
00147           // Utility to return the CCountSubSession (subsession) object
00148     CCountSubSession* CounterFromHandle(const RMessage2& aMessage,TInt aHandle);        
00149 
00150           // Delete the subsession object through its handle.
00151         void DeleteCounter(TInt aHandle);
00152       
00153       // Gets the number of server-side subsession objects.
00154         TInt CountResources();
00155           
00156           // Panics client
00157         void PanicClient(const RMessage2& aMessage,TInt aPanic) const;
00158 
00159 private:
00160       // Object container for this session.
00161         CObjectCon *iContainer;
00162 
00163           // Object index which stores objects
00164           // (CCountSubSession instances) for this session.
00165         CObjectIx* iCountersObjectIndex;
00166 
00167       // Total number of resources. In this example
00168       // a resource is just the number of CCountSubSession objects.
00169     TInt iResourceCount;
00170         };
00171 
00172 
00173 
00174 
00175 /*
00176 CCountSubSession class
00177 
00178 Represents a subsession of CCountSession.
00179 */
00180 class CCountSubSession : public CObject
00181         {
00182 public:
00183       // creates a new CCountSubSession object.
00184         static CCountSubSession* NewL(CCountSession* aSession);
00185         
00186 public: 
00187     CCountSubSession(CCountSession* aSession);  
00188         void ConstructL(CCountSession* aSession);
00189         void SetFromStringL(const RMessage2& aMessage);
00190         void Increase();
00191         void IncreaseBy(const RMessage2& aMessage);
00192         void Decrease();
00193         void DecreaseBy(const RMessage2& aMessage);
00194         void Reset();
00195         void CounterValueL(const RMessage2& aMessage);
00196    
00197 protected:
00198       // The session that owns this CCountSubSession object.
00199         CCountSession* iSession;
00200         
00201 private:
00202       // The counter value
00203         TInt iCount;
00204         };
00205 
00206 #endif

Generated by  doxygen 1.6.2