Skip to content

Commit

Permalink
erlang: update documentation
Browse files Browse the repository at this point in the history
- document use of pseudo variable $pid(name)
- regenerate README
  • Loading branch information
Seudin Kasumovic authored and seudin committed May 14, 2015
1 parent f14a5c3 commit 746152b
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 23 deletions.
57 changes: 37 additions & 20 deletions modules/erlang/README
Expand Up @@ -40,7 +40,8 @@ Seudin Kasumovic
4.3. $atom(name)
4.4. $list(name)
4.5. $tuple(name)
4.6. $xbuff(name)
4.6. $pid(name)
4.7. $xbuff(name)

5. Functions

Expand Down Expand Up @@ -81,12 +82,13 @@ Seudin Kasumovic
1.9. Example set and print to log atom
1.10. Example of using lists
1.11. Example of using tuple
1.12. Example of using xbuff
1.13. Example of using erl_rpc
1.14. Example of using erl_reg_send
1.15. Example of registered process
1.16. Example of registered process
1.17. Example of using default event route
1.12. Example of using pid
1.13. Example of using xbuff
1.14. Example of using erl_rpc
1.15. Example of using erl_reg_send
1.16. Example of use erl_reply
1.17. Example of registered process
1.18. Example of using default event route
2.1. Example of RPC call from erlang shell with no response
2.2. Example, check is line registered
2.3. Example get config variable
Expand Down Expand Up @@ -120,7 +122,8 @@ Chapter 1. Admin Guide
4.3. $atom(name)
4.4. $list(name)
4.5. $tuple(name)
4.6. $xbuff(name)
4.6. $pid(name)
4.7. $xbuff(name)

5. Functions

Expand Down Expand Up @@ -271,7 +274,8 @@ modparam("erlang", "trace_level", 5)
4.3. $atom(name)
4.4. $list(name)
4.5. $tuple(name)
4.6. $xbuff(name)
4.6. $pid(name)
4.7. $xbuff(name)

4.1. Overview

Expand All @@ -290,8 +294,8 @@ modparam("erlang", "trace_level", 5)
by self determine variable type, but we need to know what type on some
position is.
* type
get variable type. Possible types are: atom, integer, list, string
and tuple.
get variable type. Possible types are: atom, integer, list, string,
tuple and pid.
* length
get length of list or tuple.
* format
Expand Down Expand Up @@ -410,15 +414,28 @@ xlogl("L_DEBUG","length(T): $tuple(T=>length), format(T): $tuple(T=>format)\n");
DEBUG: <script>: 153:length(T): 2, format(T): {line, [{id, 23}, {owner, "Bob"}]}
...

4.6. $xbuff(name)
4.6. $pid(name)

pid holds Eralng process identifier. Provides access to pid value and
could be used in send message.

Example 1.12. Example of using pid
...
if ($xbuff(msg[0]=>type) == "pid") {
$pid(pid) = $xbuff(msg[0]);
xlogl("L_INFO","Received PID: $pid(pid=>format)\n");
}
...

4.7. $xbuff(name)

xbuff is created as generic pseudo variable to acts as other pseudo
variables exported from module. It's useful when in advance we don't
know what variable type to expect. The behavior of variable depends of
initialization. Module functions expect this PV as return value, and PV
for incoming erlang message.

Example 1.12. Example of using xbuff
Example 1.13. Example of using xbuff
...
# tuple T from previous example

