/*
O_TIMER
*/

#include <hwimman.g>
#include <timer.g>
#include <timer.rsg>
#include <hwim.h>

GLREF_D WSERV_SPEC *wserv_channel;
GLREF_D VOID *w_am;

GLDEF_C VOID main(VOID)
    {
    IN_HWIMMAN app;
    IN_WSERV ws;

    p_linklib(0);
    app.flags=FLG_APPMAN_RSCFILE|FLG_APPMAN_CLEAN|FLG_APPMAN_SRSCFILE;
    app.wserv_cat=p_getlibh(CAT_TIMER_TIMER);
    ws.com_cat=p_getlibh(CAT_TIMER_HWIM);
    app.wserv_class=C_TIMERWS;
    ws.com_class=C_COMMAN;
    p_send4(p_new(CAT_TIMER_HWIM,C_HWIMMAN),O_AM_INIT,&app,&ws);
    }

#pragma METHOD_CALL

METHOD VOID timerws_ws_dyn_init(PR_TIMERWS *self)
    {
    self->wserv.cli=f_new(CAT_TIMER_TIMER,C_TIMERBW);
    p_send2(self->wserv.cli,O_WN_INIT);
    f_newsend(CAT_TIMER_TIMER,C_MYTIMER,O_AO_INIT,"TIM:",-1);
    }

METHOD VOID timerbw_wn_init(PR_TIMERBW *self)
    {
    W_WINDATA wd;

    wd.extent.tl.x=0;
    wd.extent.tl.y=0;
    wd.extent.width=wserv_channel->conn.info.pixels.x;
    wd.extent.height=wserv_channel->conn.info.pixels.y;
    p_send5(self,O_WN_CONNECT,NULL,W_WIN_EXTENT,&wd);
    p_send3(self,O_WN_VISIBLE,WV_INITVIS);
    p_send3(self,O_WN_EMPHASISE,TRUE);
    }

METHOD VOID mytimer_ao_init(PR_MYTIMER *self,TEXT *devname,INT mode)
    {
    p_supersend4(self,O_AO_INIT,devname,mode);
    self->active.priority=PRIORITY_ACTIVE_REPEATER;
    p_send3(w_am,O_AM_ADD_TASK,self);
    p_send2(self,O_AO_QUEUE);
    }

METHOD VOID mytimer_ao_queue(PR_MYTIMER *self)
    {
    LONG delay;

    delay=20;
    p_ioc4(self->active.pcb,P_FREAD,&self->active.stat,&delay);
    self->active.isactive=TRUE;
    }

METHOD INT mytimer_ao_run(PR_MYTIMER *self)
    {
    self->mytimer.count+=1;
    hInfoPrint(TIMER_INFO,self->mytimer.count);
    p_send2(self,O_AO_QUEUE);
    return(RUN_ACTIVE_USED);
    }
