[erlang-questions] hierarchical behaviour doesn't seem to work ?

Fernando "Brujo" Benavides fernando.benavides@REDACTED
Tue Dec 13 18:47:27 CET 2011


Hi, I think it basically depends on how do you define your my_behaviour module.
This is an example of a module that implements gen_server but defines its own behaviour (called itweep).
You can see there the gen_server is started using itweep as the callback module, but itweep is started using the desired callback module (in your case, client), for instance:

start(Mod, Args, Options) ->
  …
  gen_server:start(?MODULE, {Mod, Args, User, Password, StreamTimeout}, OtherOptions).

That way, the gen_server uses itweep callback functions, but itweep itself uses client callback functions.

Hope this helps,
Cheers!

On 13/12/2011, at 14:37, Harald Welte wrote:

> Hi!
> 
> I am trying to get some code to work, but I have the feeling that
> hierarchical/netsted 'behaviour' doens't really work quite well.
> 
> Let's assume I want to defined a behaviour, which in turn is derived
> from gen_server.  The name of the module is "my_behaviour".  It exports
> the required "behaviour_info/1" function, and implements all the
> gen_server call-backs.
> 
> Then, I'm creating an actual program, let's call it "client".
> "client.erl" states "-behaviour(my_behaviour)" and implements the
> required call-backs of my_behaviour.
> 
> However, now if the runtime delivers something like a gen_server method
> such as gen_cast/gen_call, etc., it tries to call client:handle_cast()
> instead of the my_behaviour:handle_cast().  And since
> client:handle_cast() is not defined, it will crash the process.
> 
> Is this really the intended behaviour (sic) of behaviour?
> 
> To me, it seems most logical that you would want to implement levels of
> common functionality in a behaviour, and "sub-class" a number of different
> implementations off such a behaviour.  And since all of it should be OTP
> compliant, that custom behaviour itself would  be based on some OTP
> behaviour like gen_server, gen_fsm, etc.
> 
> Any comments?  Am I misunderstanding something here?  Thanks!
> -- 
> - Harald Welte <laforge@REDACTED>           http://laforge.gnumonks.org/
> ============================================================================
> "Privacy in residential applications is a desirable marketing option."
>                                                  (ETSI EN 300 175-7 Ch. A6)
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

____________________________
Fernando "Brujo" Benavides
fernando.benavides@REDACTED

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20111213/b3c4b527/attachment.htm>


More information about the erlang-questions mailing list