📄 libevent.c
字号:
/* voifax event handling library * Copyright (C) 2004 Simone Freddio & Andrea Emanuelli * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include "libevent.h"#include <sys/types.h>#include <unistd.h>#include <stdio.h>#include <string.h>typedef struct { t_libevent_handler_entry item[MAX_HANDLERS];} t_libevent_list;static t_libevent_list libevent_handlers;static int search_free_handler(void);static int search_free_handler(void){ char module[] = "search_free_handler"; int a; for (a = 0; a < MAX_HANDLERS; a++) { if (libevent_handlers.item[a].handler == NULL) return a; } TRC(TRC_ERR, module, "No free handlers"); return -1;}int libevent_add_handler(t_libevent_handler *handler, char *event){ int hidx = search_free_handler(); if (hidx == -1) { return false; } libevent_handlers.item[hidx].handler = handler; strcpy(libevent_handlers.item[hidx].event, event); return true;}int libevent_remove_handler(t_libevent_handler *handler){ int a; for (a = 0; a < MAX_HANDLERS; a++) { if (libevent_handlers.item[a].handler == handler) { libevent_handlers.item[a].handler = NULL; libevent_handlers.item[a].event[0] = 0; return true; } } return false;}int libevent_process_event(char *message){ int a, c; char args[10][200]; char *argv[10]; int argc; for (a = 0; a < MAX_HANDLERS; a++) { if (libevent_handlers.item[a].handler != NULL && strncmp(libevent_handlers.item[a].event, message, strlen(libevent_handlers.item[a].event)) == 0) { argc = sscanf(message, "%s %s %s %s %s %s", args[0], args[1], args[2], args[3], args[4], args[5]); for (c = 0; c < argc; c++) { argv[c] = args[c]; } /*if (fork()>0) {*/ libevent_handlers.item[a].handler(argc, argv); /*}*/ return true; } } return true;}int libevent_call_handler(int argc, char **argv){ char module[] = "libevent_call_handler"; int a; if (argc == 0) { TRC(TRC_ERR, module, "Argc = 0!"); return false; } for (a = 0; a < MAX_HANDLERS; a++) { if (libevent_handlers.item[a].handler != NULL && strncmp(libevent_handlers.item[a].event, argv[0], strlen(libevent_handlers.item[a].event)) == 0) { return libevent_handlers.item[a].handler(argc, argv); } } return true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -