]> git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/Service.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / adaptation / Service.cc
1 /*
2 * DEBUG: section 93 Adaptation
3 */
4
5 #include "squid.h"
6 #include "HttpRequest.h"
7 #include "adaptation/ServiceFilter.h"
8 #include "adaptation/Service.h"
9
10 Adaptation::Service::Service(const ServiceConfigPointer &aConfig): theConfig(aConfig)
11 {
12 Must(theConfig != NULL);
13 debugs(93,3, HERE << "creating adaptation service " << cfg().key);
14 }
15
16 Adaptation::Service::~Service()
17 {}
18
19 void
20 Adaptation::Service::finalize()
21 {
22 }
23
24 bool Adaptation::Service::broken() const
25 {
26 return probed() && !up();
27 }
28
29 bool
30 Adaptation::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
54 Adaptation::Services &
55 Adaptation::AllServices()
56 {
57 static Services TheServices;
58 return TheServices;
59 }
60
61 Adaptation::ServicePointer
62 Adaptation::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;
68 }
69 return NULL;
70 }
71
72 void Adaptation::DetachServices()
73 {
74 while (!AllServices().empty())
75 AllServices().pop_back()->detach();
76 }