reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
ParkOrbit.cxx
Go to the documentation of this file.
1#include "../UserAgent.hxx"
2#include "AppSubsystem.hxx"
3#include "ParkOrbit.hxx"
4#include "Server.hxx"
5
6#include <rutil/Log.hxx>
7#include <rutil/Logger.hxx>
9
10using namespace recon;
11using namespace resip;
12using namespace std;
13
14#define RESIPROCATE_SUBSYSTEM AppSubsystem::MOHPARKSERVER
15#define ALLOCATIONTIME 32 // The number of seconds to condsider a participant allocated, when a retreival is attempted
16 // If the call fails to retrieve, it will still be available to be retrieved by
17 // another attempt after this time expires.
18namespace mohparkserver
19{
20
21ParkOrbit::ParkOrbit(Server& server, unsigned long orbit, unsigned long maxParkTime, const resip::Uri& musicFilename) :
22 mServer(server),
23 mOrbit(orbit),
24 mMaxParkTime(maxParkTime)
25{
26 // Create an initial conversation and start music
28
29 // Play Music
30 mServer.createMediaResourceParticipant(mConversationHandle, musicFilename);
31
32 InfoLog(<< "ParkOrbit::ParkOrbit created orbit " << mOrbit);
33}
34
36{
37 mServer.destroyConversation(mConversationHandle);
38 InfoLog(<< "ParkOrbit::~ParkOrbit destroyed orbit " << mOrbit);
39}
40
41bool
42ParkOrbit::addParticipant(recon::ParticipantHandle participantHandle, const Uri& parkedUri, const Uri& parkerUri)
43{
44 if(mParticipants.size() < DEFAULT_BRIDGE_MAX_IN_OUTPUTS-3)
45 {
46 mServer.addParticipant(mConversationHandle, participantHandle);
47 mServer.modifyParticipantContribution(mConversationHandle, participantHandle, 100, 0 /* Mute participant */);
48 mServer.answerParticipant(participantHandle);
49
50 if(mMaxParkTime != 0)
51 {
52 mServer.getMyUserAgent()->startApplicationTimer(MAXPARKTIMEOUT, std::chrono::seconds(mMaxParkTime), participantHandle);
53 }
54
55 mParticipants.push_back(new ParticipantOrbitInfo(participantHandle, parkedUri, parkerUri));
56 InfoLog(<< "ParkOrbit::addParticipant added participant=" << participantHandle << " to orbit " << mOrbit << " (size=" << mParticipants.size() << "), parkedUri=" << parkedUri << ", parkerUri=" << parkerUri);
57 return true;
58 }
59 else
60 {
61 mServer.rejectParticipant(participantHandle, 486);
62 WarningLog(<< "ParkOrbit::addParticipant cannot add participant=" << participantHandle << " to full orbit " << mOrbit << " (size=" << mParticipants.size() << ")");
63 return false;
64 }
65}
66
67bool
69{
70 ParticipantQueue::iterator it = mParticipants.begin();
71 for(;it!=mParticipants.end();it++)
72 {
73 if((*it)->mParticipantHandle == participantHandle)
74 {
75 delete *it;
76 mParticipants.erase(it);
77 InfoLog(<< "ParkOrbit::removeParticipant removed participant=" << participantHandle << " from orbit " << mOrbit << " (size=" << mParticipants.size() << ")");
78 return true;
79 }
80 }
81 return false;
82}
83
86{
87 ParticipantHandle participantHandle = 0;
88 if(!mParticipants.empty())
89 {
91 if(now - mParticipants.front()->mAllocationTime > ALLOCATIONTIME)
92 {
93 participantHandle = mParticipants.front()->mParticipantHandle;
94 mParticipants.front()->mAllocationTime = now;
95 // Move to back of queue
96 mParticipants.push_back(mParticipants.front());
97 mParticipants.pop_front();
98 InfoLog(<< "ParkOrbit::getNextQueuedParticipant removed participant=" << participantHandle << " from orbit " << mOrbit << " (size=" << mParticipants.size() << ")");
99 }
100 }
101 return participantHandle;
102}
103
104bool
106{
107 ParticipantQueue::iterator it = mParticipants.begin();
108 for(;it!=mParticipants.end();it++)
109 {
110 if((*it)->mParticipantHandle == participantHandle)
111 {
112 InfoLog(<< "ParkOrbit::onMaxParkTimeout sending parked call back to " << (*it)->mParkerUri << ", participant=" << participantHandle << " from orbit " << mOrbit << " (size=" << mParticipants.size() << ")");
113 mServer.redirectParticipant(participantHandle, NameAddr((*it)->mParkerUri));
114 (*it)->mAllocationTime = resip::Timer::getTimeSecs(); // Ensure call can't be retrieved between now and destruction
115 mServer.destroyParticipant(participantHandle); // Fully blind transfer - don't wait for notifies
116 return true;
117 }
118 }
119 return false;
120}
121
122}
123
124/* ====================================================================
125
126 Copyright (c) 2011-2021, SIP Spectrum, Inc.
127 All rights reserved.
128
129 Redistribution and use in source and binary forms, with or without
130 modification, are permitted provided that the following conditions are
131 met:
132
133 1. Redistributions of source code must retain the above copyright
134 notice, this list of conditions and the following disclaimer.
135
136 2. Redistributions in binary form must reproduce the above copyright
137 notice, this list of conditions and the following disclaimer in the
138 documentation and/or other materials provided with the distribution.
139
140 3. Neither the name of SIP Spectrum nor the names of its contributors
141 may be used to endorse or promote products derived from this
142 software without specific prior written permission.
143
144 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
145 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
146 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
147 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
148 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
149 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
150 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
151 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
152 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
153 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
154 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
155
156 ==================================================================== */
157
#define InfoLog(args_)
Definition Logger.hxx:131
#define WarningLog(args_)
Definition Logger.hxx:134
#define ALLOCATIONTIME
Definition ParkOrbit.cxx:15
#define MAXPARKTIMEOUT
Definition Server.hxx:19
bool onMaxParkTimeout(recon::ParticipantHandle participantHandle)
bool removeParticipant(recon::ParticipantHandle participantHandle)
Definition ParkOrbit.cxx:68
bool addParticipant(recon::ParticipantHandle participantHandle, const resip::Uri &parkedUri, const resip::Uri &parkerUri)
Definition ParkOrbit.cxx:42
recon::ParticipantHandle getNextQueuedParticipant()
Definition ParkOrbit.cxx:85
ParkOrbit(Server &server, unsigned long orbit, unsigned long maxParkTime, const resip::Uri &musicFilename)
Definition ParkOrbit.cxx:21
recon::UserAgent * getMyUserAgent()
Definition Server.hxx:60
virtual void redirectParticipant(ParticipantHandle partHandle, const resip::NameAddr &destination, unsigned int redirectCode=302, RedirectSuccessCondition successCondition=RedirectSuccessOnConnected)
Redirects the participant to another endpoint.
virtual ParticipantHandle createMediaResourceParticipant(ConversationHandle convHandle, const resip::Uri &mediaUrl, const std::shared_ptr< resip::Data > &playAudioBuffer=std::shared_ptr< resip::Data >(), void *recordingCircularBuffer=0)
Creates a new media resource participant in the specified conversation.
virtual void answerParticipant(ParticipantHandle partHandle)
Signal to the participant that the call is answered.
virtual void rejectParticipant(ParticipantHandle partHandle, unsigned int rejectCode)
Rejects an incoming remote participant with the specified code.
virtual void destroyParticipant(ParticipantHandle partHandle)
Ends connections to the participant and removes it from all active conversations.
virtual void addParticipant(ConversationHandle convHandle, ParticipantHandle partHandle)
Adds the specified participant to the specified conversation.
virtual void destroyConversation(ConversationHandle convHandle)
Destroys an existing Conversation, and ends all participants that solely belong to this conversation.
virtual ConversationHandle createConversation(AutoHoldMode autoHoldMode=AutoHoldEnabled)
Create a new empty Conversation to which participants can be added.
virtual void modifyParticipantContribution(ConversationHandle convHandle, ParticipantHandle partHandle, unsigned int inputGain, unsigned int outputGain)
Modifies how the participant contributes to the particular conversation.
virtual void startApplicationTimer(unsigned int timerId, std::chrono::duration< double > duration, unsigned int seqNumber)
Used by an application to start a timer that is managed by the useragent.
Represents the "name-addr" and the "addr-spec" elements in the RFC 3261 grammar.
Definition NameAddr.hxx:19
static uint64_t getTimeSecs()
Returns the current clock time in seconds.
Definition Timer.hxx:78
Represents the "SIP-URI" and "SIPS-URI" elements in the RFC 3261 grammar.
Definition Uri.hxx:22
unsigned int ParticipantHandle
dcm! – add UnusedChecking(_enum) below;
unsigned __int64 uint64_t
Definition stdint.h:95