Commit f34ced3f authored by Lubomir Bulej's avatar Lubomir Bulej

Update DiSL agent to use the generated protocol buffers.

parent a9f11b40
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "connection.h" #include "connection.h"
#include "network.h" #include "network.h"
#include "msgchannel.h" #include "msgchannel.h"
#include "dislserver.pb-c.h"
#include "bytecode.h" #include "bytecode.h"
#include "classparser.h" #include "classparser.h"
...@@ -217,31 +218,40 @@ __instrument_class ( ...@@ -217,31 +218,40 @@ __instrument_class (
// send the it to the server. Receive the response and release the // send the it to the server. Receive the response and release the
// connection again. // connection again.
// //
struct message request = { InstrumentClassRequest request = INSTRUMENT_CLASS_REQUEST__INIT;
.message_flags = request_flags, request.has_flags = true;
.control_size = (class_name != NULL) ? strlen (class_name) : 0, request.flags = request_flags;
.classcode_size = class_def->class_byte_count, request.classname = (char *) class_name;
.control = (unsigned char *) class_name, request.has_classbytes = true;
.classcode = class_def->class_bytes, request.classbytes.len = class_def->class_byte_count;
}; request.classbytes.data = (uint8_t *) class_def->class_bytes;
// size_t send_size = instrument_class_request__get_packed_size (&request);
void * send_buffer = malloc (send_size);
assert (send_buffer != NULL);
instrument_class_request__pack (&request, send_buffer);
struct connection * conn = network_acquire_connection (); struct connection * conn = network_acquire_connection ();
message_send (conn, &request); message_send (conn, send_buffer, send_size);
//
struct message response; void * recv_buffer;
message_recv (conn, &response); size_t recv_size = message_recv (conn, &recv_buffer);
network_release_connection (conn); network_release_connection (conn);
InstrumentClassResponse * response = instrument_class_response__unpack (NULL, recv_size, recv_buffer);
assert (response != NULL);
free (recv_buffer);
// //
// Check if error occurred on the server. // Check if error occurred on the server.
// The control field of the response contains the error message. // The control field of the response contains the error message.
// //
if (response.control_size > 0) { if (response->result == INSTRUMENT_CLASS_RESULT__ERROR) {
fprintf ( fprintf (
stderr, "%sinstrumentation server error:\n%s\n", stderr, "%sinstrumentation server error:\n%s\n",
ERROR_PREFIX, response.control ERROR_PREFIX, response->errormessage
); );
exit (ERROR_SERVER); exit (ERROR_SERVER);
...@@ -252,12 +262,19 @@ __instrument_class ( ...@@ -252,12 +262,19 @@ __instrument_class (
// modified if non-empty class code has been returned. Otherwise, // modified if non-empty class code has been returned. Otherwise,
// signal that the class has not been modified. // signal that the class has not been modified.
// //
if (response.classcode_size > 0) { if (response->result == INSTRUMENT_CLASS_RESULT__CLASS_MODIFIED) {
class_def->class_byte_count = response.classcode_size; class_def->class_byte_count = response->classbytes.len;
class_def->class_bytes = response.classcode; class_def->class_bytes = response->classbytes.data;
response->has_classbytes = false;
response->classbytes.len = 0;
response->classbytes.data = NULL;
instrument_class_response__free_unpacked (response, NULL);
return true; return true;
} else { } else {
instrument_class_response__free_unpacked (response, NULL);
return false; return false;
} }
} }
......
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