tv_pc.erl
来自「OTP是开放电信平台的简称」· ERL 代码 · 共 794 行 · 第 1/2 页
ERL
794 行
db_length = DbLength, list_of_keys = ListOfKeys, max_elem_size = MaxElemSize, requested_row = ReqRowData} = Msg, Range = case ScalePos of 0 -> {0, 0}; _Other -> {1, DbLength} end, PdPid ! #pc_data{sender = self(), scale_pos = ScalePos, scale_range = Range, elementlist = DbData, list_of_keys = ListOfKeys, max_elem_size = MaxElemSize, marked_row = ReqRowData }, {MarkedObject, MarkedColor} = case ReqRowData of [] -> {undefined, undefined}; [Data] -> Data end, ProcVars#process_variables{marked_object = MarkedObject, marked_color = MarkedColor}.%%======================================================================%% Function: %%%% Return Value: %%%% Description: %%%% Parameters: %%======================================================================set_sorting_mode(Msg, ProcVars) -> #pc_set_sorting_mode{sorting = Sorting, reverse = Reverse, sort_key_no = SortKeyNo} = Msg, DbsPid = ProcVars#process_variables.dbs_pid, PdPid = ProcVars#process_variables.pd_pid, PwPid = ProcVars#process_variables.pw_pid, TableType = ProcVars#process_variables.table_type, NewSortKeyNo = case SortKeyNo of undefined -> if TableType =:= mnesia -> 2; true -> 1 end; _Other -> SortKeyNo end, Menu = case Sorting of true -> case Reverse of true -> sort_falling_order; false -> sort_rising_order end; false -> no_sorting end, PwPid ! #pw_select_menu{sender = self(), menu = Menu}, DbsPid ! #dbs_sorting_mode{sender = self(), sorting = Sorting, reverse = Reverse, sort_key_no = NewSortKeyNo }, PdPid ! #pc_set_sorting_mode_cfm{sender = self(), sort_key_no = NewSortKeyNo }.%%======================================================================%% Function: init_pw.%%%% Return Value: Tuple containing the Pid of the pw process, and the id of %% the window created by the pw process.%%%% Description: Starts the pw process, and orders it to create a window.%% (The size of the window may be given as option.)%%%% Parameters: None.%%======================================================================init_pw(PwPid, ProcVars) -> #process_variables{window_params = WinP} = ProcVars, % Now deblock pw, and order it to create a window! PwPid ! #pw_deblock{sender = self(), win_title = ?APPLICATION_NAME, win_width = ?DEFAULT_WINDOW_WIDTH, win_height = ?DEFAULT_WINDOW_HEIGHT, min_win_width = ?DEFAULT_MIN_WINDOW_WIDTH, min_win_height = ?DEFAULT_MIN_WINDOW_HEIGHT }, receive #pw_deblock_cfm{win_id = WindowId} -> ?MENU_FUNC_FILE:create_menus(PwPid), % Store the window id as well as the size of it. WinP#window_params{window_id = WindowId, window_width = ?DEFAULT_WINDOW_WIDTH, window_height = ?DEFAULT_WINDOW_HEIGHT } after 180000 -> % A timeout of 1000 ms is too short, at least the first % time the system is started! exit(error) end. %%======================================================================%% Function: %%%% Return Value: %%%% Description: %%%% Parameters: %%======================================================================init_pd(PdPid, WinP) -> #window_params{window_id = WindowId, window_width = WindowWidth, window_height = WindowHeight} = WinP, % Now deblock pd, and order it to create a canvas and a scale! PdPid ! #pd_deblock{sender = self(), win = WindowId, win_width = WindowWidth, win_height = WindowHeight, scale = true }, receive #pd_deblock_cfm{} -> done after 180000 -> exit(error) end. %%======================================================================%% Function: exit_signals.%%%% Return Value: None.%%%% Description: Decides, given an error message, action to take, i.e., whether%% operation shall procede, any process shall be restarted, or%% the table tool terminated.%%%% Parameters: Exit_info: tuple containing sender of the error message, and the %% reason.%%======================================================================exit_signals(ExitInfo, ProcVars) -> #process_variables{parent_pid = ParentPid, pd_pid = PdPid, pw_pid = PwPid, dbs_pid = DbsPid, etsread_pid = EtsreadPid, table_id = TabId, table_type = TabType, table_name = TabName, current_node = Node, local_node = LocalNode } = ProcVars, case ExitInfo of {ParentPid, Reason} -> exit(Reason); {PwPid, normal} -> exit(normal); {PwPid, error} -> io:format("Internal error... restarting. ~n"), kill_procs(normal, [PdPid, EtsreadPid, DbsPid]), NewProcVars = pc(ParentPid, Node, LocalNode, TabId, TabType, TabName, get(error_msg_mode)), loop(NewProcVars); {PdPid, _Reason} -> io:format("Internal error... restarting. ~n"), kill_procs(normal, [PwPid, EtsreadPid, DbsPid]), NewProcVars = pc(ParentPid, Node, LocalNode, TabId, TabType, TabName, get(error_msg_mode)), loop(NewProcVars); {DbsPid, _Reason} -> io:format("Internal error... restarting. ~n"), kill_procs(normal, [PdPid, PwPid, EtsreadPid]), NewProcVars = pc(ParentPid, Node, LocalNode, TabId, TabType, TabName, get(error_msg_mode)), loop(NewProcVars); {EtsreadPid, _Reason} -> io:format("Internal error... restarting. ~n"), kill_procs(normal, [PdPid, PwPid, DbsPid]), NewProcVars = pc(ParentPid, Node, LocalNode, TabId, TabType, TabName, get(error_msg_mode)), loop(NewProcVars); {_Sender, _OtherReason} -> loop(ProcVars) end.%%======================================================================%% Function: %%%% Return Value: %%%% Description: %%%% Parameters: %%======================================================================kill_procs(_Status, []) -> done;kill_procs(Status, [Pid | Tail]) -> exit(Pid, Status), kill_procs(Status, Tail).%%======================================================================%% Function: %%%% Return Value: %%%% Description: %%%% Parameters: %%======================================================================check_time_to_poll_table(Msg, ProcVars) -> #dbs_subset{required_time_etsread = EtsreadTime, required_time_dbs = DbsTime} = Msg, UserSetPollInterval = ProcVars#process_variables.poll_interval, WinP = ProcVars#process_variables.window_params, WinId = WinP#window_params.window_id, case too_short_pollinterval_chosen(UserSetPollInterval, EtsreadTime, DbsTime) of true -> EtsreadPid = ProcVars#process_variables.etsread_pid, EtsreadPid ! #etsread_set_poll_interval{sender = self(), interval = infinity}, TimeRequired = trunc(max_time_required(EtsreadTime, DbsTime) / 10 + 0.5) * 10 + 20, gs:config(WinId, [beep]), case get(error_msg_mode) of normal -> tv_utils:notify(WinId, "TV Notification", ["The current poll interval is too short!"]), Str = "to " ++ lists:flatten(io_lib:write(TimeRequired)) ++ " seconds!", tv_utils:notify(WinId, "TV Notification", ["Setting the poll interval", Str]); haiku -> ErrMsg = ["Being way too short", "The interval of polling", "Is simply increased."], tv_utils:notify(WinId, "TV Notification", ErrMsg) end, clear_message_buffer(), EtsreadPid ! #etsread_set_poll_interval{sender = self(), interval = TimeRequired}, ProcVars#process_variables{poll_interval = TimeRequired}; false -> ProcVars end.clear_message_buffer() -> receive #dbs_subset{} -> clear_message_buffer() after 100 -> done end.max_time_required(T1, T2) when is_number(T1), is_number(T2) -> if T1 > T2 -> T1; true -> T2 end;max_time_required(T1, _T2) when is_number(T1) -> T1;max_time_required(_T1, T2) -> T2. %%======================================================================%% Function: %%%% Return Value: %%%% Description: %%%% Parameters: %%======================================================================too_short_pollinterval_chosen(infinity, _EtsreadTime, _DbsTime) -> false;too_short_pollinterval_chosen(undefined, _EtsreadTime, _DbsTime) -> false;too_short_pollinterval_chosen(PollInt, EtsreadTime, _DbsTime) when EtsreadTime >= PollInt, is_number(EtsreadTime) -> true;too_short_pollinterval_chosen(PollInt, _EtsreadTime, DbsTime) when DbsTime >= PollInt, is_number(DbsTime) -> true;too_short_pollinterval_chosen(_PollInt, _EtsreadTime, _DbsTime) -> false.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?