信号处理程序函数调用错误中的错误

时间:2015-03-04 05:56:20

标签: c++ c signals signals-slots signal-handling

错误信号处理程序函数调用错误。

我在类中有一个方法,我在调用addTime(unsigned long milliSecs, BaseClass *bs, void *data)函数。

//file BaseClass.h
class BaseClass {
public:
    virtual ~BaseClass(){ }

    virtual void OnTimedout(void* data)=0;
};

//file ClassBTxxx.h
#include "TimedOut.h"
class ClassBTxxx : public BaseClass
{
public :
    ClassBTxxx();
    void functionA();
    void OnTimedout(void* data);
    .........
    .........
    TimedOut* m_TimeOut;
};

//file ClassBTxxx.cpp
ClassBTxxx::functionA()
{
    m_TimeOut = new TimeOut();

    int timeoutId =m_TimeOut->addTime(18000, this, NULL);
}

ClassBTxxx::OnTimedout(void* data)
{
    printf("OnTimedout Signal handling function is called properly\n\n");
}

//file TimedOut.h
class TimedOut
public:
    TimedOut();
    int addTime(unsigned long milliSecs, BaseClass *ph, void *data);
    ~TimedOut(){}
protected:
    itimerval m_TimerValue;
};

//file TimedOut.cpp
int TimedOut::addTime(unsigned long milliSecs, BaseClass *ph, void *data) // iam passing the ClassBTxxx object to the *ph.
{
    printf("TimedOutHandler::addTimeout\n\n");
    m_TimerValue.it_value.tv_sec = 0;
    m_TimerValue.it_value.tv_usec = milliSecs;
    m_TimerValue.it_interval.tv_sec = 0;
    m_TimerValue.it_interval.tv_usec = milliSecs;

    int ret = setitimer(ITIMER_REAL,&m_TimerValue,0); //I am setting the timer for 3 second after 3 second expired my timer has to call OnTimedout() function.
    if(0 == ret)
    {
        printf("setitimer successful\n");
        signal(SIGALRM, ph->OnTimedout(data)); //Error: Invalide use of non-static memeber function
                                               //Error: Invalide conversion of void expression
    }
    else
    {
        printf("Set Timer Unsuccessful. %d\n", ret);
    }
    return 0;
}

问题是我在3秒钟后将定时器设置为3秒钟我的定时器必须调用OnTimedout()函数。 SIGALRM信号将在3秒后发出 它必须调用OnTimedout()。我收到以下错误

  

错误:无效使用非静态memeber功能
  错误:void表达式的Invalide转换

请帮我解决此错误。谢谢

0 个答案:

没有答案