質問

I have a class in my application displaying info.
I have to get those info from a server via SOAP.
Here's my class :

class InfoControl : public TGCompositeFrame {
private:
    //char*, int....
    bool bWorking;
public:
    InfoControl(const TGWindow *p);
    virtual ~InfoControl();
    void SetEventRate(char* evnum);
    void SetBufferRate(char* rate);
    void SetSuccess(char *s);
    void RequestInfo();
    ClassDef(InfoControl,1)  //useless : ROOT specific stuff
};

I would like RequestInfo() method to be called periodically as long as bWorking is true. I red about pthread solutions, but don't know how to implement this. And maybe something more trivial is possible ?

Thanks in advance for help,
eo.

役に立ちましたか?

解決 3

Ok, found out. If someone has the same issue :

TTimer *timer = new TTimer();  
timer->Connect("Timeout()", "InfoControl", this, "RequestInfo()");  
timer->Start(1000, kFALSE);

他のヒント

Mmmm... Mb

while (bWorking)
{
    RequestInfo();
    /* sleep os sleep function, or boost, or something else. 
    time - period to sleep.*/
    sleep(time);
}

or you want async call, with some timer?

It is a little unclear what kind of effects RequestInfo() should have on the outside since it is a void, but if it somehow talks to the outside and doesn't do exclusively some internal job (then running it in an extra thread would be fine) you should maybe rethink your design.

bWorking already is private, so an InfoControl knows when it changes. You could then use something like ROOT's Qt slots implementation (e.g. with a TQObject) to trigger a needed action only when bWorking changes (e.g. hook that into some SetWorking()).

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top