anchor.diff:      end.
   
   
  +handle_stop_device_request( DeviceId, From, State ) ->
  +    do_handle_stop_device_request(
  +        orddict:find( DeviceId, State#state.devices ),
  +        From, State
  +     ).
  +
  +do_handle_stop_device_request( { ok, Device }, From, State ) ->
  +    ok = lurch_device:stop( Device#device.id ),
  +    NewDevice = Device#device{
  +        state = stopping,
  +        stopped_by = [ From | Device#device.stopped_by ]
  +    },
  +    NewDevices = orddict:store( Device#device.id, NewDevice, State#state.devices ),
  +    NewState = State#state{ devices = NewDevices },
  +    { noreply, NewState };
  +
  +do_handle_stop_device_request( error, _From, State ) ->
  +    { reply, { error, no_such_device }, State }.
  +
   
   %% ===================================================================
   %% Tests
  
positive.code: %% gen_server callbacks
  %% ===================================================================
  -record( device,
      { id         :: term()
      , os_pid     :: non_neg_integer()
      , driver     :: binary()
      , parameters :: [ binary() ]
      , events     :: [ binary() ]
      , state      :: starting | running | stopping | crashed
      , started_by :: term()
      , stopped_by :: term()
      } ).
  
  -record( state,
  
negative.code:     , fun setup_server_stop/1
      , [ fun test_start_stop_device/1
        , fun test_add_list_devices/1
        , fun test_concurent_stop/1
        ]
      }.
  
  