<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1316352013241370780</id><updated>2011-11-27T15:59:51.725-08:00</updated><title type='text'>蚂蚁快跑</title><subtitle type='html'>钟芳林(Freeant)的博客(Blog).</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://fzhong.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://fzhong.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>钟芳林</name><uri>http://www.blogger.com/profile/14620517815530657655</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>17</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1316352013241370780.post-4157714586897368194</id><published>2008-05-06T19:29:00.001-07:00</published><updated>2008-05-06T19:29:32.435-07:00</updated><title type='text'>MiniGui</title><content type='html'>&lt;p&gt;一个用于嵌入式开发的GUI库，官方网站是&lt;a title="http://www.minigui.org/" href="http://www.minigui.org/"&gt;http://www.minigui.org/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;有空了解一下&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1316352013241370780-4157714586897368194?l=fzhong.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://fzhong.blogspot.com/feeds/4157714586897368194/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1316352013241370780&amp;postID=4157714586897368194' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/4157714586897368194'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/4157714586897368194'/><link rel='alternate' type='text/html' href='http://fzhong.blogspot.com/2008/05/minigui.html' title='MiniGui'/><author><name>钟芳林</name><uri>http://www.blogger.com/profile/14620517815530657655</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1316352013241370780.post-3489410928990023535</id><published>2008-04-01T01:00:00.001-07:00</published><updated>2008-04-01T01:00:56.838-07:00</updated><title type='text'>ejabberd源码阅读笔记</title><content type='html'>&lt;h4&gt;ejabberd_sup &lt;/h4&gt;  &lt;p&gt;ejabberd_sup是ejabberd的进程监视者()，由ejabberd_app创建。&lt;/p&gt;  &lt;h5&gt;supervisor(监视进程)&lt;/h5&gt;  &lt;p&gt;&lt;strong&gt;&lt;em&gt;supervisor的功能是启动，停止和监控它的子进程。其作用是保持其子进程运行，在必要的时候重启其子进程，例如子进程死掉的时候。&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;em&gt;A supervisor is responsible for starting, stopping and monitoring its child processes. The basic idea of a supervisor is that it should keep its child processes alive by restarting them when necessary.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;ejabberd_sup负责创建一堆的子进程并监视它们，这些进程有:&lt;/p&gt;  &lt;p&gt;ejabberd_hooks,ejabberd_node_groups,ejabberd_system_monitor,ejabberd_router,ejabberd_sm,ejabberd_s2s,ejabberd_local,&lt;/p&gt;  &lt;p&gt;ejabberd_listener,ejabberd_receiver_sup,ejabberd_c2s_sup,ejabberd_s2s_in_sup,ejabberd_s2s_out_sup,ejabberd_service_sup,&lt;/p&gt;  &lt;p&gt;ejabberd_http_sup,ejabberd_http_poll_sup,ejabberd_frontend_socket_sup,ejabberd_iq_sup,ejabberd_tmp_sup&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;这些进程大部分也是以sup结尾的supervisor监视进程.&lt;/p&gt;  &lt;h4&gt;ejabberd_listener&lt;/h4&gt;  &lt;p&gt;ejabberd_listener是由ejabberd_sup创建的一个supervisor进程，他负责监视和创建一系列的网络端口监听进程。&lt;/p&gt;  &lt;p&gt;ejabberd_listener创建的端口监听进程列表是由配置文件中的listen读取的，配置文件样例如下:&lt;/p&gt;  &lt;p&gt;{listen,    &lt;br /&gt;[     &lt;br /&gt;&amp;#160; {4222, ejabberd_c2s, [     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; %%     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; %% If TLS is compiled and you installed a SSL     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; %% certificate, put the correct path to the     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; %% file and uncomment this line:     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; %%     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; %%{certfile, &amp;quot;/path/to/ssl.pem&amp;quot;}, starttls,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {access, c2s},     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {shaper, c2s_shaper},     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {max_stanza_size, 65536}     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ]}, &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;{5269, ejabberd_s2s_in, [    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {shaper, s2s_shaper},     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {max_stanza_size, 131072}     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ]}, &lt;/p&gt;  &lt;p&gt;{5280, ejabberd_http, [    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; http_poll,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; web_admin,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {request_handlers, [{[&amp;quot;httpbind&amp;quot;], mod_http_bind},{[&amp;quot;pub&amp;quot;, &amp;quot;archive&amp;quot;], mod_http_fileserver}]}     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ]},     &lt;br /&gt;{5347, ejabberd_service, [{host, &amp;quot;msn-transport.bucc.cn&amp;quot;, [{password, &amp;quot;1j5llz!o&amp;quot;}]}]}     &lt;br /&gt;]}. &lt;/p&gt;  &lt;p&gt;每个进程的格式如下,{port_no,module_name,[args]}&lt;/p&gt;  &lt;p&gt;port_no:端口号，同时也是创建进程时的进程标识&lt;/p&gt;  &lt;p&gt;module_name:进程模块名称&lt;/p&gt;  &lt;p&gt;args:参数列表&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h4&gt;ejabberd_receiver&lt;/h4&gt;  &lt;p&gt;ejabberd_receiver是一个gen_server进程(behaviour)，由ejabberd_socket创建&lt;/p&gt;  &lt;h4&gt;xml_stream&lt;/h4&gt;  &lt;h4&gt;ejabber_c2s&lt;/h4&gt;  &lt;p&gt;ejabber_cs2是一个gen_fsm(有限状态机)，维护一系列client和server之间的状态。gen_fsm的状态改变是由gen_fsm:send_event(FsmRef, Event)触发的。在ejabberd里，ejabberd_receiver通过xml_stream把事件和xml发送至ejabber_c2s改变其状态。&lt;/p&gt;  &lt;p&gt;ejabber_c2s有限状态机的初始状态是wait_for_stream,其余的状态有：&lt;/p&gt;  &lt;p&gt;wait_for_auth,wait_for_feature_request,wait_for_sasl_response,wait_for_bind,wait_for_session,session_established&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h6&gt;关于帐户免域登录：&lt;/h6&gt;  &lt;p&gt;将来如果需要添加这个功能，可以修改在ejabberd_c2s的代码实现这个功能，在wait_for_stream状态时，在给客户端发送stream:features的时候附上域名，这样客户端就可以登录的时候附上取得的域了，或者是直接在ejabberd_auth模块实现这个功能?&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1316352013241370780-3489410928990023535?l=fzhong.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://fzhong.blogspot.com/feeds/3489410928990023535/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1316352013241370780&amp;postID=3489410928990023535' title='1 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/3489410928990023535'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/3489410928990023535'/><link rel='alternate' type='text/html' href='http://fzhong.blogspot.com/2008/04/ejabberd.html' title='ejabberd源码阅读笔记'/><author><name>钟芳林</name><uri>http://www.blogger.com/profile/14620517815530657655</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1316352013241370780.post-3368479026827227492</id><published>2008-03-31T22:07:00.001-07:00</published><updated>2008-03-31T22:07:08.149-07:00</updated><title type='text'>ejabbrd-XML Representation</title><content type='html'>&lt;h4&gt;XML Representation&lt;/h4&gt;  &lt;p&gt;&lt;a name="xmlrepr"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Each XML stanza is represented as the following tuple: &lt;/p&gt;  &lt;pre&gt;XMLElement = {xmlelement, Name, Attrs, [ElementOrCDATA]}&lt;br /&gt;        Name = string()&lt;br /&gt;        Attrs = [Attr]&lt;br /&gt;        Attr = {Key, Val}&lt;br /&gt;        Key = string()&lt;br /&gt;        Val = string()&lt;br /&gt;        ElementOrCDATA = XMLElement | CDATA&lt;br /&gt;        CDATA = {xmlcdata, string()}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;E. g. this stanza: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&amp;lt;message to='test@conference.example.org' type='groupchat'&amp;gt;&lt;br /&gt;  &amp;lt;body&amp;gt;test&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/message&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;is represented as the following structure: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;{xmlelement, &amp;quot;message&amp;quot;,&lt;br /&gt;    [{&amp;quot;to&amp;quot;, &amp;quot;test@conference.example.org&amp;quot;},&lt;br /&gt;     {&amp;quot;type&amp;quot;, &amp;quot;groupchat&amp;quot;}],&lt;br /&gt;    [{xmlelement, &amp;quot;body&amp;quot;,&lt;br /&gt;         [],&lt;br /&gt;         [{xmlcdata, &amp;quot;test&amp;quot;}]}]}}&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1316352013241370780-3368479026827227492?l=fzhong.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://fzhong.blogspot.com/feeds/3368479026827227492/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1316352013241370780&amp;postID=3368479026827227492' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/3368479026827227492'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/3368479026827227492'/><link rel='alternate' type='text/html' href='http://fzhong.blogspot.com/2008/03/ejabbrd-xml-representation.html' title='ejabbrd-XML Representation'/><author><name>钟芳林</name><uri>http://www.blogger.com/profile/14620517815530657655</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1316352013241370780.post-272206671206159858</id><published>2008-03-31T22:06:00.003-07:00</published><updated>2008-03-31T22:08:31.726-07:00</updated><title type='text'>ejabberd源码阅读笔记</title><content type='html'>&lt;h4&gt;ejabberd_sup &lt;/h4&gt;  &lt;p&gt;ejabberd_sup是ejabberd的进程监视者()，由ejabberd_app创建。&lt;/p&gt;  &lt;h5&gt;supervisor(监视进程)&lt;/h5&gt;  &lt;p&gt;&lt;strong&gt;&lt;em&gt;supervisor的功能是启动，停止和监控它的子进程。其作用是保持其子进程运行，在必要的时候重启其子进程，例如子进程死掉的时候。&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;em&gt;A supervisor is responsible for starting, stopping and monitoring its child processes. The basic idea of a supervisor is that it should keep its child processes alive by restarting them when necessary.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;ejabberd_sup负责创建一堆的子进程并监视它们，这些进程有:&lt;/p&gt;  &lt;p&gt;ejabberd_hooks,ejabberd_node_groups,ejabberd_system_monitor,ejabberd_router,ejabberd_sm,ejabberd_s2s,ejabberd_local,&lt;/p&gt;  &lt;p&gt;ejabberd_listener,ejabberd_receiver_sup,ejabberd_c2s_sup,ejabberd_s2s_in_sup,ejabberd_s2s_out_sup,ejabberd_service_sup,&lt;/p&gt;  &lt;p&gt;ejabberd_http_sup,ejabberd_http_poll_sup,ejabberd_frontend_socket_sup,ejabberd_iq_sup,ejabberd_tmp_sup&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;这些进程大部分也是以sup结尾的supervisor监视进程.&lt;/p&gt;  &lt;h4&gt;ejabberd_listener&lt;/h4&gt;  &lt;p&gt;ejabberd_listener是由ejabberd_sup创建的一个supervisor进程，他负责监视和创建一系列的网络端口监听进程。&lt;/p&gt;  &lt;p&gt;ejabberd_listener创建的端口监听进程列表是由配置文件中的listen读取的，配置文件样例如下:&lt;/p&gt;  &lt;p&gt;{listen,    &lt;br /&gt;[     &lt;br /&gt;&amp;#160; {4222, ejabberd_c2s, [     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; %%     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; %% If TLS is compiled and you installed a SSL     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; %% certificate, put the correct path to the     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; %% file and uncomment this line:     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; %%     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; %%{certfile, &amp;quot;/path/to/ssl.pem&amp;quot;}, starttls,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {access, c2s},     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {shaper, c2s_shaper},     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {max_stanza_size, 65536}     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ]}, &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;{5269, ejabberd_s2s_in, [    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {shaper, s2s_shaper},     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {max_stanza_size, 131072}     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ]}, &lt;/p&gt;  &lt;p&gt;{5280, ejabberd_http, [    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; http_poll,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; web_admin,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {request_handlers, [{[&amp;quot;httpbind&amp;quot;], mod_http_bind},{[&amp;quot;pub&amp;quot;, &amp;quot;archive&amp;quot;], mod_http_fileserver}]}     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ]},     &lt;br /&gt;{5347, ejabberd_service, [{host, &amp;quot;msn-transport.bucc.cn&amp;quot;, [{password, &amp;quot;1j5llz!o&amp;quot;}]}]}     &lt;br /&gt;]}. &lt;/p&gt;  &lt;p&gt;每个进程的格式如下,{port_no,module_name,[args]}&lt;/p&gt;  &lt;p&gt;port_no:端口号，同时也是创建进程时的进程标识&lt;/p&gt;  &lt;p&gt;module_name:进程模块名称&lt;/p&gt;  &lt;p&gt;args:参数列表&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h4&gt;ejabberd_receiver&lt;/h4&gt;  &lt;p&gt;ejabberd_receiver是一个gen_server进程(behaviour)，由ejabberd_socket创建&lt;/p&gt;  &lt;h4&gt;xml_stream&lt;/h4&gt;  &lt;h4&gt;ejabber_c2s&lt;/h4&gt;  &lt;p&gt;ejabber_cs2是一个gen_fsm(有限状态机)，维护一系列client和server之间的状态。gen_fsm的状态改变是由gen_fsm:send_event(FsmRef, Event)触发的。在ejabberd里，ejabberd_receiver通过xml_stream把事件和xml发送至ejabber_c2s改变其状态。&lt;/p&gt;  &lt;p&gt;ejabber_c2s有限状态机的初始状态是wait_for_stream,其余的状态有：&lt;/p&gt;  &lt;p&gt;wait_for_auth,wait_for_feature_request,wait_for_sasl_response,wait_for_bind,wait_for_session,session_established&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1316352013241370780-272206671206159858?l=fzhong.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://fzhong.blogspot.com/feeds/272206671206159858/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1316352013241370780&amp;postID=272206671206159858' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/272206671206159858'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/272206671206159858'/><link rel='alternate' type='text/html' href='http://fzhong.blogspot.com/2008/03/ejabberd_31.html' title='ejabberd源码阅读笔记'/><author><name>钟芳林</name><uri>http://www.blogger.com/profile/14620517815530657655</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1316352013241370780.post-6000870264452931965</id><published>2008-03-31T22:06:00.001-07:00</published><updated>2008-03-31T22:06:14.608-07:00</updated><title type='text'>erlang-gen_fsm</title><content type='html'>&lt;h5&gt;MODULE&lt;/h5&gt;  &lt;p&gt;gen_fsm &lt;/p&gt;  &lt;h5&gt;MODULE SUMMARY&lt;/h5&gt;  &lt;p&gt;Generic Finite State Machine Behaviour &lt;/p&gt;  &lt;h5&gt;DESCRIPTION&lt;/h5&gt;  &lt;p&gt;A behaviour module for implementing a finite state machine. A generic finite state machine process (gen_fsm) implemented using this module will have a standard set of interface functions and include functionality for tracing and error reporting. It will also fit into an OTP supervision tree. Refer to &lt;a href="http://www.erlang.org/doc/design_principles/fsm.html"&gt;OTP Design Principles&lt;/a&gt; for more information. &lt;/p&gt;  &lt;p&gt;A gen_fsm assumes all specific parts to be located in a callback module exporting a pre-defined set of functions. The relationship between the behaviour functions and the callback functions can be illustrated as follows: &lt;/p&gt;  &lt;pre&gt;gen_fsm module                    Callback module&lt;br /&gt;--------------                    ---------------&lt;br /&gt;gen_fsm:start_link                -----&amp;gt; Module:init/1&lt;br /&gt;&lt;br /&gt;gen_fsm:send_event                -----&amp;gt; Module:StateName/2&lt;br /&gt;&lt;br /&gt;gen_fsm:send_all_state_event      -----&amp;gt; Module:handle_event/3&lt;br /&gt;&lt;br /&gt;gen_fsm:sync_send_event           -----&amp;gt; Module:StateName/3&lt;br /&gt;&lt;br /&gt;gen_fsm:sync_send_all_state_event -----&amp;gt; Module:handle_sync_event/4&lt;br /&gt;&lt;br /&gt;-                                 -----&amp;gt; Module:handle_info/3&lt;br /&gt;&lt;br /&gt;-                                 -----&amp;gt; Module:terminate/3&lt;br /&gt;&lt;br /&gt;-                                 -----&amp;gt; Module:code_change/4&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If a callback function fails or returns a bad value, the gen_fsm will terminate. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The sys module can be used for debugging a gen_fsm. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Note that a gen_fsm does not trap exit signals automatically, this must be explicitly initiated in the callback module. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Unless otherwise stated, all functions in this module fail if the specified gen_fsm does not exist or if bad arguments are given. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The gen_fsm process can go into hibernation (see &lt;a href="http://www.erlang.org/doc/man/erlang.html#erlang:hibernate-3"&gt;erlang(3)&lt;/a&gt;) if a callback function specifies 'hibernate' instead of a timeout value. This might be useful if the server is expected to be idle for a long time. However this feature should be used with care as hibernation implies at least two garbage collections (when hibernating and shortly after waking up) and is not something you'd want to do between each call to a busy state machine. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;EXPORTS&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="start_link-3"&gt;start_link(Module, Args, Options) -&amp;gt; Result&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;a name="start_link-4"&gt;start_link(FsmName, Module, Args, Options) -&amp;gt; Result&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;FsmName = {local,Name} | {global,GlobalName} &lt;br /&gt;  &lt;br /&gt;Name = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;GlobalName = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Module = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Args = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Options = [Option] &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Option = {debug,Dbgs} | {timeout,Time} | {spawn_opt,SOpts} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; Dbgs = [Dbg] &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160;&amp;#160; Dbg = trace | log | statistics &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; | {log_to_file,FileName} | {install,{Func,FuncState}} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; SOpts = [SOpt] &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160;&amp;#160; SOpt - see erlang:spawn_opt/2,3,4,5 &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Result = {ok,Pid} | ignore | {error,Error} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Pid = pid() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Error = {already_started,Pid} | term() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Creates a gen_fsm process as part of a supervision tree. The function should be called, directly or indirectly, by the supervisor. It will, among other things, ensure that the gen_fsm is linked to the supervisor. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The gen_fsm process calls Module:init/1 to initialize. To ensure a synchronized start-up procedure, start_link/3,4 does not return until Module:init/1 has returned. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If FsmName={local,Name}, the gen_fsm is registered locally as Name using register/2. If FsmName={global,GlobalName}, the gen_fsm is registered globally as GlobalName using global:register_name/2. If no name is provided, the gen_fsm is not registered. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Module is the name of the callback module. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Args is an arbitrary term which is passed as the argument to Module:init/1. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If the option {timeout,Time} is present, the gen_fsm is allowed to spend Time milliseconds initializing or it will be terminated and the start function will return {error,timeout}. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If the option {debug,Dbgs} is present, the corresponding sys function will be called for each item in Dbgs. See &lt;a href="http://www.erlang.org/doc/man/sys.html"&gt;sys(3)&lt;/a&gt;. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If the option {spawn_opt,SOpts} is present, SOpts will be passed as option list to the spawn_opt BIF which is used to spawn the gen_fsm process. See &lt;a href="http://www.erlang.org/doc/man/erlang.html#spawn_opt-2"&gt;erlang(3)&lt;/a&gt;. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Note &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Using the spawn option monitor is currently not allowed, but will cause the function to fail with reason badarg. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If the gen_fsm is successfully created and initialized the function returns {ok,Pid}, where Pid is the pid of the gen_fsm. If there already exists a process with the specified FsmName, the function returns {error,{already_started,Pid}} where Pid is the pid of that process. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If Module:init/1 fails with Reason, the function returns {error,Reason}. If Module:init/1 returns {stop,Reason} or ignore, the process is terminated and the function returns {error,Reason} or ignore, respectively. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="start-3"&gt;start(Module, Args, Options) -&amp;gt; Result&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;a name="start-4"&gt;start(FsmName, Module, Args, Options) -&amp;gt; Result&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;FsmName = {local,Name} | {global,GlobalName} &lt;br /&gt;  &lt;br /&gt;Name = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;GlobalName = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Module = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Args = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Options = [Option] &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Option = {debug,Dbgs} | {timeout,Time} | {spawn_opt,SOpts} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; Dbgs = [Dbg] &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160;&amp;#160; Dbg = trace | log | statistics &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; | {log_to_file,FileName} | {install,{Func,FuncState}} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; SOpts = [term()] &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Result = {ok,Pid} | ignore | {error,Error} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Pid = pid() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Error = {already_started,Pid} | term() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Creates a stand-alone gen_fsm process, i.e. a gen_fsm which is not part of a supervision tree and thus has no supervisor. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;See &lt;a href="http://www.erlang.org/doc/man/gen_fsm.html#start_link-3"&gt;start_link/3,4&lt;/a&gt; for a description of arguments and return values. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="send_event-2"&gt;send_event(FsmRef, Event) -&amp;gt; ok&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;FsmRef = Name | {Name,Node} | {global,GlobalName} | pid() &lt;br /&gt;  &lt;br /&gt;Name = Node = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;GlobalName = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Event = term() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Sends an event asynchronously to the gen_fsm FsmRef and returns ok immediately. The gen_fsm will call Module:StateName/2 to handle the event, where StateName is the name of the current state of the gen_fsm. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;FsmRef can be: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;  &lt;li&gt;the pid, &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;Name, if the gen_fsm is locally registered, &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;{Name,Node}, if the gen_fsm is locally registered at another node, or &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;{global,GlobalName}, if the gen_fsm is globally registered. &lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Event is an arbitrary term which is passed as one of the arguments to Module:StateName/2. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="send_all_state_event-2"&gt;send_all_state_event(FsmRef, Event) -&amp;gt; ok&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;FsmRef = Name | {Name,Node} | {global,GlobalName} | pid() &lt;br /&gt;  &lt;br /&gt;Name = Node = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;GlobalName = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Event = term() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Sends an event asynchronously to the gen_fsm FsmRef and returns ok immediately. The gen_fsm will call Module:handle_event/3 to handle the event. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;See &lt;a href="http://www.erlang.org/doc/man/gen_fsm.html#send_event-2"&gt;send_event/2&lt;/a&gt; for a description of the arguments. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The difference between send_event and send_all_state_event is which callback function is used to handle the event. This function is useful when sending events that are handled the same way in every state, as only one handle_event clause is needed to handle the event instead of one clause in each state name function. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="sync_send_event-2"&gt;sync_send_event(FsmRef, Event) -&amp;gt; Reply&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;a name="sync_send_event-3"&gt;sync_send_event(FsmRef, Event, Timeout) -&amp;gt; Reply&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;FsmRef = Name | {Name,Node} | {global,GlobalName} | pid() &lt;br /&gt;  &lt;br /&gt;Name = Node = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;GlobalName = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Event = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Timeout = int()&amp;gt;0 | infinity &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Reply = term() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Sends an event to the gen_fsm FsmRef and waits until a reply arrives or a timeout occurs. The gen_fsm will call Module:StateName/3 to handle the event, where StateName is the name of the current state of the gen_fsm. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;See &lt;a href="http://www.erlang.org/doc/man/gen_fsm.html#send_event-2"&gt;send_event/2&lt;/a&gt; for a description of FsmRef and Event. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Timeout is an integer greater than zero which specifies how many milliseconds to wait for a reply, or the atom infinity to wait indefinitely. Default value is 5000. If no reply is received within the specified time, the function call fails. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The return value Reply is defined in the return value of Module:StateName/3. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The ancient behaviour of sometimes consuming the server exit message if the server died during the call while linked to the client has been removed in OTP R12B/Erlang 5.6. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="sync_send_all_state_event-2"&gt;sync_send_all_state_event(FsmRef, Event) -&amp;gt; Reply&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;a name="sync_send_all_state_event-3"&gt;sync_send_all_state_event(FsmRef, Event, Timeout) -&amp;gt; Reply&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;FsmRef = Name | {Name,Node} | {global,GlobalName} | pid() &lt;br /&gt;  &lt;br /&gt;Name = Node = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;GlobalName = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Event = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Timeout = int()&amp;gt;0 | infinity &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Reply = term() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Sends an event to the gen_fsm FsmRef and waits until a reply arrives or a timeout occurs. The gen_fsm will call Module:handle_sync_event/4 to handle the event. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;See &lt;a href="http://www.erlang.org/doc/man/gen_fsm.html#send_event-2"&gt;send_event/2&lt;/a&gt; for a description of FsmRef and Event. See &lt;a href="http://www.erlang.org/doc/man/gen_fsm.html#sync_send_event-3"&gt;sync_send_event/3&lt;/a&gt; for a description of Timeout and Reply. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;See &lt;a href="http://www.erlang.org/doc/man/gen_fsm.html#send_all_state_event-2"&gt;send_all_state_event/2&lt;/a&gt; for a discussion about the difference between sync_send_event and sync_send_all_state_event. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="reply-2"&gt;reply(Caller, Reply) -&amp;gt; true&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Caller - see below &lt;br /&gt;  &lt;br /&gt;Reply = term() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This function can be used by a gen_fsm to explicitly send a reply to a client process that called &lt;a href="http://www.erlang.org/doc/man/gen_fsm.html#sync_send_event-2"&gt;sync_send_event/2,3&lt;/a&gt; or &lt;a href="http://www.erlang.org/doc/man/gen_fsm.html#sync_send_all_state_event-2"&gt;sync_send_all_state_event/2,3&lt;/a&gt;, when the reply cannot be defined in the return value of Module:State/3 or Module:handle_sync_event/4. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Caller must be the From argument provided to the callback function. Reply is an arbitrary term, which will be given back to the client as the return value of sync_send_event/2,3 or sync_send_all_state_event/2,3. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="send_event_after-2"&gt;send_event_after(Time, Event) -&amp;gt; Ref&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Time = integer() &lt;br /&gt;  &lt;br /&gt;Event = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Ref = reference() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Sends a delayed event internally in the gen_fsm that calls this function after Time ms. Returns immediately a reference that can be used to cancel the delayed send using &lt;a href="http://www.erlang.org/doc/man/gen_fsm.html#cancel_timer-1"&gt;cancel_timer/1&lt;/a&gt;. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The gen_fsm will call Module:StateName/2 to handle the event, where StateName is the name of the current state of the gen_fsm at the time the delayed event is delivered. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Event is an arbitrary term which is passed as one of the arguments to Module:StateName/2. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="start_timer-2"&gt;start_timer(Time, Msg) -&amp;gt; Ref&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Time = integer() &lt;br /&gt;  &lt;br /&gt;Msg = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Ref = reference() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Sends a timeout event internally in the gen_fsm that calls this function after Time ms. Returns immediately a reference that can be used to cancel the timer using &lt;a href="http://www.erlang.org/doc/man/gen_fsm.html#cancel_timer-1"&gt;cancel_timer/1&lt;/a&gt;. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The gen_fsm will call Module:StateName/2 to handle the event, where StateName is the name of the current state of the gen_fsm at the time the timeout message is delivered. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Msg is an arbitrary term which is passed in the timeout message, {timeout, Ref, Msg}, as one of the arguments to Module:StateName/2. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="cancel_timer-1"&gt;cancel_timer(Ref) -&amp;gt; RemainingTime | false&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Ref = reference() &lt;br /&gt;  &lt;br /&gt;RemainingTime = integer() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Cancels an internal timer referred by Ref in the gen_fsm that calls this function. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Ref is a reference returned from &lt;a href="http://www.erlang.org/doc/man/gen_fsm.html#send_event_after-2"&gt;send_event_after/2&lt;/a&gt; or &lt;a href="http://www.erlang.org/doc/man/gen_fsm.html#start_timer-2"&gt;start_timer/2&lt;/a&gt;. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If the timer has already timed out, but the event not yet been delivered, it is cancelled as if it had &lt;strong&gt;not&lt;/strong&gt; timed out, so there will be no false timer event after returning from this function. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Returns the remaining time in ms until the timer would have expired if Ref referred to an active timer, false otherwise. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="enter_loop-4"&gt;enter_loop(Module, Options, StateName, StateData)&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;a name="enter_loop-5"&gt;enter_loop(Module, Options, StateName, StateData, FsmName)&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;a name="enter_loop-5"&gt;enter_loop(Module, Options, StateName, StateData, Timeout)&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;a name="enter_loop-6"&gt;enter_loop(Module, Options, StateName, StateData, FsmName, Timeout)&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Module = atom() &lt;br /&gt;  &lt;br /&gt;Options = [Option] &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Option = {debug,Dbgs} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; Dbgs = [Dbg] &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160;&amp;#160; Dbg = trace | log | statistics &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; | {log_to_file,FileName} | {install,{Func,FuncState}} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;StateName = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;StateData = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;FsmName = {local,Name} | {global,GlobalName} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Name = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;GlobalName = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Timeout = int() | infinity &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Makes an existing process into a gen_fsm. Does not return, instead the calling process will enter the gen_fsm receive loop and become a gen_fsm process. The process &lt;strong&gt;must&lt;/strong&gt; have been started using one of the start functions in proc_lib, see &lt;a href="http://www.erlang.org/doc/man/proc_lib.html"&gt;proc_lib(3)&lt;/a&gt;. The user is responsible for any initialization of the process, including registering a name for it. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This function is useful when a more complex initialization procedure is needed than the gen_fsm behaviour provides. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Module, Options and FsmName have the same meanings as when calling &lt;a href="http://www.erlang.org/doc/man/gen_fsm.html#start_link-3"&gt;start[_link]/3,4&lt;/a&gt;. However, if FsmName is specified, the process must have been registered accordingly &lt;strong&gt;before&lt;/strong&gt; this function is called. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;StateName, StateData and Timeout have the same meanings as in the return value of &lt;a href="http://www.erlang.org/doc/man/gen_fsm.html#Moduleinit"&gt;Module:init/1&lt;/a&gt;. Also, the callback module Module does not need to export an init/1 function. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Failure: If the calling process was not started by a proc_lib start function, or if it is not registered according to FsmName. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;CALLBACK FUNCTIONS&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The following functions should be exported from a gen_fsm callback module. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;In the description, the expression &lt;strong&gt;state name&lt;/strong&gt; is used to denote a state of the state machine. &lt;strong&gt;state data&lt;/strong&gt; is used to denote the internal state of the Erlang process which implements the state machine. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;EXPORTS&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="Module:init-1"&gt;Module:init(Args) -&amp;gt; Result&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Args = term() &lt;br /&gt;  &lt;br /&gt;Return = {ok,StateName,StateData} | {ok,StateName,StateData,Timeout} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; | {ok,StateName,StateData,hibernate} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; | {stop,Reason} | ignore &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;StateName = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;StateData = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Timeout = int()&amp;gt;0 | infinity &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Reason = term() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="Moduleinit"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Whenever a gen_fsm is started using &lt;a href="http://www.erlang.org/doc/man/gen_fsm.html#start-3"&gt;gen_fsm:start/3,4&lt;/a&gt; or &lt;a href="http://www.erlang.org/doc/man/gen_fsm.html#start_link-3"&gt;gen_fsm:start_link/3,4&lt;/a&gt;, this function is called by the new process to initialize. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Args is the Args argument provided to the start function. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If initialization is successful, the function should return {ok,StateName,StateData}, {ok,StateName,StateData,Timeout} or {ok,StateName,StateData,hibernate}, where StateName is the initial state name and StateData the initial state data of the gen_fsm. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If an integer timeout value is provided, a timeout will occur unless an event or a message is received within Timeout milliseconds. A timeout is represented by the atom timeout and should be handled by the Module:StateName/2 callback functions. The atom infinity can be used to wait indefinitely, this is the default value. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If hibernate is specified instead of a timeout value, the process will go into hibernation when waiting for the next message to arrive (by calling &lt;a href="http://www.erlang.org/doc/man/proc_lib.html#hibernate-3"&gt;proc_lib:hibernate/3&lt;/a&gt;). &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If something goes wrong during the initialization the function should return {stop,Reason}, where Reason is any term, or ignore. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="Module:StateName-2"&gt;Module:StateName(Event, StateData) -&amp;gt; Result&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Event = timeout | term() &lt;br /&gt;  &lt;br /&gt;StateData = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Result = {next_state,NextStateName,NewStateData} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; | {next_state,NextStateName,NewStateData,Timeout} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; | {next_state,NextStateName,NewStateData,hibernate} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; | {stop,Reason,NewStateData} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;NextStateName = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;NewStateData = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Timeout = int()&amp;gt;0 | infinity &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Reason = term() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;There should be one instance of this function for each possible state name. Whenever a gen_fsm receives an event sent using &lt;a href="http://www.erlang.org/doc/man/gen_fsm.html#send_event-2"&gt;gen_fsm:send_event/2&lt;/a&gt;, the instance of this function with the same name as the current state name StateName is called to handle the event. It is also called if a timeout occurs. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Event is either the atom timeout, if a timeout has occurred, or the Event argument provided to send_event/2. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;StateData is the state data of the gen_fsm. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If the function returns {next_state,NextStateName,NewStateData}, {next_state,NextStateName,NewStateData,Timeout} or {next_state,NextStateName,NewStateData,hibernate}, the gen_fsm will continue executing with the current state name set to NextStateName and with the possibly updated state data NewStateData. See Module:init/1 for a description of Timeout and hibernate. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If the function returns {stop,Reason,NewStateData}, the gen_fsm will call Module:terminate(Reason,NewStateData) and terminate. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="Module:handle_event-3"&gt;Module:handle_event(Event, StateName, StateData) -&amp;gt; Result&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Event = term() &lt;br /&gt;  &lt;br /&gt;StateName = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;StateData = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Result = {next_state,NextStateName,NewStateData} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; | {next_state,NextStateName,NewStateData,Timeout} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; | {next_state,NextStateName,NewStateData,hibernate} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; | {stop,Reason,NewStateData} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;NextStateName = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;NewStateData = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Timeout = int()&amp;gt;0 | infinity &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Reason = term() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Whenever a gen_fsm receives an event sent using &lt;a href="http://www.erlang.org/doc/man/gen_fsm.html#send_all_state_event-2"&gt;gen_fsm:send_all_state_event/2&lt;/a&gt;, this function is called to handle the event. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;StateName is the current state name of the gen_fsm. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;See Module:StateName/2 for a description of the other arguments and possible return values. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="Module:StateName-3"&gt;Module:StateName(Event, From, StateData) -&amp;gt; Result&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Event = term() &lt;br /&gt;  &lt;br /&gt;From = {pid(),Tag} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;StateData = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Result = {reply,Reply,NextStateName,NewStateData} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; | {reply,Reply,NextStateName,NewStateData,Timeout} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; | {reply,Reply,NextStateName,NewStateData,hibernate} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; | {next_state,NextStateName,NewStateData} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; | {next_state,NextStateName,NewStateData,Timeout} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; | {next_state,NextStateName,NewStateData,hibernate} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; | {stop,Reason,Reply,NewStateData} | {stop,Reason,NewStateData} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Reply = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;NextStateName = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;NewStateData = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Timeout = int()&amp;gt;0 | infinity &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Reason = normal | term() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;There should be one instance of this function for each possible state name. Whenever a gen_fsm receives an event sent using &lt;a href="http://www.erlang.org/doc/man/gen_fsm.html#sync_send_event-2"&gt;gen_fsm:sync_send_event/2,3&lt;/a&gt;, the instance of this function with the same name as the current state name StateName is called to handle the event. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Event is the Event argument provided to sync_send_event. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;From is a tuple {Pid,Tag} where Pid is the pid of the process which called sync_send_event/2,3 and Tag is a unique tag. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;StateData is the state data of the gen_fsm. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If the function returns {reply,Reply,NextStateName,NewStateData}, {reply,Reply,NextStateName,NewStateData,Timeout} or {reply,Reply,NextStateName,NewStateData,hibernate}, Reply will be given back to From as the return value of sync_send_event/2,3. The gen_fsm then continues executing with the current state name set to NextStateName and with the possibly updated state data NewStateData. See Module:init/1 for a description of Timeout and hibernate. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If the function returns {next_state,NextStateName,NewStateData}, {next_state,NextStateName,NewStateData,Timeout} or {next_state,NextStateName,NewStateData,hibernate}, the gen_fsm will continue executing in NextStateName with NewStateData. Any reply to From must be given explicitly using &lt;a href="http://www.erlang.org/doc/man/gen_fsm.html#reply-2"&gt;gen_fsm:reply/2&lt;/a&gt;. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If the function returns {stop,Reason,Reply,NewStateData}, Reply will be given back to From. If the function returns {stop,Reason,NewStateData}, any reply to From must be given explicitly using gen_fsm:reply/2. The gen_fsm will then call Module:terminate(Reason,NewStateData) and terminate. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="Module:handle_sync_event-4"&gt;Module:handle_sync_event(Event, From, StateName, StateData) -&amp;gt; Result&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Event = term() &lt;br /&gt;  &lt;br /&gt;From = {pid(),Tag} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;StateName = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;StateData = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Result = {reply,Reply,NextStateName,NewStateData} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; | {reply,Reply,NextStateName,NewStateData,Timeout} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; | {reply,Reply,NextStateName,NewStateData,hibernate} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; | {next_state,NextStateName,NewStateData} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; | {next_state,NextStateName,NewStateData,Timeout} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; | {next_state,NextStateName,NewStateData,hibernate} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; | {stop,Reason,Reply,NewStateData} | {stop,Reason,NewStateData} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Reply = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;NextStateName = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;NewStateData = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Timeout = int()&amp;gt;0 | infinity &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Reason = term() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Whenever a gen_fsm receives an event sent using &lt;a href="http://www.erlang.org/doc/man/gen_fsm.html#sync_send_all_state_event-2"&gt;gen_fsm:sync_send_all_state_event/2,3&lt;/a&gt;, this function is called to handle the event. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;StateName is the current state name of the gen_fsm. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;See Module:StateName/3 for a description of the other arguments and possible return values. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="Module:handle_info-3"&gt;Module:handle_info(Info, StateName, StateData) -&amp;gt; Result&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Info = term() &lt;br /&gt;  &lt;br /&gt;StateName = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;StateData = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Result = {next_state,NextStateName,NewStateData} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;gt; | {next_state,NextStateName,NewStateData,Timeout} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;gt; | {next_state,NextStateName,NewStateData,hibernate} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;gt; | {stop,Reason,NewStateData} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;NextStateName = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;NewStateData = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Timeout = int()&amp;gt;0 | infinity &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Reason = normal | term() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This function is called by a gen_fsm when it receives any other message than a synchronous or asynchronous event (or a system message). &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Info is the received message. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;See Module:StateName/2 for a description of the other arguments and possible return values. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="Module:terminate-3"&gt;Module:terminate(Reason, StateName, StateData)&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Reason = normal | shutdown | term() &lt;br /&gt;  &lt;br /&gt;StateName = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;StateData = term() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This function is called by a gen_fsm when it is about to terminate. It should be the opposite of Module:init/1 and do any necessary cleaning up. When it returns, the gen_fsm terminates with Reason. The return value is ignored. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Reason is a term denoting the stop reason, StateName is the current state name, and StateData is the state data of the gen_fsm. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Reason depends on why the gen_fsm is terminating. If it is because another callback function has returned a stop tuple {stop,..}, Reason will have the value specified in that tuple. If it is due to a failure, Reason is the error reason. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If the gen_fsm is part of a supervision tree and is ordered by its supervisor to terminate, this function will be called with Reason=shutdown if the following conditions apply: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;  &lt;li&gt;the gen_fsm has been set to trap exit signals, and &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;the shutdown strategy as defined in the supervisor's child specification is an integer timeout value, not brutal_kill. &lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Otherwise, the gen_fsm will be immediately terminated. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Note that for any other reason than normal or shutdown, the gen_fsm is assumed to terminate due to an error and an error report is issued using &lt;a href="http://www.erlang.org/doc/man/error_logger.html#format-2"&gt;error_logger:format/2&lt;/a&gt;. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="Module:code_change-4"&gt;Module:code_change(OldVsn, StateName, StateData, Extra) -&amp;gt; {ok, NextStateName, NewStateData}&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;OldVsn = Vsn | {down, Vsn} &lt;br /&gt;  &lt;br /&gt;&amp;#160; Vsn = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;StateName = NextStateName = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;StateData = NewStateData = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Extra = term() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This function is called by a gen_fsm when it should update its internal state data during a release upgrade/downgrade, i.e. when the instruction {update,Module,Change,...} where Change={advanced,Extra} is given in the appup file. See &lt;a href="http://www.erlang.org/doc/design_principles/release_handling.html#instr"&gt;OTP Design Principles&lt;/a&gt;. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;In the case of an upgrade, OldVsn is Vsn, and in the case of a downgrade, OldVsn is {down,Vsn}. Vsn is defined by the vsn attribute(s) of the old version of the callback module Module. If no such attribute is defined, the version is the checksum of the BEAM file. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;StateName is the current state name and StateData the internal state data of the gen_fsm. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Extra is passed as-is from the {advanced,Extra} part of the update instruction. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The function should return the new current state name and updated internal data. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1316352013241370780-6000870264452931965?l=fzhong.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://fzhong.blogspot.com/feeds/6000870264452931965/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1316352013241370780&amp;postID=6000870264452931965' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/6000870264452931965'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/6000870264452931965'/><link rel='alternate' type='text/html' href='http://fzhong.blogspot.com/2008/03/erlang-genfsm.html' title='erlang-gen_fsm'/><author><name>钟芳林</name><uri>http://www.blogger.com/profile/14620517815530657655</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1316352013241370780.post-8502064084479264317</id><published>2008-03-31T22:05:00.001-07:00</published><updated>2008-03-31T22:05:06.760-07:00</updated><title type='text'>gen_server</title><content type='html'>&lt;h5&gt;MODULE&lt;/h5&gt;  &lt;p&gt;gen_server &lt;/p&gt;  &lt;h5&gt;MODULE SUMMARY&lt;/h5&gt;  &lt;p&gt;Generic Server Behaviour &lt;/p&gt;  &lt;h5&gt;DESCRIPTION&lt;/h5&gt;  &lt;p&gt;A behaviour module for implementing the server of a client-server relation. A generic server process (gen_server) implemented using this module will have a standard set of interface functions and include functionality for tracing and error reporting. It will also fit into an OTP supervision tree. Refer to &lt;a href="http://www.erlang.org/doc/design_principles/gen_server_concepts.html"&gt;OTP Design Principles&lt;/a&gt; for more information. &lt;/p&gt;  &lt;p&gt;A gen_server assumes all specific parts to be located in a callback module exporting a pre-defined set of functions. The relationship between the behaviour functions and the callback functions can be illustrated as follows: &lt;/p&gt;  &lt;pre&gt;gen_server module            Callback module&lt;br /&gt;-----------------            ---------------&lt;br /&gt;gen_server:start_link -----&amp;gt; Module:init/1&lt;br /&gt;&lt;br /&gt;gen_server:call&lt;br /&gt;gen_server:multi_call -----&amp;gt; Module:handle_call/3&lt;br /&gt;&lt;br /&gt;gen_server:cast&lt;br /&gt;gen_server:abcast     -----&amp;gt; Module:handle_cast/2&lt;br /&gt;&lt;br /&gt;-                     -----&amp;gt; Module:handle_info/2&lt;br /&gt;&lt;br /&gt;-                     -----&amp;gt; Module:terminate/2&lt;br /&gt;&lt;br /&gt;-                     -----&amp;gt; Module:code_change/3    &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If a callback function fails or returns a bad value, the gen_server will terminate. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The sys module can be used for debugging a gen_server. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Note that a gen_server does not trap exit signals automatically, this must be explicitly initiated in the callback module. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Unless otherwise stated, all functions in this module fail if the specified gen_server does not exist or if bad arguments are given. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The gen_server process can go into hibernation (see &lt;a href="http://www.erlang.org/doc/man/erlang.html#erlang:hibernate-3"&gt;erlang(3)&lt;/a&gt;) if a callback function specifies 'hibernate' instead of a timeout value. This might be useful if the server is expected to be idle for a long time. However this feature should be used with care as hibernation implies at least two garbage collections (when hibernating and shortly after waking up) and is not something you'd want to do between each call to a busy server. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;EXPORTS&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="start_link-3"&gt;start_link(Module, Args, Options) -&amp;gt; Result&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;a name="start_link-4"&gt;start_link(ServerName, Module, Args, Options) -&amp;gt; Result&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;ServerName = {local,Name} | {global,GlobalName} &lt;br /&gt;  &lt;br /&gt;Name = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;GlobalName = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Module = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Args = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Options = [Option] &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Option = {debug,Dbgs} | {timeout,Time} | {spawn_opt,SOpts} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; Dbgs = [Dbg] &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160;&amp;#160; Dbg = trace | log | statistics | {log_to_file,FileName} | {install,{Func,FuncState}} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; SOpts = [term()] &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Result = {ok,Pid} | ignore | {error,Error} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Pid = pid() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Error = {already_started,Pid} | term() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Creates a gen_server process as part of a supervision tree. The function should be called, directly or indirectly, by the supervisor. It will, among other things, ensure that the gen_server is linked to the supervisor. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The gen_server process calls Module:init/1 to initialize. To ensure a synchronized start-up procedure, start_link/3,4 does not return until Module:init/1 has returned. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If ServerName={local,Name} the gen_server is registered locally as Name using register/2. If ServerName={global,GlobalName} the gen_server is registered globally as GlobalName using global:register_name/2. If no name is provided, the gen_server is not registered. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Module is the name of the callback module. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Args is an arbitrary term which is passed as the argument to Module:init/1. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If the option {timeout,Time} is present, the gen_server is allowed to spend Time milliseconds initializing or it will be terminated and the start function will return {error,timeout}. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If the option {debug,Dbgs} is present, the corresponding sys function will be called for each item in Dbgs. See &lt;a href="http://www.erlang.org/doc/man/sys.html"&gt;sys(3)&lt;/a&gt;. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If the option {spawn_opt,SOpts} is present, SOpts will be passed as option list to the spawn_opt BIF which is used to spawn the gen_server. See &lt;a href="http://www.erlang.org/doc/man/erlang.html#spawn_opt-2"&gt;erlang(3)&lt;/a&gt;. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Note &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Using the spawn option monitor is currently not allowed, but will cause the function to fail with reason badarg. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If the gen_server is successfully created and initialized the function returns {ok,Pid}, where Pid is the pid of the gen_server. If there already exists a process with the specified ServerName the function returns {error,{already_started,Pid}}, where Pid is the pid of that process. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If Module:init/1 fails with Reason, the function returns {error,Reason}. If Module:init/1 returns {stop,Reason} or ignore, the process is terminated and the function returns {error,Reason} or ignore, respectively. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="start-3"&gt;start(Module, Args, Options) -&amp;gt; Result&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;a name="start-4"&gt;start(ServerName, Module, Args, Options) -&amp;gt; Result&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;ServerName = {local,Name} | {global,GlobalName} &lt;br /&gt;  &lt;br /&gt;Name = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;GlobalName = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Module = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Args = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Options = [Option] &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Option = {debug,Dbgs} | {timeout,Time} | {spawn_opt,SOpts} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; Dbgs = [Dbg] &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160;&amp;#160; Dbg = trace | log | statistics | {log_to_file,FileName} | {install,{Func,FuncState}} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; SOpts = [term()] &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Result = {ok,Pid} | ignore | {error,Error} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Pid = pid() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Error = {already_started,Pid} | term() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Creates a stand-alone gen_server process, i.e. a gen_server which is not part of a supervision tree and thus has no supervisor. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;See &lt;a href="http://www.erlang.org/doc/man/gen_server.html#start_link-3"&gt;start_link/3,4&lt;/a&gt; for a description of arguments and return values. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="call-2"&gt;call(ServerRef, Request) -&amp;gt; Reply&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;a name="call-3"&gt;call(ServerRef, Request, Timeout) -&amp;gt; Reply&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;ServerRef = Name | {Name,Node} | {global,GlobalName} | pid() &lt;br /&gt;  &lt;br /&gt;Node = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;GlobalName = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Request = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Timeout = int()&amp;gt;0 | infinity &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Reply = term() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Makes a synchronous call to the gen_server ServerRef by sending a request and waiting until a reply arrives or a timeout occurs. The gen_server will call Module:handle_call/3 to handle the request. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;ServerRef can be: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;  &lt;li&gt;the pid, &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;Name, if the gen_server is locally registered, &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;{Name,Node}, if the gen_server is locally registered at another node, or &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;{global,GlobalName}, if the gen_server is globally registered. &lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Request is an arbitrary term which is passed as one of the arguments to Module:handle_call/3. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Timeout is an integer greater than zero which specifies how many milliseconds to wait for a reply, or the atom infinity to wait indefinitely. Default value is 5000. If no reply is received within the specified time, the function call fails. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The return value Reply is defined in the return value of Module:handle_call/3. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The call may fail for several reasons, including timeout and the called gen_server dying before or during the call. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The ancient behaviour of sometimes consuming the server exit message if the server died during the call while linked to the client has been removed in OTP R12B/Erlang 5.6. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="multi_call-2"&gt;multi_call(Name, Request) -&amp;gt; Result&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;a name="multi_call-3"&gt;multi_call(Nodes, Name, Request) -&amp;gt; Result&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;a name="multi_call-4"&gt;multi_call(Nodes, Name, Request, Timeout) -&amp;gt; Result&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Nodes = [Node] &lt;br /&gt;  &lt;br /&gt;Node = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Name = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Request = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Timeout = int()&amp;gt;=0 | infinity &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Result = {Replies,BadNodes} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Replies = [{Node,Reply}] &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; Reply = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;BadNodes = [Node] &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Makes a synchronous call to all gen_servers locally registered as Name at the specified nodes by first sending a request to every node and then waiting for the replies. The gen_servers will call Module:handle_call/3 to handle the request. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The function returns a tuple {Replies,BadNodes} where Replies is a list of {Node,Reply} and BadNodes is a list of node that either did not exist, or where the gen_server Name did not exist or did not reply. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Nodes is a list of node names to which the request should be sent. Default value is the list of all known nodes [node()|nodes()]. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Name is the locally registered name of each gen_server. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Request is an arbitrary term which is passed as one of the arguments to Module:handle_call/3. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Timeout is an integer greater than zero which specifies how many milliseconds to wait for each reply, or the atom infinity to wait indefinitely. Default value is infinity. If no reply is received from a node within the specified time, the node is added to BadNodes. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;When a reply Reply is received from the gen_server at a node Node, {Node,Reply} is added to Replies. Reply is defined in the return value of Module:handle_call/3. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Warning &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If one of the nodes is not capable of process monitors, for example C or Java nodes, and the gen_server is not started when the requests are sent, but starts within 2 seconds, this function waits the whole Timeout, which may be infinity. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This problem does not exist if all nodes are Erlang nodes. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;To avoid that late answers (after the timeout) pollutes the caller's message queue, a middleman process is used to do the actual calls. Late answers will then be discarded when they arrive to a terminated process. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="cast-2"&gt;cast(ServerRef, Request) -&amp;gt; ok&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;ServerRef = Name | {Name,Node} | {global,GlobalName} | pid() &lt;br /&gt;  &lt;br /&gt;Node = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;GlobalName = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Request = term() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Sends an asynchronous request to the gen_server ServerRef and returns ok immediately, ignoring if the destination node or gen_server does not exist. The gen_server will call Module:handle_cast/2 to handle the request. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;See &lt;a href="http://www.erlang.org/doc/man/gen_server.html#call-2"&gt;call/2,3&lt;/a&gt; for a description of ServerRef. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Request is an arbitrary term which is passed as one of the arguments to Module:handle_cast/2. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="abcast-2"&gt;abcast(Name, Request) -&amp;gt; abcast&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;a name="abcast-3"&gt;abcast(Nodes, Name, Request) -&amp;gt; abcast&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Nodes = [Node] &lt;br /&gt;  &lt;br /&gt;Node = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Name = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Request = term() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Sends an asynchronous request to the gen_servers locally registered as Name at the specified nodes. The function returns immediately and ignores nodes that do not exist, or where the gen_server Name does not exist. The gen_servers will call Module:handle_cast/2 to handle the request. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;See &lt;a href="http://www.erlang.org/doc/man/gen_server.html#multi_call-2"&gt;multi_call/2,3,4&lt;/a&gt; for a description of the arguments. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="reply-2"&gt;reply(Client, Reply) -&amp;gt; Result&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Client - see below &lt;br /&gt;  &lt;br /&gt;Reply = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Result = term() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This function can be used by a gen_server to explicitly send a reply to a client that called call/2,3 or multi_call/2,3,4, when the reply cannot be defined in the return value of Module:handle_call/3. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Client must be the From argument provided to the callback function. Reply is an arbitrary term, which will be given back to the client as the return value of call/2,3 or multi_call/2,3,4. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The return value Result is not further defined, and should always be ignored. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="enter_loop-3"&gt;enter_loop(Module, Options, State)&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;a name="enter_loop-4"&gt;enter_loop(Module, Options, State, ServerName)&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;a name="enter_loop-4"&gt;enter_loop(Module, Options, State, Timeout)&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;a name="enter_loop-5"&gt;enter_loop(Module, Options, State, ServerName, Timeout)&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Module = atom() &lt;br /&gt;  &lt;br /&gt;Options = [Option] &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Option = {debug,Dbgs} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; Dbgs = [Dbg] &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160;&amp;#160; Dbg = trace | log | statistics &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; | {log_to_file,FileName} | {install,{Func,FuncState}} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;State = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;ServerName = {local,Name} | {global,GlobalName} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Name = atom() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;GlobalName = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Timeout = int() | infinity &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Makes an existing process into a gen_server. Does not return, instead the calling process will enter the gen_server receive loop and become a gen_server process. The process &lt;strong&gt;must&lt;/strong&gt; have been started using one of the start functions in proc_lib, see &lt;a href="http://www.erlang.org/doc/man/proc_lib.html"&gt;proc_lib(3)&lt;/a&gt;. The user is responsible for any initialization of the process, including registering a name for it. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This function is useful when a more complex initialization procedure is needed than the gen_server behaviour provides. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Module, Options and ServerName have the same meanings as when calling &lt;a href="http://www.erlang.org/doc/man/gen_server.html#start_link-3"&gt;gen_server:start[_link]/3,4&lt;/a&gt;. However, if ServerName is specified, the process must have been registered accordingly &lt;strong&gt;before&lt;/strong&gt; this function is called. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;State and Timeout have the same meanings as in the return value of &lt;a href="http://www.erlang.org/doc/man/gen_server.html#Moduleinit"&gt;Module:init/1&lt;/a&gt;. Also, the callback module Module does not need to export an init/1 function. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Failure: If the calling process was not started by a proc_lib start function, or if it is not registered according to ServerName. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;CALLBACK FUNCTIONS&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The following functions should be exported from a gen_server callback module. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;EXPORTS&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="Module:init-1"&gt;Module:init(Args) -&amp;gt; Result&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Args = term() &lt;br /&gt;  &lt;br /&gt;Result = {ok,State} | {ok,State,Timeout} | {ok,State,hibernate} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;| {stop,Reason} | ignore &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;State = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Timeout = int()&amp;gt;=0 | infinity &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Reason = term() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="Moduleinit"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Whenever a gen_server is started using &lt;a href="http://www.erlang.org/doc/man/gen_server.html#start-3"&gt;gen_server:start/3,4&lt;/a&gt; or &lt;a href="http://www.erlang.org/doc/man/gen_server.html#start_link-3"&gt;gen_server:start_link/3,4&lt;/a&gt;, this function is called by the new process to initialize. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Args is the Args argument provided to the start function. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If the initialization is successful, the function should return {ok,State}, {ok,State,Timeout} or {ok,State,hibernate}, where State is the internal state of the gen_server. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If an integer timeout value is provided, a timeout will occur unless a request or a message is received within Timeout milliseconds. A timeout is represented by the atom timeout which should be handled by the handle_info/2 callback function. The atom infinity can be used to wait indefinitely, this is the default value. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If hibernate is specified instead of a timeout value, the process will go into hibernation when waiting for the next message to arrive (by calling &lt;a href="http://www.erlang.org/doc/man/proc_lib.html#hibernate-3"&gt;proc_lib:hibernate/3&lt;/a&gt;). &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If something goes wrong during the initialization the function should return {stop,Reason} where Reason is any term, or ignore. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="Module:handle_call-3"&gt;Module:handle_call(Request, From, State) -&amp;gt; Result&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Request = term() &lt;br /&gt;  &lt;br /&gt;From = {pid(),Tag} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;State = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Result = {reply,Reply,NewState} | {reply,Reply,NewState,Timeout} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; | {reply,Reply,NewState,hibernate} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; | {noreply,NewState} | {noreply,NewState,Timeout} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; | {noreply,NewState,hibernate} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; | {stop,Reason,Reply,NewState} | {stop,Reason,NewState} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Reply = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;NewState = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Timeout = int()&amp;gt;=0 | infinity &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Reason = term() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Whenever a gen_server receives a request sent using &lt;a href="http://www.erlang.org/doc/man/gen_server.html#call-2"&gt;gen_server:call/2,3&lt;/a&gt; or &lt;a href="http://www.erlang.org/doc/man/gen_server.html#multi_call-2"&gt;gen_server:multi_call/2,3,4&lt;/a&gt;, this function is called to handle the request. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Request is the Request argument provided to call or multi_call. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;From is a tuple {Pid,Tag} where Pid is the pid of the client and Tag is a unique tag. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;State is the internal state of the gen_server. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If the function returns {reply,Reply,NewState}, {reply,Reply,NewState,Timeout} or {reply,Reply,NewState,hibernate}, Reply will be given back to From as the return value of call/2,3 or included in the return value of multi_call/2,3,4. The gen_server then continues executing with the possibly updated internal state NewState. See Module:init/1 for a description of Timeout and hibernate. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If the functions returns {noreply,NewState}, {noreply,NewState,Timeout} or {noreply,NewState,hibernate}, the gen_server will continue executing with NewState. Any reply to From must be given explicitly using &lt;a href="http://www.erlang.org/doc/man/gen_server.html#reply-2"&gt;gen_server:reply/2&lt;/a&gt;. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If the function returns {stop,Reason,Reply,NewState}, Reply will be given back to From. If the function returns {stop,Reason,NewState}, any reply to From must be given explicitly using gen_server:reply/2. The gen_server will then call Module:terminate(Reason,NewState) and terminate. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="Module:handle_cast-2"&gt;Module:handle_cast(Request, State) -&amp;gt; Result&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Request = term() &lt;br /&gt;  &lt;br /&gt;State = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Result = {noreply,NewState} | {noreply,NewState,Timeout} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; | {noreply,NewState,hibernate} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; | {stop,Reason,NewState} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;NewState = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Timeout = int()&amp;gt;=0 | infinity &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Reason = term() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Whenever a gen_server receives a request sent using &lt;a href="http://www.erlang.org/doc/man/gen_server.html#cast-2"&gt;gen_server:cast/2&lt;/a&gt; or &lt;a href="http://www.erlang.org/doc/man/gen_server.html#abcast-2"&gt;gen_server:abcast/2,3&lt;/a&gt;, this function is called to handle the request. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;See Module:handle_call/3 for a description of the arguments and possible return values. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="Module:handle_info-2"&gt;Module:handle_info(Info, State) -&amp;gt; Result&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Info = timeout | term() &lt;br /&gt;  &lt;br /&gt;State = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Result = {noreply,NewState} | {noreply,NewState,Timeout} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; | {noreply,NewState,hibernate} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;#160; | {stop,Reason,NewState} &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;NewState = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Timeout = int()&amp;gt;=0 | infinity &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Reason = normal | term() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This function is called by a gen_server when a timeout occurs or when it receives any other message than a synchronous or asynchronous request (or a system message). &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Info is either the atom timeout, if a timeout has occurred, or the received message. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;See Module:handle_call/3 for a description of the other arguments and possible return values. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="Module:terminate-2"&gt;Module:terminate(Reason, State)&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Reason = normal | shutdown | term() &lt;br /&gt;  &lt;br /&gt;State = term() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This function is called by a gen_server when it is about to terminate. It should be the opposite of Module:init/1 and do any necessary cleaning up. When it returns, the gen_server terminates with Reason. The return value is ignored. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Reason is a term denoting the stop reason and State is the internal state of the gen_server. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Reason depends on why the gen_server is terminating. If it is because another callback function has returned a stop tuple {stop,..}, Reason will have the value specified in that tuple. If it is due to a failure, Reason is the error reason. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If the gen_server is part of a supervision tree and is ordered by its supervisor to terminate, this function will be called with Reason=shutdown if the following conditions apply: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;  &lt;li&gt;the gen_server has been set to trap exit signals, and &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;the shutdown strategy as defined in the supervisor's child specification is an integer timeout value, not brutal_kill. &lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Otherwise, the gen_server will be immediately terminated. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Note that for any other reason than normal or shutdown, the gen_server is assumed to terminate due to an error and an error report is issued using &lt;a href="http://www.erlang.org/doc/man/error_logger.html#format-2"&gt;error_logger:format/2&lt;/a&gt;. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="Module:code_change-3"&gt;Module:code_change(OldVsn, State, Extra) -&amp;gt; {ok, NewState}&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Types: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;OldVsn = Vsn | {down, Vsn} &lt;br /&gt;  &lt;br /&gt;&amp;#160; Vsn = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;State = NewState = term() &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;Extra = term() &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This function is called by a gen_server when it should update its internal state during a release upgrade/downgrade, i.e. when the instruction {update,Module,Change,...} where Change={advanced,Extra} is given in the appup file. See &lt;a href="http://www.erlang.org/doc/design_principles/release_handling.html#instr"&gt;OTP Design Principles&lt;/a&gt; for more information. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;In the case of an upgrade, OldVsn is Vsn, and in the case of a downgrade, OldVsn is {down,Vsn}. Vsn is defined by the vsn attribute(s) of the old version of the callback module Module. If no such attribute is defined, the version is the checksum of the BEAM file. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;State is the internal state of the gen_server. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Extra is passed as-is from the {advanced,Extra} part of the update instruction. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The function should return the updated internal state. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1316352013241370780-8502064084479264317?l=fzhong.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://fzhong.blogspot.com/feeds/8502064084479264317/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1316352013241370780&amp;postID=8502064084479264317' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/8502064084479264317'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/8502064084479264317'/><link rel='alternate' type='text/html' href='http://fzhong.blogspot.com/2008/03/genserver.html' title='gen_server'/><author><name>钟芳林</name><uri>http://www.blogger.com/profile/14620517815530657655</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1316352013241370780.post-3974804662031711281</id><published>2008-03-31T22:04:00.005-07:00</published><updated>2008-03-31T22:04:45.372-07:00</updated><title type='text'>erlang-Supervisor Behaviour</title><content type='html'>&lt;h4&gt;Supervisor Behaviour&lt;/h4&gt;  &lt;p&gt;This section should be read in conjunction with supervisor(3), where all details about the supervisor behaviour is given. &lt;/p&gt;  &lt;p&gt;&lt;a name="5.1"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h5&gt;5.1 Supervision Principles&lt;/h5&gt;  &lt;p&gt;A supervisor is responsible for starting, stopping and monitoring its child processes. The basic idea of a supervisor is that it should keep its child processes alive by restarting them when necessary. &lt;/p&gt;  &lt;p&gt;Which child processes to start and monitor is specified by a list of &lt;a href="http://www.erlang.org/doc/design_principles/sup_princ.html#spec"&gt;child specifications&lt;/a&gt;. The child processes are started in the order specified by this list, and terminated in the reversed order. &lt;/p&gt;  &lt;p&gt;&lt;a name="5.2"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h5&gt;5.2 Example&lt;/h5&gt;  &lt;p&gt;The callback module for a supervisor starting the server from the &lt;a href="http://www.erlang.org/doc/design_principles/gen_server_concepts.html#ex"&gt;gen_server chapter&lt;/a&gt; could look like this: &lt;/p&gt;  &lt;p&gt;&lt;a name="ex"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;pre&gt;-module(ch_sup).&lt;br /&gt;-behaviour(supervisor).&lt;br /&gt;&lt;br /&gt;-export([start_link/0]).&lt;br /&gt;-export([init/1]).&lt;br /&gt;&lt;br /&gt;start_link() -&amp;gt;&lt;br /&gt;    supervisor:start_link(ch_sup, []).&lt;br /&gt;&lt;br /&gt;init(_Args) -&amp;gt;&lt;br /&gt;    {ok, {{one_for_one, 1, 60},&lt;br /&gt;          [{ch3, {ch3, start_link, []},&lt;br /&gt;            permanent, brutal_kill, worker, [ch3]}]}}.&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;one_for_one is the &lt;a href="http://www.erlang.org/doc/design_principles/sup_princ.html#strategy"&gt;restart strategy&lt;/a&gt;. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;1 and 60 defines the &lt;a href="http://www.erlang.org/doc/design_principles/sup_princ.html#frequency"&gt;maximum restart frequency&lt;/a&gt;. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The tuple {ch3, ...} is a &lt;a href="http://www.erlang.org/doc/design_principles/sup_princ.html#spec"&gt;child specification&lt;/a&gt;. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="strategy"&gt;&lt;/a&gt;&lt;a name="5.3"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;5.3 Restart Strategy&lt;/h5&gt;&lt;br /&gt;&lt;a name="5.3.1"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;h6&gt;5.3.1 one_for_one&lt;/h6&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If a child process terminates, only that process is restarted. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="sup4"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;img alt="sup4" src="http://www.erlang.org/doc/design_principles/sup4.gif" /&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;em&gt;One_For_One Supervision&lt;/em&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="5.3.2"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h6&gt;5.3.2 one_for_all&lt;/h6&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If a child process terminates, all other child processes are terminated and then all child processes, including the terminated one, are restarted. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="sup5"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;img alt="sup5" src="http://www.erlang.org/doc/design_principles/sup5.gif" /&gt; &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;em&gt;One_For_All Supervision&lt;/em&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="5.3.3"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h6&gt;5.3.3 rest_for_one&lt;/h6&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If a child process terminates, the 'rest' of the child processes -- i.e. the child processes after the terminated process in start order -- are terminated. Then the terminated child process and the rest of the child processes are restarted. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="frequency"&gt;&lt;/a&gt;&lt;a name="5.4"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;5.4 Maximum Restart Frequency&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The supervisors have a built-in mechanism to limit the number of restarts which can occur in a given time interval. This is determined by the values of the two parameters MaxR and MaxT in the start specification returned by the callback function init: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;init(...) -&amp;gt;&lt;br /&gt;    {ok, {{RestartStrategy, MaxR, MaxT},&lt;br /&gt;          [ChildSpec, ...]}}.&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If more than MaxR number of restarts occur in the last MaxT seconds, then the supervisor terminates all the child processes and then itself. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;When the supervisor terminates, then the next higher level supervisor takes some action. It either restarts the terminated supervisor, or terminates itself. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The intention of the restart mechanism is to prevent a situation where a process repeatedly dies for the same reason, only to be restarted again. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="spec"&gt;&lt;/a&gt;&lt;a name="5.5"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;5.5 Child Specification&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This is the type definition for a child specification: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;{Id, StartFunc, Restart, Shutdown, Type, Modules}&lt;br /&gt;    Id = term()&lt;br /&gt;    StartFunc = {M, F, A}&lt;br /&gt;        M = F = atom()&lt;br /&gt;        A = [term()]&lt;br /&gt;    Restart = permanent | transient | temporary&lt;br /&gt;    Shutdown = brutal_kill | integer() &amp;amp;gt;=0 | infinity&lt;br /&gt;    Type = worker | supervisor&lt;br /&gt;    Modules = [Module] | dynamic&lt;br /&gt;        Module = atom()&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;  &lt;li&gt;Id is a name that is used to identify the child specification internally by the supervisor. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;StartFunc defines the function call used to start the child process. It is a module-function-arguments tuple used as apply(M, F, A). &lt;br /&gt;    &lt;br /&gt;It should be (or result in) a call to supervisor:start_link, gen_server:start_link, gen_fsm:start_link or gen_event:start_link. (Or a function compliant with these functions, see supervisor(3) for details. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;Restart defines when a terminated child process should be restarted. &lt;br /&gt;    &lt;ul&gt;&lt;br /&gt;      &lt;li&gt;A permanent child process is always restarted. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;      &lt;li&gt;A temporary child process is never restarted. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;      &lt;li&gt;A transient child process is restarted only if it terminates abnormally, i.e. with another exit reason than normal. &lt;/li&gt;&lt;br /&gt;    &lt;/ul&gt;&lt;br /&gt;  &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;&lt;a name="shutdown"&gt;&lt;/a&gt;Shutdown defines how a child process should be terminated. &lt;br /&gt;&lt;br /&gt;    &lt;ul&gt;&lt;br /&gt;      &lt;li&gt;brutal_kill means the child process is unconditionally terminated using exit(Child, kill). &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;      &lt;li&gt;An integer timeout value means that the supervisor tells the child process to terminate by calling exit(Child, shutdown) and then waits for an exit signal back. If no exit signal is received within the specified time, the child process is unconditionally terminated using exit(Child, kill). &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;      &lt;li&gt;If the child process is another supervisor, it should be set to infinity to give the subtree enough time to shutdown. &lt;/li&gt;&lt;br /&gt;    &lt;/ul&gt;&lt;br /&gt;  &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;Type specifies if the child process is a supervisor or a worker. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;Modules should be a list with one element [Module], where Module is the name of the callback module, if the child process is a supervisor, gen_server or gen_fsm. If the child process is a gen_event, Modules should be dynamic. &lt;br /&gt;    &lt;br /&gt;This information is used by the release handler during upgrades and downgrades, see &lt;a href="http://www.erlang.org/doc/design_principles/release_handling.html"&gt;Release Handling&lt;/a&gt;. &lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Example: The child specification to start the server ch3 in the example above looks like: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;{ch3,&lt;br /&gt; {ch3, start_link, []},&lt;br /&gt; permanent, brutal_kill, worker, [ch3]}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Example: A child specification to start the event manager from the chapter about &lt;a href="http://www.erlang.org/doc/design_principles/events.html#mgr"&gt;gen_event&lt;/a&gt;: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;{error_man,&lt;br /&gt; {gen_event, start_link, [{local, error_man}]},&lt;br /&gt; permanent, 5000, worker, dynamic}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Both the server and event manager are registered processes which can be expected to be accessible at all times, thus they are specified to be permanent. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;ch3 does not need to do any cleaning up before termination, thus no shutdown time is needed but brutal_kill should be sufficient. error_man may need some time for the event handlers to clean up, thus Shutdown is set to 5000 ms. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Example: A child specification to start another supervisor: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;{sup,&lt;br /&gt; {sup, start_link, []},&lt;br /&gt; transient, infinity, supervisor, [sup]}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="super_tree"&gt;&lt;/a&gt;&lt;a name="5.6"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;5.6 Starting a Supervisor&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;In the example above, the supervisor is started by calling ch_sup:start_link(): &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;start_link() -&amp;gt;&lt;br /&gt;    supervisor:start_link(ch_sup, []).&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;ch_sup:start_link calls the function supervisor:start_link/2. This function spawns and links to a new process, a supervisor. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;  &lt;li&gt;The first argument, ch_sup, is the name of the callback module, that is the module where the init callback function is located. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;The second argument, [], is a term which is passed as-is to the callback function init. Here, init does not need any indata and ignores the argument. &lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;In this case, the supervisor is not registered. Instead its pid must be used. A name can be specified by calling supervisor:start_link({local, Name}, Module, Args) or supervisor:start_link({global, Name}, Module, Args). &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The new supervisor process calls the callback function ch_sup:init([]). init is expected to return {ok, StartSpec}: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;init(_Args) -&amp;gt;&lt;br /&gt;    {ok, {{one_for_one, 1, 60},&lt;br /&gt;          [{ch3, {ch3, start_link, []},&lt;br /&gt;            permanent, brutal_kill, worker, [ch3]}]}}.&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The supervisor then starts all its child processes according to the child specifications in the start specification. In this case there is one child process, ch3. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Note that supervisor:start_link is synchronous. It does not return until all child processes have been started. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="5.7"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;5.7 Adding a Child Process&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;In addition to the static supervision tree, we can also add dynamic child processes to an existing supervisor with the following call: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;supervisor:start_child(Sup, ChildSpec)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Sup is the pid, or name, of the supervisor. ChildSpec is a &lt;a href="http://www.erlang.org/doc/design_principles/sup_princ.html#spec"&gt;child specification&lt;/a&gt;. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Child processes added using start_child/2 behave in the same manner as the other child processes, with the following important exception: If a supervisor dies and is re-created, then all child processes which were dynamically added to the supervisor will be lost. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="5.8"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;5.8 Stopping a Child Process&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Any child process, static or dynamic, can be stopped in accordance with the shutdown specification: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;supervisor:terminate_child(Sup, Id)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The child specification for a stopped child process is deleted with the following call: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;supervisor:delete_child(Sup, Id)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Sup is the pid, or name, of the supervisor. Id is the id specified in the &lt;a href="http://www.erlang.org/doc/design_principles/sup_princ.html#spec"&gt;child specification&lt;/a&gt;. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;As with dynamically added child processes, the effects of deleting a static child process is lost if the supervisor itself restarts. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="5.9"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;5.9 Simple-One-For-One Supervisors&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;A supervisor with restart strategy simple_one_for_one is a simplified one_for_one supervisor, where all child processes are dynamically added instances of the same process. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Example of a callback module for a simple_one_for_one supervisor: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;-module(simple_sup).&lt;br /&gt;-behaviour(supervisor).&lt;br /&gt;&lt;br /&gt;-export([start_link/0]).&lt;br /&gt;-export([init/1]).&lt;br /&gt;&lt;br /&gt;start_link() -&amp;gt;&lt;br /&gt;    supervisor:start_link(simple_sup, []).&lt;br /&gt;&lt;br /&gt;init(_Args) -&amp;gt;&lt;br /&gt;    {ok, {{simple_one_for_one, 0, 1},&lt;br /&gt;          [{call, {call, start_link, []},&lt;br /&gt;            temporary, brutal_kill, worker, [call]}]}}.&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;When started, the supervisor will not start any child processes. Instead, all child processes are added dynamically by calling: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;supervisor:start_child(Sup, List)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Sup is the pid, or name, of the supervisor. List is an arbitrary list of terms which will be added to the list of arguments specified in the child specification. If the start function is specified as {M, F, A}, then the child process is started by calling apply(M, F, A++List). &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;For example, adding a child to simple_sup above: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;supervisor:start_child(Pid, [id1])&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;results in the child process being started by calling apply(call, start_link, []++[id1]), or actually: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;call:start_link(id1)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="5.10"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;5.10 Stopping&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Since the supervisor is part of a supervision tree, it will automatically be terminated by its supervisor. When asked to shutdown, it will terminate all child processes in reversed start order according to the respective shutdown specifications, and then terminate itself. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1316352013241370780-3974804662031711281?l=fzhong.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://fzhong.blogspot.com/feeds/3974804662031711281/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1316352013241370780&amp;postID=3974804662031711281' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/3974804662031711281'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/3974804662031711281'/><link rel='alternate' type='text/html' href='http://fzhong.blogspot.com/2008/03/erlang-supervisor-behaviour.html' title='erlang-Supervisor Behaviour'/><author><name>钟芳林</name><uri>http://www.blogger.com/profile/14620517815530657655</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1316352013241370780.post-6353480239527436028</id><published>2008-03-31T22:04:00.003-07:00</published><updated>2008-03-31T22:04:23.908-07:00</updated><title type='text'>erlang之Module gen_fsm</title><content type='html'>&lt;p&gt;Module gen_fsm&lt;/p&gt;  &lt;p&gt;有限状态机模块。&lt;/p&gt;  &lt;h5&gt;什么是有限状态机(FSM)？PS：唉，大学编译原理没学好，现在要补课&lt;/h5&gt;  &lt;p&gt;简述    &lt;br /&gt;有限状态机（以下用FSM指代）是一种算法思想，简单而言，有限状态机由一组状态、一个初始状态、输入和根据输入及现有状态转换为下一个状态的转换函数组成。 &lt;/p&gt;  &lt;h5&gt;&amp;#160;&lt;/h5&gt;  &lt;h4&gt;Gen_Fsm Behaviour&lt;/h4&gt;  &lt;p&gt;This chapter should be read in conjunction with gen_fsm(3), where all interface functions and callback functions are described in detail. &lt;/p&gt;  &lt;p&gt;&lt;a name="3.1"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h5&gt;3.1 Finite State Machines&lt;/h5&gt;  &lt;p&gt;A finite state machine, FSM, can be described as a set of relations of the form: &lt;/p&gt;  &lt;pre&gt;State(S) x Event(E) -&amp;gt; Actions(A), State(S')&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;These relations are interpreted as meaning: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;  &lt;p&gt;If we are in state S and the event E occurs, we should perform the actions A and make a transition to the state S'. &lt;/p&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;For an FSM implemented using the gen_fsm behaviour, the state transition rules are written as a number of Erlang functions which conform to the following convention: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;StateName(Event, StateData) -&amp;gt;&lt;br /&gt;    .. code for actions here ...&lt;br /&gt;    {next_state, StateName', StateData'}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="3.2"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;3.2 Example&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;A door with a code lock could be viewed as an FSM. Initially, the door is locked. Anytime someone presses a button, this generates an event. Depending on what buttons have been pressed before, the sequence so far may be correct, incomplete or wrong. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If it is correct, the door is unlocked for 30 seconds (30000 ms). If it is incomplete, we wait for another button to be pressed. If it is is wrong, we start all over, waiting for a new button sequence. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Implementing the code lock FSM using gen_fsm results in this callback module: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="ex"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;-module(code_lock).&lt;br /&gt;-behaviour(gen_fsm).&lt;br /&gt;&lt;br /&gt;-export([start_link/1]).&lt;br /&gt;-export([button/1]).&lt;br /&gt;-export([init/1, locked/2, open/2]).&lt;br /&gt;&lt;br /&gt;start_link(Code) -&amp;gt;&lt;br /&gt;    gen_fsm:start_link({local, code_lock}, code_lock, Code, []).&lt;br /&gt;&lt;br /&gt;button(Digit) -&amp;gt;&lt;br /&gt;    gen_fsm:send_event(code_lock, {button, Digit}).&lt;br /&gt;&lt;br /&gt;init(Code) -&amp;gt;&lt;br /&gt;    {ok, locked, {[], Code}}.&lt;br /&gt;&lt;br /&gt;locked({button, Digit}, {SoFar, Code}) -&amp;gt;&lt;br /&gt;    case [Digit|SoFar] of&lt;br /&gt;        Code -&amp;gt;&lt;br /&gt;            do_unlock(),&lt;br /&gt;            {next_state, open, {[], Code}, 3000};&lt;br /&gt;        Incomplete when length(Incomplete)&amp;lt;length(Code) -&amp;gt;&lt;br /&gt;            {next_state, locked, {Incomplete, Code}};&lt;br /&gt;        _Wrong -&amp;gt;&lt;br /&gt;            {next_state, locked, {[], Code}};&lt;br /&gt;    end.&lt;br /&gt;&lt;br /&gt;open(timeout, State) -&amp;gt;&lt;br /&gt;    do_lock(),&lt;br /&gt;    {next_state, locked, State}.&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The code is explained in the next sections. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="3.3"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;3.3 Starting a Gen_Fsm&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;In the example in the previous section, the gen_fsm is started by calling code_lock:start_link(Code): &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;start_link(Code) -&amp;gt;&lt;br /&gt;    gen_fsm:start_link({local, code_lock}, code_lock, Code, []).&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;start_link calls the function gen_fsm:start_link/4. This function spawns and links to a new process, a gen_fsm. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;  &lt;li&gt;The first argument {local, code_lock} specifies the name. In this case, the gen_fsm will be locally registered as code_lock. &lt;br /&gt;    &lt;br /&gt;If the name is omitted, the gen_fsm is not registered. Instead its pid must be used. The name could also be given as {global, Name}, in which case the gen_fsm is registered using global:register_name/2. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;The second argument, code_lock, is the name of the callback module, that is the module where the callback functions are located. &lt;br /&gt;    &lt;br /&gt;In this case, the interface functions (start_link and button) are located in the same module as the callback functions (init, locked and open). This is normally good programming practice, to have the code corresponding to one process contained in one module. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;The third argument, Code, is a term which is passed as-is to the callback function init. Here, init gets the correct code for the lock as indata. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;The fourth argument, [], is a list of options. See gen_fsm(3) for available options. &lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If name registration succeeds, the new gen_fsm process calls the callback function code_lock:init(Code). This function is expected to return {ok, StateName, StateData}, where StateName is the name of the initial state of the gen_fsm. In this case locked, assuming the door is locked to begin with. StateData is the internal state of the gen_fsm. (For gen_fsms, the internal state is often referred to 'state data' to distinguish it from the state as in states of a state machine.) In this case, the state data is the button sequence so far (empty to begin with) and the correct code of the lock. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;init(Code) -&amp;gt;&lt;br /&gt;    {ok, locked, {[], Code}}.&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Note that gen_fsm:start_link is synchronous. It does not return until the gen_fsm has been initialized and is ready to receive notifications. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;gen_fsm:start_link must be used if the gen_fsm is part of a supervision tree, i.e. is started by a supervisor. There is another function gen_fsm:start to start a stand-alone gen_fsm, i.e. a gen_fsm which is not part of a supervision tree. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="3.4"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;3.4 Notifying About Events&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The function notifying the code lock about a button event is implemented using gen_fsm:send_event/2: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;button(Digit) -&amp;gt;&lt;br /&gt;    gen_fsm:send_event(code_lock, {button, Digit}).&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;code_lock is the name of the gen_fsm and must agree with the name used to start it. {button, Digit} is the actual event. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The event is made into a message and sent to the gen_fsm. When the event is received, the gen_fsm calls StateName(Event, StateData) which is expected to return a tuple {next_state, StateName1, StateData1}. StateName is the name of the current state and StateName1 is the name of the next state to go to. StateData1 is a new value for the state data of the gen_fsm. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;locked({button, Digit}, {SoFar, Code}) -&amp;gt;&lt;br /&gt;    case [Digit|SoFar] of&lt;br /&gt;        Code -&amp;gt;&lt;br /&gt;            do_unlock(),&lt;br /&gt;            {next_state, open, {[], Code}, 30000};&lt;br /&gt;        Incomplete when length(Incomplete)&amp;lt;length(Code) -&amp;gt;&lt;br /&gt;            {next_state, locked, {Incomplete, Code}};&lt;br /&gt;        _Wrong -&amp;gt;&lt;br /&gt;            {next_state, locked, {[], Code}};&lt;br /&gt;    end.&lt;br /&gt;&lt;br /&gt;open(timeout, State) -&amp;gt;&lt;br /&gt;    do_lock(),&lt;br /&gt;    {next_state, locked, State}.&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If the door is locked and a button is pressed, the complete button sequence so far is compared with the correct code for the lock and, depending on the result, the door is either unlocked and the gen_fsm goes to state open, or the door remains in state locked. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="3.5"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;3.5 Timeouts&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;When a correct code has been givened, the door is unlocked and the following tuple is returned from locked/2: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;{next_state, open, {[], Code}, 30000};&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;30000 is a timeout value in milliseconds. After 30000 ms, i.e. 30 seconds, a timeout occurs. Then StateName(timeout, StateData) is called. In this case, the timeout occurs when the door has been in state open for 30 seconds. After that the door is locked again: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;open(timeout, State) -&amp;gt;&lt;br /&gt;    do_lock(),&lt;br /&gt;    {next_state, locked, State}.&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="3.6"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;3.6 All State Events&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Sometimes an event can arrive at any state of the gen_fsm. Instead of sending the message with gen_fsm:send_event/2 and writing one clause handling the event for each state function, the message can be sent with gen_fsm:send_all_state_event/2 and handled with Module:handle_event/3: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;-module(code_lock).&lt;br /&gt;...&lt;br /&gt;-export([stop/0]).&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;stop() -&amp;gt;&lt;br /&gt;    gen_fsm:send_all_state_event(code_lock, stop).&lt;br /&gt;&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;handle_event(stop, _StateName, StateData) -&amp;gt;&lt;br /&gt;    {stop, normal, StateData}.&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="3.7"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;3.7 Stopping&lt;/h5&gt;&lt;br /&gt;&lt;a name="3.7.1"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;h6&gt;3.7.1 In a Supervision Tree&lt;/h6&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If the gen_fsm is part of a supervision tree, no stop function is needed. The gen_fsm will automatically be terminated by its supervisor. Exactly how this is done is defined by a &lt;a href="http://erlang.org/doc/design_principles/sup_princ.html#shutdown"&gt;shutdown strategy&lt;/a&gt; set in the supervisor. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If it is necessary to clean up before termination, the shutdown strategy must be a timeout value and the gen_fsm must be set to trap exit signals in the init function. When ordered to shutdown, the gen_fsm will then call the callback function terminate(shutdown, StateName, StateData): &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;init(Args) -&amp;gt;&lt;br /&gt;    ...,&lt;br /&gt;    process_flag(trap_exit, true),&lt;br /&gt;    ...,&lt;br /&gt;    {ok, StateName, StateData}.&lt;br /&gt;&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;terminate(shutdown, StateName, StateData) -&amp;gt;&lt;br /&gt;    ..code for cleaning up here..&lt;br /&gt;    ok.&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="3.7.2"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h6&gt;3.7.2 Stand-Alone Gen_Fsms&lt;/h6&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If the gen_fsm is not part of a supervision tree, a stop function may be useful, for example: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;...&lt;br /&gt;-export([stop/0]).&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;stop() -&amp;gt;&lt;br /&gt;    gen_fsm:send_all_state_event(code_lock, stop).&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;handle_event(stop, _StateName, StateData) -&amp;gt;&lt;br /&gt;    {stop, normal, StateData}.&lt;br /&gt;&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;terminate(normal, _StateName, _StateData) -&amp;gt;&lt;br /&gt;    ok.&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The callback function handling the stop event returns a tuple {stop,normal,StateData1}, where normal specifies that it is a normal termination and StateData1 is a new value for the state data of the gen_fsm. This will cause the gen_fsm to call terminate(normal,StateName,StateData1) and then terminate gracefully: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="3.8"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;3.8 Handling Other Messages&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If the gen_fsm should be able to receive other messages than events, the callback function handle_info(Info, StateName, StateData) must be implemented to handle them. Examples of other messages are exit messages, if the gen_fsm is linked to other processes (than the supervisor) and trapping exit signals. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;handle_info({'EXIT', Pid, Reason}, StateName, StateData) -&amp;gt;&lt;br /&gt;    ..code to handle exits here..&lt;br /&gt;    {next_state, StateName1, StateData1}.&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;/ul&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1316352013241370780-6353480239527436028?l=fzhong.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://fzhong.blogspot.com/feeds/6353480239527436028/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1316352013241370780&amp;postID=6353480239527436028' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/6353480239527436028'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/6353480239527436028'/><link rel='alternate' type='text/html' href='http://fzhong.blogspot.com/2008/03/erlangmodule-genfsm.html' title='erlang之Module gen_fsm'/><author><name>钟芳林</name><uri>http://www.blogger.com/profile/14620517815530657655</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1316352013241370780.post-1673670440411338355</id><published>2008-03-31T22:04:00.001-07:00</published><updated>2008-03-31T22:04:00.793-07:00</updated><title type='text'>ejabberd模块开发</title><content type='html'>&lt;p&gt;Introduction &lt;/p&gt;  &lt;p&gt;ejabberd internal modules works as plugins. Each module is an &lt;a href="http://erlang.org/"&gt;erlang&lt;/a&gt; module with a name beginning with &amp;#8220;mod_&amp;#8221;. If you don&amp;#8217;t already know Erlang, you should also take a look at this &lt;a href="http://erlang.org/doc/doc-5.5.3/doc/getting_started/part_frame.html"&gt;doc&lt;/a&gt;. &lt;/p&gt;  &lt;h4&gt;API of the module&lt;/h4&gt;  &lt;p&gt;All the internal modules must use the &amp;#8220;gen_mod&amp;#8221; behavior. &lt;/p&gt;  &lt;p&gt;It must provide the following API: &lt;/p&gt;  &lt;p&gt;&lt;code&gt;start(Host, Opts) -&amp;gt; ok      &lt;br /&gt;stop(Host) -&amp;gt; ok       &lt;br /&gt;* Host = string()       &lt;br /&gt;* Opts = [{Name, Value}]       &lt;br /&gt;* Name = Value = string() &lt;/code&gt;&lt;/p&gt;  &lt;p&gt;Host is the name of the virtual host running the module. The start/2 and stop/1 functions are called for each virtual host at start and stop time of the server.    &lt;br /&gt;Opts is a lists of options set in the configuration file for the module. They can be retrieved with the &lt;a href="http://www.process-one.net/en?URL=http://www.process-one.net/en/wiki/gen_mod/"&gt;gen mod:get opt/3&lt;/a&gt; function. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1316352013241370780-1673670440411338355?l=fzhong.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://fzhong.blogspot.com/feeds/1673670440411338355/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1316352013241370780&amp;postID=1673670440411338355' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/1673670440411338355'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/1673670440411338355'/><link rel='alternate' type='text/html' href='http://fzhong.blogspot.com/2008/03/ejabberd.html' title='ejabberd模块开发'/><author><name>钟芳林</name><uri>http://www.blogger.com/profile/14620517815530657655</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1316352013241370780.post-10291408385134540</id><published>2008-03-31T22:03:00.005-07:00</published><updated>2008-03-31T22:03:42.523-07:00</updated><title type='text'>解决Qt4.4 beta输入法侯选框的问题</title><content type='html'>&lt;p&gt;昨天在QInputContext.cpp找了半天，尝试修改代码也没有解决侯选框出不来的问题。在说到解决方法之前，首先感谢souce insight，没有这么好的编辑器，我都不知道要怎么去看这些大型工程的源代码。&lt;/p&gt;  &lt;p&gt;查看了一下IME编辑相关的资料，顺代的在qt4.4的源码中搜索与WM_IME开头的消息除理代码，不多，也就几条，最后在qapplication_win.cpp让我给发现了，嘿嘿，就是在处理WM_IME_NOTIFY消息的代码有问题，代码如下：&lt;/p&gt;  &lt;p&gt;case WM_IME_NOTIFY:    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // special handling for ime, only for widgets in a popup     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (wParam&amp;#160; == IMN_OPENCANDIDATE) {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; imeParentWnd = hwnd;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (QApplication::activePopupWidget()) {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // temporarily disable the mouse grab to allow mouse input in     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // the ime candidate window. The actual handle is untouched     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (autoCaptureWnd)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ReleaseCapture();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } else if (wParam&amp;#160; == IMN_CLOSECANDIDATE) {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; imeParentWnd = 0;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (QApplication::activePopupWidget()) {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // undo the action above, when candidate window is closed     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (autoCaptureWnd)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; SetCapture(autoCaptureWnd);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;  &lt;p&gt;result = false;//added by zhongfanglin@gmail.com    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; break;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; default:     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; result = false;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // event was not processed     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; break;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; if (evt_type != QEvent::None) {&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // simple event    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; QEvent e(evt_type);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; result = qt_sendSpontaneousEvent(widget, &amp;amp;e);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;  &lt;p&gt;//add by zhongfanglin@anzsoft.com    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; if(AnzSkin-&amp;gt;winEventFilter(&amp;amp;msg,&amp;amp;res))     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; RETURN(res);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; //end add &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; if (result)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; RETURN(false); &lt;/p&gt;  &lt;p&gt;do_default:    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; RETURN(QWinInputContext::DefWindowProc(hwnd,message,wParam,lParam))     &lt;br /&gt;} &lt;/p&gt;  &lt;p&gt;&amp;#160; &lt;/p&gt;  &lt;p&gt;&amp;#160; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;作用没太看明白，但是从代码可以看出，WM_IME_NOTIFY被拦截了，并没有交给默认的消息处理函数，所以在case WM_IME_NOTIFY:节添加了一句代码，result = false,重新编译QtGui模块，运行程序，期待已久的输入法侯选框终于出现了。&lt;/p&gt;  &lt;p&gt;不过没明白的是，我用的五笔加加在修改这个代码之前是能出侯选框的，看来是五笔加加不是用的IME体系的侯选框处理机制。&lt;/p&gt;  &lt;p&gt;顺便发个牢骚，现在好用的拼音输入法真多，又漂亮又好用，为吓咪就没人做好看漂亮又好用的五笔呢。。。。。。只怪用不来拼音输入法，只好老实的用偶的五笔了。&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1316352013241370780-10291408385134540?l=fzhong.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://fzhong.blogspot.com/feeds/10291408385134540/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1316352013241370780&amp;postID=10291408385134540' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/10291408385134540'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/10291408385134540'/><link rel='alternate' type='text/html' href='http://fzhong.blogspot.com/2008/03/qt44-beta.html' title='解决Qt4.4 beta输入法侯选框的问题'/><author><name>钟芳林</name><uri>http://www.blogger.com/profile/14620517815530657655</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1316352013241370780.post-1187587065163969262</id><published>2008-03-31T22:03:00.003-07:00</published><updated>2008-03-31T22:03:23.375-07:00</updated><title type='text'>升级至Qt4.4又碰到输入法问题</title><content type='html'>&lt;p&gt;昨天把QT库的版本升级到了4.4_beta以解决之前版本的切换窗口之后输入法叫不起来的问题。我自己用的是五笔加加输入法，因为测试过没有问题，所以决定不等Qt发布Release版本，先用beta版本对付一下。&lt;/p&gt;  &lt;p&gt;升级的时候也碰到不少问题，特别是stylesheet的问题，很多style都要修改，郁闷。最后还是完成了升级。&lt;/p&gt;  &lt;p&gt;不过晚上的时候老詹说又有输入法问题，输入法的选字窗口显示了。咦，我的五笔加加工作是正常的啊。我是那种典型的发音不准的南方人，所以从来不用拼音输入法的，一直都用五笔加加输入法，所以没有发现这个问题！装上其它的输入法试了一下，果然是！！！郁闷&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;在网上搜索了一下，发现在有个在&lt;a href="trolltech.html"&gt;Trolltech&lt;/a&gt;工作的中国工程师齐亮，给他发了封邮件询问一下这个问题，不知道会不会看到这个邮件。希望这个问题能够解决。&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1316352013241370780-1187587065163969262?l=fzhong.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://fzhong.blogspot.com/feeds/1187587065163969262/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1316352013241370780&amp;postID=1187587065163969262' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/1187587065163969262'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/1187587065163969262'/><link rel='alternate' type='text/html' href='http://fzhong.blogspot.com/2008/03/qt44.html' title='升级至Qt4.4又碰到输入法问题'/><author><name>钟芳林</name><uri>http://www.blogger.com/profile/14620517815530657655</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1316352013241370780.post-2151539826336620423</id><published>2008-03-31T22:03:00.001-07:00</published><updated>2008-03-31T22:03:02.872-07:00</updated><title type='text'>Qt4.4 QTabWidget fixed</title><content type='html'>&lt;p&gt;在设置tabPosition为west，并且想设置tab只显示Icon不显示文字时Tab会比想要的效果长，为了解决这个问题，修改&lt;/p&gt;  &lt;p&gt;QStyleSheetStyle::sizeFromContents函数，修改部分如下：（只要修改一句代码，注释一些代码即可） &lt;/p&gt;  &lt;p&gt;&amp;#160; &lt;/p&gt;  &lt;p&gt;#ifndef QT_NO_TABBAR    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; case CT_TabBarTab: {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; QRenderRule subRule = renderRule(w, opt, PseudoElement_TabBarTab);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; sz = csz.expandedTo(subRule.minimumContentsSize());     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (subRule.hasBox() || subRule.hasBorder()) {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; sz = subRule.boxSize(sz);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; int spaceForIcon = 0;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; bool vertical = false;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (const QStyleOptionTab *tab = qstyleoption_cast&amp;lt;const QStyleOptionTab *&amp;gt;(opt)) {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (!tab-&amp;gt;icon.isNull())     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; spaceForIcon = 6 /* icon offset */ + 4 /* spacing */ + 2 /* magic */; // ###: hardcoded to match with common style     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; vertical = verticalTabs(tab-&amp;gt;shape);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return sz;//commited by zhongfanglin@gmail.com + QSize(vertical ? 0 : spaceForIcon, vertical ? spaceForIcon : 0);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; break;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;#endif // QT_NO_TABBAR&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1316352013241370780-2151539826336620423?l=fzhong.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://fzhong.blogspot.com/feeds/2151539826336620423/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1316352013241370780&amp;postID=2151539826336620423' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/2151539826336620423'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/2151539826336620423'/><link rel='alternate' type='text/html' href='http://fzhong.blogspot.com/2008/03/qt44-qtabwidget-fixed.html' title='Qt4.4 QTabWidget fixed'/><author><name>钟芳林</name><uri>http://www.blogger.com/profile/14620517815530657655</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1316352013241370780.post-433699298776193635</id><published>2008-03-31T22:02:00.003-07:00</published><updated>2008-03-31T22:02:43.339-07:00</updated><title type='text'>firefox开发：使用XPCOM访问Windows注册表（Accessing the Windows Registry Using XPCOM）</title><content type='html'>&lt;h4&gt;Introduction &lt;/h4&gt;  &lt;p&gt;When implementing Windows-specific functionality, it is often useful to access the Windows registry for information about the environment or other installed programs. To this end, there exist &lt;a href="http://developer.mozilla.org/en/docs/XPCOM"&gt;XPCOM&lt;/a&gt; interfaces to read and write registry data. This article will show you how to use the available interfaces in several Mozilla products. &lt;/p&gt;  &lt;p&gt;The examples in this document are all written in &lt;a href="http://developer.mozilla.org/en/docs/JavaScript"&gt;JavaScript&lt;/a&gt; using &lt;a href="http://developer.mozilla.org/en/docs/XPCOM"&gt;XPCOM&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;&lt;a name="Support_in_Firefox_1.5_or_newer"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h4&gt;[&lt;a href="http://developer.mozilla.org/en/docs/index.php?title=Accessing_the_Windows_Registry_Using_XPCOM&amp;amp;action=edit&amp;amp;section=2"&gt;edit&lt;/a&gt;] Support in Firefox 1.5 or newer &lt;/h4&gt;  &lt;p&gt;In &lt;a href="http://developer.mozilla.org/en/docs/Firefox_1.5"&gt;Firefox 1.5&lt;/a&gt;, a new API was added, &lt;a href="http://developer.mozilla.org/en/docs/index.php?title=nsIWindowsRegKey&amp;amp;action=edit"&gt;nsIWindowsRegKey&lt;/a&gt;, which provides extensive registry functionality. The interface follows the Windows API fairly closely, but with many of the low-level details taken care of for you. If you are writing an extension that only needs to support Firefox 1.5 or newer, then you only need to read this section. &lt;/p&gt;  &lt;p&gt;&lt;a name="A_simple_example"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h5&gt;[&lt;a href="http://developer.mozilla.org/en/docs/index.php?title=Accessing_the_Windows_Registry_Using_XPCOM&amp;amp;action=edit&amp;amp;section=3"&gt;edit&lt;/a&gt;] A simple example &lt;/h5&gt;  &lt;p&gt;Here's a simple example showing how to read your Windows ProductId: &lt;/p&gt;  &lt;pre&gt;var wrk = Components.classes[&amp;quot;@mozilla.org/windows-registry-key;1&amp;quot;]&lt;br /&gt;                    .createInstance(Components.interfaces.nsIWindowsRegKey);&lt;br /&gt;wrk.open(wrk.ROOT_KEY_LOCAL_MACHINE,&lt;br /&gt;         &amp;quot;SOFTWARE\\Microsoft\\Windows\\CurrentVersion&amp;quot;,&lt;br /&gt;         wrk.ACCESS_READ);&lt;br /&gt;var id = wrk.readStringValue(&amp;quot;ProductId&amp;quot;);&lt;br /&gt;wrk.close();&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This example, while simple, shows several important things about using the interface. First, you must use &lt;code&gt;createInstance()&lt;/code&gt; to get an object implementing this interface, not &lt;code&gt;getService()&lt;/code&gt;. Second, you must call &lt;code&gt;open()&lt;/code&gt; on the key before attempting to read a value. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Notice in the &lt;code&gt;open()&lt;/code&gt; call that the root key to use is specified using the named constants available on the &lt;a href="http://developer.mozilla.org/en/docs/index.php?title=nsIWindowsRegKey&amp;amp;action=edit"&gt;nsIWindowsRegKey&lt;/a&gt; interface, in this case &lt;code&gt;ROOT_KEY_LOCAL_MACHINE&lt;/code&gt;, which corresponds to &lt;code&gt;HKEY_LOCAL_MACHINE&lt;/code&gt; in the Windows registry. Also notice that the path to the key has backslashes escaped, a necessity in JavaScript and C++ string constants. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The desired access rights are specified using a named constant from the interface, in this example &lt;code&gt;ACCESS_READ&lt;/code&gt;. This can be very important when dealing with non-Administrator accounts with restricted privileges. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The value is read using &lt;code&gt;readStringValue()&lt;/code&gt;. You have to specify what type of data you expect to read, which we will expand on later. Finally, note that you should close the key when you are done to avoid wasting system resources. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="Opening_Registry_Keys"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;[&lt;a href="http://developer.mozilla.org/en/docs/index.php?title=Accessing_the_Windows_Registry_Using_XPCOM&amp;amp;action=edit&amp;amp;section=4"&gt;edit&lt;/a&gt;] Opening Registry Keys &lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Before doing anything with a registry key you must first open the key you are interested in. The example above demonstates this using the &lt;code&gt;open()&lt;/code&gt; method. If you want to create a new key, you can use the &lt;code&gt;create()&lt;/code&gt; method, which takes the same parameters as &lt;code&gt;open()&lt;/code&gt;. Note that it is not an error to call &lt;code&gt;create()&lt;/code&gt; on an existing key, and doing so has the same result as calling &lt;code&gt;open()&lt;/code&gt;. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Both of these methods take a root key as the first parameter. From JavaScript, you will want to use the named constants on the interface for this parameter. They are: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;  &lt;li&gt;&lt;code&gt;ROOT_KEY_CLASSES_ROOT&lt;/code&gt; &amp;#8212; Corresponds to &lt;code&gt;HKEY_CLASSES_ROOT&lt;/code&gt; &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;&lt;code&gt;ROOT_KEY_CURRENT_USER&lt;/code&gt; &amp;#8212; Corresponds to &lt;code&gt;HKEY_CURRENT_USER&lt;/code&gt; &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;&lt;code&gt;ROOT_KEY_LOCAL_MACHINE&lt;/code&gt; &amp;#8212; Corresponds to &lt;code&gt;HKEY_LOCAL_MACHINE&lt;/code&gt; &lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The second parameter for &lt;code&gt;open()&lt;/code&gt; and &lt;code&gt;create()&lt;/code&gt; is the path to the key. As noted in the example above, you will need to escape backslashes within the string. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The third parameter for &lt;code&gt;open()&lt;/code&gt; and &lt;code&gt;create()&lt;/code&gt; is the access mode. It is specified as a bitwise combination of flags defined on the interface. You can read the interface documentation for a full explanation, but we will show only the three most commonly used modes here: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;  &lt;li&gt;&lt;code&gt;ACCESS_READ&lt;/code&gt; &amp;#8212; For reading values, enumerating keys, and receiving notifications &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;&lt;code&gt;ACCESS_WRITE&lt;/code&gt; &amp;#8212; For setting values and creating sub keys &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;&lt;code&gt;ACCESS_ALL&lt;/code&gt; &amp;#8212; Access for all operations &lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;In addition to &lt;code&gt;open()&lt;/code&gt; and &lt;code&gt;create()&lt;/code&gt;, there are the &lt;code&gt;openChild()&lt;/code&gt; and &lt;code&gt;createChild()&lt;/code&gt; methods. You can call these methods on an already-opened registry key to open a child key. Both methods take a relative path and access mode as parameters and return a new object implementing &lt;a href="http://developer.mozilla.org/en/docs/index.php?title=nsIWindowsRegKey&amp;amp;action=edit"&gt;nsIWindowsRegKey&lt;/a&gt;. Here's the simple example again, but using &lt;code&gt;openChild()&lt;/code&gt;: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;var wrk = Components.classes[&amp;quot;@mozilla.org/windows-registry-key;1&amp;quot;]&lt;br /&gt;                    .createInstance(Components.interfaces.nsIWindowsRegKey);&lt;br /&gt;wrk.open(wrk.ROOT_KEY_LOCAL_MACHINE,&lt;br /&gt;         &amp;quot;SOFTWARE\\Microsoft&amp;quot;,&lt;br /&gt;         wrk.ACCESS_READ);&lt;br /&gt;var subkey = wrk.openChild(&amp;quot;Windows\\CurrentVersion&amp;quot;, wrk.ACCESS_READ);&lt;br /&gt;var id = subkey.readStringValue(&amp;quot;ProductId&amp;quot;);&lt;br /&gt;subkey.close();&lt;br /&gt;wrk.close();&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Once you've opened a registry key, you can begin to make use of it. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="Reading_Registry_Values"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;[&lt;a href="http://developer.mozilla.org/en/docs/index.php?title=Accessing_the_Windows_Registry_Using_XPCOM&amp;amp;action=edit&amp;amp;section=5"&gt;edit&lt;/a&gt;] Reading Registry Values &lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Probably the most common action associated with the Windows registry is reading values. The simple example above shows how to read an existing string value. However, Windows registry values can have several data types, so you need to ensure that you read the correct type. You can check the type of a value using the method &lt;code&gt;getValueType()&lt;/code&gt;. This method returns an integer indicating the data type of the value. The data types supported by this interface are defined as named constants on the interface as follows: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;  &lt;li&gt;&lt;code&gt;TYPE_NONE&lt;/code&gt; &amp;#8212; Probably not useful &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;&lt;code&gt;TYPE_STRING&lt;/code&gt; &amp;#8212; A Unicode string value &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;&lt;code&gt;TYPE_BINARY&lt;/code&gt; &amp;#8212; Binary data &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;&lt;code&gt;TYPE_INT&lt;/code&gt; &amp;#8212; A 32 bit integer &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;&lt;code&gt;TYPE_INT64&lt;/code&gt; &amp;#8212; A 64 bit integer &lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Each of these types (except &lt;code&gt;TYPE_NONE&lt;/code&gt;) has a corresponding method to read the value data: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;  &lt;li&gt;&lt;code&gt;readStringValue()&lt;/code&gt; &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;&lt;code&gt;readBinaryValue()&lt;/code&gt; &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;&lt;code&gt;readIntValue()&lt;/code&gt; &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;&lt;code&gt;readInt64Value()&lt;/code&gt; &lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Since JavaScript is a dynamically-typed language, you may wish to use the following code to handle all types of data. In this function, &lt;code&gt;wrk&lt;/code&gt; is expected to be an already opened &lt;a href="http://developer.mozilla.org/en/docs/index.php?title=nsIWindowsRegKey&amp;amp;action=edit"&gt;nsIWindowsRegKey&lt;/a&gt;. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;function readRegistryValue(wrk, value)&lt;br /&gt;{&lt;br /&gt;  switch (wrk.getValueType(value)) {&lt;br /&gt;    case wrk.TYPE_STRING:&lt;br /&gt;      return wrk.readStringValue(value);&lt;br /&gt;    case wrk.TYPE_BINARY:&lt;br /&gt;      return wrk.readBinaryValue(value);&lt;br /&gt;    case wrk.TYPE_INT:&lt;br /&gt;      return wrk.readIntValue(value);&lt;br /&gt;    case wrk.TYPE_INT64:&lt;br /&gt;      return wrk.readInt64Value(value);&lt;br /&gt;  }&lt;br /&gt;  // unknown type&lt;br /&gt;  return null;&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;a name="Writing_Registry_Values"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;[&lt;a href="http://developer.mozilla.org/en/docs/index.php?title=Accessing_the_Windows_Registry_Using_XPCOM&amp;amp;action=edit&amp;amp;section=6"&gt;edit&lt;/a&gt;] Writing Registry Values &lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Writing registry values is quite similar to reading. For each supported data type, there is a &lt;code&gt;write*Value()&lt;/code&gt; method complementary to the &lt;code&gt;read*Value()&lt;/code&gt; method. Don't forget that if you are writing a new value, you may need to &lt;code&gt;create()&lt;/code&gt; the parent key first. This example demonstrates writing a new string value: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;var wrk = Components.classes[&amp;quot;@mozilla.org/windows-registry-key;1&amp;quot;]&lt;br /&gt;                    .createInstance(Components.interfaces.nsIWindowsRegKey);&lt;br /&gt;wrk.create(wrk.ROOT_KEY_CURRENT_USER,&lt;br /&gt;           &amp;quot;SOFTWARE\\MDC\\Test&amp;quot;,&lt;br /&gt;           wrk.ACCESS_WRITE);&lt;br /&gt;wrk.writeStringValue(&amp;quot;TestValue&amp;quot;, &amp;quot;Hello World!&amp;quot;);&lt;br /&gt;wrk.close();&lt;/pre&gt;&lt;br /&gt;&lt;a name="Checking_the_Existence_of_Keys_and_Values"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;[&lt;a href="http://developer.mozilla.org/en/docs/index.php?title=Accessing_the_Windows_Registry_Using_XPCOM&amp;amp;action=edit&amp;amp;section=7"&gt;edit&lt;/a&gt;] Checking the Existence of Keys and Values &lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Before you attempt to read a value or open a child key, you should check to see whether it exists first. The &lt;a href="http://developer.mozilla.org/en/docs/index.php?title=nsIWindowsRegKey&amp;amp;action=edit"&gt;nsIWindowsRegKey&lt;/a&gt; interface provides methods for both of these&amp;#8212;&lt;code&gt;hasValue()&lt;/code&gt; and &lt;code&gt;hasChild()&lt;/code&gt;&amp;#8212;as demonstrated in this example: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;var wrk = Components.classes[&amp;quot;@mozilla.org/windows-registry-key;1&amp;quot;]&lt;br /&gt;                    .createInstance(Components.interfaces.nsIWindowsRegKey);&lt;br /&gt;wrk.open(wrk.ROOT_KEY_LOCAL_MACHINE,&lt;br /&gt;           &amp;quot;SOFTWARE\\Microsoft&amp;quot;,&lt;br /&gt;           wrk.ACCESS_READ);&lt;br /&gt;if (wrk.hasChild(&amp;quot;Windows&amp;quot;)) {&lt;br /&gt;  var subkey = wrk.openChild(&amp;quot;Windows\\CurrentVersion&amp;quot;, wrk.ACCESS_READ);&lt;br /&gt;  var id;&lt;br /&gt;  if (subkey.hasValue(&amp;quot;ProductId&amp;quot;))&lt;br /&gt;    id = subkey.readStringValue(&amp;quot;ProductId&amp;quot;);&lt;br /&gt;  subkey.close();&lt;br /&gt;}&lt;br /&gt;wrk.close();&lt;/pre&gt;&lt;br /&gt;&lt;a name="Enumerating_Registry_Keys_and_Values"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;[&lt;a href="http://developer.mozilla.org/en/docs/index.php?title=Accessing_the_Windows_Registry_Using_XPCOM&amp;amp;action=edit&amp;amp;section=8"&gt;edit&lt;/a&gt;] Enumerating Registry Keys and Values &lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;In some situations, you may want to enumerate a number of keys or values whose names you do not know. The &lt;a href="http://developer.mozilla.org/en/docs/index.php?title=nsIWindowsRegKey&amp;amp;action=edit"&gt;nsIWindowsRegKey&lt;/a&gt; interface provides the &lt;code&gt;childCount&lt;/code&gt;, &lt;code&gt;getChildName()&lt;/code&gt;, &lt;code&gt;valueCount&lt;/code&gt;, and &lt;code&gt;getValueName()&lt;/code&gt; properties and methods for enumerating keys and values respectively. You can use these methods to read a list of values or recursively access a branch of the registry. This example reads all the startup programs in one key of the registry. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;var wrk = Components.classes[&amp;quot;@mozilla.org/windows-registry-key;1&amp;quot;]&lt;br /&gt;                    .createInstance(Components.interfaces.nsIWindowsRegKey);&lt;br /&gt;wrk.open(wrk.ROOT_KEY_LOCAL_MACHINE,&lt;br /&gt;         &amp;quot;SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run&amp;quot;,&lt;br /&gt;         wrk.ACCESS_READ);&lt;br /&gt;for (var i=0; i&amp;lt;wrk.valueCount; i++) {&lt;br /&gt;  var name  = wrk.getValueName(i);&lt;br /&gt;  var value = readRegistryValue(wrk, name);&lt;br /&gt;  // do something interesting here...&lt;br /&gt;}&lt;br /&gt;wrk.close();&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;For simplicity, this example assumes the existence of the &lt;code&gt;readRegistryValue()&lt;/code&gt; function defined above. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="Removing_Registry_Keys_and_Values"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;[&lt;a href="http://developer.mozilla.org/en/docs/index.php?title=Accessing_the_Windows_Registry_Using_XPCOM&amp;amp;action=edit&amp;amp;section=9"&gt;edit&lt;/a&gt;] Removing Registry Keys and Values &lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;To remove child keys and values from the registry, you can use the &lt;code&gt;removeChild()&lt;/code&gt; and &lt;code&gt;removeValue()&lt;/code&gt; methods. &lt;code&gt;removeChild()&lt;/code&gt; removes a child key and all of its values, but will fail if the key has any child keys of its own. In that case you must manually enumerate the children and remove them individually. This example shows how to recursively delete a registry key and all of its children. Use with caution! &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;function removeChildrenRecursive(wrk)&lt;br /&gt;{&lt;br /&gt;  // we count backwards because we're removing them as we go&lt;br /&gt;  for (var i = wrk.childCount - 1; i &amp;gt;= 0; i--) {&lt;br /&gt;    var name   = wrk.getChildName(i);&lt;br /&gt;    var subkey = wrk.openChild(name, wrk.ACCESS_ALL);&lt;br /&gt;    removeChildrenRecursive(subkey);&lt;br /&gt;    subkey.close();&lt;br /&gt;    wrk.removeChild(name);&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;var wrk = Components.classes[&amp;quot;@mozilla.org/windows-registry-key;1&amp;quot;]&lt;br /&gt;                    .createInstance(Components.interfaces.nsIWindowsRegKey);&lt;br /&gt;wrk.open(wrk.ROOT_KEY_CURRENT_USER,&lt;br /&gt;         &amp;quot;SOFTWARE\\MDC\\Test&amp;quot;,&lt;br /&gt;         wrk.ACCESS_ALL);&lt;br /&gt;removeChildrenRecursive(wrk);&lt;br /&gt;wrk.close();&lt;/pre&gt;&lt;br /&gt;&lt;a name="Monitoring_Registry_Keys"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;[&lt;a href="http://developer.mozilla.org/en/docs/index.php?title=Accessing_the_Windows_Registry_Using_XPCOM&amp;amp;action=edit&amp;amp;section=10"&gt;edit&lt;/a&gt;] Monitoring Registry Keys &lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If you would like to know whether a registry key has changed since you last checked it, you can use the &lt;code&gt;startWatching()&lt;/code&gt;, &lt;code&gt;stopWatching()&lt;/code&gt;, and &lt;code&gt;hasChanged()&lt;/code&gt; methods. You must call &lt;code&gt;startWatching()&lt;/code&gt; for the key to be monitored. The method takes one parameter, a boolean indicating whether child keys should be watched. After that, you can call &lt;code&gt;hasChanged()&lt;/code&gt; to determine whether or not you need to reread the value. Calling &lt;code&gt;hasChanged()&lt;/code&gt; automatically resets the watch, so you can be sure that if it returns &lt;code&gt;true&lt;/code&gt; there are changes. This example demonstrates a trivial registry value cache for one key: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;var cache = {};&lt;br /&gt;&lt;br /&gt;function readRegistryValueNoCache(wrk, value)&lt;br /&gt;{&lt;br /&gt;  switch (wrk.getValueType(value)) {&lt;br /&gt;    case wrk.TYPE_STRING:&lt;br /&gt;      return wrk.readStringValue(value);&lt;br /&gt;    case wrk.TYPE_BINARY:&lt;br /&gt;      return wrk.readBinaryValue(value);&lt;br /&gt;    case wrk.TYPE_INT:&lt;br /&gt;      return wrk.readIntValue(value);&lt;br /&gt;    case wrk.TYPE_INT64:&lt;br /&gt;      return wrk.readInt64Value(value);&lt;br /&gt;  }&lt;br /&gt;  // unknown type&lt;br /&gt;  return null;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function readRegistryValue(wrk, value)&lt;br /&gt;{&lt;br /&gt;  if (wrk.hasChanged()) {&lt;br /&gt;    // wipe out the cache&lt;br /&gt;    cache = {};&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  if (value in cache) {&lt;br /&gt;    return cache[value];&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  cache[value] = readRegistryValueNoCache(wrk, value);&lt;br /&gt;  return cache[value];&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;var wrk = Components.classes[&amp;quot;@mozilla.org/windows-registry-key;1&amp;quot;]&lt;br /&gt;                    .createInstance(Components.interfaces.nsIWindowsRegKey);&lt;br /&gt;wrk.open(wrk.ROOT_KEY_LOCAL_MACHINE,&lt;br /&gt;         &amp;quot;SOFTWARE\\Microsoft\\Windows\\CurrentVersion&amp;quot;,&lt;br /&gt;         wrk.ACCESS_READ);&lt;br /&gt;wrk.startWatching(false); // only watch the values on this key, not child keys&lt;br /&gt;var id = readRegistryValue(wrk, &amp;quot;ProductId&amp;quot;);&lt;br /&gt;/* later you can read this again,&lt;br /&gt;   and it should come from the cache unless&lt;br /&gt;   there have been changes to the registry.&lt;br /&gt;   Remember to call wrk.close() when you&lt;br /&gt;   are finished!&lt;br /&gt;*/&lt;/pre&gt;&lt;br /&gt;&lt;a name="Support_in_Firefox_1.0"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;[&lt;a href="http://developer.mozilla.org/en/docs/index.php?title=Accessing_the_Windows_Registry_Using_XPCOM&amp;amp;action=edit&amp;amp;section=11"&gt;edit&lt;/a&gt;] Support in Firefox 1.0 &lt;/h4&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Firefox 1.0 includes a much simpler interface to the Windows registry, without most of the functionality supported in newer versions. The functionality is exposed in the &lt;a href="http://developer.mozilla.org/en/docs/index.php?title=nsIWindowsShellService&amp;amp;action=edit"&gt;nsIWindowsShellService&lt;/a&gt; interface. It consists of only one method, &lt;code&gt;getRegistryEntry()&lt;/code&gt;, and a set of named constants to specify the root key. You can use it as shown in the following example: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;var wss = Components.classes[&amp;quot;@mozilla.org/browser/shell-service;1&amp;quot;]&lt;br /&gt;                    .getService(Components.interfaces.nsIWindowsShellService);&lt;br /&gt;var id = wss.getRegistryEntry(wss.HKLM,&lt;br /&gt;                              &amp;quot;SOFTWARE\\Microsoft\\Windows\\CurrentVersion&amp;quot;,&lt;br /&gt;                              &amp;quot;ProductId&amp;quot;);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;Note:&lt;/b&gt; There's no way to set a registry value using this interface. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="Support_in_SeaMonkey_and_Other_Non-toolkit_Applications"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;[&lt;a href="http://developer.mozilla.org/en/docs/index.php?title=Accessing_the_Windows_Registry_Using_XPCOM&amp;amp;action=edit&amp;amp;section=12"&gt;edit&lt;/a&gt;] Support in SeaMonkey and Other Non-toolkit Applications &lt;/h4&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;In older versions of SeaMonkey and other non-toolkit-based applications, an interface existed called nsIWindowsRegistry, containing the same method and named constants as the methods described above for Firefox 1.0. It can be used as follows: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;var wss = Components.classes[&amp;quot;@mozilla.org/winhooks;1&amp;quot;]&lt;br /&gt;                    .getService(Components.interfaces.nsIWindowsRegistry);&lt;br /&gt;var id = wss.getRegistryEntry(wss.HKLM,&lt;br /&gt;                              &amp;quot;SOFTWARE\\Microsoft\\Windows\\CurrentVersion&amp;quot;,&lt;br /&gt;                              &amp;quot;ProductId&amp;quot;);&lt;/pre&gt;&lt;br /&gt;&lt;a name="Backwards_Compatibility"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;[&lt;a href="http://developer.mozilla.org/en/docs/index.php?title=Accessing_the_Windows_Registry_Using_XPCOM&amp;amp;action=edit&amp;amp;section=13"&gt;edit&lt;/a&gt;] Backwards Compatibility &lt;/h4&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If you need to support Firefox 1.0 and other older browser versions, you should check to see which interfaces are available. The following skeleton code will allow you to determine which interface to use: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;if (&amp;quot;@mozilla.org/windows-registry-key;1&amp;quot; in Components.classes) {&lt;br /&gt;  // Firefox 1.5 or newer&lt;br /&gt;}&lt;br /&gt;else if (&amp;quot;@mozilla.org/winhooks;1&amp;quot; in Components.classes) {&lt;br /&gt;  // SeaMonkey or other older non-toolkit application&lt;br /&gt;}&lt;br /&gt;else if (&amp;quot;@mozilla.org/browser/shell-service;1&amp;quot; in Components.classes) {&lt;br /&gt;  var wss = Components.classes[&amp;quot;@mozilla.org/browser/shell-service;1&amp;quot;]&lt;br /&gt;                      .getService(Components.interfaces.nsIWindowsShellService);&lt;br /&gt;  if (&amp;quot;getRegistryEntry&amp;quot; in wss) {&lt;br /&gt;    // Firefox 1.0&lt;br /&gt;  }&lt;br /&gt;  else {&lt;br /&gt;    // nothing supported&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;else {&lt;br /&gt;  // nothing supported&lt;br /&gt;}&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1316352013241370780-433699298776193635?l=fzhong.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://fzhong.blogspot.com/feeds/433699298776193635/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1316352013241370780&amp;postID=433699298776193635' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/433699298776193635'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/433699298776193635'/><link rel='alternate' type='text/html' href='http://fzhong.blogspot.com/2008/03/firefoxxpcomwindowsaccessing-windows.html' title='firefox开发：使用XPCOM访问Windows注册表（Accessing the Windows Registry Using XPCOM）'/><author><name>钟芳林</name><uri>http://www.blogger.com/profile/14620517815530657655</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1316352013241370780.post-7309068286181548058</id><published>2008-03-31T22:02:00.001-07:00</published><updated>2008-03-31T22:02:14.846-07:00</updated><title type='text'>[转]在Windows中查看端口占用情况的简单方法</title><content type='html'>&lt;p&gt;用这个命令，在DOS窗口执行：netstat -ano    &lt;br /&gt;看看占用0.0.0:80端口的PID是多少     &lt;br /&gt;然后在&amp;#8220;任务管理器&amp;#8221;中查到与该PID对应的程序。     &lt;br /&gt;如果任务管理器的进程页中看不到PID栏，则在任务管理器的菜单〖查看〗〖选择列〗中选择一下 &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1316352013241370780-7309068286181548058?l=fzhong.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://fzhong.blogspot.com/feeds/7309068286181548058/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1316352013241370780&amp;postID=7309068286181548058' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/7309068286181548058'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/7309068286181548058'/><link rel='alternate' type='text/html' href='http://fzhong.blogspot.com/2008/03/windows.html' title='[转]在Windows中查看端口占用情况的简单方法'/><author><name>钟芳林</name><uri>http://www.blogger.com/profile/14620517815530657655</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1316352013241370780.post-97186505537630917</id><published>2008-03-31T22:01:00.003-07:00</published><updated>2008-03-31T22:01:40.918-07:00</updated><title type='text'>XUL Tutorial:XUL Structure</title><content type='html'>&lt;p&gt;XUL,是XML User Interface Language的缩写。&lt;/p&gt;  &lt;h3&gt;XUL Tutorial:XUL Structure&lt;/h3&gt;  &lt;h5&gt;From MDC&lt;/h5&gt;  &lt;p&gt;&amp;#171; &lt;a href="http://developer.mozilla.org/en/docs/XUL_Tutorial:Introduction"&gt;Previous&lt;/a&gt; &lt;a href="http://developer.mozilla.org/en/docs/XUL_Tutorial:The_Chrome_URL"&gt;Next&lt;/a&gt; &amp;#187; &lt;/p&gt;  &lt;h4&gt;Contents&lt;/h4&gt; [&lt;a href="http://developer.mozilla.org/"&gt;hide&lt;/a&gt;]   &lt;ul&gt;   &lt;li&gt;&lt;a href="http://developer.mozilla.org/en/docs/XUL_Tutorial:XUL_Structure#How_XUL_is_Handled"&gt;1 How XUL is Handled&lt;/a&gt;       &lt;ul&gt;       &lt;li&gt;&lt;a href="http://developer.mozilla.org/en/docs/XUL_Tutorial:XUL_Structure#Document_types:_HTML_XML_XUL_CSS"&gt;1.1 Document types: HTML XML XUL CSS&lt;/a&gt; &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;&lt;a href="http://developer.mozilla.org/en/docs/XUL_Tutorial:XUL_Structure#Package_Organization"&gt;2 Package Organization&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://developer.mozilla.org/en/docs/XUL_Tutorial:XUL_Structure#Content_Packages"&gt;3 Content Packages&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://developer.mozilla.org/en/docs/XUL_Tutorial:XUL_Structure#Skins_or_Themes"&gt;4 Skins or Themes&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://developer.mozilla.org/en/docs/XUL_Tutorial:XUL_Structure#Locales"&gt;5 Locales&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://developer.mozilla.org/en/docs/XUL_Tutorial:XUL_Structure#Other_Packages"&gt;6 Other Packages&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://developer.mozilla.org/en/docs/XUL_Tutorial:XUL_Structure#Adding_a_Package"&gt;7 Adding a Package&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;We'll begin by looking at how the XUL is handled in Mozilla. &lt;/p&gt;  &lt;p&gt;&lt;a name="How_XUL_is_Handled"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h4&gt;[&lt;a href="http://developer.mozilla.org/en/docs/index.php?title=XUL_Tutorial:XUL_Structure&amp;amp;action=edit&amp;amp;section=1"&gt;edit&lt;/a&gt;] How XUL is Handled &lt;/h4&gt;  &lt;p&gt;In Mozilla, XUL is handled much in the same way that HTML or other types of content are handled. When you type the URL of an HTML page into the browser's address field, the browser locates the web site and downloads the content. The Mozilla rendering engine takes the content in the form of HTML source and transforms it into a document tree. The tree is then converted into a set of objects that can be displayed on the screen. Style sheets (&lt;a href="http://developer.mozilla.org/en/docs/CSS"&gt;CSS&lt;/a&gt;), images, and other technologies are used to control the presentation. XUL functions in much the same way. &lt;/p&gt;  &lt;p&gt;In fact, in Mozilla, all document types, whether they are HTML or XUL, or even &lt;a href="http://developer.mozilla.org/en/docs/SVG"&gt;SVG&lt;/a&gt;, are all handled by the same underlying code. This means that the same CSS properties may be used to style both HTML and XUL, and many of the features can be shared between both. However, there are some features that are specific to HTML such as forms, and others which are specific to XUL such as &lt;a href="http://developer.mozilla.org/en/docs/XUL_Tutorial:Overlays"&gt;overlays&lt;/a&gt;. Since XUL and HTML are handled in the same way, you can load both from either your local file system, from a web page, or from an extension or standalone &lt;a href="http://developer.mozilla.org/en/docs/XULRunner"&gt;XULRunner&lt;/a&gt; application. &lt;/p&gt;  &lt;p&gt;Content from remote sources &lt;code&gt;eg http://localhost/~username/&lt;/code&gt;, regardless of whether they are HTML or XUL or another document type, are limited in the type of operations they can perform, for security reasons. For this reason, Mozilla provides a method of installing content locally and registering the installed files as part of its &lt;b&gt;&lt;a href="http://developer.mozilla.org/en/docs/chrome"&gt;chrome&lt;/a&gt;&lt;/b&gt; system. This allows a special URL form to be used called a &lt;code&gt;chrome://&lt;/code&gt; URL. By accessing a file using a chrome URL, the files receive elevated privileges to access local files, access preferences and bookmarks and perform other privileged operations. Obviously, web pages do not get these privileges, unless they are signed with a digital certificate and the user has granted permission to perform these operations. &lt;/p&gt;  &lt;p&gt;This &lt;b&gt;chrome&lt;/b&gt; package registration is the way Firefox extensions are able to add features to the browser. The extensions are small packages of XUL files, JavaScript, style sheets and images packed together into a single file. This file can be created by using a ZIP utility. When the user downloads it, it will be installed onto the user's machine. It will hook into the browser using a XUL specific feature called an &lt;a href="http://developer.mozilla.org/en/docs/Overlay"&gt;overlay&lt;/a&gt; which allows the XUL from the extension and the XUL in the browser to combine together. To the user, it may seem like the extension has &lt;i&gt;modified&lt;/i&gt; the browser, but in reality, the code is all separate, and the extension may be uninstalled easily. Registered packages are not required to use overlays, of course. If they don't, you won't be able to access them via the main browser interface, but you can still access them via the chrome URL, if you know what it is. &lt;/p&gt;  &lt;p&gt;Standalone XUL applications may include XUL code in a similar way, but, of course, the XUL for the application will be included as part of the installation, instead of having to be installed separately as an extension. However, this XUL code will be registered in the chrome system such that the application can display the UI. &lt;/p&gt;  &lt;p&gt;It is worth noting that the Mozilla browser itself is actually just a set of packages containing XUL files, JavaScript and style sheets. These files are accessed via a chrome URL and have enhanced privileges and work just like any other package. Of course, the browser is much larger and more sophisticated than most extensions. Firefox and Thunderbird as well as number of other components are all written in XUL and are all accessible via chrome URLs. You can examine these packages by looking in the chrome directory where Firefox or another XUL application is installed. &lt;/p&gt;  &lt;p&gt;The chrome URL always begins with 'chrome://'. Much like how the 'http://' URL always refers to remote web sites accessed using HTTP and the 'file://' URL always refers to local files, the 'chrome://' URL always refers to installed packages and extensions. We'll look more at the syntax of a chrome URL in the next section. It is important to note that when accessing content through a chrome URL, it gains the enhanced privileges described above that other kinds of URLs do not. For instance, an HTTP URL does not have any special privileges, and an error will occur if a web page tries, for example, to read a local file. However, a file loaded via a chrome URL will be able to read files without restriction. &lt;/p&gt;  &lt;p&gt;This distinction is important. This means that there are certain things that content of web pages cannot do, such as read the user's bookmarks. This distinction is not based on the kind of content being displayed; only on the type of URL used. Both HTML and XUL placed on a web site have no extra permissions; however both HTML and XUL loaded through a chrome URL have enhanced permissions. &lt;/p&gt;  &lt;p&gt;If you are going to use XUL on a web site, you can just put the XUL file on the web site as you would an HTML file, and then load its URL in a browser &lt;small&gt;http://localhost/xul.php&lt;/small&gt;. Ensure that your web server is configured to send XUL files with the content type of &lt;b&gt;&lt;code&gt;application/vnd.mozilla.xul+xml&lt;/code&gt;&lt;/b&gt; (eg with PHP &lt;code&gt;header('Content-type: application/vnd.mozilla.xul+xml');&lt;/code&gt;). This content type is how Mozilla knows the difference between HTML and XUL. Mozilla does not use the file extension, unless reading files from the file system, but you should use the &lt;tt&gt;.xul&lt;/tt&gt; extension for all XUL files. You can load XUL files from your own machine by opening them in the browser, or by double-clicking the file in your file manager. &lt;/p&gt;  &lt;p&gt;Remember that remote XUL will have significant restrictions on what it can do. &lt;/p&gt;  &lt;p&gt;&lt;a name="Document_types:_HTML_XML_XUL_CSS"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h5&gt;[&lt;a href="http://developer.mozilla.org/en/docs/index.php?title=XUL_Tutorial:XUL_Structure&amp;amp;action=edit&amp;amp;section=2"&gt;edit&lt;/a&gt;] Document types: HTML XML XUL CSS&lt;/h5&gt;  &lt;p&gt;Mozilla uses a distinctly different kind of document object (&lt;a href="http://developer.mozilla.org/en/docs/DOM"&gt;DOM&lt;/a&gt;) for HTML and XUL, although they share most of their functionality. There are three main types of document in Mozilla: HTML, XML, and XUL. Naturally, the HTML document is used for HTML documents, the XUL document is used for XUL documents, and the XML document is used for other types of XML documents. Since XUL is also XML, the XUL document is a subtype of the more generic XML document. There are subtle differences in functionality. For example, while the form controls on an HTML page are accessible via the &lt;code&gt;document.forms&lt;/code&gt; property, this property isn't available for XUL documents, since XUL doesn't have forms in the HTML sense. Likewise, XUL specific features such as overlays and templates are only available in XUL documents. &lt;/p&gt;  &lt;p&gt;This distinction between documents is important. It is possible to use many XUL features in HTML or XML documents since they aren't document type specific; however other features require the right kind of document. For instance, you can use the XUL layout types in other documents since they don't rely on the XUL document type to function. &lt;/p&gt;  &lt;p&gt;To summarize the points made above: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Mozilla renders both &lt;a href="http://developer.mozilla.org/en/docs/HTML"&gt;HTML&lt;/a&gt; and &lt;a href="http://developer.mozilla.org/en/docs/XUL"&gt;XUL&lt;/a&gt; using the same underlying engine and uses &lt;a href="http://developer.mozilla.org/en/docs/CSS"&gt;CSS&lt;/a&gt; to specify their presentation. &lt;/li&gt;    &lt;li&gt;XUL may be loaded from a remote site, the local file system, or installed as a package and accessed using a &lt;a href="http://developer.mozilla.org/en/docs/chrome"&gt;chrome&lt;/a&gt; URL. This last option is what browser extensions do. &lt;/li&gt;    &lt;li&gt;Chrome URLs may be used to access installed packages and open them with enhanced privileges. &lt;/li&gt;    &lt;li&gt;HTML, XML, and XUL each have a different document type. Some features may be used in any document type whereas some features are specific to one kind of document. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The next few sections describe the basic structure of a chrome package which can be installed into Mozilla. However, if you just want to get started building a simple application, you may skip ahead to &lt;a href="http://developer.mozilla.org/en/docs/XUL_Tutorial:Creating_a_Window"&gt;Creating a Window&lt;/a&gt; and save this section for later. &lt;/p&gt;  &lt;p&gt;&lt;a name="Package_Organization"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h4&gt;[&lt;a href="http://developer.mozilla.org/en/docs/index.php?title=XUL_Tutorial:XUL_Structure&amp;amp;action=edit&amp;amp;section=3"&gt;edit&lt;/a&gt;] Package Organization &lt;/h4&gt;  &lt;p&gt;Mozilla is organized in such a way that you can have as many components as you want pre-installed. Each extension is also a component with a separate chrome URL. It also has one component for each installed theme and locale. Each of these components, or packages, is made up of a set of files that describe the user interface for it. For example, the messenger component has descriptions of the mail messages list window, the composition window and the address book dialogs. &lt;/p&gt;  &lt;p&gt;The packages that are provided with Mozilla are located within the chrome directory, which are in the directory where you installed Mozilla. The chrome directory is where you find all the files that describe the user interface used by the Mozilla browser, mail client, and other applications. Typically, you put all the XUL files for an application in this directory, although extensions are installed in the extensions directory for a particular user. Just copying a XUL file into the &lt;tt&gt;chrome&lt;/tt&gt; directory doesn't give the file any extra permissions, nor can it be accessed via a chrome URL. To gain the extra privileges, you will need to create a manifest file and put that in the chrome directory. This file is easy to create, as it is typically only a couple of lines long. It is used to map a chrome URL to a file or directory path on the disk where the XUL files are located. Details of how to create this file will be discussed in a &lt;a href="http://developer.mozilla.org/en/docs/XUL_Tutorial:Manifest_Files"&gt;later section&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;The only way to create content that can be accessed through a chrome URL is by creating a package as described in the next few sections. This directory is called 'chrome' likely because it seemed like a convenient name to use for the directory where the chrome packages that are included with Mozilla are kept. &lt;/p&gt;  &lt;p&gt;To further the confusion, there are two other places where the word &amp;quot;chrome&amp;quot; might appear. These are the &lt;code&gt;-chrome&lt;/code&gt; command line argument and the &lt;code&gt;chrome&lt;/code&gt; modifier to the &lt;code&gt;&lt;a href="http://developer.mozilla.org/en/docs/DOM:window.open"&gt;window.open()&lt;/a&gt;&lt;/code&gt; function. Neither of these features grant extra privileges; instead they are used to open a new top-level window without the browser UI such as the menu and toolbar. You will commonly use this feature in more complex XUL applications since you wouldn't want the browser UI to exist around your dialog boxes. &lt;/p&gt;  &lt;p&gt;The files for a package are usually combined into a single JAR file. A JAR file may created and examined using a ZIP utility. For instance, you can open the JAR files in Mozilla's &lt;tt&gt;chrome&lt;/tt&gt; directory to see the basic structure of a package. Although it's normal to combine the files into a JAR file, packages may also be accessed in expanded form into a directory. Although you don't normally distribute a package this way, it is handy during development since you can edit the file directly and then reload the XUL file without having to repackage or reinstall the files. &lt;/p&gt;  &lt;p&gt;By default, Mozilla applications parse XUL files and scripts, and store a pre-compiled version in memory for the remainder of the application session. This improves performance. However, because of this, the XUL will be not be reloaded even when the source files are changed. To disable this mechanism, it is necessary to change the preference &lt;code&gt;nglayout.debug.disable_xul_cache&lt;/code&gt;. In Firefox, this preference may be added to the user preferences by typing &amp;quot;about:config&amp;quot; in the address field, and setting this value to true. Or, just manually edit your &lt;tt&gt;user.js&lt;/tt&gt; preferences file and add the following line: &lt;/p&gt;  &lt;pre&gt;pref(&amp;quot;nglayout.debug.disable_xul_cache&amp;quot;, true);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;There are usually three different parts to a chrome package, although they are all optional. Each part is stored in a different directory. These three sets are the content, the skin, and the locale, which are all described below. A particular package might provide one or more skins and locales, but a user can replace them with their own. In addition, the package might include several different applications, each accessible via different chrome URLs. The packaging system is flexible enough so that you can include whatever parts you need and allow other parts, such as the text for different languages, to be downloaded separately. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The three types of chrome packages are: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;  &lt;li&gt;&lt;b&gt;Content&lt;/b&gt; - Windows and scripts &lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;The declarations of the windows and the user interface elements contained within them. These are stored in XUL files, which have a &lt;tt&gt;.xul&lt;/tt&gt; extension. A content package can have multiple XUL files, but the main window should have a filename that is the same as the package name. For example, the editor package will have a file within it called &lt;tt&gt;editor.xul&lt;/tt&gt;. Scripts are placed in separate files alongside the XUL files. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;&lt;b&gt;Skin&lt;/b&gt; - Style sheets, images and other theme specific files &lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;Style sheets describe details of the appearance of a window. They are stored separately from XUL files to facilitate modifying the skin (theme) of an application. Any images used are stored here also. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;&lt;b&gt;Locale&lt;/b&gt; - Locale specific files &lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;All the text that is displayed within a window is stored separately. This way, a user can have a set for their own language. &lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;a name="Content_Packages"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;[&lt;a href="http://developer.mozilla.org/en/docs/index.php?title=XUL_Tutorial:XUL_Structure&amp;amp;action=edit&amp;amp;section=4"&gt;edit&lt;/a&gt;] Content Packages &lt;/h4&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The name of the JAR file might describe what it contains, but you can't be sure unless you view its contents. Let's use the browser package included with Firefox as an example. If you extract the files in &lt;tt&gt;browser.jar&lt;/tt&gt;, you will find that it contains a directory structure much like the following: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;content&lt;br /&gt;   browser&lt;br /&gt;      browser.xul&lt;br /&gt;      browser.js&lt;br /&gt;      -- other browser XUL and JS files goes here --&lt;br /&gt;      bookmarks&lt;br /&gt;         -- bookmarks files go here --&lt;br /&gt;      preferences&lt;br /&gt;         -- preferences files go here --&lt;br /&gt;.&lt;br /&gt;.&lt;br /&gt;.&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This is easily recognizable as a content package, as the top-level directory is called &lt;tt&gt;content&lt;/tt&gt;. For skins, this directory will usually be called &lt;tt&gt;skin&lt;/tt&gt; and for locales, it will usually be called &lt;tt&gt;locale&lt;/tt&gt;. This naming scheme isn't necessary, but this is a common convention to make the parts of a package clearer. Some packages may include a content section, a skin, and a locale. In this case, you will find a subdirectory for each type. For example, Chatzilla is distributed in this way. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The &lt;tt&gt;content/browser&lt;/tt&gt; directory contains a number of files with &lt;tt&gt;.xul&lt;/tt&gt; and &lt;tt&gt;.js&lt;/tt&gt; extensions. The XUL files are the ones with the &lt;tt&gt;.xul&lt;/tt&gt; extension. The files with &lt;tt&gt;.js&lt;/tt&gt; extensions are JavaScript files containing scripts that handle the functionality of a window. Many XUL files have a script file associated with them, and some may have more than one. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;In the listing above, two files have been shown. There are of course others, but for simplicity they aren't shown. The file &lt;tt&gt;browser.xul&lt;/tt&gt; is the XUL file that describes the main browser window. The main window for a content package should have the same name as the package with a &lt;tt&gt;.xul&lt;/tt&gt; extension. In this case, the package name is &amp;quot;browser&amp;quot; so we expect to find &lt;tt&gt;browser.xul&lt;/tt&gt;. Some of the other XUL files describe separate windows. For example, the file &lt;tt&gt;pageInfo.xul&lt;/tt&gt; describes the page info dialog. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Many packages will include a &lt;tt&gt;contents.rdf&lt;/tt&gt; file, which describes the package, its author, and the overlays it uses. However, this file is obsolete and has been replaced with a simpler mechanism. This newer method is the manifest file mentioned earlier, and you will find these as files with the &lt;tt&gt;.manifest&lt;/tt&gt; extension in the chrome directory. For instance, &lt;tt&gt;browser.manifest&lt;/tt&gt; describes the browser package. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Several subdirectories, such as &lt;tt&gt;bookmarks&lt;/tt&gt; and &lt;tt&gt;preferences&lt;/tt&gt;, describe additional sections of the browser component. They are placed in different directories only to keep the files more organized. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="Skins_or_Themes"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;[&lt;a href="http://developer.mozilla.org/en/docs/index.php?title=XUL_Tutorial:XUL_Structure&amp;amp;action=edit&amp;amp;section=5"&gt;edit&lt;/a&gt;] Skins or Themes &lt;/h4&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Although the underlying code for Mozilla calls them skins and the user interface calls them themes, they're both referring to the same thing. The &lt;tt&gt;classic.jar&lt;/tt&gt; file describes the default theme provided with Firefox. The structure is similar to the content packages. For example, examining &lt;tt&gt;classic.jar&lt;/tt&gt;: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;skin&lt;br /&gt;   classic&lt;br /&gt;      browser&lt;br /&gt;         browser.css&lt;br /&gt;         -- other browser skin files go here --&lt;br /&gt;      global&lt;br /&gt;         -- global skin files go here --&lt;br /&gt;.&lt;br /&gt;.&lt;br /&gt;.&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Again, this directory structure isn't necessary and is used for convenience. You can actually put all the files in one directory at the top level and not use subdirectories. However, for larger applications, subdirectories are used to separate the different components. In the example above, a directory exists for theme related files for the browser and another for global theme related files. The global directory contains skin files that are general to all packages. These files will apply to all components and will be included with your own standalone applications. The global part defines the appearance of all of the common XUL widgets, whereas the other directories have files that are specific to those applications. Firefox includes both the global and browser theme files in one archive, but they can be included separately. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;A skin is made up of CSS files and a number of images used to define the look of an interface. The file &lt;tt&gt;browser.css&lt;/tt&gt; is used by &lt;tt&gt;browser.xul&lt;/tt&gt; and contains styles that define the appearance of various parts of the browser interface. Again, note how the file &lt;tt&gt;browser.css&lt;/tt&gt; has the same name as the package. By changing the CSS files, you can adjust the appearance of a window without changing its function. This is how you can create a new theme. The XUL part remains the same but the skin part changes independently. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="Locales"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;[&lt;a href="http://developer.mozilla.org/en/docs/index.php?title=XUL_Tutorial:XUL_Structure&amp;amp;action=edit&amp;amp;section=6"&gt;edit&lt;/a&gt;] Locales &lt;/h4&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The file &lt;tt&gt;en-US.jar&lt;/tt&gt; describes the language information for each component, in this case for US English. Like the skins, each language file contains files that specify text used by the package for a specific language. The locale structure is similar to the others, so it won't be listed here. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The localized text is stored in two types of files: DTD files and properties files. The DTD files have a &lt;tt&gt;.dtd&lt;/tt&gt; extension and contain entity declarations, one for each text string that is used in a window. For example, the file &lt;tt&gt;browser.dtd&lt;/tt&gt; contains entity declarations for each menu command. In addition, keyboard shortcuts for each command are also defined, because they may be different for each language. DTD files are used by XUL files so, in general, you will have one per XUL file. The locale part also contains properties files, which are similar, but are used by script files. The file &lt;tt&gt;browser.properties&lt;/tt&gt; contains a few such localized strings. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This structure allows you to translate Mozilla or a component into a different language by just adding a new locale for that language. You don't have to change the XUL code at all. In addition, another person could supply a separate package that applies a skin or locale to your content part, thus providing support for a new theme or language without having to change the original package. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="Other_Packages"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;[&lt;a href="http://developer.mozilla.org/en/docs/index.php?title=XUL_Tutorial:XUL_Structure&amp;amp;action=edit&amp;amp;section=7"&gt;edit&lt;/a&gt;] Other Packages &lt;/h4&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;There is a special package called toolkit (or global). We saw the global directory earlier for skins. The file &lt;tt&gt;toolkit.jar&lt;/tt&gt; contains the corresponding content part for it. It contains some global dialogs and definitions. It also defines the default appearance and functionality of the various common XUL widgets such as textboxes and buttons. The files located in the global part of a skin package contain the default look for all of the XUL interface elements. The toolkit package is used by all XUL applications. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="Adding_a_Package"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;[&lt;a href="http://developer.mozilla.org/en/docs/index.php?title=XUL_Tutorial:XUL_Structure&amp;amp;action=edit&amp;amp;section=8"&gt;edit&lt;/a&gt;] Adding a Package &lt;/h4&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Mozilla places the packages that are included with the installation in the &lt;tt&gt;chrome&lt;/tt&gt; directory. However, they do not need to be placed there. When installing another package, you can place it anywhere on the disk, as long as a manifest file points to it. It is common to place packages into the &lt;tt&gt;chrome&lt;/tt&gt; directory simply because it is convenient; however, they will work just as well from another directory or somewhere on your local network. You cannot store them on a remote site, unless the remote site is mounted through the local file system. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;There are two &lt;tt&gt;chrome&lt;/tt&gt; directories used for XUL applications: one is installed in the same place where the application is installed, while the other is part of user's profile. The former allows packages that are shared by all users while the latter allows packages to be created only for a specific user or users. Extensions, while installed in a separate extensions directory, are also usually user specific. Any manifest files located in either chrome directory will be examined to see which packages are installed. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;In the next section, we'll look at how to refer to chrome packages using the chrome URL. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1316352013241370780-97186505537630917?l=fzhong.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://fzhong.blogspot.com/feeds/97186505537630917/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1316352013241370780&amp;postID=97186505537630917' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/97186505537630917'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/97186505537630917'/><link rel='alternate' type='text/html' href='http://fzhong.blogspot.com/2008/03/xul-tutorialxul-structure.html' title='XUL Tutorial:XUL Structure'/><author><name>钟芳林</name><uri>http://www.blogger.com/profile/14620517815530657655</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1316352013241370780.post-3532299099810231878</id><published>2008-03-31T22:01:00.001-07:00</published><updated>2008-03-31T22:01:11.091-07:00</updated><title type='text'>Setting up extension development environment</title><content type='html'>&lt;h3&gt;Setting up extension development environment&lt;/h3&gt;  &lt;h5&gt;From MDC&lt;/h5&gt;  &lt;p&gt;This article gives suggestions on how to set up your Mozilla application for extension development. &lt;/p&gt;  &lt;h4&gt;Contents&lt;/h4&gt; [&lt;a href="http://developer.mozilla.org/"&gt;hide&lt;/a&gt;]   &lt;ul&gt;   &lt;li&gt;&lt;a href="http://developer.mozilla.org/en/docs/Setting_up_extension_development_environment#Development_preferences"&gt;1 Development preferences&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://developer.mozilla.org/en/docs/Setting_up_extension_development_environment#Development_extensions"&gt;2 Development extensions&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://developer.mozilla.org/en/docs/Setting_up_extension_development_environment#Development_profile"&gt;3 Development profile&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://developer.mozilla.org/en/docs/Setting_up_extension_development_environment#Custom_code_location"&gt;4 Custom code location&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://developer.mozilla.org/en/docs/Setting_up_extension_development_environment#Using_directories_rather_than_JARs"&gt;5 Using directories rather than JARs&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a name="Development_preferences"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h4&gt;[&lt;a href="http://developer.mozilla.org/en/docs/index.php?title=Setting_up_extension_development_environment&amp;amp;action=edit&amp;amp;section=1"&gt;edit&lt;/a&gt;] Development preferences&lt;/h4&gt;  &lt;p&gt;These preferences will make debugging easier at the expense of lower performance. &lt;/p&gt;  &lt;p&gt;See &lt;a href="http://www.mozilla.org/support/firefox/edit"&gt;Editing Configuration Files&lt;/a&gt; for information on setting preferences. Note that some of these preferences are not listed in &lt;tt&gt;about:config&lt;/tt&gt; by default, so you'll need to create new (boolean) entries for them. &lt;/p&gt;  &lt;p&gt;See below under &amp;quot;Development Profile&amp;quot; to setup a separate development profile before you make these changes. &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;b&gt;javascript.options.showInConsole&lt;/b&gt; = &lt;b&gt;true&lt;/b&gt;. Logs errors in chrome files to the &lt;a href="http://developer.mozilla.org/en/docs/Error_Console"&gt;Error Console&lt;/a&gt;. &lt;/li&gt;    &lt;li&gt;&lt;b&gt;nglayout.debug.disable_xul_cache&lt;/b&gt; = &lt;b&gt;true&lt;/b&gt;. Disables the XUL cache so that changes to windows and dialogs do not require a restart. This assumes you're &lt;a href="http://developer.mozilla.org/en/docs/Setting_up_extension_development_environment#Using_directories_rather_than_JARs"&gt;using directories rather than JARs&lt;/a&gt;. Changes to XUL overlays will still require reloading of the document overlaid. &lt;/li&gt;    &lt;li&gt;&lt;b&gt;browser.dom.window.dump.enabled&lt;/b&gt; = &lt;b&gt;true&lt;/b&gt;. Enables the use of the dump() statement to print to the standard console. See &lt;code&gt;&lt;a href="http://developer.mozilla.org/en/docs/DOM:window.dump"&gt;window.dump&lt;/a&gt;&lt;/code&gt; for more info. You can also use &lt;code&gt;&lt;a href="http://developer.mozilla.org/en/docs/nsIConsoleService"&gt;nsIConsoleService&lt;/a&gt;&lt;/code&gt; from privileged script. &lt;/li&gt;    &lt;li&gt;&lt;b&gt;javascript.options.strict&lt;/b&gt; = &lt;b&gt;true&lt;/b&gt;. Enables strict JavaScript warnings in the Error Console. Note that since many people have this setting turned off when developing, you will see lots of warnings for problems with their code in addition to warnings for your own extension. You can filter those with &lt;a href="https://addons.mozilla.org/en-US/firefox/addon/1815"&gt;Console&lt;sup&gt;2&lt;/sup&gt;&lt;/a&gt;. &lt;/li&gt; &lt;/ul&gt; &lt;a name="Development_extensions"&gt;&lt;/a&gt;  &lt;h4&gt;[&lt;a href="http://developer.mozilla.org/en/docs/index.php?title=Setting_up_extension_development_environment&amp;amp;action=edit&amp;amp;section=2"&gt;edit&lt;/a&gt;] Development extensions&lt;/h4&gt;  &lt;p&gt;These extensions may help you with your development. &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;DOM Inspector, an option of a custom installation. &lt;/li&gt;    &lt;li&gt;&lt;a href="https://addons.mozilla.org/en-US/firefox/addon/216"&gt;Venkman&lt;/a&gt;, a JavaScript Debugger. &lt;/li&gt;    &lt;li&gt;&lt;a href="http://ted.mielczarek.org/code/mozilla/extensiondev/"&gt;Extension Developer's Extension&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="https://addons.mozilla.org/en-US/firefox/addon/1815"&gt;Console&lt;sup&gt;2&lt;/sup&gt;&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="https://addons.mozilla.org/firefox/4453"&gt;Chrome List&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="https://addons.mozilla.org/en-US/firefox/addon/1843"&gt;Firebug&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="https://addons.mozilla.org/de/firefox/addon/1729"&gt;Execute JS&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://xpcomviewer.mozdev.org"&gt;XPCOMViewer&lt;/a&gt;, an XPCOM inspector &lt;/li&gt; &lt;/ul&gt; &lt;a name="Development_profile"&gt;&lt;/a&gt;  &lt;h4&gt;[&lt;a href="http://developer.mozilla.org/en/docs/index.php?title=Setting_up_extension_development_environment&amp;amp;action=edit&amp;amp;section=3"&gt;edit&lt;/a&gt;] Development profile&lt;/h4&gt;  &lt;p&gt;To avoid the performance hit of development-related prefs and extensions, and to avoid borking your personal data, you can use a separate profile for development work. &lt;/p&gt;  &lt;p&gt;You can run two instances of Firefox using separate profiles if you start Firefox with the &lt;tt&gt;-no-remote&lt;/tt&gt; parameter. For example, the following command will run your development profile whether &amp;quot;normal&amp;quot; Firefox is already running or not. (Assuming your development profile is called &amp;quot;dev&amp;quot;): &lt;/p&gt;  &lt;pre&gt;start &amp;quot;&amp;quot; &amp;quot;%ProgramFiles%\Mozilla Firefox\firefox.exe&amp;quot; -no-remote -P dev&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;To run Firefox with default profile just run &amp;quot;firefox&amp;quot; or &amp;quot;firefox -P default&amp;quot;, as usual. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="Custom_code_location"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;[&lt;a href="http://developer.mozilla.org/en/docs/index.php?title=Setting_up_extension_development_environment&amp;amp;action=edit&amp;amp;section=4"&gt;edit&lt;/a&gt;] Custom code location&lt;/h4&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Rather than having to constantly reinstall the extension whenever you change something and to protect your source files from accidental deletion when uninstalling, you can place your source outside your profile in a location of your choosing. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;  &lt;li&gt;Find the extension ID from the install.rdf included with your extension &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;Create a file in your_profile_directory/extensions/ with the above ID as the filename (eg. `your_profile_directory/extensions/{46D1B3C0-DB7A-4b1a-863A-6EE6F77ECB58}`) (&lt;a href="http://kb.mozillazine.org/Profile_folder"&gt;Find your profile directory&lt;/a&gt;) &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;The contents of this file should be the path to the folder that contains your install.rdf file. (eg. `/full/path/to/yourExtension`. Windows users should use the drive name (CAPS) and backslashes instead of slashes: eg. `C:\full\path\to\yourExtension`). In Firefox 3, if you already the extension installed via XPI, you might need to install one or all of the extensions.* files in the profile folder. Backup first, but these files will be regenerated. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;Place the file in the extensions folder of your profile and restart the application. &lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;a name="Using_directories_rather_than_JARs"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;[&lt;a href="http://developer.mozilla.org/en/docs/index.php?title=Setting_up_extension_development_environment&amp;amp;action=edit&amp;amp;section=5"&gt;edit&lt;/a&gt;] Using directories rather than JARs&lt;/h4&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Regardless of whether you choose to package your extension's chrome in a JAR or in directories, developing in directories is simpler. If you choose a JARed structure for releasing, you can still develop with a directory structure by editing your chrome.manifest. For example, rather than having &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;content	myExtension	jar:chrome/myExtension.jar!/content/&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;use &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;content	myExtension	chrome/content/&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1316352013241370780-3532299099810231878?l=fzhong.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://fzhong.blogspot.com/feeds/3532299099810231878/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1316352013241370780&amp;postID=3532299099810231878' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/3532299099810231878'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/3532299099810231878'/><link rel='alternate' type='text/html' href='http://fzhong.blogspot.com/2008/03/setting-up-extension-development.html' title='Setting up extension development environment'/><author><name>钟芳林</name><uri>http://www.blogger.com/profile/14620517815530657655</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1316352013241370780.post-1925034772300331415</id><published>2007-05-21T20:54:00.000-07:00</published><updated>2007-05-21T20:55:35.349-07:00</updated><title type='text'>QT程序的Jpeg图像不能显示的问题</title><content type='html'>&lt;div class=Section1&gt;  &lt;p class=MsoNormal&gt;&lt;span style='font-size:9.0pt;font-family:"Tahoma","sans-serif"; color:black'&gt;QT&lt;/span&gt;&lt;span style='font-size:9.0pt;font-family:宋体;color:black'&gt;编译的程序在本机编译后到目标机器不能显示&lt;/span&gt;&lt;span style='font-size:9.0pt;font-family:"Tahoma","sans-serif";color:black'&gt;Jpeg&lt;/span&gt;&lt;span style='font-size:9.0pt;font-family:宋体;color:black'&gt;图像，需要把&lt;/span&gt;&lt;span style='font-size:9.0pt;font-family:"Tahoma","sans-serif";color:black'&gt;QT&lt;/span&gt;&lt;span style='font-size:9.0pt;font-family:宋体;color:black'&gt;目录下的&lt;/span&gt;&lt;span style='font-size:9.0pt;font-family:"Tahoma","sans-serif";color:black'&gt;plugins/imageformats&lt;/span&gt;&lt;span style='font-size:9.0pt;font-family:宋体;color:black'&gt;目录下的&lt;/span&gt;&lt;span style='font-size:9.0pt;font-family:"Tahoma","sans-serif";color:black'&gt;jpeg1.dll&lt;/span&gt;&lt;span style='font-size:9.0pt;font-family:宋体;color:black'&gt;等图片格式支持文件一起发布到目标应用程序的目录的&lt;/span&gt;&lt;span style='font-size:9.0pt;font-family:"Tahoma","sans-serif";color:black'&gt;imageformats&lt;/span&gt;&lt;span style='font-size:9.0pt;font-family:宋体;color:black'&gt;目录下&lt;/span&gt;&lt;span lang=EN-US&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1316352013241370780-1925034772300331415?l=fzhong.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://fzhong.blogspot.com/feeds/1925034772300331415/comments/default' title='帖子评论'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1316352013241370780&amp;postID=1925034772300331415' title='0 条评论'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/1925034772300331415'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1316352013241370780/posts/default/1925034772300331415'/><link rel='alternate' type='text/html' href='http://fzhong.blogspot.com/2007/05/qtjpeg.html' title='QT程序的Jpeg图像不能显示的问题'/><author><name>钟芳林</name><uri>http://www.blogger.com/profile/14620517815530657655</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
