<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Hi, I think it basically depends on how do you define your my_behaviour module.</div><div><a href="https://github.com/inaka/itweet/blob/master/src/itweep.erl">This</a> is an example of a module that implements gen_server but defines its own behaviour (called itweep).</div><div>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:</div><div><br></div><div><pre style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font: normal normal normal 12px/normal 'Bitstream Vera Sans Mono', Courier, monospace; font-family: 'Bitstream Vera Sans Mono', Courier, monospace; font-size: 12px; line-height: 1.4; font-style: normal; font-variant: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); position: static; color: rgb(0, 0, 0); z-index: auto; "><div class="line" id="LC127" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 1em; "><span class="nf" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(153, 0, 0); font-weight: bold; ">start</span><span class="p" style="font-weight: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">(</span><span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 128, 128); "><b>Mod</b></span><span class="p" style="font-weight: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">,</span> <span class="nv" style="font-weight: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 128, 128); ">Args</span><span class="p" style="font-weight: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">,</span> <span class="nv" style="font-weight: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 128, 128); ">Options</span><span class="p" style="font-weight: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">)</span> <span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-weight: bold; ">-></span></div><div class="line" id="LC128" style="font-weight: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 1em; "> …</div><div class="line" id="LC129" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 1em; "> <span class="nn" style="font-weight: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(85, 85, 85); ">gen_server</span><span class="p" style="font-weight: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">:</span><span class="n" style="font-weight: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">start</span><span class="p" style="font-weight: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">(</span><span class="o" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">?</span><span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 128, 128); "><b>MODULE</b></span><span class="p" style="font-weight: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">,</span> <span class="p" style="font-weight: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">{</span><span class="nv" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 128, 128); "><b>Mod</b></span><span class="p" style="font-weight: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">,</span> <span class="nv" style="font-weight: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 128, 128); ">Args</span><span class="p" style="font-weight: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">,</span> <span class="nv" style="font-weight: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 128, 128); ">User</span><span class="p" style="font-weight: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">,</span> <span class="nv" style="font-weight: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 128, 128); ">Password</span><span class="p" style="font-weight: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">,</span> <span class="nv" style="font-weight: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 128, 128); ">StreamTimeout</span><span class="p" style="font-weight: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">},</span> <span class="nv" style="font-weight: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(0, 128, 128); ">OtherOptions</span><span class="p" style="font-weight: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">).</span></div></pre><div><br></div></div><div>That way, the gen_server uses itweep callback functions, but itweep itself uses <i>client</i> callback functions.</div><div><br></div><div>Hope this helps,</div><div>Cheers!</div><br><div><div>On 13/12/2011, at 14:37, Harald Welte wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Hi!<br><br>I am trying to get some code to work, but I have the feeling that<br>hierarchical/netsted 'behaviour' doens't really work quite well.<br><br>Let's assume I want to defined a behaviour, which in turn is derived<br>from gen_server. The name of the module is "my_behaviour". It exports<br>the required "behaviour_info/1" function, and implements all the<br>gen_server call-backs.<br><br>Then, I'm creating an actual program, let's call it "client".<br>"client.erl" states "-behaviour(my_behaviour)" and implements the<br>required call-backs of my_behaviour.<br><br>However, now if the runtime delivers something like a gen_server method<br>such as gen_cast/gen_call, etc., it tries to call client:handle_cast()<br>instead of the my_behaviour:handle_cast(). And since<br>client:handle_cast() is not defined, it will crash the process.<br><br>Is this really the intended behaviour (sic) of behaviour?<br><br>To me, it seems most logical that you would want to implement levels of<br>common functionality in a behaviour, and "sub-class" a number of different<br>implementations off such a behaviour. And since all of it should be OTP<br>compliant, that custom behaviour itself would be based on some OTP<br>behaviour like gen_server, gen_fsm, etc.<br><br>Any comments? Am I misunderstanding something here? Thanks!<br>-- <br>- Harald Welte <<a href="mailto:laforge@gnumonks.org">laforge@gnumonks.org</a>> <a href="http://laforge.gnumonks.org/">http://laforge.gnumonks.org/</a><br>============================================================================<br>"Privacy in residential applications is a desirable marketing option."<br> (ETSI EN 300 175-7 Ch. A6)<br>_______________________________________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>http://erlang.org/mailman/listinfo/erlang-questions<br></div></blockquote></div><br><div>
<div><font class="Apple-style-span" face="Verdana"><b>____________________________</b></font></div><div><font class="Apple-style-span" face="Verdana"><b>Fernando "Brujo" Benavides</b></font></div><div><font class="Apple-style-span" face="Verdana"><a href="mailto:fernando.benavides@inakanetworks.com">fernando.benavides@inakanetworks.com</a></font></div>
</div>
<br></body></html>