Skip to content

Commit

Permalink
implement load_evemu_events() with load_script_from_string()
Browse files Browse the repository at this point in the history
This avoids the temporary file.
  • Loading branch information
martinpitt committed Dec 22, 2024
1 parent 005f05e commit dec82e5
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/umockdev.vala
Original file line number Diff line number Diff line change
Expand Up @@ -1184,8 +1184,7 @@ public class Testbed: GLib.Object {
var default_dev_re = new Regex("^# device (.*)$");
var event_re = new Regex("^E: ([0-9]+)\\.([0-9]+) +([0-9a-fA-F]+) +([0-9a-fA-F]+) +(-?[0-9]+) *#?");

string script_file;
int script_fd = FileUtils.open_tmp ("evemu.XXXXXX.script", out script_file);
string script = "";
int delay = 0;
bool first = true;

Expand Down Expand Up @@ -1218,22 +1217,17 @@ public class Testbed: GLib.Object {

uint8[] ev_data = new uint8[sizeof(LinuxFixes.Input.Event)];
Posix.memcpy(ev_data, &ev, ev_data.length);
string script_line = "r " + delay.to_string() + " " + ScriptRunner.encode(ev_data) + "\n";
assert (Posix.write(script_fd, script_line, script_line.length) == script_line.length);
script += "r " + delay.to_string() + " " + ScriptRunner.encode(ev_data) + "\n";
}

Posix.close (script_fd);

string? owned_dev = dev;
if (owned_dev == null) {
if (recorded_dev == null)
error("null passed for device node, but recording %s has no '# device' header", eventsfile);
owned_dev = recorded_dev;
}

bool ret = load_script(owned_dev, script_file);
FileUtils.unlink(script_file);
return ret;
return load_script_from_string(owned_dev, script);
}

private static HashTable<string, string> bus_lookup_table;
Expand Down

0 comments on commit dec82e5

Please sign in to comment.