mobilemessaging/smsmtm/test/class0smsnotifier/src/class0smsTxtnotifier.cpp
changeset 31 ebfee66fde93
parent 0 72b543305e3a
equal deleted inserted replaced
30:6a20128ce557 31:ebfee66fde93
       
     1 // Copyright (c) 2007-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 // class0smsnotifier.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "class0smsTxtnotifier.h"
       
    19 #include <tmsvpackednotifierrequest.h>
       
    20 #include <gsmubuf.h>
       
    21 #include <s32mem.h>
       
    22 #include <e32base.h>
       
    23 
       
    24 
       
    25 
       
    26 /* UID of Class 0 SMS test notifier */
       
    27 const TUid KClass0SmsNotifierPluginUid  = {0x2000C382};
       
    28 const TUid KClass0SmsNotifierOutput 	= {0x2000C382};
       
    29 
       
    30 //class 0 SMS data will be writing to file
       
    31 _LIT(KTestClas0Sms, "\\logs\\testexecute\\class0sms.txt");
       
    32 
       
    33 EXPORT_C CArrayPtr<MNotifierBase2>* NotifierArray()
       
    34 	{
       
    35 	CArrayPtrFlat<MNotifierBase2>* subjects=NULL;
       
    36 	TRAPD( err, subjects=new (ELeave)CArrayPtrFlat<MNotifierBase2>(1) );
       
    37 	if( err == KErrNone )
       
    38 		{
       
    39 		TRAP( err, subjects->AppendL( CClass0SmsTxtNotifier::NewL()) );
       
    40 		return(subjects);
       
    41 		}
       
    42 	else
       
    43 		{
       
    44 		return NULL;
       
    45 		}
       
    46 	}
       
    47 
       
    48 CClass0SmsTxtNotifier* CClass0SmsTxtNotifier::NewL()
       
    49 	{
       
    50 	CClass0SmsTxtNotifier* self=new (ELeave) CClass0SmsTxtNotifier();
       
    51 	CleanupStack::PushL(self);
       
    52 	self->ConstructL();
       
    53 	CleanupStack::Pop(self);
       
    54 	return self;
       
    55 	}
       
    56 	
       
    57 void CClass0SmsTxtNotifier::ConstructL()
       
    58 	{
       
    59 	}
       
    60 
       
    61 CClass0SmsTxtNotifier::~CClass0SmsTxtNotifier()
       
    62 	{
       
    63 	}
       
    64 
       
    65 CClass0SmsTxtNotifier::CClass0SmsTxtNotifier()
       
    66 	{
       
    67 	iInfo.iUid      = KClass0SmsNotifierPluginUid;
       
    68 	iInfo.iChannel  = KClass0SmsNotifierOutput;
       
    69 	iInfo.iPriority = ENotifierPriorityHigh;
       
    70 	}
       
    71 
       
    72 void CClass0SmsTxtNotifier::Release()
       
    73 	{
       
    74 	}
       
    75 
       
    76 /**
       
    77 Called when a notifier is first loaded to allow any initial construction that is required.
       
    78  */
       
    79 CClass0SmsTxtNotifier::TNotifierInfo CClass0SmsTxtNotifier::RegisterL()
       
    80 	{
       
    81 	return iInfo;
       
    82 	}
       
    83 
       
    84 CClass0SmsTxtNotifier::TNotifierInfo CClass0SmsTxtNotifier::Info() const
       
    85 	{
       
    86 	return iInfo;
       
    87 	}
       
    88 	
       
    89 /**
       
    90 The notifier has been deactivated so resources can be freed and outstanding messages completed.
       
    91  */
       
    92 void CClass0SmsTxtNotifier::Cancel()
       
    93 	{
       
    94 	}
       
    95 
       
    96 /**
       
    97 Start the Notifier with data aBuffer. 
       
    98 
       
    99 Not used for confirm notifiers
       
   100 */
       
   101 TPtrC8 CClass0SmsTxtNotifier::StartL(const TDesC8& aBuffer)
       
   102 	{
       
   103 	CreateFile(aBuffer);
       
   104 	return KNullDesC8(); 
       
   105 	}
       
   106 	
       
   107 /**
       
   108 Start the notifier with data aBuffer. aMessage should be completed when the notifier is deactivated.
       
   109 
       
   110 May be called multiple times if more than one client starts the notifier. The notifier is immediately 
       
   111 responsible for completing aMessage.
       
   112 */
       
   113 void CClass0SmsTxtNotifier::StartL(const TDesC8& aBuffer, TInt /*aReplySlot*/, const RMessagePtr2& aMessage)
       
   114 	{
       
   115 	// extract the notifier request parameters
       
   116 	CreateFile(aBuffer);
       
   117 	aMessage.Complete(KErrNone);
       
   118 	}
       
   119 	
       
   120 /**
       
   121 Update a currently active notifier with data aBuffer.
       
   122 
       
   123 Not used for confirm notifiers
       
   124 */
       
   125 TPtrC8 CClass0SmsTxtNotifier::UpdateL(const TDesC8& aBuffer)
       
   126 	{
       
   127 	CreateFile(aBuffer);
       
   128 	return KNullDesC8();
       
   129 	}
       
   130 
       
   131 
       
   132 //write received class0sms data to file
       
   133 void CClass0SmsTxtNotifier::CreateFile(const TDesC8& aBuff)
       
   134 {
       
   135 	RFs fs;
       
   136 	User::LeaveIfError(fs.Connect());
       
   137 	CleanupClosePushL(fs);
       
   138 	
       
   139 	TInt startPos, endPos;
       
   140 	TBool isLastMessage = EFalse;
       
   141 	
       
   142 	RDesReadStream readStream(aBuff);
       
   143 	CleanupClosePushL (readStream);
       
   144 		
       
   145 	startPos = readStream.ReadInt32L();
       
   146 	endPos = readStream.ReadInt32L();
       
   147 	isLastMessage = readStream.ReadInt32L();
       
   148 	
       
   149 	TBuf<1000> smsMsg1;
       
   150 	readStream >> smsMsg1;
       
   151 		
       
   152 	RFile file;
       
   153 
       
   154 	TPtrC8 smsMsg(REINTERPRET_CAST(const TUint8*, smsMsg1.Ptr()), smsMsg1.Size()); 
       
   155 	User::LeaveIfError(file.Replace(fs, KTestClas0Sms, EFileShareAny | EFileWrite));
       
   156 	file.Write(smsMsg);
       
   157 	
       
   158 	file.Close();
       
   159 	CleanupStack::PopAndDestroy(&readStream);
       
   160 	CleanupStack::PopAndDestroy(&fs);
       
   161 }