]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/ecap/ServiceRep.cc
2 * DEBUG: section 93 eCAP Interface
6 #include <libecap/adapter/service.h>
7 #include "adaptation/ecap/ServiceRep.h"
8 #include "adaptation/ecap/XactionRep.h"
9 #include "base/TextException.h"
11 // configured eCAP service wrappers
12 static std::list
<Adaptation::Ecap::ServiceRep::AdapterService
> TheServices
;
14 Adaptation::Ecap::ServiceRep::ServiceRep(const Adaptation::ServiceConfig
&cfg
):
15 /*AsyncJob("Adaptation::Ecap::ServiceRep"),*/ Adaptation::Service(cfg
),
20 Adaptation::Ecap::ServiceRep::~ServiceRep()
24 void Adaptation::Ecap::ServiceRep::noteFailure()
26 assert(false); // XXX: should this be ICAP-specific?
30 Adaptation::Ecap::ServiceRep::finalize()
32 Adaptation::Service::finalize();
33 theService
= FindAdapterService(cfg().uri
);
35 debugs(93,3, HERE
<< "starting eCAP service: " << theService
->uri());
38 debugs(93,1, "Warning: configured ecap_service was not loaded: " <<
43 bool Adaptation::Ecap::ServiceRep::probed() const
45 return true; // we "probe" the adapter in finalize().
48 bool Adaptation::Ecap::ServiceRep::up() const
50 return theService
!= NULL
;
53 bool Adaptation::Ecap::ServiceRep::wantsUrl(const String
&urlPath
) const
56 return theService
->wantsUrl(urlPath
.termedBuf());
59 Adaptation::Initiate
*
60 Adaptation::Ecap::ServiceRep::makeXactLauncher(Adaptation::Initiator
*initiator
,
61 HttpMsg
*virgin
, HttpRequest
*cause
)
64 XactionRep
*rep
= new XactionRep(initiator
, virgin
, cause
, Pointer(this));
65 XactionRep::AdapterXaction
x(theService
->makeXaction(rep
));
70 // returns a temporary string depicting service status, for debugging
71 const char *Adaptation::Ecap::ServiceRep::status() const
73 // TODO: move generic stuff from eCAP and ICAP to Adaptation
82 buf
.append("down", 4);
85 buf
.append(",detached", 9);
93 void Adaptation::Ecap::ServiceRep::detach()
98 bool Adaptation::Ecap::ServiceRep::detached() const
103 Adaptation::Ecap::ServiceRep::AdapterService
104 Adaptation::Ecap::FindAdapterService(const String
& serviceUri
)
106 typedef std::list
<ServiceRep::AdapterService
>::const_iterator ASCI
;
107 for (ASCI s
= TheServices
.begin(); s
!= TheServices
.end(); ++s
) {
109 if (serviceUri
== (*s
)->uri().c_str())
112 return ServiceRep::AdapterService();
116 Adaptation::Ecap::RegisterAdapterService(const Adaptation::Ecap::ServiceRep::AdapterService
& adapterService
)
118 typedef std::list
<ServiceRep::AdapterService
>::iterator ASI
;
119 for (ASI s
= TheServices
.begin(); s
!= TheServices
.end(); ++s
) {
121 if (adapterService
->uri() == (*s
)->uri()) {
123 debugs(93, 3, "updated eCAP module service: " <<
124 adapterService
->uri());
128 TheServices
.push_back(adapterService
);
129 debugs(93, 3, "registered eCAP module service: " << adapterService
->uri());
133 Adaptation::Ecap::UnregisterAdapterService(const String
& serviceUri
)
135 typedef std::list
<ServiceRep::AdapterService
>::iterator ASI
;
136 for (ASI s
= TheServices
.begin(); s
!= TheServices
.end(); ++s
) {
137 if (serviceUri
== (*s
)->uri().c_str()) {
138 TheServices
.erase(s
);
139 debugs(93, 3, "unregistered eCAP module service: " << serviceUri
);
143 debugs(93, 3, "failed to unregister eCAP module service: " << serviceUri
);
147 Adaptation::Ecap::CheckUnusedAdapterServices(const Adaptation::Services
& cfgs
)
149 typedef std::list
<ServiceRep::AdapterService
>::const_iterator ASCI
;
150 for (ASCI loaded
= TheServices
.begin(); loaded
!= TheServices
.end();
153 for (Services::const_iterator cfged
= cfgs
.begin();
154 cfged
!= cfgs
.end() && !found
; ++cfged
) {
155 found
= (*cfged
)->cfg().uri
== (*loaded
)->uri().c_str();
158 debugs(93, 1, "Warning: loaded eCAP service has no matching " <<
159 "ecap_service config option: " << (*loaded
)->uri());