...
This commit is contained in:
1
pkg/servers/ui/models/.gitkeep
Normal file
1
pkg/servers/ui/models/.gitkeep
Normal file
@@ -0,0 +1 @@
|
||||
# This file is intentionally left blank to ensure the directory is tracked by Git.
|
48
pkg/servers/ui/models/process_model.go
Normal file
48
pkg/servers/ui/models/process_model.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package models
|
||||
|
||||
// Process represents a single running process with its relevant details.
|
||||
type Process struct {
|
||||
PID int `json:"pid"`
|
||||
Name string `json:"name"`
|
||||
CPU float64 `json:"cpu"` // CPU usage percentage
|
||||
Memory float64 `json:"memory"` // Memory usage in MB
|
||||
// Add other fields if needed, e.g., User, Status, Path
|
||||
}
|
||||
|
||||
// ProcessManagerService defines the interface for interacting with the system's process manager.
|
||||
// This will be implemented by a struct that calls pkg/system/processmanager.
|
||||
type ProcessManagerService interface {
|
||||
GetProcesses() ([]Process, error)
|
||||
KillProcess(pid int) error
|
||||
}
|
||||
|
||||
// TODO: Implement a concrete ProcessManagerService that uses pkg/system/processmanager.
|
||||
// For now, we can create a mock implementation for development and testing of the UI.
|
||||
|
||||
// MockProcessManager is a mock implementation of ProcessManagerService for UI development.
|
||||
type MockProcessManager struct{}
|
||||
|
||||
// GetProcesses returns a list of mock processes.
|
||||
func (m *MockProcessManager) GetProcesses() ([]Process, error) {
|
||||
// Return some mock data
|
||||
return []Process{
|
||||
{PID: 1001, Name: "SystemIdleProcess", CPU: 95.5, Memory: 0.1},
|
||||
{PID: 1002, Name: "explorer.exe", CPU: 1.2, Memory: 150.7},
|
||||
{PID: 1003, Name: "chrome.exe", CPU: 25.8, Memory: 512.3},
|
||||
{PID: 1004, Name: "code.exe", CPU: 5.1, Memory: 350.0},
|
||||
{PID: 1005, Name: "go.exe", CPU: 0.5, Memory: 80.2},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// KillProcess simulates killing a process.
|
||||
func (m *MockProcessManager) KillProcess(pid int) error {
|
||||
// In a real implementation, this would call the system process manager.
|
||||
// For mock, we just print a message or do nothing.
|
||||
// fmt.Printf("Mock: Attempting to kill process %d\n", pid)
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewMockProcessManager creates a new instance of MockProcessManager.
|
||||
func NewMockProcessManager() ProcessManagerService {
|
||||
return &MockProcessManager{}
|
||||
}
|
Reference in New Issue
Block a user