terminalsecurity/SCP/DmEventNotifier/src/DmEventHandler.cpp
changeset 0 b497e44ab2fc
child 5 3f7d9dbe57c8
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2  * Copyright (c) 2009 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: This is the entry point of the application
       
    15  *
       
    16  */
       
    17 
       
    18 //System include
       
    19 #include <schinfo.h>
       
    20 #include <schtask.h>
       
    21 #include <s32file.h>
       
    22 #include <e32math.h>
       
    23 #include <e32cons.h>
       
    24 #include <e32property.h>
       
    25 
       
    26 //User include
       
    27 #include "DmEventScheduler.h"
       
    28 #include "DmEventNotifierDebug.h"
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // InvokeNotifiersL - This function is called to notify servers on any event
       
    32 // -----------------------------------------------------------------------------
       
    33 LOCAL_D void InvokeNotifiersL(RFile& aTaskFile)
       
    34     {
       
    35     FLOG(_L("DmEventHandler InvokeNotifiersL >>"));
       
    36 
       
    37     CFileStore*         store;
       
    38     RStoreReadStream    instream;
       
    39     // Get tasks from scheduler's store
       
    40     store = CDirectFileStore::FromLC(aTaskFile);
       
    41     instream.OpenLC(*store,store->Root());
       
    42     TInt count = instream.ReadInt32L();
       
    43     FLOG(_L("SwInstallhandler  task count  %d"),count );
       
    44 
       
    45     CScheduledTask* task = CScheduledTask::NewLC(instream);
       
    46     HBufC* b = const_cast<HBufC*>(&(task->Data()));
       
    47     TPtr ptr = b->Des();
       
    48     TName taskname(ptr);
       
    49 
       
    50     CleanupStack::PopAndDestroy (task);
       
    51     CleanupStack::PopAndDestroy( &instream );
       
    52     CleanupStack::PopAndDestroy( store );
       
    53 
       
    54 
       
    55     FLOG(_L("Waiting for completion..."));
       
    56     CDmEventScheduler* sch = CDmEventScheduler::NewLC();
       
    57     sch->WaitAndCreateConditionScheduleL(taskname);
       
    58     CleanupStack::PopAndDestroy(sch);
       
    59 
       
    60     FLOG(_L("DmEventHandler InvokeNotifiersL <<"));
       
    61     }
       
    62 
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // ExecuteL - This function is called to check if check the purpose of invocation
       
    66 //  of this executable
       
    67 // -----------------------------------------------------------------------------
       
    68 LOCAL_D TInt ExecuteL()
       
    69     {
       
    70     FLOG(_L("DmEventHandler ExecuteL...>>"));
       
    71     TInt err = KErrNoMemory;
       
    72 
       
    73     RFile file;
       
    74 
       
    75     // Adopt the task file from the Task Scheduler
       
    76     err = file.AdoptFromCreator(TScheduledTaskFile::FsHandleIndex(),
       
    77             TScheduledTaskFile::FileHandleIndex());
       
    78     FLOG(_L("  err  %d"),err );
       
    79 
       
    80 
       
    81     if (KErrNone == err)
       
    82         {
       
    83         TRAP(err, InvokeNotifiersL(file));
       
    84         FLOG(_L("Error = %d"), err);
       
    85         }
       
    86     else if (KErrNotFound == err)
       
    87         {
       
    88         //If err =-1, certain that there is no task scheduled. So, start and register the condition schedule
       
    89         CDmEventScheduler* sch = CDmEventScheduler::NewLC();
       
    90         sch->CreateConditionScheduleL();
       
    91         CleanupStack::PopAndDestroy(sch);
       
    92         }
       
    93     else
       
    94         __LEAVE_IF_ERROR(err);
       
    95 
       
    96     file.Close();
       
    97 
       
    98     FLOG(_L("DmEventHandler ExecuteL...<<"));
       
    99     return err;
       
   100     }
       
   101 
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // Execute - This is called by the entry point
       
   105 // -----------------------------------------------------------------------------
       
   106 LOCAL_D TInt Execute()
       
   107     {
       
   108     __UHEAP_MARK;
       
   109     FLOG(_L("DmEventHandler Execute() >>"));
       
   110 
       
   111     TInt err = KErrNoMemory;
       
   112 
       
   113     // construct and install active scheduler
       
   114     CActiveScheduler* scheduler = new CActiveScheduler;
       
   115     if (!scheduler)
       
   116         {
       
   117         return err;
       
   118         }
       
   119     CActiveScheduler::Install(scheduler);
       
   120     CTrapCleanup* cleanupStack = CTrapCleanup::New();
       
   121 
       
   122     if (cleanupStack)
       
   123         {
       
   124         TRAP(err, ExecuteL());
       
   125         delete cleanupStack; cleanupStack = NULL;
       
   126         }
       
   127     delete scheduler; scheduler = NULL;
       
   128     
       
   129     FLOG(_L("DmEventHandler Execute() <<"));
       
   130     __UHEAP_MARKEND;
       
   131     return err;
       
   132     }
       
   133 
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // E32Main - The entry point of this executable
       
   137 // -----------------------------------------------------------------------------
       
   138 GLDEF_C TInt E32Main()
       
   139     {
       
   140     return Execute();
       
   141     }
       
   142 // End of File