commonappservices/alarmservertest/TestAlarmSrv/AlarmCreateDelete/AlarmCreate.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <e32base.h>
       
    17 #include <asclisession.h>
       
    18 #include <asshdalarm.h>
       
    19 
       
    20 LOCAL_D RASCliSession asCliSession;
       
    21 
       
    22 LOCAL_C TBool AlarmExistsL()
       
    23 	{
       
    24 	// Get security info of this process.
       
    25 	TSecurityInfo info;
       
    26 	info.Set(RProcess());
       
    27 	
       
    28 	// Get list of alarms
       
    29 	RArray<TAlarmId> alarmIds;
       
    30 	//__UHEAP_MARK;
       
    31 	asCliSession.GetAlarmIdListL(alarmIds);
       
    32 	//__UHEAP_MARKEND;
       
    33 	
       
    34 	TInt i;
       
    35 	for(i = 0; i < alarmIds.Count(); i++)
       
    36 		{
       
    37 		TASShdAlarm alarm;
       
    38 		
       
    39 		TInt err = asCliSession.GetAlarmDetails(alarmIds[i], alarm);
       
    40 		
       
    41 		TSecureId sidOfAlarm = alarm.GetSid();
       
    42 		if(info.iSecureId == sidOfAlarm)
       
    43 			{
       
    44 			// Already an alarm with the same SID of this process exists.
       
    45 			// No need to create another
       
    46 			alarmIds.Reset();
       
    47 			return ETrue;	
       
    48 			}
       
    49 		}
       
    50 		alarmIds.Reset();
       
    51 		return EFalse;
       
    52 	}
       
    53 	
       
    54 LOCAL_C void MainL()
       
    55 	{
       
    56 	asCliSession = RASCliSession();
       
    57 	User::LeaveIfError(asCliSession.Connect());
       
    58 
       
    59 	if( !AlarmExistsL() )
       
    60 		{
       
    61 		TASShdAlarm alarm;
       
    62 		alarm.Category() = KASCliCategoryClock;
       
    63 		alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
    64 		alarm.NextDueTime().HomeTime();
       
    65 			
       
    66 		TInt minutes = 60;
       
    67 		alarm.NextDueTime() += TTimeIntervalMinutes(minutes);
       
    68 			
       
    69 		asCliSession.AlarmAdd(alarm);
       
    70 		}
       
    71 	}
       
    72 
       
    73 GLDEF_C int E32Main()
       
    74 	{
       
    75 	__UHEAP_MARK;
       
    76 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
    77 	if(!cleanup)
       
    78 	{
       
    79 		return KErrNoMemory;
       
    80 	}
       
    81 	TRAPD(err, MainL());
       
    82 	delete cleanup;
       
    83 	__UHEAP_MARKEND;
       
    84 	return err;
       
    85 	}
       
    86