- Timestamp:
- Nov 29, 2013 5:56:02 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/pjsua2/pjsip-apps/src/samples/pjsua2_demo.cpp
r4647 r4663 24 24 using namespace pj; 25 25 26 class MyAccount; 27 28 class MyCall : public Call 29 { 30 private: 31 MyAccount *myAcc; 32 33 public: 34 MyCall(Account &acc, int call_id = PJSUA_INVALID_ID) 35 : Call(acc, call_id) 36 { 37 myAcc = (MyAccount *)&acc; 38 } 39 40 virtual void onCallState(OnCallStateParam &prm); 41 }; 42 26 43 class MyAccount : public Account 27 44 { 45 public: 46 std::vector<Call *> calls; 47 28 48 public: 29 49 MyAccount() 30 50 {} 31 51 52 ~MyAccount() 53 { 54 std::cout << "*** Account is being deleted: No of calls=" 55 << calls.size() << std::endl; 56 } 57 58 void removeCall(Call *call) 59 { 60 for (std::vector<Call *>::iterator it = calls.begin(); 61 it != calls.end(); ++it) 62 { 63 if (*it == call) { 64 calls.erase(it); 65 break; 66 } 67 } 68 } 69 32 70 virtual void onRegState(OnRegStateParam &prm) 33 71 { … … 36 74 << prm.code << std::endl; 37 75 } 76 77 virtual void onIncomingCall(OnIncomingCallParam &iprm) 78 { 79 Call *call = new MyCall(*this, iprm.callId); 80 CallInfo ci = call->getInfo(); 81 CallOpParam prm; 82 83 std::cout << "*** Incoming Call: " << ci.remoteURI << " [" 84 << ci.stateText << "]" << std::endl; 85 86 calls.push_back(call); 87 prm.statusCode = (pjsip_status_code)200; 88 call->answer(prm); 89 } 38 90 }; 91 92 void MyCall::onCallState(OnCallStateParam &prm) 93 { 94 CallInfo ci = getInfo(); 95 std::cout << "*** Call: " << ci.remoteURI << " [" << ci.stateText 96 << "]" << std::endl; 97 98 if (ci.state == PJSIP_INV_STATE_DISCONNECTED) { 99 myAcc->removeCall(this); 100 /* Delete the call */ 101 delete this; 102 } 103 } 39 104 40 105 static void mainProg1() throw(Error) … … 65 130 acc_cfg.sipConfig.authCreds.push_back( AuthCredInfo("digest", "*", 66 131 "test1", 0, "test1") ); 67 std::auto_ptr< Account> acc(new MyAccount);132 std::auto_ptr<MyAccount> acc(new MyAccount); 68 133 acc->create(acc_cfg); 69 134 70 135 pj_thread_sleep(2000); 71 136 137 // Make outgoing call 138 Call *call = new MyCall(*acc); 139 acc->calls.push_back(call); 140 CallOpParam prm(true); 141 prm.opt.audioCount = 1; 142 prm.opt.videoCount = 0; 143 call->makeCall("sip:test1@pjsip.org", prm); 144 145 // Hangup all calls 146 pj_thread_sleep(8000); 147 ep.hangupAllCalls(); 148 pj_thread_sleep(4000); 149 72 150 // Destroy library 73 151 std::cout << "*** PJSUA2 SHUTTING DOWN ***" << std::endl; … … 190 268 191 269 try { 192 mainProg ();270 mainProg1(); 193 271 std::cout << "Success" << std::endl; 194 272 } catch (Error & err) {
Note: See TracChangeset
for help on using the changeset viewer.