From 88b530ea24977081020feb2123124063e58dfc12 Mon Sep 17 00:00:00 2001 From: Steve Vinoski Date: Fri, 27 Nov 2009 12:37:13 -0500 Subject: Teach sys:get_status/1,2 to call Mod:format_status/2 Restore the ability for gen_server and gen_fsm callback modules to format their own state for display under the sys:get_status/1,2 calls. This ability is extremely useful for new behavior modules based on gen_server or gen_fsm, so that they can display their status in a more meaningful way than just dumping the state record. It is also generally useful for applications wanting to display their gen_server or gen_fsm callback module state in something other than the default manner. Also document the previously undocumented the gen_server:format_status/2 and gen_fsm:format_status/2 optional callback functions that, if exported by the callback module, are invoked when sys:get_status/1,2 are called. Add unit tests to ensure that format_status/2 functions exported from a gen_fsm callback module and a gen_server callback module are called when sys:get_status/1,2 are called. --- lib/stdlib/doc/src/gen_fsm.xml | 30 ++++++++++++++++++++++++++++++ lib/stdlib/doc/src/gen_server.xml | 29 +++++++++++++++++++++++++++++ lib/stdlib/doc/src/sys.xml | 11 +++++++++++ 3 files changed, 70 insertions(+) (limited to 'lib/stdlib/doc') diff --git a/lib/stdlib/doc/src/gen_fsm.xml b/lib/stdlib/doc/src/gen_fsm.xml index f5d8b9bb48..739cd0bffd 100644 --- a/lib/stdlib/doc/src/gen_fsm.xml +++ b/lib/stdlib/doc/src/gen_fsm.xml @@ -729,6 +729,36 @@ gen_fsm:sync_send_all_state_event -----> Module:handle_sync_event/4 updated internal data.

+ + Module:format_status(normal, [PDict, StateData]) -> Status + Optional function for providing a term describing the + current gen_fsm status. + + PDict = [{Key, Value}] + StateData = term() + Status = [term()] + + +

This callback is optional, so callback modules need not + export it. The gen_fsm module provides a default + implementation of this function that returns the callback + module state data.

+

This function is called by a gen_fsm process when one + of sys:get_status/1,2 + is invoked to get the gen_fsm status. A callback module + wishing to customise the sys:get_status/1,2 return + value exports an instance of format_status/2 that + returns a term describing the current status of the + gen_fsm.

+

PDict is the current value of the gen_fsm's + process dictionary.

+

StateData is the internal state data of the + gen_fsm.

+

The function should return Status, a list of one or + more terms that customise the details of the current state + and status of the gen_fsm.

+
+
diff --git a/lib/stdlib/doc/src/gen_server.xml b/lib/stdlib/doc/src/gen_server.xml index 8496802259..30c04d1d52 100644 --- a/lib/stdlib/doc/src/gen_server.xml +++ b/lib/stdlib/doc/src/gen_server.xml @@ -598,6 +598,35 @@ gen_server:abcast -----> Module:handle_cast/2

The function should return the updated internal state.

+ + Module:format_status(normal, [PDict, State]) -> Status + Optional function for providing a term describing the + current gen_server status. + + PDict = [{Key, Value}] + State = term() + Status = [term()] + + +

This callback is optional, so callback modules need not + export it. The gen_server module provides a default + implementation of this function that returns the callback + module state.

+

This function is called by a gen_server process when one + of sys:get_status/1,2 + is invoked to get the gen_server status. A callback module + wishing to customise the sys:get_status/1,2 return + value exports an instance of format_status/2 that + returns a term describing the current status of the + gen_server.

+

PDict is the current value of the gen_server's + process dictionary.

+

State is the internal state of the gen_server.

+

The function should return Status, a list of one or + more terms that customise the details of the current state + and status of the gen_server.

+
+
diff --git a/lib/stdlib/doc/src/sys.xml b/lib/stdlib/doc/src/sys.xml index a395a8a415..51fd5ee8d4 100644 --- a/lib/stdlib/doc/src/sys.xml +++ b/lib/stdlib/doc/src/sys.xml @@ -237,6 +237,17 @@

Gets the status of the process.

+

The value of Misc varies for different types of + processes. For example, a gen_server process returns + the callback module's state, and a gen_fsm process + returns information such as its current state name. Callback + modules for gen_server and gen_fsm can also + customise the value of Misc by exporting + a format_status/2 function that contributes + module-specific information; + see gen_server:format_status/2 + and gen_fsm:format_status/2 + for more details.

-- cgit v1.2.3