eventsui/eventshandlerui/eventshandler/src/evthandler.cpp
branchRCL_3
changeset 17 1fc85118c3ae
parent 16 8173571d354e
child 18 870918037e16
equal deleted inserted replaced
16:8173571d354e 17:1fc85118c3ae
     1 /*
       
     2 * Copyright (c) 2008 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:  Client Provider for Events Handler Server
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //INCLUDE FILES
       
    20 
       
    21 //SYSTEM INCLUDES
       
    22 #include <e32base.h>
       
    23 #include <bacline.h> 		// CCommandLineArguments
       
    24 
       
    25 //USER INCLUDES
       
    26 #include "evthandler.h"
       
    27 #include "evthandlerclientserver.h"
       
    28 #include "evthandlerclient.h"
       
    29 #include "evthandlerserverconsts.h"
       
    30 #include "evtdebug.h"
       
    31 #include "evtmgmtuiengine.h"
       
    32 #include "evtevent.h"
       
    33 #include "evteventmanager.h"
       
    34 
       
    35 //CONSTANTS
       
    36 _LIT( KEventId,"%d");
       
    37 _LIT(KEvtHandler,"Handler Ui Panic");
       
    38 static const TInt KSchedulerCreate = 1;
       
    39 
       
    40 // ----------------------------------------------------------------------------
       
    41 // void EvtHandlerStartup::HandleEventL()
       
    42 // ----------------------------------------------------------------------------
       
    43 //
       
    44 void EvtHandlerStartup::HandleEventL()
       
    45 	{
       
    46 	EVTUIDEBUG("+ EvtHandlerStartup::HandleEventL()");
       
    47 	TBuf<KEvtCommandMessageLength> cmdArg;
       
    48 	TBuf<KEventIdLength> eventId;
       
    49     TEvtConsoleAction evtAction = EEvtActionNone;
       
    50 	TEvtEventId evtId = 0;
       
    51 	TInt action=0;
       
    52 	TBool isValidEventId = EFalse;
       
    53 	
       
    54 	// create and install the active scheduler we need
       
    55 	CActiveScheduler* scheduler=new(ELeave) CActiveScheduler;
       
    56 	__ASSERT_ALWAYS(scheduler!=NULL,User::Panic(KEvtHandler, KSchedulerCreate));
       
    57 	CleanupStack::PushL(scheduler);
       
    58 	CActiveScheduler::Install(scheduler);  
       
    59 
       
    60 	while( ETrue )
       
    61 		{
       
    62 		//Create CommandLine Arguments and read it.
       
    63 		CCommandLineArguments* args = CCommandLineArguments::NewLC();
       
    64 		// check for valid argument count
       
    65 		TInt cnt = args->Count();
       
    66         TPtrC cmdPrt1( args->Arg( 0 ) );
       
    67 		if( cnt == 2 ) // 2 - Process name, Console Action:Event Id
       
    68 			{
       
    69 			TPtrC cmdPrt( args->Arg( 1 ) ); // read first argument - Console Action:Event Id
       
    70 			cmdArg.Copy( cmdPrt );
       
    71 			}
       
    72 		CleanupStack::PopAndDestroy( args );
       
    73 		
       
    74 		// Check for valid arguments 
       
    75 		if( cmdArg.Length() <= 0 )
       
    76 			{
       
    77 			break;
       
    78 			}
       
    79 		
       
    80 		// Extract the Action for Event
       
    81 		TLex lex( cmdArg );
       
    82 		TInt errorCode = lex.Val( action );
       
    83 		if( errorCode != KErrNone)
       
    84 			{
       
    85 			break;
       
    86 			}
       
    87 		
       
    88 		// Get the meaningful Action.
       
    89 		evtAction = static_cast<TEvtConsoleAction>(action);
       
    90         
       
    91         // Increment the Delimiter
       
    92         lex.Inc();
       
    93 
       
    94         // Extract the Id of Event
       
    95 		errorCode = lex.Val( evtId, EDecimal );
       
    96         if( errorCode != KErrNone)
       
    97             {
       
    98             break;
       
    99             }
       
   100         
       
   101         // Format the Event Id buffer
       
   102 		eventId.Format( KEventId, evtId );
       
   103 		
       
   104 		// Set the Valid Event Id flag as True 
       
   105 		isValidEventId = ETrue;
       
   106 		break;
       
   107 		}
       
   108 
       
   109 	if ( isValidEventId )
       
   110 		{
       
   111 		EVTUIDEBUG1("EvtHandlerStartup::HandleEventL - Event Id %S",&eventId);
       
   112 		
       
   113 		// Create an engine instance to handle the requested actions.
       
   114 		CEvtMgmtUiEngine* engine = CEvtMgmtUiEngine::NewLC();
       
   115 		
       
   116 		switch( evtAction )
       
   117 		    {
       
   118 		    case EEvtActionFired:
       
   119 				{
       
   120 		        // Calculate the Accuracy of the Fired Event
       
   121 		        TEvtFireAccuracy accuracy = engine->CalculateFiredAccuracyL( evtId );
       
   122 		        
       
   123 		        // Launch the Server to handle the fired event
       
   124 		        REvtHandlerSession popupClient;
       
   125 		        CleanupClosePushL( popupClient );
       
   126 		        User::LeaveIfError( popupClient.Connect() );
       
   127 		        popupClient.SendEventId( eventId, accuracy );
       
   128 		        CleanupStack::PopAndDestroy( );   // popupClient
       
   129 		        break;
       
   130 				}
       
   131 		    case EEvtActionChangeState:
       
   132 		        {
       
   133 				// Handle the Change State
       
   134 		        engine->HandleFiredTriggerStateL( evtId );
       
   135 		        break;
       
   136 				}
       
   137 		    default:
       
   138 		        break;
       
   139 		    }
       
   140 		
       
   141 		CleanupStack::PopAndDestroy( );	// engine
       
   142 		}
       
   143 	
       
   144 	// Delete active scheduler
       
   145    	CleanupStack::PopAndDestroy(scheduler);
       
   146    	
       
   147 	EVTUIDEBUG("- EvtHandlerStartup::HandleEventL()");
       
   148 	}
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // TInt EvtHandlerServerStartup::StartEvtHandlerServer()
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 TInt EvtHandlerStartup::StartEvtHandler()
       
   155     {
       
   156 	EVTUIDEBUG("+ EvtHandlerStartup::StartEvtHandler()");
       
   157     __UHEAP_MARK;
       
   158     CTrapCleanup* cleanupStack = CTrapCleanup::New();
       
   159     TInt ret = KErrNoMemory;
       
   160     if ( cleanupStack )
       
   161         {
       
   162         TRAP(ret, HandleEventL());
       
   163         delete cleanupStack;
       
   164         }
       
   165     __UHEAP_MARKEND;
       
   166 	EVTUIDEBUG("- EvtHandlerStartup::StartEvtHandler()");
       
   167     return ret;    
       
   168     }
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // TInt E32Main
       
   172 // Server process entry-point
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 TInt E32Main()
       
   176     {
       
   177 	EVTUIDEBUG("+ E32Main()");
       
   178     return EvtHandlerStartup::StartEvtHandler();    
       
   179     }
       
   180 
       
   181 // End of File