inline void pigeonhole::_pige_line(int line, string& raw) { bool flag_no_match = true; for (slot_set_type::iterator it = _slots.begin(); it != _slots.end(); ++it) { // begin for boost::smatch match; if (regex_match(raw, match, it->pattern)) { flag_no_match = false; try { if (it->handler) { it->handler(line, raw, match); continue; } } catch (...) { } }//end if }// end for if (flag_no_match&&raw.size()) { try { if (_default_handler) _default_handler(line, raw); } catch (...) { } } }
static void _process_event(watch_entry_t *pentry) { static char buf[1024]; static char path_buf[256]; int path_len; char *dir_name = NULL; static int ret = 0; ret = read(pentry->fd, buf, sizeof(buf)); if( ret > 0 ) { char *cur = buf; struct inotify_event *pie = NULL; /* see defination: use man 7 inotify */ E_CHANGE_MODE_t change_mode = NO_CHANGE; while( ret > 0 ) { pie = (struct inotify_event*)cur; #if 0 dbg("watch_fd = %d\nmask = 0x%x\ncookie = 0x%x\nlen = %d\nname = %s\n", pie->wd, pie->mask, pie->cookie, pie->len, pie->name); #endif /* inotify_event to our event */ if( pie->mask & IN_MOVE_SELF ) change_mode = SELF_MOVE; else if( pie->mask & IN_DELETE_SELF ) change_mode = SELF_DELETE; else if( pie->mask & IN_CREATE ) change_mode = SUB_CREATE; else if( pie->mask & IN_DELETE ) change_mode = SUB_DELETE; else if( pie->mask & IN_MOVED_FROM ) change_mode = SUB_MOVE_FROM; else if( pie->mask & IN_MOVED_TO ) change_mode = SUB_MOVE_TO; #if 0 /* self_move, cannot find the new name, ? * just replace it's new name */ #endif /* prefix path */ path_len = sizeof(path_buf)-128; memset(path_buf, 0, sizeof(path_buf)); dir_name = _get_path_by_fd(pentry, pie->wd, path_buf, &path_len); dbg("mask=0x%0x dir_name = %s pie_name=%s<END>\n", pie->mask, dir_name, pie->name); /* this path or filename */ dbg("dir_name=%s pie->name=%s\n", dir_name, pie->name); if( dir_name ) strcat(dir_name, pie->name); /* call default handler */ /* this will add or remove the fd */ _default_handler(pentry, pie->wd, dir_name, change_mode); /* call user's process handler */ if( pentry->handler ) { pentry->handler(pie->wd, dir_name, change_mode); } /* for next event */ cur += (sizeof(struct inotify_event) + pie->len); ret -= (sizeof(struct inotify_event) + pie->len); } } }