Symbian3/PDK/Source/GUID-3D1E5144-00BC-51AF-8887-4C97167E73FB.dita
changeset 1 25a17d01db0c
child 3 46218c8b8afa
equal deleted inserted replaced
0:89d6a7a84779 1:25a17d01db0c
       
     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 &lt;e32std.h&gt;
       
    14 #include &lt;es_sock.h&gt;
       
    15 #include &lt;gsmubuf.h&gt;
       
    16 #include &lt;gsmumsg.h&gt;
       
    17 #include &lt;gsmuset.h&gt;
       
    18 #include &lt;smsustrm.h&gt;
       
    19 #include &lt;smsuaddr.h&gt;
       
    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-&gt;SetUserDataSettingsL(smsSettings);
       
    55 
       
    56 smsMessage-&gt;SetToFromAddressL(KDestination);
       
    57 smsMessage-&gt;SmsPDU().SetServiceCenterAddressL(KServiceCentre);
       
    58 buffer-&gt;InsertL(0,KSmsMessage);
       
    59 
       
    60 TRequestStatus status;
       
    61 
       
    62 RSmsSocketWriteStream writestream(socket);
       
    63 
       
    64 writestream &lt;&lt; *smsMessage;
       
    65 writestream.CommitL();
       
    66 
       
    67 TPckgBuf&lt;TUint&gt; sbuf;
       
    68 socket.Ioctl(KIoctlSendSmsMessage, status, &amp;sbuf, KSolSmsProv);
       
    69 User::WaitForRequest(status);
       
    70 
       
    71 CleanupStack::PopAndDestroy(smsMessage);
       
    72 CleanupStack::PopAndDestroy(&amp;socket);
       
    73 CleanupStack::PopAndDestroy(&amp;socketServer);
       
    74 CleanupStack::PopAndDestroy(&amp;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 &lt;e32std.h&gt;
       
    77 #include &lt;es_sock.h&gt;
       
    78 #include &lt;gsmubuf.h&gt;
       
    79 #include &lt;gsmumsg.h&gt;
       
    80 #include &lt;gsmuset.h&gt;
       
    81 #include &lt;smsustrm.h&gt;
       
    82 #include &lt;smsuaddr.h&gt;
       
    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&lt;TUint&gt; sbuf;
       
   112 
       
   113 socket.Ioctl(KIOctlSelect,status,&amp;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 &gt;&gt; *smsMessage;
       
   123 
       
   124 socket.Ioctl(KIoctlReadMessageSucceeded, status, &amp;sbuf, KSolSmsProv);
       
   125 User::WaitForRequest(status);
       
   126 CleanupStack::Pop(smsMessage);    
       
   127 
       
   128 //clear the contents from buffer
       
   129 CleanupStack::PopAndDestroy(smsMessage);
       
   130 CleanupStack::PopAndDestroy(&amp;socket);
       
   131 CleanupStack::PopAndDestroy(&amp;socketServer);
       
   132 CleanupStack::PopAndDestroy(&amp;fs);
       
   133 </codeblock> </section> </conbody></concept>