uiacceltk/hitchcock/ServerCore/Src/alfappsrvsessionBase.cpp
changeset 0 15bf7259bb7c
child 3 d8a3531bc6b8
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "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 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   Server session
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <uiacceltk/HuiEnv.h>
       
    20 #include <uiacceltk/HuiRoster.h>
       
    21 #include <uiacceltk/HuiDisplay.h>
       
    22 #include <uiacceltk/HuiEvent.h>
       
    23 #include <uiacceltk/HuiControl.h>
       
    24 #include <uiacceltk/HuiControlGroup.h>
       
    25 #include <uiacceltk/HuiUtil.h>
       
    26 
       
    27 #include "alf/alfappsrvsessionbase.h"
       
    28 #include "alf/alfappserver.h"
       
    29 #include "alf/alfappui.h"
       
    30 #include "alf/alfconstants.h"
       
    31 #include "alfloggingconfiguration.h"
       
    32 #include "alflogger.h"
       
    33 #include "alfsrvdisplaysubsession.h"
       
    34 #include "alfsrvcontrolgroupsubsession.h"
       
    35 #include "alfsrvtransformationsubsession.h"
       
    36 #include "alf/alfextensionfactory.h"
       
    37 #include "alf/alfversion.h"
       
    38 #include "alfsrvsettingshandler.h"
       
    39 
       
    40 const TUint KAlfMaxCpuUsageDuringPointerEvent = 35; // Percentage
       
    41 
       
    42 struct TAlfHandleAndImplUid
       
    43     {
       
    44     TAlfHandleAndImplUid(TInt aHandle, TInt aUid):iHandle(aHandle),iUid(aUid){}
       
    45     static TBool Compare(const TInt* aKey, const TAlfHandleAndImplUid& aEntry)
       
    46         {
       
    47         return (*aKey==aEntry.iHandle);
       
    48         }
       
    49     TInt iHandle;
       
    50     TInt iUid;
       
    51     };
       
    52 
       
    53 struct TAlfTouchEventS: public TAlfTouchEvent
       
    54     {
       
    55     TAlfTouchEventS(const THuiEvent& aEvent) 
       
    56         {
       
    57         iEvent = aEvent.iPointerEvent;
       
    58         Mem::FillZ(iControls, sizeof(iControls));
       
    59         Mem::FillZ(iVisuals, sizeof(iVisuals));
       
    60         }
       
    61         
       
    62     void AppendCtrl(TInt aControlHandle, TInt aVisualHandle)
       
    63         {
       
    64         for (TInt ii = 0; ii < KAlfTouchEventControlCount; ii++)
       
    65             {
       
    66             if (iControls[ii] == 0)
       
    67                 {
       
    68                 iControls[ii] = aControlHandle;
       
    69                 iVisuals[ii] = aVisualHandle;
       
    70                 break;
       
    71                 }
       
    72             else if ( ii == KAlfTouchEventControlCount-1 )
       
    73                 {
       
    74                 __ALFLOGSTRING( "TAlfTouchEventS::AppendCtrl: Overflow" )
       
    75                 }
       
    76             else
       
    77                 {
       
    78                 // For PC-lint
       
    79                 }
       
    80             }
       
    81         }
       
    82     };
       
    83 
       
    84 NONSHARABLE_CLASS(CAlfAppSrvSessionBase::TPrivateData)
       
    85     {
       
    86     public:
       
    87     enum TAlfPtrEventState 
       
    88         {
       
    89         ENotInitialized,
       
    90         EStartNewEvent,
       
    91         EUpdateCtrls,
       
    92         ENotFocused
       
    93         };
       
    94     
       
    95     public:
       
    96     TPrivateData():iSharedEnv(0),iContainer(0),iObjectIx(0) {}
       
    97     CHuiEnv* iSharedEnv;
       
    98     TInt iClientWindowGroupId;
       
    99     CObjectCon* iContainer;     // Not own
       
   100     CObjectIx* iObjectIx;       // Own
       
   101     RArray<TAlfHandleAndImplUid> iHandles;    
       
   102     RPointerArray<CAlfClientMessage> iMessages;
       
   103     RArray<TAlfTouchEventS>       iHuiEvents; // now only pointer events are supported
       
   104     TAlfPtrEventState iPtrEventState;
       
   105     RMessagePtr2 iPointerEvent;
       
   106     RMessagePtr2 iSystemEvent;
       
   107     TInt iParentId;
       
   108     TBool iActive;
       
   109     }; 
       
   110 
       
   111 // ======== MEMBER FUNCTIONS ========
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // Cosntructor
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 EXPORT_C CAlfAppSrvSessionBase::CAlfAppSrvSessionBase(const CAlfAppServer* aServer)
       
   118     :iHost(const_cast<CAlfAppServer*>(aServer))
       
   119     {
       
   120     }
       
   121 
       
   122 EXPORT_C CAlfAppSrvSessionBase::CAlfAppSrvSessionBase()
       
   123     :iHost(static_cast<CAlfAppServer*>(CEikonEnv::Static()->AppServer()))
       
   124     {
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // Destructor
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 EXPORT_C CAlfAppSrvSessionBase::~CAlfAppSrvSessionBase()
       
   132     { 
       
   133     iHost->HandleClientExit(reinterpret_cast<TInt>(this));
       
   134     
       
   135     if ( iData )
       
   136         {
       
   137         iData->iHandles.Close();
       
   138         delete iData->iObjectIx;
       
   139     
       
   140         // there shouldn't be orphean messages unless client app has been abnormally terminated...
       
   141         while( iData->iMessages.Count() )
       
   142             {
       
   143             iData->iMessages[0]->CompleteMessageD(KErrCancel);
       
   144             iData->iMessages.Remove(0);
       
   145             }
       
   146 
       
   147         iData->iMessages.Close();
       
   148         iData->iHuiEvents.Close();
       
   149         if (!iData->iPointerEvent.IsNull())
       
   150             {
       
   151             iData->iPointerEvent.Complete(KErrCancel);
       
   152             }
       
   153         if (!iData->iSystemEvent.IsNull())
       
   154             {
       
   155             iData->iSystemEvent.Complete(KErrCancel);
       
   156             }
       
   157         delete iData;
       
   158         }
       
   159     iHost = NULL;
       
   160     }
       
   161   
       
   162 // ---------------------------------------------------------------------------
       
   163 // Called when focus gained.
       
   164 // ---------------------------------------------------------------------------
       
   165 //  
       
   166 EXPORT_C void CAlfAppSrvSessionBase::FocusGainedL( TBool /*aDoTransitionEffect*/ )
       
   167     {
       
   168     // do some default effect if any
       
   169     }
       
   170   
       
   171 // ---------------------------------------------------------------------------
       
   172 // Called when focus lost.
       
   173 // ---------------------------------------------------------------------------
       
   174 //    
       
   175 EXPORT_C TBool CAlfAppSrvSessionBase::FocusLostL( TBool /*aDoTransitionEffect*/ )
       
   176     {
       
   177     // do some default effect if any
       
   178     return EFalse;
       
   179     }
       
   180     
       
   181 // ---------------------------------------------------------------------------
       
   182 // Returns server.
       
   183 // ---------------------------------------------------------------------------
       
   184 //  
       
   185 EXPORT_C CAlfAppServer* CAlfAppSrvSessionBase::AlfServer()
       
   186     {
       
   187     return iHost;
       
   188     }
       
   189 
       
   190 // ---------------------------------------------------------------------------
       
   191 // Returns AppUi.
       
   192 // ---------------------------------------------------------------------------
       
   193 //  
       
   194 EXPORT_C CAlfAppUi* CAlfAppSrvSessionBase::AlfAppUi()
       
   195     {
       
   196     return iHost->AppUi(); // there is always AppUi when it is possible to create clients
       
   197     }
       
   198 
       
   199 // ---------------------------------------------------------------------------
       
   200 // From class CAknAppServiceBase.
       
   201 // Called when client requests a service.
       
   202 // ---------------------------------------------------------------------------
       
   203 //
       
   204 EXPORT_C void CAlfAppSrvSessionBase::ServiceL(const RMessage2& aMessage)
       
   205     {
       
   206     if(iHost->MetricsInterface())
       
   207         {
       
   208         iHost->MetricsInterface()->EnterClientMessageL(reinterpret_cast<TInt>(this), aMessage);
       
   209         if (aMessage.IsNull())
       
   210             { // metrics interface completed the message, just abort handling of message 
       
   211             return;
       
   212             }
       
   213         }
       
   214         
       
   215     
       
   216 #ifdef _ALF_LOGGING
       
   217     TRAPD( err, 
       
   218         {
       
   219         if (!DoSubSessionCmdL(aMessage))    
       
   220             {
       
   221             DoHandleCommandL(aMessage);
       
   222             }
       
   223         } );
       
   224     if ( err != KErrNone )
       
   225         {
       
   226         __ALFLOGSTRING2( "CAlfAppSrvSessionBase::ServiceL req %d err %d", aMessage.Function(), err )
       
   227         User::Leave( err );
       
   228         }
       
   229         
       
   230 #else
       
   231     if (!DoSubSessionCmdL(aMessage))    
       
   232         {
       
   233         DoHandleCommandL(aMessage);
       
   234         }
       
   235 #endif
       
   236 
       
   237     if(iHost->MetricsInterface())
       
   238         {
       
   239         iHost->MetricsInterface()->ExitClientMessage(reinterpret_cast<TInt>(this), aMessage);
       
   240         }
       
   241 
       
   242     }
       
   243 
       
   244 // ---------------------------------------------------------------------------
       
   245 // 
       
   246 // ---------------------------------------------------------------------------
       
   247 // 
       
   248 TBool CAlfAppSrvSessionBase::DoSubSessionCmdL(const RMessage2& aMessage)
       
   249     {
       
   250     TBool handled = ETrue;
       
   251     TInt function = aMessage.Function();
       
   252      // check if we are creating a subsession
       
   253     if ( function == EAlfCreateSubSession )
       
   254         {
       
   255         // Create subsession.
       
   256         CAlfSrvSubSessionBase* subSession = CreateSubSessionLC( aMessage );
       
   257         
       
   258         // Add to container (takes ownership)
       
   259         iData->iContainer->AddL( subSession );
       
   260         CleanupStack::Pop( subSession );
       
   261         
       
   262         const TInt handle = iData->iObjectIx->AddL( subSession );
       
   263         
       
   264         iData->iHandles.AppendL(TAlfHandleAndImplUid(handle,subSession->iFactoryUid));
       
   265         
       
   266         // Inform client of the handle its been allocated
       
   267         TPckg<TInt> handlePckg( handle );
       
   268         aMessage.Write(3,handlePckg);
       
   269         
       
   270         if ( !aMessage.IsNull() )
       
   271             {
       
   272             // Complete the message
       
   273             aMessage.Complete( KErrNone );
       
   274             }
       
   275         }
       
   276         
       
   277     else if ( function == EAlfDoSubSessionCmd ||
       
   278         function == EAlfDoAsyncSubSessionCmd ||
       
   279         function == EAlfSubSCancelAsynchRequest )
       
   280         {
       
   281         // Find an appropriate object and pass the message to it
       
   282         // for processing...
       
   283         //
       
   284         // we don't allow subsessions close each other, but session that sent the 
       
   285         // original request must be used for cancelling  
       
   286         //
       
   287         // We could use subsession information from message queue if anyone 
       
   288         // needs to be able to cancel commands
       
   289         const TInt handle = aMessage.Int3();
       
   290         
       
   291         // Fetch the sub-session by its handle
       
   292         CObject* object = iData->iObjectIx->At( handle );
       
   293         __ASSERT_ALWAYS( object , USER_INVARIANT() );
       
   294          
       
   295         CAlfSrvSubSessionBase* subsession = static_cast<CAlfSrvSubSessionBase*>(object);
       
   296         if (function != EAlfSubSCancelAsynchRequest)
       
   297             {
       
   298             subsession->ProcessMessageL( aMessage );
       
   299             }
       
   300         else
       
   301             {
       
   302             TInt index = iData->iMessages.Find(aMessage.Int0(), CAlfClientMessage::Compare);
       
   303             TInt count = iData->iMessages.Count();
       
   304             
       
   305             if  (index != KErrNotFound)   
       
   306                 {
       
   307                 TInt2 cancelParams(iData->iMessages[index]->iClientId, iData->iMessages[index]->iDecodedOp);
       
   308                 TPckgC<TInt2> inbuf(cancelParams);
       
   309                 TBuf8<1> dum;
       
   310                 MAlfExtension* cmdHandler =  subsession->AsCommandHandler();
       
   311                 if (cmdHandler)
       
   312                     {
       
   313                     cmdHandler->HandleCmdL(EAlfSubSCancelAsynchRequest, inbuf, dum);
       
   314                     }
       
   315                 if (count == iData->iMessages.Count()) // message not successfully removed
       
   316                     {
       
   317 #ifdef _ALF_LOGGING
       
   318                     RThread thread; 
       
   319                     iData->iMessages[index]->iMessage.ClientL(thread);
       
   320                     const TName threadName = thread.Name();
       
   321                     __ALFLOGSTRING2( "CAlfAppSrvSessionBase::DoSubSessionCmdL: Asynch message from client: %S, op: %d was not cancelled correctly",
       
   322                         &threadName, iData->iMessages[index]->iDecodedOp)
       
   323                     thread.Close();
       
   324 #endif // _ALF_LOGGING       
       
   325                     
       
   326                     iData->iMessages[index]->CompleteMessageD(KErrCancel);
       
   327                     iData->iMessages.Remove(index);
       
   328                     }                
       
   329                 }
       
   330             aMessage.Complete(KErrNone);
       
   331             }
       
   332         }
       
   333 
       
   334     else if (function == EAlfCloseSubSession)
       
   335         {
       
   336         CloseSubSession(aMessage);
       
   337         }
       
   338      else 
       
   339         {
       
   340         handled = EFalse;
       
   341         }    
       
   342     
       
   343     return handled;
       
   344     }
       
   345 
       
   346 // ---------------------------------------------------------------------------
       
   347 // Called on contruction.
       
   348 // ---------------------------------------------------------------------------
       
   349 // 
       
   350 EXPORT_C void CAlfAppSrvSessionBase::BaseConstructL()
       
   351     {
       
   352     // instrument private data etc..
       
   353     __ASSERT_ALWAYS(!iData,USER_INVARIANT());
       
   354     iData = new (ELeave) TPrivateData();
       
   355     iData->iSharedEnv = &AlfAppUi()->HuiEnv();
       
   356     iData->iClientWindowGroupId = KErrNotFound;
       
   357     
       
   358     iData->iContainer = iHost->NewContainerL();
       
   359     iData->iObjectIx = CObjectIx::NewL();  
       
   360     iData->iParentId = KErrNotFound; 
       
   361     }
       
   362     
       
   363 // ---------------------------------------------------------------------------
       
   364 // 
       
   365 // ---------------------------------------------------------------------------
       
   366 // 
       
   367 EXPORT_C void CAlfAppSrvSessionBase::ExtensionInterfaceL(TUid /*aInterfaceId*/, TAny*& /*aImplementaion*/)
       
   368     {
       
   369     
       
   370     }
       
   371 
       
   372 // ---------------------------------------------------------------------------
       
   373 // 
       
   374 // ---------------------------------------------------------------------------
       
   375 // 
       
   376 EXPORT_C CHuiEnv* CAlfAppSrvSessionBase::SharedHuiEnv() const
       
   377     {
       
   378     if (iData)
       
   379         {
       
   380         return iData->iSharedEnv;
       
   381         }
       
   382         
       
   383     return 0;
       
   384     }
       
   385 
       
   386 // ---------------------------------------------------------------------------
       
   387 // 
       
   388 // ---------------------------------------------------------------------------
       
   389 // 
       
   390 EXPORT_C void CAlfAppSrvSessionBase::SetClientWindowGroupId(TInt aId)
       
   391     {
       
   392     __ASSERT_DEBUG(iData, USER_INVARIANT());
       
   393     iData->iClientWindowGroupId = aId;
       
   394     }
       
   395 
       
   396 // ---------------------------------------------------------------------------
       
   397 // 
       
   398 // ---------------------------------------------------------------------------
       
   399 //     
       
   400 EXPORT_C TRect CAlfAppSrvSessionBase::ClientDrawingArea() const
       
   401     {
       
   402     return TRect(0,0,0,0);
       
   403     }
       
   404 
       
   405 // ---------------------------------------------------------------------------
       
   406 // 
       
   407 // ---------------------------------------------------------------------------
       
   408 // 
       
   409 TInt CAlfAppSrvSessionBase::ClientWindowGroup() const
       
   410     {
       
   411     if (iData)
       
   412         {
       
   413         return iData->iClientWindowGroupId;
       
   414         }
       
   415     else
       
   416         {
       
   417         return KErrNotFound;
       
   418         }
       
   419     }
       
   420   
       
   421 // ---------------------------------------------------------------------------
       
   422 // 
       
   423 // ---------------------------------------------------------------------------
       
   424 //   
       
   425 CAlfSrvSubSessionBase* CAlfAppSrvSessionBase::CreateSubSessionLC(const RMessage2& aMessage)
       
   426     {
       
   427     CAlfSrvSubSessionBase* subSession = NULL;
       
   428     
       
   429     TPckgBuf<TAlfImplementationInformation> buf;
       
   430     aMessage.ReadL(0,buf);
       
   431 
       
   432     if (buf().iImplementationUid == 0) // built in component requested
       
   433         {
       
   434         switch (buf().iImplementationId)
       
   435             {
       
   436             case EAlfDisplaySubSessionOpen:
       
   437                 {
       
   438                 TRect rect;
       
   439                 TPckg<TRect> rectPckg(rect); 
       
   440                 aMessage.Read(1,rectPckg);
       
   441 
       
   442                 TAlfDisplayCreateParams params;
       
   443                 TPckg<TAlfDisplayCreateParams> paramPckg(params); 
       
   444                 aMessage.Read(2,paramPckg);
       
   445 
       
   446                 const TInt windowGroupId = params.iWindowGroupId;
       
   447                 const TInt displayType = params.iDisplayType;
       
   448                 subSession = CAlfSrvDisplaySubSession::NewLC( *this, rect, windowGroupId, displayType, KHuiUidBackBufferScreen0 );
       
   449                 break;
       
   450                 }
       
   451             case EAlfDisplaySubSessionOpen2:
       
   452                 {
       
   453                 TRect rect;
       
   454                 TPckg<TRect> rectPckg(rect); 
       
   455                 aMessage.Read(1,rectPckg);
       
   456 
       
   457                 TAlfDisplayCreateParams2 params;
       
   458                 TPckg<TAlfDisplayCreateParams2> paramPckg(params); 
       
   459                 aMessage.Read(2,paramPckg);
       
   460 
       
   461                 const TInt windowGroupId = params.iWindowGroupId;
       
   462                 const TInt displayType = params.iDisplayType;
       
   463                 const TUid bufferUid = params.iBufferUid;
       
   464                 subSession = CAlfSrvDisplaySubSession::NewLC( *this, rect, windowGroupId, displayType, bufferUid );
       
   465                 break;
       
   466                 }
       
   467             case EAlfControlGroupSubSessionOpen:
       
   468                 {
       
   469                 const TInt id = aMessage.Int1();
       
   470                 subSession = CAlfSrvControlGroupSubSession::NewLC( *this, id );
       
   471                 break;
       
   472                 }
       
   473             
       
   474             case EAlfTransformationSubSessionOpen:
       
   475                 {
       
   476                 subSession = CAlfSrvTransformationSubSession::NewLC( *this );
       
   477                 break;
       
   478                 }
       
   479             
       
   480             default:
       
   481                 subSession = CAlfSrvSubSessionBase::NewLC( aMessage, 
       
   482                                                    buf().iImplementationUid,
       
   483                                                    buf().iImplementationId, 
       
   484                                                    *this );
       
   485                 break;
       
   486             }
       
   487         }
       
   488     else
       
   489         {
       
   490         // Check what API has been used when app has been compiled before
       
   491         // loading extension. If runtime version is no more binary compatible, leave
       
   492         TVersion compiletimeVersion = buf().iVersion;
       
   493         TVersion runtimeVersion = TVersion(ALF_VERSION_MAJOR, ALF_VERSION_MINOR, ALF_VERSION_BUILD);
       
   494         // Major version (AlfClient.dll) has been already checked in the client side at this time.        
       
   495         // Minor version (AlfServercore, coretoolkit) is checked here.
       
   496         if (compiletimeVersion.iMinor != runtimeVersion.iMinor)
       
   497             {
       
   498             User::Leave(KErrNotSupported);    
       
   499             }
       
   500         // For check also build here
       
   501         else if (compiletimeVersion.iBuild > runtimeVersion.iBuild)
       
   502             {                
       
   503             User::Leave(KErrNotSupported);    
       
   504             }    
       
   505         else
       
   506             {                
       
   507             subSession = CAlfSrvSubSessionBase::NewLC( aMessage, 
       
   508                                                        buf().iImplementationUid,
       
   509                                                        buf().iImplementationId,                                                        *this );
       
   510             }
       
   511         }
       
   512          
       
   513     return subSession;
       
   514     }
       
   515 
       
   516 
       
   517 // -----------------------------------------------------------------------------
       
   518 // Remove object from object index
       
   519 // -----------------------------------------------------------------------------
       
   520 //
       
   521 void CAlfAppSrvSessionBase::CloseSubSession( const RMessage2& aMessage )
       
   522     {
       
   523     TInt handle = aMessage.Int3();
       
   524     CloseSubSession(handle);
       
   525     
       
   526     TInt err = KErrNone;
       
   527 
       
   528 #ifdef _DEBUG    
       
   529     for (TInt ii = iData->iMessages.Count()-1; ii >= 0; ii--)
       
   530         {
       
   531         if ((iData->iMessages)[ii]->iSubSession == handle)
       
   532             {
       
   533             iData->iMessages[ii]->CompleteMessageD(KErrCancel);
       
   534             iData->iMessages.Remove(ii);
       
   535             err = KErrCompletion;
       
   536             }
       
   537         }
       
   538 #endif
       
   539         
       
   540     aMessage.Complete( err );
       
   541     }
       
   542 
       
   543 // ---------------------------------------------------------------------------
       
   544 // 
       
   545 // ---------------------------------------------------------------------------
       
   546 // 
       
   547 void CAlfAppSrvSessionBase::CloseSubSession(TInt aHandle)
       
   548     {
       
   549     CObject* obj = iData->iObjectIx->At( aHandle );  
       
   550     __ASSERT_ALWAYS( obj, USER_INVARIANT() );
       
   551     iData->iObjectIx->Remove( aHandle );
       
   552     
       
   553     TInt index = iData->iHandles.Find(aHandle, TAlfHandleAndImplUid::Compare);
       
   554     if (index != KErrNotFound)
       
   555         {
       
   556         AlfServer()->DestroyedObject( iData->iHandles[index].iUid );
       
   557         iData->iHandles.Remove(index);
       
   558         }
       
   559     }
       
   560 
       
   561 // ---------------------------------------------------------------------------
       
   562 // 
       
   563 // ---------------------------------------------------------------------------
       
   564 // 
       
   565 TBool CAlfAppSrvSessionBase::HasSession( TInt aSubSessionHandle ) const
       
   566     {
       
   567     CObject* object = iData->iObjectIx->At( aSubSessionHandle );
       
   568     return object != NULL;
       
   569     }
       
   570 
       
   571 // ---------------------------------------------------------------------------
       
   572 // 
       
   573 // ---------------------------------------------------------------------------
       
   574 // 
       
   575 CAlfSrvSubSessionBase& CAlfAppSrvSessionBase::SubSession( TInt aSubSessionHandle )
       
   576     {
       
   577     // Fetch the sub-session by its handle
       
   578     CObject* object = iData->iObjectIx->At( aSubSessionHandle );
       
   579     __ASSERT_ALWAYS( object, USER_INVARIANT() );
       
   580     CAlfSrvSubSessionBase* subSession = static_cast<CAlfSrvSubSessionBase*>(object);
       
   581     return *subSession;
       
   582     }
       
   583  
       
   584 // ---------------------------------------------------------------------------
       
   585 // 
       
   586 // ---------------------------------------------------------------------------
       
   587 // 
       
   588 TAny* FetchInterface(const THuiInterfaceSupport aType, CAlfSrvSubSessionBase* aSubSession )
       
   589 	{
       
   590 	TAny* result = 0;
       
   591 	switch (aType)
       
   592 	    {
       
   593 	    case EHuiObjectTypeVisual:
       
   594 	        result = aSubSession->AsHuiVisual();
       
   595 	        break;
       
   596 	    
       
   597 	    case EHuiObjectTypeLayout:
       
   598 	        result = aSubSession->AsHuiLayout();
       
   599 	        break;
       
   600 	    
       
   601 	    case EHuiObjectTypeControl:
       
   602 	        result = aSubSession->AsHuiControl();
       
   603 	        break;
       
   604 	        
       
   605 	    case EHuiObjectTypeControlGroup:
       
   606 	        result = aSubSession->AsHuiControlCroup();
       
   607 	        break;
       
   608 	        
       
   609 	    case EHuiObjectTypeDisplay:
       
   610 	        result = aSubSession->AsHuiDisplay();
       
   611 	        break;
       
   612 	    
       
   613 	    case EHuiObjectTypeBrush:
       
   614 	        result = aSubSession->AsHuiBrush();
       
   615 	        break;
       
   616 	    
       
   617 	    case EHuiInterfaceMappingFunction:
       
   618 	        result = aSubSession->AsMappingFunction();        
       
   619 	        break;
       
   620 	
       
   621 	    case EHuiInterfaceVisualOwner:
       
   622 	        result = aSubSession->AsVisualOwner();        
       
   623 	        break;
       
   624 	    case EAlfBrushHandler:
       
   625 	        result = aSubSession->AsBrushHandler();
       
   626 	        break;
       
   627 	    default:
       
   628 	       {
       
   629 	       if ( aSubSession->AsCommandHandler() )    
       
   630 	           {
       
   631 	           result = aSubSession->AsCommandHandler()->GetInterface(aType);     
       
   632 	           }
       
   633 	       break;
       
   634 	       }
       
   635 	   }    
       
   636 	return result;
       
   637 	}
       
   638 
       
   639 // ---------------------------------------------------------------------------
       
   640 // 
       
   641 // ---------------------------------------------------------------------------
       
   642 // 
       
   643 EXPORT_C TAny* CAlfAppSrvSessionBase::GetInterfaceL(const THuiInterfaceSupport& aType, TInt aHandle)
       
   644     {
       
   645     CObject* obj = iData->iObjectIx->At( aHandle );  
       
   646     if (!obj)
       
   647         {
       
   648         User::Leave(KErrArgument);
       
   649         }
       
   650     
       
   651     CAlfSrvSubSessionBase* subSession = static_cast<CAlfSrvSubSessionBase*>(obj);
       
   652 
       
   653     TAny* result = FetchInterface(aType, subSession);
       
   654 
       
   655     if (!result)
       
   656         {
       
   657         User::Leave(KErrArgument);
       
   658         }
       
   659     
       
   660     return result;
       
   661     }
       
   662 
       
   663 // ---------------------------------------------------------------------------
       
   664 // 
       
   665 // ---------------------------------------------------------------------------
       
   666 // 
       
   667 EXPORT_C TInt CAlfAppSrvSessionBase::GetHandleFromInterface(const THuiInterfaceSupport& aType, TAny* aInterface)
       
   668     {
       
   669     TInt handle = KErrNotFound;
       
   670     for (TInt ii = iData->iHandles.Count()-1; ii >= 0; ii--)
       
   671         {
       
   672         const TInt handleitr = iData->iHandles[ii].iHandle;
       
   673         CAlfSrvSubSessionBase* subSession = &SubSession(handleitr);
       
   674 
       
   675         TAny* result = FetchInterface(aType, subSession);    
       
   676         
       
   677         if (result == aInterface)
       
   678             {
       
   679             handle = handleitr;
       
   680             break;
       
   681             }
       
   682         }
       
   683     return handle;
       
   684     }
       
   685  
       
   686 // ---------------------------------------------------------------------------
       
   687 // 
       
   688 // ---------------------------------------------------------------------------
       
   689 // 
       
   690 EXPORT_C CAlfLayoutManager* CAlfAppSrvSessionBase::LayoutManager() const
       
   691     {
       
   692     return NULL;
       
   693     }
       
   694 
       
   695 // ---------------------------------------------------------------------------
       
   696 // Extension method to implement new virtual like methods w/o breakin binary compatibility
       
   697 // ---------------------------------------------------------------------------
       
   698 //     
       
   699 EXPORT_C void CAlfAppSrvSessionBase::AlfInterfaceProviderExtension(const TUid& /*aExtensionUid*/, TAny** /*aExtensionParams*/)
       
   700     {
       
   701     
       
   702     }
       
   703 
       
   704 
       
   705 // ---------------------------------------------------------------------------
       
   706 // 
       
   707 // ---------------------------------------------------------------------------
       
   708 // 
       
   709 EXPORT_C void CAlfAppSrvSessionBase::FactoryDestroyed(TInt aFactoryUid)
       
   710     {
       
   711     // Todo: We should rather close the whole application...
       
   712     
       
   713     for (TInt ii = iData->iHandles.Count()-1; ii >= 0; ii--) // destroy in reverse order
       
   714         {
       
   715         if (iData->iHandles[ii].iUid == aFactoryUid)
       
   716             {
       
   717             CloseSubSession(iData->iHandles[ii].iHandle);
       
   718             }
       
   719         }
       
   720     }
       
   721  
       
   722 // ---------------------------------------------------------------------------
       
   723 // 
       
   724 // ---------------------------------------------------------------------------
       
   725 // 
       
   726 CAlfClientMessage* CAlfAppSrvSessionBase::CreateNewMessageHolderL(const RMessage2& aMessage)
       
   727     {
       
   728     CAlfClientMessage* msg = CAlfClientMessage::NewLC(aMessage.Int3(), aMessage);
       
   729     
       
   730     TInt lenght1 = aMessage.GetDesLength(1);
       
   731     TInt lenght2 = aMessage.GetDesMaxLength(2);
       
   732      
       
   733     msg->iInBuf = HBufC8::NewL(lenght1);
       
   734     TPtr8 inBuf = msg->iInBuf->Des();
       
   735     aMessage.ReadL(1,inBuf); 
       
   736         
       
   737     msg->iOutBuf = HBufC8::NewL(lenght2);
       
   738     
       
   739     if (aMessage.Function() == EAlfDoAsyncSubSessionCmd)
       
   740         {
       
   741         TInt2 params(0,0);
       
   742         TPckg<TInt2> pbuf(params);
       
   743         aMessage.ReadL(0,pbuf);
       
   744         msg->SetClientParams(params);
       
   745         }
       
   746     else
       
   747         {
       
   748         msg->iDecodedOp = aMessage.Int0();
       
   749         }
       
   750         
       
   751     iData->iMessages.InsertL(msg, 0);
       
   752     CleanupStack::Pop(msg);
       
   753     return msg;  
       
   754     }
       
   755 
       
   756 // ---------------------------------------------------------------------------
       
   757 // 
       
   758 // ---------------------------------------------------------------------------
       
   759 // 
       
   760 EXPORT_C TInt CAlfAppSrvSessionBase::HandleCurrentCommanndAsynch()
       
   761     {
       
   762     // If your code hits following assert, it is beacuse client side meant the command to be synchronous 
       
   763     // but the extension implementation wants to turn that asynchronous. 
       
   764     // either client side should request the command asynchronously, of server side implementation should complete 
       
   765     // the message synchronously    
       
   766     ASSERT(iData->iMessages[0]->iClientId);
       
   767     
       
   768     if (iData->iMessages.Count() && !iData->iMessages[0]->iIsAsync )
       
   769         {
       
   770         iData->iMessages[0]->iIsAsync = ETrue; 
       
   771         }
       
   772         
       
   773     return iData->iMessages[0]->iClientId;
       
   774     }
       
   775 
       
   776 // ---------------------------------------------------------------------------
       
   777 // 
       
   778 // ---------------------------------------------------------------------------
       
   779 // 
       
   780 EXPORT_C void CAlfAppSrvSessionBase::CompleteCmd(TInt aCommandId, TInt aResult)
       
   781     {
       
   782     if (iData->iMessages.Count() == 0)
       
   783         {
       
   784         return; // we could leave instead..
       
   785         }
       
   786         
       
   787     if (aCommandId == 0) // subsession default 
       
   788         {
       
   789         if (aResult != KErrNone || !iData->iMessages[0]->iIsAsync) 
       
   790             {
       
   791             iData->iMessages[0]->CompleteMessageD(aResult);
       
   792             iData->iMessages.Remove(0);
       
   793             }
       
   794 
       
   795         return;
       
   796         }
       
   797 
       
   798     TInt index = iData->iMessages.Find(aCommandId, CAlfClientMessage::Compare);
       
   799     
       
   800     if  (index != KErrNotFound)   
       
   801         {
       
   802         iData->iMessages[index]->CompleteMessageD(aResult);
       
   803         iData->iMessages.Remove(index);
       
   804         }
       
   805     }
       
   806 
       
   807 // ---------------------------------------------------------------------------
       
   808 // 
       
   809 // ---------------------------------------------------------------------------
       
   810 // 
       
   811 void CAlfAppSrvSessionBase::HandleEventL(TAny* aCtrlPtr, TAny* aVisualPtr, const THuiEvent& aEvent)
       
   812     {
       
   813     // resolve ctrl client handle
       
   814     switch(iData->iPtrEventState)
       
   815         {
       
   816         case CAlfAppSrvSessionBase::TPrivateData::EStartNewEvent:
       
   817             {
       
   818             const TAlfTouchEventS touchEvent( aEvent );      
       
   819             
       
   820             // Purge drag events that come in sequence, because the client cannot handle all in time.    
       
   821             if ( touchEvent.iEvent.iType == TPointerEvent::EDrag )
       
   822                 {
       
   823                 while ( iData->iHuiEvents.Count() && 
       
   824                         iData->iHuiEvents[0].iEvent.iType == TPointerEvent::EDrag )
       
   825                     {
       
   826                     iData->iHuiEvents.Remove(0);
       
   827                     }
       
   828                 }
       
   829             
       
   830             iData->iHuiEvents.InsertL(touchEvent,0);            
       
   831             iData->iPtrEventState = CAlfAppSrvSessionBase::TPrivateData::EUpdateCtrls;
       
   832             } // fall through
       
   833         case CAlfAppSrvSessionBase::TPrivateData::EUpdateCtrls:
       
   834             {
       
   835             TInt controlHandle = GetHandleFromInterface(EHuiObjectTypeControl, aCtrlPtr);
       
   836             ASSERT(controlHandle != KErrNotFound); // panic at will
       
   837             
       
   838             TInt visualHandle = 0;
       
   839             if (aVisualPtr)
       
   840                 {
       
   841                 visualHandle = GetHandleFromInterface(EHuiObjectTypeVisual, aVisualPtr);
       
   842                 ASSERT(visualHandle != KErrNotFound);
       
   843                 }
       
   844             iData->iHuiEvents[0].AppendCtrl(controlHandle, visualHandle);
       
   845             }
       
   846             break;
       
   847         default: // don't do anything unless focused and initialized
       
   848             break;
       
   849         }
       
   850     }
       
   851 
       
   852 // ---------------------------------------------------------------------------
       
   853 // 
       
   854 // ---------------------------------------------------------------------------
       
   855 // 
       
   856 void CAlfAppSrvSessionBase::StartPointerHandling()
       
   857     {
       
   858     if (iData->iPtrEventState != CAlfAppSrvSessionBase::TPrivateData::ENotInitialized)
       
   859         {
       
   860         iData->iPtrEventState = CAlfAppSrvSessionBase::TPrivateData::EStartNewEvent;
       
   861         }
       
   862     }
       
   863 
       
   864 // ---------------------------------------------------------------------------
       
   865 // 
       
   866 // ---------------------------------------------------------------------------
       
   867 // 
       
   868 void CAlfAppSrvSessionBase::FlushPointerHandling()
       
   869     {
       
   870     if (iData->iPtrEventState != CAlfAppSrvSessionBase::TPrivateData::ENotInitialized)
       
   871         {
       
   872         iData->iPtrEventState = CAlfAppSrvSessionBase::TPrivateData::ENotFocused;
       
   873         if (iData->iHuiEvents.Count() == 1) // manually trigger the event queue if only one item
       
   874             {
       
   875             TriggerPointerEvent(0);
       
   876             }
       
   877         }
       
   878     }
       
   879 
       
   880 // ---------------------------------------------------------------------------
       
   881 // 
       
   882 // ---------------------------------------------------------------------------
       
   883 // 
       
   884 void CAlfAppSrvSessionBase::TriggerPointerEvent(const RMessage2* aMessage)
       
   885     {
       
   886     if (aMessage)
       
   887     	{ 	
       
   888      	if (iData->iPointerEvent.IsNull())
       
   889         	{
       
   890         	iData->iPtrEventState = CAlfAppSrvSessionBase::TPrivateData::ENotFocused; // ensure that state machine gets running 
       
   891         	iData->iPointerEvent = *aMessage;
       
   892         
       
   893         	// Reset cpu time to the correct value
       
   894         	TUint maxCpuUsage = AlfAppUi()->SettingsHandler().MaxCpuUsage();
       
   895    			SharedHuiEnv()->SetMaxCpuTime(maxCpuUsage);
       
   896         	}
       
   897         else
       
   898         	{
       
   899         	// There is already message waiting. Complete this with an error, and proceed with existing message.
       
   900         	aMessage->Complete(KErrInUse);
       
   901         	}
       
   902     	}
       
   903     else if (iData->iPointerEvent.IsNull())
       
   904         {
       
   905     	// Server is calling this internally and client is not ready.
       
   906         // Take cpu time from rendering to give more time to event handling, both in server and client.
       
   907    		SharedHuiEnv()->SetMaxCpuTime(KAlfMaxCpuUsageDuringPointerEvent);
       
   908         }
       
   909         
       
   910     if (!iData->iPointerEvent.IsNull() 
       
   911         && (iData->iHuiEvents.Count() > 1 
       
   912             || (iData->iHuiEvents.Count() == 1 && iData->iPtrEventState == CAlfAppSrvSessionBase::TPrivateData::ENotFocused )))
       
   913         {
       
   914         TPckg<TAlfTouchEventS> buf(iData->iHuiEvents[iData->iHuiEvents.Count()-1]);
       
   915         TInt error = iData->iPointerEvent.Write(0,buf);
       
   916         if ( error != KErrNone )
       
   917             {
       
   918             __ALFLOGSTRING1( "CAlfAppSrvSessionBase::TriggerPointerEvent: write error: %d", error )
       
   919             }
       
   920         iData->iPointerEvent.Complete(error);        
       
   921         iData->iHuiEvents.Remove(iData->iHuiEvents.Count()-1);
       
   922         }
       
   923     }
       
   924 
       
   925 // ---------------------------------------------------------------------------
       
   926 // 
       
   927 // ---------------------------------------------------------------------------
       
   928 // 
       
   929 void CAlfAppSrvSessionBase::CancelPointerEvents()
       
   930     {
       
   931     if (!iData->iPointerEvent.IsNull())
       
   932         {
       
   933         iData->iPointerEvent.Complete(KErrCancel);
       
   934         }
       
   935     }
       
   936 
       
   937 // ---------------------------------------------------------------------------
       
   938 // 
       
   939 // ---------------------------------------------------------------------------
       
   940 // 
       
   941 void CAlfAppSrvSessionBase::GetSystemEvents(const RMessage2* aMessage)
       
   942     {
       
   943     if (aMessage && iData->iSystemEvent.IsNull())
       
   944         {
       
   945         iData->iSystemEvent = *aMessage;
       
   946         }
       
   947     else 
       
   948         {
       
   949 	    __ASSERT_DEBUG(aMessage, USER_INVARIANT());
       
   950         aMessage->Complete(KErrInUse);
       
   951         }
       
   952         
       
   953     }
       
   954 
       
   955 // ---------------------------------------------------------------------------
       
   956 // 
       
   957 // ---------------------------------------------------------------------------
       
   958 // 
       
   959 void CAlfAppSrvSessionBase::TriggerSystemEvent(TInt aEvent)
       
   960     {
       
   961     if (!iData->iSystemEvent.IsNull()) 
       
   962         {
       
   963         TPckg<TInt> eventPckg(aEvent);
       
   964         TInt error = iData->iSystemEvent.Write(0,eventPckg);
       
   965         if ( error != KErrNone )
       
   966             {
       
   967             __ALFLOGSTRING1( "CAlfAppSrvSessionBase::TriggerSystemEvent: write error: %d", error )
       
   968             }
       
   969         iData->iSystemEvent.Complete(error);        
       
   970         }        
       
   971     }
       
   972 
       
   973 
       
   974 // ---------------------------------------------------------------------------
       
   975 // 
       
   976 // ---------------------------------------------------------------------------
       
   977 // 
       
   978 void CAlfAppSrvSessionBase::CancelSystemEvents()
       
   979     {
       
   980     if (!iData->iSystemEvent.IsNull())
       
   981         {
       
   982         iData->iSystemEvent.Complete(KErrCancel);
       
   983         }
       
   984     }
       
   985 
       
   986 // ---------------------------------------------------------------------------
       
   987 // 
       
   988 // ---------------------------------------------------------------------------
       
   989 //     
       
   990 void CAlfAppSrvSessionBase::GetSubsessionsByTypeL( 
       
   991     RPointerArray<CAlfSrvSubSessionBase>& aArray, 
       
   992     const THuiInterfaceSupport& aType )
       
   993     {
       
   994     aArray.Reset();
       
   995     
       
   996     for (TInt ii = iData->iHandles.Count()-1; ii >= 0; ii--)
       
   997         {
       
   998         const TInt handleitr = iData->iHandles[ii].iHandle;
       
   999         CAlfSrvSubSessionBase* subSession = &SubSession(handleitr);
       
  1000 
       
  1001         if ( FetchInterface( aType, subSession ) )
       
  1002             {
       
  1003             aArray.AppendL(subSession);
       
  1004             }
       
  1005         }
       
  1006     }
       
  1007 
       
  1008 // ---------------------------------------------------------------------------
       
  1009 // 
       
  1010 // ---------------------------------------------------------------------------
       
  1011 //     
       
  1012 EXPORT_C CAlfAppServer::TAlfWGPostion CAlfAppSrvSessionBase::PreferredWindowGroupPosition() const
       
  1013     {
       
  1014     return CAlfAppServer::EBehindOfParent;
       
  1015     }
       
  1016 
       
  1017   
       
  1018 // ---------------------------------------------------------------------------
       
  1019 // 
       
  1020 // ---------------------------------------------------------------------------
       
  1021 //    
       
  1022 EXPORT_C THuiRefreshMode CAlfAppSrvSessionBase::PreferredRefreshMode() const
       
  1023     {
       
  1024     return EHuiRefreshModeAutomatic;
       
  1025     }
       
  1026 
       
  1027 // ---------------------------------------------------------------------------
       
  1028 // Future proofing, just base call for now 
       
  1029 // ---------------------------------------------------------------------------
       
  1030 //     
       
  1031 EXPORT_C void CAlfAppSrvSessionBase::ServiceError(const RMessage2& aMessage,TInt aError)
       
  1032     {
       
  1033     CAknAppServiceBase::ServiceError(aMessage,aError);
       
  1034     }
       
  1035 
       
  1036 // ---------------------------------------------------------------------------
       
  1037 // Future proofing, just base call for now 
       
  1038 // ---------------------------------------------------------------------------
       
  1039 //     
       
  1040 EXPORT_C TInt CAlfAppSrvSessionBase::CountResources()
       
  1041     {
       
  1042     return CAknAppServiceBase::CountResources();
       
  1043     }
       
  1044 
       
  1045 
       
  1046 // ---------------------------------------------------------------------------
       
  1047 // Future proofing, just base call for now 
       
  1048 // ---------------------------------------------------------------------------
       
  1049 //     
       
  1050 EXPORT_C void CAlfAppSrvSessionBase::Disconnect(const RMessage2& aMessage)
       
  1051     {
       
  1052     CAknAppServiceBase::Disconnect(aMessage);
       
  1053     }
       
  1054 
       
  1055 // ---------------------------------------------------------------------------
       
  1056 // From CSession2. Future proofing, just base call for now 
       
  1057 // ---------------------------------------------------------------------------
       
  1058 //     
       
  1059 EXPORT_C TInt CAlfAppSrvSessionBase::Extension_(TUint aExtensionId, TAny*& a0, TAny* a1)
       
  1060     {
       
  1061     return CAknAppServiceBase::Extension_(aExtensionId,a0,a1);
       
  1062     }
       
  1063 
       
  1064 void CAlfAppSrvSessionBase::SetParentWindowGroupId(TInt aParentId)
       
  1065     {
       
  1066     iData->iParentId = aParentId;
       
  1067     }
       
  1068 
       
  1069 TInt CAlfAppSrvSessionBase::ParentWindowGroupId()
       
  1070     {
       
  1071     return iData->iParentId;
       
  1072     }
       
  1073 
       
  1074 void CAlfAppSrvSessionBase::ResetRootlayerTransformationsL()
       
  1075     {
       
  1076     RPointerArray<CAlfSrvSubSessionBase> groups;
       
  1077     CleanupClosePushL( groups );
       
  1078     GetSubsessionsByTypeL( groups, EHuiObjectTypeControlGroup );
       
  1079     for ( TInt g = 0 ; g < groups.Count() ; g++ )
       
  1080         {
       
  1081         CHuiControlGroup* group = groups[g]->AsHuiControlCroup();
       
  1082         ASSERT( group ); 
       
  1083         CHuiLayout* hostContainer = group->Control(0).ContainerLayout( NULL );
       
  1084         if (hostContainer)
       
  1085             {
       
  1086             hostContainer->EnableTransformationL(EFalse);
       
  1087             hostContainer->iOpacity.Set(1.f);
       
  1088             }
       
  1089         }
       
  1090     CleanupStack::PopAndDestroy();
       
  1091     }
       
  1092 
       
  1093 // RnD
       
  1094 void CAlfAppSrvSessionBase::ActivateContainerLayoutL(TBool aActivate)
       
  1095     {
       
  1096     if (iData->iActive != aActivate)
       
  1097         {
       
  1098         iData->iActive = aActivate;
       
  1099         RPointerArray<CAlfSrvSubSessionBase> groups;
       
  1100         CleanupClosePushL( groups );
       
  1101         GetSubsessionsByTypeL( groups, EHuiObjectTypeControlGroup );
       
  1102         for ( TInt g = 0 ; g < groups.Count() ; g++ )
       
  1103             {
       
  1104             CHuiControlGroup* group = groups[g]->AsHuiControlCroup();
       
  1105             ASSERT( group ); 
       
  1106             CHuiLayout* hostContainer = group->Control(0).ContainerLayout( NULL );
       
  1107             if (hostContainer)
       
  1108                 {
       
  1109                 if (aActivate)
       
  1110                     {
       
  1111                     hostContainer->ClearFlag(EHuiVisualFlagInactive);
       
  1112                     }
       
  1113                 else
       
  1114                     {
       
  1115                     hostContainer->SetFlag(EHuiVisualFlagInactive);
       
  1116                     }
       
  1117                 }
       
  1118             }
       
  1119         CleanupStack::PopAndDestroy();
       
  1120         }
       
  1121     }
       
  1122    
       
  1123 // End of file    
       
  1124