×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    8

    Unhappy Creating asynchronous service provider - Help

    Hi,
    I´m developing an application that have to do a very large calculation (about 4 sec.). I Think the best way to do this and avoid interrupt GUI events, it´s creating an asynchronous service provider (an asynchronous method) and use it with an Active Object.

    What I am doing :

    void CAsyncFGP::calculate()
    {
    //CAsyncFGP is derived from CActive
    //iclc is an instance of CHardCalc

    iStatus = KRequestPending;
    iclc->calc(iStatus);

    SetActive();
    Util::Log(_L("Finish.."));
    }

    void CAsyncFGP::RunL()
    {
    Util::Log(_L("RunL.."));
    }

    void CHardCalc::calc(TRequestStatus& aStatus)
    {
    //The hardCalc method is responsible for do the large stuff

    TRequestStatus* st = &aStatus;
    /////
    //do large stuff
    User::RequestComplete(st, KErrNone);
    }

    There is something wrong here because the line of code with the message 'Finish' is only running after the method CHardCalc::calc finished ! This method isn´t running in async mode.

    Please, anybody knows what is wrong here ?
    Any help will be very appreciated.

    Thank´s

    Felipe

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,699

    Re: Creating asynchronous service provider - Help

    Your code is a traditional, synchronous call of method "calc", with some unnecessary extras resembling an active object.
    Indeed there is no such thing as "asynchronous method call". Active objects are to be used for non-blocking waiting for an event, they are something like callbacks with improvements (priority, mutual exclusion and "thread-safety" - since being triggered, they run in the same thread, one after the other).

    For a non-blocking long running calculation, you can create a low-priority active object:
    Code:
    CSomething::RunL()
    {
    ... do something quickly ...
    
    ... if not ready:
    SetActive();
    TRequestStatus *stat=&iStatus;
    User::RequestComplete(stat, KErrNone);
    }
    Where "do something quickly" can be one or a few steps of an unrolled/split loop, a larger switch, or the mix of the two. RunL will start over shortly after the RequestComplete, but higher priority AOs can run between the invocations of your RunL.

    However, if the switch is going to be huge, you should rather consider starting a new thread instead.

  3. #3
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: Creating asynchronous service provider - Help

    You've not fully grasped the concepts of what asynchronous and active objects etc. mean, their relation to threads and multitasking etc.

    Passing a TRequestStatus to a function doesn't magically make your program not hang if there is a long activity. If there is a calculation that takes 4 seconds, it still takes 4 seconds and has to use the CPU for 4 seconds, you can't make that magically go away, there's still only one CPU. What you can do though is make other programs get a chance to use the CPU if they need to while your calculation is happening, you do this by splitting your calculation into a number of steps i.e. 1/10 of a second each (although don't misunderstand that and think that means you have to time how long each part of the calculation takes). THe way you do this is to break your calculation into parts using an active object as wizard as described. In his example, in the ".... do something quickly ...." part instead of doing all your calculation, do about 1/100 of it. Thus the RunL() will get called 100 times before your calculation is complete, however if something else needs to use the CPU in the meanwhile it will be it inbetween your RunL getting called.

Similar Threads

  1. 6680 and bluetooth service profiles
    By ceruault in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2005-10-08, 22:24
  2. Service Provider Lock
    By e2easy.com in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2004-08-09, 01:34
  3. Replies: 3
    Last Post: 2004-05-28, 14:44
  4. How to create Asynchronous function (Service Provider)
    By awasthi_vivek in forum Symbian
    Replies: 0
    Last Post: 2004-04-07, 08:32
  5. Nokia M2M Gateway Service Provider Edition
    By m2mvuw in forum Nokia M2M
    Replies: 2
    Last Post: 2004-03-01, 10:45

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×