phonebookui/Phonebook2/xSPExtensionManager/src/CxSPViewActivator.cpp
changeset 0 e686773b3f54
child 18 d4f567ce2e7c
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     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: 
       
    15 *       View activator - activates a tab view upon client request
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CxSPViewActivator.h"
       
    22 #include <CxSPViewData.h>
       
    23 #include "CxSPViewInfo.h"
       
    24 
       
    25 
       
    26 // System includes
       
    27 #include <aknViewAppUi.h>
       
    28 
       
    29 // Unnamed namespace for local definitions
       
    30 namespace
       
    31     {
       
    32     const TInt KDesAddressParam = 2; // Des address is in param ix 2
       
    33     _LIT( KPanicText, "xSPViewActivator" );
       
    34     
       
    35     enum TPanicCode
       
    36         {
       
    37         EBadDescriptorLength,
       
    38         EBadDescriptor
       
    39         };
       
    40     } // namespace
       
    41 
       
    42 // ================= MEMBER FUNCTIONS =======================
       
    43 
       
    44 CxSPViewActivator* CxSPViewActivator::NewL(CxSPViewIdChanger* aViewIdChanger)
       
    45     {
       
    46     CxSPViewActivator* self = new(ELeave) CxSPViewActivator(aViewIdChanger);
       
    47 
       
    48     CleanupStack::PushL(self);
       
    49     self->ConstructL();
       
    50     CleanupStack::Pop();    // self
       
    51 
       
    52     return self;
       
    53     }
       
    54 
       
    55 CxSPViewActivator::CxSPViewActivator(CxSPViewIdChanger* aViewIdChanger) : 
       
    56                                                 CServer2(EPriorityStandard)
       
    57     {
       
    58     iViewIdChanger = aViewIdChanger;
       
    59     }
       
    60 
       
    61 void CxSPViewActivator::ConstructL()
       
    62     {
       
    63     StartL(KxSPServer);
       
    64     }
       
    65 
       
    66 CxSPViewActivator::~CxSPViewActivator()
       
    67     {
       
    68     }
       
    69 
       
    70 CSession2* CxSPViewActivator::NewSessionL(const TVersion& aVersion, const RMessage2&) const
       
    71     {
       
    72     TBool supported = User::QueryVersionSupported(TVersion(KxSPViewServerMajor,
       
    73                                                     KxSPViewServerMinor,
       
    74                                                     KxSPViewServerBuild),
       
    75                                                     aVersion);
       
    76     if(!supported)
       
    77         {
       
    78         User::Leave(KErrNotSupported);
       
    79         }
       
    80 
       
    81     return new (ELeave) CxSPViewActivatorSession();
       
    82     }
       
    83 
       
    84 void CxSPViewActivator::ActivateView1L(const RMessage2 &aMessage)
       
    85     {
       
    86     TUint32 ecomID = aMessage.Int0();
       
    87     TUint32 viewID = aMessage.Int1();
       
    88 
       
    89     TInt err = KErrNone;
       
    90     TInt newViewId;
       
    91     if(ecomID)
       
    92         {
       
    93         err = iViewIdChanger->GetNewView(ecomID, viewID, newViewId);
       
    94         }
       
    95     else
       
    96         {
       
    97         newViewId = viewID;
       
    98         }
       
    99 
       
   100     aMessage.Complete(err);
       
   101 
       
   102     if(err == KErrNone)
       
   103         {
       
   104         // Activate the view
       
   105         static_cast<CAknViewAppUi*>(CCoeEnv::Static()->AppUi())->ActivateLocalViewL(
       
   106                                                                 TUid::Uid((TInt)newViewId));
       
   107         }
       
   108 
       
   109     return;
       
   110     }
       
   111 
       
   112 void CxSPViewActivator::ActivateView2L(const RMessage2 &aMessage)
       
   113     {
       
   114     TInt err = KErrNone;
       
   115 
       
   116     TUint32 ecomID = aMessage.Int0();
       
   117     TUint32 viewID = aMessage.Int1();
       
   118     TInt desLen = aMessage.GetDesLength(KDesAddressParam);
       
   119     if( desLen <= 0 )
       
   120         {
       
   121         aMessage.Panic( KPanicText, EBadDescriptorLength );
       
   122         }
       
   123     else
       
   124         {
       
   125         HBufC8* paramBuf = HBufC8::NewL(desLen);
       
   126         CleanupStack::PushL(paramBuf);
       
   127         TPtr8 ptr = paramBuf->Des();
       
   128         aMessage.ReadL(KDesAddressParam, ptr);
       
   129     
       
   130         TInt newViewId;
       
   131         if(ecomID)
       
   132             {
       
   133             err = iViewIdChanger->GetNewView(ecomID, viewID, newViewId);
       
   134             }
       
   135         else
       
   136             {
       
   137             newViewId = viewID;
       
   138             }
       
   139     
       
   140         aMessage.Complete(err);
       
   141     
       
   142         if(err == KErrNone)
       
   143             {
       
   144             // Make view id
       
   145             const TVwsViewId viewId(TUid::Uid(KUid), TUid::Uid(newViewId));
       
   146             // Activate the view
       
   147             static_cast<CAknViewAppUi*>(CCoeEnv::Static()->AppUi())->ActivateViewL(
       
   148                                                         viewId, CPbk2ViewState::Uid(), *paramBuf);
       
   149             }
       
   150     
       
   151         CleanupStack::PopAndDestroy();  // paramBuf;
       
   152         }
       
   153     }
       
   154 
       
   155 void CxSPViewActivator::ActivateView2AsyncL(const RMessage2 &aMessage)
       
   156     {
       
   157     TInt err = KErrNone;
       
   158 
       
   159     TUint32 ecomID = aMessage.Int0();
       
   160     TUint32 viewID = aMessage.Int1();
       
   161     TInt desLen = aMessage.GetDesLength(KDesAddressParam);
       
   162     if( desLen <= 0 )
       
   163         {
       
   164         aMessage.Panic( KPanicText, EBadDescriptorLength );
       
   165         }
       
   166     else
       
   167         {
       
   168         HBufC8* paramBuf = HBufC8::NewL(desLen);
       
   169         CleanupStack::PushL(paramBuf);
       
   170         TPtr8 ptr = paramBuf->Des();
       
   171         aMessage.ReadL(KDesAddressParam, ptr);
       
   172     
       
   173         TInt newViewId;
       
   174         if(ecomID)
       
   175             {
       
   176             err = iViewIdChanger->GetNewView(ecomID, viewID, newViewId);
       
   177             }
       
   178         else
       
   179             {
       
   180             newViewId = viewID;
       
   181             }
       
   182     
       
   183         aMessage.Complete(err);
       
   184     
       
   185         if(err == KErrNone)
       
   186             {
       
   187             // Make view id
       
   188             const TVwsViewId viewId(TUid::Uid(KUid), TUid::Uid(newViewId));
       
   189             // Activate the view
       
   190             static_cast<CAknViewAppUi*>(CCoeEnv::Static()->AppUi())->ActivateViewL(
       
   191                                                         viewId, CPbk2ViewState::Uid(), *paramBuf);
       
   192             }
       
   193     
       
   194         CleanupStack::PopAndDestroy();  // paramBuf;
       
   195         }
       
   196 
       
   197     }
       
   198     
       
   199 void CxSPViewActivator::GetViewCountL(const RMessage2 &aMessage)
       
   200     {
       
   201     TInt tabsCount;
       
   202     TInt dummy;
       
   203     iViewIdChanger->GetViewCount( tabsCount, dummy );   
       
   204     TPckgC<TInt> tabsCountDes( tabsCount );
       
   205     TRAPD( err, aMessage.WriteL( 0, tabsCountDes ) );
       
   206     if( err != KErrNone )
       
   207         {
       
   208         aMessage.Panic( KPanicText, EBadDescriptor );
       
   209         User::Leave( err );
       
   210         }
       
   211     else
       
   212         {
       
   213         aMessage.Complete( KErrNone );
       
   214         }
       
   215     }
       
   216         
       
   217 void CxSPViewActivator::GetViewDataPackLengthL(const RMessage2 &aMessage)
       
   218     {
       
   219     TInt index = aMessage.Int0();
       
   220     TInt tabsCount;
       
   221     TInt dummy;
       
   222     iViewIdChanger->GetViewCount( tabsCount, dummy );
       
   223     if( index < 0 )
       
   224         {
       
   225         aMessage.Complete( KErrUnderflow );
       
   226         }
       
   227     else if( index >= tabsCount )
       
   228         {
       
   229         aMessage.Complete( KErrOverflow );
       
   230         }
       
   231     else
       
   232         {
       
   233         RPointerArray<CxSPViewInfo> infoArray;
       
   234         CleanupClosePushL( infoArray );
       
   235         iViewIdChanger->GetTabViewInfoL( infoArray );
       
   236         const CxSPViewInfo& info = *infoArray[index];
       
   237         CxSPViewData* viewData = CxSPViewData::NewL();
       
   238         CleanupStack::PushL( viewData );
       
   239         viewData->SetEComId( info.Id() );
       
   240         viewData->SetOriginalViewId( info.OldViewId() );
       
   241         viewData->SetIconId( info.SortIconId() );
       
   242         viewData->SetMaskId( info.SortMaskId() );
       
   243         viewData->SetIconFileL( info.SortIconFile() );
       
   244         viewData->SetViewNameL( info.Name() );
       
   245         HBufC8* packed = viewData->PackL();
       
   246         TInt length = packed->Length();
       
   247         delete packed;                      
       
   248         CleanupStack::PopAndDestroy(); // viewData
       
   249         CleanupStack::PopAndDestroy(); // infoArray     
       
   250         TPckgC<TInt> lengthDes( length );
       
   251         TRAPD( err, aMessage.WriteL( 1, lengthDes ) );
       
   252         if( err != KErrNone )
       
   253             {
       
   254             aMessage.Panic( KPanicText, EBadDescriptor );
       
   255             User::Leave( err );
       
   256             }
       
   257         else
       
   258             {
       
   259             aMessage.Complete( KErrNone );
       
   260             }
       
   261         }   
       
   262     }
       
   263         
       
   264 void CxSPViewActivator::GetViewDataL(const RMessage2 &aMessage)
       
   265     {
       
   266     TInt index = aMessage.Int0();
       
   267     TInt tabsCount;
       
   268     TInt dummy;
       
   269     iViewIdChanger->GetViewCount( tabsCount, dummy );
       
   270     if( index < 0 )
       
   271         {
       
   272         aMessage.Complete( KErrUnderflow );
       
   273         }
       
   274     else if( index >= tabsCount )
       
   275         {
       
   276         aMessage.Complete( KErrOverflow );
       
   277         }
       
   278     else
       
   279         {
       
   280         RPointerArray<CxSPViewInfo> infoArray;
       
   281         CleanupClosePushL( infoArray );
       
   282         iViewIdChanger->GetTabViewInfoL( infoArray );
       
   283         const CxSPViewInfo& info = *infoArray[index];
       
   284         CxSPViewData* viewData = CxSPViewData::NewL();
       
   285         CleanupStack::PushL( viewData );
       
   286         viewData->SetEComId( info.Id() );
       
   287         viewData->SetOriginalViewId( info.OldViewId() );
       
   288         viewData->SetIconId( info.SortIconId() );
       
   289         viewData->SetMaskId( info.SortMaskId() );
       
   290         viewData->SetIconFileL( info.SortIconFile() );
       
   291         viewData->SetViewNameL( info.Name() );
       
   292         HBufC8* packed = viewData->PackL();
       
   293         CleanupStack::PushL( packed );      
       
   294         TRAPD( err, aMessage.WriteL( 1, *packed ) );
       
   295         if( err != KErrNone )
       
   296             {
       
   297             aMessage.Panic( KPanicText, EBadDescriptor );
       
   298             User::Leave( err );
       
   299             }
       
   300         else
       
   301             {
       
   302             aMessage.Complete( KErrNone );
       
   303             }
       
   304         CleanupStack::PopAndDestroy(); // packed                    
       
   305         CleanupStack::PopAndDestroy(); // viewData
       
   306         CleanupStack::PopAndDestroy(); // infoArray     
       
   307         }   
       
   308     }
       
   309            
       
   310 void CxSPViewActivator::StartL(const TDesC &aName)
       
   311     {
       
   312     CServer2::StartL(aName);
       
   313 
       
   314     RSemaphore semaphore;
       
   315     if(semaphore.OpenGlobal(KxSPServer) == KErrNone)
       
   316         {
       
   317         semaphore.Signal();
       
   318         semaphore.Close();
       
   319         }
       
   320     }
       
   321 
       
   322 void CxSPViewActivatorSession::ServiceL(const RMessage2 &aMessage)
       
   323     {
       
   324     // There are currently separate synchronous and asynchronous op codes for
       
   325     // some of the services. The server side implementation is however
       
   326     // synchronous and the opcodes are handled similarily whenever possible.
       
   327     // For example EGetViewCount and EGetViewCountAsync are treated identically
       
   328     // and the corresponding async cancel operation (ECancelGetViewCountAsync)
       
   329     // does nothing and completes immediately.
       
   330 
       
   331     switch(aMessage.Function())
       
   332         {
       
   333         case EActivateView1:
       
   334             ((CxSPViewActivator*)Server())->ActivateView1L(aMessage);
       
   335             break;
       
   336         case EActivateView2:
       
   337             ((CxSPViewActivator*)Server())->ActivateView2L(aMessage);
       
   338             break;
       
   339         case EActivateView2Async:
       
   340             ((CxSPViewActivator*)Server())->ActivateView2AsyncL( aMessage );
       
   341             break;            
       
   342         case EGetViewCount: // FALLTHROUGH
       
   343         case EGetViewCountAsync:
       
   344             ((CxSPViewActivator*)Server())->GetViewCountL(aMessage);
       
   345             break;
       
   346         case ECancelGetViewCountAsync:
       
   347             aMessage.Complete( KErrNone );
       
   348             break;
       
   349         case EGetViewDataPackLength:
       
   350             ((CxSPViewActivator*)Server())->GetViewDataPackLengthL(aMessage);
       
   351             break;
       
   352         case EGetViewDataPackLengthAsync:
       
   353             ((CxSPViewActivator*)Server())->GetViewDataPackLengthL( aMessage );
       
   354             break;
       
   355         case ECancelGetViewDataPackLengthAsync:
       
   356             aMessage.Complete( KErrNone );               
       
   357             break;                                                                            
       
   358         case EGetViewData:
       
   359             ((CxSPViewActivator*)Server())->GetViewDataL(aMessage);
       
   360             break;
       
   361         case EGetViewDataAsync:
       
   362             ((CxSPViewActivator*)Server())->GetViewDataL( aMessage );
       
   363             break;
       
   364         case ECancelActivateView2Async:
       
   365             aMessage.Complete( KErrNone );
       
   366             break;
       
   367         case ECancelGetViewDataAsync:
       
   368             aMessage.Complete( KErrNone );
       
   369             break;
       
   370         default:
       
   371             aMessage.Complete(KErrNotSupported);
       
   372         }
       
   373     }
       
   374         
       
   375 // End of file.