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