|
1 // Copyright (c) 2004-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 // |
|
15 |
|
16 #include <e32base.h> |
|
17 #include "pigeonservermtm.h" |
|
18 #include <msvapi.h> |
|
19 #include <msvids.h> |
|
20 #include <msvuids.h> |
|
21 #include <msvschedulepackage.h> |
|
22 #include <msvschedulesend.h> |
|
23 #include <msvschedulesettings.h> |
|
24 |
|
25 |
|
26 class CSessionObserver : public MMsvSessionObserver, public CBase |
|
27 { |
|
28 public: |
|
29 void HandleSessionEventL(TMsvSessionEvent,TAny*,TAny*,TAny*) {}; |
|
30 }; |
|
31 |
|
32 LOCAL_C TBool FindOrCreateScheduleL(RScheduler& aScheduler, const TTime& aTime, const CMsvScheduleSettings& aSettings, TSchedulerItemRef& aRef) |
|
33 { |
|
34 TRAPD(err, CMsvScheduleSend::FindScheduleL(aScheduler, aTime, aRef)); |
|
35 |
|
36 if( err != KErrNone ) |
|
37 CMsvScheduleSend::CreateScheduleL(aScheduler, aSettings, aTime, aSettings.ValidityPeriod(), aRef); |
|
38 |
|
39 return (err == KErrNone); |
|
40 } |
|
41 |
|
42 LOCAL_C void DoExecuteL() |
|
43 { |
|
44 CActiveScheduler* activeScheduler = new (ELeave) CActiveScheduler(); |
|
45 CleanupStack::PushL(activeScheduler); |
|
46 CActiveScheduler::Install(activeScheduler); |
|
47 |
|
48 // Create Session |
|
49 CSessionObserver* sessionObserver; |
|
50 sessionObserver = new (ELeave) CSessionObserver; |
|
51 CleanupStack::PushL(sessionObserver); |
|
52 |
|
53 CMsvSession* session = CMsvSession::OpenSyncL(*sessionObserver); |
|
54 CleanupStack::PushL(session); |
|
55 |
|
56 // Set the message entry to global Outbox folder |
|
57 CMsvEntry* msvEntry = session->GetEntryL(KMsvGlobalOutBoxIndexEntryId); |
|
58 CleanupStack::PushL(msvEntry); |
|
59 |
|
60 // Get the selection of Pigeon messages present in Outbox |
|
61 CMsvEntrySelection* selection = msvEntry->ChildrenWithMtmL(KUidMsgTypePigeon); |
|
62 CleanupStack::PushL(selection); |
|
63 |
|
64 // Schedule it to send immediately - use default settings. |
|
65 CMsvScheduleSettings* settings = CMsvScheduleSettings::NewL(); |
|
66 CleanupStack::PushL(settings); |
|
67 |
|
68 RScheduler scheduler; |
|
69 TSchedulerItemRef ref; |
|
70 |
|
71 CMsvScheduleSend::ConnectAndRegisterL(scheduler, *settings); |
|
72 CleanupClosePushL(scheduler); |
|
73 |
|
74 TInt selCount = selection->Count(); |
|
75 |
|
76 for( TInt index = 0; index < selCount; ++index ) |
|
77 { |
|
78 msvEntry->SetEntryL(selection->At(index)); |
|
79 |
|
80 if(msvEntry != NULL) |
|
81 { |
|
82 TMsvEntry entry = msvEntry->Entry(); |
|
83 |
|
84 ref.iHandle = KErrNotFound; |
|
85 |
|
86 FindOrCreateScheduleL(scheduler, entry.iDate, *settings, ref); |
|
87 |
|
88 User::LeaveIfError(scheduler.DisableSchedule(ref.iHandle)); |
|
89 |
|
90 TMsvSchedulePackage package; |
|
91 package.iPollProgress = 3000000; |
|
92 package.iCommandId = ESendScheduledL; |
|
93 package.iId = selection->At(index); |
|
94 |
|
95 TTaskInfo info; |
|
96 |
|
97 CMsvScheduleSend::ScheduleEntryL(scheduler, ref, package, info); |
|
98 |
|
99 User::LeaveIfError(scheduler.EnableSchedule(ref.iHandle)); |
|
100 } |
|
101 } |
|
102 CleanupStack::PopAndDestroy(7, activeScheduler); |
|
103 } |
|
104 |
|
105 LOCAL_C TInt Execute() |
|
106 { |
|
107 __UHEAP_MARK; |
|
108 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
109 |
|
110 TRAPD(err, DoExecuteL()); |
|
111 |
|
112 delete cleanup; |
|
113 __UHEAP_MARKEND; |
|
114 |
|
115 return err; |
|
116 } |
|
117 |
|
118 GLDEF_C TInt E32Main() |
|
119 { |
|
120 return Execute(); |
|
121 } |
|
122 |