Esempio n. 1
0
void fetch(void)
{
    prep_signals();
    if (nsig > 0) map_signals();
    prep_annotators();
    prep_times();
    printf("{ \"fetch\":\n");
    if ((fetchsignals() + fetchannotations()) == 0) printf("null");
    printf("}\n");
}
int main(void)
{
	int sfd, epfd;
	struct connection main_c;
	struct epoll_event new_evts[MAX_CONNECTIONS];

	if (unittest_http_parse(0)) return -1;

	prep_signals();

	epfd = epoll_create(MAX_CONNECTIONS);
	sfd = connmgr_create_server(8000);
	main_c.evt_id = sfd;
	event_new(epfd, &main_c);

	cos_init(NULL);

	while (1) {
		int nevts, i, accept_event = 0;

		nevts = epoll_wait(epfd, new_evts, MAX_CONNECTIONS, -1);
		if (nevts < 0) {
			perror("waiting for events");
			return -1;
		}
		for (i = 0 ; i < nevts ; i++) {
			struct epoll_event *e = &new_evts[i];
			struct connection *c = (struct connection *)e->data.ptr;

			if (c == &main_c) {
				if (e->events & (EPOLLERR | EPOLLHUP)) {
					printf("errors on the listen fd\n");
					return -1;
				}
				accept_event = 1;
			} else if (e->events & (EPOLLERR | EPOLLHUP)) {
				event_delete(epfd, c);
				close(c->evt_id);
				http_close_connection(c->conn_id);
				/* FIXME: free requests for connection */
			} else {
				int ret;

				ret = connection_event(c);
				if (ret > 0) {
					event_delete(epfd, c);
					close(c->evt_id);
					http_close_connection(c->conn_id);
				} else if (ret < 0) {
					return -1;
				}
			}
		}

		if (accept_event) {
			struct connection *c;
			c = connmgr_accept(main_c.evt_id);
			if (NULL == c) {
				printf("Not a large enough connection namespace.");
			} else {
				event_new(epfd, c);
			}
		}
	}
	return 0;
}
Esempio n. 3
0
void info(void)
{
    char *info, *p;
    int i;
    WFDB_Time t;

    prep_signals();
    if (nsig < 0) {
	lwfail("The '.hea' file could not be read");
	return;
    }
    printf("{ \"info\":\n");
    printf("  { \"db\": %s,\n", p = strjson(db)); SFREE(p);
    printf("    \"record\": %s,\n", p = strjson(record)); SFREE(p);
    printf("    \"tfreq\": %g,\n", tfreq);
    p = timstr(0);
    if (*p == '[') {
        printf("    \"start\": \"%s\",\n", mstimstr(0L));
	printf("    \"end\": \"%s\",\n", mstimstr(-strtim("e")));
    }
    else {
        printf("    \"start\": null,\n");
	printf("    \"end\": null,\n");
    }
    t = strtim("e");
    if (t > (WFDB_Time)0) {
	p = mstimstr(t);
	while (*p == ' ') p++;
	printf("    \"duration\": \"%s\",\n", p);
    }
    else
	printf("    \"duration\": null,\n");

    if (nsig > 0) {
	printf("    \"signal\": [\n");
	for (i = 0; i < nsig; i++) {
	    printf("      { \"name\": %s,\n", p = strjson(sname[i])); SFREE(p);
	    printf("        \"tps\": %g,\n", tfreq/(ffreq*s[i].spf));
	    if (s[i].units) {
		printf("        \"units\": %s,\n", p = strjson(s[i].units));
		SFREE(p);
	    }
	    else
		printf("        \"units\": null,\n");
	    printf("        \"gain\": %g,\n",
		   s[i].gain ? s[i].gain : WFDB_DEFGAIN);
	    printf("        \"adcres\": %d,\n", s[i].adcres);
	    printf("        \"adczero\": %d,\n", s[i].adczero);
	    printf("        \"baseline\": %d\n", s[i].baseline);
	    printf("      }%s", i < nsig-1 ? ",\n" : "\n    ],\n");
	}
    }
    else
	printf("    \"signal\": null,\n");

    if (info = getinfo(recpath)) {
	printf("    \"note\": [\n      %s", p = strjson(info));
	while (info = getinfo((char *)NULL)) {
	    printf(",\n      %s", p = strjson(info));
	    SFREE(p);
	}
	printf("\n    ]\n");
    }
    else
	printf("    \"note\": null\n");

    printf("  },\n");
    lwpass();
}