ed00f34b0a1aa75b8e9dc6d5df0cbdfed40a89e8
4 * BabelTrace - Convert Text to CTF
6 * Copyright 2010, 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * Depends on glibc 2.10 for getline().
21 #include <sys/types.h>
29 #include <uuid/uuid.h>
32 #include <babeltrace/babeltrace.h>
33 #include <babeltrace/ctf/types.h>
35 int babeltrace_debug
= 0;
40 void write_packet_header(struct stream_pos
*pos
, uuid_t uuid
)
42 struct stream_pos dummy
;
45 dummy_pos(pos
, &dummy
);
46 align_pos(&dummy
, sizeof(uint32_t) * CHAR_BIT
);
47 move_pos(&dummy
, sizeof(uint32_t) * CHAR_BIT
);
48 assert(!pos_packet(&dummy
));
50 align_pos(pos
, sizeof(uint32_t) * CHAR_BIT
);
51 *(uint32_t *) get_pos_addr(pos
) = 0xC1FC1FC1;
52 move_pos(pos
, sizeof(uint32_t) * CHAR_BIT
);
55 dummy_pos(pos
, &dummy
);
56 align_pos(&dummy
, sizeof(uint8_t) * CHAR_BIT
);
57 move_pos(&dummy
, 16 * CHAR_BIT
);
58 assert(!pos_packet(&dummy
));
60 align_pos(pos
, sizeof(uint8_t) * CHAR_BIT
);
61 memcpy(get_pos_addr(pos
), uuid
, 16);
62 move_pos(pos
, 16 * CHAR_BIT
);
66 void write_packet_context(struct stream_pos
*pos
)
68 struct stream_pos dummy
;
71 dummy_pos(pos
, &dummy
);
72 align_pos(&dummy
, sizeof(uint32_t) * CHAR_BIT
);
73 move_pos(&dummy
, sizeof(uint32_t) * CHAR_BIT
);
74 assert(!pos_packet(&dummy
));
76 align_pos(pos
, sizeof(uint32_t) * CHAR_BIT
);
77 *(uint32_t *) get_pos_addr(pos
) = -1U; /* Not known yet */
78 pos
->content_size_loc
= (uint32_t *) get_pos_addr(pos
);
79 move_pos(pos
, sizeof(uint32_t) * CHAR_BIT
);
82 dummy_pos(pos
, &dummy
);
83 align_pos(&dummy
, sizeof(uint32_t) * CHAR_BIT
);
84 move_pos(&dummy
, sizeof(uint32_t) * CHAR_BIT
);
85 assert(!pos_packet(&dummy
));
87 align_pos(pos
, sizeof(uint32_t) * CHAR_BIT
);
88 *(uint32_t *) get_pos_addr(pos
) = pos
->packet_size
;
89 move_pos(pos
, sizeof(uint32_t) * CHAR_BIT
);
93 void trace_string(char *line
, struct stream_pos
*pos
, size_t len
)
95 struct stream_pos dummy
;
98 printf_debug("read: %s\n", line
);
100 dummy_pos(pos
, &dummy
);
101 align_pos(&dummy
, sizeof(uint8_t) * CHAR_BIT
);
102 move_pos(&dummy
, len
* CHAR_BIT
);
103 if (pos_packet(&dummy
)) {
104 /* TODO write content size */
106 write_packet_header(pos
, s_uuid
);
107 write_packet_context(pos
);
108 if (attempt
++ == 1) {
109 fprintf(stdout
, "[Error] Line too large for packet size (%zukB) (discarded)\n",
110 pos
->packet_size
/ CHAR_BIT
/ 1024);
116 align_pos(pos
, sizeof(uint8_t) * CHAR_BIT
);
117 memcpy(get_pos_addr(pos
), line
, len
);
118 move_pos(pos
, len
* CHAR_BIT
);
122 void trace_text(FILE *input
, int output
)
124 struct stream_pos pos
;
126 char *line
= NULL
, *nl
;
129 init_pos(&pos
, output
);
131 write_packet_header(&pos
, s_uuid
);
132 write_packet_context(&pos
);
134 len
= getline(&line
, &linesize
, input
);
137 nl
= strrchr(line
, '\n');
140 trace_string(line
, &pos
, nl
- line
+ 1);
145 int main(int argc
, char **argv
)
149 ret
= unlink("dummystream");
154 fd
= open("dummystream", O_RDWR
|O_CREAT
, S_IRUSR
|S_IWUSR
);
160 ret
= uuid_parse("2a6422d0-6cee-11e0-8c08-cb07d7b3a564", s_uuid
);
162 printf("uuid parse error\n");
167 trace_text(stdin
, fd
);
This page took 0.051727 seconds and 3 git commands to generate.