[erlang-patches] wx_object fixes.

Dan Gudmundsson dangud@REDACTED
Fri Oct 9 14:50:33 CEST 2009


Thanks I'll have look at it.

/Dan

On Fri, Oct 9, 2009 at 1:14 PM, Mazen Harake
<mazen.harake@REDACTED> wrote:
> I've attached a patch that fixes two issues with the wx_object.erl file.
>
> 1) I removed a pattern match in the start functions so that if a server
> returns {stop, ...} in the init function it doesn't crash with a badmatch
> error.
>
> 2) I added 2 call functions which makes it possible to call an wx_object
> using the registered name that was used when creating the object. Currently
> it was only possible to make a call to an object when you have the reference
> and not by name.
>
> I have tested it in normal cases but I can't guarantee 100% bugfree fixes :D
> This patch will get anyone going until these issues are fixed (or patch
> applied) to the release.
>
> cheers,
>
> /Mazen
>
> --- wx_object.original.erl      2009-09-25 23:22:12.810000000 +0200
> +++ wx_object.erl       2009-10-09 12:22:13.115710400 +0200
> @@ -143,8 +143,7 @@
>  %% @doc Starts a generic wx_object server and invokes Mod:init(Args) in the
>  %% new process.
>  start(Mod, Args, Options) ->
> -    {ok, Pid} = gen:start(?MODULE, nolink, Mod, Args,
> [get(?WXE_IDENTIFIER)|Options]),
> -    receive {ack, Pid, Ref = #wx_ref{}} -> Ref end.
> +    gen_response(gen:start(?MODULE, nolink, Mod, Args,
> [get(?WXE_IDENTIFIER)|Options])).
>
>  %% @spec (Name, Mod, Args, Options) -> wxWindow:wxWindow()
>  %%   Name = {local, atom()}
> @@ -155,8 +154,7 @@
>  %% @doc Starts a generic wx_object server and invokes Mod:init(Args) in the
>  %% new process.
>  start(Name, Mod, Args, Options) ->
> -    {ok, Pid} = gen:start(?MODULE, nolink, Name, Mod, Args,
> [get(?WXE_IDENTIFIER)|Options]),
> -    receive {ack, Pid, Ref = #wx_ref{}} -> Ref end.
> +    gen_response(gen:start(?MODULE, nolink, Name, Mod, Args,
> [get(?WXE_IDENTIFIER)|Options])).
>
>  %% @spec (Mod, Args, Options) -> wxWindow:wxWindow()
>  %%   Mod = atom()
> @@ -166,8 +164,7 @@
>  %% @doc Starts a generic wx_object server and invokes Mod:init(Args) in the
>  %% new process.
>  start_link(Mod, Args, Options) ->
> -    {ok, Pid} = gen:start(?MODULE, link, Mod, Args,
> [get(?WXE_IDENTIFIER)|Options]),
> -    receive {ack, Pid, Ref = #wx_ref{}} -> Ref end.
> +    gen_response(gen:start(?MODULE, link, Mod, Args,
> [get(?WXE_IDENTIFIER)|Options])).
>
>  %% @spec (Name, Mod, Args, Options) -> wxWindow:wxWindow()
>  %%   Name = {local, atom()}
> @@ -177,9 +174,13 @@
>  %%   Flag = trace | log | {logfile, File} | statistics | debug
>  %% @doc Starts a generic wx_object server and invokes Mod:init(Args) in the
>  %% new process.
> -start_link(Name, Mod, Args, Options) ->
> -    {ok, Pid} = gen:start(?MODULE, link, Name, Mod, Args,
> [get(?WXE_IDENTIFIER)|Options]),
> -    receive {ack, Pid, Ref = #wx_ref{}} -> Ref end.
> +start_link(Name, Mod, Args, Options) ->
> +    gen_response(gen:start(?MODULE, link, Name, Mod, Args,
> [get(?WXE_IDENTIFIER)|Options])).
> +
> +gen_response({ok, Pid}) ->
> +    receive {ack, Pid, Ref = #wx_ref{}} -> Ref end;
> +gen_response(Reply) ->
> +    Reply.
>
>  %% @spec(wxObject(), Request) -> term()
>  %% @doc Make a call to a wx_object server.
> @@ -190,7 +191,18 @@
>        Res
>     catch _:Reason ->
>            erlang:error({Reason, {?MODULE, call, [Ref, Request]}})
> -    end.
> +    end;
> +%% @spec(atom(), Request) -> term()
> +%% @doc Make a call to a registered wx_object server
> +%% Invokes handle_call(Request, From, State) in server
> +call(Name, Request) when is_atom(Name) ->
> +    try
> +        {ok,Res} = gen:call(Name, '$gen_call', Request),
> +        Res
> +    catch _:Reason ->
> +            erlang:error({Reason, {?MODULE, call, [Name, Request]}})
> +    end.
> +
>  %% @spec(wxObject(), Request, integer()) -> term()
>  %% @doc Make a call to a wx_object server.
>  %% Invokes handle_call(Request, From, State) in server
> @@ -200,6 +212,16 @@
>        Res
>     catch _:Reason ->
>            erlang:error({Reason, {?MODULE, call, [Ref, Request, Timeout]}})
> +    end;
> +%% @spec(atom(), Request, integer()) -> term()
> +%% @doc Make a call to a registered wx_object server
> +%% Invokes handle_call(Request, From, State) in server
> +call(Name, Request, Timeout) when is_atom(Name) ->
> +    try
> +        {ok,Res} = gen:call(Name, '$gen_call', Request, Timeout),
> +        Res
> +    catch _:Reason ->
> +            erlang:error({Reason, {?MODULE, call, [Name, Request,
> Timeout]}})
>     end.
>
>  %% -----------------------------------------------------------------
>
>
> ________________________________________________________________
> erlang-patches mailing list. See http://www.erlang.org/faq.html
> erlang-patches (at) erlang.org
>


More information about the erlang-patches mailing list