]> git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/Service.h
Merge from trunk
[thirdparty/squid.git] / src / adaptation / Service.h
1 #ifndef SQUID_ADAPTATION__SERVICE_H
2 #define SQUID_ADAPTATION__SERVICE_H
3
4 #include "SquidString.h"
5 #include "RefCount.h"
6 #include "adaptation/forward.h"
7 #include "adaptation/Elements.h"
8 #include "adaptation/ServiceConfig.h"
9
10 // TODO: Move src/ICAP/ICAPServiceRep.h API comments here and update them
11
12 class HttpMsg;
13 class HttpRequest;
14
15 namespace Adaptation
16 {
17
18 // manages adaptation service configuration in squid.conf
19 // specific adaptation mechanisms extend this class
20 class Service: public RefCountable
21 {
22 public:
23 typedef RefCount<Service> Pointer;
24 typedef String Id;
25
26 public:
27 Service(const ServiceConfig &aConfig);
28 virtual ~Service();
29
30 // call when the service is no longer needed or valid
31 virtual void invalidate() = 0;
32
33 virtual bool probed() const = 0; // see comments above
34 virtual bool broken() const;
35 virtual bool up() const = 0; // see comments above
36
37 virtual Initiate *makeXactLauncher(Initiator *, HttpMsg *virginHeader, HttpRequest *virginCause) = 0;
38
39 typedef void Callback(void *data, Pointer &service);
40 void callWhenReady(Callback *cb, void *data);
41
42 bool wants(const ServiceFilter &filter) const;
43
44 // the methods below can only be called on an up() service
45 virtual bool wantsUrl(const String &urlPath) const = 0;
46
47 // called by transactions to report service failure
48 virtual void noteFailure() = 0;
49
50 const ServiceConfig &cfg() const { return theConfig; }
51
52 virtual void finalize(); // called after creation
53
54 protected:
55 ServiceConfig &writeableCfg() { return theConfig; }
56
57 private:
58 ServiceConfig theConfig;
59 };
60
61 typedef Service::Pointer ServicePointer;
62
63 typedef Vector<Adaptation::ServicePointer> Services;
64 extern Services &AllServices();
65 extern ServicePointer FindService(const Service::Id &key);
66
67 } // namespace Adaptation
68
69 #endif /* SQUID_ADAPTATION__SERVICE_H */