]> git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/Service.cc
Merged from trunk
[thirdparty/squid.git] / src / adaptation / Service.cc
1 /*
2 * DEBUG: section XXX
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 ServiceConfig &aConfig): theConfig(aConfig)
11 {
12 debugs(93,3, HERE << "creating adaptation service " << theConfig.key);
13 }
14
15 Adaptation::Service::~Service()
16 {}
17
18 void
19 Adaptation::Service::finalize()
20 {
21 }
22
23 bool Adaptation::Service::broken() const
24 {
25 return probed() && !up();
26 }
27
28 bool
29 Adaptation::Service::wants(const ServiceFilter &filter) const
30 {
31 if (cfg().method != filter.method)
32 return false;
33
34 if (cfg().point != filter.point)
35 return false;
36
37 // sending a message to a broken service is likely to cause errors
38 if (cfg().bypass && broken())
39 return false;
40
41 if (up()) {
42 // Sending a message to a service that does not want it is useless.
43 // note that we cannot check wantsUrl for service that is not "up"
44 // note that even essential services are skipped on unwanted URLs!
45 return wantsUrl(filter.request->urlpath);
46 }
47
48 // The service is down and is either not bypassable or not probed due
49 // to the bypass && broken() test above. Thus, we want to use it!
50 return true;
51 }
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 }