reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
ProcessorChain.cxx
Go to the documentation of this file.
1#if defined(HAVE_CONFIG_H)
2#include "config.h"
3#endif
4
5#include <iostream>
6
11
12#include "rutil/Logger.hxx"
13#include "rutil/Inserter.hxx"
14
15#define RESIPROCATE_SUBSYSTEM resip::Subsystem::REPRO
16
17using namespace resip;
18using namespace repro;
19using namespace std;
20
21
23 Processor(Data::Empty, type),
24 mChainReady(false)
25{
26 switch(type)
27 {
28 case REQUEST_CHAIN:
29 setName("RequestProcessor");
30 break;
31 case RESPONSE_CHAIN:
32 setName("ResponseProcessor");
33 break;
34 case TARGET_CHAIN:
35 setName("TargetProcessor");
36 break;
37 case NO_TYPE:
38 default:
39 setName("UnknownProcessor");
40 break;
41 }
42 DebugLog(<< "Instantiating new " << mName << " chain");
43}
44
46{
47 //DebugLog (<< "Deleting Chain: " << this);
48 for (Chain::iterator i = mChain.begin(); i != mChain.end(); ++i)
49 {
50 //DebugLog (<< "Deleting RP: " << *i << " : " << **i);
51 delete *i;
52 }
53 mChain.clear();
54}
55
56void
57repro::ProcessorChain::addProcessor(unique_ptr<Processor> rp)
58{
59 DebugLog(<< "Adding new " << mName << " to chain: " << *(rp.get()));
60 resip_assert(!mChainReady);
61 rp->pushAddress((short)mChain.size());
62 rp->pushAddress(mAddress);
63 rp->setChainType(mType);
64 mChain.push_back(rp.release());
65}
66
69{
70 //DebugLog(<< mName << " handling request: " << *this << "; reqcontext = " << rc);
71
72 if(!mChainReady)
73 {
74 onChainComplete();
75 resip_assert(mChainReady);
76 }
77
78 processor_action_t action;
79 unsigned int position=0;
80
82
83 if(msg)
84 {
85 ProcessorMessage* proc = dynamic_cast<ProcessorMessage*>(msg);
86
87 if(proc)
88 {
89 position=proc->popAddr();
90 }
91 }
92
93 for (; (position >=0 && position < mChain.size()); ++position)
94 {
95 DebugLog(<< "Chain invoking " << mName << ": " << *(mChain[position]));
96
97 action = mChain[position]->process(rc);
98
99 if (action == SkipAllChains)
100 {
101 DebugLog(<< mName << " aborted all chains: " << *(mChain[position]));
102 return SkipAllChains;
103 }
104
105 if (action == WaitingForEvent)
106 {
107 DebugLog(<< mName << " waiting for async response: " << *(mChain[position]));
108 return WaitingForEvent;
109 }
110
111 if (action == SkipThisChain)
112 {
113 DebugLog(<< mName << " skipping current chain: " << *(mChain[position]));
114 return Continue;
115 }
116
117 }
118 //DebugLog(<< "Monkey done processing: " << *(mChain[position]));
119 return Continue;
120}
121
122void
123ProcessorChain::pushAddress(const std::vector<short>& address)
124{
125 Processor::pushAddress(address);
126 for(std::vector<Processor*>::iterator i=mChain.begin();i!=mChain.end();++i)
127 {
128 (**i).pushAddress(address);
129 }
130}
131
132void
133ProcessorChain::pushAddress(const short address)
134{
135 Processor::pushAddress(address);
136 for(std::vector<Processor*>::iterator i=mChain.begin();i!=mChain.end();++i)
137 {
138 (**i).pushAddress(address);
139 }
140}
141
142
143void
145{
146 mType=type;
147 std::vector<Processor*>::iterator i;
148 for(i=mChain.begin();i!=mChain.end();++i)
149 {
150 (*i)->setChainType(type);
151 }
152}
153
154void
155ProcessorChain::onChainComplete()
156{
157 short i = 0;
158 for(Chain::iterator it = mChain.begin() ; it != mChain.end(); it++)
159 {
160 (*it)->mAddress.clear();
161 (*it)->pushAddress(i++);
162 (*it)->pushAddress(mAddress);
163 }
164 mChainReady = true;
165}
166
168repro::operator << (EncodeStream &os, const repro::ProcessorChain &pc)
169{
170 os << pc.getName() << " chain: " << InserterP(pc.mChain);
171 return os;
172}
173
174
175/* ====================================================================
176 * The Vovida Software License, Version 1.0
177 *
178 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
179 *
180 * Redistribution and use in source and binary forms, with or without
181 * modification, are permitted provided that the following conditions
182 * are met:
183 *
184 * 1. Redistributions of source code must retain the above copyright
185 * notice, this list of conditions and the following disclaimer.
186 *
187 * 2. Redistributions in binary form must reproduce the above copyright
188 * notice, this list of conditions and the following disclaimer in
189 * the documentation and/or other materials provided with the
190 * distribution.
191 *
192 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
193 * and "Vovida Open Communication Application Library (VOCAL)" must
194 * not be used to endorse or promote products derived from this
195 * software without prior written permission. For written
196 * permission, please contact vocal@vovida.org.
197 *
198 * 4. Products derived from this software may not be called "VOCAL", nor
199 * may "VOCAL" appear in their name, without prior written
200 * permission of Vovida Networks, Inc.
201 *
202 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
203 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
204 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
205 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
206 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
207 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
208 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
209 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
210 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
211 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
212 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
213 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
214 * DAMAGE.
215 *
216 * ====================================================================
217 *
218 * This software consists of voluntary contributions made by Vovida
219 * Networks, Inc. and many individuals on behalf of Vovida Networks,
220 * Inc. For more information on Vovida Networks, Inc., please see
221 * <http://www.vovida.org/>.
222 *
223 */
#define DebugLog(args_)
Definition Logger.hxx:128
#define resip_assert(x)
This file needs to work for both C and C++ code.
virtual void pushAddress(const std::vector< short > &address)
virtual void setChainType(ChainType type)
ProcessorChain(ChainType type)
void addProcessor(std::unique_ptr< Processor >)
virtual processor_action_t process(RequestContext &)
resip::Data mName
Definition Processor.hxx:53
std::vector< short > mAddress
Definition Processor.hxx:51
virtual void setName(const resip::Data &name)
Definition Processor.cxx:51
virtual const resip::Data & getName() const
Definition Processor.cxx:57
ChainType mType
Definition Processor.hxx:52
virtual void pushAddress(const std::vector< short > &address)
Definition Processor.cxx:24
resip::Message * getCurrentEvent()
Returns the event that we are currently working on.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
The base-class used for message-passing.
Definition Message.hxx:21
This Class is used to implement a primitive form of RPC using loose XML formatting.
EncodeStream & operator<<(EncodeStream &os, const repro::Processor &rp)
Definition Processor.cxx:69
dcm! – add UnusedChecking(_enum) below;
InserterPClass< T > InserterP(const T &t)
Templatized function to construct an instance of InserterClass for a container to be inserted.
Definition Inserter.hxx:558
#define EncodeStream