3
* Copyright 2004--2005, 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
#ifndef TALK_P2P_BASE_SESSIONDESCRIPTION_H_
29
#define TALK_P2P_BASE_SESSIONDESCRIPTION_H_
35
#include "talk/base/constructormagic.h"
39
// Describes a session content. Individual content types inherit from
40
// this class. Analagous to a <jingle><content><description> or
41
// <session><description>.
42
class ContentDescription {
44
virtual ~ContentDescription() {}
45
virtual ContentDescription* Copy() const = 0;
48
// Analagous to a <jingle><content> or <session><description>.
49
// name = name of <content name="...">
50
// type = xmlns of <content>
52
ContentInfo() : description(NULL) {}
53
ContentInfo(const std::string& name,
54
const std::string& type,
55
const ContentDescription* description) :
56
name(name), type(type), description(description) {}
59
const ContentDescription* description;
62
// This class provides a mechanism to aggregate different media contents into a
63
// group. This group can also be shared with the peers in a pre-defined format.
64
// GroupInfo should be populated only with the |content_name| of the
68
explicit ContentGroup(const std::string& semantics) :
69
semantics_(semantics) {}
70
void AddContentName(const std::string& content_name);
71
bool RemoveContentName(const std::string& content_name);
72
bool HasContentName(const std::string& content_name) const;
73
const std::string* FirstContentName() const;
74
const std::string& semantics() const { return semantics_; }
75
const std::set<std::string>& content_types() const { return content_types_; }
78
std::string semantics_;
79
std::set<std::string> content_types_;
82
typedef std::vector<ContentInfo> ContentInfos;
83
typedef std::vector<ContentGroup> ContentGroups;
85
const ContentInfo* FindContentInfoByName(
86
const ContentInfos& contents, const std::string& name);
87
const ContentInfo* FindContentInfoByType(
88
const ContentInfos& contents, const std::string& type);
90
// Describes a collection of contents, each with its own name and
91
// type. Analgous to a <jingle> or <session> stanza. Assumes that
92
// contents are unique be name, but doesn't enforce that.
93
class SessionDescription {
95
SessionDescription() {}
96
explicit SessionDescription(const ContentInfos& contents) :
97
contents_(contents) {}
98
SessionDescription(const ContentInfos& contents,
99
const ContentGroups& groups) :
101
content_groups_(groups) {}
102
SessionDescription* Copy() const;
103
const ContentInfo* GetContentByName(const std::string& name) const;
104
const ContentInfo* FirstContentByType(const std::string& type) const;
105
const ContentInfo* FirstContent() const;
106
// Takes ownership of ContentDescription*.
107
void AddContent(const std::string& name,
108
const std::string& type,
109
const ContentDescription* description);
110
bool RemoveContentByName(const std::string& name);
111
const ContentInfos& contents() const { return contents_; }
112
const ContentGroups& groups() const { return content_groups_; }
114
~SessionDescription() {
115
for (ContentInfos::iterator content = contents_.begin();
116
content != contents_.end(); content++) {
117
delete content->description;
120
bool HasGroup(const std::string& name) const;
121
void AddGroup(const ContentGroup& group) { content_groups_.push_back(group); }
122
// Remove the first group with the same semantics specified by |name|.
123
void RemoveGroupByName(const std::string& name);
124
const ContentGroup* GetGroupByName(const std::string& name) const;
127
ContentInfos contents_;
128
ContentGroups content_groups_;
131
// Indicates whether a ContentDescription was an offer or an answer, as
132
// described in http://www.ietf.org/rfc/rfc3264.txt. CA_UPDATE
133
// indicates a jingle update message which contains a subset of a full
134
// session description
136
CA_OFFER, CA_ANSWER, CA_UPDATE
139
// Indicates whether a ContentDescription was sent by the local client
140
// or received from the remote client.
145
} // namespace cricket
147
#endif // TALK_P2P_BASE_SESSIONDESCRIPTION_H_