]> git.ipfire.org Git - thirdparty/squid.git/blame - src/adaptation/Service.cc
Source Maintenance: enforce #include statement block ordering
[thirdparty/squid.git] / src / adaptation / Service.cc
CommitLineData
a68cf076 1/*
b510f3a1 2 * DEBUG: section 93 Adaptation
a68cf076
AR
3 */
4
582c2af2 5#include "squid.h"
a22e6cd3
AR
6#include "HttpRequest.h"
7#include "adaptation/ServiceFilter.h"
a68cf076
AR
8#include "adaptation/Service.h"
9
6666da11 10Adaptation::Service::Service(const ServiceConfigPointer &aConfig): theConfig(aConfig)
a5c0ca41 11{
e1e90d26
AR
12 Must(theConfig != NULL);
13 debugs(93,3, HERE << "creating adaptation service " << cfg().key);
a5c0ca41 14}
a68cf076
AR
15
16Adaptation::Service::~Service()
17{}
18
62c7f90e 19void
d81a31f1 20Adaptation::Service::finalize()
a68cf076 21{
62c7f90e
AR
22}
23
201438ac
AR
24bool Adaptation::Service::broken() const
25{
26 return probed() && !up();
27}
28
a22e6cd3
AR
29bool
30Adaptation::Service::wants(const ServiceFilter &filter) const
31{
32 if (cfg().method != filter.method)
33 return false;
34
35 if (cfg().point != filter.point)
36 return false;
37
38 // sending a message to a broken service is likely to cause errors
39 if (cfg().bypass && broken())
40 return false;
41
42 if (up()) {
43 // Sending a message to a service that does not want it is useless.
44 // note that we cannot check wantsUrl for service that is not "up"
45 // note that even essential services are skipped on unwanted URLs!
46 return wantsUrl(filter.request->urlpath);
47 }
48
49 // The service is down and is either not bypassable or not probed due
50 // to the bypass && broken() test above. Thus, we want to use it!
51 return true;
52}
53
62c7f90e
AR
54Adaptation::Services &
55Adaptation::AllServices()
56{
57 static Services TheServices;
58 return TheServices;
59}
60
61Adaptation::ServicePointer
62Adaptation::FindService(const Service::Id& key)
63{
64 typedef Services::iterator SI;
65 for (SI i = AllServices().begin(); i != AllServices().end(); ++i) {
66 if ((*i)->cfg().key == key)
67 return *i;
26ac0430 68 }
62c7f90e 69 return NULL;
a68cf076 70}
76fc7e57
AJ
71
72void Adaptation::DetachServices()
73{
74 while (!AllServices().empty())
75 AllServices().pop_back()->detach();
76}