omadrm/drmhelper/drmhelperserver/src/IdleObserver.cpp
branchRCL_3
changeset 18 8a03a285ab14
parent 0 95b198f216e5
child 84 b09186059647
equal deleted inserted replaced
17:e16d72588c28 18:8a03a285ab14
    19 
    19 
    20 // INCLUDE FILES
    20 // INCLUDE FILES
    21 #include    <e32base.h>
    21 #include    <e32base.h>
    22 #include    <e32std.h>
    22 #include    <e32std.h>
    23 #include    <f32file.h>
    23 #include    <f32file.h>
    24 #include    <ActiveIdle2DomainPSKeys.h>
    24 #include    <activeidle2domainpskeys.h>
    25 #include    <e32property.h> //for RProperty
    25 #include    <e32property.h> //for RProperty
    26 #include    "IdleObserver.h"
    26 #include    "IdleObserver.h"
    27 #include    "DRMHelperServer.h"
    27 #include    "DRMHelperServer.h"
    28 
    28 
    29 // EXTERNAL DATA STRUCTURES
    29 // EXTERNAL DATA STRUCTURES
    30 // EXTERNAL FUNCTION PROTOTYPES  
    30 // EXTERNAL FUNCTION PROTOTYPES
    31 // CONSTANTS
    31 // CONSTANTS
    32 // MACROS
    32 // MACROS
    33 // LOCAL CONSTANTS AND MACROS
    33 // LOCAL CONSTANTS AND MACROS
    34 
    34 
    35 
    35 
    36 #ifdef _DRM_TESTING
    36 #ifdef _DRM_TESTING
    37 LOCAL_C void WriteFileL( const TDesC8& text , RFs &aFs , const TDesC& aName )
    37 LOCAL_C void WriteFileL( const TDesC8& text , RFs &aFs , const TDesC& aName )
    38 	{
    38     {
    39     RFile file;
    39     RFile file;
    40 	TInt size;
    40     TInt size;
    41     User::LeaveIfError( file.Open( aFs, aName , EFileWrite ) );
    41     User::LeaveIfError( file.Open( aFs, aName , EFileWrite ) );
    42     CleanupClosePushL( file );
    42     CleanupClosePushL( file );
    43     User::LeaveIfError( file.Size( size ) );
    43     User::LeaveIfError( file.Size( size ) );
    44 	User::LeaveIfError( file.Write( size, text ) );
    44     User::LeaveIfError( file.Write( size, text ) );
    45     CleanupStack::PopAndDestroy(&file); //file
    45     CleanupStack::PopAndDestroy(&file); //file
    46 	}
    46     }
    47 
    47 
    48 LOCAL_C void WriteLogL( const TDesC8& text , RFs &aFs )
    48 LOCAL_C void WriteLogL( const TDesC8& text , RFs &aFs )
    49 	{
    49     {
    50 	_LIT( KLogFile , "c:\\IOLog.txt" );
    50     _LIT( KLogFile , "c:\\IOLog.txt" );
    51 	WriteFileL( text , aFs , KLogFile );
    51     WriteFileL( text , aFs , KLogFile );
    52 	}
    52     }
    53 
    53 
    54 LOCAL_C void CreateLogL()
    54 LOCAL_C void CreateLogL()
    55 	{
    55     {
    56     RFs fs;
    56     RFs fs;
    57     User::LeaveIfError(fs.Connect());
    57     User::LeaveIfError(fs.Connect());
    58     CleanupClosePushL(fs);
    58     CleanupClosePushL(fs);
    59     RFile file;
    59     RFile file;
    60     User::LeaveIfError( file.Replace( fs , _L("c:\\IOLog.txt") , EFileWrite ) );
    60     User::LeaveIfError( file.Replace( fs , _L("c:\\IOLog.txt") , EFileWrite ) );
    61     file.Close();
    61     file.Close();
    62     CleanupStack::PopAndDestroy(&fs); //fs
    62     CleanupStack::PopAndDestroy(&fs); //fs
    63 	}
    63     }
    64 
    64 
    65 LOCAL_C void WriteL( const TDesC& aText )
    65 LOCAL_C void WriteL( const TDesC& aText )
    66 	{
    66     {
    67     RFs fs;
    67     RFs fs;
    68     User::LeaveIfError( fs.Connect() );
    68     User::LeaveIfError( fs.Connect() );
    69     CleanupClosePushL(fs);
    69     CleanupClosePushL(fs);
    70 	HBufC8* text = HBufC8::NewLC(1000);
    70     HBufC8* text = HBufC8::NewLC(1000);
    71 	TPtr8 textptr(text->Des() );
    71     TPtr8 textptr(text->Des() );
    72 	textptr.Append( aText );
    72     textptr.Append( aText );
    73     textptr.Append(_L( "\r\n" ));
    73     textptr.Append(_L( "\r\n" ));
    74 	WriteLogL(textptr , fs);
    74     WriteLogL(textptr , fs);
    75     CleanupStack::PopAndDestroy(text);
    75     CleanupStack::PopAndDestroy(text);
    76     CleanupStack::PopAndDestroy(&fs); //fs
    76     CleanupStack::PopAndDestroy(&fs); //fs
    77 	}
    77     }
    78 
    78 
    79 LOCAL_C void WriteCurrentTimeL()
    79 LOCAL_C void WriteCurrentTimeL()
    80 	{
    80     {
    81     RFs fs;
    81     RFs fs;
    82     User::LeaveIfError( fs.Connect() );
    82     User::LeaveIfError( fs.Connect() );
    83     CleanupClosePushL(fs);
    83     CleanupClosePushL(fs);
    84 	HBufC8* text = HBufC8::NewLC(100);
    84     HBufC8* text = HBufC8::NewLC(100);
    85 	TPtr8 textptr(text->Des() );
    85     TPtr8 textptr(text->Des() );
    86 // Date and Time display
    86 // Date and Time display
    87     TTime time;
    87     TTime time;
    88     time.HomeTime();
    88     time.HomeTime();
    89 	TBuf<256> dateString;
    89     TBuf<256> dateString;
    90 	_LIT(KDate,"%*E%*D%X%*N%*Y %1 %2 '%3");
    90     _LIT(KDate,"%*E%*D%X%*N%*Y %1 %2 '%3");
    91 	time.FormatL(dateString,KDate);
    91     time.FormatL(dateString,KDate);
    92 	textptr.Append(_L( "\r\n\t\tData:\t" ) );
    92     textptr.Append(_L( "\r\n\t\tData:\t" ) );
    93 	textptr.Append( dateString );
    93     textptr.Append( dateString );
    94 	_LIT(KTime,"%-B%:0%J%:1%T%:2%S%:3%+B");
    94     _LIT(KTime,"%-B%:0%J%:1%T%:2%S%:3%+B");
    95 	time.FormatL(dateString,KTime);
    95     time.FormatL(dateString,KTime);
    96 	textptr.Append(_L( "\r\n\t\tTime:\t" ) );
    96     textptr.Append(_L( "\r\n\t\tTime:\t" ) );
    97 	textptr.Append( dateString );
    97     textptr.Append( dateString );
    98 	textptr.Append(_L( "\r\n" ) );
    98     textptr.Append(_L( "\r\n" ) );
    99 	textptr.Append(_L( "\r\n" ) );
    99     textptr.Append(_L( "\r\n" ) );
   100 	WriteLogL(textptr , fs);
   100     WriteLogL(textptr , fs);
   101     CleanupStack::PopAndDestroy(text);
   101     CleanupStack::PopAndDestroy(text);
   102     CleanupStack::PopAndDestroy(&fs); //fs
   102     CleanupStack::PopAndDestroy(&fs); //fs
   103 	}
   103     }
   104 #endif
   104 #endif
   105 // MODULE DATA STRUCTURES
   105 // MODULE DATA STRUCTURES
   106 // LOCAL FUNCTION PROTOTYPES
   106 // LOCAL FUNCTION PROTOTYPES
   107 // FORWARD DECLARATIONS
   107 // FORWARD DECLARATIONS
   108 
   108 
   134 #ifdef _DRM_TESTING
   134 #ifdef _DRM_TESTING
   135     CreateLogL(); //test
   135     CreateLogL(); //test
   136 #endif
   136 #endif
   137     User::LeaveIfError( iProperty.Attach( KPSUidAiInformation, KActiveIdleState ) );
   137     User::LeaveIfError( iProperty.Attach( KPSUidAiInformation, KActiveIdleState ) );
   138     }
   138     }
   139                     
   139 
   140 // -----------------------------------------------------------------------------
   140 // -----------------------------------------------------------------------------
   141 // CIdleObserver::NewL
   141 // CIdleObserver::NewL
   142 // Two-phased constructor.
   142 // Two-phased constructor.
   143 // -----------------------------------------------------------------------------
   143 // -----------------------------------------------------------------------------
   144 //
   144 //
   145 CIdleObserver* CIdleObserver::NewL(CDRMHelperServer& aServer)
   145 CIdleObserver* CIdleObserver::NewL(CDRMHelperServer& aServer)
   146     {
   146     {
   147     CIdleObserver* self = new( ELeave ) CIdleObserver(aServer);
   147     CIdleObserver* self = new( ELeave ) CIdleObserver(aServer);
   148     
   148 
   149     CleanupStack::PushL( self );
   149     CleanupStack::PushL( self );
   150     self->ConstructL();
   150     self->ConstructL();
   151     CleanupStack::Pop(self);
   151     CleanupStack::Pop(self);
   152 
   152 
   153     return self;
   153     return self;
   154     }
   154     }
   155 
   155 
   156     
   156 
   157 // Destructor
   157 // Destructor
   158 CIdleObserver::~CIdleObserver()
   158 CIdleObserver::~CIdleObserver()
   159     {
   159     {
   160 #ifdef _DRM_TESTING
   160 #ifdef _DRM_TESTING
   161     TRAPD( err , WriteL(_L("CIdleObserver-Destruct")) ); 
   161     TRAPD( err , WriteL(_L("CIdleObserver-Destruct")) );
   162     TRAP( err , WriteCurrentTimeL() );
   162     TRAP( err , WriteCurrentTimeL() );
   163 #endif
   163 #endif
   164     Cancel();
   164     Cancel();
   165     iProperty.Close();
   165     iProperty.Close();
   166     }
   166     }
   190 // (other items were commented in a header).
   190 // (other items were commented in a header).
   191 // -----------------------------------------------------------------------------
   191 // -----------------------------------------------------------------------------
   192 //
   192 //
   193 void CIdleObserver::RunL()
   193 void CIdleObserver::RunL()
   194     {
   194     {
   195 #ifdef _DRM_TESTING 
   195 #ifdef _DRM_TESTING
   196     //test code start
   196     //test code start
   197     WriteL(_L("RunL"));
   197     WriteL(_L("RunL"));
   198     WriteCurrentTimeL();
   198     WriteCurrentTimeL();
   199     //test code end
   199     //test code end
   200 #endif
   200 #endif
   201     
   201 
   202     // Resubscribe before processing new value to prevent missing updates
   202     // Resubscribe before processing new value to prevent missing updates
   203     TInt idleStauts = 0;
   203     TInt idleStauts = 0;
   204     TInt err( iStatus.Int() );
   204     TInt err( iStatus.Int() );
   205     if (err == KErrNone)
   205     if (err == KErrNone)
   206         {
   206         {
   207         StartL();
   207         StartL();
   208         User::LeaveIfError( iProperty.Get( 
   208         User::LeaveIfError( iProperty.Get(
   209                 KPSUidAiInformation, 
   209                 KPSUidAiInformation,
   210                 KActiveIdleState, idleStauts ) );
   210                 KActiveIdleState, idleStauts ) );
   211         if ( idleStauts == EPSAiForeground ) 
   211         if ( idleStauts == EPSAiForeground )
   212             {
   212             {
   213             iServer.HandleIdleL();
   213             iServer.HandleIdleL();
   214             }
   214             }
   215         }
   215         }
   216     else if ( err != KErrCancel )
   216     else if ( err != KErrCancel )
   217         {
   217         {
   218         StartL();
   218         StartL();
   219         }  
   219         }
   220     }
   220     }
   221 
   221 
   222 // -----------------------------------------------------------------------------
   222 // -----------------------------------------------------------------------------
   223 // CIdleObserver::DoCancel
   223 // CIdleObserver::DoCancel
   224 // From CActive
   224 // From CActive
   233 #endif
   233 #endif
   234     iProperty.Cancel();
   234     iProperty.Cancel();
   235     }
   235     }
   236 
   236 
   237 // ========================== OTHER EXPORTED FUNCTIONS =========================
   237 // ========================== OTHER EXPORTED FUNCTIONS =========================
   238 //  End of File  
   238 //  End of File