devicemgmtnotifications/dmdevdialogserver/src/dmdevicedialogsession.cpp
changeset 44 39aa16f3fdc2
equal deleted inserted replaced
43:c8e5c3d81b42 44:39aa16f3fdc2
       
     1 /*
       
     2  * Copyright (c) 2009 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: Implementation of DM Device Dialogs
       
    15  */
       
    16 
       
    17 #include "dmdevicedialogsession.h"
       
    18 #include "dmdevdialogclientserver.h"
       
    19 
       
    20 // ----------------------------------------------------------------------------------------
       
    21 // CDmDeviceDialogSession::CDmDeviceDialogSession
       
    22 // ----------------------------------------------------------------------------------------
       
    23 CDmDeviceDialogSession::CDmDeviceDialogSession()
       
    24     {    
       
    25     }
       
    26 
       
    27 // ----------------------------------------------------------------------------------------
       
    28 // CDmDeviceDialogSession::~CDmDeviceDialogSession
       
    29 // ----------------------------------------------------------------------------------------
       
    30 CDmDeviceDialogSession::~CDmDeviceDialogSession()
       
    31     {
       
    32     FLOG(_L("CDmDeviceDialogSession::~CDmDeviceDialogSession-- begin"));    
       
    33     if ( !Server().RequestPending() )
       
    34         {
       
    35         FLOG(_L("CDmDeviceDialogSession::~CDmDeviceDialogSession Stopserver"));
       
    36         Server().StopServer();
       
    37         }
       
    38     FLOG(_L("CDmDeviceDialogSession::~CDmDeviceDialogSession-- end"));
       
    39     }
       
    40 
       
    41 // ----------------------------------------------------------------------------------------
       
    42 // CDmDeviceDialogSession::Server
       
    43 // ----------------------------------------------------------------------------------------
       
    44 CDmDeviceDialogServer& CDmDeviceDialogSession::Server()
       
    45     {
       
    46     return *static_cast<CDmDeviceDialogServer*> (const_cast<CServer2*> (CSession2::Server()));
       
    47     }
       
    48 
       
    49 // ----------------------------------------------------------------------------------------
       
    50 // CDmDeviceDialogSession::CheckClientSecureIdL
       
    51 // ----------------------------------------------------------------------------------------
       
    52 TBool CDmDeviceDialogSession::CheckClientSecureId(const RMessage2& aMessage)
       
    53     {
       
    54     TUid fota = TUid::Uid(KFotaServerUid);
       
    55     TUid sosserver = TUid::Uid(KSosServerUid);
       
    56     TUid scomo = TUid::Uid(KScomoServerUid);
       
    57 
       
    58     // Fotaserver
       
    59     if (aMessage.SecureId() == fota.iUid)
       
    60         {
       
    61         FLOG(_L("[CDmDeviceDialogSession] CheckClientSecureId client is \
       
    62 		fotaserver!"));
       
    63         return ETrue;
       
    64         }
       
    65 
       
    66     // Sosserver
       
    67     else if (aMessage.SecureId() == sosserver.iUid)
       
    68         {
       
    69         FLOG(_L("[CDmDeviceDialogSession] CheckClientSecureId client is \
       
    70       sosserver!"));
       
    71         return ETrue;
       
    72         }
       
    73     // Scomoserver
       
    74         else if (aMessage.SecureId() == scomo.iUid)
       
    75             {
       
    76             FLOG(_L("[CDmDeviceDialogSession] CheckClientSecureId client is \
       
    77           SCOMO server!"));
       
    78             return ETrue;
       
    79             }
       
    80     // test app
       
    81     else if (aMessage.SecureId() == 0x102073E4)
       
    82         {
       
    83         FLOG(_L("[CDmDeviceDialogSession] CheckClientSecureId client is \
       
    84         testapp!"));
       
    85         return ETrue;
       
    86         }
       
    87     else
       
    88         {
       
    89         FLOG(_L("[CDmDeviceDialogSession] CheckClientSecureId client 0x%X is\
       
    90                  unknown (msg %d), bailing out"),
       
    91                 aMessage.SecureId().iId, aMessage.Function());        
       
    92         }
       
    93     return EFalse;
       
    94     }
       
    95 
       
    96 // ----------------------------------------------------------------------------------------
       
    97 // CDmDeviceDialogSession::ServiceL
       
    98 // ----------------------------------------------------------------------------------------
       
    99 void CDmDeviceDialogSession::ServiceL(const RMessage2& aMessage)
       
   100     {
       
   101     RThread clt;
       
   102     aMessage.ClientL(clt);
       
   103     TFullName cltnm = clt.FullName();
       
   104     FLOG(_L( "CDmDeviceDialogSession::ServiceL      %d   serving for %S?" ),
       
   105             aMessage.Function(), &cltnm);
       
   106     if (CheckClientSecureId(aMessage))
       
   107         {
       
   108         FLOG(_L( "CDmDeviceDialogSession::ServiceL access ok"));
       
   109 		Server().CancelServerCloseRequest();
       
   110 		if(!Server().IsPkgZeroNoteDisplaying() || aMessage.Function() == 
       
   111 		        ECancelServerAlert )
       
   112 		    {
       
   113             TRAPD(err,DispatchMessageL(aMessage));
       
   114             FLOG(_L( "CDmDeviceDialogSession::ServiceL err is %d"), err);
       
   115             User::LeaveIfError(err);
       
   116 		    }
       
   117 		else //User not responded to earlier package zero, so no other services 
       
   118 		    {
       
   119             FLOG(_L( "CDmDeviceDialogSession::ServiceL server is busy"));
       
   120             aMessage.Complete(KErrServerBusy);
       
   121 		    }        
       
   122         }
       
   123     else
       
   124         {
       
   125         FLOG(_L( "CDmDeviceDialogSession::ServiceL access denied"));
       
   126         aMessage.Complete(KErrAccessDenied);
       
   127         }
       
   128     }
       
   129 
       
   130 // ----------------------------------------------------------------------------------------
       
   131 // CDmDeviceDialogSession::ServiceError
       
   132 // ----------------------------------------------------------------------------------------
       
   133 void CDmDeviceDialogSession::ServiceError(const RMessage2& aMessage,
       
   134         TInt aError)
       
   135     {
       
   136     CSession2::ServiceError(aMessage, aError);
       
   137     }
       
   138 
       
   139 // ----------------------------------------------------------------------------------------
       
   140 // CDmDeviceDialogSession::DispatchMessageL
       
   141 // ----------------------------------------------------------------------------------------
       
   142 void CDmDeviceDialogSession::DispatchMessageL(const RMessage2& aMessage)
       
   143     {
       
   144     FLOG(_L("CDmDeviceDialogSession::DispatchMessageL-begin"));
       
   145     iMessage = aMessage;
       
   146     switch (aMessage.Function())
       
   147         {
       
   148         case EServerAlert:
       
   149             {
       
   150             FLOG(_L("CDmDeviceDialogSession::DispatchMessageL \
       
   151                      Server alert case:"));
       
   152             TInt Uimode = aMessage.Int2();
       
   153             if (Uimode == CDmDeviceDialogServer::ESANSilent)
       
   154                 aMessage.Complete(KErrNone);
       
   155             else
       
   156                 {
       
   157                 Server().NewAsyncRequest();
       
   158                 TInt ProfileId = aMessage.Int0();
       
   159                 TInt JobId = aMessage.Int1();
       
   160                 TInt ReplySlot = 3;
       
   161                 Server().LaunchPkgZeroNoteL(ProfileId, JobId, ReplySlot, Uimode,
       
   162                         iMessage);
       
   163                 }
       
   164             }
       
   165             break;
       
   166         case EPkgConnectNoteIsActive:
       
   167             {
       
   168             FLOG(_L("CDmDeviceDialogSession::DispatchMessageL EPkgZeroOngoing \
       
   169                      case:"));
       
   170             TBool ret = Server().IsConenctDialogDisplaying();
       
   171             TPckgBuf<TInt> callactive(ret);
       
   172             aMessage.WriteL(0, callactive);
       
   173             aMessage.Complete(KErrNone);
       
   174             }
       
   175             break;
       
   176         case EPkgZeroConnectNoteDismiss:
       
   177             {
       
   178             FLOG(_L("CDmDeviceDialogSession::DispatchMessageL \
       
   179                     EPkgZeroConnectNoteDismiss case:"));
       
   180             if (Server().IsConenctDialogDisplaying())
       
   181                 Server().DismissDialog();
       
   182             aMessage.Complete(KErrNone);
       
   183             }
       
   184             break;
       
   185         case EPkgZeroConnectNoteShowAgain:
       
   186             {
       
   187             FLOG(_L("CDmDeviceDialogSession::DispatchMessageL \
       
   188                     EPkgZeroConnectNoteShow case:"));
       
   189             if (!Server().IsConenctDialogDisplaying())
       
   190                 Server().ShowConnectDialogAgainL();
       
   191             aMessage.Complete(KErrNone);
       
   192             }
       
   193             break;
       
   194         case EShowDisplayAlert:
       
   195             {
       
   196             FLOG(_L("CDmDeviceDialogSession::DispatchMessageL \
       
   197                     EDisplayAlert case:"));	
       
   198             HBufC* alerttext = HBufC::NewLC(aMessage.GetDesLengthL(0));
       
   199             TPtr bufPtr = alerttext->Des();
       
   200             aMessage.ReadL(0, bufPtr, 0);
       
   201             Server().NewAsyncRequest();
       
   202             Server().ShowDisplayalertL(bufPtr, iMessage);
       
   203             CleanupStack::PopAndDestroy();             
       
   204             }
       
   205             break;
       
   206         case EShowConfirmationalert:
       
   207             {          
       
   208             HBufC* alerttext = HBufC::NewLC(aMessage.GetDesLengthL(2));
       
   209             TPtr alerttxtptr = alerttext->Des();
       
   210             aMessage.ReadL(2, alerttxtptr);
       
   211             HBufC* alertheader = HBufC::NewLC(aMessage.GetDesLengthL(1));
       
   212             TPtr alertheaderptr = alertheader->Des();
       
   213             aMessage.ReadL(1, alertheaderptr);
       
   214             Server().NewAsyncRequest();
       
   215             Server().ShowConfirmationalertL(aMessage.Int0(), alertheaderptr,
       
   216                     alerttxtptr, iMessage);
       
   217             CleanupStack::PopAndDestroy(2);
       
   218             }
       
   219             break;
       
   220         case ECancelServerAlert:
       
   221             {          
       
   222             Server().CancelPendingServerAlert();
       
   223             aMessage.Complete(KErrNone);
       
   224             }
       
   225             break;    
       
   226         default:
       
   227             {
       
   228             FLOG(_L("CDmDeviceDialogSession::DispatchMessageL default case: \
       
   229                     and a leave happened"));            
       
   230             User::Leave(KErrArgument);
       
   231             }
       
   232         }
       
   233     FLOG(_L("CDmDeviceDialogSession::DispatchMessageL:end"));
       
   234     }
       
   235 //End of file