Android Open Source - sdl_tester_android Sdl Response Factory






From Project

Back to project page sdl_tester_android.

License

The source code is released under:

Copyright (c) 2014, Ford Motor Company All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are m...

If you think the Android project sdl_tester_android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.livio.sdl;
/*w  w  w. java 2  s  .  c om*/
import com.smartdevicelink.protocol.enums.FunctionID;
import com.smartdevicelink.proxy.RPCRequest;
import com.smartdevicelink.proxy.RPCResponse;
import com.smartdevicelink.proxy.interfaces.IProxyListenerALM;
import com.smartdevicelink.proxy.rpc.AddCommandResponse;
import com.smartdevicelink.proxy.rpc.AddSubMenuResponse;
import com.smartdevicelink.proxy.rpc.AlertResponse;
import com.smartdevicelink.proxy.rpc.ChangeRegistrationResponse;
import com.smartdevicelink.proxy.rpc.CreateInteractionChoiceSetResponse;
import com.smartdevicelink.proxy.rpc.DeleteCommandResponse;
import com.smartdevicelink.proxy.rpc.DeleteFileResponse;
import com.smartdevicelink.proxy.rpc.DeleteInteractionChoiceSetResponse;
import com.smartdevicelink.proxy.rpc.DeleteSubMenuResponse;
import com.smartdevicelink.proxy.rpc.GetDTCsResponse;
import com.smartdevicelink.proxy.rpc.GetVehicleDataResponse;
import com.smartdevicelink.proxy.rpc.ListFilesResponse;
import com.smartdevicelink.proxy.rpc.PerformInteractionResponse;
import com.smartdevicelink.proxy.rpc.PutFileResponse;
import com.smartdevicelink.proxy.rpc.ReadDIDResponse;
import com.smartdevicelink.proxy.rpc.ResetGlobalPropertiesResponse;
import com.smartdevicelink.proxy.rpc.ScrollableMessageResponse;
import com.smartdevicelink.proxy.rpc.SetAppIconResponse;
import com.smartdevicelink.proxy.rpc.SetGlobalPropertiesResponse;
import com.smartdevicelink.proxy.rpc.SetMediaClockTimerResponse;
import com.smartdevicelink.proxy.rpc.ShowResponse;
import com.smartdevicelink.proxy.rpc.SliderResponse;
import com.smartdevicelink.proxy.rpc.SpeakResponse;
import com.smartdevicelink.proxy.rpc.SubscribeButtonResponse;
import com.smartdevicelink.proxy.rpc.SubscribeVehicleDataResponse;
import com.smartdevicelink.proxy.rpc.UnsubscribeButtonResponse;
import com.smartdevicelink.proxy.rpc.UnsubscribeVehicleDataResponse;
import com.smartdevicelink.proxy.rpc.enums.Result;

/**
 * A factory class to generate responses based on the input requests.
 *
 * @author Mike Burke
 *
 */
public final class SdlResponseFactory {

  private SdlResponseFactory() {}
  
