serviceproviders/sapi_logging/loggingservice/src/loggingservice.cpp
changeset 5 989d2f495d90
child 36 c210248fa89d
equal deleted inserted replaced
1:a36b1e19a461 5:989d2f495d90
       
     1 /*
       
     2 * Copyright (c) 2007 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 the License "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:  Implements logging SAPI deligator class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32def.h>
       
    20 #include <logwrap.h>
       
    21 #include <logcli.h>
       
    22 
       
    23 #include "logiter.h"
       
    24 #include "loggingservice.h"
       
    25 #include "loggingasyncservice.h"
       
    26 #include "loggingsyncservice.h"
       
    27 #include "loggingevent.h"
       
    28 #include  "loggingfilter.h"
       
    29 #include  "loggingcallbackslot.h"
       
    30 
       
    31 /**
       
    32 * Default Constructor Method
       
    33 */
       
    34 
       
    35 CLoggingService :: CLoggingService()
       
    36     {
       
    37     }
       
    38 
       
    39 /**
       
    40 * Default Destructor
       
    41 */
       
    42 CLoggingService :: ~CLoggingService()
       
    43     {
       
    44     /**
       
    45      * Iterate through the registration table and
       
    46      * cancel and delete any outstanding async request
       
    47      */
       
    48     for(TInt iter = 0 ; iter < iRegTable.Count() ; ++iter)
       
    49         {
       
    50         delete iRegTable[iter] ;
       
    51         }
       
    52     delete iLogService;
       
    53     delete iSapiEvent;
       
    54     iRegTable.Close() ;
       
    55     }
       
    56 
       
    57 /**
       
    58 *Two phased constructor implementation
       
    59 */
       
    60 EXPORT_C CLoggingService* CLoggingService :: NewL()
       
    61     {
       
    62     CLoggingService* self = CLoggingService::NewLC();
       
    63     CleanupStack::Pop(self);
       
    64     return self;
       
    65     }
       
    66 
       
    67 /**
       
    68 * Two phased constructor implementation
       
    69 */
       
    70 CLoggingService* CLoggingService :: NewLC()
       
    71     {
       
    72     CLoggingService* self = new (ELeave) CLoggingService();
       
    73     CleanupStack::PushL(self);
       
    74     self->ConstructL();
       
    75     return self;
       
    76     }
       
    77 
       
    78 /**
       
    79 * This function constructs the member elements of CLogsEvent Class
       
    80 */
       
    81 void CLoggingService:: ConstructL()
       
    82     {
       
    83     iSapiEvent = CLogsEvent :: NewL();
       
    84     iLogService = CLogSyncService :: NewL();
       
    85     }
       
    86 
       
    87 /**
       
    88 * Adds an event to the event database synchronously
       
    89 * @parm Details of the event to be logged
       
    90 */
       
    91 EXPORT_C TLogId CLoggingService :: AddEventL( CLogsEvent* aSapiEvent )
       
    92     {
       
    93     //Check The registration Table, and make sure that no async
       
    94     // Request is pending
       
    95     return iLogService->AddL(aSapiEvent->getEvent());
       
    96     }
       
    97 
       
    98 /**
       
    99 * Async AddEvent function. adds an Event asynchronously
       
   100 * do event database
       
   101 * @param aEvent, details of the event to be added to the
       
   102 * event database
       
   103 */
       
   104 EXPORT_C TInt CLoggingService :: AddEventL( TUint aTransId ,
       
   105                                             CLogsEvent* aSapiEvent ,
       
   106                                             MLoggingCallback* aCallback )
       
   107     {
       
   108     CLogAsyncService *LogAsyncService = CLogAsyncService :: NewL(aCallback) ;
       
   109     LogAsyncService->AddL( aTransId ,aSapiEvent->getEvent());
       
   110     CCallbackSlot *LogSlot = CCallbackSlot :: NewL() ;
       
   111     LogSlot->SetUid(aTransId) ;
       
   112     LogSlot->SetActiveObj(LogAsyncService) ;
       
   113     iRegTable.Append(LogSlot) ;
       
   114     return KErrNone ;
       
   115     }
       
   116 
       
   117 /**
       
   118 * Deletes an event from the event database synchronously
       
   119 * @parm Details of the event to be logged
       
   120 * @param aFilter, search criteria for this event in event database
       
   121 */
       
   122 
       
   123 EXPORT_C TInt CLoggingService :: DeleteEventL( TLogId aLogId )
       
   124     {
       
   125     return iLogService->Delete(aLogId);
       
   126     }
       
   127 
       
   128 /**
       
   129 * Deletes a event from the event database
       
   130 * @param aLogId Event id of the event in the database
       
   131 * @param aFilter, search criteria for this event in event database
       
   132 */
       
   133 EXPORT_C void CLoggingService :: DeleteEventL( TUint aTransId ,
       
   134                                                TLogId aLogId,
       
   135                                                MLoggingCallback* aCallback )
       
   136 
       
   137     {
       
   138     CLogAsyncService  *LogAsyncService =  CLogAsyncService :: NewL(aCallback) ;
       
   139     LogAsyncService->Delete(aTransId ,aLogId);
       
   140     CCallbackSlot *slot = CCallbackSlot :: NewL() ;
       
   141     slot->SetUid(aTransId) ;
       
   142     slot->SetActiveObj(LogAsyncService) ;
       
   143     iRegTable.Append(slot) ;
       
   144     }
       
   145 
       
   146 /**
       
   147 * Gets the event list from events from the log database synchronously
       
   148 *
       
   149 * @param aLogId Event id of the event in the database
       
   150 * @param aFilter, search criteria for this event in event database
       
   151 *
       
   152 * Returns the iterator
       
   153 */
       
   154 EXPORT_C CLogIter* CLoggingService :: GetListL( CLogsFilter* aFilter )
       
   155     {
       
   156     CLogIter* iter=NULL  ;
       
   157     switch(aFilter->GetRequestType())
       
   158         {
       
   159         case EReadEvents :
       
   160             {
       
   161             iter = iLogService->GetListL(aFilter->getFilter()) ;
       
   162             break ;
       
   163             }
       
   164     
       
   165         case EGetEvent :
       
   166             {
       
   167             CLogsEvent *event = aFilter->GetEvent() ;
       
   168             iter = iLogService->GetEventL(event->getEvent()) ;
       
   169     
       
   170             if(iter )
       
   171                 {
       
   172                 iter->SetEventL(event) ;
       
   173                 }
       
   174     
       
   175             break ;
       
   176             }
       
   177     
       
   178         case EGetRecent :
       
   179             {
       
   180             iter = iLogService->ReadRecentEventsL( aFilter->GetRecentList(), aFilter->getFilter() ) ;
       
   181             break ;
       
   182             }
       
   183     
       
   184         default :
       
   185             {
       
   186             User :: Leave(KErrArgument) ;
       
   187             }
       
   188         }
       
   189     return iter ;
       
   190     }
       
   191 
       
   192 /**
       
   193 * Gets the event list from events from the log database asynchronously
       
   194 *
       
   195 * @param aTransId, transactionid of the async event
       
   196 * @param aFilter, search criteria for this event in event database
       
   197 * @param aCallback, call back address
       
   198 */
       
   199 EXPORT_C TInt CLoggingService :: GetListL( TUint aTransId , 
       
   200                                            CLogsFilter* aFilter ,
       
   201                                            MLoggingCallback* aCallback )
       
   202     {
       
   203     CLogAsyncService* LogAsyncService = CLogAsyncService :: NewL(aCallback) ;
       
   204     /**
       
   205      * Parse the request type and  issue the request to loggingservice
       
   206      * class accordingly
       
   207      */
       
   208     switch(aFilter->GetRequestType())
       
   209         {
       
   210         case EReadEvents :
       
   211             {
       
   212             LogAsyncService->GetListL(aTransId , aFilter->getFilter()) ;
       
   213             break ;
       
   214             }
       
   215     
       
   216         case EGetEvent :
       
   217             {
       
   218             CLogsEvent *event = aFilter->GetEvent() ;
       
   219             LogAsyncService->GetEventL(aTransId , event->getEvent()) ;
       
   220             break ;
       
   221             }
       
   222     
       
   223         case EGetRecent :
       
   224             {
       
   225             LogAsyncService->ReadRecentEventsL(aTransId , aFilter->GetRecentList(), aFilter->getFilter()) ;
       
   226             break ;
       
   227             }
       
   228     
       
   229         default :
       
   230             {
       
   231             User :: Leave(KErrArgument) ;
       
   232             }
       
   233         }
       
   234     CCallbackSlot *slot = CCallbackSlot :: NewL() ;
       
   235     slot->SetActiveObj(LogAsyncService) ;
       
   236     slot->SetUid(aTransId) ;
       
   237     iRegTable.Append(slot);
       
   238     return KErrNone ;
       
   239     }
       
   240 
       
   241 
       
   242 /**
       
   243 * Notifies the updates happening to the log database
       
   244 *
       
   245 * @param aDelay, notification interval.
       
   246 */
       
   247 
       
   248 EXPORT_C TInt CLoggingService :: NotifyUpdatesL( TUint aUid ,
       
   249                                                  TTimeIntervalMicroSeconds32 aDelay ,
       
   250                                                  MLoggingCallback *aCallback )
       
   251     {
       
   252     CLogAsyncService *AsyncService = CLogAsyncService :: NewL(aCallback);
       
   253     AsyncService->SetInterval(aDelay) ;
       
   254     AsyncService->NotifyUpdates(aUid ,aDelay) ;
       
   255     CCallbackSlot *slot = CCallbackSlot :: NewL() ;
       
   256     slot->SetActiveObj(AsyncService) ;
       
   257     slot->SetUid(aUid) ;
       
   258     iRegTable.AppendL(slot) ;
       
   259     return KErrNone ;
       
   260     }
       
   261 
       
   262 /**
       
   263 * CancelServiceL, cancels the on going service
       
   264 * @param aTransid
       
   265 */
       
   266 EXPORT_C TInt CLoggingService :: CancelServiceL( TUint aTransid )
       
   267     {
       
   268     for(TInt iterator = 0 ; iterator < iRegTable.Count() ; ++iterator)
       
   269         {
       
   270         if((iRegTable[iterator]->getUid()) == aTransid)
       
   271             {
       
   272            (iRegTable[iterator])->GetActiveObj()->Cancel() ;
       
   273             delete iRegTable[iterator];
       
   274             iRegTable[iterator]=NULL;
       
   275             iRegTable.Remove( iterator );
       
   276             iRegTable.Compress();
       
   277             return KErrNone ;
       
   278             }
       
   279         }
       
   280     
       
   281     return KErrNotFound ;
       
   282     }
       
   283 
       
   284