]> git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/Service.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / adaptation / Service.h
1 /*
2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #ifndef SQUID_ADAPTATION__SERVICE_H
10 #define SQUID_ADAPTATION__SERVICE_H
11
12 #include "AccessLogEntry.h"
13 #include "adaptation/Elements.h"
14 #include "adaptation/forward.h"
15 #include "adaptation/ServiceConfig.h"
16 #include "base/RefCount.h"
17 #include "SquidString.h"
18
19 // TODO: Move src/ICAP/ICAPServiceRep.h API comments here and update them
20
21 class HttpMsg;
22 class HttpRequest;
23
24 namespace Adaptation
25 {
26
27 // manages adaptation service configuration in squid.conf
28 // specific adaptation mechanisms extend this class
29 class Service: public RefCountable
30 {
31 public:
32 typedef RefCount<Service> Pointer;
33 typedef String Id;
34
35 public:
36 explicit Service(const ServiceConfigPointer &aConfig);
37 virtual ~Service();
38
39 virtual bool probed() const = 0; // see comments above
40 virtual bool broken() const;
41 virtual bool up() const = 0; // see comments above
42
43 virtual Initiate *makeXactLauncher(HttpMsg *virginHeader, HttpRequest *virginCause, AccessLogEntry::Pointer &alp) = 0;
44
45 bool wants(const ServiceFilter &filter) const;
46
47 // the methods below can only be called on an up() service
48 virtual bool wantsUrl(const SBuf &urlPath) const = 0;
49
50 // called by transactions to report service failure
51 virtual void noteFailure() = 0;
52
53 const ServiceConfig &cfg() const { return *theConfig; }
54
55 virtual void finalize(); // called after creation
56
57 /// called when removed from the config; the service will be
58 /// auto-destroyed when the last refcounting user leaves
59 virtual void detach() = 0;
60 /// whether detached() was called
61 virtual bool detached() const = 0;
62
63 protected:
64 ServiceConfig &writeableCfg() { return *theConfig; }
65
66 private:
67 ServiceConfigPointer theConfig;
68 };
69
70 typedef Service::Pointer ServicePointer;
71
72 typedef std::vector<Adaptation::ServicePointer> Services;
73 Services &AllServices();
74 ServicePointer FindService(const Service::Id &key);
75
76 /// detach all adaptation services from current configuration
77 void DetachServices();
78
79 } // namespace Adaptation
80
81 #endif /* SQUID_ADAPTATION__SERVICE_H */
82