Главная » Просмотр файлов » Symbian OS Communications

Symbian OS Communications (779884), страница 50

Файл №779884 Symbian OS Communications (Symbian Books) 50 страницаSymbian OS Communications (779884) страница 502018-01-10СтудИзба
Просмтор этого файла доступен только зарегистрированным пользователям. Но у нас супер быстрая регистрация: достаточно только электронной почты!

Текст из файла (страница 50)

At this point some codecould check to see if it is a weather report message. If so, then thecontent of the message would be passed to the weather report parserand the message would then be deleted. Unfortunately there are somedisadvantages to this approach:1. The binary message, which is not intended for the user in raw form,briefly appears in the inbox before disappearing again.2. All observers in the system are notified about the binary SMS and itssubsequent deletion. This may result in the user being alerted to thearrival of a new SMS.A better approach for implementing this functionality is to intercept theSMS message before it reaches the message server. This can be achievedby using the SMS socket API.8.5.1 SMS Socket APIIn the summary screen application, the CWeatherReportWatcherclass waits for weather report messages.

It does this by opening a socket236RECEIVING MESSAGESto the SMS stack2 and registering for all SMS messages starting with‘Weather:’.The ‘Weather report’ SMS encoding is very simple – it consists of theprefix ‘Weather:’ followed by a single digit, either ‘1’, ‘2’, or ‘3’. Thesecorrespond to ‘sunny’, ‘cloudy’ or ‘rainy’ – we don’t get much interestingweather in the UK!Example 8.11 shows the declaration of CWeatherReportWatcherthat is later used to intercept the weather report messages.class CWeatherReportWatcher : public CActive{...private:RSocketServ iSocketServer;RSocket iSmsSocket;// . .

.enum TWeatherWatcherState{EWaitingForWeatherReport,EAcknowledgingWeatherReport};TWeatherWatcherState iState;};Example 8.11Class declaration for CWeatherReportWatcherExample 8.11 shows how the CWeatherReportWatcher has twostates.1.Waiting for a weather report SMS message.2.Acknowledging the received SMS message.The weather report watcher is implemented as an active object becauseboth the waiting and the acknowledging operations are potentially longrunning and therefore should be performed asynchronously. The activeobject allows these operations to run without blocking the entire thread.Note that if the thread was blocked then the message summaries wouldnot be updated with any newly received messages.Example 8.12 shows how the SMS socket is opened and how itregisters an interest in SMS messages with the prefix ‘‘Weather:’’ by usingRSocket::Bind()._LIT8(KWeatherReportPrefixString, "Weather:");...2For generic information on socket usage, see Chapter 3.RECEIVING APPLICATION-SPECIFIC SMS MESSAGES237void CWeatherReportWatcher::ConstructL(){CActiveScheduler::Add(this);// Connect to sockets server// SMS messages are intercepted via socketsUser::LeaveIfError(iSocketServer.Connect());// Open SMS socketUser::LeaveIfError(iSmsSocket.Open(iSocketServer, KSMSAddrFamily,KSockDatagram, KSMSDatagramProtocol));// Set SMS prefix - only intercept SMS messages starting with a// particular stringTSmsAddr smsAddress;smsAddress.SetSmsAddrFamily(ESmsAddrMatchText);smsAddress.SetTextMatch(KWeatherReportPrefixString);iSmsSocket.Bind(smsAddress);WaitForWeatherReportL();}Example 8.12prefixRegistering to receive SMS messages with a specificWaitForWeatherReport() implements the code that actuallywaits for a weather report message to be received.

This is shownin Example 8.13. Note how RSocket::Ioctl() is used to asynchronously wait for an SMS that matches the attributes that have alreadybeen set on the socket.void CWeatherReportWatcher::WaitForWeatherReportL(){// Wait for an appropriate SMS message// the RunL will be called when an appropriate SMS message is received// Note that the smsAddress has already been set in ConstructL so we// will only intercept messages starting with ’Weather:’iSbuf()=KSockSelectRead;iSmsSocket.Ioctl(KIOctlSelect, iStatus, &iSbuf, KSOLSocket);iState = EWaitingForWeatherReport;SetActive();}Example 8.13arriveWaiting for a message with the registered prefix toWhen a weather report message has been received RunL() is called.RunL() is split into two parts, the first to handle a newly received weatherreport and the second to handle the completion of the acknowledgement.238RECEIVING MESSAGESvoid CWeatherReportWatcher::RunL(){if (iState == EWaitingForWeatherReport){CSmsBuffer* smsBuffer=CSmsBuffer::NewL();CleanupStack::PushL(smsBuffer);CSmsMessage* smsMessage = CSmsMessage::NewL(iFs, ESmsDeliver,smsBuffer);// smsMessage has taken ownership of smsBuffer so remove it from the// cleanup stack.CleanupStack::Pop(smsBuffer);CleanupStack::PushL(smsMessage);RSmsSocketReadStream readstream(iSmsSocket);// This function may leavereadstream >> *smsMessage;// Extract the text from the SMS bufferTBuf<KMaxWeatherReportLength> weatherReportBuf;TInt bufferLength = smsBuffer->Length();if (bufferLength > KMaxWeatherReportLength){bufferLength = KMaxWeatherReportLength;}smsBuffer->Extract(weatherReportBuf, 0, bufferLength);Example 8.14Handling an SMS upon arrivalExample 8.14 shows how the contents of the SMS message areextracted from the SMS socket and how CSmsBuffer and CSmsMessage are used.

Once the weather report has been extracted into adescriptor then it is processed by the code shown in Example 8.15:MWeatherReportObserver::TWeatherReport weatherReport =MWeatherReportObserver::ENone;// Process the messageif (weatherReportBuf.Length() >= KMaxWeatherReportLength){// Get the last character. The last character represents the// weather report.TUint16 lastCharacter = weatherReportBuf[KMaxWeatherReportLength 1];// Process the messageswitch (lastCharacter){case ’1’:weatherReport = MWeatherReportObserver::ESunny;break;case ’2’:weatherReport = MWeatherReportObserver::ECloudy;break;RECEIVING APPLICATION-SPECIFIC SMS MESSAGES239case ’3’:weatherReport = MWeatherReportObserver::ERainy;break;// No default. Leave weather report as ’None’.}}// Update the UI with the new weather reportiWeatherReportObserver.NewWeatherReport(weatherReport);CleanupStack::PopAndDestroy(smsMessage);Example 8.15Processing the received SMSMessages with the contents ‘‘Weather:1’’ cause the UI to be updatedwith an ESunny weather report.

Messages with contents ‘‘Weather:2’’cause the UI to be updated with an ECloudy report, etc.Once the incoming message has been processed then the applicationmust acknowledge it. This lets the SMS stack know that the application hassuccessfully dealt with the SMS so it can be deleted from the reassemblystore.If the current state of the system prevents the handling of this message,for example, due to low memory then the acknowledgement can beomitted so that the SMS stack will attempt to deliver the message to theapplication again and it can be processed later when the appropriateresources may be available.Example 8.16 shows how the weather report is acknowledged.// Acknowledge successful processing of the SMS messageTPckgBuf<TUint> sbuf;iSmsSocket.Ioctl(KIoctlReadMessageSucceeded, iStatus, &sbuf,KSolSmsProv);// Wait for the acknowledgement to be sent, go active.iState = EAcknowledgingWeatherReport;SetActive();}Example 8.16Acknowledging receipt of a received SMSFinally, CWeatherReportWatcher waits for the acknowledgementto complete.

Once this is done RunL() is called again, this time theacknowledgement branch is executed where it then waits for a newweather report message.void CWeatherReportWatcher::RunL(){...else if (iState == EAcknowledgingWeatherReport)240RECEIVING MESSAGES{// The acknowledgement has now been sent so wait for another weather// report.WaitForWeatherReportL();}}Example 8.17Waiting for the acknowledgement process to complete8.6 SummaryIn this chapter, we have learnt how to:• define the structure of the message store• access messages in the message store• filter messages, for example by message type• access the generic parts of each message, for example, sender andsubject information• access the message-type specific parts of messages, such as, emailattachments• monitor the message store for changes• receive an application-specific SMS before it reaches the messagestore.9Sending MessagesThis chapter builds on Chapter 8 to provide a more complete guide tothe messaging architecture on Symbian OS.This chapter details the high-level SendAs messaging API in SymbianOS and also the UI platform-specific Send dialogs.

Характеристики

Тип файла
PDF-файл
Размер
3,18 Mb
Материал
Тип материала
Высшее учебное заведение

Список файлов книги

Свежие статьи
Популярно сейчас
А знаете ли Вы, что из года в год задания практически не меняются? Математика, преподаваемая в учебных заведениях, никак не менялась минимум 30 лет. Найдите нужный учебный материал на СтудИзбе!
Ответы на популярные вопросы
Да! Наши авторы собирают и выкладывают те работы, которые сдаются в Вашем учебном заведении ежегодно и уже проверены преподавателями.
Да! У нас любой человек может выложить любую учебную работу и зарабатывать на её продажах! Но каждый учебный материал публикуется только после тщательной проверки администрацией.
Вернём деньги! А если быть более точными, то автору даётся немного времени на исправление, а если не исправит или выйдет время, то вернём деньги в полном объёме!
Да! На равне с готовыми студенческими работами у нас продаются услуги. Цены на услуги видны сразу, то есть Вам нужно только указать параметры и сразу можно оплачивать.
Отзывы студентов
Ставлю 10/10
Все нравится, очень удобный сайт, помогает в учебе. Кроме этого, можно заработать самому, выставляя готовые учебные материалы на продажу здесь. Рейтинги и отзывы на преподавателей очень помогают сориентироваться в начале нового семестра. Спасибо за такую функцию. Ставлю максимальную оценку.
Лучшая платформа для успешной сдачи сессии
Познакомился со СтудИзбой благодаря своему другу, очень нравится интерфейс, количество доступных файлов, цена, в общем, все прекрасно. Даже сам продаю какие-то свои работы.
Студизба ван лав ❤
Очень офигенный сайт для студентов. Много полезных учебных материалов. Пользуюсь студизбой с октября 2021 года. Серьёзных нареканий нет. Хотелось бы, что бы ввели подписочную модель и сделали материалы дешевле 300 рублей в рамках подписки бесплатными.
Отличный сайт
Лично меня всё устраивает - и покупка, и продажа; и цены, и возможность предпросмотра куска файла, и обилие бесплатных файлов (в подборках по авторам, читай, ВУЗам и факультетам). Есть определённые баги, но всё решаемо, да и администраторы реагируют в течение суток.
Маленький отзыв о большом помощнике!
Студизба спасает в те моменты, когда сроки горят, а работ накопилось достаточно. Довольно удобный сайт с простой навигацией и огромным количеством материалов.
Студ. Изба как крупнейший сборник работ для студентов
Тут дофига бывает всего полезного. Печально, что бывают предметы по которым даже одного бесплатного решения нет, но это скорее вопрос к студентам. В остальном всё здорово.
Спасательный островок
Если уже не успеваешь разобраться или застрял на каком-то задание поможет тебе быстро и недорого решить твою проблему.
Всё и так отлично
Всё очень удобно. Особенно круто, что есть система бонусов и можно выводить остатки денег. Очень много качественных бесплатных файлов.
Отзыв о системе "Студизба"
Отличная платформа для распространения работ, востребованных студентами. Хорошо налаженная и качественная работа сайта, огромная база заданий и аудитория.
Отличный помощник
Отличный сайт с кучей полезных файлов, позволяющий найти много методичек / учебников / отзывов о вузах и преподователях.
Отлично помогает студентам в любой момент для решения трудных и незамедлительных задач
Хотелось бы больше конкретной информации о преподавателях. А так в принципе хороший сайт, всегда им пользуюсь и ни разу не было желания прекратить. Хороший сайт для помощи студентам, удобный и приятный интерфейс. Из недостатков можно выделить только отсутствия небольшого количества файлов.
Спасибо за шикарный сайт
Великолепный сайт на котором студент за не большие деньги может найти помощь с дз, проектами курсовыми, лабораторными, а также узнать отзывы на преподавателей и бесплатно скачать пособия.
Популярные преподаватели
Добавляйте материалы
и зарабатывайте!
Продажи идут автоматически
6309
Авторов
на СтудИзбе
313
Средний доход
с одного платного файла
Обучение Подробнее