×
Namespaces

Variants
Actions
(Difference between revisions)

Archived:Changing asynchronous method to synchronous in Symbian C++

From Nokia Developer Wiki
Jump to: navigation, search
Forum Nokia KB (Talk | contribs)
lpvalente (Talk | contribs)
m (Lpvalente -)
 
(12 intermediate revisions by 5 users not shown)
Line 1: Line 1:
__NOTOC__
+
[[Category:Symbian C++]][[Category:Code Snippet]][[Category:S60 3rd Edition (initial release)]][[Category:Code Snippet]]
__NOEDITSECTION__
+
{{Archived|timestamp=20120313125306|user=roy.debjit| }}
 
+
{|style="background:#eceff2" width="660px" border="1" cellpadding="5" cellspacing="0"
+
|-
+
|'''ID''' ||
+
|'''Creation date''' || May 21, 2008
+
|-
+
|'''Platform''' || S60 3rd Edition, MR
+
|'''Tested on devices''' || Nokia N95
+
|-
+
|'''Category''' || Symbian C++
+
|'''Subcategory''' || Code Examples
+
|-
+
|}
+
 
+
 
+
{|style="background:#eceff2" width="660px" border="1" cellpadding="5" cellspacing="0"
+
|-
+
|'''Keywords (APIs, classes, methods, functions):''' CActiveSchedulerWait, CActive, TRequestStatus
+
|}
+
  
 +
{{ArticleMetaData <!-- v1.2 -->
 +
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
 +
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 +
|devices= Nokia N95
 +
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
 +
|platform= S60 3rd Edition, MR
 +
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
 +
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= CActiveSchedulerWait, CActive, TRequestStatus
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by= <!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20080521
 +
|author= [[User:Tepaa]]
 +
<!-- The following are not in current metadata -->
 +
|subcategory= Code Examples
 +
|id= CS000983
 +
}}
 +
 
 
==Overview==
 
==Overview==
This code snippet shows how to change an asynchronous method interface to a  
+
{{Abstract|This code snippet shows how to change an asynchronous method interface to a synchronous method. This can be done with CActiveSchedulerWait.}}
synchronous method. This can be done with CActiveSchedulerWait.
+
  
 
There are two different synchronous methods:
 
There are two different synchronous methods:
Line 29: Line 35:
 
* CMyClass::DoAsynchronousWithStatusL() uses CActiveSchedulerWait for waiting for the asynchronous method that has TRequestStatus in its interface. The method completes with CMyClass::RunL().
 
* CMyClass::DoAsynchronousWithStatusL() uses CActiveSchedulerWait for waiting for the asynchronous method that has TRequestStatus in its interface. The method completes with CMyClass::RunL().
  
For more information on using CActiveSchedulerWait, see article  [[Using CActiveSchedulerWait]]
+
For more information on using CActiveSchedulerWait, see article  [[Archived:Using CActiveSchedulerWait]]
  
 
==MMP file==
 
==MMP file==
 
The following capabilities and libraries are required:
 
The following capabilities and libraries are required:
 
<code cpp>
 
<code cpp>
CAPABILITY   None
+
CAPABILITY None
LIBRARY       euser.lib
+
LIBRARY euser.lib
 
</code>
 
</code>
  
Line 68: Line 74:
 
     private:
 
     private:
 
         CSomeAsyncClass*      iSomeAsyncClass;
 
         CSomeAsyncClass*      iSomeAsyncClass;
         CActiveSchedulerWait   iSchedulerWait;
+
         CActiveSchedulerWait iSchedulerWait;
         TInt                   iResult;
+
         TInt iResult;
 
     };
 
     };
 
</code>
 
</code>
Line 149: Line 155:
 
void CMyClass::DoCancel()
 
