tv_pc.erl

来自「OTP是开放电信平台的简称」· ERL 代码 · 共 794 行 · 第 1/2 页

ERL
794
字号
%% ``The contents of this file are subject to the Erlang Public License,%% Version 1.1, (the "License"); you may not use this file except in%% compliance with the License. You should have received a copy of the%% Erlang Public License along with this software. If not, it can be%% retrieved via the world wide web at http://www.erlang.org/.%% %% Software distributed under the License is distributed on an "AS IS"%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See%% the License for the specific language governing rights and limitations%% under the License.%% %% The Initial Developer of the Original Code is Ericsson Utvecklings AB.%% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings%% AB. All Rights Reserved.''%% %%     $Id$%%%%%*********************************************************************%%% %%%   Description:      pc part of the table tool, i.e., the process controlling%%%                     all other processes, and managing the actions to take.%%%%%%*********************************************************************-module(tv_pc).-export([pc/7,	 send_data/2	]).-include("tv_int_def.hrl").-include("tv_int_msg.hrl").-include("tv_pc_int_def.hrl").%%%*********************************************************************%%% EXTERNAL FUNCTIONS%%%*********************************************************************%%======================================================================%% Function:      pc.%%%% Return Value:  None.%%%% Description:   Process controlling the processes 'pd', 'pw', 'dbs' and 'etsread'.%%                After necessary initialisations, an eternal loop is%%                entered, where window created messages are received and %%                handled, as well as user input.%%%% Parameters:    %%======================================================================pc(Master, Node, LocalNode, TableId, KindOfTable, TableName, ErrMsgMode) ->    process_flag(trap_exit, true),    put(error_msg_mode, ErrMsgMode),    ProcVars = prepare_and_open_table(Node, LocalNode, TableId, KindOfTable, TableName, 				false, #process_variables{parent_pid=Master}),    loop(ProcVars).%%%********************************************************************%%% INTERNAL FUNCTIONS%%%********************************************************************prepare_and_open_table(Node, LocalNode, TabId, TabType, TabName, Raise, ProcVars) ->    IpPid      = spawn(tv_ip, ip, [self()]),    show_progress(IpPid, 5, "Initializing graphics..."),    TmpProcVars = start_procs(IpPid, ProcVars),    show_progress(IpPid, 5, "Loading table..."),    NewProcVars = ?MENU_FUNC_FILE:open_table(Node, LocalNode, TabId, TabType, TabName, 					     Raise, TmpProcVars),    IpPid ! #ip_quit{sender = self()},       % Now make window visible!    WinP = NewProcVars#process_variables.window_params,    gs:config(WinP#window_params.window_id, [{map, true}]),    NewProcVars.start_procs(IpPid, ProcVars) ->    ErrorMsgMode = get(error_msg_mode),    PwPid        = spawn_link(tv_pw, pw, [self()]),    PdPid        = spawn_link(tv_pd, pd, [self(), ErrorMsgMode]),    DbsPid       = spawn_link(tv_db, dbs, [self(), ErrorMsgMode]),    EtsreadPid   = spawn_link(tv_etsread, etsread, [self(), ErrorMsgMode]),    show_progress(IpPid, 5, "Initializing graphics..."),    NewWinP = init_pw(PwPid, ProcVars),    show_progress(IpPid, 5, "Initializing graphics..."),    init_pd(PdPid, NewWinP),    ProcVars#process_variables{pw_pid        = PwPid,			       pd_pid        = PdPid,			       dbs_pid       = DbsPid,			       etsread_pid   = EtsreadPid,			       current_node  = node(),  %% Will be replaced, when table opened.			       local_node    = true,			       window_params = NewWinP			       }.%%======================================================================%% Function:      %%%% Return Value:  %%%% Description:   %%%% Parameters:    %%======================================================================show_progress(IpPid, NofElements, Text) ->    IpPid ! #ip_update{sender               = self(),		       nof_elements_to_mark = NofElements,		       text                 = Text		      }.    %%======================================================================%% Function:      loop.%%%% Return Value:  None.%%%% Description:   Eternal (well, almost) loop, receiving messages and %%                handling them.%%%% Parameters:    None.%%======================================================================loop(ProcVars) ->    receive	Msg ->	    case Msg of                    % Normal messages!		#dbs_subset{} ->		    NewProcVars1 = send_data(Msg, ProcVars),		    NewProcVars2 = check_time_to_poll_table(Msg, NewProcVars1),		    loop(NewProcVars2);		#pc_poll_table{} ->		    TmpProcVars  = check_node(ProcVars),		    NewProcVars = ?MENU_FUNC_FILE:poll_table(TmpProcVars),		    loop(NewProcVars);		#pc_search_req{} ->		    DbsPid = ProcVars#process_variables.dbs_pid,		    DbsPid ! #dbs_search_req{sender=self()},		    loop(ProcVars);		#pc_set_sorting_mode{} ->		    set_sorting_mode(Msg, ProcVars),		    loop(ProcVars);                #pc_data_req{element = Pos, nof_elements = Length} ->		    DbsPid = ProcVars#process_variables.dbs_pid,		    DbsPid ! #dbs_subset_req{sender           = self(), 					     subset_pos       = Pos,					     subset_length    = Length					    },                    loop(ProcVars);		#pc_marked_row{row_no=RowNo, object=Obj, color=Color} ->		    DbsPid = ProcVars#process_variables.dbs_pid,		    DbsPid ! #dbs_marked_row{sender = self(),					     row_no = RowNo					    },		    NewProcVars = ProcVars#process_variables{marked_row    = RowNo,							     marked_object = Obj,							     marked_color  = Color},		    loop(NewProcVars);		                #pc_menu_msg{} ->                    Fcn = Msg#pc_menu_msg.data,                    NewProcVars = ?MENU_FUNC_FILE:Fcn(ProcVars),                    loop(NewProcVars); 		#pd_updated_object{object=Obj,old_object=OldObj,old_color=Color,obj_no=ObjNo} ->		    DbsPid = ProcVars#process_variables.dbs_pid,		    DbsPid ! #dbs_updated_object{sender     = self(),						 object     = Obj,						 old_object = OldObj,						 old_color  = Color,						 obj_no     = ObjNo},		    loop(ProcVars);		#pd_new_object{object=Obj} ->		    DbsPid = ProcVars#process_variables.dbs_pid,		    DbsPid ! #dbs_new_object{sender     = self(),					     object     = Obj},		    loop(ProcVars);		#pc_show_table_info{} ->		    NewProcVars = ?MENU_FUNC_FILE:table_info(ProcVars),		    loop(NewProcVars);                #pc_win_conf{} ->                    NewProcVars = ?GRAPH_FUNC_FILE:win_conf(Msg, ProcVars),                    loop(NewProcVars);				#pc_help{} ->		    NewProcVars = ?MENU_FUNC_FILE:help_button(ProcVars),		    loop(NewProcVars);		#pc_dead_table{automatic_polling = AutoPoll} ->		    WinP  = ProcVars#process_variables.window_params,		    WinId = WinP#window_params.window_id,		    gs:config(WinId, [beep]),		    case get(error_msg_mode) of			normal ->			    tv_utils:notify(WinId, "TV Notification", 					    ["The table no longer exists!"]);			haiku ->			    ErrMsg1 = ["A table that big?",				       "It might be very useful.",				       "But now it is gone."],			    tv_utils:notify(WinId, "TV Notification", ErrMsg1)		    end,		    NewProcVars =			case AutoPoll of			    true ->				gs:config(WinId, [beep]),				case get(error_msg_mode) of				    normal ->					tv_utils:notify(WinId, "TV Notification",							["The automatic polling is turned off!"]);				    haiku ->					ErrMsg2 = ["Previously on",						  "The polling is now idled.",						  "That's the way it is."],					tv_utils:notify(WinId, "TV Notification", ErrMsg2)				end,				ProcVars#process_variables{poll_interval = infinity};			    false ->				ProcVars			end,		    loop(NewProcVars);		#pc_nodedown{automatic_polling = AutoPoll} ->		    WinP = ProcVars#process_variables.window_params,		    WinId = WinP#window_params.window_id,		    gs:config(WinId, [beep]),		    case get(error_msg_mode) of			normal ->			    tv_utils:notify(WinId, "TV Notification", 					    ["The node is down, and the",					     "table cannot be reached."]);			haiku ->			    ErrMsg1 = ["With searching comes loss",				       "And the presence of absence:",				       "Node is down."],			    tv_utils:notify(WinId, "TV Notification", ErrMsg1)		    end,		    NewProcVars = 			case AutoPoll of			    true ->				gs:config(WinId, [beep]),				case get(error_msg_mode) of				    normal ->					tv_utils:notify(WinId, "TV Notification",							["The automatic polling is turned off!"]);				    haiku ->					ErrMsg = ["Previously on,",						  "The polling is now idled.",						  "That's the way it is."],					tv_utils:notify(WinId, "TV Notification", ErrMsg)				end,				ProcVars#process_variables{poll_interval = infinity};			    false ->				ProcVars			end,		    loop(NewProcVars);		    		{pc_edit_object, _Sender} ->		    NewProcVars = ?MENU_FUNC_FILE:insert_object(ProcVars),		    loop(NewProcVars);		    		check_node ->		    NewProcVars  = check_node(ProcVars),		    loop(NewProcVars);		raise ->		    WinP = ProcVars#process_variables.window_params,		    gs:config(WinP#window_params.window_id, [raise]),		    loop(ProcVars);		{error_msg_mode, Mode} ->		    ProcVars#process_variables.dbs_pid ! {error_msg_mode, Mode},		    ProcVars#process_variables.etsread_pid ! {error_msg_mode, Mode},		    ProcVars#process_variables.pd_pid ! {error_msg_mode, Mode},		    put(error_msg_mode, Mode),		    loop(ProcVars);		   % Exit messages!		{'EXIT', Sender, Reason} ->		    exit_signals({Sender, Reason}, ProcVars);				_Other ->		    loop(ProcVars)	    end    end.	check_node(ProcVars) ->    #process_variables{pw_pid       = PwPid,		       current_node = OldCurrNode,		       local_node   = LocalNode,		       table_id     = TableId,		       table_type   = TableType,		       table_name   = TableName}  = ProcVars,    HomeNode = node(),    case net_adm:ping(OldCurrNode) of	pong ->	    ProcVars;	pang when not LocalNode ->	    ProcVars;	pang when LocalNode ->	    %% XXX [siri] Will this ever happen? I thought local_node	    %% indicated if current_node was the node where tv was	    %% started. If so, we are pinging ourselves here, and	    %% a pang can never happen??	    WinTitle = ?MENU_FUNC_FILE:get_window_title(TableType,HomeNode,TableId,TableName),	    PwPid ! #pw_set_window_title{sender = self(),					 win_title = WinTitle},	    ProcVars#process_variables{current_node = HomeNode}    end.send_data(Msg, ProcVars) ->    #process_variables{pd_pid           = PdPid,		       parent_pid       = ParentPid,		       table_id         = Table,		       table_type       = Type,		       current_node     = Node}  = ProcVars,        ParentPid ! {tv_update_infowin, Table, Node, Type},    #dbs_subset{data                  = DbData,		subset_pos            = ScalePos,

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?