Browse code

SBC: CC interface extended with method for module initialization

Václav Kubart authored on 07/09/2012 13:07:03
Showing 3 changed files
... ...
@@ -35,6 +35,11 @@ class ExtendedCCInterface
35 35
   public:
36 36
     // call state changes
37 37
 
38
+    /** First method called from extended CC module interface.
39
+     * It should initialize CC module internals (initial INVITE can be used for
40
+     * evaluating CC module parameters. */
41
+    virtual void init(SBCCallLeg *call, const AmSipRequest &invite) { }
42
+
38 43
     virtual void onStateChange(SBCCallLeg *call) { };
39 44
 
40 45
     virtual void onTerminateLeg(SBCCallLeg *call) { }
... ...
@@ -18,7 +18,7 @@
18 18
 
19 19
 using namespace std;
20 20
 
21
-#define TRACE INFO
21
+#define TRACE DBG
22 22
 
23 23
 // helper functions
24 24
 
... ...
@@ -154,15 +154,28 @@ SBCCallLeg::SBCCallLeg(const SBCCallProfile& call_profile)
154 154
 }
155 155
 
156 156
 // B leg constructor (from SBCCalleeSession)
157
-SBCCallLeg::SBCCallLeg(const SBCCallLeg* caller, const SBCCallProfile& _call_profile)
157
+SBCCallLeg::SBCCallLeg(SBCCallLeg* caller, const AmSipRequest &original_invite)
158 158
   : auth(NULL),
159
-    call_profile(_call_profile),
159
+    call_profile(caller->getCallProfile()),
160 160
     CallLeg(caller)
161 161
 {
162
-  call_profile.cc_vars.clear(); // we do not want to inherit these from caller do we?
162
+  // FIXME: do we want to inherit cc_vars from caller?
163
+  // Can be pretty dangerous when caller stored pointer to object - we should
164
+  // not probably operate on it! But on other hand it could be handy for
165
+  // something, so just take care when using stored objects...
166
+  // call_profile.cc_vars.clear();
163 167
 
164 168
   dlg.setRel100State(Am100rel::REL100_IGNORED);
165 169
   dlg.setOAEnabled(false);
170
+
171
+  // CC interfaces and variables should be already "evaluated" by A leg, we just
172
+  // need to load the DI interfaces for us (later they will be initialized with
173
+  // original INVITE so it must be done in A leg's thread!)
174
+  if (!getCCInterfaces()) {
175
+    throw AmSession::Exception(500, SIP_REPLY_SERVER_INTERNAL_ERROR);
176
+  }
177
+
178
+  initCCModules(original_invite);
166 179
 }
167 180
 
168 181
 void SBCCallLeg::onStart()
... ...
@@ -212,12 +225,6 @@ void SBCCallLeg::applyAProfile()
212 225
 
213 226
 void SBCCallLeg::applyBProfile()
214 227
 {
215
-  // CC interfaces and variables should be already "evaluated" by A leg, we just
216
-  // need to load the DI interfaces for us
217
-  if (!getCCInterfaces()) {
218
-    throw AmSession::Exception(500, SIP_REPLY_SERVER_INTERNAL_ERROR);
219
-  }
220
-
221 228
   if (!call_profile.contact.empty()) {
222 229
     dlg.contact_uri = SIP_HDR_COLSP(SIP_HDR_CONTACT) + call_profile.contact + CRLF;
223 230
   }
... ...
@@ -709,6 +716,8 @@ void SBCCallLeg::onInvite(const AmSipRequest& req)
709 716
     throw AmSession::Exception(500, SIP_REPLY_SERVER_INTERNAL_ERROR);
710 717
   }
711 718
 
719
+  initCCModules(req);
720
+
712 721
   string ruri, to, from;
713 722
   ruri = call_profile.ruri.empty() ? req.r_uri : call_profile.ruri;
714 723
   if(!call_profile.ruri_host.empty()){
... ...
@@ -777,16 +786,16 @@ void SBCCallLeg::onInvite(const AmSipRequest& req)
777 786
 
778 787
   if (getCallStatus() == Disconnected) {
779 788
     // no CC module connected a callee yet
780
-    connectCallee(to, ruri, from, invite_req); // connect to the B leg(s) using modified request
789
+    connectCallee(to, ruri, from, req, invite_req); // connect to the B leg(s) using modified request
781 790
   }
782 791
 }
783 792
 
784 793
 void SBCCallLeg::connectCallee(const string& remote_party, const string& remote_uri,
785
-    const string &from, const AmSipRequest &invite)
794
+    const string &from, const AmSipRequest &original_invite, const AmSipRequest &invite)
786 795
 {
787 796
   // FIXME: no fork for now
788 797
 
789
-  SBCCallLeg* callee_session = new SBCCallLeg(this, call_profile);
798
+  SBCCallLeg* callee_session = new SBCCallLeg(this, original_invite);
790 799
   callee_session->setLocalParty(from, from);
791 800
   callee_session->setRemoteParty(remote_party, remote_uri);
792 801
 
... ...
@@ -830,13 +839,13 @@ bool SBCCallLeg::getCCInterfaces() {
830 839
       cc_di->invoke("getExtendedInterfaceHandler", args, ret);
831 840
       ExtendedCCInterface *iface = dynamic_cast<ExtendedCCInterface*>(ret[0].asObject());
832 841
       if (iface) {
833
-        INFO("extended CC interface offered by cc_module '%s'\n", cc_module.c_str());
842
+        DBG("extended CC interface offered by cc_module '%s'\n", cc_module.c_str());
834 843
         cc_ext.push_back(iface);
835 844
       }
836 845
       else WARN("BUG: returned invalid extended CC interface by cc_module '%s'\n", cc_module.c_str());
837 846
     }
838 847
     catch (...) {
839
-      INFO("extended CC interface not supported by cc_module '%s'\n", cc_module.c_str());
848
+      DBG("extended CC interface not supported by cc_module '%s'\n", cc_module.c_str());
840 849
     }
841 850
   }
842 851
   return true;
... ...
@@ -1420,3 +1429,10 @@ void SBCCallLeg::changeRtpMode(RTPRelayMode new_mode)
1420 1429
   // FIXME: use AmB2BMedia in all RTP relay modes to avoid these problems?
1421 1430
   ERROR("BUG: not implemented yet\n");
1422 1431
 }
1432
+
1433
+void SBCCallLeg::initCCModules(const AmSipRequest &original_invite)
1434
+{
1435
+  for (vector<ExtendedCCInterface*>::iterator i = cc_ext.begin(); i != cc_ext.end(); ++i) {
1436
+    (*i)->init(this, original_invite);
1437
+  }
1438
+}
... ...
@@ -85,7 +85,8 @@ class SBCCallLeg : public CallLeg, public CredentialHolder
85 85
   void CCEnd();
86 86
   void CCEnd(const CCInterfaceListIteratorT& end_interface);
87 87
 
88
-  void connectCallee(const string& remote_party, const string& remote_uri, const string &from, const AmSipRequest &invite_req);
88
+  void connectCallee(const string& remote_party, const string& remote_uri, const string &from,
89
+      const AmSipRequest &original_invite, const AmSipRequest &invite_req);
89 90
   int filterSdp(AmMimeBody &body, const string &method);
90 91
   void appendTranscoderCodecs(AmSdp &sdp);
91 92
   void savePayloadIDs(AmSdp &sdp);
... ...
@@ -101,7 +102,7 @@ class SBCCallLeg : public CallLeg, public CredentialHolder
101 102
  public:
102 103
 
103 104
   SBCCallLeg(const SBCCallProfile& call_profile);
104
-  SBCCallLeg(const SBCCallLeg* caller, const SBCCallProfile& _call_profile);
105
+  SBCCallLeg(SBCCallLeg* caller, const AmSipRequest &original_invite);
105 106
   ~SBCCallLeg();
106 107
 
107 108
   void process(AmEvent* ev);
... ...
@@ -118,6 +119,7 @@ class SBCCallLeg : public CallLeg, public CredentialHolder
118 119
   UACAuthCred* getCredentials();
119 120
 
120 121
   void setAuthHandler(AmSessionEventHandler* h) { auth = h; }
122
+  void initCCModules(const AmSipRequest &original_invite);
121 123
 
122 124
   /** save call timer; only effective before call is connected */
123 125
   void saveCallTimer(int timer, double timeout);
... ...
@@ -131,7 +133,7 @@ class SBCCallLeg : public CallLeg, public CredentialHolder
131 133
   void setLocalParty(const string &party, const string &uri) { dlg.local_party = party; dlg.local_uri = uri; }
132 134
   void setRemoteParty(const string &party, const string &uri) { dlg.remote_party = party; dlg.remote_uri = uri; }
133 135
 
134
-  void addCallee(CallLeg *callee, const AmSipRequest &invite) { CallLeg::addCallee(callee, invite); }
136
+  void addCallee(SBCCallLeg *callee, const AmSipRequest &invite) { CallLeg::addCallee(callee, invite); }
135 137
   void addCallee(const string &session_tag, const AmSipRequest &invite) { CallLeg::addCallee(session_tag, invite); }
136 138
   void replaceExistingLeg(const string &session_tag, const AmSipRequest &invite) { CallLeg::replaceExistingLeg(session_tag, invite); }
137 139