core/AmB2BSession.h
37abd537
 #ifndef AmB2BSession_h
 #define AmB2BSession_h
 
 #include "AmSession.h"
 #include "AmSipDialog.h"
 
 enum { B2BTerminateLeg, 
        B2BConnectLeg, 
        B2BCallAccepted, 
        B2BSipRequest, 
        B2BSipReply };
 
809a2727
 /** \brief base class for event in B2B session */
37abd537
 struct B2BEvent: public AmEvent
 {
     B2BEvent(int ev_id) 
 	: AmEvent(ev_id)
     {}
 };
 
809a2727
 /** \brief base class for SIP event in B2B session */
37abd537
 struct B2BSipEvent: public B2BEvent
 {
     bool forward;
 
     B2BSipEvent(int ev_id, bool forward)
 	: B2BEvent(ev_id),
 	  forward(forward)
     {}
 };
 
809a2727
 /** \brief SIP request in B2B session */
37abd537
 struct B2BSipRequestEvent: public B2BSipEvent
 {
     AmSipRequest req;
 
     B2BSipRequestEvent(const AmSipRequest& req, bool forward)
 	: B2BSipEvent(B2BSipRequest,forward),
 	  req(req)
     {}
 };
 
809a2727
 /** \brief SIP reply in B2B session */
37abd537
 struct B2BSipReplyEvent: public B2BSipEvent
 {
     AmSipReply reply;
 
     B2BSipReplyEvent(const AmSipReply& reply, bool forward)
 	: B2BSipEvent(B2BSipReply,forward),
 	  reply(reply)
     {}
 };
 
809a2727
 /** \brief trigger connecting the callee leg in B2B session */
37abd537
 struct B2BConnectEvent: public B2BEvent
 {
     string remote_party;
     string remote_uri;
 
     string content_type;
     string body;
     string hdrs;
 
     B2BConnectEvent(const string& remote_party,
 		    const string& remote_uri)
 	: B2BEvent(B2BConnectLeg),
 	  remote_party(remote_party),
 	  remote_uri(remote_uri)
     {}
 };
 
809a2727
 /**
  * \brief Base class for Sessions in B2BUA mode.
  * 
  * It has two legs: Callee- and caller-leg.
  */
37abd537
 class AmB2BSession: public AmSession
 {
 protected:
54cc24b0
     /** local tag of the other leg */
37abd537
     string other_id;
 
54cc24b0
     /** Tell if the session should
      *  process SIP request itself
      * or only relay them.
      */
37abd537
     bool sip_relay_only;
 
54cc24b0
     /** Requests which
      * have been relayed (sent)
      */
37abd537
     TransMap relayed_req;
 
54cc24b0
     /** Requests received for relaying */
37abd537
     map<int,AmSipRequest> recvd_req;
 
     void clear_other();
 
54cc24b0
     /** Relay one event to the other side. */
37abd537
     virtual void relayEvent(AmEvent* ev);
 
     void relaySip(const AmSipRequest& req);
     void relaySip(const AmSipRequest& orig, const AmSipReply& reply);
 
54cc24b0
     /** Terminate our leg and forget the other. */
37abd537
     void terminateLeg();
 
54cc24b0
     /** Terminate the other leg and forget it.*/
37abd537
     virtual void terminateOtherLeg();
 
54cc24b0
     /** @see AmSession */
37abd537
     void onSipRequest(const AmSipRequest& req);
     void onSipReply(const AmSipReply& reply);
 
54cc24b0
     /** @see AmEventQueue */
37abd537
     void process(AmEvent* event);
 
54cc24b0
     /** B2BEvent handler */
37abd537
     virtual void onB2BEvent(B2BEvent* ev);
 
     // Other leg received a BYE
     virtual void onOtherBye(const AmSipRequest& req);
 
54cc24b0
     /** INVITE from other leg has been replied */
98e12fce
     virtual void onOtherReply(const AmSipReply& reply);
37abd537
 
     AmB2BSession()
 	: sip_relay_only(true)
     {}
     AmB2BSession(const string& other_local_tag)
 	: other_id(other_local_tag),
 	  sip_relay_only(true)
     {}
 
     virtual ~AmB2BSession();
 };
 
 class AmB2BCalleeSession;
 
809a2727
 /** \brief Caller leg of a B2B session */
37abd537
 class AmB2BCallerSession: public AmB2BSession
 {
 public:
     enum CalleeStatus {
 	None=0,
 	NoReply,
 	Ringing,
 	Connected
     };
 
 private:
     // Callee Status
     CalleeStatus callee_status;
     AmSipRequest invite_req;
 
     void relayEvent(AmEvent* ev);
     void createCalleeSession();
     int  reinviteCaller(const AmSipReply& callee_reply);
 
 public:
     AmB2BCallerSession();
     
     CalleeStatus getCalleeStatus() { return callee_status; }
 
     virtual AmB2BCalleeSession* newCalleeSession();
 
     void connectCallee(const string& remote_party,
 		       const string& remote_uri);
 
     const AmSipRequest& getOriginalRequest() { return invite_req; }
 
     // @see AmDialogState
     void onSessionStart(const AmSipRequest& req);
 
     // @see AmB2BSession
     void terminateLeg();
     void terminateOtherLeg();
     void onB2BEvent(B2BEvent* ev);
 
     void set_sip_relay_only(bool r) { sip_relay_only = r; }
 };
 
809a2727
 /** \brief Callee leg of a B2B session */
37abd537
 class AmB2BCalleeSession: public AmB2BSession
 {
 public:
     AmB2BCalleeSession(const string& other_local_tag)
 	: AmB2BSession(other_local_tag)
     {}
 
     AmB2BCalleeSession(const AmB2BCallerSession* caller)
 	: AmB2BSession(caller->getLocalTag())
     {}
 
     void onB2BEvent(B2BEvent* ev);
 };
 
 #endif