  /**
   * Creates a generic "Success" response for the input request with no input checking.  The created
   * response is sent back to the appropriate method of the input listener.
   * 
   * @param request The request to respond to
   * @param listener The listener to inform when the response is complete
   */
  public static void sendGenericResponseForRequest(RPCRequest request, IProxyListenerALM listener){
    if(listener == null){
      throw new NullPointerException();
    }

    final String reqName = request.getFunctionName();
    final int correlationId = request.getCorrelationID();
    
    // this is really bad
    if(reqName.equals(FunctionID.ALERT)){
      AlertResponse result = new AlertResponse();
      setSuccessParams(result, correlationId);
      listener.onAlertResponse(result);
    }
    else if(reqName.equals(FunctionID.SPEAK)){
      SpeakResponse result = new SpeakResponse();
      setSuccessParams(result, correlationId);
      listener.onSpeakResponse(result);
    }
    else if(reqName.equals(FunctionID.SHOW)){
      ShowResponse result = new ShowResponse();
      setSuccessParams(result, correlationId);
      listener.onShowResponse(result);
    }
    else if(reqName.equals(FunctionID.SUBSCRIBE_BUTTON)){
      SubscribeButtonResponse result = new SubscribeButtonResponse();
      setSuccessParams(result, correlationId);
      listener.onSubscribeButtonResponse(result);
      
    }
    else if(reqName.equals(FunctionID.UNSUBSCRIBE_BUTTON)){
      UnsubscribeButtonResponse result = new UnsubscribeButtonResponse();
      setSuccessParams(result, correlationId);
      listener.onUnsubscribeButtonResponse(result);
    }
    else if(reqName.equals(FunctionID.ADD_COMMAND)){
      AddCommandResponse result = new AddCommandResponse();
      setSuccessParams(result, correlationId);
      listener.onAddCommandResponse(result);
    }
    else if(reqName.equals(FunctionID.DELETE_COMMAND)){
      DeleteCommandResponse result = new DeleteCommandResponse();
      setSuccessParams(result, correlationId);
      listener.onDeleteCommandResponse(result);
    }
    else if(reqName.equals(FunctionID.ADD_SUB_MENU)){
      AddSubMenuResponse result = new AddSubMenuResponse();
      setSuccessParams(result, correlationId);
      listener.onAddSubMenuResponse(result);
    }
    else if(reqName.equals(FunctionID.DELETE_SUB_MENU)){
      DeleteSubMenuResponse result = new DeleteSubMenuResponse();
      setSuccessParams(result, correlationId);
      listener.onDeleteSubMenuResponse(result);
    }
    else if(reqName.equals(FunctionID.SET_GLOBAL_PROPERTIES)){
      SetGlobalPropertiesResponse result = new SetGlobalPropertiesResponse();
      setSuccessParams(result, correlationId);
      listener.onSetGlobalPropertiesResponse(result);
    }
    else if(reqName.equals(FunctionID.RESET_GLOBAL_PROPERTIES)){
      ResetGlobalPropertiesResponse result = new ResetGlobalPropertiesResponse();
      setSuccessParams(result, correlationId);
      listener.onResetGlobalPropertiesResponse(result);
    }
    else if(reqName.equals(FunctionID.SET_MEDIA_CLOCK_TIMER)){
      SetMediaClockTimerResponse result = new SetMediaClockTimerResponse();
      setSuccessParams(result, correlationId);
      listener.onSetMediaClockTimerResponse(result);
    }
    else if(reqName.equals(FunctionID.CREATE_INTERACTION_CHOICE_SET)){
      CreateInteractionChoiceSetResponse result = new CreateInteractionChoiceSetResponse();
      setSuccessParams(result, correlationId);
      listener.onCreateInteractionChoiceSetResponse(result);
    }
    else if(reqName.equals(FunctionID.DELETE_INTERACTION_CHOICE_SET)){
      DeleteInteractionChoiceSetResponse result = new DeleteInteractionChoiceSetResponse();
      setSuccessParams(result, correlationId);
      listener.onDeleteInteractionChoiceSetResponse(result);
    }
    else if(reqName.equals(FunctionID.PERFORM_INTERACTION)){
      PerformInteractionResponse result = new PerformInteractionResponse();
      setSuccessParams(result, correlationId);
      listener.onPerformInteractionResponse(result);
    }
    else if(reqName.equals(FunctionID.SLIDER)){
      SliderResponse result = new SliderResponse();
      setSuccessParams(result, correlationId);
      listener.onSliderResponse(result);
    }
    else if(reqName.equals(FunctionID.SCROLLABLE_MESSAGE)){
      ScrollableMessageResponse result = new ScrollableMessageResponse();
      setSuccessParams(result, correlationId);
      listener.onScrollableMessageResponse(result);
    }
    else if(reqName.equals(FunctionID.CHANGE_REGISTRATION)){
      ChangeRegistrationResponse result = new ChangeRegistrationResponse();
      setSuccessParams(result, correlationId);
      listener.onChangeRegistrationResponse(result);
    }
    else if(reqName.equals(FunctionID.PUT_FILE)){
      PutFileResponse result = new PutFileResponse();
      setSuccessParams(result, correlationId);
      listener.onPutFileResponse(result);
    }
    else if(reqName.equals(FunctionID.DELETE_FILE)){
      DeleteFileResponse result = new DeleteFileResponse();
      setSuccessParams(result, correlationId);
      listener.onDeleteFileResponse(result);
    }
    else if(reqName.equals(FunctionID.LIST_FILES)){
      ListFilesResponse result = new ListFilesResponse();
      setSuccessParams(result, correlationId);
      listener.onListFilesResponse(result);
    }
    else if(reqName.equals(FunctionID.SET_APP_ICON)){
      SetAppIconResponse result = new SetAppIconResponse();
      setSuccessParams(result, correlationId);
      listener.onSetAppIconResponse(result);
    }
    else if(reqName.equals(FunctionID.SUBSCRIBE_VEHICLE_DATA)){
      SubscribeVehicleDataResponse result = new SubscribeVehicleDataResponse();
      setSuccessParams(result, correlationId);
      listener.onSubscribeVehicleDataResponse(result);
    }
    else if(reqName.equals(FunctionID.UNSUBSCRIBE_VEHICLE_DATA)){
      UnsubscribeVehicleDataResponse result = new UnsubscribeVehicleDataResponse();
      setSuccessParams(result, correlationId);
      listener.onUnsubscribeVehicleDataResponse(result);
    }
    else if(reqName.equals(FunctionID.GET_VEHICLE_DATA)){
      GetVehicleDataResponse result = new GetVehicleDataResponse();
      setSuccessParams(result, correlationId);
      listener.onGetVehicleDataResponse(result);
    }
    else if(reqName.equals(FunctionID.READ_DID)){
      ReadDIDResponse result = new ReadDIDResponse();
      setSuccessParams(result, correlationId);
      listener.onReadDIDResponse(result);
    }
    else if(reqName.equals(FunctionID.GET_DTCS)){
      GetDTCsResponse result = new GetDTCsResponse();
      setSuccessParams(result, correlationId);
      listener.onGetDTCsResponse(result);
    }
  }
  
