Browse code

B2B calls: tightening the interface

Václav Kubart authored on 17/08/2012 15:10:42
Showing 4 changed files
... ...
@@ -191,11 +191,6 @@ void CallLeg::onB2BEvent(B2BEvent* ev)
191 191
   AmB2BSession::onB2BEvent(ev);
192 192
 }
193 193
 
194
-void CallLeg::onBLegRefused(const AmSipReply& reply)
195
-{
196
-  terminateOtherLeg(reply.from_tag);
197
-}
198
-
199 194
 int CallLeg::relaySipReply(AmSipReply &reply)
200 195
 {
201 196
   std::map<int,AmSipRequest>::iterator t_req = recvd_req.find(reply.cseq);
... ...
@@ -351,6 +346,8 @@ void CallLeg::onB2BReply(B2BSipReplyEvent *ev)
351 346
 
352 347
       // clean up the other leg; 
353 348
       // eventually do serial fork, handle redirect or whatever else
349
+      terminateOtherLeg(reply.from_tag);
350
+
354 351
       onBLegRefused(reply);
355 352
 
356 353
       if (!b_legs.empty()) {
... ...
@@ -67,7 +67,6 @@ struct ReconnectLegEvent: public B2BEvent
67 67
   virtual ~ReconnectLegEvent() { if (media && media->releaseReference()) delete media; }
68 68
 };
69 69
 
70
-
71 70
 /** composed AmB2BCalleeSession & AmB2BCallerSession
72 71
  * represents indepenedently A or B leg of a call,
73 72
  * old clases left for compatibility
... ...
@@ -138,12 +137,42 @@ class CallLeg: public AmB2BSession
138 137
      * be used directly by successors, right?) */
139 138
     void terminateOtherLeg(const string &id);
140 139
 
140
+    void terminateCall();
141
+
141 142
     void updateCallStatus(CallStatus new_status);
143
+
144
+    //////////////////////////////////////////////////////////////////////
145
+    // callbacks (intended to be redefined in successors but should not be
146
+    // called by them directly)
147
+
148
+    /* handler called when call status changes */
142 149
     virtual void onCallStatusChange() { }
143 150
 
144
-  public:
145
-    void terminateCall();
151
+    /** handler called when the second leg is connected */
152
+    virtual void onCallConnected(const AmSipReply& reply) { }
153
+
154
+    /** handler called when call is stopped */
155
+    virtual void onCallStopped() { }
146 156
 
157
+    /** Method called if given B leg couldn't establish the call (refused with
158
+     * failure response)
159
+     *
160
+     * Redefine to implement serial fork or handle redirect. */
161
+    virtual void onBLegRefused(const AmSipReply& reply) { }
162
+
163
+  protected:
164
+
165
+    // functions offered to successors
166
+
167
+    /** add given call leg as our B leg */
168
+    void addCallee(CallLeg *callee, const AmSipRequest &relayed_invite);
169
+
170
+    /** add given already existing session as our B leg */
171
+    void addCallee(const string &session_tag, const AmSipRequest &relayed_invite);
172
+
173
+    CallStatus getCallStatus() { return call_status; }
174
+
175
+  public:
147 176
     // @see AmB2BSession
148 177
     virtual void terminateLeg();
149 178
     virtual void terminateOtherLeg();
... ...
@@ -160,27 +189,6 @@ class CallLeg: public AmB2BSession
160 189
 
161 190
     //int reinviteCaller(const AmSipReply& callee_reply);
162 191
 
163
-    /** Method called if given B leg couldn't establish the call (refused with
164
-     * failure response)
165
-     *
166
-     * Redefine to implement serial fork or handle redirect, 
167
-     * currently only terminates the other leg. */
168
-    virtual void onBLegRefused(const AmSipReply& reply);
169
-
170
-    /** handler called when the second leg is connected */
171
-    virtual void onCallConnected(const AmSipReply& reply) { }
172
-
173
-    /** handler called when call is stopped */
174
-    virtual void onCallStopped() { }
175
-
176
-    /** add given call leg as our B leg */
177
-    void addCallee(CallLeg *callee, const AmSipRequest &relayed_invite);
178
-
179
-    /** add given already existing session as our B leg */
180
-    void addCallee(const string &session_tag, const AmSipRequest &relayed_invite);
181
-
182
-    bool haveBLeg() { return !(other_id.empty() && b_legs.empty()); }
183
-
184 192
   public:
185 193
     /** creates A leg */
186 194
     CallLeg();
... ...
@@ -188,15 +196,6 @@ class CallLeg: public AmB2BSession
188 196
     /** creates B leg using given session as A leg */
189 197
     CallLeg(const CallLeg* caller);
190 198
 
191
-    /** Initialize RTP relay according to the "src".
192
-     * Previously was initializeRTPRelay which initialised the session given as parameter
193
-     * according settings in this instance (i.e. the opposite stuff)!
194
-     *
195
-     * original comment: initialize RTP relay mode, if rtp_relay_enabled
196
-     * must be called *before* callee_session is started
197
-     */
198
-    void initRTPRelay(const CallLeg* src);
199
-
200 199
 };
201 200
 
202 201
 
... ...
@@ -762,7 +762,7 @@ void SBCCallLeg::onInvite(const AmSipRequest& req)
762 762
     (*i)->onInitialInvite(this, &call_profile, params);
763 763
   }
764 764
 
765
-  if (!haveBLeg()) {
765
+  if (getCallStatus() == Disconnected) {
766 766
     // no CC module connected a callee yet
767 767
     connectCallee(to, ruri, from, invite_req); // connect to the B leg(s) using modified request
768 768
   }
... ...
@@ -130,6 +130,9 @@ class SBCCallLeg : public CallLeg, public CredentialHolder
130 130
   void setLocalParty(const string &party, const string &uri) { dlg.local_party = party; dlg.local_uri = uri; }
131 131
   void setRemoteParty(const string &party, const string &uri) { dlg.remote_party = party; dlg.remote_uri = uri; }
132 132
 
133
+  void addCallee(CallLeg *callee, const AmSipRequest &invite) { CallLeg::addCallee(callee, invite); }
134
+  void addCallee(const string &session_tag, const AmSipRequest &invite) { CallLeg::addCallee(session_tag, invite); }
135
+
133 136
  protected:
134 137
   int relayEvent(AmEvent* ev);
135 138