Commit aa28feed authored by Petr Štětka's avatar Petr Štětka
Browse files

Changed Posix.pid_t to GLib.Pid.

parent 46e4e80c
using Posix;
namespace Usage
{
public class CpuMonitor
......
using Posix;
namespace Usage
{
public class MemoryMonitor
......
using NI;
using Posix;
namespace Usage
{
......
......@@ -5,7 +5,7 @@ namespace Usage
public class ProcessDialog : Gtk.Dialog
{
ProcessDialogHeaderBar headerbar;
pid_t pid;
Pid pid;
string process;
GraphBlock processor_graph_block;
GraphBlock memory_graph_block;
......@@ -13,7 +13,7 @@ namespace Usage
GraphBlock downloads_graph_block;
GraphBlock uploads_graph_block;
public ProcessDialog(pid_t pid, string app_name, string process)
public ProcessDialog(Pid pid, string app_name, string process)
{
Object(use_header_bar: 1);
set_modal(true);
......@@ -101,7 +101,7 @@ namespace Usage
private string process;
private Gtk.Button stop_button;
public ProcessDialogHeaderBar(Gtk.Button stop_button, pid_t pid, string app_name, string process)
public ProcessDialogHeaderBar(Gtk.Button stop_button, Pid pid, string app_name, string process)
{
this.app_name = app_name;
this.process = process;
......@@ -133,9 +133,9 @@ namespace Usage
return !(process in unkillable_processes);
}
private void kill_process(pid_t pid)
private void kill_process(Pid pid)
{
Posix.kill (pid, Posix.SIGKILL);
Posix.kill (pid, Posix.SIGKILL);
}
public void set_process_state(ProcessStatus status)
......
using Posix;
using Gee;
namespace Usage
......
using Posix;
namespace Usage
{
public class Process : Object
{
pid_t pid;
Pid pid;
string cmdline;
string cmdline_parameter; //Isn't parameters as "-p" etc, but parameter for running app, for ex. "--writer' with libreoffice, or "privacy" with gnome-control-center
string display_name;
......@@ -17,11 +15,11 @@ namespace Usage
uint64 net_download;
uint64 net_upload;
uint64 net_all;
HashTable<pid_t?, Process>? sub_processes;
HashTable<Pid?, Process>? sub_processes;
bool alive;
ProcessStatus status;
public Process(pid_t pid, string cmdline, string cmdline_parameter, string display_name)
public Process(Pid pid, string cmdline, string cmdline_parameter, string display_name)
{
this.pid = pid;
this.cmdline = cmdline;
......@@ -56,12 +54,12 @@ namespace Usage
this.status = process.get_status();
}
public pid_t get_pid()
public Pid get_pid()
{
return pid;
}
public void set_pid(pid_t pid)
public void set_pid(Pid pid)
{
this.pid = pid;
}
......@@ -186,12 +184,12 @@ namespace Usage
this.net_all = net_all;
}
public HashTable<pid_t?, Process>? get_sub_processes()
public HashTable<Pid?, Process>? get_sub_processes()
{
return sub_processes;
}
public void set_sub_processes(HashTable<pid_t?, Process>? sub_processes)
public void set_sub_processes(HashTable<Pid?, Process>? sub_processes)
{
this.sub_processes = sub_processes;
}
......
using Gee;
using Posix;
namespace Usage
{
......
using Posix;
namespace Usage
{
public class SubProcessSubRow : Gtk.ListBoxRow
......
using Posix;
namespace Usage
{
public class SystemMonitor : Object
......@@ -19,27 +17,20 @@ namespace Usage
private MemoryMonitor memory_monitor;
private NetworkMonitor network_monitor;
private HashTable<pid_t?, Process> process_table_pid;
private HashTable<Pid?, Process> process_table_pid;
private HashTable<string, Process> cpu_process_table;
private HashTable<string, Process> ram_process_table;
private HashTable<string, Process> net_process_table;
private int process_mode = GTop.KERN_PROC_UID;
private int process_mode = GTop.EXCLUDE_SYSTEM;
private GLib.List<AppInfo> apps_info;
public enum ProcessMode
{
ALL,
USER,
EXCLUDE_IDLE
}
public List<unowned Process> get_processes_pid()
{
return process_table_pid.get_values();
}
public unowned Process get_process_by_pid(pid_t pid)
public unowned Process get_process_by_pid(Pid pid)
{
return process_table_pid.get(pid);
}
......@@ -87,7 +78,7 @@ namespace Usage
memory_monitor = new MemoryMonitor();
network_monitor = new NetworkMonitor();
process_table_pid = new HashTable<pid_t?, Process>(int_hash, int_equal);
process_table_pid = new HashTable<Pid?, Process>(int_hash, int_equal);
cpu_process_table = new HashTable<string, Process>(str_hash, str_equal);
ram_process_table = new HashTable<string, Process>(str_hash, str_equal);
net_process_table = new HashTable<string, Process>(str_hash, str_equal);
......@@ -129,9 +120,8 @@ namespace Usage
set_alive_false_table_cmdline(ref ram_process_table);
set_alive_false_table_cmdline(ref net_process_table);
var uid = Posix.getuid();
GTop.Proclist proclist;
var pids = GTop.get_proclist (out proclist, process_mode, uid);
var pids = GTop.get_proclist (out proclist, process_mode);
for(uint i = 0; i < proclist.number; i++)
{
......@@ -164,7 +154,7 @@ namespace Usage
}
}
var process_table_pid_condition = new HashTable<pid_t?, Process>(int_hash, int_equal);
var process_table_pid_condition = new HashTable<Pid?, Process>(int_hash, int_equal);
foreach(unowned Process process in process_table_pid.get_values())
{
if(process.get_cpu_load() >= 1)
......@@ -191,22 +181,6 @@ namespace Usage
return true;
}
public void set_process_mode(ProcessMode mode)
{
switch(mode)
{
case ProcessMode.ALL:
process_mode = GTop.KERN_PROC_ALL;
break;
case ProcessMode.USER:
process_mode = GTop.KERN_PROC_UID;
break;
case ProcessMode.EXCLUDE_IDLE:
process_mode = GTop.EXCLUDE_IDLE;
break;
}
}
private string get_display_name(string cmdline, string cmdline_parameter)
{
AppInfo app_info = null;
......@@ -250,7 +224,7 @@ namespace Usage
return cmdline;
}
private string get_full_process_cmd_for_pid (pid_t pid, out string cmd_parameter)
private string get_full_process_cmd_for_pid (Pid pid, out string cmd_parameter)
{
GTop.ProcArgs proc_args;
GTop.ProcState proc_state;
......@@ -342,7 +316,7 @@ namespace Usage
}
}
private void get_updates_table_cmdline(HashTable<pid_t?, Process> from_table, ref HashTable<string, Process> to_table)
private void get_updates_table_cmdline(HashTable<Pid?, Process> from_table, ref HashTable<string, Process> to_table)
{
foreach(unowned Process process_it in from_table.get_values())
{
......@@ -371,7 +345,7 @@ namespace Usage
}
else //transform to group and add subrow
{
to_table[process_it.get_cmdline()].set_sub_processes(new HashTable<pid_t?, Process>(int_hash, int_equal));
to_table[process_it.get_cmdline()].set_sub_processes(new HashTable<Pid?, Process>(int_hash, int_equal));
unowned Process process = to_table[process_it.get_cmdline()];
var sub_process_one = new Process(process.get_pid(), process.get_cmdline(), process.get_cmdline_parameter(), process.get_display_name());
......
......@@ -29,10 +29,24 @@ namespace GTop {
[CCode(cname = "GLIBTOP_KERN_PROC_ALL")]
public const int KERN_PROC_ALL;
[CCode(cname = "GLIBTOP_KERN_PROC_PID")]
public const int KERN_PROC_PID;
[CCode(cname = "GLIBTOP_KERN_PROC_PGRP")]
public const int KERN_PROC_PRGP;
[CCode(cname = "GLIBTOP_KERN_PROC_SESSION")]
public const int KERN_PROC_SESSION;
[CCode(cname = "GLIBTOP_KERN_PROC_TTY")]
public const int KERN_PROC_TTY;
[CCode(cname = "GLIBTOP_KERN_PROC_UID")]
public const int KERN_PROC_UID;
[CCode(cname = "GLIBTOP_KERN_PROC_RUID")]
public const int KERN_PROC_RUID;
[CCode(cname = "GLIBTOP_KERN_PROC_MASK")]
public const int KERN_PROC_MASK;
[CCode(cname = "GLIBTOP_EXCLUDE_IDLE")]
public const int EXCLUDE_IDLE;
[CCode(cname = "GLIBTOP_EXCLUDE_SYSTEM")]
public const int EXCLUDE_SYSTEM;
[CCode(cname = "glibtop_proclist", cheader_filename = "glibtop/proclist.h")]
public struct Proclist {
......@@ -42,7 +56,7 @@ namespace GTop {
uint64 size;
}
[CCode(array_length = false, array_null_terminated = false)]
public Posix.pid_t[] get_proclist(out Proclist proclist, uint64 which, uint64 arg);
public GLib.Pid[] get_proclist(out Proclist proclist, uint64 which, uint64? arg = null);
[CCode(cname = "glibtop_proc_state", cheader_filename = "glibtop/procstate.h")]
public struct ProcState {
......@@ -57,7 +71,7 @@ namespace GTop {
int processor;
int last_processor;
}
public void get_proc_state(out ProcState proc_state, Posix.pid_t pid);
public void get_proc_state(out ProcState proc_state, GLib.Pid pid);
[CCode(cname = "GLIBTOP_PROCESS_RUNNING")]
public const int PROCESS_RUNNING;
......@@ -89,7 +103,7 @@ namespace GTop {
uint64 xcpu_utime[1024];
uint64 xcpu_stime[1024];
}
public void get_proc_time(out ProcTime proc_time, Posix.pid_t pid);
public void get_proc_time(out ProcTime proc_time, GLib.Pid pid);
[CCode(cname = "glibtop_mem", cheader_filename = "glibtop/mem.h")]
public struct Mem {
......@@ -126,7 +140,7 @@ namespace GTop {
uint64 rss;
uint64 rss_rlim;
}
public void get_proc_mem(out ProcMem proc_mem, Posix.pid_t pid);
public void get_proc_mem(out ProcMem proc_mem, GLib.Pid pid);
[CCode(cname = "glibtop_netlist", cheader_filename = "glibtop/netlist.h")]
public struct Netlist {
......@@ -159,7 +173,7 @@ namespace GTop {
int32 ngroups;
int32 groups[64];
}
public void get_proc_uid(out ProcUid proc_uid, Posix.pid_t pid);
public void get_proc_uid(out ProcUid proc_uid, GLib.Pid pid);
[CCode(cname = "glibtop_proc_args", cheader_filename = "glibtop/procargs.h")]
public struct ProcArgs {
......@@ -167,7 +181,7 @@ namespace GTop {
uint64 size;
}
[CCode(array_null_terminated = "true")]
public string[] get_proc_argv(out ProcArgs proc_args, Posix.pid_t pid);
public string[] get_proc_argv(out ProcArgs proc_args, GLib.Pid pid);
[CCode(cname = "glibtop_fsusage", cheader_filename = "glibtop/fsusage.h")]
public struct FsUsage {
......
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