fbs/fontandbitmapserver/sfbs/SESSION.CPP
changeset 168 2bd88482bfe5
parent 152 9f1c3fea0f87
child 178 89bd4cfee505
equal deleted inserted replaced
152:9f1c3fea0f87 168:2bd88482bfe5
     1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 1995-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    19 #include "FBSVER.H"
    19 #include "FBSVER.H"
    20 #include "FbsRalc.h"
    20 #include "FbsRalc.h"
    21 #include "fbshelper.h"
    21 #include "fbshelper.h"
    22 #include "FbsMessage.H"
    22 #include "FbsMessage.H"
    23 #include <graphics/fbsoogmmessage.h>
    23 #include <graphics/fbsoogmmessage.h>
       
    24 #include "OstTraceDefinitions.h"
       
    25 #include "fbstrace.h"
       
    26 #ifdef OST_TRACE_COMPILER_IN_USE
       
    27 #include "SESSIONTraces.h"
       
    28 #endif
    24 
    29 
    25 GLDEF_C void Panic(TFbsPanic aPanic)
    30 GLDEF_C void Panic(TFbsPanic aPanic)
    26 	{
    31 	{
    27 	_LIT(KFBSERVClientPanicCategory,"FBSCLI");
    32 	_LIT(KFBSERVClientPanicCategory,"FBSCLI");
    28 	User::Panic(KFBSERVClientPanicCategory,aPanic);
    33 	User::Panic(KFBSERVClientPanicCategory,aPanic);
    89 @publishedAll 
    94 @publishedAll 
    90 @released
    95 @released
    91 */
    96 */
    92 EXPORT_C TInt RFbsSession::Connect(RFs& aFileServer)
    97 EXPORT_C TInt RFbsSession::Connect(RFs& aFileServer)
    93 	{
    98 	{
       
    99     TInt ret = KErrNone;
    94 	RFbsSession* thisptr = (RFbsSession*)Dll::Tls();
   100 	RFbsSession* thisptr = (RFbsSession*)Dll::Tls();
       
   101 	FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, RFBSSESSION_CONNECT_ENTRY, "> this=0x%08x;", (TUint)thisptr);)
    95 	if(thisptr)
   102 	if(thisptr)
    96 		{
   103 		{
    97 		thisptr->iConnections++;
   104 		thisptr->iConnections++;
    98 		return KErrNone;
   105 		FBS_OST(OstTraceExt2(GRAPHICS_CONTROL_SEMANTICS, RFBSSESSION_CONNECT_INFO, "# Connected to existing session; this=0x%08x; iConnections=%d;", (TInt)thisptr, thisptr->iConnections);)
    99 		}
   106 		}
   100 	TInt ret = RFbsSession::DoAlloc(thisptr);
   107 	else
   101 	if(ret!=KErrNone)
   108 	    {
   102 		return ret;
   109         ret = RFbsSession::DoAlloc(thisptr);
   103 	return thisptr->DoConnect(aFileServer);
   110         if(ret!=KErrNone)
       
   111             {
       
   112             FBS_OST(OstTrace1(TRACE_ERROR, RFBSSESSION_CONNECT_ERROR, "! DoAlloc returned %d", ret);)
       
   113             }
       
   114         else
       
   115             {
       
   116             ret = thisptr->DoConnect(aFileServer);
       
   117             if(ret!=KErrNone)
       
   118                 {
       
   119                 FBS_OST(OstTraceExt2(TRACE_ERROR, RFBSSESSION_CONNECT_ERROR2, "! this=0x%08x; DoConnect returned %d", (TInt)thisptr, ret);)
       
   120                 }
       
   121             }
       
   122 	    }
       
   123 	
       
   124 	FBS_OST(OstTraceExt2(GRAPHICS_CONTROL_FUNCTIONS, RFBSSESSION_CONNECT_EXIT, "< this=0x%08x; ret=%d", (TUint)thisptr, ret);)
       
   125 	return ret; 
   104 	}
   126 	}
   105 
   127 
   106 /** Creates a session with the Font and Bitmap server.
   128 /** Creates a session with the Font and Bitmap server.
   107 @return KErrNone, if successful; KErrNoMemory if there is not enough memory 
   129 @return KErrNone, if successful; KErrNoMemory if there is not enough memory 
   108 to create the session; otherwise another of the system-wide error codes. 
   130 to create the session; otherwise another of the system-wide error codes. 
   109 @publishedAll 
   131 @publishedAll 
   110 @released
   132 @released
   111 */
   133 */
   112 EXPORT_C TInt RFbsSession::Connect()
   134 EXPORT_C TInt RFbsSession::Connect()
   113 	{
   135 	{
       
   136     TInt ret = KErrNone;
   114 	RFbsSession* thisptr = (RFbsSession*)Dll::Tls();
   137 	RFbsSession* thisptr = (RFbsSession*)Dll::Tls();
       
   138 	FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, RFBSSESSION_CONNECT2_ENTRY, "> this=0x%08x;", (TUint)thisptr);)
   115 	if(thisptr)
   139 	if(thisptr)
   116 		{
   140 		{
   117 		thisptr->iConnections++;
   141 		thisptr->iConnections++;
   118 		return KErrNone;
   142 	    FBS_OST(OstTraceExt2(GRAPHICS_CONTROL_SEMANTICS, RFBSSESSION_CONNECT2_INFO, "# Connected to existing session; this=0x%08x; iConnections=%d;", (TInt)thisptr, thisptr->iConnections);)
   119 		}
   143 		}
   120 	TInt ret = RFbsSession::DoAlloc(thisptr);
   144 	else
   121 	if (ret!=KErrNone)
   145 	    {
   122 		return ret;
   146         TInt ret = RFbsSession::DoAlloc(thisptr);
   123 	ret = thisptr->iFileServer.Connect();
   147         if (ret!=KErrNone)
   124 	if(ret!=KErrNone)
   148             {
   125 		{
   149             FBS_OST(OstTrace1(TRACE_ERROR, RFBSSESSION_CONNECT2_ERROR, "! DoAlloc returned %d", ret);)
   126 		thisptr->Disconnect();
   150             goto end;
   127 		return ret;
   151             }
   128 		}
   152             
   129 	return thisptr->DoConnect(thisptr->iFileServer);
   153         ret = thisptr->iFileServer.Connect();
       
   154         if(ret!=KErrNone)
       
   155             {
       
   156             thisptr->Disconnect();
       
   157             FBS_OST(OstTraceExt2(TRACE_ERROR, RFBSSESSION_CONNECT2_ERROR2, "! this=0x%08x; RFs::Connect() returned %d", (TInt)thisptr, ret);)
       
   158             goto end;
       
   159             }
       
   160         
       
   161         ret = thisptr->DoConnect(thisptr->iFileServer);
       
   162         if(ret!=KErrNone)
       
   163             {
       
   164             FBS_OST(OstTraceExt2(TRACE_ERROR, RFBSSESSION_CONNECT2_ERROR3, "! this=0x%08x; DoConnect returned %d", (TInt)thisptr, ret);)
       
   165             }
       
   166 	    }
       
   167 end:
       
   168 	FBS_OST(OstTraceExt2(GRAPHICS_CONTROL_FUNCTIONS, RFBSSESSION_CONNECT2_EXIT, "< this=0x%08x; ret=%d", (TUint)thisptr, ret);)
       
   169 	return ret;
   130 	}
   170 	}
   131 
   171 
   132 /** Closes the session with the Font and Bitmap server. 
   172 /** Closes the session with the Font and Bitmap server. 
   133 @publishedAll 
   173 @publishedAll 
   134 @released
   174 @released
   135 */
   175 */
   136 EXPORT_C void RFbsSession::Disconnect()
   176 EXPORT_C void RFbsSession::Disconnect()
   137 	{
   177 	{
   138 	RFbsSession* thisptr=(RFbsSession*)Dll::Tls();
   178 	RFbsSession* thisptr=(RFbsSession*)Dll::Tls();
   139 	if(thisptr==NULL) return;
   179     FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, RFBSSESSION_DISCONNECT_ENTRY, "> this=0x%08x;", (TUint)thisptr);)
   140 	if(thisptr->iConnections>0)
   180 	if(thisptr)
   141 		{
   181 	    {
   142 		thisptr->iCallBack.iPtr=NULL;
   182         TInt tempServerSessionHandle = thisptr->ServerSessionHandle();
   143 		thisptr->iCallBack.CallBack();
   183         if(thisptr->iConnections>0)
   144 		// Destructor of CFbsSessionHelper may call SendCommand to cancel an
   184             {
   145 		// outstanding request, therefore destruction must be done before
   185             thisptr->iCallBack.iPtr=NULL;
   146 		// iConnections is 0 to avoid an assertion going off.
   186             thisptr->iCallBack.CallBack();
   147 		if(thisptr->iConnections==1)
   187             // Destructor of CFbsSessionHelper may call SendCommand to cancel an
   148 			{
   188             // outstanding request, therefore destruction must be done before
   149 			delete thisptr->iHelper;
   189             // iConnections is 0 to avoid an assertion going off.
   150 			}
   190             if(thisptr->iConnections==1)
   151 		thisptr->iConnections--;
   191                 {
   152 		}
   192                 delete thisptr->iHelper;
   153 	if(thisptr->iConnections==0)
   193                 }
   154 		{
   194             thisptr->iConnections--;
   155 		thisptr->iSharedChunk.Close();
   195             }
   156 		thisptr->iLargeBitmapChunk.Close();
   196         if(thisptr->iConnections==0)
   157 		// Call close on the iFileServer regardless of whether this session owns it: 
   197             {
   158 		// if we don't own it, close will do nothing if there are still open files, 
   198             thisptr->iSharedChunk.Close();
   159 		// so always calling close introduces extra safety
   199             thisptr->iLargeBitmapChunk.Close();
   160 		thisptr->iFileServer.Close();
   200             // Call close on the iFileServer regardless of whether this session owns it: 
   161 		delete thisptr->iRomFileAddrCache; 
   201             // if we don't own it, close will do nothing if there are still open files, 
   162 		delete thisptr->iScanLineBuffer;
   202             // so always calling close introduces extra safety
   163 		delete thisptr->iDecompressionBuffer;
   203             thisptr->iFileServer.Close();
   164 		thisptr->Close();
   204             delete thisptr->iRomFileAddrCache; 
   165 		delete thisptr;
   205             delete thisptr->iScanLineBuffer;
   166 		Dll::FreeTls();
   206             delete thisptr->iDecompressionBuffer;
   167 		}
   207             thisptr->Close();
       
   208             delete thisptr;
       
   209             Dll::FreeTls();	
       
   210             }
       
   211         FBS_OST(OstTraceExt3(GRAPHICS_CONTROL_SEMANTICS, RFBSSESSION_DISCONNECT_INFO, "# Disconnected from session; this=0x%08x; iConnections=%d; iSSH=0x%08x", (TInt)thisptr, thisptr->iConnections, tempServerSessionHandle);)
       
   212 	    }
       
   213 	FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, RFBSSESSION_DISCONNECT_EXIT2, "< this=0x%08x;", (TUint)thisptr);)
   168 	}
   214 	}
   169 
   215 
   170 /**  Gets the current Font and Bitmap server session.
   216 /**  Gets the current Font and Bitmap server session.
   171 @return  A pointer to the current session or NULL if Connect() has not been 
   217 @return  A pointer to the current session or NULL if Connect() has not been 
   172 called yet. 
   218 called yet. 
   357 		{
   403 		{
   358 		Disconnect();
   404 		Disconnect();
   359 		return KErrNoMemory;
   405 		return KErrNoMemory;
   360 		}
   406 		}
   361 	iHelper->iServerSessionHandle = serverAssignedHandle;
   407 	iHelper->iServerSessionHandle = serverAssignedHandle;
       
   408 	
   362 	ret = iLargeBitmapChunk.OpenGlobal(KFBSERVLargeChunkName,EFalse);
   409 	ret = iLargeBitmapChunk.OpenGlobal(KFBSERVLargeChunkName,EFalse);
   363 	if(ret!=KErrNone) 
   410 	if(ret!=KErrNone) 
   364 		Panic(EFbsPanicChunkError);
   411 		Panic(EFbsPanicChunkError);
   365 	
   412 	
   366 	iSpare = (TUint32*)&aFileServer;
   413 	iSpare = (TUint32*)&aFileServer;
       
   414 	
       
   415     FBS_OST(OstTraceExt2(GRAPHICS_CONTROL_SEMANTICS, RFBSSESSION_DOCONNECT_INFO, "# New FBS Session created; this=0x%08x; iSSH=0x%08x;", (TInt)this, serverAssignedHandle);)
   367 	return KErrNone;
   416 	return KErrNone;
   368 	}
   417 	}
   369 	
   418 	
   370 /**  
   419 /**  
   371 Allocates the buffer for decoding compressed rom bitmaps.
   420 Allocates the buffer for decoding compressed rom bitmaps.