]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/adaptation/Service.h
Source Format Enforcement (#1234)
[thirdparty/squid.git] / src / adaptation / Service.h
index 15806dd3eaf91deb64c2a4511ef682167aece493..c7ea7f9b84cc29d7b376adc06d9a26caa8152d1b 100644 (file)
@@ -1,18 +1,26 @@
+/*
+ * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
 #ifndef SQUID_ADAPTATION__SERVICE_H
 #define SQUID_ADAPTATION__SERVICE_H
 
-#include "SquidString.h"
-#include "RefCount.h"
-#include "adaptation/forward.h"
+#include "AccessLogEntry.h"
 #include "adaptation/Elements.h"
+#include "adaptation/forward.h"
 #include "adaptation/ServiceConfig.h"
+#include "base/RefCount.h"
+#include "http/forward.h"
+#include "SquidString.h"
 
 // TODO: Move src/ICAP/ICAPServiceRep.h API comments here and update them
 
-class HttpMsg;
-class HttpRequest;
-
-namespace Adaptation {
+namespace Adaptation
+{
 
 // manages adaptation service configuration in squid.conf
 // specific adaptation mechanisms extend this class
@@ -23,44 +31,50 @@ public:
     typedef String Id;
 
 public:
-    Service(const ServiceConfig &aConfig);
-    virtual ~Service();
-
-    // call when the service is no longer needed or valid
-    virtual void invalidate() = 0;
+    explicit Service(const ServiceConfigPointer &aConfig);
+    ~Service() override;
 
     virtual bool probed() const = 0; // see comments above
     virtual bool broken() const;
     virtual bool up() const = 0; // see comments above
 
-    virtual Initiate *makeXactLauncher(Initiator *, HttpMsg *virginHeader, HttpRequest *virginCause) = 0;
+    virtual Initiate *makeXactLauncher(Http::Message *virginHeader, HttpRequest *virginCause, AccessLogEntry::Pointer &alp) = 0;
 
-    typedef void Callback(void *data, Pointer &service);
-    void callWhenReady(Callback *cb, void *data);
+    bool wants(const ServiceFilter &filter) const;
 
     // the methods below can only be called on an up() service
-    virtual bool wantsUrl(const String &urlPath) const = 0;
+    virtual bool wantsUrl(const SBuf &urlPath) const = 0;
 
     // called by transactions to report service failure
     virtual void noteFailure() = 0;
 
-    const ServiceConfig &cfg() const { return theConfig; }
+    const ServiceConfig &cfg() const { return *theConfig; }
 
     virtual void finalize(); // called after creation
 
+    /// called when removed from the config; the service will be
+    /// auto-destroyed when the last refcounting user leaves
+    virtual void detach() = 0;
+    /// whether detached() was called
+    virtual bool detached() const = 0;
+
 protected:
-    ServiceConfig &writeableCfg() { return theConfig; }
+    ServiceConfig &writeableCfg() { return *theConfig; }
 
 private:
-    ServiceConfig theConfig;
+    ServiceConfigPointer theConfig;
 };
 
 typedef Service::Pointer ServicePointer;
 
-typedef Vector<Adaptation::ServicePointer> Services;
-extern Services &AllServices();
-extern ServicePointer FindService(const Service::Id &key);
+typedef std::vector<Adaptation::ServicePointer> Services;
+Services &AllServices();
+ServicePointer FindService(const Service::Id &key);
+
+/// detach all adaptation services from current configuration
+void DetachServices();
 
 } // namespace Adaptation
 
 #endif /* SQUID_ADAPTATION__SERVICE_H */
+