void event_numeric (irc_session_t * session, unsigned int event, const char * origin, const char ** params, unsigned int count)
{
	char buf[24];
	sprintf (buf, "%d", event);

	dump_event (session, buf, origin, params, count);
}
void event_connect (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count)
{
	irc_ctx_t * ctx = (irc_ctx_t *) irc_get_ctx (session);
	dump_event (session, event, origin, params, count);

	irc_cmd_join (session, ctx->channel, 0);
}
예제 #3
0
void event_join( irc_session_t *irc_session, const char *event, const char *origin, const char **params, unsigned int count ) {
	ConfigArrayPtr settings[2];
	char nickbuf[128];
	char buffer[512];

dump_event( irc_session, event, origin, params, count );
irc_cmd_user_mode( irc_session, "+i" );
irc_target_get_nick( origin, nickbuf, sizeof(nickbuf) );

settings[0] = GetSetting( "IRC Bot Nick" );
if( !strcmp( nickbuf, settings[0]->string_value ) ) {
	info( "IRC Bot Joined Channel: %s", params[0] );
	snprintf(buffer, sizeof(buffer), "op %s", params[0] );	
	irc_cmd_msg( irc_session, "ChanServ", buffer );
} else if( !strcmp( nickbuf, "ChanServ" ) ) {
	settings[0] = GetSetting( "IRC Bot Pass" );
	if( settings[0]->string_value ){
		snprintf(buffer, sizeof(buffer), "identify %s", settings[0]->string_value );
		irc_cmd_msg( irc_session, "NickServ", buffer);
	}
	snprintf(buffer, sizeof(buffer), "op %s", params[0] );	
	irc_cmd_msg( irc_session, "ChanServ", buffer );
}

return;
}
void event_privmsg (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count)
{
	dump_event (session, event, origin, params, count);

	printf ("'%s' said me (%s): %s\n", 
		origin ? origin : "someone",
		params[0], params[1] );
}
예제 #5
0
static void addToList(struct ril_event * ev, struct ril_event * list)
{
    ev->next = list;
    ev->prev = list->prev;
    ev->prev->next = ev;
    list->prev = ev;
    dump_event(ev);
}
예제 #6
0
/* Append a new subscription event to the subscription event queue and schedule a main loop event */
void pa_subscription_post(pa_core *c, pa_subscription_event_type_t t, uint32_t idx) {
    pa_subscription_event *e;
    pa_assert(c);

    /* No need for queuing subscriptions of no one is listening */
    if (!c->subscriptions)
        return;

    if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) != PA_SUBSCRIPTION_EVENT_NEW) {
        pa_subscription_event *i, *n;

        /* Check for duplicates */
        for (i = c->subscription_event_last; i; i = n) {
            n = i->prev;

            /* not the same object type */
            if (((t ^ i->type) & PA_SUBSCRIPTION_EVENT_FACILITY_MASK))
                continue;

            /* not the same object */
            if (i->index != idx)
                continue;

            if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) {
                /* This object is being removed, hence there is no
                 * point in keeping the old events regarding this
                 * entry in the queue. */

                free_event(i);
                pa_log_debug("Dropped redundant event due to remove event.");
                continue;
            }

            if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_CHANGE) {
                /* This object has changed. If a "new" or "change" event for
                 * this object is still in the queue we can exit. */

                pa_log_debug("Dropped redundant event due to change event.");
                return;
            }
        }
    }

    e = pa_xnew(pa_subscription_event, 1);
    e->core = c;
    e->type = t;
    e->index = idx;

    PA_LLIST_INSERT_AFTER(pa_subscription_event, c->subscription_event_queue, c->subscription_event_last, e);
    c->subscription_event_last = e;

#ifdef DEBUG
    dump_event("Queued", e);
