#include "piwdgx.h"
#include "piperiodx.h"

/* Nouvelle-Fonction */
static void xttimer_action(XtPointer usd, XtIntervalId * /*tid*/)
{
PIPeriodX * pip;
XtIntervalId id;
pip = (PIPeriodX *)usd;
pip->DoPeriodic();
int szx, szy, szf;
XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
id = XtAppAddTimeOut(*appctx, pip->Intervalms(), xttimer_action, pip);
pip->SetTimerId(id);
return;
}


/* --Methode-- */
PIPeriodX::PIPeriodX(int dt, UsPeriodicAction act, void * usp)
: Periodic(dt, act, usp)
{
}

/* --Methode-- */
PIPeriodX::~PIPeriodX()
{
if (mFgact) Stop();
}

/* --Methode-- */
void PIPeriodX::Start(int dt)
{
if (mFgact) return;
if (dt > 0)  { mDt = dt;  mDtms = dt*1000; }

int szx,szy,szf;
XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
mTId = XtAppAddTimeOut(*appctx, Intervalms(), xttimer_action, this);
mFgact = true;
return;
}

void
PIPeriodX::Stop()
{
if(mFgact)
  XtRemoveTimeOut(mTId);
mFgact = false;
return;
}

