Commit 513d855e authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Add capabilities packet to trace code.

parent 1add24c0
......@@ -350,6 +350,22 @@ int trace_packet_type_set(struct trace_pkt *pkt, enum trace_value_type type)
return 0;
}
int trace_packet_capabilities_set(struct trace_pkt *pkt, unsigned cap)
{
size_t len = sizeof(struct trace_header) +
sizeof(struct trace_ptype_capabilities);
if (pkt->len < len) {
struct trace_ptype_capabilities *pcap;
pkt->len = len;
trace_packet_resize(pkt, pkt->len);
pkt->data[0] = TRACE_PTYPE_CAPABILITIES;
pcap = (void*)pkt->data + 1;
pcap->capabilities = htobe32(cap);
}
return 0;
}
bool trace_check(struct trace *trace)
{
if (trace->fd < 0) {
......@@ -495,6 +511,10 @@ int trace_handle_recv(struct trace *trace)
}
break;
}
case TRACE_PTYPE_CAPABILITIES: {
/* ignore caps for now */
break;
}
case TRACE_PTYPE_DATA: {
/* ignore channel number for now (no multiplexing yet */
size_t pos = sizeof(struct trace_header) +
......@@ -617,3 +637,14 @@ char *enum_trace_state2str(enum trace_state state)
}
}
char *enum_trace_cap2str(unsigned cap)
{
switch(cap) {
case TRACE_CAP_PROXY:
return "PROXY";
case TRACE_CAP_MULTIPLEX:
return "MULTIPLEX";
default:
return "unknown";
}
}
......@@ -35,6 +35,7 @@ enum trace_ptype {
TRACE_PTYPE_INTERVAL = 3,
TRACE_PTYPE_DATA = 4,
TRACE_PTYPE_VALUE_TYPE = 5,
TRACE_PTYPE_CAPABILITIES = 6,
};
enum trace_value_type {
......@@ -81,6 +82,11 @@ struct trace_value {
struct timespec t;
};
#define TRACE_CAP_PROXY 0x01
#define TRACE_CAP_MULTIPLEX 0x02
char *enum_trace_cap2str(unsigned cap);
struct trace {
int fd;
char *host;
......@@ -171,6 +177,7 @@ int trace_packet_timestamp_set(struct trace_pkt *pkt,
int trace_packet_name_set(struct trace_pkt *pkt, char *name);
int trace_packet_type_set(struct trace_pkt *pkt, enum trace_value_type type);
int trace_packet_value_add(struct trace_pkt *pkt, struct trace_value *value, enum trace_value_type type);
int trace_packet_capabilities_set(struct trace_pkt *pkt, unsigned cap);
bool trace_check(struct trace *trace);
bool trace_fd_set(struct trace *trace, fd_set *set, int *high);
......
......@@ -77,4 +77,11 @@ struct trace_ptype_value {
} u;
} __packed;
struct trace_ptype_capabilities {
uint32_t capabilities;
/* Note: This package type may be extended with additional fields in
the future. Parsers may ignore new fields.
*/
} __packed;
#endif /* _INCLUDE_TRACE_DEF_H_ */
......@@ -37,6 +37,7 @@
static char *tr_host;
static int tr_port;
static struct trace_pkt *caps_pkt;
static struct trace_pkt *interval_pkt;
static struct timespec base_interval;
......@@ -388,6 +389,7 @@ static void client_accept(int fd_listen)
trace_initialize_fd(client, fd);
trace_packet_write(client, caps_pkt);
trace_packet_write(client, interval_pkt);
trace_packet_write(client, list_pkt);
client->handler_interval = client_interval;
......@@ -535,6 +537,9 @@ int main (int argc, char **argv)
list->handler_list_entry = handler_list_entry;
trace_autorecover(list, true);
caps_pkt = trace_packet_new();
trace_packet_capabilities_set(caps_pkt, TRACE_CAP_PROXY);
list_pkt = trace_packet_new();
while (trace_state_get(list) != TRACE_STATE_READY) {
......
......@@ -126,6 +126,7 @@ var trace_ptype = {
INTERVAL: 3,
DATA: 4,
VALUE_TYPE: 5,
CAPABILITIES: 6,
};
Object.freeze(trace_ptype);
......@@ -325,6 +326,9 @@ trace_stream.prototype.handle = function() {
this.interval.sec |= pkt.getUint32(5, false);
this.interval.nsec = pkt.getUint32(9, false);
break;
case trace_ptype.CAPABILITES:
/* ignore capabilities for now */
break;
case trace_ptype.DATA:
j = 2; /* header + channel number */
var datasize;
......
......@@ -104,6 +104,7 @@ static struct trace_hdl *trace_hdl;
static int controller_trace_server_port;
/* Thes are created when starting the server and sent to each new client */
struct trace_pkt *controller_trace_pkt_caps;
struct trace_pkt *controller_trace_pkt_interval;
struct trace_pkt *controller_trace_pkt_list;
......@@ -429,6 +430,8 @@ static void *controller_trace_server(void *arg)
trace_initialize_fd(&trace_hdl[i].trace, client);
/* Send info to client */
trace_packet_write(&trace_hdl[i].trace,
controller_trace_pkt_caps);
trace_packet_write(&trace_hdl[i].trace,
controller_trace_pkt_interval);
trace_packet_write(&trace_hdl[i].trace,
......@@ -484,6 +487,9 @@ void controller_trace_server_start(int portnr, int max)
trace_hdl[i].trace.handler_interval = handler_interval;
}
controller_trace_pkt_caps = trace_packet_new();
trace_packet_capabilities_set(controller_trace_pkt_caps, 0);
controller_trace_pkt_interval = trace_packet_new();
period = controller_time_sample_period_get();
interval.tv_sec = period;
......
Markdown is supported
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