Discussion Board

Results 1 to 11 of 11

Thread: About CActive

  1. #1
    Regular Contributor
    Join Date
    Aug 2004
    Posts
    94

    About CActive

    请问,我一个类继承自CActive类。
    当我收到一个请求后SetActive()了,我怎么才能知道active scheduler执行这个request要用多长时间?
    当我发起另外一个request的时候。判断IsActive()总是IsActive()==0。这个时候我新发起的request不能执行。大家CActive一般是怎么用的?

  2. #2
    Regular Contributor
    Join Date
    Apr 2003
    Posts
    305
    Hi,
    IsActive == 0 means there is no request is outstanding. At this moment you can submit your next new request, and then call the SetActive() to notify the Active Scheduler/system framework that there is a new request is outstanding.
    Br/Colin_CJ

  3. #3
    Regular Contributor
    Join Date
    Aug 2004
    Posts
    94
    sorry.说错了。是IsActive()==1.并且会持续几秒种的时间IsActive()才会等于0。影响下一步的操作。

  4. #4
    Regular Contributor
    Join Date
    Apr 2003
    Posts
    305
    Well, then the service will take quite a long time (several seconds). If you issue the next request before the previous request is served, it may generate errors. If your requests don't need to wait for the previous request finished, I think your application does not need to use CActive.

  5. #5
    Registered User
    Join Date
    Oct 2003
    Posts
    31
    不知道你的每一个request是不是调用同一个函数, 如果是的话,可以这样用:

    RequestXXX()
    {
    //check not already active

    AsyncXXX(iStatus);
    SetActive();
    }

    void RunL()
    {
    ...
    if(!iDone)
    {
    RequestXXX();
    }
    ...
    }

    AsyncXXX是你调用的asynchronous function。 当它完成时RunL会被执行, 在RunL里边再调用RequestXXX(), 如此就可以每当AsyncXXX完成时就自动发出下一个request了

  6. #6
    Regular Contributor
    Join Date
    Jul 2004
    Location
    shenzhen
    Posts
    193
    jiayaoyu,确实如此。

  7. #7
    Regular Contributor
    Join Date
    Aug 2004
    Posts
    94
    如果在CActive 调用到Run()以前(有可能是几秒),有可能需要调用几次RequestXXX()。怎么办?

  8. #8
    Regular Contributor
    Join Date
    Jul 2004
    Location
    shenzhen
    Posts
    193
    agirllikeyou, 你的网络问题还没有解决吗?
    如果你需要多次调用RequestXXX,那么你可以换一个角度来解决。

    例如
    void CXXX::SendData(const TDesC& data)
    {
    if( IsActive())
    {
    iPendingBuffer.Append(data);
    }
    else
    {
    iSocket.Send(data, iStatus);
    SetActive();
    }
    }

    //From CActive
    void CXXX::RunL()
    {
    if(iPendingBuffer.Length() > 0)
    {
    iSocket.Send(iPendingBuffer, iStatus);
    SetActive();
    iPendingBuffer.Zero();
    }
    }

    其中iPendingBuffer可能是一个TBuf或者HBufC,当IsActive()的时候,你就将需要发送的数据保留在这个Buffer中,等上次的Request完成以后再发送。

  9. #9
    Regular Contributor
    Join Date
    Aug 2004
    Posts
    94
    嘿嘿,我把那个问题搁浅了,先做UI的部分
    我最早就是这么做的。我定义的iPendingBuffer大小是512个字节的。发现綺过几次的iPendingBuffer.Append(data)后,总超出iPendingBuffer的大小。我又不想再扩大iPendingBuffer的size。因为已綺很大了。所以我想通过别的途径解决这个问题。

  10. #10
    Regular Contributor
    Join Date
    Jul 2004
    Location
    shenzhen
    Posts
    193
    噢。呵呵。
    不过512个字节实在不大,完全可能分配更多些。毕竟这块内存并不是分配在stack上,而是Heap中,完全没有问题的。而且你使用HBufC的话,还可以动态分配的,需要多少就分配多少。别的途径我看也难。

  11. #11
    Regular Contributor
    Join Date
    Aug 2004
    Posts
    94
    xiexie la

Posting Permissions

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