examples/Messaging/BIOMessageMgr/Src/BIOMessage.cpp

00001 /*
00002 Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010   this list of conditions and the following disclaimer in the documentation
00011   and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013   may be used to endorse or promote products derived from this software
00014   without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description:  
00028 */
00029 
00030 
00031 #include "BIOMessage.h"
00032 
00033 
00034 CBioMessage::CBioMessage()
00035         {       
00036                 
00037         }
00038 
00044 CBioMessage::~CBioMessage()
00045         {       
00046         iSendAs.Close();
00047         delete iConsole;
00048         }
00049 
00050 CBioMessage* CBioMessage::NewL()
00051         {
00052         CBioMessage* self = new (ELeave) CBioMessage();
00053         CleanupStack::PushL(self);
00054         self->ConstructL();
00055         CleanupStack::Pop();
00056         return self;
00057         }
00058 
00062 void CBioMessage::ConstructL()
00063         {
00064         
00065         iConsole = Console::NewL(KTestTitle,TSize(KConsFullScreen,KConsFullScreen));
00066         _LIT(KTextWelcome, "### BIO messaging ### \n");
00067         iConsole->Printf ( KTextWelcome );
00068 
00069         _LIT(KTextStartApp, "\n Starting the BIO message application ............ \n");
00070         iConsole->Printf ( KTextStartApp );
00071         
00072         _LIT(KTextPressAKey, "\n Press any key to step through the example ............ \n");
00073         iConsole->Printf ( KTextPressAKey );
00074         iConsole->Getch ();
00075 
00076         _LIT(KTextInit, "\n #1. Intializing ............ \n");
00077         iConsole->Printf ( KTextInit );
00078         
00079         iConsole->Getch ();     
00080                 
00081         }       
00082 
00083 void CBioMessage::StartL()
00084         {
00085         Connect();
00086         RSendAsMessage message;
00087         CreateL(message);
00088         SendL(message);
00089         
00090         _LIT(KTextParserTitle, " \n\n### BIO Message Parsing ### \n");
00091         iConsole->Printf ( KTextParserTitle );
00092         
00093         ParseL();       
00094         CleanupStack::PopAndDestroy(4, iObserver); //selection, iEntry, iSession, iObserver
00095         }
00096 
00102 void CBioMessage::Connect()
00103         {
00104         _LIT(KTextConn, "\n #2. Connecting to message server ............ \n");
00105         iConsole->Printf ( KTextConn );
00106         iConsole->Getch ();
00107 
00108         TInt err = iSendAs.Connect(KSendAsDefaultMessageSlots);
00109         if ( err == KErrNone)
00110                 {
00111                 _LIT(KTextErrInn, "\n Connection is successful\n");
00112                 iConsole->Printf ( KTextErrInn );
00113 
00114                 }
00115         else
00116                 {
00117                 _LIT(KTextErrOut, "\n\n Connection has failed\n");
00118                 iConsole->Printf ( KTextErrOut );
00119                 }
00120         }
00121 
00122 void CBioMessage::CleanMailFolderL(TMsvId aFolderId)
00123         {
00124         CDummyObserver* observer = new(ELeave) CDummyObserver;
00125         CleanupStack::PushL(observer);
00126         CMsvSession* session = CMsvSession::OpenSyncL(*observer);
00127         CleanupStack::PushL(session);   
00128         CMsvEntry* entry = CMsvEntry::NewL(*session, aFolderId, 
00129                 TMsvSelectionOrdering(KMsvNoGrouping,EMsvSortByNone,ETrue));
00130         CleanupStack::PushL(entry);
00131         
00132         CMsvEntrySelection* selection = entry->ChildrenL();
00133         CleanupStack::PushL(selection);
00134 
00135         TMsvLocalOperationProgress progress;
00136         if (selection->Count() > 0)
00137                 {
00138                 entry->DeleteL(*selection, progress);
00139                 }
00140 
00141         CleanupStack::PopAndDestroy(4); // selection, entry, session, observer
00142         }
00143 
00148 void CBioMessage::CreateL( RSendAsMessage& aMessage)
00149         {
00150         CSendAsMessageTypes* messageTypes = CSendAsMessageTypes::NewL();
00151         CleanupStack::PushL(messageTypes);      
00152 
00153         iSendAs.FilteredMessageTypesL(*messageTypes);
00154 
00155         TUid sendAsMtmUid;
00156                 
00157         // Returning the message UID based on the message type 
00158         // such as 0 for SMTP Client, 1 for SMS Client, 2 for Infrared client MTM and 3 for Bluetooth client MTM.
00159         sendAsMtmUid = messageTypes->UidFromNameL(_L("SMS Client"));
00160         
00161         CleanupStack::PopAndDestroy(messageTypes);      
00162 
00163         _LIT(KTextCreate, "\n #3. Creating a BIO message ............ \n");
00164         iConsole->Printf ( KTextCreate );
00165         iConsole->Getch ();
00166         
00167         CleanMailFolderL(KMsvDraftEntryId);
00168         
00169         iObserver = new(ELeave) CDummyObserver;
00170         CleanupStack::PushL(iObserver);
00171         iSession = CMsvSession::OpenSyncL(*iObserver);
00172         CleanupStack::PushL(iSession);
00173         iEntry = CMsvEntry::NewL(*iSession, KMsvDraftEntryId, 
00174         TMsvSelectionOrdering(KMsvNoGrouping,EMsvSortByNone,ETrue));
00175         CleanupStack::PushL(iEntry);
00176 
00177         iSelection = iEntry->ChildrenL();
00178         CleanupStack::PushL(iSelection);
00179         
00180         TInt count = iSelection->Count();
00181         if ( count == 0) // Check no message
00182                 {
00183                 CleanupStack::PopAndDestroy(iSelection);
00184                 iSelection = NULL;
00185                 }       
00186 
00187         aMessage.CreateL(iSendAs, sendAsMtmUid);
00188         aMessage.SetBodyTextL(KBodyText);
00189         aMessage.AddRecipientL(KAddress1, KAlias1, RSendAsMessage::ESendAsRecipientTo);
00190         aMessage.AddRecipientL(KAddress3, RSendAsMessage::ESendAsRecipientCc);
00191         aMessage.AddRecipientL(KAddress4, KAlias2, RSendAsMessage::ESendAsRecipientCc);
00192 
00193         TUid bioType = KUidBIOVCardMsg;
00194         aMessage.SetBioTypeL(bioType);  
00195         iEntry->SetEntryL(KMsvSentEntryId);
00196         
00197         
00198                 
00199         iEntry->SetEntryL(KMsvDraftEntryId);
00200         iSelection = iEntry->ChildrenL();
00201         CleanupStack::PushL(iSelection);        
00202         if(iSelection->Count() >= 1)
00203                 {
00204                 iEntry->SetEntryL((*iSelection)[0]);
00205                 }
00206         }
00207 
00212 void CBioMessage::SendL(RSendAsMessage& aMessage)
00213         {
00214         _LIT(KTextSend, "\n #4. Sending the BIO message ............ \n");
00215         iConsole->Printf ( KTextSend );
00216         iConsole->Getch ();
00217         
00218         CMsvOperationWait* wait = CMsvOperationWait::NewLC();
00219         wait->iStatus = KRequestPending;
00220         wait->Start();
00221         
00222         aMessage.SendMessageAndCloseL();
00223         
00224         CleanupStack::PopAndDestroy();  // wait
00225         
00226         _LIT(KTextClose, "\n The BIO message has been sent \n");
00227         iConsole->Printf ( KTextClose );
00228         iConsole->Getch ();
00229         }
00230 
00234 void CBioMessage::ParseL()
00235         {
00236         _LIT(KTextParse, "\n #5. Parsing the BIO message ............ \n");
00237         iConsole->Printf ( KTextParse );
00238         iConsole->Getch ();
00239         
00240         CBioParser* bioParser = CBioParser::NewL(iEntry);
00241         bioParser->ParserL();
00242         
00243         _LIT(KTextParsed, "\n The BIO message has been parsed \n");
00244         iConsole->Printf ( KTextParsed );
00245         iConsole->Getch ();
00246         
00247         delete bioParser;
00248         }
00249 
00250 LOCAL_C void MainL()
00251         {
00252         CActiveScheduler* scheduler = new (ELeave) CActiveScheduler;
00253         CActiveScheduler::Install( scheduler );
00254         
00255         CBioMessage* app = CBioMessage::NewL();
00256         CleanupStack::PushL(app);
00257         app->StartL();
00258         CleanupStack::PopAndDestroy(app);
00259         
00260         delete scheduler;
00261         }
00262 
00263 GLDEF_C TInt E32Main()
00264         {
00265     __UHEAP_MARK;
00266     CTrapCleanup* cleanup = CTrapCleanup::New();
00267     if(cleanup == NULL)
00268         {
00269         return KErrNoMemory;
00270         }
00271     TRAPD(err, MainL());
00272         if(err != KErrNone)
00273                 {       
00274                 User::Panic(_L("failed to complete"),err);
00275                 }
00276 
00277     delete cleanup;
00278     __UHEAP_MARKEND;
00279     return KErrNone;
00280         }

Generated by  doxygen 1.6.2