|
1 /** |
|
2 * ==================================================================== |
|
3 * messaging.h |
|
4 * |
|
5 * Copyright (c) 2007-2009 Nokia Corporation |
|
6 * |
|
7 * Licensed under the Apache License, Version 2.0 (the "License"); |
|
8 * you may not use this file except in compliance with the License. |
|
9 * You may obtain a copy of the License at |
|
10 * |
|
11 * http://www.apache.org/licenses/LICENSE-2.0 |
|
12 * |
|
13 * Unless required by applicable law or agreed to in writing, software |
|
14 * distributed under the License is distributed on an "AS IS" BASIS, |
|
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
16 * See the License for the specific language governing permissions and |
|
17 * limitations under the License. |
|
18 * ==================================================================== |
|
19 */ |
|
20 #ifndef __MESSAGING_H__ |
|
21 #define __MESSAGING_H__ |
|
22 |
|
23 #include "Python.h" |
|
24 #include "symbian_python_ext_util.h" |
|
25 |
|
26 #include <e32std.h> |
|
27 #include <eikenv.h> |
|
28 #include <Gsmuelem.h> |
|
29 |
|
30 #include <e32base.h> |
|
31 |
|
32 #include <mtclreg.h> |
|
33 #include <msvuids.h> |
|
34 #include <txtrich.h> |
|
35 |
|
36 #include <smut.h> |
|
37 #include <smutset.h> |
|
38 #include <smsclnt.h> |
|
39 #include <smscmds.h> |
|
40 #include <smuthdr.h> |
|
41 |
|
42 #include <pythread.h> |
|
43 |
|
44 #define MaxMessageLength 39015 |
|
45 #define MaxTelephoneNumberLength 30 |
|
46 #define MaxNameLength 60 |
|
47 |
|
48 /* The thread exit function which deletes the messaging object */ |
|
49 extern "C" void delete_mes_object(void); |
|
50 |
|
51 /* |
|
52 * |
|
53 * Implementation of messaging.sms_send |
|
54 * (based on S60 SDK 2.0 example) |
|
55 * |
|
56 */ |
|
57 class MMsvObserver |
|
58 { |
|
59 public: |
|
60 enum TStatus {ECreated, EMovedToOutBox, EScheduledForSend, ESent, EDeleted}; |
|
61 enum TError {EScheduleFailed=5, ESendFailed, ENoServiceCentre, EFatalServerError}; |
|
62 |
|
63 virtual void HandleStatusChange(TStatus aStatus) = 0; |
|
64 virtual void HandleError(TError aError) = 0; |
|
65 }; |
|
66 |
|
67 /* |
|
68 * Python callback class |
|
69 * |
|
70 */ |
|
71 #ifndef EKA2 |
|
72 class TPyMesCallBack |
|
73 #else |
|
74 NONSHARABLE_CLASS(TPyMesCallBack) |
|
75 #endif |
|
76 { |
|
77 public: |
|
78 TInt MessagingEvent(TInt aArg); |
|
79 public: |
|
80 PyObject* iCb; // Not owned. |
|
81 private: |
|
82 }; |
|
83 |
|
84 /* |
|
85 * |
|
86 * The actual messaging handler |
|
87 * |
|
88 */ |
|
89 #ifndef EKA2 |
|
90 class CMsvHandler : public CActive, public MMsvSessionObserver |
|
91 #else |
|
92 NONSHARABLE_CLASS(CMsvHandler) : public CActive, public MMsvSessionObserver |
|
93 #endif |
|
94 { |
|
95 public: |
|
96 ~CMsvHandler(); |
|
97 virtual TBool IsIdle() { |
|
98 return (iMtmRegistry ? ETrue : EFalse); |
|
99 } |
|
100 |
|
101 protected: // from CActive |
|
102 CMsvHandler(MMsvObserver&); |
|
103 |
|
104 void DoCancel() { if (iOperation) iOperation->Cancel(); } |
|
105 void ConstructL() { iSession = CMsvSession::OpenAsyncL(*this); } |
|
106 virtual void CompleteConstructL() { |
|
107 iMtmRegistry = CClientMtmRegistry::NewL(*iSession); |
|
108 } |
|
109 |
|
110 virtual void SetMtmEntryL(TMsvId); |
|
111 virtual void DeleteEntryL(TMsvEntry& aMsvEntry); |
|
112 |
|
113 protected: |
|
114 CMsvOperation* iOperation; |
|
115 CMsvSession* iSession; |
|
116 CBaseMtm* iMtm; |
|
117 CClientMtmRegistry* iMtmRegistry; |
|
118 MMsvObserver& iObserver; |
|
119 }; |
|
120 |
|
121 /* |
|
122 * |
|
123 * SMS handler |
|
124 * |
|
125 */ |
|
126 #ifndef EKA2 |
|
127 class CSmsSendHandler : public CMsvHandler |
|
128 #else |
|
129 NONSHARABLE_CLASS(CSmsSendHandler) : public CMsvHandler |
|
130 #endif |
|
131 { |
|
132 public: |
|
133 static CSmsSendHandler* NewL(MMsvObserver&, const TDesC&, const TDesC&, const TDesC&, const TInt); |
|
134 static CSmsSendHandler* NewLC(MMsvObserver&, const TDesC&, const TDesC&, const TDesC&, const TInt); |
|
135 |
|
136 ~CSmsSendHandler(); |
|
137 public: // from CMsvHandler |
|
138 TBool IsIdle(); |
|
139 |
|
140 public: // from MMsvSessionObserver |
|
141 void HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* aArg3); |
|
142 |
|
143 protected: |
|
144 void RunL(); |
|
145 CSmsSendHandler(MMsvObserver& aObserver, const TDesC& aTelNum, const TDesC& aMsgBody, const TDesC& aRecipientName, const TInt encoding ) : |
|
146 CMsvHandler(aObserver), iPhase(EIdle), iTelNum(aTelNum), iMessageText(aMsgBody), iRecipientName(aRecipientName), iEncoding(encoding) {;} |
|
147 |
|
148 private: |
|
149 void ConstructL() {CMsvHandler::ConstructL();} |
|
150 void CreateNewMessageL(); |
|
151 TBool SetupSmsHeaderL(); |
|
152 void PopulateMessageL(TMsvEntry& aMsvEntry); |
|
153 TBool InitializeMessageL(); |
|
154 TBool MoveMessageEntryL(TMsvId); |
|
155 void SetScheduledSendingStateL(CMsvEntrySelection&); |
|
156 void HandleChangedEntryL(TMsvId); |
|
157 void SendToL() { CreateNewMessageL(); }; |
|
158 private: |
|
159 enum TPhase {EIdle, EWaitingForCreate, EWaitingForMove, |
|
160 EWaitingForScheduled, EWaitingForSent, EWaitingForDeleted}; |
|
161 |
|
162 TPhase iPhase; |
|
163 TBuf<MaxTelephoneNumberLength> iTelNum; |
|
164 TBuf<MaxMessageLength> iMessageText; |
|
165 TBuf<MaxNameLength> iRecipientName; |
|
166 TInt iEncoding; |
|
167 }; |
|
168 |
|
169 /* |
|
170 * |
|
171 * Observer for the status and errors. |
|
172 * |
|
173 */ |
|
174 #ifndef EKA2 |
|
175 class SmsObserver: public MMsvObserver |
|
176 #else |
|
177 NONSHARABLE_CLASS(SmsObserver) : public MMsvObserver |
|
178 #endif |
|
179 { |
|
180 public: |
|
181 SmsObserver():iStatus(KErrNone) {;} |
|
182 virtual ~SmsObserver() {} |
|
183 void SetCallBack(TPyMesCallBack &aCb); |
|
184 |
|
185 void HandleStatusChange(MMsvObserver::TStatus aStatus); |
|
186 void HandleError(MMsvObserver::TError aError); |
|
187 |
|
188 private: |
|
189 TInt iStatus; // XXX Remove me |
|
190 TPyMesCallBack iCallMe; |
|
191 }; |
|
192 |
|
193 //////////////TYPE DEFINITION///////////////// |
|
194 |
|
195 #define MES_type ((PyTypeObject*)SPyGetGlobalString("MESType")) |
|
196 |
|
197 struct MES_object { |
|
198 PyObject_VAR_HEAD |
|
199 CMsvHandler* messaging; |
|
200 TPyMesCallBack myCallBack; |
|
201 TBool callBackSet; |
|
202 MMsvObserver* smsObserver; |
|
203 }; |
|
204 |
|
205 #endif /*__MESSAGING_H__*/ |