Expand Down Expand Up @@ -457,7 +474,7 @@ DEBUG: <script>: 410:typeof(X): tuple, length(X): 2, format(X): {line, [{id, 23}
function. If executing remote function caused error function still
returns true but error is encoded into repl parameter.

Example 1.13. Example of using erl_rpc
Example 1.14. Example of using erl_rpc
...
# example of call erlang:list_to_tuple(["one","two"])
# on remote node
Expand Down Expand Up @@ -487,7 +504,7 @@ DEBUG: <script>: 386:type(repl): tuple, format(repl): {"one", "two"}

The argument msg is containing the message to be sent.

Example 1.14. Example of using erl_reg_send
Example 1.15. Example of using erl_reg_send
...
# example of send message to registered process
# {notifier,'node1@erlang.lan'} ! {example,message}
Expand All @@ -506,7 +523,7 @@ erl_reg_send("notifier","$tuple(M)");
Function to send message from event route (pseudo process). Function
sends reply message msg to the sender process.

Example 1.15. Example of registered process
Example 1.16. Example of use erl_reply
...
# event route acts as registered process
event_route[erlang:greetings] {
Expand Down Expand Up @@ -543,16 +560,16 @@ INFO: <script>: 951:Received message: {"hello", "Kamailio"}
we can use event routes. Event routes executed when asynchronous
message received from erlang node.

Event route receive message in $xbuff(msg). Reply variable is optional
and can be sent with erl_reply.
Event route receives message in $xbuff(msg) and sender process in
$xbuff(pid). Reply message is optional and can be sent with erl_reply.

6.1. Registered pseudo process

To create pseudo erlang registered process in Kamailio scrip create
event route in form of event_route[erlang:<my_process_name>]. Where
<my_process_name> is the name of pseudo process.

Example 1.16. Example of registered process
Example 1.17. Example of registered process
...
# event route acts as registered process
event_route[erlang:handler] {
Expand All @@ -576,7 +593,7 @@ INFO: <script>: 951:Received message: {"hello", "Kamailio"}
The reserved pseudo process name to receive messages sent to Kamailio C
node. The message are sent to non registered process.

Example 1.17. Example of using default event route
Example 1.18. Example of using default event route
...
# default event route from erlang
event_route[erlang:self] {
Expand Down
25 changes: 22 additions & 3 deletions modules/erlang/doc/erlang_admin.xml
Expand Up @@ -241,7 +241,7 @@ modparam("erlang", "trace_level", 5)
<varname>type</varname>
<para>
get variable type. Possible types are: <emphasis>atom, integer,
list, string</emphasis> and <emphasis>tuple</emphasis>.
list, string</emphasis>, <emphasis>tuple</emphasis> and <emphasis>pid</emphasis>.
</para>
</listitem>
<listitem>
Expand Down Expand Up @@ -390,6 +390,24 @@ xlogl("L_DEBUG","length(T): $tuple(T=>length), format(T): $tuple(T=>format)\n");
&gt; log output is:
...
DEBUG: &lt;script&gt;: 153:length(T): 2, format(T): {line, [{id, 23}, {owner, "Bob"}]}
...
</programlisting>
</example>
</section>
<section id="erlang.v.pid">
<title><varname>$pid(name)</varname></title>
<para>
<emphasis>pid</emphasis> holds Eralng process identifier. Provides
access to pid value and could be used in send message.
</para>
<example>
<title>Example of using pid</title>
<programlisting format="linespecific">
...
if ($xbuff(msg[0]=>type) == "pid") {
$pid(pid) = $xbuff(msg[0]);
xlogl("L_INFO","Received PID: $pid(pid=>format)\n");
}
...
</programlisting>
</example>
Expand Down Expand Up @@ -553,8 +571,9 @@ INFO: &lt;script&gt;: 951:Received message: {"hello", "Kamailio"}
from erlang node.
</para>
<para>
Event route receive message in <varname>$xbuff(msg)</varname>. Reply
variable is optional and can be sent with <emphasis>erl_reply</emphasis>.
Event route receives message in <varname>$xbuff(msg)</varname> and sender
process in <varname>$xbuff(pid)</varname>. Reply message is optional
and can be sent with <emphasis>erl_reply</emphasis>.
</para>
<section>
<title>Registered pseudo process</title>
Expand Down

0 comments on commit 746152b

Please sign in to comment.