locationsystemui/locationsysui/queryandnotification/src/EPos_CPosPrivacyNotifier.cpp
branchRCL_3
changeset 16 6fcbaa43369c
equal deleted inserted replaced
13:19bff11d6c18 16:6fcbaa43369c
       
     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:   Class for LBS Privacy Query & Notify (Q&N) privacy notifiers.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <lbs/epos_cposcontactrequestor.h>
       
    21 #include <lbs/epos_cposservicerequestor.h>
       
    22 #include <lbs/epos_privacynotifier.hrh>
       
    23 #include <EPos_CPosPrivacyNotifier.h>
       
    24 #include "EPos_CPosPrivacyNotifierExtension.h"
       
    25 
       
    26 #if defined(NRH_UNIT_TEST)
       
    27 // For the NRH unit test, use a custom notifier UID.
       
    28 // This is so that we can have both the unit test
       
    29 // Q&N notifier and the integration test Q&N notifier
       
    30 // (using the real UID) in the same ROM.
       
    31 const TUid KNotifierUid = { 0x10283744 };
       
    32 #else
       
    33 const TUid KNotifierUid = { KPosPrivacyNotifierImplUid };
       
    34 #endif // NRH_UNIT_TEST
       
    35 
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 /**
       
    39 Default constructor.
       
    40 
       
    41 This constructor assumes that the notifier only supports
       
    42 EBasicCapabilities, i.e. the notifier supports queries but only
       
    43 notifications of accepted requests are supported. If the notifier
       
    44 is more advanced, the overloaded constructor should be used.
       
    45 */
       
    46 EXPORT_C CPosPrivacyNotifier::CPosPrivacyNotifier()
       
    47     {
       
    48     }
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 /**
       
    52 Symbian 2nd phase constructor. Must be called first thing during construction.
       
    53 
       
    54 The notifier must specify channel and priority. These attributes are
       
    55 defined by the Notifier Framework in eiknotapi.h.
       
    56 
       
    57 The different priority values are defined in
       
    58 MEikSrvNotifierBase2::TNotifierPriority.
       
    59 
       
    60 @param aChannel A channel. See definition in Notifier Framework.
       
    61 @param aPriority A notifier priority. See definition in Notifier Framework.
       
    62 
       
    63 @see MEikSrvNotifierBase2::TNotifierPriority
       
    64 */
       
    65 EXPORT_C void CPosPrivacyNotifier::BaseConstructL(
       
    66     TUid aChannel,
       
    67     TInt aPriority)
       
    68     {
       
    69     iExtension = CPosPrivacyNotifierExtension::NewL(this);
       
    70     iExtension->iNotifierInfo.iChannel = aChannel;
       
    71     iExtension->iNotifierInfo.iPriority = aPriority;
       
    72     iExtension->iNotifierInfo.iUid = KNotifierUid;
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 EXPORT_C CPosPrivacyNotifier::~CPosPrivacyNotifier()
       
    77     {
       
    78     delete iExtension;
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 /**
       
    83 Retrieves a handle to the notifier base.
       
    84 
       
    85 This handle is needed to populate the notifier base array in the
       
    86 notifier factory method.
       
    87 
       
    88 @return A handle to the notifier base.
       
    89 */
       
    90 EXPORT_C MEikSrvNotifierBase2* CPosPrivacyNotifier::NotifierBase() const
       
    91     {
       
    92     return iExtension;
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 /**
       
    97 Retrieves the cancel reason.
       
    98 
       
    99 Cancel reason can only be retrieved when HandleRequestCancelled or 
       
   100 HandleAllRequestCancelled is running. If the method is called at another 
       
   101 time, it will return ECancelReasonNotAvailable.
       
   102 
       
   103 Note that the TCancelReason enum is designed to be extendable,
       
   104 i.e. new values may be added in the future. This means that any
       
   105 unrecognized value must be treated like ECancelReasonNotAvailable.
       
   106 
       
   107 @return The cancel reason.
       
   108 
       
   109 @see HandleRequestCancelled()
       
   110 @see HandleAllRequestCancelled()
       
   111 @see ECancelReasonNotAvailable
       
   112 @see TCancelReason
       
   113 */
       
   114 EXPORT_C TPosVerifyCancelReason
       
   115    CPosPrivacyNotifier::CancelReason() const
       
   116     {
       
   117     TPosQNRequestId requestId = CurrentRequest();
       
   118     TInt index = iExtension->Find(requestId);
       
   119 
       
   120     if (index == KErrNotFound)
       
   121         {
       
   122         return EPosCancelReasonNotAvailable;
       
   123         }
       
   124 
       
   125     return iExtension->iRequestArray[index].iCancelReason;
       
   126     }
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 /**
       
   130 Returns a list of all outstanding privacy query and notification requests.
       
   131 
       
   132 If there are no outstanding requests, an empty array will be returned.
       
   133 
       
   134 @param aRequestArray On return, this array will contain all
       
   135   outstanding query and notification requests.
       
   136 */
       
   137 EXPORT_C void CPosPrivacyNotifier::GetRequestsL(
       
   138     RArray<TPosQNRequestId>& aRequestArray) const
       
   139     {
       
   140     aRequestArray.Reset();
       
   141     for (TInt i = 0; i < iExtension->iRequestArray.Count(); i++)
       
   142         {
       
   143         User::LeaveIfError(
       
   144             aRequestArray.Append(iExtension->iRequestArray[i].iId));
       
   145         }
       
   146     }
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 /**
       
   150 Checks whether a request is privacy query or notification type.
       
   151 
       
   152 @param aRequestId The ID of the request to check.
       
   153 @return @p EQuery if query type and ENotification if notification type.
       
   154 
       
   155 @leave If the specified request is not an outstanding request, this method
       
   156   will leave with error code KErrNotFound.
       
   157 */
       
   158 EXPORT_C CPosPrivacyNotifier::TRequestType CPosPrivacyNotifier::RequestTypeL(
       
   159     TPosQNRequestId aRequestId) const
       
   160     {
       
   161     TInt index = iExtension->Find(aRequestId);
       
   162     __ASSERT_ALWAYS(index != KErrNotFound, User::Leave(KErrNotFound));
       
   163 
       
   164     if (iExtension->iRequestArray[index].iType ==
       
   165         TPosQNInputData::EQuery)
       
   166         {
       
   167         return CPosPrivacyNotifier::EQuery;
       
   168         }
       
   169 
       
   170     return CPosPrivacyNotifier::ENotification;
       
   171     }
       
   172 
       
   173 // ---------------------------------------------------------------------------
       
   174 /**
       
   175 Sets the request which the notifier wants to read information about.
       
   176 
       
   177 Current request specifies the request which will be accessed when
       
   178 RequestorCountL and RequestorLC are called.
       
   179 
       
   180 @param aRequestId The ID of the current request.
       
   181 
       
   182 @leave If the specified request is not an outstanding request, this method
       
   183   will leave with error code KErrNotFound.
       
   184 */
       
   185 EXPORT_C void CPosPrivacyNotifier::SetCurrentRequestL(
       
   186     TPosQNRequestId aRequestId)
       
   187     {
       
   188     iExtension->PrepareL(aRequestId);
       
   189     }
       
   190 
       
   191 // ---------------------------------------------------------------------------
       
   192 /**
       
   193 Returns the ID of the current request.
       
   194 
       
   195 Current request specifies the request which will be accessed when
       
   196 RequestorCountL and RequestorLC are called.
       
   197 
       
   198 @return The ID of the current request. If the current request has
       
   199   become invalid, e.g. the request set as current has been cancelled,
       
   200   KPosNullQNRequestId will be returned.
       
   201 
       
   202 @see RequestorCountL()
       
   203 @see RequestorLC()
       
   204 */
       
   205 EXPORT_C TPosQNRequestId CPosPrivacyNotifier::CurrentRequest() const
       
   206     {
       
   207     return iExtension->iCurrentRequestId;
       
   208     }
       
   209 
       
   210 // ---------------------------------------------------------------------------
       
   211 /**
       
   212 Retrieves the timeout strategy for a query.
       
   213 
       
   214 Timeout strategy specifies what the decision will be if the
       
   215 verification query times out. The decision is either
       
   216 EPosDecisionRejected or EPosDecisionAccepted.
       
   217 
       
   218 Before calling this method, current request must first be set by
       
   219 calling SetCurrentRequestL.
       
   220 
       
   221 Timeout strategy can only be retrieved for a query request. If the
       
   222 current request is a notification, this method will return
       
   223 EPosDecisionNotAvailable.
       
   224 
       
   225 Note that the TPosRequestDecision enum is designed to be
       
   226 extendable, i.e. new values may be added in the future. This means
       
   227 that any unrecognized value must be treated like
       
   228 EPosDecisionNotAvailable.
       
   229 
       
   230 @return The timeout strategy.
       
   231 
       
   232 @see SetCurrentRequestL()
       
   233 */
       
   234 EXPORT_C TPosRequestDecision CPosPrivacyNotifier::QueryTimeoutStrategy() const
       
   235     {
       
   236     TPosQNRequestId requestId = CurrentRequest();
       
   237     TInt index = iExtension->Find(requestId);
       
   238 
       
   239     if (index == KErrNotFound ||
       
   240         iExtension->iRequestArray[index].iType ==
       
   241             TPosQNInputData::ENotification)
       
   242         {
       
   243         return EPosDecisionNotAvailable;
       
   244         }
       
   245 
       
   246     return iExtension->iRequestArray[index].iTimeoutStrategy;
       
   247     }
       
   248 
       
   249 // ---------------------------------------------------------------------------
       
   250 /**
       
   251 Retrieves the source of the location request.
       
   252 
       
   253 Before calling this method, current request must first be set by
       
   254 calling SetCurrentRequestL.
       
   255 
       
   256 Note that the TPosRequestSource enum is designed to be extendable, 
       
   257 i.e. new values may be added in the future. This means that any 
       
   258 unrecognized value must be treated like EPosRequestSourceNotAvailable.
       
   259 
       
   260 @return The request source, e.g. EPosRequestSourceNetwork or
       
   261   EPosRequestSourceNotAvailable if the request source is not specified.
       
   262 
       
   263 @see SetCurrentRequestL()
       
   264 @see TPosRequestSource
       
   265 */
       
   266 EXPORT_C TPosRequestSource CPosPrivacyNotifier::RequestSource() const
       
   267     {
       
   268     TPosQNRequestId requestId = CurrentRequest();
       
   269     TInt index = iExtension->Find(requestId);
       
   270 
       
   271     if (index == KErrNotFound)
       
   272         {
       
   273         return EPosRequestSourceNotAvailable;
       
   274         }
       
   275 
       
   276     return iExtension->iRequestArray[index].iRequestSource;
       
   277     }
       
   278 
       
   279 // ---------------------------------------------------------------------------
       
   280 /**
       
   281 Retrieves whether the location request was accepted or rejected.
       
   282 
       
   283 For notification requests, this method will return the request
       
   284 decision. For queries, this method will return EPosDecisionNotAvailable.
       
   285 
       
   286 Before calling this method, current request must first be set by
       
   287 calling SetCurrentRequestL, otherwise this method will return
       
   288 EPosDecisionNotAvailable.
       
   289 
       
   290 Note that the TPosRequestDecision enum is designed to be
       
   291 extendable, i.e. new values may be added in the future. 
       
   292 This means that any unrecognized value must be treated like
       
   293 EPosDecisionNotAvailable.
       
   294 
       
   295 @return Whether the location request was accepted or rejected, or
       
   296   EPosDecisionNotAvailable if the outcome has not yet been decided.
       
   297   
       
   298 @see SetCurrentRequestL()
       
   299 @see TPosRequestDecision
       
   300 */
       
   301 EXPORT_C TPosRequestDecision
       
   302     CPosPrivacyNotifier::LocationRequestDecision() const
       
   303     {
       
   304     TPosQNRequestId requestId = CurrentRequest();
       
   305     TInt index = iExtension->Find(requestId);
       
   306 
       
   307     if (index == KErrNotFound ||
       
   308         iExtension->iRequestArray[index].iType == TPosQNInputData::EQuery)
       
   309         {
       
   310         return EPosDecisionNotAvailable;
       
   311         }
       
   312 
       
   313     return iExtension->iRequestArray[index].iRequestDecision;
       
   314     }
       
   315 
       
   316 // ---------------------------------------------------------------------------
       
   317 /**
       
   318 Retrieves the reason for a notification.
       
   319 
       
   320 Note that the TPosNotificationReason enum is designed to be
       
   321 extendable, i.e. new values may be added in the future. This means
       
   322 that any unrecognized value must be treated like
       
   323 EPosNotificationReasonNotAvailable. 
       
   324 If the notification reason is not known, the notification request 
       
   325 should be completed with code KErrNotSupported.
       
   326 
       
   327 @return The notification reason.
       
   328   For queries, this method will return EPosNotificationReasonNotAvailable.
       
   329 
       
   330   Before calling this method, current request must first be set by
       
   331   calling SetCurrentRequestL, otherwise this method will return
       
   332   EPosNotificationReasonNotAvailable.
       
   333 
       
   334 @see EPosNotificationReasonNotAvailable
       
   335 @see SetCurrentRequestL()
       
   336 @see TPosNotificationReason
       
   337 */
       
   338 EXPORT_C TPosNotificationReason CPosPrivacyNotifier::NotificationReason() const
       
   339     {
       
   340     TPosQNRequestId requestId = CurrentRequest();
       
   341     TInt index = iExtension->Find(requestId);
       
   342 
       
   343     if (index == KErrNotFound ||
       
   344         iExtension->iRequestArray[index].iType == TPosQNInputData::EQuery)
       
   345         {
       
   346         return EPosNotificationReasonNotAvailable;
       
   347         }
       
   348 
       
   349     return iExtension->iRequestArray[index].iNotificationReason;
       
   350     }
       
   351 
       
   352 // ---------------------------------------------------------------------------
       
   353 /**
       
   354 Returns the number of requestors in the current request.
       
   355 
       
   356 Before calling this method, current request must first be set by
       
   357 calling SetCurrentRequestL.
       
   358 
       
   359 @return The number of requestors in the current request.
       
   360 
       
   361 @leave If the current request has not been set or the current request is no
       
   362   longer valid, e.g. because it has been cancelled or completed, this
       
   363   method will leave with error code KErrNotFound.
       
   364 
       
   365 @see SetCurrentRequestL()
       
   366 */
       
   367 EXPORT_C TInt CPosPrivacyNotifier::RequestorCountL() const
       
   368     {
       
   369     __ASSERT_ALWAYS(CurrentRequest() != KPosNullQNRequestId,
       
   370         User::Leave(KErrNotFound));
       
   371 
       
   372     return iExtension->iRequestorStack.Count();
       
   373     }
       
   374 
       
   375 // ---------------------------------------------------------------------------
       
   376 /**
       
   377 Returns basic information about the requestor at a specified index.
       
   378 
       
   379 Before calling this method, current request must first be set by
       
   380 calling SetCurrentRequestL. 
       
   381 
       
   382 Whether the requestor is a contact or a service can be found by
       
   383 calling CPosRequestor::RequestorType.
       
   384 
       
   385 If the requestor is a contact, the requestor object can be cast to
       
   386 CPosContactRequestor.
       
   387 
       
   388 If the requestor is a service, the requestor object can be cast to
       
   389 CPosServiceRequestor.
       
   390 
       
   391 @param aRequestorIndex The index of the requestor.
       
   392 @return Information about the requestor.
       
   393 
       
   394 @leave If the specified requestor index is not valid, i.e. less than 0 or
       
   395   larger than or equal to RequestorCountL, this method will
       
   396   leave with error code KErrArgument.
       
   397 
       
   398   If the current request has not been set or the current request is no 
       
   399   longer valid, e.g. because it has been cancelled or completed, this method 
       
   400   will leave with error code KErrNotFound.
       
   401 
       
   402 @see SetCurrentRequestL()
       
   403 @see RequestorCountL()
       
   404 @see CPosContactRequestor
       
   405 @see CPosServiceRequestor
       
   406 @see CPosRequestor::RequestorType
       
   407 */
       
   408 EXPORT_C CPosRequestor* CPosPrivacyNotifier::RequestorLC(
       
   409     TInt aRequestorIndex) const
       
   410     {
       
   411     __ASSERT_ALWAYS(CurrentRequest() != KPosNullQNRequestId,
       
   412         User::Leave(KErrNotFound));
       
   413 
       
   414     __ASSERT_ALWAYS(aRequestorIndex >= 0 &&
       
   415         aRequestorIndex < iExtension->iRequestorStack.Count(),
       
   416         User::Leave(KErrArgument));
       
   417 
       
   418     CPosRequestor* requestor = iExtension->iRequestorStack[aRequestorIndex];
       
   419     TInt type = requestor->RequestorType();
       
   420     CPosRequestor::TRequestorIdFormat format = requestor->RequestorIdFormat();
       
   421     TPtrC idString = requestor->RequestorIdString();
       
   422 
       
   423     if (type == CPosRequestor::ERequestorService)
       
   424         {
       
   425         CPosServiceRequestor* serviceRequestor = CPosServiceRequestor::NewLC(format, idString);
       
   426         serviceRequestor->SetRequestType(requestor->RequestType());
       
   427         serviceRequestor->SetNetworkType(requestor->NetworkType());
       
   428         return serviceRequestor;
       
   429         }
       
   430 
       
   431     CPosContactRequestor* contactRequestor = CPosContactRequestor::NewLC(format, idString);
       
   432     contactRequestor->SetRequestType(requestor->RequestType());
       
   433     contactRequestor->SetNetworkType(requestor->NetworkType());
       
   434     return contactRequestor;
       
   435     }
       
   436 
       
   437 // ---------------------------------------------------------------------------
       
   438 /**
       
   439 This method completes a privacy query or notification request.
       
   440 
       
   441 @param aRequestId The ID of the privacy query or notification request
       
   442   to complete.
       
   443 @param aCompletionCode The request completion code.
       
   444   If the request is a privacy query, the completion code should be one of:
       
   445   - KErrNone if query is accepted by the phone user.
       
   446   - KErrAccessDenied if query is rejected by the phone user.
       
   447   - KErrTimedOut if the query times out.
       
   448 
       
   449   If the request is a privacy notification, the completion code should be one of:
       
   450   - KErrNone if the phone user dismisses the privacy notification
       
   451   - KErrTimedOut if the notification times out.
       
   452 */
       
   453 EXPORT_C void CPosPrivacyNotifier::CompleteRequest(
       
   454     TPosQNRequestId aRequestId,
       
   455     TInt aCompletionCode)
       
   456     {
       
   457     iExtension->CompleteRequest(aRequestId, aCompletionCode);
       
   458     }
       
   459 
       
   460 // ---------------------------------------------------------------------------
       
   461 /**
       
   462 This method completes all outstanding requests.
       
   463 
       
   464 This method can be used to accept or reject all outstanding
       
   465 requests by completing with codes @p KErrNone or @p KErrAccessDenied
       
   466 respectively. All notification requests will also be completed with
       
   467 this code.
       
   468 
       
   469 @param aCompletionCode The request completion code.
       
   470 */
       
   471 EXPORT_C void CPosPrivacyNotifier::CompleteAllRequests(TInt aCompletionCode)
       
   472     {
       
   473     iExtension->CompleteAllRequests(aCompletionCode);
       
   474     }
       
   475 
       
   476 // ---------------------------------------------------------------------------
       
   477 /**
       
   478 Checks that the Privacy UI was launched by the expected client.
       
   479 
       
   480 The caller specifies the secure ID of the expected client and this
       
   481 method returns whether the Privacy UI was launched by that client or not.
       
   482 
       
   483 @param aSecureId The secureID of the expected client
       
   484 @return ETrue if the client that called the notifier is the expected client
       
   485 */
       
   486 #pragma message("NOTE: CPosPrivacyNotifier::CheckClientSecureId has no type/return definition.")
       
   487 EXPORT_C TBool CPosPrivacyNotifier::CheckClientSecureId(TSecureId aSecureId)
       
   488     {
       
   489     return iExtension->iMessage.SecureId() == aSecureId;
       
   490     }