Serenity Operating System
at hosted 73 lines 3.4 kB view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this 9 * list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include "ProcessFileDescriptorMapWidget.h" 28#include <LibGUI/BoxLayout.h> 29#include <LibGUI/JsonArrayModel.h> 30#include <LibGUI/TableView.h> 31 32ProcessFileDescriptorMapWidget::ProcessFileDescriptorMapWidget() 33{ 34 set_layout<GUI::VerticalBoxLayout>(); 35 layout()->set_margins({ 4, 4, 4, 4 }); 36 m_table_view = add<GUI::TableView>(); 37 m_table_view->set_size_columns_to_fit_content(true); 38 39 Vector<GUI::JsonArrayModel::FieldSpec> pid_fds_fields; 40 pid_fds_fields.empend("fd", "FD", Gfx::TextAlignment::CenterRight); 41 pid_fds_fields.empend("class", "Class", Gfx::TextAlignment::CenterLeft); 42 pid_fds_fields.empend("offset", "Offset", Gfx::TextAlignment::CenterRight); 43 pid_fds_fields.empend("absolute_path", "Path", Gfx::TextAlignment::CenterLeft); 44 pid_fds_fields.empend("Access", Gfx::TextAlignment::CenterLeft, [](auto& object) { 45 return object.get("seekable").to_bool() ? "Seekable" : "Sequential"; 46 }); 47 pid_fds_fields.empend("Blocking", Gfx::TextAlignment::CenterLeft, [](auto& object) { 48 return object.get("blocking").to_bool() ? "Blocking" : "Nonblocking"; 49 }); 50 pid_fds_fields.empend("On exec", Gfx::TextAlignment::CenterLeft, [](auto& object) { 51 return object.get("cloexec").to_bool() ? "Close" : "Keep"; 52 }); 53 pid_fds_fields.empend("Can read", Gfx::TextAlignment::CenterLeft, [](auto& object) { 54 return object.get("can_read").to_bool() ? "Yes" : "No"; 55 }); 56 pid_fds_fields.empend("Can write", Gfx::TextAlignment::CenterLeft, [](auto& object) { 57 return object.get("can_write").to_bool() ? "Yes" : "No"; 58 }); 59 60 m_table_view->set_model(GUI::JsonArrayModel::create({}, move(pid_fds_fields))); 61} 62 63ProcessFileDescriptorMapWidget::~ProcessFileDescriptorMapWidget() 64{ 65} 66 67void ProcessFileDescriptorMapWidget::set_pid(pid_t pid) 68{ 69 if (m_pid == pid) 70 return; 71 m_pid = pid; 72 static_cast<GUI::JsonArrayModel*>(m_table_view->model())->set_json_path(String::format("/proc/%d/fds", m_pid)); 73}