15976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org/*
25976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * libjingle
35976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * Copyright 2004--2005, Google Inc.
45976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *
55976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * Redistribution and use in source and binary forms, with or without
65976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * modification, are permitted provided that the following conditions are met:
75976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *
85976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *  1. Redistributions of source code must retain the above copyright notice,
95976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *     this list of conditions and the following disclaimer.
105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *  2. Redistributions in binary form must reproduce the above copyright notice,
115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *     this list of conditions and the following disclaimer in the documentation
125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *     and/or other materials provided with the distribution.
135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *  3. The name of the author may not be used to endorse or promote products
145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *     derived from this software without specific prior written permission.
155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *
165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
245976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
255976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
265976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org */
275976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
285976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#ifndef TALK_P2P_BASE_SESSIONCLIENT_H_
295976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#define TALK_P2P_BASE_SESSIONCLIENT_H_
305976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
315976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/p2p/base/constants.h"
325976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
335976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgnamespace buzz {
345976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgclass XmlElement;
355976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org}
365976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
375976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgnamespace cricket {
385976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
395976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstruct ParseError;
405976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgclass Session;
415976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgclass ContentDescription;
425976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
435976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgclass ContentParser {
445976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org public:
455976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool ParseContent(SignalingProtocol protocol,
465976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                            const buzz::XmlElement* elem,
475976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                            ContentDescription** content,
485976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                            ParseError* error) = 0;
495976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // If not IsWriteable, then a given content should be "skipped" when
505976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // writing in the given protocol, as if it didn't exist.  We assume
515976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // most things are writeable.  We do this to avoid strange cases
525976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // like data contents in Gingle, which aren't writable.
535976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool IsWritable(SignalingProtocol protocol,
545976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                          const ContentDescription* content) {
555976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    return true;
565976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
575976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool WriteContent(SignalingProtocol protocol,
585976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                            const ContentDescription* content,
595976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                            buzz::XmlElement** elem,
605976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                            WriteError* error) = 0;
615976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual ~ContentParser() {}
625976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org};
635976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
645976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// A SessionClient exists in 1-1 relation with each session.  The implementor
655976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// of this interface is the one that understands *what* the two sides are
665976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// trying to send to one another.  The lower-level layers only know how to send
675976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// data; they do not know what is being sent.
685976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgclass SessionClient : public ContentParser {
695976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org public:
705976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // Notifies the client of the creation / destruction of sessions of this type.
715976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  //
725976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // IMPORTANT: The SessionClient, in its handling of OnSessionCreate, must
735976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // create whatever channels are indicate in the description.  This is because
745976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // the remote client may already be attempting to connect those channels. If
755976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // we do not create our channel right away, then connection may fail or be
765976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // delayed.
775976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual void OnSessionCreate(Session* session, bool received_initiate) = 0;
785976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual void OnSessionDestroy(Session* session) = 0;
795976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
805976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool ParseContent(SignalingProtocol protocol,
815976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                            const buzz::XmlElement* elem,
825976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                            ContentDescription** content,
835976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                            ParseError* error) = 0;
845976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool WriteContent(SignalingProtocol protocol,
855976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                            const ContentDescription* content,
865976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                            buzz::XmlElement** elem,
875976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                            WriteError* error) = 0;
885976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org protected:
895976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // The SessionClient interface explicitly does not include destructor
905976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual ~SessionClient() { }
915976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org};
925976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
935976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org}  // namespace cricket
945976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
955976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#endif  // TALK_P2P_BASE_SESSIONCLIENT_H_
96