locationsystemui/locationsysui/queryandnotification/src/EPos_CPosPrivacyNotifierExtension.cpp
changeset 18 3825cf2dc8c2
child 20 82ee1f804b63
equal deleted inserted replaced
1:788b770ce3ae 18:3825cf2dc8c2
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <s32mem.h>
       
    22 #include <lbs/epos_privacy.h>
       
    23 #include <lbs/epos_cposrequestor.h>
       
    24 #include "EPos_CPosPrivacyNotifierExtension.h"
       
    25 #include "EPos_CPosRequestHandler.h"
       
    26 
       
    27 // ================= MEMBER FUNCTIONS =======================
       
    28 
       
    29 // C++ default constructor can NOT contain any code, that
       
    30 // might leave.
       
    31 //
       
    32 CPosPrivacyNotifierExtension::CPosPrivacyNotifierExtension()
       
    33     {
       
    34     }
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CPosPrivacyNotifierExtension::ConstructL
       
    38 // Symbian 2nd phase constructor can leave.
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 void CPosPrivacyNotifierExtension::ConstructL(
       
    42     CPosPrivacyNotifier* aPrivNotifier)
       
    43     {
       
    44     iRequestHandler = CPosRequestHandler::NewL(aPrivNotifier, this);
       
    45     iPrivacyNotifier = aPrivNotifier;
       
    46     ResetData();
       
    47     }
       
    48 
       
    49 // Two-phased constructor
       
    50 CPosPrivacyNotifierExtension* CPosPrivacyNotifierExtension::NewL(
       
    51     CPosPrivacyNotifier* aPrivNotifier)
       
    52     {
       
    53     CPosPrivacyNotifierExtension* self = new (ELeave)
       
    54         CPosPrivacyNotifierExtension;
       
    55     CleanupStack::PushL(self);
       
    56     self->ConstructL(aPrivNotifier);
       
    57     CleanupStack::Pop(self);
       
    58     return self;
       
    59     }
       
    60 
       
    61 // Destructor
       
    62 CPosPrivacyNotifierExtension::~CPosPrivacyNotifierExtension()
       
    63     {
       
    64     iRequestorStack.ResetAndDestroy();
       
    65     iRequestArray.Close();
       
    66     delete iRequestHandler;
       
    67     }
       
    68 
       
    69 // ---------------------------------------------------------
       
    70 // CPosPrivacyNotifierExtension::Find
       
    71 //
       
    72 // (other items were commented in a header).
       
    73 // ---------------------------------------------------------
       
    74 //
       
    75 TInt CPosPrivacyNotifierExtension::Find(TPosQNRequestId aRequestId) const
       
    76     {
       
    77     for (TInt index = 0; index < iRequestArray.Count(); index++)
       
    78         {
       
    79         if (iRequestArray[index].iId == aRequestId)
       
    80             {
       
    81             return index;
       
    82             }
       
    83         }
       
    84     return KErrNotFound;
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------
       
    88 // CPosPrivacyNotifierExtension::ResetData
       
    89 //
       
    90 // (other items were commented in a header).
       
    91 // ---------------------------------------------------------
       
    92 //
       
    93 void CPosPrivacyNotifierExtension::ResetData()
       
    94     {
       
    95     iRequestorStack.ResetAndDestroy();
       
    96     iCurrentRequestId = KPosNullQNRequestId;
       
    97     }
       
    98 
       
    99 // ---------------------------------------------------------
       
   100 // CPosPrivacyNotifierExtension::RemoveRequestFromArray
       
   101 //
       
   102 // (other items were commented in a header).
       
   103 // ---------------------------------------------------------
       
   104 //
       
   105 TInt CPosPrivacyNotifierExtension::RemoveRequestFromArray(
       
   106     TPosQNRequestId aRequestId)
       
   107     {
       
   108     TInt index = Find(aRequestId);
       
   109     if (index == KErrNotFound)
       
   110         {
       
   111         return KErrNotFound;
       
   112         }
       
   113 
       
   114     iRequestArray.Remove(index);
       
   115     return index;
       
   116     }
       
   117 
       
   118 // ---------------------------------------------------------
       
   119 // CPosPrivacyNotifierExtension::PrepareL
       
   120 //
       
   121 // (other items were commented in a header).
       
   122 // ---------------------------------------------------------
       
   123 //
       
   124 void CPosPrivacyNotifierExtension::PrepareL(
       
   125     TPosQNRequestId aRequestId)
       
   126     {
       
   127     TInt index = Find(aRequestId);
       
   128     __ASSERT_ALWAYS(index != KErrNotFound, User::Leave(KErrNotFound));
       
   129 
       
   130     iCurrentRequestId = aRequestId;
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------
       
   134 // CPosPrivacyNotifierExtension::CompleteRequest
       
   135 //
       
   136 // (other items were commented in a header).
       
   137 // ---------------------------------------------------------
       
   138 //
       
   139 void CPosPrivacyNotifierExtension::CompleteRequest(
       
   140     TPosQNRequestId aRequestId,
       
   141     TInt aCompletionCode)
       
   142     {
       
   143     TInt index = Find(aRequestId);
       
   144     if (index != KErrNotFound)
       
   145         {
       
   146         if (iRequestArray[index].iType == TPosQNInputData::EQuery)
       
   147             {
       
   148             // A verification request and the requestor is expecting a response
       
   149             iMessage.Complete(aCompletionCode);
       
   150             }
       
   151         else
       
   152             {
       
   153             // Intentionally empty. The request was for displaying a notification
       
   154             // The requestor is not expecting a response
       
   155             }
       
   156 
       
   157         iRequestArray.Remove(index);
       
   158         ResetData();
       
   159         }
       
   160     }
       
   161 
       
   162 // ---------------------------------------------------------
       
   163 // CPosPrivacyNotifierExtension::CompleteAllRequests
       
   164 //
       
   165 // (other items were commented in a header).
       
   166 // ---------------------------------------------------------
       
   167 //
       
   168 void CPosPrivacyNotifierExtension::CompleteAllRequests(TInt aCompletionCode)
       
   169     {
       
   170     CompleteRequest(iCurrentRequestId, aCompletionCode);
       
   171     }
       
   172 
       
   173 // ---------------------------------------------------------
       
   174 // CPosPrivacyNotifierExtension::Release
       
   175 //
       
   176 // (other items were commented in a header).
       
   177 // ---------------------------------------------------------
       
   178 //
       
   179 void CPosPrivacyNotifierExtension::Release()
       
   180     {
       
   181     delete iPrivacyNotifier;
       
   182     iPrivacyNotifier = NULL;
       
   183     }
       
   184 
       
   185 // ---------------------------------------------------------
       
   186 // CPosPrivacyNotifierExtension::RegisterL
       
   187 //
       
   188 // (other items were commented in a header).
       
   189 // ---------------------------------------------------------
       
   190 //
       
   191 CPosPrivacyNotifierExtension::TNotifierInfo
       
   192     CPosPrivacyNotifierExtension::RegisterL()
       
   193     {
       
   194     return iNotifierInfo;
       
   195     }
       
   196 
       
   197 // ---------------------------------------------------------
       
   198 // CPosPrivacyNotifierExtension::Info
       
   199 //
       
   200 // (other items were commented in a header).
       
   201 // ---------------------------------------------------------
       
   202 //
       
   203 CPosPrivacyNotifierExtension::TNotifierInfo
       
   204     CPosPrivacyNotifierExtension::Info() const
       
   205     {
       
   206     return iNotifierInfo;
       
   207     }
       
   208 
       
   209 // ---------------------------------------------------------
       
   210 // CPosPrivacyNotifierExtension::StartL
       
   211 //
       
   212 // (other items were commented in a header).
       
   213 // ---------------------------------------------------------
       
   214 //
       
   215 TPtrC8 CPosPrivacyNotifierExtension::StartL(const TDesC8& /*aBuffer*/)
       
   216     {
       
   217     return TPtrC8();
       
   218     }
       
   219 
       
   220 // ---------------------------------------------------------
       
   221 // CPosPrivacyNotifierExtension::StartL
       
   222 //
       
   223 // (other items were commented in a header).
       
   224 // ---------------------------------------------------------
       
   225 //
       
   226 void CPosPrivacyNotifierExtension::StartL(
       
   227     const TDesC8& /*aBuffer*/,
       
   228     TInt /*aReplySlot*/,
       
   229     const RMessagePtr2& aMessage)
       
   230     {
       
   231     iMessage = aMessage;
       
   232     }
       
   233 
       
   234 // ---------------------------------------------------------
       
   235 // CPosPrivacyNotifierExtension::Cancel
       
   236 //
       
   237 // (other items were commented in a header).
       
   238 // ---------------------------------------------------------
       
   239 //
       
   240 void CPosPrivacyNotifierExtension::Cancel()
       
   241     {
       
   242     if (iRequestArray.Count() > 0)
       
   243         {
       
   244         TPosQNRequestId reqId = iRequestArray[0].iId;
       
   245         iPrivacyNotifier->HandleRequestCancelled(reqId);
       
   246         CompleteRequest(reqId, KErrCancel);
       
   247         }
       
   248     }
       
   249 
       
   250 // ---------------------------------------------------------
       
   251 // CPosPrivacyNotifierExtension::UpdateL
       
   252 //
       
   253 // (other items were commented in a header).
       
   254 // ---------------------------------------------------------
       
   255 //
       
   256 TPtrC8 CPosPrivacyNotifierExtension::UpdateL(const TDesC8& aBuffer)
       
   257     {
       
   258     TPtrC8 tposQnData = aBuffer.Left(KPosQNInputDataClassSize);
       
   259 
       
   260     TPckgBuf<TPosQNInputData> input;
       
   261     input.Copy(tposQnData);
       
   262     TPosQNInputData update = input();
       
   263 
       
   264     TInt index = Find(update.iId);
       
   265     if (update.iCancelReason == EPosCancelReasonNotAvailable || 
       
   266         (update.iCancelReason == EPosCancelReasonTimeout && 
       
   267         update.iNotificationReason == EPosVerificationTimeout) )
       
   268         {
       
   269         HBufC8* buf = HBufC8::NewLC(update.iDataSize);
       
   270         TPtrC8 bufPtr = aBuffer.Mid(KPosQNInputDataClassSize);
       
   271 
       
   272         RDesReadStream stream(bufPtr);
       
   273         CleanupClosePushL(stream);
       
   274         iRequestorStack.InternalizeL(stream);
       
   275         CleanupStack::PopAndDestroy(2, buf); //buf, stream
       
   276 
       
   277         User::LeaveIfError(iRequestArray.Append(update));
       
   278         iRequestHandler->ScheduleRequest(update);
       
   279         }
       
   280     else
       
   281         {
       
   282         if (index == KErrNotFound)
       
   283             {
       
   284             User::Leave(KErrArgument);
       
   285             }
       
   286 
       
   287         iRequestArray[index].iCancelReason = update.iCancelReason;
       
   288         }
       
   289 
       
   290     return TPtrC8();
       
   291     }
       
   292 
       
   293 //  End of File