henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame^] | 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_SESSIONCLIENT_H_ |
| 29 | #define TALK_P2P_BASE_SESSIONCLIENT_H_ |
| 30 | |
| 31 | #include "talk/p2p/base/constants.h" |
| 32 | |
| 33 | namespace buzz { |
| 34 | class XmlElement; |
| 35 | } |
| 36 | |
| 37 | namespace cricket { |
| 38 | |
| 39 | struct ParseError; |
| 40 | class Session; |
| 41 | class ContentDescription; |
| 42 | |
| 43 | class ContentParser { |
| 44 | public: |
| 45 | virtual bool ParseContent(SignalingProtocol protocol, |
| 46 | const buzz::XmlElement* elem, |
| 47 | ContentDescription** content, |
| 48 | ParseError* error) = 0; |
| 49 | // If not IsWriteable, then a given content should be "skipped" when |
| 50 | // writing in the given protocol, as if it didn't exist. We assume |
| 51 | // most things are writeable. We do this to avoid strange cases |
| 52 | // like data contents in Gingle, which aren't writable. |
| 53 | virtual bool IsWritable(SignalingProtocol protocol, |
| 54 | const ContentDescription* content) { |
| 55 | return true; |
| 56 | } |
| 57 | virtual bool WriteContent(SignalingProtocol protocol, |
| 58 | const ContentDescription* content, |
| 59 | buzz::XmlElement** elem, |
| 60 | WriteError* error) = 0; |
| 61 | virtual ~ContentParser() {} |
| 62 | }; |
| 63 | |
| 64 | // A SessionClient exists in 1-1 relation with each session. The implementor |
| 65 | // of this interface is the one that understands *what* the two sides are |
| 66 | // trying to send to one another. The lower-level layers only know how to send |
| 67 | // data; they do not know what is being sent. |
| 68 | class SessionClient : public ContentParser { |
| 69 | public: |
| 70 | // Notifies the client of the creation / destruction of sessions of this type. |
| 71 | // |
| 72 | // IMPORTANT: The SessionClient, in its handling of OnSessionCreate, must |
| 73 | // create whatever channels are indicate in the description. This is because |
| 74 | // the remote client may already be attempting to connect those channels. If |
| 75 | // we do not create our channel right away, then connection may fail or be |
| 76 | // delayed. |
| 77 | virtual void OnSessionCreate(Session* session, bool received_initiate) = 0; |
| 78 | virtual void OnSessionDestroy(Session* session) = 0; |
| 79 | |
| 80 | virtual bool ParseContent(SignalingProtocol protocol, |
| 81 | const buzz::XmlElement* elem, |
| 82 | ContentDescription** content, |
| 83 | ParseError* error) = 0; |
| 84 | virtual bool WriteContent(SignalingProtocol protocol, |
| 85 | const ContentDescription* content, |
| 86 | buzz::XmlElement** elem, |
| 87 | WriteError* error) = 0; |
| 88 | protected: |
| 89 | // The SessionClient interface explicitly does not include destructor |
| 90 | virtual ~SessionClient() { } |
| 91 | }; |
| 92 | |
| 93 | } // namespace cricket |
| 94 | |
| 95 | #endif // TALK_P2P_BASE_SESSIONCLIENT_H_ |