~foura/libacme

cdd8844c69f9e0848fc9e3e8ac8e73adca59d44d — james palmer 1 year, 10 months ago b26a8fb
events: better naming for event functions. added aeventopen, aeventclose.

- this naming makes more sense.
- open and close functions mean the program does not
  need to manually set w->eventfd.
4 files changed, 37 insertions(+), 12 deletions(-)

M acme.h
M event.c
M libacme.man
M window.c
M acme.h => acme.h +5 -3
@@ 13,8 13,8 @@ struct AWin {
	int ctlfd;
	int addrfd;
	int datafd;
	int eventfd;
	int bodyfd;
	int eventfd;

	char buf[512];
	char *bufp;


@@ 50,5 50,7 @@ int		awinput(AWin *, char *);
int		awinaddtag(AWin *, char *);
int		awinsettag(AWin *, char *);

int		aeventnext(AWin *, AEvent *);
int		aeventsend(AWin *, AEvent *);
void	aeventopen(AWin *);
int		aeventread(AWin *, AEvent *);
int		aeventwrite(AWin *, AEvent *);
void	aeventclose(AWin *w);

M event.c => event.c +16 -2
@@ 77,8 77,15 @@ getdata(AWin *w, AEvent *e)
	return o;
}

void
aeventopen(AWin *w)
{
	if(w->eventfd < 0)
		w->eventfd = awinfsopen(w, "event", ORDWR);
}

int
aeventnext(AWin *w, AEvent *e)
aeventread(AWin *w, AEvent *e)
{
	int flags;
	


@@ 107,10 114,17 @@ loop:
}

int
aeventsend(AWin *w, AEvent *e)
aeventwrite(AWin *w, AEvent *e)
{
	if(e->flags & 0x2)
		return fprint(w->eventfd, "%c%c%d %d\n", e->origin, e->type, e->p, e->p);
	else
		return fprint(w->eventfd, "%c%c%d %d\n", e->origin, e->type, e->q0, e->q1);
}

void
aeventclose(AWin *w)
{
	close(w->eventfd);
	w->eventfd = -1;
}

M libacme.man => libacme.man +15 -7
@@ 28,9 28,13 @@ acme \- functions for interacting with acme's filesystem interface
.B void		awinsettag(AWin *w, char *tag);
.br
.PP
.B void		aeventstop(AWin *w);
.B void		aeventlisten(AWin *w);
.br
.B void		aeventnext(AWin *w);
.br
.B void		aeventsend(AWin *w, AEvent *ev);
.br
.B void		aeventstop(AWin *w);
.SH DESCRIPTION
.PP
These routines provide a C interface to


@@ 63,15 67,19 @@ into
to the end of the window tag.
.I Awinsettag replaces the current window tag.
.PP
.I Aeventnext reads the next event into
.I Aeventopen
opens the window event file. It should be called before using
.IR aeventnext .
.I Aeventread
reads the next event into
.BR ev .
.I Aventsend writes the event
.I Aventwrite
writes the event
.B ev
to the events file.
They require 
.B w->eventfd
to be a file descriptor reffering to
the event file in the window\'s directory.
.I Aeventclose
closes the event file. It should be called when the program
no longer wishes to process events.
.SH FILES
.PP
.B /sys/include/acme.h

M window.c => window.c +1 -0
@@ 36,6 36,7 @@ awincreate(void)
	w->addrfd = awinfsopen(w, "addr", ORDWR);
	w->datafd = awinfsopen(w, "data", ORDWR);
	w->bodyfd = awinfsopen(w, "body", OWRITE);
	w->eventfd = -1;

	w->next = awins;
	awins = w;