Commit 60f27edd authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Remove old valclient stuff

Various small fixes
parent d94567dc
......@@ -33,7 +33,6 @@
#include <errno.h>
#define TIMEOUT 10
#define VALCLIENT_UPDATE_NSEC (100*1000*1000)
static char *tr_host;
static int tr_port;
......@@ -47,6 +46,7 @@ struct private {
time_t lastclient;
struct trace_value lastvalue;
bool firstvalue;
};
......@@ -69,14 +69,21 @@ static void common_denom(struct timespec *common, struct timespec *int1, struct
d1 = i1 / b;
d2 = i2 / b;
if (d2 && d1 > d2 && !(d1 % d2)) {
if (d1 == d2) {
inew = d1;
} else if (d2 && d1 > d2 && !(d1 % d2)) {
inew = d2;
} else if (d1 && d2 > d1 && !(d2 % d1)) {
inew = d1;
} else {
inew = 1;
if (!d1 && d2)
inew = d2;
else if (d1 && !d2)
inew = d1;
else
inew = 1;
}
common->tv_sec = base_interval.tv_sec * inew;
common->tv_nsec = base_interval.tv_nsec * inew;
common->tv_sec += common->tv_nsec / 1000000000;
......@@ -89,23 +96,17 @@ static void server_interval_check(struct trace *server)
enum trace_interval_type type = 0;
struct timespec interval;
int i;
bool has_valclient;
bool fullrate = false;
interval.tv_sec = 0;
interval.tv_nsec = 0;
has_valclient = priv->lastclient + TIMEOUT > time(NULL);
if (has_valclient) {
interval.tv_sec = 0;
interval.tv_nsec = VALCLIENT_UPDATE_NSEC;
}
for (i = 0; i < priv->nr_clients; i++) {
switch (priv->clients[i]->interval_type) {
case TRACE_INTERVAL_TYPE_INTERVAL:
if (type) {
if (type && type != TRACE_INTERVAL_TYPE_INTERVAL) {
printf("Different types requested\n");
fullrate = true;
} else {
type = TRACE_INTERVAL_TYPE_INTERVAL;
......@@ -117,7 +118,8 @@ static void server_interval_check(struct trace *server)
break;
case TRACE_INTERVAL_TYPE_CHANGED:
if (type) {
if (type && type != TRACE_INTERVAL_TYPE_CHANGED) {
printf("Different types requested\n");
fullrate = true;
} else {
type = TRACE_INTERVAL_TYPE_CHANGED;
......@@ -129,18 +131,6 @@ static void server_interval_check(struct trace *server)
}
if (!type && has_valclient) {
switch (server->type) {
case TRACE_VALUE_TYPE_FLOAT:
type = TRACE_INTERVAL_TYPE_INTERVAL;
interval.tv_sec = 0;
interval.tv_nsec = VALCLIENT_UPDATE_NSEC;
break;
default:
type = TRACE_INTERVAL_TYPE_CHANGED;
}
}
if (fullrate) {
type = TRACE_INTERVAL_TYPE_INTERVAL;
interval.tv_sec = base_interval.tv_sec;
......@@ -220,12 +210,29 @@ static void client_interval(struct trace *trace,
}
static struct trace_pkt *list_pkt;
static char **list_names;
static int nr_list_names;
static bool check_list(char *name)
{
int i;
for (i = 0; i < nr_list_names; i++) {
if (!strcmp(name, list_names[i]))
return true;
}
return false;
}
static void handler_list_entry(struct trace *trace,
char *name, enum trace_value_type type, char *unit)
{
trace_packet_list_add(list_pkt, name, type, unit);
nr_list_names++;
list_names = realloc(list_names, sizeof(char *)*nr_list_names);
list_names[nr_list_names-1] = strdup(name);
trace_autorecover(trace, false);
}
......@@ -270,7 +277,7 @@ static void server_value(struct trace *trace,
else
changed = false;
priv->lastvalue.value.u32 = value->value.u32;
pkt = trace_packet_new();
trace_packet_value_add(pkt, value, trace->type);
......@@ -279,7 +286,7 @@ static void server_value(struct trace *trace,
switch (priv->clients[i]->interval_type) {
case TRACE_INTERVAL_TYPE_CHANGED:
send = changed;
send = changed || priv->firstvalue;
break;
case TRACE_INTERVAL_TYPE_INTERVAL:
send =!timespec_mod(&value->t,
......@@ -302,6 +309,7 @@ static void server_value(struct trace *trace,
}
trace_packet_put(pkt);
}
priv->firstvalue = false;
}
static void server_timestamp(struct trace *trace,
......@@ -403,6 +411,9 @@ static struct trace *server_find(char *name)
struct private *priv;
int i;
if (!check_list(name))
return NULL;
for (i = 0; i < nr_server_traces; i++) {
if (!strcmp(server_traces[i]->name, name))
break;
......@@ -427,6 +438,7 @@ static struct trace *server_find(char *name)
priv = calloc(sizeof(struct private), 1);
trace->private = priv;
priv->firstvalue = true;
server_traces[nr_server_traces] = trace;
......@@ -449,6 +461,10 @@ static void client_add(struct trace *client)
printf("Going to add client to trace '%s'\n", client->name);
trace = server_find(client->name);
if (!trace) {
trace_free(client);
printf("Trace not found\n");
}
priv = trace->private;
......@@ -479,134 +495,10 @@ static void client_add(struct trace *client)
printf("Trace now has %d clients\n", priv->nr_clients);
}
struct valclient {
int fd;
size_t len;
char request[1024];
};
int nr_valclients;
struct valclient **valclients;
static void free_val(int i)
{
free(valclients[i]);
memmove(&valclients[i], &valclients[i+1],
(nr_valclients-i-1)*sizeof(struct valclient *));
nr_valclients--;
}
static void val_accept(fd_listenval)
{
int fd;
struct valclient *valclient;
fd = tcp_accept(fd_listenval);
if (fd < 0)
return;
ioctl(fd, FIONBIO, &(int){ 1 });
valclient = calloc(1, sizeof(struct valclient));
valclient->fd = fd;
valclient->len = 0;
valclients = realloc(valclients,
sizeof(struct valclient*)*(nr_valclients + 1));
valclients[nr_valclients] = valclient;
nr_valclients++;
}
static void val_handle(struct valclient *valclient)
{
ssize_t r;
int i;
char reply[1024];
r = read(valclient->fd, &valclient->request[valclient->len],
1024 - valclient->len);
if ((r < 0 && errno != EAGAIN) || r == 0) {
close(valclient->fd);
valclient->fd = -1;
return;
}
valclient->len += r;
for (i = 0; i < valclient->len - 1; i++) {
if (!valclient->request[i] && !valclient->request[i+1]) {
char *name;
char *replyp;
time_t now = time(NULL);
replyp = reply;
for (name = valclient->request; name[0];
name += strlen(name) + 1) {
struct trace *trace;
struct private *priv;
bool int_check;
trace = server_find(name);
priv = trace->private;
int_check = priv->lastclient + TIMEOUT < now;
priv->lastclient = now;
if (int_check);
server_interval_check(trace);
switch(trace->type) {
case TRACE_VALUE_TYPE_FLOAT:
replyp += sprintf(replyp, "%g ",
trace->value.value.f);
break;
case TRACE_VALUE_TYPE_BOOL:
replyp += sprintf(replyp, "%d ",
trace->value.value.b);
break;
case TRACE_VALUE_TYPE_UINT8:
replyp += sprintf(replyp, "%d ",
trace->value.value.u8);
break;
case TRACE_VALUE_TYPE_UINT16:
replyp += sprintf(replyp, "%d ",
trace->value.value.u16);
break;
case TRACE_VALUE_TYPE_UINT32:
replyp += sprintf(replyp, "%d ",
trace->value.value.u32);
break;
case TRACE_VALUE_TYPE_SINT8:
replyp += sprintf(replyp, "%d ",
trace->value.value.s8);
break;
case TRACE_VALUE_TYPE_SINT16:
replyp += sprintf(replyp, "%d ",
trace->value.value.s16);
break;
case TRACE_VALUE_TYPE_SINT32:
replyp += sprintf(replyp, "%d ",
trace->value.value.s32);
break;
}
}
sprintf(replyp, "\n");
write(valclient->fd, reply, strlen(reply));
close(valclient->fd);
valclient->fd = -1;
}
}
}
int main (int argc, char **argv)
{
int fd_listen, fd_listenval;
int fd_listen;
fd_set fd_rd;
struct trace *list;
int high, i, j;
......@@ -617,12 +509,6 @@ int main (int argc, char **argv)
return 1;
}
fd_listenval = tcp_listen(CONSOLE_TRACE_VAL_PORT, 0, 100);
if (fd_listenval < 0) {
printf("Could not open listen port %d\n", CONSOLE_TRACE_VAL_PORT);
return 1;
}
signal(SIGPIPE, SIG_IGN);
/* determine socket on dt_ctrl */
......@@ -671,9 +557,6 @@ int main (int argc, char **argv)
high = fd_listen;
FD_SET(fd_listen, &fd_rd);
FD_SET(fd_listenval, &fd_rd);
if (fd_listenval > high)
high = fd_listenval;
for (i = 0; i < nr_client_traces; i++) {
trace_fd_set(client_traces[i], &fd_rd, &high);
......@@ -686,30 +569,13 @@ int main (int argc, char **argv)
trace_fd_set(priv->clients[j], &fd_rd, &high);
}
}
for (i = 0; i < nr_valclients; i++) {
FD_SET(valclients[i]->fd, &fd_rd);
if (valclients[i]->fd > high)
high = valclients[i]->fd;
}
select(high + 1, &fd_rd, NULL, NULL, &timeout);
if (FD_ISSET(fd_listen, &fd_rd)) {
client_accept(fd_listen);
}
if (FD_ISSET(fd_listenval, &fd_rd)) {
val_accept(fd_listenval);
}
for (i = 0; i < nr_valclients; i++) {
if (FD_ISSET(valclients[i]->fd, &fd_rd)) {
val_handle(valclients[i]);
}
if (valclients[i]->fd < 0) {
free_val(i);
i--;
}
}
for (i = 0; i < nr_client_traces; i++) {
if(trace_handle(client_traces[i], &fd_rd))
continue;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment