Browse code

SBC: CC interface extended by initial INVITE handling

Plus few helper methods to allow forking from CC modules.

Václav Kubart authored on 15/08/2012 07:40:57
Showing 4 changed files
... ...
@@ -150,6 +150,7 @@ class CallLeg: public AmB2BSession
150 150
     virtual void onCallStopped() { }
151 151
 
152 152
     void addCallee(CallLeg *callee, const AmSipRequest &relayed_invite);
153
+    bool haveBLeg() { return !(other_id.empty() && b_legs.empty()); }
153 154
 
154 155
   public:
155 156
     /** creates A leg */
... ...
@@ -4,12 +4,33 @@
4 4
 class SBCCallLeg;
5 5
 class SBCCallProfile;
6 6
 
7
-class ExtendedCCInterface {
7
+struct InitialInviteHandlerParams
8
+{
9
+  string remote_party;
10
+  string remote_uri;
11
+  string from;
12
+  const AmSipRequest *original_invite;
13
+  AmSipRequest *modified_invite;
14
+
15
+  InitialInviteHandlerParams(const string &to, const string &ruri, const string &_from,
16
+      const AmSipRequest *original, AmSipRequest *modified):
17
+      remote_party(to), remote_uri(ruri), from(_from),
18
+      original_invite(original), modified_invite(modified) { }
19
+};
20
+
21
+class ExtendedCCInterface
22
+{
8 23
   protected:
9 24
     ~ExtendedCCInterface() { }
10 25
 
11 26
   public:
12
-    virtual void onStateChange(SBCCallLeg *call, SBCCallProfile *call_profile) = 0;
27
+    virtual void onStateChange(SBCCallLeg *call, SBCCallProfile *call_profile) { };
28
+
29
+    /** called from A-leg onInvite with modified request (i.e. with call profile
30
+     * driven replacements already done, FIXME: do we need original as well?)
31
+     *
32
+     * can be used for forking or handling INVITE with Replaces header */
33
+    virtual void onInitialInvite(SBCCallLeg *call, SBCCallProfile *call_profile, InitialInviteHandlerParams &params) { }
13 34
 };
14 35
 
15 36
 #endif
... ...
@@ -159,6 +159,8 @@ SBCCallLeg::SBCCallLeg(const SBCCallLeg* caller, const SBCCallProfile& _call_pro
159 159
     call_profile(_call_profile),
160 160
     CallLeg(caller)
161 161
 {
162
+  call_profile.cc_vars.clear(); // we do not want to inherit these from caller do we?
163
+
162 164
   dlg.setRel100State(Am100rel::REL100_IGNORED);
163 165
   dlg.setOAEnabled(false);
164 166
 }
... ...
@@ -752,9 +754,18 @@ void SBCCallLeg::onInvite(const AmSipRequest& req)
752 754
   // we evaluated the settings, now we can initialize internals (like RTP relay)
753 755
   // we have to use original request (not the altered one) because for example
754 756
   // codecs filtered out might be used in direction to caller
755
-  CallLeg::onInvite(req); 
757
+  CallLeg::onInvite(req);
756 758
 
757
-  connectCallee(to, ruri, from, invite_req); // connect to the B leg(s) using modified request
759
+  // call extend call controls
760
+  InitialInviteHandlerParams params(to, ruri, from, &req, &invite_req);
761
+  for (vector<ExtendedCCInterface*>::iterator i = cc_ext.begin(); i != cc_ext.end(); ++i) {
762
+    (*i)->onInitialInvite(this, &call_profile, params);
763
+  }
764
+
765
+  if (!haveBLeg()) {
766
+    // no CC module connected a callee yet
767
+    connectCallee(to, ruri, from, invite_req); // connect to the B leg(s) using modified request
768
+  }
758 769
 }
759 770
 
760 771
 void SBCCallLeg::connectCallee(const string& remote_party, const string& remote_uri,
... ...
@@ -126,6 +126,10 @@ class SBCCallLeg : public CallLeg, public CredentialHolder
126 126
   /** clear all saved call timer, only effective before call is connected */
127 127
   void clearCallTimers();
128 128
 
129
+  // from SBCCalleeSession
130
+  void setLocalParty(const string &party, const string &uri) { dlg.local_party = party; dlg.local_uri = uri; }
131
+  void setRemoteParty(const string &party, const string &uri) { dlg.remote_party = party; dlg.remote_uri = uri; }
132
+
129 133
  protected:
130 134
   int relayEvent(AmEvent* ev);
131 135
 
... ...
@@ -141,10 +145,6 @@ class SBCCallLeg : public CallLeg, public CredentialHolder
141 145
   void onControlCmd(string& cmd, AmArg& params);
142 146
 
143 147
   void createCalleeSession();
144
-
145
-  // from SBCCalleeSession
146
-  void setLocalParty(const string &party, const string &uri) { dlg.local_party = party; dlg.local_uri = uri; }
147
-  void setRemoteParty(const string &party, const string &uri) { dlg.remote_party = party; dlg.remote_uri = uri; }
148 148
 };
149 149
 
150 150
 #endif