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