]> git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/Service.cc
Renamed squid.h to squid-old.h and config.h to squid.h
[thirdparty/squid.git] / src / adaptation / Service.cc
1 /*
2 * DEBUG: section 93 Adaptation
3 */
4
5 #include "squid-old.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
55 Adaptation::Services &
56 Adaptation::AllServices()
57 {
58 static Services TheServices;
59 return TheServices;
60 }
61
62 Adaptation::ServicePointer
63 Adaptation::FindService(const Service::Id& key)
64 {
65 typedef Services::iterator SI;
66 for (SI i = AllServices().begin(); i != AllServices().end(); ++i) {
67 if ((*i)->cfg().key == key)
68 return *i;
69 }
70 return NULL;
71 }
72
73 void Adaptation::DetachServices()
74 {
75 while (!AllServices().empty())
76 AllServices().pop_back()->detach();
77 }