3
* Copyright 2011, Google Inc.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
8
* 1. Redistributions of source code must retain the above copyright notice,
9
* this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright notice,
11
* this list of conditions and the following disclaimer in the documentation
12
* and/or other materials provided with the distribution.
13
* 3. The name of the author may not be used to endorse or promote products
14
* derived from this software without specific prior written permission.
16
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
// This file contain classes for parsing and serializing ROAP messages.
29
// The ROAP messages are defined in
30
// http://tools.ietf.org/html/draft-jennings-rtcweb-signaling-01.
32
#ifndef TALK_APP_WEBRTC_ROAPMESSAGES_H_
33
#define TALK_APP_WEBRTC_ROAPMESSAGES_H_
37
#include "talk/app/webrtc/roaperrorcodes.h"
38
#include "talk/base/basictypes.h"
39
#include "talk/base/json.h"
43
class RoapMessageBase {
45
enum RoapMessageType {
54
RoapMessageBase(RoapMessageType type,
55
const std::string& offer_session_id,
56
const std::string& answer_session_id,
57
const std::string& session_token,
58
const std::string& response_token,
61
bool Parse(const std::string& message);
62
std::string Serialize();
64
RoapMessageType type() const { return type_; }
65
const std::string& offer_session_id() const { return offer_session_id_; }
66
const std::string& answer_session_id() const { return answer_session_id_; }
67
const std::string& session_token() const { return session_token_; }
68
const std::string& response_token() const { return response_token_; }
69
uint32 seq() const { return seq_; }
72
virtual void SerializeElement(Json::Value* message);
73
Json::Value jmessage_; // Contains the parsed json message.
76
RoapMessageType type_;
77
std::string offer_session_id_;
78
std::string answer_session_id_;
79
std::string session_token_;
80
std::string response_token_;
84
class RoapAnswer : public RoapMessageBase {
86
// Ctor for creating a new RoapAnswer used for deserialization.
87
// Call Parse after creating this object to parse an answer based on the
89
explicit RoapAnswer(const RoapMessageBase& base);
91
// Ctor for creating a new RoapAnswer used for serialization.
92
// See the specification for a full description of the arguments.
93
// |desc| is the session description in sdp-format, including ice candidates.
94
RoapAnswer(const std::string& offer_session_id,
95
const std::string& answer_session_id,
96
const std::string& session_token,
97
const std::string& response_token,
99
const std::string& desc);
102
// Get remote SessionDescription if the session description has been parsed.
103
// Empty string otherwise.
104
const std::string& SessionDescription() const { return desc_; }
105
bool more_coming() const { return more_coming_ ; }
108
virtual void SerializeElement(Json::Value* message);
115
class RoapOffer : public RoapMessageBase {
117
// Ctor for creating a new RoapOffer used for deserialization.
118
// Call Parse after creating this object to parse an answer based on the
119
// message in |base|.
120
explicit RoapOffer(const RoapMessageBase& base);
121
// Ctor for creating a new RoapOffer used for serialization.
122
// See the specification for a full description of the arguments.
123
// |desc| is the session description in sdp-format, including ice candidates.
124
RoapOffer(const std::string& offer_session_id,
125
const std::string& answer_session_id,
126
const std::string& session_token,
129
const std::string& desc);
132
uint32 tie_breaker() const { return tie_breaker_; }
133
// Get remote SessionDescription if the session description has been parsed.
134
// Empty string otherwise.
135
const std::string& SessionDescription() const { return desc_; }
138
virtual void SerializeElement(Json::Value* message);
145
class RoapError : public RoapMessageBase {
147
explicit RoapError(const RoapMessageBase& base);
148
RoapError(const std::string& offer_session_id,
149
const std::string& answer_session_id,
150
const std::string& session_token,
151
const std::string& response_token,
153
RoapErrorCode error);
155
RoapErrorCode error() const { return error_; }
158
virtual void SerializeElement(Json::Value* message);
161
RoapErrorCode error_;
164
class RoapOk : public RoapMessageBase {
166
explicit RoapOk(const RoapMessageBase& base);
167
RoapOk(const std::string& offer_session_id,
168
const std::string& answer_session_id,
169
const std::string& session_token,
170
const std::string& response_token,
174
class RoapShutdown : public RoapMessageBase {
176
explicit RoapShutdown(const RoapMessageBase& base);
177
RoapShutdown(const std::string& offer_session_id,
178
const std::string& answer_session_id,
179
const std::string& session_token,
183
} // namespace webrtc
185
#endif // TALK_APP_WEBRTC_ROAPMESSAGES_H_