1 #ifndef __SESSION_UPDATE_H
2 #define __SESSION_UPDATE_H
3 
4 #include <string>
5 #include "AmMimeBody.h"
6 #include "AmAppTimer.h"
7 
8 class CallLeg;
9 
10 /* interface to be implemented by re-applicable operations on a session
11  * expected usage: the operation generates a reINVITE and if this reINVITE fails
12  * with specific error code (491, ...) the operation can be re-applied
13  *
14  * Note that only one session update operation may be running, others need
15  * to wait for finishing the current one.
16  * */
17 class SessionUpdate
18 {
19   private:
20     int request_cseq;
21 
22   protected:
setCSeq(int cseq)23     void setCSeq(int cseq) { request_cseq = cseq; }
24 
SessionUpdate()25     SessionUpdate(): request_cseq(-1) { }
26 
27   public:
28     // used to (re)apply session update
29     // returns the CSeq of generated request (reINVITE/...)
30     virtual void apply(CallLeg *call) = 0;
31 
32 //    virtual void onSipReply(CallLeg *call, AmSipReply &reply);
~SessionUpdate()33     virtual ~SessionUpdate() { }
34 
35     // check whether update request was sent out
hasCSeq()36     bool hasCSeq() const { return request_cseq >= 0; }
37 
38     // check the request cseq value
hasCSeq(int cseq)39     bool hasCSeq(int cseq) const { return request_cseq == cseq; }
40 
41     // reset internal state to be prepared for retrying the update operation
reset()42     virtual void reset() { setCSeq(-1); }
43 
44 };
45 
46 class PutOnHold: public SessionUpdate
47 {
48   public:
49     virtual void apply(CallLeg *call);
50 };
51 
52 class ResumeHeld: public SessionUpdate
53 {
54   public:
55     virtual void apply(CallLeg *call);
56 };
57 
58 class Reinvite: public SessionUpdate
59 {
60     std::string hdrs;
61     AmMimeBody body;
62     unsigned r_cseq;
63     bool relayed_invite;
64     bool establishing;
65 
66   public:
67     virtual void apply(CallLeg *call);
68 
69     Reinvite(const std::string& _hdrs, const AmMimeBody& _body,
70         bool _establishing = false,
71         bool _relayed_invite = false, unsigned int _r_cseq = 0):
hdrs(_hdrs)72           hdrs(_hdrs), body(_body), r_cseq(_r_cseq),
73           relayed_invite(_relayed_invite), establishing(_establishing) { }
74 };
75 
76 class SessionUpdateTimer: public DirectAppTimer
77 {
78   private:
79     std::string ltag;
80     bool has_started;
81 
82   public:
SessionUpdateTimer()83     SessionUpdateTimer(): has_started(false) { }
~SessionUpdateTimer()84     ~SessionUpdateTimer() { if (has_started) AmAppTimer::instance()->removeTimer(this); }
85 
86     void fire();
started()87     bool started() { return has_started; }
88 
89     // start the timer (local tag is supplied here because it may change during
90     // call legs's lifetime)
91     void start(const std::string &_ltag, double delay);
92 };
93 
94 #endif
95