Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1902793
  • 博文数量: 217
  • 博客积分: 4362
  • 博客等级: 上校
  • 技术积分: 4180
  • 用 户 组: 普通用户
  • 注册时间: 2009-09-20 09:31
文章分类

全部博文(217)

文章存档

2017年(1)

2015年(2)

2014年(2)

2013年(6)

2012年(42)

2011年(119)

2010年(28)

2009年(17)

分类: LINUX

2011-03-25 13:33:53

erlang gen_fsm模式模板:
%%File Name:pro_ureq.erl
%%Using:This module is used for processing user's request which is "MASTER_VM_START".
%%The command is used for select a NC.
-module(pro_ureq).
-behaviour(gen_fsm).
-export([start/1]).
-export([message/1]).
-export([init/1, nc_unvailable/2, nc_available/2, code_change/4, handle_info/3]).
-export([handle_event/3, terminate/3, handle_sync_event/4]).
start(AllResource) ->
   
    gen_fsm:start_link({local, pro_ureq}, pro_ureq, AllResource, []).
message(Msg) ->
    gen_fsm:send_event(pro_ureq, {button, Msg}).

%%%Callback function
nc_unvailable({button, Msg}, {_SoFar, AllResource}) ->
    io:format("~p   ~p~n",[AllResource, Msg]),
    {next_state, nc_available, {[], AllResource}}.
nc_available(A, State) ->
    io:format("ssssssssssssssss~p~n", [A]),
    {next_state, nc_unvailable, State}.
init(AllResource) ->
    {ok, nc_unvailable, {[], AllResource}}.
code_change(_OldVsn, StateName, StateData, _Extra) ->
    {ok, StateName, StateData}.
handle_info(Info, StateName, StateData) ->
%%%%return Result
    {Info, StateName, StateData}.
handle_event(Event, StateName, StateData) ->
%%%%return Result
    {Event, StateName, StateData}.
terminate(_Reason, _StateName, _StateData) ->
    ok.
handle_sync_event(Event, From, StateName, StateData) ->
%%%%return Result
    {Event, From, StateName, StateData}.
阅读(10117) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~