  private static void setSuccessParams(RPCResponse response, int correlationId){
    response.setSuccess(true);
    response.setCorrelationID(correlationId);
    response.setResultCode(Result.SUCCESS);
  }

}




Java Source Code List

com.livio.sdl.IdGenerator.java
com.livio.sdl.IpAddress.java
com.livio.sdl.SdlConstants.java
com.livio.sdl.SdlImageItem.java
com.livio.sdl.SdlLogMessage.java
com.livio.sdl.SdlRequestFactory.java
com.livio.sdl.SdlResponseFactory.java
com.livio.sdl.SdlResponseTracker.java
com.livio.sdl.SdlService.java
com.livio.sdl.adapters.SdlImageAdapter.java
com.livio.sdl.adapters.SdlMessageAdapter.java
com.livio.sdl.dialogs.BaseAlertDialog.java
com.livio.sdl.dialogs.BaseImageListDialog.java
com.livio.sdl.dialogs.BaseMultipleListViewDialog.java
com.livio.sdl.dialogs.BaseOkCancelDialog.java
com.livio.sdl.dialogs.BaseSingleListViewDialog.java
com.livio.sdl.dialogs.ImageListDialog.java
com.livio.sdl.dialogs.IndeterminateProgressDialog.java
com.livio.sdl.dialogs.JsonFlipperDialog.java
com.livio.sdl.dialogs.ListViewDialog.java
com.livio.sdl.dialogs.MultipleListViewDialog.java
com.livio.sdl.dialogs.SingleJsonDialog.java
com.livio.sdl.dialogs.TextViewAlertDialog.java
com.livio.sdl.dialogs.TextViewOkCancelDialog.java
com.livio.sdl.enums.EnumClickListener.java
com.livio.sdl.enums.EnumComparator.java
com.livio.sdl.enums.SdlButton.java
com.livio.sdl.enums.SdlCommand.java
com.livio.sdl.enums.SdlImageType.java
com.livio.sdl.enums.SdlInteractionMode.java
com.livio.sdl.enums.SdlLanguage.java
com.livio.sdl.enums.SdlSpeechCapability.java
com.livio.sdl.enums.SdlSystemAction.java
com.livio.sdl.enums.SdlTextAlignment.java
com.livio.sdl.enums.SdlTransportType.java
com.livio.sdl.enums.SdlUpdateMode.java
com.livio.sdl.enums.SdlVehicleData.java
com.livio.sdl.menu.CommandButton.java
com.livio.sdl.menu.MenuItem.java
com.livio.sdl.menu.MenuManager.java
com.livio.sdl.menu.SubmenuButton.java
com.livio.sdl.utils.AndroidUtils.java
com.livio.sdl.utils.ApplicationPreferences.java
com.livio.sdl.utils.Counter.java
com.livio.sdl.utils.DownCounter.java
com.livio.sdl.utils.MathUtils.java
com.livio.sdl.utils.SdlUtils.java
com.livio.sdl.utils.StringUtils.java
com.livio.sdl.utils.Timeout.java
com.livio.sdl.utils.UpCounter.java
com.livio.sdl.utils.WifiUtils.java
com.livio.sdl.viewhelpers.MinMaxInputFilter.java
com.livio.sdl.viewhelpers.SeekBarCalculator.java
com.livio.sdltester.HelpActivity.java
com.livio.sdltester.LivioSdlTesterPreferences.java
com.livio.sdltester.MainActivity.java
com.livio.sdltester.SdlTesterImageResource.java
com.livio.sdltester.dialogs.AddCommandDialog.java
com.livio.sdltester.dialogs.AddSubMenuDialog.java
com.livio.sdltester.dialogs.ButtonSubscriptionDialog.java
com.livio.sdltester.dialogs.ButtonUnsubscriptionDialog.java
com.livio.sdltester.dialogs.ChangeRegistrationDialog.java
com.livio.sdltester.dialogs.ChoiceItemDialog.java
com.livio.sdltester.dialogs.CreateInteractionChoiceSetDialog.java
com.livio.sdltester.dialogs.DeleteCommandDialog.java
com.livio.sdltester.dialogs.DeleteFileDialog.java
com.livio.sdltester.dialogs.DeleteInteractionDialog.java
com.livio.sdltester.dialogs.DeleteSubmenuDialog.java
com.livio.sdltester.dialogs.GetDtcsDialog.java
com.livio.sdltester.dialogs.PerformInteractionDialog.java
com.livio.sdltester.dialogs.PutFileDialog.java
com.livio.sdltester.dialogs.ReadDidsDialog.java
com.livio.sdltester.dialogs.ScrollableMessageDialog.java
com.livio.sdltester.dialogs.SdlAlertDialog.java
com.livio.sdltester.dialogs.SdlConnectionDialog.java
com.livio.sdltester.dialogs.SetAppIconDialog.java
com.livio.sdltester.dialogs.SetMediaClockTimerDialog.java
com.livio.sdltester.dialogs.ShowDialog.java
com.livio.sdltester.dialogs.SliderDialog.java
com.livio.sdltester.dialogs.SoftButtonItemDialog.java
com.livio.sdltester.dialogs.SoftButtonListDialog.java
com.livio.sdltester.dialogs.SpeakDialog.java