localconnectivityservice/generichid/tsrc/GenericHidTest/src/alarmcontrol.cpp
branchRCL_3
changeset 42 0aa8cc770c8a
equal deleted inserted replaced
40:453dfc402455 42:0aa8cc770c8a
       
     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:  Dialhandling class for hid test application
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "alarmcontrol.h"
       
    20 #include "ASShdAlarm.h"
       
    21 #include "asshddefs.h"
       
    22 
       
    23 _LIT(KSoundName, "a");    // For the alarm alert note.
       
    24 const TUid KAlarmClockOne = { 0x101F793A };
       
    25 
       
    26 // ---------------------------------------------------------------------------
       
    27 // NewL
       
    28 // ---------------------------------------------------------------------------
       
    29 //
       
    30 CAlarmControl* CAlarmControl::NewL( CStifLogger* aLogger )
       
    31     {
       
    32     CAlarmControl* self = CAlarmControl::NewLC(aLogger);
       
    33     CleanupStack::Pop( self );
       
    34     return self;
       
    35     }
       
    36 
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // NewLC
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 CAlarmControl* CAlarmControl::NewLC( CStifLogger* aLogger )
       
    43     {
       
    44     CAlarmControl* self = new( ELeave ) CAlarmControl(aLogger);
       
    45     CleanupStack::PushL( self );
       
    46     self->ConstructL();
       
    47     return self;
       
    48     }
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // Constructor
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 CAlarmControl::CAlarmControl( CStifLogger* aLogger ):
       
    55 iLog(aLogger)
       
    56     {
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // destructor
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 CAlarmControl::~CAlarmControl()
       
    64     {
       
    65     if (iAlarmServer.Handle() != KNullHandle)
       
    66         {
       
    67         iAlarmServer.Close();    
       
    68         }    
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // ConstructL
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 void CAlarmControl::ConstructL()
       
    76     {   
       
    77     User::LeaveIfError(iAlarmServer.Connect());
       
    78     }
       
    79 // ---------------------------------------------------------------------------
       
    80 // CreateClockAlarm
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 void CAlarmControl::CreateClockAlarm( TInt aTime )
       
    84     {
       
    85     STIF_LOG("CreateClockAlarm");
       
    86     TInt minute;
       
    87     TTime tmp;
       
    88     tmp.HomeTime();
       
    89     TDateTime alarmdtime = tmp.DateTime();
       
    90     minute = alarmdtime.Minute();
       
    91     minute = minute+aTime;
       
    92     alarmdtime.SetMinute(minute);
       
    93     
       
    94     STIF_LOG("CreateClockAlarm solve minutes");
       
    95     TASShdAlarm alarm;
       
    96     alarm.Category() = KAlarmClockOne;
       
    97     alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatOnce;
       
    98     alarm.OriginalExpiryTime() = alarmdtime;
       
    99     alarm.NextDueTime() = alarmdtime;
       
   100     alarm.SoundName() = KSoundName;
       
   101     
       
   102     STIF_LOG("CreateClockAlarm solve data");
       
   103     alarm.ClientFlags().Set( 0 );
       
   104     
       
   105     STIF_LOG("CreateClockAlarm solve add alarm");
       
   106     iAlarmServer.AlarmAdd(alarm);
       
   107     iAlarmID = alarm.Id();
       
   108     
       
   109     STIF_LOG("CreateClockAlarm solve add activate alarm");
       
   110     iAlarmServer.SetAlarmStatus(iAlarmID, EAlarmStatusEnabled);
       
   111     
       
   112     STIF_LOG("CreateClockAlarm completed");
       
   113     }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // CreateClockAlarm
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 void CAlarmControl::DeleteAlarm()
       
   120     {
       
   121     iAlarmServer.AlarmDelete(iAlarmID);
       
   122     }