~ubuntu-branches/debian/experimental/kopete/experimental

« back to all changes in this revision

Viewing changes to protocols/jabber/googletalk/libjingle/talk/p2p/base/sessiondescription.h

  • Committer: Package Import Robot
  • Author(s): Maximiliano Curia
  • Date: 2015-02-24 11:32:57 UTC
  • mfrom: (1.1.41 vivid)
  • Revision ID: package-import@ubuntu.com-20150224113257-gnupg4v7lzz18ij0
Tags: 4:14.12.2-1
* New upstream release (14.12.2).
* Bump Standards-Version to 3.9.6, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * libjingle
3
 
 * Copyright 2004--2005, Google Inc.
4
 
 *
5
 
 * Redistribution and use in source and binary forms, with or without
6
 
 * modification, are permitted provided that the following conditions are met:
7
 
 *
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.
15
 
 *
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.
26
 
 */
27
 
 
28
 
#ifndef TALK_P2P_BASE_SESSIONDESCRIPTION_H_
29
 
#define TALK_P2P_BASE_SESSIONDESCRIPTION_H_
30
 
 
31
 
#include <set>
32
 
#include <string>
33
 
#include <vector>
34
 
 
35
 
#include "talk/base/constructormagic.h"
36
 
 
37
 
namespace cricket {
38
 
 
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 {
43
 
 public:
44
 
  virtual ~ContentDescription() {}
45
 
  virtual ContentDescription* Copy() const = 0;
46
 
};
47
 
 
48
 
// Analagous to a <jingle><content> or <session><description>.
49
 
// name = name of <content name="...">
50
 
// type = xmlns of <content>
51
 
struct ContentInfo {
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) {}
57
 
  std::string name;
58
 
  std::string type;
59
 
  const ContentDescription* description;
60
 
};
61
 
 
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
65
 
// MediaDescription.
66
 
class ContentGroup {
67
 
 public:
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_; }
76
 
 
77
 
 private:
78
 
  std::string semantics_;
79
 
  std::set<std::string> content_types_;
80
 
};
81
 
 
82
 
typedef std::vector<ContentInfo> ContentInfos;
83
 
typedef std::vector<ContentGroup> ContentGroups;
84
 
 
85
 
const ContentInfo* FindContentInfoByName(
86
 
    const ContentInfos& contents, const std::string& name);
87
 
const ContentInfo* FindContentInfoByType(
88
 
    const ContentInfos& contents, const std::string& type);
89
 
 
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 {
94
 
 public:
95
 
  SessionDescription() {}
96
 
  explicit SessionDescription(const ContentInfos& contents) :
97
 
      contents_(contents) {}
98
 
  SessionDescription(const ContentInfos& contents,
99
 
                     const ContentGroups& groups) :
100
 
      contents_(contents),
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_; }
113
 
 
114
 
  ~SessionDescription() {
115
 
    for (ContentInfos::iterator content = contents_.begin();
116
 
         content != contents_.end(); content++) {
117
 
      delete content->description;
118
 
    }
119
 
  }
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;
125
 
 
126
 
 private:
127
 
  ContentInfos contents_;
128
 
  ContentGroups content_groups_;
129
 
};
130
 
 
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
135
 
enum ContentAction {
136
 
  CA_OFFER, CA_ANSWER, CA_UPDATE
137
 
};
138
 
 
139
 
// Indicates whether a ContentDescription was sent by the local client
140
 
// or received from the remote client.
141
 
enum ContentSource {
142
 
  CS_LOCAL, CS_REMOTE
143
 
};
144
 
 
145
 
}  // namespace cricket
146
 
 
147
 
#endif  // TALK_P2P_BASE_SESSIONDESCRIPTION_H_