Hold only a const version of Settings in Process

This commit is contained in:
Christian Göttsche 2020-10-21 21:26:05 +02:00 committed by cgzones
parent 7109172431
commit 4eb443926f
20 changed files with 28 additions and 28 deletions

View File

@ -399,7 +399,7 @@ const ProcessClass Process_class = {
.writeField = Process_writeField,
};
void Process_init(Process* this, struct Settings_* settings) {
void Process_init(Process* this, const struct Settings_* settings) {
this->settings = settings;
this->tag = false;
this->showChildren = true;

View File

@ -59,7 +59,7 @@ struct Settings_;
typedef struct Process_ {
Object super;
struct Settings_* settings;
const struct Settings_* settings;
unsigned long long int time;
pid_t pid;
@ -119,7 +119,7 @@ extern ProcessFieldData Process_fields[];
extern ProcessPidColumn Process_pidColumns[];
extern char Process_pidFormat[20];
typedef Process*(*Process_New)(struct Settings_*);
typedef Process*(*Process_New)(const struct Settings_*);
typedef void (*Process_WriteField)(const Process*, RichString*, ProcessField);
typedef struct ProcessClass_ {
@ -164,7 +164,7 @@ void Process_done(Process* this);
extern const ProcessClass Process_class;
void Process_init(Process* this, struct Settings_* settings);
void Process_init(Process* this, const struct Settings_* settings);
void Process_toggleTag(Process* this);

View File

@ -28,7 +28,7 @@ const ProcessClass DarwinProcess_class = {
.writeField = Process_writeField,
};
DarwinProcess* DarwinProcess_new(Settings* settings) {
Process* DarwinProcess_new(const Settings* settings) {
DarwinProcess* this = xCalloc(1, sizeof(DarwinProcess));
Object_setClass(this, Class(DarwinProcess));
Process_init(&this->super, settings);
@ -37,7 +37,7 @@ DarwinProcess* DarwinProcess_new(Settings* settings) {
this->stime = 0;
this->taskAccess = true;
return this;
return &this->super;
}
void Process_delete(Object* cast) {

View File

@ -22,7 +22,7 @@ typedef struct DarwinProcess_ {
extern const ProcessClass DarwinProcess_class;
DarwinProcess* DarwinProcess_new(Settings* settings);
Process* DarwinProcess_new(const Settings* settings);
void Process_delete(Object* cast);

View File

@ -186,7 +186,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
ps = ProcessList_getKInfoProcs(&count);
for(size_t i = 0; i < count; ++i) {
proc = (DarwinProcess *)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, (Process_New)DarwinProcess_new);
proc = (DarwinProcess *)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, DarwinProcess_new);
DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], preExisting);
DarwinProcess_setFromLibprocPidinfo(proc, dpl);

View File

@ -69,11 +69,11 @@ ProcessPidColumn Process_pidColumns[] = {
{ .id = 0, .label = NULL },
};
DragonFlyBSDProcess* DragonFlyBSDProcess_new(Settings* settings) {
Process* DragonFlyBSDProcess_new(const Settings* settings) {
DragonFlyBSDProcess* this = xCalloc(1, sizeof(DragonFlyBSDProcess));
Object_setClass(this, Class(DragonFlyBSDProcess));
Process_init(&this->super, settings);
return this;
return &this->super;
}
void Process_delete(Object* cast) {

View File

@ -33,7 +33,7 @@ extern ProcessFieldData Process_fields[];
extern ProcessPidColumn Process_pidColumns[];
DragonFlyBSDProcess* DragonFlyBSDProcess_new(Settings* settings);
Process* DragonFlyBSDProcess_new(const Settings* settings);
void Process_delete(Object* cast);

View File

@ -385,7 +385,7 @@ void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) {
bool ATTR_UNUSED isIdleProcess = false;
// note: dragonflybsd kernel processes all have the same pid, so we misuse the kernel thread address to give them a unique identifier
Process* proc = ProcessList_getProcess(this, kproc->kp_ktaddr ? (pid_t)kproc->kp_ktaddr : kproc->kp_pid, &preExisting, (Process_New) DragonFlyBSDProcess_new);
Process* proc = ProcessList_getProcess(this, kproc->kp_ktaddr ? (pid_t)kproc->kp_ktaddr : kproc->kp_pid, &preExisting, DragonFlyBSDProcess_new);
DragonFlyBSDProcess* dfp = (DragonFlyBSDProcess*) proc;
proc->show = ! ((hideKernelThreads && Process_isKernelThread(dfp)) || (hideUserlandThreads && Process_isUserlandThread(proc)));

View File

@ -69,11 +69,11 @@ ProcessPidColumn Process_pidColumns[] = {
{ .id = 0, .label = NULL },
};
FreeBSDProcess* FreeBSDProcess_new(Settings* settings) {
Process* FreeBSDProcess_new(const Settings* settings) {
FreeBSDProcess* this = xCalloc(1, sizeof(FreeBSDProcess));
Object_setClass(this, Class(FreeBSDProcess));
Process_init(&this->super, settings);
return this;
return &this->super;
}
void Process_delete(Object* cast) {

View File

@ -39,7 +39,7 @@ extern ProcessFieldData Process_fields[];
extern ProcessPidColumn Process_pidColumns[];
FreeBSDProcess* FreeBSDProcess_new(Settings* settings);
Process* FreeBSDProcess_new(const Settings* settings);
void Process_delete(Object* cast);

View File

@ -401,7 +401,7 @@ void ProcessList_goThroughEntries(ProcessList* this, bool pauseProcessUpdate) {
struct kinfo_proc* kproc = &kprocs[i];
bool preExisting = false;
// TODO: bool isIdleProcess = false;
Process* proc = ProcessList_getProcess(this, kproc->ki_pid, &preExisting, (Process_New) FreeBSDProcess_new);
Process* proc = ProcessList_getProcess(this, kproc->ki_pid, &preExisting, FreeBSDProcess_new);
FreeBSDProcess* fp = (FreeBSDProcess*) proc;
proc->show = ! ((hideKernelThreads && Process_isKernelThread(fp)) || (hideUserlandThreads && Process_isUserlandThread(proc)));

View File

@ -138,11 +138,11 @@ const ProcessClass LinuxProcess_class = {
.writeField = LinuxProcess_writeField,
};
LinuxProcess* LinuxProcess_new(Settings* settings) {
Process* LinuxProcess_new(const Settings* settings) {
LinuxProcess* this = xCalloc(1, sizeof(LinuxProcess));
Object_setClass(this, Class(LinuxProcess));
Process_init(&this->super, settings);
return this;
return &this->super;
}
void Process_delete(Object* cast) {

View File

@ -167,7 +167,7 @@ extern ProcessPidColumn Process_pidColumns[];
extern const ProcessClass LinuxProcess_class;
LinuxProcess* LinuxProcess_new(Settings* settings);
Process* LinuxProcess_new(const Settings* settings);
void Process_delete(Object* cast);

View File

@ -971,7 +971,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char*
continue;
bool preExisting = false;
Process* proc = ProcessList_getProcess(pl, pid, &preExisting, (Process_New) LinuxProcess_new);
Process* proc = ProcessList_getProcess(pl, pid, &preExisting, LinuxProcess_new);
proc->tgid = parent ? parent->pid : pid;
LinuxProcess* lp = (LinuxProcess*) proc;

View File

@ -165,11 +165,11 @@ ProcessPidColumn Process_pidColumns[] = {
{ .id = 0, .label = NULL },
};
OpenBSDProcess* OpenBSDProcess_new(Settings* settings) {
Process* OpenBSDProcess_new(const Settings* settings) {
OpenBSDProcess* this = xCalloc(sizeof(OpenBSDProcess), 1);
Object_setClass(this, Class(OpenBSDProcess));
Process_init(&this->super, settings);
return this;
return &this->this;
}
void Process_delete(Object* cast) {

View File

@ -27,7 +27,7 @@ extern ProcessFieldData Process_fields[];
extern ProcessPidColumn Process_pidColumns[];
OpenBSDProcess* OpenBSDProcess_new(Settings* settings);
Process* OpenBSDProcess_new(const Settings* settings);
void Process_delete(Object* cast);

View File

@ -203,7 +203,7 @@ static inline void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) {
kproc = &kprocs[i];
preExisting = false;
proc = ProcessList_getProcess(&this->super, kproc->p_pid, &preExisting, (Process_New) OpenBSDProcess_new);
proc = ProcessList_getProcess(&this->super, kproc->p_pid, &preExisting, OpenBSDProcess_new);
fp = (OpenBSDProcess*) proc;
proc->show = ! ((hideKernelThreads && Process_isKernelThread(proc))

View File

@ -79,11 +79,11 @@ ProcessPidColumn Process_pidColumns[] = {
{ .id = 0, .label = NULL },
};
SolarisProcess* SolarisProcess_new(Settings* settings) {
Process* SolarisProcess_new(const Settings* settings) {
SolarisProcess* this = xCalloc(1, sizeof(SolarisProcess));
Object_setClass(this, Class(SolarisProcess));
Process_init(&this->super, settings);
return this;
return &this->super;
}
void Process_delete(Object* cast) {

View File

@ -50,7 +50,7 @@ extern ProcessFieldData Process_fields[];
extern ProcessPidColumn Process_pidColumns[];
SolarisProcess* SolarisProcess_new(Settings* settings);
Process* SolarisProcess_new(const Settings* settings);
void Process_delete(Object* cast);

View File

@ -279,7 +279,7 @@ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void *
} else {
getpid = lwpid;
}
Process *proc = ProcessList_getProcess(pl, getpid, &preExisting, (Process_New) SolarisProcess_new);
Process *proc = ProcessList_getProcess(pl, getpid, &preExisting, SolarisProcess_new);
SolarisProcess *sproc = (SolarisProcess*) proc;
// Common code pass 1