1%% 2%% %CopyrightBegin% 3%% 4%% Copyright Ericsson AB 2013-2018. All Rights Reserved. 5%% 6%% Licensed under the Apache License, Version 2.0 (the "License"); 7%% you may not use this file except in compliance with the License. 8%% You may obtain a copy of the License at 9%% 10%% http://www.apache.org/licenses/LICENSE-2.0 11%% 12%% Unless required by applicable law or agreed to in writing, software 13%% distributed under the License is distributed on an "AS IS" BASIS, 14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15%% See the License for the specific language governing permissions and 16%% limitations under the License. 17%% 18%% %CopyrightEnd% 19-module(cdv_port_cb). 20 21-export([col_to_elem/1, 22 col_spec/0, 23 get_info/1, 24 get_detail_cols/1, 25 get_details/2, 26 detail_pages/0, 27 format/1]). 28 29-include_lib("wx/include/wx.hrl"). 30-include("crashdump_viewer.hrl"). 31 32%% Columns 33-define(COL_ID, 0). 34-define(COL_CONN, ?COL_ID+1). 35-define(COL_NAME, ?COL_CONN+1). 36-define(COL_CTRL, ?COL_NAME+1). 37-define(COL_QUEUE, ?COL_CTRL+1). 38-define(COL_SLOT, ?COL_QUEUE+1). 39 40 41 42%% Callbacks for cdv_virtual_list_wx 43col_to_elem(id) -> col_to_elem(?COL_ID); 44col_to_elem(?COL_ID) -> #port.id; 45col_to_elem(?COL_CONN) -> #port.connected; 46col_to_elem(?COL_NAME) -> #port.name; 47col_to_elem(?COL_CTRL) -> #port.controls; 48col_to_elem(?COL_QUEUE) -> #port.queue; 49col_to_elem(?COL_SLOT) -> #port.slot. 50 51col_spec() -> 52 [{"Id", ?wxLIST_FORMAT_LEFT, 100}, 53 {"Connected", ?wxLIST_FORMAT_LEFT, 120}, 54 {"Name", ?wxLIST_FORMAT_LEFT, 150}, 55 {"Controls", ?wxLIST_FORMAT_LEFT, 200}, 56 {"Queue", ?wxLIST_FORMAT_RIGHT, 100}, 57 {"Slot", ?wxLIST_FORMAT_RIGHT, 50}]. 58 59get_info(_) -> 60 {ok,Info,TW} = crashdump_viewer:ports(), 61 {Info,TW}. 62 63get_detail_cols(_) -> 64 {[{port, ?COL_ID},{process, ?COL_CONN}],true}. 65 66%% Callbacks for cdv_detail_wx 67get_details(Id, _Data) -> 68 case crashdump_viewer:port(Id) of 69 {ok,Info,TW} -> 70 Proplist = 71 crashdump_viewer:to_proplist(record_info(fields,port),Info), 72 {ok,{Id,Proplist,TW}}; 73 {error,{other_node,NodeId}} -> 74 Info = "The port you are searching for was residing on " 75 "a remote node. No port information is available. " 76 "Show information about the remote node?", 77 Fun = fun() -> cdv_virtual_list_wx:start_detail_win(NodeId, node) end, 78 {yes_no, Info, Fun}; 79 {error,not_found} -> 80 Info = "The port you are searching for could not be found.", 81 {info,Info} 82 end. 83 84detail_pages() -> 85 [{"General Information", fun init_gen_page/2}]. 86 87init_gen_page(Parent, Info) -> 88 Fields = info_fields(), 89 cdv_info_wx:start_link(Parent,{Fields,Info,[]}). 90 91format({I1,I2}) -> 92 "#Port<"++integer_to_list(I1) ++ "." ++ integer_to_list(I2) ++ ">"; 93format(D) -> 94 D. 95 96 97%%%----------------------------------------------------------------- 98%%% Internal 99info_fields() -> 100 [{"Overview", 101 [{"Name", name}, 102 {"State", state}, 103 {"Task Flags", task_flags}, 104 {"Connected", {click,connected}}, 105 {"Slot", slot}, 106 {"Controls", controls}, 107 {"Input bytes", input}, 108 {"Output bytes", output}, 109 {"Queue bytes", queue}, 110 {"Port data", port_data}]}, 111 {scroll_boxes, 112 [{"Links",1,{click,links}}, 113 {"Monitors",1,{click,monitors}}, 114 {"Suspended",1,{click,suspended}} 115 ]}]. 116