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

« back to all changes in this revision

Viewing changes to protocols/jabber/googletalk/libjingle/talk/p2p/base/transportchannel.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_TRANSPORTCHANNEL_H_
29
 
#define TALK_P2P_BASE_TRANSPORTCHANNEL_H_
30
 
 
31
 
#include <string>
32
 
#include "talk/base/basictypes.h"
33
 
#include "talk/base/sigslot.h"
34
 
#include "talk/base/socket.h"
35
 
 
36
 
namespace cricket {
37
 
 
38
 
class Candidate;
39
 
class P2PTransportChannel;
40
 
 
41
 
// A TransportChannel represents one logical stream of packets that are sent
42
 
// between the two sides of a session.
43
 
class TransportChannel: public sigslot::has_slots<> {
44
 
 public:
45
 
  TransportChannel(const std::string& name, const std::string &content_type)
46
 
      : name_(name), content_type_(content_type),
47
 
        readable_(false), writable_(false) {}
48
 
  virtual ~TransportChannel() {}
49
 
 
50
 
  // Returns the session id of this channel.
51
 
  const std::string& session_id() const { return session_id_; }
52
 
  // Returns the name of this channel.
53
 
  const std::string& name() const { return name_; }
54
 
  const std::string& content_type() const { return content_type_; }
55
 
 
56
 
  // Returns the readable and states of this channel.  Each time one of these
57
 
  // states changes, a signal is raised.  These states are aggregated by the
58
 
  // TransportManager.
59
 
  bool readable() const { return readable_; }
60
 
  bool writable() const { return writable_; }
61
 
  sigslot::signal1<TransportChannel*> SignalReadableState;
62
 
  sigslot::signal1<TransportChannel*> SignalWritableState;
63
 
 
64
 
  // Attempts to send the given packet.  The return value is < 0 on failure.
65
 
  virtual int SendPacket(const char *data, size_t len) = 0;
66
 
 
67
 
  // Sets a socket option on this channel.  Note that not all options are
68
 
  // supported by all transport types.
69
 
  virtual int SetOption(talk_base::Socket::Option opt, int value) = 0;
70
 
 
71
 
  // Sets session id which created this transport channel.
72
 
  // This is called from TransportProxy::GetOrCreateImpl.
73
 
  void set_session_id(const std::string& session_id) {
74
 
    session_id_ = session_id;
75
 
  }
76
 
 
77
 
  // Returns the most recent error that occurred on this channel.
78
 
  virtual int GetError() = 0;
79
 
 
80
 
  // This hack is here to allow the SocketMonitor to downcast to the
81
 
  // P2PTransportChannel safely.
82
 
  // TODO: Generalize network monitoring.
83
 
  virtual P2PTransportChannel* GetP2PChannel() { return NULL; }
84
 
 
85
 
  // Signalled each time a packet is received on this channel.
86
 
  sigslot::signal3<TransportChannel*, const char*, size_t> SignalReadPacket;
87
 
 
88
 
  // This signal occurs when there is a change in the way that packets are
89
 
  // being routed, i.e. to a different remote location. The candidate
90
 
  // indicates where and how we are currently sending media.
91
 
  sigslot::signal2<TransportChannel*, const Candidate&> SignalRouteChange;
92
 
 
93
 
  // Invoked when the channel is being destroyed.
94
 
  sigslot::signal1<TransportChannel*> SignalDestroyed;
95
 
 
96
 
  // Debugging description of this transport channel.
97
 
  std::string ToString() const;
98
 
 
99
 
 protected:
100
 
  // Sets the readable state, signaling if necessary.
101
 
  void set_readable(bool readable);
102
 
 
103
 
  // Sets the writable state, signaling if necessary.
104
 
  void set_writable(bool writable);
105
 
 
106
 
 
107
 
 private:
108
 
  std::string session_id_;
109
 
  std::string name_;
110
 
  std::string content_type_;
111
 
  bool readable_;
112
 
  bool writable_;
113
 
 
114
 
  DISALLOW_EVIL_CONSTRUCTORS(TransportChannel);
115
 
};
116
 
 
117
 
}  // namespace cricket
118
 
 
119
 
#endif  // TALK_P2P_BASE_TRANSPORTCHANNEL_H_