locationsystemui/locationsysui/privacyverifiernotifierui/locprivacyserver/src/locprivacyserversession.cpp
changeset 32 b12ea03c50a3
child 37 e175e2ba2fb0
equal deleted inserted replaced
25:73f6c2762ffe 32:b12ea03c50a3
       
     1 /*
       
     2 * Copyright (c) 2010 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 class implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <s32mem.h>
       
    20 #include <lbs/EPos_RPosRequestorStack.h>
       
    21 #include "locprivacyinternal.h" 
       
    22 #include "locprivacyserver.h"
       
    23 #include "locprivacyserversession.h"
       
    24 #include "locprivacyserverdebugpanic.h"
       
    25 #include "locrequestorutilsresolver.h"
       
    26 // CONSTANTS
       
    27 
       
    28 // ================= MEMBER FUNCTIONS =======================
       
    29 
       
    30 // Two-phased constructor
       
    31 CLocPrivacyServerSession* CLocPrivacyServerSession::NewL(
       
    32         CLocPrivacyServer& aServer)
       
    33     {
       
    34     CLocPrivacyServerSession* self = new (ELeave) CLocPrivacyServerSession();
       
    35     CleanupStack::PushL(self);
       
    36     self->ConstructL(aServer);
       
    37     CleanupStack::Pop();
       
    38     return self;
       
    39     }
       
    40 
       
    41 // Destructor
       
    42 CLocPrivacyServerSession::~CLocPrivacyServerSession()
       
    43     {
       
    44     CloseSession();
       
    45     delete iBufFlat;
       
    46     iBufFlat = NULL;
       
    47     }
       
    48 
       
    49 // C++ default constructor can NOT contain any code, that
       
    50 // might leave.
       
    51 //
       
    52 CLocPrivacyServerSession::CLocPrivacyServerSession() :
       
    53     CSession2(), iBufFlat(NULL)
       
    54     {
       
    55     // Doesn't really do anything according to the header file (e32def.h,
       
    56     // lines 139 and 184) and the documentation doesn't mention it.
       
    57     __DECLARE_NAME(_S("CLocPrivacyServerSession"));
       
    58     }
       
    59 
       
    60 // EPOC default constructor
       
    61 void CLocPrivacyServerSession::ConstructL(CLocPrivacyServer& aServer)
       
    62     {
       
    63     aServer.IncrementSessions();
       
    64     iBufFlat = CBufFlat::NewL(KPosBufFlatExpandSize);
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------
       
    68 // CLocPrivacyServerSession::ServiceL
       
    69 //
       
    70 // (other items were commented in a header).
       
    71 // ---------------------------------------------------------
       
    72 //
       
    73 void CLocPrivacyServerSession::ServiceL(const RMessage2& aMessage)
       
    74     {
       
    75     TRAPD(err, DispatchL(aMessage));
       
    76 
       
    77     aMessage.Complete(err);
       
    78 
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------
       
    82 // CLocPrivacyServerSession::CloseSession
       
    83 //
       
    84 // (other items were commented in a header).
       
    85 // ---------------------------------------------------------
       
    86 //
       
    87 void CLocPrivacyServerSession::CloseSession()
       
    88     {
       
    89     CLocPrivacyServer
       
    90             * server =
       
    91                     static_cast<CLocPrivacyServer*> (const_cast<CServer2*> (Server()));
       
    92     server->DecrementSessions(this);
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------
       
    96 // CLocPrivacyServerSession::DispatchL
       
    97 //
       
    98 // (other items were commented in a header).
       
    99 // ---------------------------------------------------------
       
   100 //
       
   101 void CLocPrivacyServerSession::DispatchL(const RMessage2& aMessage)
       
   102     {
       
   103     switch ( aMessage.Function() )
       
   104         {
       
   105         case ELocPrivacyGetSize:
       
   106             
       
   107            {
       
   108            TInt desLength=0;
       
   109            desLength = aMessage.GetDesLength( 1 );          
       
   110 
       
   111            CBufFlat* bufFlat1 = CBufFlat::NewL(desLength);
       
   112            CleanupStack::PushL(bufFlat1);
       
   113            bufFlat1->ResizeL(desLength);
       
   114            
       
   115            TPtr8 ptr(bufFlat1->Ptr(0));
       
   116            // Copy content to local buffer
       
   117            aMessage.ReadL(1, ptr);
       
   118 
       
   119            RBufReadStream readStream(*bufFlat1);
       
   120            CleanupClosePushL(readStream);
       
   121            
       
   122            RPosRequestorStack* requestors1 = new (ELeave) RPosRequestorStack;
       
   123            CleanupStack::PushL(requestors1);
       
   124             requestors1->InternalizeL(readStream);
       
   125 
       
   126             CLocRequestorUtilsResolver* res =
       
   127                     CLocRequestorUtilsResolver::NewL();
       
   128             CleanupStack::PushL(res);
       
   129 
       
   130             res->ResolveRequestorsL(*requestors1);
       
   131 
       
   132                
       
   133            // use data member buffer and externalize 
       
   134 
       
   135             RBufWriteStream writeStream;
       
   136             // Reset the buffer
       
   137             iBufFlat->Reset();
       
   138             writeStream.Open(*iBufFlat);
       
   139             CleanupClosePushL(writeStream);
       
   140 
       
   141             requestors1->ExternalizeL(writeStream);
       
   142             writeStream.CommitL();
       
   143 
       
   144             // Find the new size
       
   145 
       
   146             TInt newsize  = iBufFlat->Size();
       
   147 
       
   148             CleanupStack::PopAndDestroy(&writeStream);
       
   149             CleanupStack::PopAndDestroy(res);
       
   150             CleanupStack::PopAndDestroy(requestors1);
       
   151             CleanupStack::PopAndDestroy(&readStream);
       
   152             CleanupStack::PopAndDestroy(bufFlat1);
       
   153 
       
   154             // write back new size
       
   155             TPtr8 ptr1(reinterpret_cast<TUint8*> (&newsize),
       
   156                     sizeof(newsize), sizeof(newsize));
       
   157                   
       
   158             aMessage.WriteL(0, ptr1);
       
   159          	}     
       
   160             break;
       
   161 
       
   162         case ELocPrivacyResolve:
       
   163             {
       
   164             TPtr8 ptr2 = iBufFlat->Ptr(0);
       
   165             aMessage.WriteL(0, ptr2);
       
   166         	}
       
   167             break;
       
   168             
       
   169         default:
       
   170             aMessage.Panic(KLocPrivSrvDebugPanicCategory,
       
   171                     ELocPrivSrvPanicUnknownActivity);
       
   172             break;
       
   173         }
       
   174     }
       
   175 
       
   176 //  End of File