anchor.diff:  %% @end
   -module(dbus_peer_connection).
   
  --behaviour(gen_fsm).
  +-behaviour(gen_statem).
   -behaviour(dbus_connection).
   
   -include("dbus.hrl").
  
positive.code: %% @end
  -spec cast(pid(), dbus_message()) -> ok | {error, term()}.
  cast(Conn, #dbus_message{}=Msg) when is_pid(Conn) ->
      gen_fsm:send_event(Conn, Msg).
  
  
  %% @doc Launch authentication on this connection
  
negative.code:             {next_state, authenticated, State#state{buf=BufAndData}}
      end;
  
  handle_event({call, From}, auth, authenticated, _State) ->
      gen_statem:reply(From, authenticated),
      keep_state_and_data;
  
  handle_event({call, {Pid, Tag}=From}, {call, #dbus_message{}=Msg}, authenticated, 
                #state{sock=Sock, serial=S, pending=Pending}=State) ->
      Data = dbus_marshaller:marshal_message(dbus_message:set_serial(S, Msg)),
      true = ets:insert(Pending, {S, Pid, Tag}),
      ok = dbus_transport:send(Sock, Data),
      gen_statem:reply(From, {ok, {self(), Tag}}),
      {keep_state, State#state{serial=S+1}};
  
  %% Other
  handle_event(info, closed, _, State) ->
      ?error("Connection closed...~n", []),
      {stop, closed, State};
  
  %% Unhandled
  handle_event(_, Evt, StateName, State) ->
      ?error("Unhandled event: ~p~n", [Evt]),
      {next_state, StateName, State}.
  
  
  