src/location/qmlbackendtriggerchangeao_s60.cpp
changeset 0 876b1a06bc25
equal deleted inserted replaced
-1:000000000000 0:876b1a06bc25
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include "qmlbackendmonitorao_s60_p.h"
       
    43 #include "qgeoareamonitor_s60_p.h"
       
    44 #include "qmlbackendmonitorinfo_s60_p.h"
       
    45 #include "qmlbackendtriggerchangeao_s60_p.h"
       
    46 
       
    47 #include <lbtsessiontrigger.h>
       
    48 #include <lbttriggerentry.h>
       
    49 
       
    50 QTM_BEGIN_NAMESPACE
       
    51 
       
    52 //Design chnages
       
    53 
       
    54 QMLBackendTriggerChangeAO* QMLBackendTriggerChangeAO::instance = NULL;
       
    55 TInt QMLBackendTriggerChangeAO::refCount = 0;
       
    56 
       
    57 
       
    58 //request for the notification of trigger change event with the
       
    59 //LBT server
       
    60 void QMLBackendTriggerChangeAO::NotifyChangeEvent()
       
    61 {
       
    62     if (!IsActive()) {
       
    63         iStatus = KRequestPending;
       
    64         iLbt.NotifyTriggerChangeEvent(iTriggerChangeEvent, iStatus);
       
    65         SetActive();
       
    66     }
       
    67 }
       
    68 
       
    69 
       
    70 QMLBackendTriggerChangeAO::~QMLBackendTriggerChangeAO()
       
    71 {
       
    72     Cancel();
       
    73     iLbt.Close();
       
    74 }
       
    75 
       
    76 void  QMLBackendTriggerChangeAO::DoCancel()
       
    77 {
       
    78     if (IsActive()) { //if AO is active,cancel the trigger change event request
       
    79         iLbt.CancelNotifyTriggerChangeEvent();
       
    80     }
       
    81 }
       
    82 
       
    83 void QMLBackendTriggerChangeAO::RunL()
       
    84 {
       
    85     switch (iStatus.Int()) {
       
    86         case KErrNone :
       
    87 #if 0
       
    88             //implementation takes the updation, deletion into consideration
       
    89             //from the UI, which is'nt possible with the current UI for LBT.
       
    90             //The same should be considered once made availbale as part of the UI
       
    91             //check for Multiple trigger change events
       
    92             if (iTriggerChangeEvent.iEventType == ELbtTriggerChangeEventMultiple) {
       
    93                 CMonitorTriggerInfo* triggerInfo1 = NULL;
       
    94 
       
    95                 CMonitorTriggerInfo* triggerInfo2 = NULL;
       
    96 
       
    97                 CMonitorTriggerInfo* triggerInfo3 = NULL;
       
    98 
       
    99                 TInt i = 0, count = 0;
       
   100 
       
   101                 RPointerArray < CLbtTriggerInfo > trigInfoList;
       
   102 
       
   103                 CLbtTriggerEntry* entry = NULL;
       
   104 
       
   105                 //retrieve the list of triggers created by the client
       
   106                 iLbt.GetTriggersL(trigInfoList);
       
   107 
       
   108                 CleanupClosePushL(trigInfoList);
       
   109 
       
   110                 count = trigInfoList.Count();
       
   111 
       
   112                 //get the header of the linked list holding the information
       
   113                 //of the trigger
       
   114                 triggerInfo1 = iTriggerMonitorInfo->getMonitorTriggerInfo();
       
   115 
       
   116                 while (triggerInfo1) {
       
   117                     for (i = 0; i < count; i++) {
       
   118                         //get the trigger entryinfo
       
   119                         entry = trigInfoList[i]->TriggerEntry();
       
   120 
       
   121                         //if the triggerinfo retrieved matches the trigInfoList
       
   122                         //id break
       
   123                         if (triggerInfo1->iTriggerID == entry->Id())
       
   124                             break;
       
   125                     }
       
   126 
       
   127                     triggerInfo2 = triggerInfo1->next;
       
   128 
       
   129                     if (i == count)   //if the triggerinfo1->triggerid not found
       
   130                         //in the trigger list of the LBT server,
       
   131                         //remove the triggerinfo from the linked list
       
   132                     {
       
   133                         iTriggerMonitorInfo->removeMonitorTriggerInfo(
       
   134                             triggerInfo1->iTriggerID);
       
   135                     } else {
       
   136 
       
   137                         //if triggerinfo1->triggerid is found in the trigger list,
       
   138                         //and if it is an entry trigger, search for the corresponding
       
   139                         //exit trigger in the linked list
       
   140                         if (triggerInfo1->iType == EntryTrigger)
       
   141                             triggerInfo3 = iTriggerMonitorInfo->getMonitorTriggerInfo(
       
   142                                                triggerInfo1->iParent , ExitTrigger);
       
   143 
       
   144                         //if triggerinfo1->triggerid is found in the trigger list,
       
   145                         //and if it is an entry trigger, search for the corresponding
       
   146                         //entry trigger in the linked list
       
   147                         else if (triggerInfo1->iType == ExitTrigger)
       
   148                             triggerInfo3 = iTriggerMonitorInfo->getMonitorTriggerInfo(
       
   149                                                triggerInfo1->iParent, EntryTrigger);
       
   150 
       
   151                         //callback called for the notification change event of the trigger
       
   152                         if (triggerInfo3) {
       
   153 
       
   154                             (triggerInfo1->iParent)->handleTriggerChangeEvent(iTriggerChangeEvent.iEventType, trigInfoList[i],
       
   155                                     triggerInfo3->iTriggerID);
       
   156                         } else {
       
   157                             (triggerInfo1->iParent)->handleTriggerChangeEvent(iTriggerChangeEvent.iEventType, trigInfoList[i],
       
   158                                     NULL);
       
   159                         }
       
   160 
       
   161                     }
       
   162                     triggerInfo3 = NULL;
       
   163 
       
   164                     triggerInfo1 = triggerInfo2;
       
   165                 }
       
   166 
       
   167                 CleanupStack::Pop(1);
       
   168 
       
   169                 //cloae the trigInfoList, holding the list of trigger
       
   170                 //info
       
   171                 trigInfoList.Close();
       
   172 
       
   173             }
       
   174             //check for trigger delete event
       
   175             else if (iTriggerChangeEvent.iEventType == ELbtTriggerChangeEventDeleted) {
       
   176                 //delete the entry from the linked list,corresponding to the
       
   177                 //iTriggerChangeEvent.iTriggerId
       
   178                 iTriggerMonitorInfo->removeMonitorTriggerInfo(
       
   179                     iTriggerChangeEvent.iTriggerId);
       
   180             }
       
   181             //check for trigger updation event
       
   182             else if (iTriggerChangeEvent.iEventType == ELbtTriggerChangeEventUpdated) {
       
   183                 CLbtTriggerInfo *info = NULL;
       
   184 
       
   185                 //get the triggerinfo from the linked list corresponding
       
   186                 //to the iTriggerChangeEvent.iTriggerId
       
   187                 CMonitorTriggerInfo* triggerInfo1 = iTriggerMonitorInfo->getMonitorTriggerInfo(
       
   188                                                         iTriggerChangeEvent.iTriggerId);
       
   189 
       
   190                 if (!triggerInfo1)
       
   191                     break;
       
   192 
       
   193                 //get the triggerinfo of trigger with id - iTriggerChangeEvent.iTriggerId
       
   194                 //from the LBT server
       
   195                 info = iLbt.GetTriggerLC(iTriggerChangeEvent.iTriggerId);
       
   196 
       
   197                 if (info == NULL)
       
   198                     break;
       
   199 
       
   200                 //change in one-trigger,must update the corresponding entry/exit
       
   201                 //trigger
       
   202                 if (triggerInfo1) {
       
   203                     CMonitorTriggerInfo* triggerInfo2 = NULL;
       
   204 
       
   205                     //if the trigger updated is EntryTrigger, get the information
       
   206                     //of the corresponding ExitTrigger if any,from the
       
   207                     //linked list
       
   208                     if (triggerInfo1->iType == EntryTrigger)
       
   209                         triggerInfo2 = iTriggerMonitorInfo->getMonitorTriggerInfo(
       
   210                                            triggerInfo1->iParent, ExitTrigger);
       
   211 
       
   212                     //if the trigger updated is ExitTrigger, get the information
       
   213                     //of the corresponding EntryTrigger if any,fro mthe
       
   214                     //linked list
       
   215                     else if (triggerInfo1->iType == ExitTrigger)
       
   216                         triggerInfo2 = iTriggerMonitorInfo->getMonitorTriggerInfo(
       
   217                                            triggerInfo1->iParent, EntryTrigger);
       
   218 
       
   219                     //callback called for the notification change event for the trigger
       
   220                     if (triggerInfo2) {
       
   221                         (triggerInfo1->iParent)->handleTriggerChangeEvent(iTriggerChangeEvent.iEventType, info,
       
   222                                 triggerInfo2->iTriggerID);
       
   223                     } else {
       
   224                         (triggerInfo1->iParent)->handleTriggerChangeEvent(iTriggerChangeEvent.iEventType, info,
       
   225                                 NULL);
       
   226                     }
       
   227                 }
       
   228 
       
   229                 //pop and destroy the triggerinfo retrived from GetTriggerLC()
       
   230                 CleanupStack::PopAndDestroy(info);
       
   231             }
       
   232 #endif
       
   233             if (iTriggerChangeEvent.iEventType == ELbtTriggerChangeEventMultiple) {
       
   234 
       
   235                 CMonitorTriggerInfo* triggerInfo1 = NULL;
       
   236 
       
   237                 CMonitorTriggerInfo* triggerInfo2 = NULL;
       
   238 
       
   239                 TInt i = 0, count = 0;
       
   240 
       
   241                 RArray < TLbtTriggerId > triggerIdList;
       
   242 
       
   243 
       
   244                 //retrieve the list of trigger IDs created by the client
       
   245                 TRAPD(ret, iLbt.ListTriggerIdsL(triggerIdList));
       
   246 
       
   247                 if (ret != KErrNone) {
       
   248                     break;
       
   249                 }
       
   250 
       
   251                 CleanupClosePushL(triggerIdList);
       
   252 
       
   253                 count = triggerIdList.Count();
       
   254 
       
   255                 //get the header of the linked list holding the information
       
   256                 //of the trigger
       
   257                 triggerInfo1 = iTriggerMonitorInfo->getMonitorTriggerInfo();
       
   258 
       
   259                 while (triggerInfo1) {
       
   260                     for (i = 0; i < count; i++) {
       
   261                         //if the triggerinfo retrieved matches the triggerIdList
       
   262                         //id break
       
   263                         if (triggerInfo1->iTriggerID == triggerIdList[i])
       
   264                             break;
       
   265                     }
       
   266 
       
   267                     triggerInfo2 = triggerInfo1->next;
       
   268 
       
   269                     if (i == count)   //if the triggerinfo1->triggerid not found
       
   270                         //in the trigger list of the LBT server,
       
   271                         //remove the triggerinfo from the linked list
       
   272                     {
       
   273                         iTriggerMonitorInfo->removeMonitorTriggerInfo(
       
   274                             triggerInfo1->iTriggerID);
       
   275                     }
       
   276 
       
   277                     triggerInfo1 = triggerInfo2;
       
   278                 }
       
   279 
       
   280                 CleanupStack::Pop(1);
       
   281 
       
   282                 //close the trigInfoList, holding the list of trigger
       
   283                 //info
       
   284                 triggerIdList.Close();
       
   285             }
       
   286 
       
   287             //check for trigger delete event
       
   288             else if (iTriggerChangeEvent.iEventType == ELbtTriggerChangeEventDeleted) {
       
   289                 //delete the entry from the linked list,corresponding to the
       
   290                 //iTriggerChangeEvent.iTriggerId
       
   291                 iTriggerMonitorInfo->removeMonitorTriggerInfo(
       
   292                     iTriggerChangeEvent.iTriggerId);
       
   293             }
       
   294             break;
       
   295 
       
   296         default :
       
   297             break;
       
   298     }
       
   299 
       
   300     //request for the notification of any notification change events
       
   301     NotifyChangeEvent();
       
   302 }
       
   303 
       
   304 
       
   305 //static function called prior to the destruction of the
       
   306 //singleton QMLBackendTriggerChangeAO object
       
   307 void QMLBackendTriggerChangeAO::DeleteAO()
       
   308 {
       
   309     //decrement the referent count
       
   310     refCount--;
       
   311 
       
   312     if (!refCount) { //if reference count becomes 0 delete the instance
       
   313         delete instance;
       
   314         instance = NULL;
       
   315     }
       
   316 }
       
   317 
       
   318 QMLBackendTriggerChangeAO* QMLBackendTriggerChangeAO::NewL(RLbtServer& aLbtServ)
       
   319 {
       
   320 
       
   321     if (!instance) {
       
   322         instance = new  QMLBackendTriggerChangeAO;
       
   323         instance->ConstructL(aLbtServ);
       
   324         if (!instance->isValid()) {
       
   325             delete instance;
       
   326             instance = NULL;
       
   327             return NULL;
       
   328         }
       
   329     }
       
   330     refCount++;
       
   331     return instance;
       
   332 
       
   333 }
       
   334 
       
   335 QMLBackendTriggerChangeAO::QMLBackendTriggerChangeAO() : CActive(EPriorityNormal), iTriggerMonitorInfo(NULL)
       
   336 {
       
   337     CActiveScheduler::Add(this);        //add current AO, to the Schedular
       
   338 }
       
   339 
       
   340 void QMLBackendTriggerChangeAO::ConstructL(RLbtServer& aLbtServ)
       
   341 {
       
   342     if (iLbt.Open(aLbtServ) == KErrNone) { //open the RLBT subsesion
       
   343         subsessionCreated = TRUE;
       
   344         //Get the pointer to the CBackendMonitorInfo singleton object
       
   345         iTriggerMonitorInfo = CBackendMonitorInfo::NewL();
       
   346     }
       
   347 }
       
   348 
       
   349 QTM_END_NAMESPACE