void * kqwork(void *arg) { int ret; struct kevent ev; char *name, *flags; while(not_done) { /* Do our stopping thing */ pthread_mutex_lock(&mut); pthread_mutex_unlock(&mut); /* Now go get the kqueue */ ret = kevent(kq, NULL, 0, &ev, 1, NULL); if (ret > 0) { name = get_filter_name(ev.filter); flags = get_flags_name(ev.flags); if (silence == 0) { printf("Filter %s ident:%d flags:%s fflags:0x%x data:%p udata:%p\n", name, (int)ev.ident, flags, (uint32_t)ev.fflags, (void *)ev.data, ev.udata); } if (flags) { free(flags); } } else if (ret < 0) { if (errno == EINTR) { continue; } printf("Kq bad event errno:%d -- exiting thread\n", errno); break; } } return(NULL); }
// Returns NULL or non-NULL, depending on if anything is available or not // when it is called. DCBuffer * DCFilter::read_non_blocking(const std::string & portName) { // Gets Anthill input port handler InputPortHandler inPort = dsGetInputPortByName((char *) portName.c_str()); if(inPort == -1) { string exitMsg = "read_non_blocking: There is no port "+portName+" in filter "+get_filter_name(); dsExit((char *)exitMsg.c_str()); } // Reads the data using Anthill int bufSz = dsReadNonBlockingBuffer(inPort, recvBuf->getBufPtr(), recvBuf->getSize()); if (bufSz == 0) { // There is no data to be received now. return NULL; } if (bufSz != EOW) { // Pack the data in a DCBuffer DCBuffer * dcBuf = new DCBuffer(bufSz); memcpy(dcBuf->getPtr(), recvBuf->getBufPtr(), bufSz); dcBuf->setUsedSize(bufSz); return dcBuf; } // Received an EOW. There isn't more data to be received. return NULL; }
std::string DCFilter::get_param(const std::string & key) { if (user_params.count(key) == 0) { std::cerr << "ERROR: invalid get_param call on key '" << key << "' in filter " << get_filter_name() << " rank " << get_my_rank() << std::endl << std::flush; exit(1); } return user_params[key]; }
int DCFilter::close_out_port(std::string portName) { // Gets Anthill output port handler OutputPortHandler outPort = dsGetOutputPortByName((char *) portName.c_str()); if(outPort == -1) { string exitMsg = "close_out_port: There is no port "+portName+" in filter "+get_filter_name(); dsExit((char *)exitMsg.c_str()); } return dsCloseOutputPort(outPort); }
int filterA::init(){ cout << "init " << get_filter_name() << " Id: " << get_global_filter_thread_id() << ". Rank: " << get_my_rank() << "\n"; if(has_out_port("out")) { get_out_port_names(); } if(has_in_port("in")) { get_in_port_names(); } return 0; }
// Writes packed buffer to other filter void DCFilter::write(DCBuffer *buf, const std::string & portName) { // Gets Anthill output port handler OutputPortHandler outPort = dsGetOutputPortByName((char *) portName.c_str()); if(outPort == -1) { string exitMsg = "write: There is no port "+portName+" in filter "+get_filter_name(); dsExit((char *)exitMsg.c_str()); } // Gets the packed buffer that will be written void *dsBuf = (void *) buf->getPtr(); int dsBufSz = buf->getUsedSize(); // Writes the packed buffer using Anthill dsWriteBuffer(outPort, dsBuf, dsBufSz); }
void add_dialog_filters(GtkWidget *dialog, char * const p_types[], uint4 p_type_count ) { GtkFileFilter *filter ; if ( p_type_count >= 1 ) { for (uint4 a=0; a < p_type_count; a++) { char *t_filter_name, *t_filter_masks; t_filter_name = get_filter_name(p_types[a]); t_filter_masks = get_filter_masks(p_types[a]); filter = gtk_file_filter_new(); gtk_file_filter_set_name(filter, t_filter_name); if (strcasecmp (t_filter_name, "All files") != 0) { for ( uint4 m = 0 ; m < get_filter_count(t_filter_masks); m++) { char *t_filter_mask; t_filter_mask = get_filter_mask(m, t_filter_masks); char *filter_mask; filter_mask = nil; MCCStringFormat(filter_mask, "*.%s", t_filter_mask); gtk_file_filter_add_pattern(filter, filter_mask); MCCStringFree(filter_mask); delete t_filter_mask; } } else gtk_file_filter_add_pattern ( filter, "*" ); gtk_file_chooser_add_filter ( GTK_FILE_CHOOSER ( dialog ) , filter ) ; delete t_filter_name; delete t_filter_masks; } } }
int filterA::process(){ cout << "process " << get_filter_name() << " Id: " << get_global_filter_thread_id() << ". Rank: " << get_my_rank() << "\n"; DCBuffer * outBuffer = new DCBuffer(100); outBuffer->pack("s", "Hellow!!!"); write (outBuffer, "out"); outBuffer->Delete(); DCBuffer * outBuffer1 = new DCBuffer(100); outBuffer1->pack("s", "NonBlocking message."); write_nocopy(outBuffer1, "out"); outBuffer1->Delete(); //filter_exit("Nao e' nada nao"); return 0; }
int filterA::fini(){ cout << "finalize " << get_filter_name() << " Id: " << get_global_filter_thread_id() << ". Rank: " << get_my_rank() << "\n"; return 0; }
int cmd_kevent(char *argv[], int argc) { struct kevent event; u_short def; int fd, i, ret; short filt; char *flags; if (argc < 2) { unknown: printf("You need at minimum two args fd and type\n"); printf("akq fd type ..options..\n"); printf("fd = a file descriptor\n"); printf("type = read or write\n"); printf("options include:\n"); printf(" - add\n"); printf(" - clear\n"); printf(" - delete\n"); printf(" - disable\n"); printf(" - dispatch\n"); printf(" - enable\n"); printf(" - oneshot\n"); printf(" - receipt\n"); return(0); } fd = strtol(argv[0], NULL, 0); if (strcmp(argv[1], "read") == 0) { filt = EVFILT_READ; } else if (strcmp(argv[1], "write") == 0) { filt = EVFILT_WRITE; } else { printf("Unkown filter type %s\n", argv[1]); goto unknown; } if (argc == 2) { def = EV_ADD|EV_ENABLE|EV_DISPATCH; } else { def = 0; for(i=2; i<argc; i++) { if (strcmp(argv[i], "disable") == 0) { def |= EV_DISABLE; } else if (strcmp(argv[i], "delete") == 0) { def |= EV_DELETE; } else if (strcmp(argv[i], "enable") == 0) { def |= EV_ENABLE; } else if (strcmp(argv[i], "add") == 0) { def |= EV_ADD; } else if (strcmp(argv[i], "dispatch") == 0) { def |= EV_DISPATCH; } else if (strcmp(argv[i], "receipt") == 0) { def |= EV_RECEIPT; } else if (strcmp(argv[i], "oneshot") == 0) { def |= EV_ONESHOT; } else if (strcmp(argv[i], "clear") == 0) { def |= EV_CLEAR; } else { printf("Unknown option %s - skipping\n", argv[i]); } } } EV_SET(&event, fd, filt, def, 0, 0, (void *)count); flags = get_flags_name(event.flags); printf("Set in fd:%d fil:%s flags:%s count:%d\n", fd, get_filter_name(event.filter), flags, count); count++; if (flags) { free(flags); } errno = 0; ret = kevent(kq, &event, 1, NULL, 0, NULL); printf("Returns %d errno:%d\n", ret, errno); return(0); }
static int getFiletriggers_raw(const char * rootDir, int * nftp, struct filetrigger_raw ** list_raw) /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/ /*@modifies *nftp, *list_raw, rpmGlobalMacroContext, fileSystem, internalState @*/ { const char * dn = filetriggers_dir(); const char * globstr = NULL; ARGV_t av = NULL; int ac = 0; int xx; int i; if (dn == NULL) goto exit; globstr = rpmGetPath(rootDir, dn, "/*" FILTER_EXTENSION, NULL); xx = rpmGlob(globstr, &ac, &av); if (ac == 0) goto exit; *list_raw = xcalloc(ac, sizeof(**list_raw)); for (i = 0; i < ac; i++) { const char * fn = av[i]; int fdno = open(fn, O_RDONLY); struct stat sb; if (fdno == -1) { rpmlog(RPMLOG_ERR, "opening %s failed: %s\n", fn, strerror(errno)); continue; } if (fstat(fdno, &sb) == 0 && sb.st_size > 0) { size_t bn = sb.st_size; char * b = xmalloc(bn + 1); if (read(fdno, b, bn) != (ssize_t)bn) { rpmlog(RPMLOG_ERR, "reading %s failed: %s\n", fn, strerror(errno)); b = _free(b); } else { char * be = b + bn; *be = '\0'; if ((be = strchr(b, '\n')) != NULL) { *be = '\0'; while (be > b && xisspace((int)be[-1])) *(--be) = '\0'; } (*list_raw)[i].regexp = b; (*list_raw)[i].name = get_filter_name(fn); } } xx = close(fdno); } exit: if (nftp != NULL) *nftp = ac; av = argvFree(av); globstr = _free(globstr); return RPMRC_OK; }