4 package com.smartdevicelink.proxy;
\r
6 import java.util.Hashtable;
\r
8 import com.smartdevicelink.proxy.constants.Names;
\r
9 import com.smartdevicelink.proxy.rpc.enums.Result;
\r
10 import com.smartdevicelink.util.DebugTool;
\r
13 * Result sent by SMARTDEVICELINK after an RPC is processed, consists of four parts:
\r
18 * An integer value correlating the response to the corresponding request.
\r
20 * </li> <li>Success:
\r
22 * A Boolean indicating whether the original request was successfully processed.
\r
24 * </li> <li>ResultCode:
\r
27 * The result code provides additional information about a response returning a
\r
31 * Any response can have at least one, or possibly more, of the following result
\r
32 * code values: SUCCESS, INVALID_DATA, OUT_OF_MEMORY, TOO_MANY_PENDING_REQUESTS,
\r
33 * APPLICATION_NOT_REGISTERED, GENERIC_ERROR,REJECTED.
\r
36 * Any additional result codes for a given operation can be found in related
\r
42 * A string of text representing additional information returned from SMARTDEVICELINK. This
\r
43 * could be useful in debugging.
\r
48 public class RPCResponse extends RPCMessage {
\r
50 *<p>Constructs a newly allocated RPCResponse object using function name</p>
\r
51 *@param functionName a string that indicates the function's name
\r
53 public RPCResponse(String functionName) {
\r
54 super(functionName, "response");
\r
57 *<p>Constructs a newly allocated RPCResponse object indicated by the Hashtable parameter</p>
\r
58 *@param hash The Hashtable to use
\r
60 public RPCResponse(Hashtable hash) {
\r
64 *<p>Constructs a newly allocated RPCResponse object using a RPCMessage object</p>
\r
65 *@param rpcMsg The {@linkplain RPCMessage} to use
\r
67 public RPCResponse(RPCMessage rpcMsg) {
\r
73 * Returns correlationID the ID of the request
\r
76 * @return int the ID of the request
\r
78 public Integer getCorrelationID() {
\r
79 return (Integer)function.get(Names.correlationID);
\r
84 * Set the correlationID
\r
87 * @param correlationID
\r
88 * the ID of the response
\r
90 public void setCorrelationID(Integer correlationID) {
\r
91 if (correlationID != null) {
\r
92 function.put(Names.correlationID, correlationID );
\r
93 } else if (parameters.contains(Names.correlationID)){
\r
94 function.remove(Names.correlationID);
\r
99 * Returns Success whether the request is successfully processed
\r
102 * @return Boolean the status of whether the request is successfully done
\r
104 public Boolean getSuccess() {
\r
105 return (Boolean) parameters.get( Names.success );
\r
109 * Set the Success status
\r
113 * whether the request is successfully processed
\r
115 public void setSuccess( Boolean success ) {
\r
116 if (success != null) {
\r
117 parameters.put(Names.success, success );
\r
122 * Returns ResultCode additional information about a response returning a failed outcome
\r
125 * @return {@linkplain Result} the status of whether the request is successfully done
\r
127 public Result getResultCode() {
\r
128 Object obj = parameters.get(Names.resultCode);
\r
129 if (obj instanceof Result) {
\r
130 return (Result) obj;
\r
131 } else if (obj instanceof String) {
\r
132 Result theCode = null;
\r
134 theCode = Result.valueForString((String) obj);
\r
135 } catch (Exception e) {
\r
136 DebugTool.logError("Failed to parse " + getClass().getSimpleName() + "." + Names.resultCode, e);
\r
144 * Set the additional information about a response returning a failed outcome
\r
147 * @param resultCode
\r
148 * whether the request is successfully processed
\r
150 public void setResultCode( Result resultCode ) {
\r
151 if (resultCode != null) {
\r
152 parameters.put(Names.resultCode, resultCode );
\r
157 * Returns a string of text representing additional information returned from SMARTDEVICELINK
\r
160 * @return String A string of text representing additional information returned from SMARTDEVICELINK
\r
162 public String getInfo() {
\r
163 return (String) parameters.get( Names.info );
\r
167 * Set a string of text representing additional information returned from SMARTDEVICELINK
\r
171 * a string of text representing additional information returned from SMARTDEVICELINK
\r
173 public void setInfo( String info ) {
\r
174 if (info != null) {
\r
175 parameters.put(Names.info, info );
\r