Skip to content

Commit

Permalink
provider wip
Browse files Browse the repository at this point in the history
  • Loading branch information
stsdc committed Dec 10, 2023
1 parent 8f7c929 commit bb35702
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 105 deletions.
8 changes: 1 addition & 7 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public class Monitor.MainWindow : Hdy.ApplicationWindow {
show_all ();

dbusserver = DBusServer.get_default ();
var dbus_workaround_client = DBusWorkaroundClient.get_default();

headerbar.search_revealer.set_reveal_child (stack.visible_child_name == "process_view");
stack.notify["visible-child-name"].connect (() => {
Expand All @@ -90,12 +89,7 @@ public class Monitor.MainWindow : Hdy.ApplicationWindow {
var res = resources.serialize ();
statusbar.update (res);
dbusserver.update (res);
try {
HashTable<string, string>[] p = dbus_workaround_client.interface.get_processes ("");
debug("%s", p[400]["cmdline"] );
} catch (Error e) {
warning (e.message);
}

return false;
});
return true;
Expand Down
2 changes: 0 additions & 2 deletions src/Managers/ContainerManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ namespace Monitor {
assert_nonnull (container_object);

this.add_container (container_object);


}
var remove_me = new Gee.HashSet<DockerContainer> ();
foreach (var container in this.container_list.values) {
Expand Down
2 changes: 1 addition & 1 deletion src/Managers/HttpClientAsync.vala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace Monitor {
r = curl.setopt (Curl.Option.WRITEFUNCTION, HttpClientResponse.read_body_data);
assert_true (r == Curl.Code.OK);

// debug ("call api method: %s - %s", this.get_request_method (method), url);
debug ("call api method: %s - %s", this.get_request_method (method), url);

yield this.perform (curl);

Expand Down
30 changes: 5 additions & 25 deletions src/Managers/ProcessManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ namespace Monitor {
/**
* Gets all new process and adds them
*/
public async void update_processes () {
public async void update_processes () {
/* CPU */
GTop.Cpu cpu_data;
GTop.get_cpu (out cpu_data);
Expand Down Expand Up @@ -135,34 +135,14 @@ namespace Monitor {
// var pids = GTop.get_proclist (out proclist, GTop.GLIBTOP_KERN_PROC_UID, uid);
var pids = GTop.get_proclist (out proclist, GTop.GLIBTOP_KERN_PROC_ALL, uid);

if (ProcessUtils.is_flatpak_env ()) {
var pp = ProcessProvider.get_default ();
var pp_pids = pp.get_pids ();
for (int i = 0; i < proclist.number; i++) {
int pid = pids[i];

// foreach (var pid in pp_pids) {
// debug ("yeah %d", pid);
// }

debug ("Size %u", pp_pids.length ());

foreach (int pid in pp_pids) {
if (!process_list.has_key (pid) && !kernel_process_blacklist.contains (pid)) {
add_process (pid);
}
if (!process_list.has_key (pid) && !kernel_process_blacklist.contains (pid)) {
add_process (pid);
}
debug ("process_list size %u", process_list.size);
} else {
// for (int i = 0; i < proclist.number; i++) {
// int pid = pids[i];

// if (!process_list.has_key (pid) && !kernel_process_blacklist.contains (pid)) {
// add_process (pid);
// }
// }
}



cpu_last_used = used;
cpu_last_total = cpu_data.total;
cpu_last_useds = useds;
Expand Down
85 changes: 17 additions & 68 deletions src/Managers/ProcessProvider.vala
Original file line number Diff line number Diff line change
Expand Up @@ -7,77 +7,26 @@ namespace Monitor {

public Gee.HashSet<int> pids = new Gee.HashSet<int> ();

DBusWorkaroundClient dbus_workaround_client;

public ProcessProvider () {
if (ProcessUtils.is_flatpak_env ()) {
dbus_workaround_client = DBusWorkaroundClient.get_default ();
}
}

public GLib.List<int> get_pids () {
var new_pids = new GLib.List<int> ();

try {
string[] spawn_args = { "flatpak-spawn", "--host", "ls" };
string[] spawn_env = Environ.get ();
Pid child_pid;

int standard_input;
int standard_output;
int standard_error;


string ls_stdout;
string ls_stderr;
int ls_status;

// GLib.Process.spawn_async_with_pipes
// (
// "/proc/",
// spawn_args,
// spawn_env,
// SpawnFlags.SEARCH_PATH | SpawnFlags.DO_NOT_REAP_CHILD,
// null,
// out child_pid,
// out standard_input,
// out standard_output,
// out standard_error
// );

GLib.Process.spawn_command_line_sync (
"ls /tmp/fakeproc/proc/",
out ls_stdout,
out ls_stderr,
out ls_status);

// stdout:
// IOChannel output = new IOChannel.unix_new (standard_output);
// output.add_watch (IOCondition.IN | IOCondition.HUP, (channel, condition) => {
// return process_line (channel, condition, new_pids);
// });

//// stderr:
// IOChannel error = new IOChannel.unix_new (standard_error);
// error.add_watch (IOCondition.IN | IOCondition.HUP, (channel, condition) => {
//// return process_line (channel, condition, "stderr");
// return true;
// });

// ChildWatch.add (child_pid, (pid, status) => {
////// Triggered when the child indicated by child_pid exits
// GLib.Process.close_pid (pid);
//// loop.quit ();
// });

// debug (ls_stdout);
foreach (var line in ls_stdout.strip ().split ("\n")) {
if (line[0].isdigit ()) {
// print ("---->" + line + "\n");
new_pids.append (int.parse (line));
}
}


} catch (SpawnError e) {
error ("Error: %s\n", e.message);
}
return new_pids;
public int[] get_pids () {
// try {
// HashTable<string, string>[] p = dbus_workaround_client.interface.get_processes ("");
// debug ("%s", p[400]["cmdline"] );
// } catch (Error e) {
// warning (e.message);
// }
GTop.ProcList proclist;
// var pids = GTop.get_proclist (out proclist, GTop.GLIBTOP_KERN_PROC_UID, uid);
int[] pids = GTop.get_proclist (out proclist, GTop.GLIBTOP_KERN_PROC_ALL, Posix.getuid ());
debug("%d", pids.length);
return pids;
}

private bool process_line (IOChannel channel, IOCondition condition, GLib.List<int> _pids) {
Expand Down
2 changes: 1 addition & 1 deletion src/Services/DBusWorkaroundClient.vala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[DBus (name = "com.github.stsdc.monitor.workaround.GetProcesses")]
public interface Monitor.DBusWorkaroundClientInterface : Object {
public abstract HashTable<string, string>[] get_processes (string empty) throws Error;
public abstract HashTable<string, string>[] get_processes (string empty) throws Error;

}

Expand Down
2 changes: 1 addition & 1 deletion subprojects/stylesheet
Submodule stylesheet updated 1 files
+12 −10 po/ru.po

0 comments on commit bb35702

Please sign in to comment.