#endif

    sched_event(c);
}
예제 #7
0
static void removeFromList(struct ril_event * ev)
{
    dlog("~~~~ Removing event ~~~~");
    dump_event(ev);

    ev->next->prev = ev->prev;
    ev->prev->next = ev->next;
    ev->next = NULL;
    ev->prev = NULL;
}
예제 #8
0
파일: upil_event.c 프로젝트: albuer/upil
static void removeFromList(struct upil_event * ev)
{
    upil_printf(MSG_EXCESSIVE, "~~~~ Removing event ~~~~");
    dump_event(ev);

    ev->next->prev = ev->prev;
    ev->prev->next = ev->next;
    ev->next = NULL;
    ev->prev = NULL;
}
예제 #9
0
파일: ino.c 프로젝트: jimenezrick/fast-move
void watch_events(void)
{
	GNode *modified_directory, *removed_file;
	File *new_file;
	gboolean refresh_request = FALSE;
	struct timeval time;
	struct inotify_event *event;
	int n, i;
	fd_set fds;

	CHECK_INOTIFY_ENABLED();
again:	time.tv_sec = 0;
	time.tv_usec = 0;
	FD_ZERO(&fds);
	FD_SET(inotify_descriptor, &fds);
	while ((n = select(inotify_descriptor + 1, &fds, NULL, NULL, &time)) == 1) {
again2:		if ((n = read(inotify_descriptor, events_buffer, BUFFER_LENGTH)) > 0) {
			for (i = 0; i < n; i += sizeof(struct inotify_event) + event->len) {
				event = (struct inotify_event *) (events_buffer + i);
				if (debug_inotify == TRUE)
					dump_event(event);
				modified_directory = (GNode *) g_hash_table_lookup(
						watches_table, &(event->wd));

				if (event->mask & IN_CREATE || event->mask & IN_MOVED_TO) {
					if ((new_file = create_new_file(event->name,
									get_path(modified_directory), FALSE)) != NULL)
						refresh_request |= insert_in_tree(modified_directory, new_file);
				} else if (event->mask & IN_DELETE || event->mask & IN_MOVED_FROM) {
					if ((removed_file = search_node_by_name(modified_directory,
									event->name)) != NULL)
						refresh_request |= remove_from_tree(removed_file, FALSE);
				} else if (event->mask & IN_UNMOUNT) {
					refresh_request |= remove_from_tree(modified_directory, TRUE);
				}
			}
		} else if (n == -1) {
			if (errno == EINTR)
				goto again2;
			else
				PRINT_ERRNO_AND_EXIT();
		}
	}
	if (n == -1) {
		if (errno == EINTR)
			goto again;
		else
			PRINT_ERRNO_AND_EXIT();
	}
	if (refresh_request == TRUE)
		refresh_screen();
}
예제 #10
0
static bool removeFromList(struct ril_event * ev)
{
    dlog("~~~~ Removing event ~~~~");
	/* Make sure the event actually exists */
	if (!(ev->prev && ev->next))
		return false;
    dump_event(ev);
    ev->next->prev = ev->prev;
    ev->prev->next = ev->next;
    ev->next = NULL;
    ev->prev = NULL;
	return true;
}
예제 #11
0
static void process_event(struct mtp_event* event)
{
  switch(event->typ) {
  case MTP_EVENT_ISUP:
    l4isup_event(event);
    break;
  case MTP_EVENT_SCCP:
    break;
  case MTP_EVENT_REQ_REGISTER:
    if (event->regist.ss7_protocol == 5) {
      struct link* link = &links[event->regist.isup.slinkix];
      mtp3_register_isup(link->mtp3fd, link->linkix);
    }
    break;
  case MTP_EVENT_LOG:
    ast_log(event->log.level, event->log.file, event->log.line,
	    event->log.function, "%s", event->buf);
    break;

  case MTP_EVENT_DUMP:
    dump_event(event);
    break;

  case MTP_EVENT_STATUS:
    {
      struct link* link = event->status.link;
      char* name = link ? link->name : "(peer)";
      switch(event->status.link_state) {
      case MTP_EVENT_STATUS_LINK_UP:
	l4isup_link_status_change(link, 1);
	ast_log(LOG_WARNING, "MTP is now UP on link '%s'.\n", name);
	break;
      case MTP_EVENT_STATUS_LINK_DOWN:
	l4isup_link_status_change(link, 0);
	ast_log(LOG_WARNING, "MTP is now DOWN on link '%s'.\n", name);
	break;
      case MTP_EVENT_STATUS_INSERVICE:
	ast_log(LOG_WARNING, "Signaling ready for linkset '%s'.\n", link->linkset->name);
	l4isup_inservice(link);
	break;
      default:
	ast_log(LOG_NOTICE, "Unknown event type STATUS (%d), "
		"not processed.\n", event->status.link_state);
      }
    }
    break;

  default:
    ast_log(LOG_NOTICE, "Unexpected mtp event type %d.\n", event->typ);
  }
}
예제 #12
0
void event_connect( irc_session_t *irc_session, const char *event, const char *origin, const char **params, unsigned int count ) {
	ConfigArrayPtr setting;
	char buffer[512];
dump_event (irc_session, event, origin, params, count);
info( "IRC Bot Connected to server: %s", origin );
setting = GetSetting( "IRC Bot Pass" );
if( setting->string_value ){
	snprintf(buffer, sizeof(buffer), "identify %s", setting->string_value );
	irc_cmd_msg(sysconfig.irc_session, "NickServ", buffer);
}
setting = GetSetting( "IRC Channel" );
irc_cmd_join( irc_session, setting->string_value, 0 );

return;
}
예제 #13
0
/* Deferred callback for dispatching subscription events */
static void defer_cb(pa_mainloop_api *m, pa_defer_event *de, void *userdata) {
    pa_core *c = userdata;
    pa_subscription *s;

    pa_assert(c->mainloop == m);
    pa_assert(c);
    pa_assert(c->subscription_defer_event == de);

    c->mainloop->defer_enable(c->subscription_defer_event, 0);

    /* Dispatch queued events */

    while (c->subscription_event_queue) {
        pa_subscription_event *e = c->subscription_event_queue;

        for (s = c->subscriptions; s; s = s->next) {

            if (!s->dead && pa_subscription_match_flags(s->mask, e->type))
                s->callback(c, e->type, e->index, s->userdata);
        }

#ifdef DEBUG
        dump_event("Dispatched", e);
#endif
        free_event(e);
    }

    /* Remove dead subscriptions */

    s = c->subscriptions;
    while (s) {
        pa_subscription *n = s->next;
        if (s->dead)
            free_subscription(s);
        s = n;
    }
}
// OMX calls this handler for all the events it emits
static OMX_ERRORTYPE event_handler(
        OMX_HANDLETYPE hComponent,
        OMX_PTR pAppData,
        OMX_EVENTTYPE eEvent,
        OMX_U32 nData1,
        OMX_U32 nData2,
        OMX_PTR pEventData) {

    dump_event(hComponent, eEvent, nData1, nData2);

    appctx *ctx = (appctx *)pAppData;

    switch(eEvent) {
        case OMX_EventCmdComplete:
            vcos_semaphore_wait(&ctx->handler_lock);
            if(nData1 == OMX_CommandFlush) {
                ctx->flushed = 1;
            }
            vcos_semaphore_post(&ctx->handler_lock);
            break;
        case OMX_EventParamOrConfigChanged:
            vcos_semaphore_wait(&ctx->handler_lock);
            if(nData2 == OMX_IndexParamCameraDeviceNumber) {
                ctx->camera_ready = 1;
            }
            vcos_semaphore_post(&ctx->handler_lock);
            break;
        case OMX_EventError:
            omx_die(nData1, "error event received");
            break;
        default:
            break;
    }

    return OMX_ErrorNone;
}
예제 #15
0
static void
dump_result(pmResult *resp)
{
    int		i;
    int		j;
    int		n;
    char	**names;
    pmDesc	desc;

    if (sflag) {
	int		nbyte;
	nbyte = do_size(resp);
	printf("[%d bytes]\n", nbyte);
    }

    if (xflag) {
	char	       *ddmm;
	char	       *yr;

	ddmm = pmCtime(&resp->timestamp.tv_sec, timebuf);
	ddmm[10] = '\0';
	yr = &ddmm[20];
	printf("%s ", ddmm);
	__pmPrintStamp(stdout, &resp->timestamp);
	printf(" %4.4s", yr);
	if (xflag >= 2)
	    printf(" (%.6f)", __pmtimevalSub(&resp->timestamp, &label.ll_start));
    }
    else
	__pmPrintStamp(stdout, &resp->timestamp);

    if (resp->numpmid == 0) {
	printf("  <mark>\n");
	return;
    }

    for (i = 0; i < resp->numpmid; i++) {
	pmValueSet	*vsp = resp->vset[i];

	if (i > 0)
	    printf("            ");
	n = pmNameAll(vsp->pmid, &names);
	if (vsp->numval == 0) {
	    printf("  %s (", pmIDStr(vsp->pmid));
	    __pmPrintMetricNames(stdout, n, names, " or ");
	    printf("): No values returned!\n");
	    goto next;
	}
	else if (vsp->numval < 0) {
	    printf("  %s (", pmIDStr(vsp->pmid));
	    __pmPrintMetricNames(stdout, n, names, " or ");
	    printf("): %s\n", pmErrStr(vsp->numval));
	    goto next;
	}

	if (pmLookupDesc(vsp->pmid, &desc) < 0) {
	    /* don't know, so punt on the most common cases */
	    desc.indom = PM_INDOM_NULL;
	    if (vsp->valfmt == PM_VAL_INSITU)
		desc.type = PM_TYPE_32;
	    else
		desc.type = PM_TYPE_AGGREGATE;
	}

	for (j = 0; j < vsp->numval; j++) {
	    if (desc.type == PM_TYPE_EVENT ||
		desc.type == PM_TYPE_HIGHRES_EVENT)
		dump_event(n, names, vsp, j, desc.indom, desc.type);
	    else
		dump_metric(n, names, vsp, j, desc.indom, desc.type);
	}
next:
	if (n > 0)
	    free(names);
    }
}
예제 #16
0
unint parse_buf(u8 *buf)
{
	ring_header_s *rh = (ring_header_s *)buf;
	ring_event_s *r;
	unint commit;
	unint length;
	unint size = 0;
	u64 time;
	u8 *end;

	if (Dump) pr_ring_header(rh);
	time = rh->time_stamp;
	commit = rh->commit;
	buf += sizeof(*rh);
	end = &buf[commit];
	pthread_mutex_lock(&Count_lock);
	for (; buf < end; buf += size) {
		r = (ring_event_s *)buf;
		if (r->type_len == 0) {
			/* Larger record where size is at beginning of record */
			length = r->array[0];
			size = 4 + length * 4;
			time += r->time_delta;
		} else if (r->type_len <= 28) {
			/* Data record */
			length = r->type_len;
			size = 4 + length * 4;
			time += r->time_delta;
			if (Dump) {
				dump_event(buf);
			} else {
				parse_event(buf+4, time);
			}
		} else if (r->type_len == 29) {
			/* Left over page padding or discarded event */
			if (r->time_delta == 0) {
				break;
			} else {
				length = r->array[0];
				size = 4 + length * 4;
			}
		} else if (r->type_len == 30) {
			/* Extended time delta */
			size = 8;
			time += (((u64)r->array[0]) << 28) | r->time_delta;
		} else if (r->type_len == 31) {
			/* Sync time with external clock (NOT IMMPLEMENTED) */
			size = 12;
			time = r->array[0];
			time += *(u64 *)&(r->array[1]) * ONE_BILLION;
		} else {
			warn(" Unknown event %d", r->type_len);
			/* Unknown - ignore */
			size = 4;
			break;
		}
		if (size > end - buf) {
			break;
		}
	}
	pthread_mutex_unlock(&Count_lock);
	return commit;
}
void event_join (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count)
{
	dump_event (session, event, origin, params, count);
	irc_cmd_user_mode (session, "+i");
	irc_cmd_msg (session, params[0], "Hi all");
}
예제 #18
0
int main(int argc, char** argv){

	int fd;
	ssize_t r;

	struct input_event ev;

	openlog("buttond",LOG_PERROR,LOG_DAEMON);

	if (getuid()!=0) {
		syslog(LOG_ERR, "Started as non root terminating");
		return 1;
	}

	if(argc==2 && strncmp(argv[1],"-f",2)==0){
		syslog(LOG_NOTICE,"Running in foreground");	
	}else{
		syslog(LOG_NOTICE,"Daemonizing");	
		daemon(0,0);
		write_pidfile();
	}

	signal(SIGPIPE, SIG_IGN);
	signal(SIGHUP, SIG_IGN);
	signal(SIGINT, sighandler);
	signal(SIGTERM, sighandler);
	signal(SIGALRM, sigshutdown);


	if((fd=open(DEVICE,O_RDONLY))<0){
		syslog(LOG_ERR, "Failed to open device " DEVICE " %m");
		return 1;
	}

	devinfo(fd);

	while( dorun && ((r=read(fd,&ev,sizeof(ev)))>0)){
		if(r==sizeof(ev)){
			if(ev.type!=EV_KEY){
				continue;
			}
			dump_event(&ev);
			if(ev.value == B_KEY_DOWN){
				syslog(LOG_DEBUG, "Start shutdown timer");
				alarm(POWER_DOWN_DELAY);
			}else if(ev.value == B_KEY_UP){
				syslog(LOG_DEBUG, "Cancel shutdown timer");
				alarm(0);
			}

		}else{
			syslog(LOG_DEBUG,"Got event %zu bytes",r);
		}	
	}

	close(fd);
	syslog(LOG_NOTICE, "Daemon terminating");
	closelog();

	unlink(PIDFILE);

	return 0;
}
int main(int argc, char *argv[])
{
	static const char short_options[] = "hVlp:";
	static const struct option long_options[] = {
		{"help", 0, NULL, 'h'},
		{"version", 0, NULL, 'V'},
		{"list", 0, NULL, 'l'},
		{"port", 1, NULL, 'p'},
		{ }
	};

	int do_list = 0;
	struct pollfd *pfds;
	int npfds;
	int c, err;

	init_seq();

	while ((c = getopt_long(argc, argv, short_options,
				long_options, NULL)) != -1) {
		switch (c) {
		case 'h':
			help(argv[0]);
			return 0;
		case 'V':
			version();
			return 0;
		case 'l':
			do_list = 1;
			break;
		case 'p':
			parse_ports(optarg);
			break;
		default:
			help(argv[0]);
			return 1;
		}
	}
	if (optind < argc) {
		help(argv[0]);
		return 1;
	}

	if (do_list) {
		list_ports();
		return 0;
	}

	create_port();
	connect_ports();

	err = snd_seq_nonblock(seq, 1);
	check_snd("set nonblock mode", err);
	
	if (port_count > 0)
		printf("Waiting for data.");
	else
		printf("Waiting for data at port %d:0.",
		       snd_seq_client_id(seq));
	printf(" Press Ctrl+C to end.\n");
	printf("Source  Event                  Ch  Data\n");
	
	signal(SIGINT, sighandler);
	signal(SIGTERM, sighandler);

	npfds = snd_seq_poll_descriptors_count(seq, POLLIN);
	pfds = alloca(sizeof(*pfds) * npfds);
	for (;;) {
		snd_seq_poll_descriptors(seq, pfds, npfds, POLLIN);
		if (poll(pfds, npfds, -1) < 0)
			break;
		do {
			snd_seq_event_t *event;
			err = snd_seq_event_input(seq, &event);
			if (err < 0)
				break;
			if (event)
				dump_event(event);
		} while (err > 0);
		fflush(stdout);
		if (stop)
			break;
	}

	snd_seq_close(seq);
	return 0;
}