|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
|
3 <!-- This component and the accompanying materials are made available under the terms of the License |
|
4 "Eclipse Public License v1.0" which accompanies this distribution, |
|
5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
|
6 <!-- Initial Contributors: |
|
7 Nokia Corporation - initial contribution. |
|
8 Contributors: |
|
9 --> |
|
10 <!DOCTYPE concept |
|
11 PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd"> |
|
12 <concept xml:lang="en" id="GUID-3D1E5144-00BC-51AF-8887-4C97167E73FB"><title>SMS Stack Tutorial</title><shortdesc>This tutorial describes how to send and receive messages using the SMS stack. </shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody><example id="GUID-BA144B2C-BDE0-5D9E-A977-ED38C80CB8E7"><title>Send SMS example</title> <codeblock id="GUID-CC32288F-16DA-56C5-97B0-CBF18A674DBD" xml:space="preserve"> |
|
13 #include <e32std.h> |
|
14 #include <es_sock.h> |
|
15 #include <gsmubuf.h> |
|
16 #include <gsmumsg.h> |
|
17 #include <gsmuset.h> |
|
18 #include <smsustrm.h> |
|
19 #include <smsuaddr.h> |
|
20 |
|
21 _LIT(KSmsMessage, "Sample SMS message for illustration"); |
|
22 _LIT(KDestination,"+44789456123"); |
|
23 _LIT(KServiceCentre, "+44123456789"); |
|
24 RFs fs; |
|
25 RSocketServ socketServer; |
|
26 RSocket socket; |
|
27 |
|
28 //connect to the file server |
|
29 User::LeaveIfError(fs.Connect()); |
|
30 CleanupClosePushL(fs); |
|
31 |
|
32 //connect to the socket server |
|
33 User::LeaveIfError(socketServer.Connect()); |
|
34 CleanupClosePushL(socketServer); |
|
35 |
|
36 //Open a SMS socket |
|
37 User::LeaveIfError(socket.Open(socketServer, KSMSAddrFamily, KSockDatagram, KSMSDatagramProtocol)); |
|
38 CleanupClosePushL(socket); |
|
39 TSmsAddr smsAddr; |
|
40 |
|
41 //set the sockets to only send the messages |
|
42 smsAddr.SetSmsAddrFamily(ESmsAddrSendOnly); |
|
43 |
|
44 //Bind the socket |
|
45 socket.Bind(smsAddr); |
|
46 |
|
47 //create a message and encoding scheme to be used |
|
48 CSmsBuffer* buffer=CSmsBuffer::NewL(); |
|
49 CSmsMessage* smsMessage=CSmsMessage::NewL(fs, CSmsPDU::ESmsSubmit, buffer); |
|
50 CleanupStack::PushL(smsMessage); |
|
51 |
|
52 TSmsUserDataSettings smsSettings; |
|
53 smsSettings.SetAlphabet(TSmsDataCodingScheme::ESmsAlphabet7Bit); |
|
54 smsMessage->SetUserDataSettingsL(smsSettings); |
|
55 |
|
56 smsMessage->SetToFromAddressL(KDestination); |
|
57 smsMessage->SmsPDU().SetServiceCenterAddressL(KServiceCentre); |
|
58 buffer->InsertL(0,KSmsMessage); |
|
59 |
|
60 TRequestStatus status; |
|
61 |
|
62 RSmsSocketWriteStream writestream(socket); |
|
63 |
|
64 writestream << *smsMessage; |
|
65 writestream.CommitL(); |
|
66 |
|
67 TPckgBuf<TUint> sbuf; |
|
68 socket.Ioctl(KIoctlSendSmsMessage, status, &sbuf, KSolSmsProv); |
|
69 User::WaitForRequest(status); |
|
70 |
|
71 CleanupStack::PopAndDestroy(smsMessage); |
|
72 CleanupStack::PopAndDestroy(&socket); |
|
73 CleanupStack::PopAndDestroy(&socketServer); |
|
74 CleanupStack::PopAndDestroy(&fs); |
|
75 </codeblock> </example> <section id="GUID-314DEC98-B67D-5ADF-B5E7-D96FEAF59455"><title>Receive SMS example</title> <codeblock id="GUID-F3EC34CF-90C1-59FE-9CBE-2912DF02D0AC" xml:space="preserve"> |
|
76 #include <e32std.h> |
|
77 #include <es_sock.h> |
|
78 #include <gsmubuf.h> |
|
79 #include <gsmumsg.h> |
|
80 #include <gsmuset.h> |
|
81 #include <smsustrm.h> |
|
82 #include <smsuaddr.h> |
|
83 |
|
84 _LIT(KSmsMessage, "Sample SMS message for illustration"); |
|
85 _LIT(KDestination,"+44789456123"); |
|
86 _LIT(KServiceCentre, "+44123456789"); |
|
87 RFs fs; |
|
88 RSocketServ socketServer; |
|
89 RSocket socket; |
|
90 |
|
91 //connect to the file server |
|
92 User::LeaveIfError(fs.Connect()); |
|
93 CleanupClosePushL(fs); |
|
94 |
|
95 //connect to the socket server |
|
96 User::LeaveIfError(socketServer.Connect()); |
|
97 CleanupClosePushL(socketServer); |
|
98 |
|
99 //Open a SMS socket |
|
100 User::LeaveIfError(socket.Open(socketServer, KSMSAddrFamily, KSockDatagram, KSMSDatagramProtocol)); |
|
101 CleanupClosePushL(socket); |
|
102 |
|
103 TSmsAddr smsAddr; |
|
104 |
|
105 //set the sockets to receive all SMS messages |
|
106 smsAddr.SetSmsAddrFamily(ESmsAddrRecvAny); |
|
107 |
|
108 //Bind the socket |
|
109 socket.Bind(smsAddr); |
|
110 TRequestStatus status; |
|
111 TPckgBuf<TUint> sbuf; |
|
112 |
|
113 socket.Ioctl(KIOctlSelect,status,&sbuf,KSOLSocket); |
|
114 User::WaitForRequest(status); |
|
115 CSmsBuffer* buffer=CSmsBuffer::NewL(); |
|
116 CSmsMessage* smsMessage=CSmsMessage::NewL(fs, CSmsPDU::ESmsSubmit, buffer); |
|
117 CleanupStack::PushL(smsMessage); |
|
118 |
|
119 //read from the stream |
|
120 RSmsSocketReadStream readstream(socket); |
|
121 |
|
122 readstream >> *smsMessage; |
|
123 |
|
124 socket.Ioctl(KIoctlReadMessageSucceeded, status, &sbuf, KSolSmsProv); |
|
125 User::WaitForRequest(status); |
|
126 CleanupStack::Pop(smsMessage); |
|
127 |
|
128 //clear the contents from buffer |
|
129 CleanupStack::PopAndDestroy(smsMessage); |
|
130 CleanupStack::PopAndDestroy(&socket); |
|
131 CleanupStack::PopAndDestroy(&socketServer); |
|
132 CleanupStack::PopAndDestroy(&fs); |
|
133 </codeblock> </section> </conbody></concept> |