2015-04-13 12:09:26 -04:00
|
|
|
// Licensed to the Software Freedom Conservancy (SFC) under one
|
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
|
// distributed with this work for additional information
|
|
|
|
|
// regarding copyright ownership. The SFC licenses this file
|
|
|
|
|
// to you under the Apache License, Version 2.0 (the "License");
|
2013-01-11 22:18:32 +01:00
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
|
|
// Defines a response for use in the JSON Wire Protocol. The protocol is
|
|
|
|
|
// defined at http://code.google.com/p/selenium/wiki/JsonWireProtocol.
|
|
|
|
|
|
|
|
|
|
#ifndef WEBDRIVER_SERVER_RESPONSE_H_
|
|
|
|
|
#define WEBDRIVER_SERVER_RESPONSE_H_
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include "json.h"
|
|
|
|
|
|
|
|
|
|
namespace webdriver {
|
|
|
|
|
|
|
|
|
|
class Response {
|
|
|
|
|
public:
|
|
|
|
|
Response(void);
|
|
|
|
|
virtual ~Response(void);
|
|
|
|
|
std::string Serialize(void);
|
|
|
|
|
void Deserialize(const std::string& json);
|
|
|
|
|
|
|
|
|
|
Json::Value value(void) const { return this->value_; }
|
|
|
|
|
|
2017-02-22 14:13:25 -08:00
|
|
|
std::string error(void) const { return this->error_; }
|
2014-07-01 11:42:36 -04:00
|
|
|
|
2019-01-10 17:20:12 -08:00
|
|
|
Json::Value additional_data(void) const { return this->additional_data_; }
|
|
|
|
|
|
2017-02-22 14:13:25 -08:00
|
|
|
int GetHttpResponseCode(void);
|
|
|
|
|
std::string GetSessionId(void);
|
|
|
|
|
void SetResponse(const std::string& error, const Json::Value& response_value);
|
2013-01-11 22:18:32 +01:00
|
|
|
void SetSuccessResponse(const Json::Value& response_value);
|
|
|
|
|
void SetErrorResponse(const int error_code, const std::string& message);
|
2017-02-22 14:13:25 -08:00
|
|
|
void SetErrorResponse(const std::string& error, const std::string& message);
|
|
|
|
|
void AddAdditionalData(const std::string& data_name, const std::string& data_value);
|
2013-01-11 22:18:32 +01:00
|
|
|
|
|
|
|
|
private:
|
2017-02-22 14:13:25 -08:00
|
|
|
std::string ConvertErrorCode(const int error_code);
|
2014-09-05 02:00:00 +00:00
|
|
|
int ConvertStatusToCode(const std::string& status_string);
|
|
|
|
|
|
2017-02-22 14:13:25 -08:00
|
|
|
// The error of the response, if any.
|
|
|
|
|
std::string error_;
|
2013-01-11 22:18:32 +01:00
|
|
|
// A JSON object that represents the value of the response.
|
|
|
|
|
Json::Value value_;
|
2017-02-22 14:13:25 -08:00
|
|
|
Json::Value additional_data_;
|
2013-01-11 22:18:32 +01:00
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(Response);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webdriver
|
|
|
|
|
|
|
|
|
|
#endif // WEBDRIVER_SERVER_RESPONSE_H_
|