int event_proc(EatEvent_st* event) { int i = 0; LOG_DEBUG("event: %s happened", getEventDescription(event->event)); for (i = 0; i < sizeof(eventProcs) / sizeof(eventProcs[0]); i++) { if (eventProcs[i].event == event->event) { EVENT_FUNC pfn = eventProcs[i].pfn; if (pfn) { return pfn(event); } else { LOG_ERROR("event(%s) not processed!", getEventDescription(event->event)); return -1; } } } LOG_ERROR("event(%s) has no handler!", getEventDescription(event->event)); return -1; }
static void soc_notify_cb(s8 s,soc_event_enum event,eat_bool result, u16 ack_size) { u8 buffer[1152] = {0};//1K + 128 for upgrade module s32 rc = 0; LOG_DEBUG("SOCKET notify:socketid(%d), event(%s).", s, getEventDescription(event)); switch (event) { case SOC_READ: rc = eat_soc_recv(socket_id, buffer, 1152);//1K + 128 for upgrade module if (rc > 0) { client_proc(buffer, rc); } else { LOG_ERROR("eat_soc_recv error:rc=%d!", rc); } break; case SOC_CONNECT: if(result) { LOG_DEBUG("SOC_CONNECT success."); fsm_run(EVT_SOCKET_CONNECTED); } else { LOG_ERROR("SOC_CONNECT failed, maybe the server is OFF!"); fsm_run(EVT_SOCKET_CONNECT_FAILED); eat_soc_close(s); } break; case SOC_CLOSE: LOG_INFO("SOC_CLOSE:socketid = %d", s); eat_soc_close(s); fsm_run(EVT_SOCKET_DISCONNECTED); break; case SOC_ACKED: LOG_DEBUG("acked size of send data: %d.", ack_size); break; default: LOG_INFO("SOC_NOTIFY %d not handled", event); break; } }
int event_proc(EatEvent_st* event) { int i = 0; LOG_DEBUG("event: %s", getEventDescription(event->event)); for (i = 0; i < sizeof(msgProcs) / sizeof(msgProcs[0]); i++) { if (msgProcs[i].event == event->event) { EVENT_FUNC pfn = msgProcs[i].pfn; if (pfn) { return pfn(event); } else { LOG_ERROR("event(%d) not processed!", event->event); } } } return -1; }