commands/fed/inc/common.h
changeset 0 7f656887cf89
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // common.h
       
     2 // 
       
     3 // Copyright (c) 2009 - 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 #ifndef COMMON_H_
       
    13 #define COMMON_H_
       
    14 
       
    15 #include <e32std.h>
       
    16 #include <e32def.h>
       
    17 #include <e32cmn.h>
       
    18 #include <e32keys.h>
       
    19 
       
    20 #ifdef ASSERT
       
    21 #undef ASSERT
       
    22 #endif
       
    23 #define ASSERT(x) __ASSERT_ALWAYS(x, AssertionFail(#x, __FILE__, __LINE__))
       
    24 void AssertionFail(const char* aAssertion, const char* aFile, TInt aLine);
       
    25 
       
    26 #if defined(_DEBUG)
       
    27 #define ASSERT_DEBUG(c,p) ASSERT(c)
       
    28 #else
       
    29 #define ASSERT_DEBUG(c,p)
       
    30 #endif
       
    31 
       
    32 #define CTRL(x) ((x)-'a'+1)
       
    33 
       
    34 class DCommandWindow;
       
    35 
       
    36 class TWindow
       
    37 {
       
    38 public:
       
    39 	TWindow()
       
    40 		: iX(0), iY(0), iWidth(0), iHeight(0) {}
       
    41 	TWindow(TInt aPosX, TInt aPosY, TInt aWidth, TInt aHeight)
       
    42 		: iX(aPosX), iY(aPosY), iWidth(aWidth), iHeight(aHeight) {}
       
    43 
       
    44 	TBool operator==(const TWindow& aWindow) const
       
    45 		{return iX == aWindow.iX && iY == aWindow.iY && iWidth == aWindow.iWidth && iHeight == aWindow.iHeight;}
       
    46 
       
    47 	TPoint Relocate(const TPoint& aPos) const
       
    48 		{return TPoint(iX + aPos.iX, iY + aPos.iY);}
       
    49 
       
    50 	TInt NextX() const {return iX + iWidth;}
       
    51 	TInt NextY() const {return iY + iHeight;}
       
    52 
       
    53 	TPoint Origin() const { return TPoint(iX, iY); }
       
    54 
       
    55 	TInt iX;
       
    56 	TInt iY;
       
    57 	TInt iWidth;
       
    58 	TInt iHeight;
       
    59 };
       
    60 
       
    61 //Overloaded by a class which can draw on the console
       
    62 class MViewController
       
    63 {
       
    64 public:
       
    65 	/*
       
    66 	 Activate the View and set the new position and size of the window (which may be not changed).
       
    67 	 The window is visible so only the difference between the old and the new window has to be redrawn.
       
    68 	 Used when the window needs to be resized or moved.*/
       
    69 	virtual void ResizeL(const TWindow& aWindow) = 0;
       
    70 	/*
       
    71 	 Activate the View and set the new position and size of the window (which may be not changed).
       
    72 	 The View is not visible so it has to redraw the whole window.
       
    73 	 Used when switching views visible in the same window.*/
       
    74 	virtual void RedrawL(const TWindow& aWindow) = 0;
       
    75 	/*
       
    76 	This view must stop drawing on the console, however It can still process data in the background.*/
       
    77 	virtual void DeactivateL() = 0;
       
    78 };
       
    79 
       
    80 //Overloaded by a class which uses a memory cache shared by another class (i.e. by MShareCacheProvider)
       
    81 class MSharedCacheClient
       
    82 {
       
    83 	//Gives the class, which owns the buffer, a chance to complete all writings using data in the buffer
       
    84 	virtual void InvalidateBuffer(TRequestStatus& aStatus) = 0;
       
    85 };
       
    86 
       
    87 class TRange;
       
    88 
       
    89 /*
       
    90  Overloaded by a class which provides shared access to its memory cache. The MSharedCacheClient class, which
       
    91  needs access to the memory cache provided by this class, supplies TPtrC8 descriptor pointer, which is being
       
    92  set to point to the existing data loaded to the memory cache and maintained by this class.
       
    93 */
       
    94 class MSharedCacheProvider
       
    95 	{
       
    96 	//Called to add a new client to this file buffer
       
    97 	virtual TInt RegisterClient(MSharedCacheClient& aClient, TPtrC& aDes, TRange& aRange, TInt& aRangeStartLineNumber) = 0;
       
    98 	virtual void UnregisterClient(MSharedCacheClient& aClient) = 0;
       
    99 	};
       
   100 
       
   101 //Overloaded by a class which can receive key input from the user
       
   102 class MKeyConsumer
       
   103 {
       
   104 public:
       
   105 	//Returns EFalse if the key wasn't consumed
       
   106 	virtual TBool ConsumeKeyL(const TKeyCode& aCode) = 0;
       
   107 };
       
   108 
       
   109 //Overloaded by a class which can defer closing the application
       
   110 class MDeferredClose
       
   111 {
       
   112 public:
       
   113 	/*
       
   114 	 Called when the object is about to be closed, gives a chance to save changed data.
       
   115 	 If the object can be closed immediately it should return ETrue, otherwise EFalse.
       
   116 	 If any data or info should be shown to the user then a request should be registered with MRequestHandler*/
       
   117 	virtual TBool TryCloseL() = 0;
       
   118 };
       
   119 
       
   120 class CConsoleBase;
       
   121 class CColorConsoleBase;
       
   122 class RFs;
       
   123 
       
   124 class MConsoleProvider
       
   125 	{
       
   126 public:
       
   127 	virtual CConsoleBase& Console() = 0;
       
   128 	virtual CColorConsoleBase* ColorConsole() = 0;
       
   129 	virtual RFs& Fs() = 0;
       
   130 	virtual void WriteStatus(const TDesC& aNameToTruncate, TRefByValue<const TDesC> aFmt, ...) = 0;
       
   131 	virtual void InfoPrint(TRefByValue<const TDesC> aFmt, ...) = 0;
       
   132 	virtual TKeyCode Query(const TDesC& aPrompt, const TDesC& aValidKeys) = 0;
       
   133 	virtual TBool QueryFilename(const TDesC& aPrompt, TFileName& aFileName) = 0;
       
   134 	virtual TBool QueryText(const TDesC& aPrompt, TDes& aText) = 0;
       
   135 	};
       
   136 
       
   137 // General helper class, suprised we don't have anything else suitable...
       
   138 class TRange
       
   139 	{
       
   140 public:
       
   141 	inline TRange() : iLocation(0), iLength(0) {}
       
   142 	inline TRange(TInt aLocation, TInt aLength)
       
   143 		: iLocation(aLocation), iLength(aLength)
       
   144 		{}
       
   145 		
       
   146 	inline TInt Max() const
       
   147 		{
       
   148 		return iLocation + iLength;
       
   149 		}
       
   150 
       
   151 	inline TBool Contains(TInt aLocation) const
       
   152 		{
       
   153 		return aLocation >= iLocation && aLocation < Max();
       
   154 		}
       
   155 	inline void Intersect(const TRange& aRange)
       
   156 		{
       
   157 		TInt end = Min(this->Max(), aRange.Max());
       
   158 		iLocation = ::Max(iLocation, aRange.iLocation); // Have to use :: to say "look at global namespace implementation of Max()"
       
   159 		iLength = end - iLocation;
       
   160 		}
       
   161 public:
       
   162 	TInt iLocation;
       
   163 	TInt iLength;
       
   164 	};
       
   165 
       
   166 extern TInt KConsoleWidthCorrection;
       
   167 extern TInt KConsoleHeightCorrection;
       
   168 TInt TabWidth();
       
   169 void ShowHelpL();
       
   170 
       
   171 #endif /*COMMON_H_*/