void CMyClass::DoCancel()
 
     {
 
     {
     // This cancels the DoAsynchronousWithStatusL() method
+
     // This cancels the DoAsynchronousWithStatusL() method
 
     iResult = KErrCancel;
 
     iResult = KErrCancel;
 
     iSchedulerWait.AsyncStop();
 
     iSchedulerWait.AsyncStop();
Line 159: Line 165:
  
 
==See also==
 
==See also==
[[Using CActiveSchedulerWait]]
+
[[Archived:Using CActiveSchedulerWait]]
 
+
[[Category:Symbian C++]][[Category:Code Examples]][[Category:S60 3rd Edition]]
+

Latest revision as of 01:26, 25 August 2012

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Article Metadata
Tested with
Devices(s): Nokia N95
Compatibility
Platform(s): S60 3rd Edition, MR
S60 3rd Edition (initial release)
Article
Keywords: CActiveSchedulerWait, CActive, TRequestStatus
Created: tepaa (21 May 2008)
Last edited: lpvalente (25 Aug 2012)

Contents

[edit] Overview

This code snippet shows how to change an asynchronous method interface to a synchronous method. This can be done with CActiveSchedulerWait.

There are two different synchronous methods:

  • CMyClass::DoAsynchronousL() uses CActiveSchedulerWait for waiting for the asynchronous method that completes with CMyClass::AsyncComplete()
  • CMyClass::DoAsynchronousWithStatusL() uses CActiveSchedulerWait for waiting for the asynchronous method that has TRequestStatus in its interface. The method completes with CMyClass::RunL().

For more information on using CActiveSchedulerWait, see article Archived:Using CActiveSchedulerWait

[edit] MMP file

The following capabilities and libraries are required:

CAPABILITY None
LIBRARY euser.lib

[edit] Header

#include <e32base.h>
 
// for CSomeAsyncClass
class MAsynchIF
{
public:
void AsyncComplete(TInt aResult);
};
 
class CMyClass : public CActive, MAsynchIF
{
public:
static CMyClass* NewLC();
virtual ~CMyClass();
 
// Synchronous methods
TInt DoAsynchronousL();
TInt DoAsynchronousWithStatusL();
 
private: // From MAsynchIF (CSomeAsyncClass)
void AsyncComplete(TInt aResult);
 
private: // From CActive
void RunL();
void DoCancel();
 
private:
CSomeAsyncClass* iSomeAsyncClass;
CActiveSchedulerWait iSchedulerWait;
TInt iResult;
};

[edit] Source

CMyClass* CMyClass::NewLC()
{
CMyClass* self = new (ELeave) CMyClass();
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
 
CMyClass::CMyClass()
: CActive(CActive::EPriorityStandard)
{
}
 
void CMyClass::ConstructL()
{
CActiveScheduler::Add(this);
iSomeAsyncClass = CSomeAsyncClass::NewL(this);
}
 
CMyClass::~CMyClass()
{
Cancel();
delete iSomeAsyncClass;
}
 
// This is a synchronous method even though it calls an asynchronous interface that
// completes with CMyClass::AsyncComplete()
TInt CMyClass::DoAsynchronousL()
{
User::LeaveIfError(iSomeAsyncClass->SomeAsynchronousIfL());
 
iSchedulerWait.Start();
// Continues here after CMyClass::AsyncComplete() is called
// by CSomeAsyncClass.
 
return iResult;
}
 
void CMyClass::AsyncComplete(TInt aResult)
{
iResult = aResult;
iSchedulerWait.AsyncStop();
}
 
// This is an synchronous method even though it calls an asynchronous interface that
// completes with CMyClass::RunL() because it uses TRequestStatus as
// a parameter
TInt CMyClass::DoAsynchronousWithStatusL()
{
if (!IsActive())
{
User::LeaveIfError(iSomeAsyncClass->SomeAsynchronousIfL(iStatus));
SetActive();
 
iSchedulerWait.Start();
// Continues here after CMyClass::RunL() is called
// by CSomeAsyncClass.
}
else
{
User::Leave(KErrNotReady);
}
return iResult;
}
 
void CMyClass::RunL()
{
// This is called when DoAsynchronousWithStatusL() completes
iResult = iStatus.Int();
iSchedulerWait.AsyncStop();
}
 
void CMyClass::DoCancel()
{
// This cancels the DoAsynchronousWithStatusL() method
iResult = KErrCancel;
iSchedulerWait.AsyncStop();
}

[edit] Postconditions

The asynchronous methods looks like a synchronous method.

[edit] See also

Archived:Using CActiveSchedulerWait

This page was last modified on 25 August 2012, at 01:26.
96 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×