00055 {
00056
struct timeval tv;
00057
char c;
00058
00059
for(;;)
00060 {
00061
switch (m_state)
00062 {
00063
case 0:
00064
00065
if (!pclIOT -> get_iq())
00066
return;
00067 pclIOT -> read_input( &c, 1 );
00068
if (c == 0x02)
00069 m_state = 1;
00070
break;
00071
case 1:
00072
DEB(printf(
"EventFactory state 1\n");)
00073 if (pclIOT -> get_iq() < m_l0)
00074 return;
00075 pclIOT -> read_input( (
char *)&m_id, sizeof(IO_IDTYPE) );
00076 pclIOT -> read_input( (
char *)&m_length, sizeof(IO_LENGTHTYPE) );
00077 m_state = 2;
00078 break;
00079 case 2:
00080 DEB(printf("
EventFactory state 2\n");)
00081 if (pclIOT -> get_iq() < m_length - m_l0)
00082 return;
00083 m_state = 0;
00084 if ( (m_pclMessage = GetClass(m_id)) == NULL)
00085 {
00086 fprintf(stderr,
"EventFactory, GetClass() failed, id = %d\n",m_id);
00087
return;
00088 }
00089
#ifdef TRY_VAR
00090
m_pclMessage -> ReadVars(pclIOT);
00091
#else
00092
m_pclMessage -> read_message(pclIOT);
00093
#endif
00094
00095
if (m_pclMessage -> GetIOFamily() == IOF_FORM)
00096 {
00097
DEB(printf(
"Form received - add to input thread form list\n");)
00098
00099 SDL_Event e;
00100
00101 m_pclMessage -> FormInit(pclIOT);
00102 e.user.type = SDL_USEREVENT;
00103 e.user.code = SDL_USEREVENT_ADDFORM;
00104 e.user.data1 = m_pclMessage;
00105 e.user.data2 = NULL;
00106 SDL_PushEvent(&e);
00107 }
00108 else
00109 {
00110
00111
if (m_pclMessage -> GetID() != EVENT_SYNC)
00112 {
00113 tv.tv_usec = (m_pclMessage -> GetTicks() -
ticks.get_sync()) * 1000;
00114
long l = tv.tv_usec / 1000;
00115 tv.tv_sec = tv.tv_usec / 1000000;
00116 tv.tv_usec %= 1000000;
00117
if (tv.tv_sec > 0 || tv.tv_usec > 0)
00118 {
00119
DEB(printf(
"timing event (%ld,%ld) %ld ms\n", tv.tv_sec,tv.tv_usec,l);)
00120 SDL_Delay(l);
00121 }
00122 }
00123 m_pclMessage -> Execute(pclIOT);
00124 }
00125 if (m_pclMessage -> DeleteOnExecute())
00126 {
00127
delete m_pclMessage;
00128 }
00129
break;
00130 }
00131 }
00132 }