IMPSengine/impswatcher/Src/ImpsPushHandler.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2002 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:  ECOM plugin .dll for handling IMPS related WAP push messages.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32std.h>
       
    21 #include <CPushHandlerBase.h>
       
    22 #include <ecom/ImplementationProxy.h>
       
    23 #include <PluginKiller.h>
       
    24 #include <PushMessage.h>
       
    25 #include <PushLog.h>
       
    26 #include "ImpsPushHandler.h"
       
    27 
       
    28 // CONSTANTS
       
    29 
       
    30 _LIT8( KWVID, "WVCI*" );
       
    31 
       
    32 // ECOM framework related
       
    33 const TImplementationProxy ImplementationTable[] = 
       
    34     {
       
    35 #ifdef __EABI__
       
    36     IMPLEMENTATION_PROXY_ENTRY(0x101F4696, CImpsPushHandler::NewL)
       
    37 #else
       
    38     {{0x101F4696}, CImpsPushHandler::NewL}
       
    39 #endif
       
    40     };
       
    41 
       
    42 // ============================= LOCAL FUNCTIONS ===============================
       
    43 #ifdef _IMPS_LOGGING_ON_
       
    44 const TInt KLogBufferLength = 256;
       
    45 _LIT(KLogDir, "impswatcher");
       
    46 _LIT(KLogFile, "impspushhandlerplugin.txt");
       
    47 
       
    48 void CWatcherLogger::Log(TRefByValue<const TDesC> aFmt,...)
       
    49     {
       
    50     VA_LIST list;
       
    51     VA_START(list, aFmt);
       
    52 
       
    53     // Print to log file
       
    54     TBuf<KLogBufferLength> buf;
       
    55     buf.FormatList(aFmt, list);
       
    56 
       
    57     // Write to log file
       
    58     RFileLogger::Write(KLogDir, KLogFile, EFileLoggingModeAppend, buf);
       
    59     }
       
    60 #endif
       
    61 
       
    62 // ============================ MEMBER FUNCTIONS ===============================
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CImpsPushHandler::New
       
    66 // 1st phase constructor
       
    67 // Returns: <new CImpsPushHandler>:
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 CImpsPushHandler* CImpsPushHandler::NewL( )
       
    71     {
       
    72 #ifdef _IMPS_LOGGING_ON_
       
    73     CWatcherLogger::Log( KNewL );
       
    74 #endif
       
    75     CImpsPushHandler* self = new( ELeave ) CImpsPushHandler( );
       
    76     CleanupStack::PushL( self );
       
    77     self->ConstructL( );
       
    78     CleanupStack::Pop( self );
       
    79     return self;
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CImpsPushHandler::CImpsPushHandler
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 CImpsPushHandler::CImpsPushHandler( )
       
    87     :CPushHandlerBase()
       
    88     {
       
    89     }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CImpsPushHandler::ConstructL
       
    93 // Adds the AO to the Active Scheduler.
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 void CImpsPushHandler::ConstructL( )
       
    97     {
       
    98     // Add plugin to AS
       
    99 #ifndef _DOUNITTEST
       
   100     CActiveScheduler::Add( this );
       
   101 #endif
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CImpsPushHandler::~CImpsPushHandler
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 CImpsPushHandler::~CImpsPushHandler( )
       
   109     {
       
   110 #ifdef _IMPS_LOGGING_ON_
       
   111     CWatcherLogger::Log( KDestructor );
       
   112 #endif
       
   113 
       
   114     // AO's destructor always calls Cancel()
       
   115     Cancel( );
       
   116 
       
   117     delete iPushMsg;
       
   118 
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CImpsPushHandler::HandleMessageL
       
   123 // Starts the message handling procedure asynchronously.
       
   124 // This is not used in CL messages
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 void CImpsPushHandler::HandleMessageL(
       
   128     CPushMessage* aPushMsg,
       
   129     TRequestStatus& aStatus )
       
   130     {
       
   131 #ifdef _IMPS_LOGGING_ON_
       
   132     CWatcherLogger::Log( KHandleMessageAsync );
       
   133 #endif
       
   134 
       
   135     // We take ownership of this object and delete it ourself
       
   136     iPushMsg = aPushMsg;
       
   137     SetConfirmationStatus( aStatus );
       
   138     SignalConfirmationStatus( KErrNotSupported );
       
   139     iPluginKiller->KillPushPlugin( );
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CImpsPushHandler::HandleMessageL
       
   144 // Synchronous version of the HandleMessageL(). See asynchronous version's 
       
   145 //  description.
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 void CImpsPushHandler::HandleMessageL( CPushMessage* aPushMsg )
       
   149     {
       
   150 #ifdef _IMPS_LOGGING_ON_
       
   151     CWatcherLogger::Log( KHandleMessageSync );
       
   152 #endif
       
   153 
       
   154     // We take ownership of this object and delete it ourself
       
   155     iPushMsg = aPushMsg;  
       
   156 
       
   157     // Do sanity checks
       
   158     if( PerformCheck( ) == KErrNone )
       
   159         {
       
   160         TransferMessage( );
       
   161         }
       
   162 
       
   163     // Finish up
       
   164     iPluginKiller->KillPushPlugin( );
       
   165     }
       
   166 
       
   167 // -----------------------------------------------------------------------------
       
   168 // CImpsPushHandler::CancelHandleMessage
       
   169 // Cancels the pending asynchronous HandleMessageL.
       
   170 // This is not used in CL messages
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 void CImpsPushHandler::CancelHandleMessage( )
       
   174     {
       
   175 #ifdef _IMPS_LOGGING_ON_
       
   176     CWatcherLogger::Log( KCancelHandleMessage );
       
   177 #endif
       
   178     Cancel( );
       
   179     }
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // CImpsPushHandler::DoCancel
       
   183 // Cancels the operation.
       
   184 // This is not used in CL messages
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 void CImpsPushHandler::DoCancel( )
       
   188     {
       
   189 #ifdef _IMPS_LOGGING_ON_
       
   190     CWatcherLogger::Log( KDoCancel );
       
   191 #endif
       
   192     }
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CImpsPushHandler::RunL
       
   196 // Basically all the work is done from/through this method.
       
   197 // This is not used in CL messages
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 void CImpsPushHandler::RunL( )
       
   201     {
       
   202 #ifdef _IMPS_LOGGING_ON_
       
   203     CWatcherLogger::Log( KRun );
       
   204 #endif
       
   205 
       
   206     }
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // CImpsPushHandler::RunError
       
   210 // Called by ActiveScheduler in case RunL leaves. Currently does nothing.
       
   211 // Returns: <KErrNone>: 
       
   212 // This is not used in CL messages
       
   213 // -----------------------------------------------------------------------------
       
   214 //
       
   215 TInt CImpsPushHandler::RunError(TInt /*aError*/)
       
   216     {
       
   217 #ifdef _IMPS_LOGGING_ON_
       
   218     CWatcherLogger::Log( KRunError );
       
   219 #endif
       
   220     return KErrNone;
       
   221     }
       
   222 
       
   223 // -----------------------------------------------------------------------------
       
   224 // CImpsPushHandler::CPushHandlerBase_Reserved1
       
   225 // Reserved for future expansion.
       
   226 // -----------------------------------------------------------------------------
       
   227 //
       
   228 void CImpsPushHandler::CPushHandlerBase_Reserved1( )
       
   229     {
       
   230 #ifndef _DOUNITTEST
       
   231     User::Panic( KNotSupported, KErrNotSupported );
       
   232 #endif
       
   233     }
       
   234 
       
   235 // -----------------------------------------------------------------------------
       
   236 // CImpsPushHandler::CPushHandlerBase_Reserved2
       
   237 // Reserved for future expansion.
       
   238 // -----------------------------------------------------------------------------
       
   239 //
       
   240 void CImpsPushHandler::CPushHandlerBase_Reserved2( )
       
   241     {
       
   242 #ifndef _DOUNITTEST
       
   243     User::Panic( KNotSupported, KErrNotSupported );
       
   244 #endif
       
   245     }
       
   246 
       
   247 // -----------------------------------------------------------------------------
       
   248 // CImpsPushHandler::PerformCheck
       
   249 // Returns: <errorcode>: KErrCorrupt if the message has invalid format
       
   250 // -----------------------------------------------------------------------------
       
   251 //
       
   252 TInt CImpsPushHandler::PerformCheck( )
       
   253     {
       
   254     TInt error = KErrNone;
       
   255 
       
   256     TPtrC8 messageBodyPtr;
       
   257     TBool bodyPresent = EFalse;
       
   258     bodyPresent = iPushMsg->GetMessageBody( messageBodyPtr );
       
   259     // Check that the message begins with WVCI keyword
       
   260     if ( ( !bodyPresent ) || ( messageBodyPtr.Match( KWVID ) == KErrNotFound ) )
       
   261         {
       
   262 #ifdef _IMPS_LOGGING_ON_
       
   263         CWatcherLogger::Log( KMessageWasCorrupt );
       
   264 #endif
       
   265         error = KErrCorrupt;
       
   266         }
       
   267 
       
   268     return error;
       
   269     }
       
   270 
       
   271 // -----------------------------------------------------------------------------
       
   272 // CImpsPushHandler::TransferMessage
       
   273 // -----------------------------------------------------------------------------
       
   274 //
       
   275 void CImpsPushHandler::TransferMessage( )
       
   276     {
       
   277 #ifdef _IMPS_LOGGING_ON_
       
   278     CWatcherLogger::Log( KTransferMessage );
       
   279 #endif
       
   280     TInt serverRunning = iWatchClient.Register( );
       
   281     if( serverRunning == KErrNone )
       
   282         {
       
   283         TPtrC8 messageBodyPtr;
       
   284         TBool bodyPresent = iPushMsg->GetMessageBody( messageBodyPtr );
       
   285         if( bodyPresent )
       
   286             {
       
   287             iWatchClient.SendCIR( messageBodyPtr );
       
   288             }
       
   289         iWatchClient.UnRegister( );
       
   290         }
       
   291     }
       
   292 
       
   293 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   294 
       
   295 // -----------------------------------------------------------------------------
       
   296 // ImplementationGroupProxy
       
   297 // Returns: TImplementationProxy*: Implementation table to the ECOM framework 
       
   298 // -----------------------------------------------------------------------------
       
   299 //
       
   300 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount )
       
   301     {
       
   302     aTableCount = sizeof( ImplementationTable ) / sizeof( TImplementationProxy );
       
   303 
       
   304     return ImplementationTable;
       
   305     }
       
   306 
       
   307 
       
   308 //  End of File
       
   309