libraries/clogger/inc/SensibleServer.h
changeset 0 7f656887cf89
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // SensibleServer.h
       
     2 // 
       
     3 // Copyright (c) 2006 - 2010 Accenture. All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the "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 // Accenture - Initial contribution
       
    11 //
       
    12 
       
    13 #ifndef SENSIBLESERVER_H
       
    14 #define SENSIBLESERVER_H
       
    15 
       
    16 #include <e32base.h>
       
    17 #include "cliserv.h"
       
    18 #include <f32file.h>
       
    19 #include <gdi.h>
       
    20 #include <basched.h>
       
    21 
       
    22 #include "SensibleCompat.h"
       
    23 
       
    24 class CCallbackContext;
       
    25 class CSensibleSession;
       
    26 class CFilteringScheduler;
       
    27 
       
    28 void PanicClient(const RMessage& aMessage, TInt TMyPanic);
       
    29 extern void CleanupPanicPushL();
       
    30 
       
    31 class CShutdown : public CTimer
       
    32 	{
       
    33 public:
       
    34 	inline CShutdown();
       
    35 	inline void ConstructL();
       
    36 	inline void Start(TInt aDelay);
       
    37 private:
       
    38 	void RunL();
       
    39 	};
       
    40 
       
    41 class CSensibleServer : public CServerBase
       
    42 	{
       
    43 public:
       
    44 	void AddSession();
       
    45 	void DropSession();
       
    46 	inline CFilteringScheduler* Scheduler();
       
    47 	CSensibleServer();
       
    48 	~CSensibleServer();
       
    49 	virtual void ConstructL();
       
    50 
       
    51 	// Some functions that call into the filtering scheduler
       
    52 	// NOTE: These functions cannot be used at the same time as queuing a callback that requires a result, nor can they be nested (you'll get a panic)
       
    53 	//void BlockAllAOsExceptServerRequests();
       
    54 	void BlockRequestsFrom(CActive* aActive1, CActive* aActive2=NULL);
       
    55 	void StopBlocking();
       
    56 
       
    57 protected:
       
    58 	#ifdef __HIDE_IPC_V1__
       
    59 	CSession2* NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const;
       
    60 	#else
       
    61 	CSessionBase* NewSessionL(const TVersion& aVersion) const;
       
    62 	#endif
       
    63 	TInt RunError(TInt aError);
       
    64 	virtual TInt TransientServerShutdownTime() const; // Return 0 to never shutdown
       
    65 
       
    66 private:
       
    67 	TInt iSessionCount;
       
    68 	CShutdown iShutdown;
       
    69 	CFilteringScheduler* iScheduler;
       
    70 	CActiveScheduler* iOldScheduler;
       
    71 	};
       
    72 
       
    73 class CSensibleSession : public CSessionBase
       
    74 	{
       
    75 public:
       
    76 	CSensibleSession();
       
    77 	#ifndef __HIDE_IPC_V1__
       
    78 	void CreateL(const CServer& aServer);
       
    79 	#endif
       
    80 	void CreateL();
       
    81 	void QueueCallbackL(CCallbackContext* aContext); // This completes a callback immediately if possible, otherwise queues it. Used for callbacks that MUST be delivered.
       
    82 	TBool DispatchCallback(TServerCallback& aCallback); // This completes a callback immediately if possible, otherwise returns EFalse. Used for notify-style callbacks. The callback cannot have a context.
       
    83 	void CompleteNextCallback();
       
    84 
       
    85 protected:
       
    86 	virtual TBool DoServiceL(const RMessage& aMessage); // return EFalse if aMessage wasn't handled
       
    87 	~CSensibleSession();
       
    88 
       
    89 private:
       
    90 	inline CSensibleServer& Server();
       
    91 	void ServiceL(const RMessage& aMessage);
       
    92 //	inline TBool ReceivePending() const;
       
    93 private:
       
    94 	TSglQue<CCallbackContext> iCallbackQ;
       
    95 	RMessage iCallbackNotifier;
       
    96 	TBool iCallbackPending;
       
    97 	TBool iWaitingForCallbackResult;
       
    98 	};
       
    99 
       
   100 enum TCallbackContextFlags
       
   101 	{
       
   102 	EResultHBufC8 = 2,
       
   103 	EResultHBufC16 = 4,
       
   104 	EResultIsLeaveCode = 8,
       
   105 	EActive = 16,
       
   106 	EBlockServer = 32,
       
   107 	};
       
   108 
       
   109 class TCallbackWriter
       
   110 	{
       
   111 public:
       
   112 	TCallbackWriter(TServerCallback& aCallback, HBufC8** aContext);
       
   113 
       
   114 	// If any of the AddLs leave, they will delete aContext if it has been created
       
   115 	void AddL(TInt aInt);
       
   116 	void AddL(TUint aInt);
       
   117 	void AddL(TPoint aPoint);
       
   118 	void AddL(TSize aSize);
       
   119 	void AddL(TRgb aRgb);
       
   120 	void AddL(TRect aRect);
       
   121 	void AddL(const TDesC16& aDesc);
       
   122 	void AddL(const TDesC8& aDesc);
       
   123 
       
   124 private:
       
   125 	void AddL(const TDesC8& aData, char* aType);
       
   126 
       
   127 private:
       
   128 	TServerCallback& iCallback;
       
   129 	HBufC8** iContext;
       
   130 	TPtr8 iBuf;
       
   131 	TBool iInContext;
       
   132 	};
       
   133 
       
   134 class CCallbackContext : public CBase
       
   135 	{
       
   136 public:
       
   137 	union TResult
       
   138 		{
       
   139 		HBufC8** s;
       
   140 		HBufC16** l;
       
   141 		TDes8* pkg;
       
   142 		TInt integer;
       
   143 		};
       
   144 		
       
   145 public:
       
   146 	CCallbackContext(TCallbackCode aCode);
       
   147 	~CCallbackContext();
       
   148 	void SetFlags(TInt aFlags);
       
   149 	TBool Flag(TInt aFlags) const; // All bits of aFlags must be set to return true
       
   150 	void ClearFlags(TInt aFlags);
       
   151 	TBool CallbackRequiresResult() const;
       
   152 	TBool CallbackHasContext() const;
       
   153 	//void SetContext(HBufC8* aContext); // Takes ownership and clears flag EContextHBufC16
       
   154 	//void SetContext(HBufC16* aContext); // Takes ownership and sets flag EContextHBufC16
       
   155 	TCallbackWriter Writer();
       
   156 
       
   157 	void SetResult(TDes8& aPkg); // Sets appropriate flags
       
   158 	void SetResult(HBufC8*& aResult); // Sets appropriate flags
       
   159 	void SetResult(HBufC16*& aResult); // Sets appropriate flags
       
   160 	//void SetResult(TInt& aResult); // Sets appropriate flags
       
   161 	HBufC8* Context();
       
   162 	TResult& Result();
       
   163 	TServerCallback& Callback();
       
   164 	
       
   165 private:
       
   166 	void AddContext(const TUint8* aPtr, TInt aSize, char* aType);
       
   167 private:
       
   168 	TInt iFlags; // bitwise OR of TCallbackContextFlags
       
   169 	TServerCallback iCallback;
       
   170 	HBufC8* iContext;
       
   171 	TResult iResult;
       
   172 
       
   173 public:
       
   174 	TSglQueLink iLink;
       
   175 	};
       
   176 
       
   177 #endif