ServiceGroups.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 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_GROUPS_H
10#define SQUID_ADAPTATION__SERVICE_GROUPS_H
11
12#include "adaptation/Elements.h"
13#include "adaptation/forward.h"
14#include "base/RefCount.h"
15#include "SquidString.h"
16
17#include <vector>
18
19namespace Adaptation
20{
21
22// Interface for grouping adaptation services together.
23// Specific groups differ in how the first and the next services are selected
25{
26public:
28
29 typedef std::vector<String> Store;
30 typedef String Id;
31 typedef unsigned int Pos; // vector<>::position_type
32 friend class ServicePlan;
33
34public:
35 ServiceGroup(const String &aKind, bool areAllServicesSame);
36 virtual ~ServiceGroup();
37
38 virtual void parse();
39 virtual void finalize(); // called after all are parsed
40
41 bool wants(const ServiceFilter &filter) const;
42
43protected:
45 bool has(const Pos pos) const {
46 // does not check that the service at pos still exists
47 return pos < services.size(); // unsigned pos is never negative
48 }
49
51
53 bool findReplacement(const ServiceFilter &filter, Pos &pos) const;
55 bool findLink(const ServiceFilter &filter, Pos &pos) const;
56
57private:
58 ServicePointer at(const Pos pos) const;
59 bool findService(const ServiceFilter &filter, Pos &pos) const;
60
61 void checkUniqueness(const Pos checkedPos) const;
62 void finalizeMsg(const char *msg, const String &culprit, bool error) const;
63
64public:
69
72
73 const bool allServicesSame; // whether we can freely substitute services
74};
75
76// a group of equivalent services; one service per set is usually used
78{
79public:
80 ServiceSet();
81
82protected:
83 virtual bool replace(Pos &pos) const { return has(++pos); }
84 virtual bool advance(Pos &) const { return false; }
85};
86
87// corner case: a group consisting of one service
89{
90public:
91 SingleService(const String &aServiceKey);
92
93protected:
94 virtual bool replace(Pos &) const { return false; }
95 virtual bool advance(Pos &) const { return false; }
96};
97
100{
101public:
102 ServiceChain();
103
104protected:
105 virtual bool replace(Pos &) const { return false; }
106 virtual bool advance(Pos &pos) const { return has(++pos); }
107};
108
111{
112public:
114
116 static void Split(const ServiceFilter &filter, const String &ids,
117 DynamicGroupCfg &current, DynamicGroupCfg &future);
118};
119
123{
124public:
125 typedef unsigned int Pos; // vector<>::position_type
126
127public:
128 ServicePlan();
129 explicit ServicePlan(const ServiceGroupPointer &g, const ServiceFilter &filter);
130
132 bool exhausted() const { return atEof; }
133
135 ServicePointer current() const;
137 ServicePointer next(const ServiceFilter &filter);
138
139 std::ostream &print(std::ostream &os) const;
140
141private:
144 bool atEof;
145};
146
147inline
148std::ostream &operator <<(std::ostream &os, const ServicePlan &p)
149{
150 return p.print(os);
151}
152
153typedef std::vector<ServiceGroupPointer> Groups;
156
157} // namespace Adaptation
158
159#endif /* SQUID_ADAPTATION__SERVICE_GROUPS_H */
160
#define RefCountable
The locking interface for use on Reference-Counted classes.
Definition: Lock.h:66
void error(char *format,...)
DynamicServiceGroup configuration to remember future dynamic chains.
a temporary service chain built upon another service request
static void Split(const ServiceFilter &filter, const String &ids, DynamicGroupCfg &current, DynamicGroupCfg &future)
separates dynamic services matching current location from future ones
DynamicServiceChain(const DynamicGroupCfg &cfg, const ServiceFilter &f)
a group of services that must be used one after another
virtual bool advance(Pos &pos) const
virtual bool replace(Pos &) const
information used to search for adaptation services
Definition: ServiceFilter.h:23
RefCount< ServiceGroup > Pointer
Definition: ServiceGroups.h:27
std::vector< String > Store
Definition: ServiceGroups.h:29
const bool allServicesSame
based on the first added service
Definition: ServiceGroups.h:73
bool wants(const ServiceFilter &filter) const
bool findLink(const ServiceFilter &filter, Pos &pos) const
find next to link after success, starting with pos
ServiceGroup(const String &aKind, bool areAllServicesSame)
void checkUniqueness(const Pos checkedPos) const
checks that the service name or URI is not repeated later in the group
ServicePointer at(const Pos pos) const
Store removedServices
the disabled services in the case ecap or icap is disabled
Definition: ServiceGroups.h:68
VectPoint point
based on the first added service
Definition: ServiceGroups.h:71
void finalizeMsg(const char *msg, const String &culprit, bool error) const
emits a formatted warning or error message at the appropriate dbg level
bool findReplacement(const ServiceFilter &filter, Pos &pos) const
these methods control group iteration; used by ServicePlan
bool findService(const ServiceFilter &filter, Pos &pos) const
bool has(const Pos pos) const
< whether this group has a service at the specified pos
Definition: ServiceGroups.h:45
ServicePointer replacement(const ServiceFilter &filter)
next to try after failure
bool atEof
cached information for better performance
Pos pos
current service position within the group
std::ostream & print(std::ostream &os) const
ServicePointer next(const ServiceFilter &filter)
next in chain after success
ServiceGroupPointer group
the group we are iterating
ServicePointer current() const
returns nil if the plan is complete
virtual bool replace(Pos &pos) const
Definition: ServiceGroups.h:83
virtual bool advance(Pos &) const
Definition: ServiceGroups.h:84
virtual bool replace(Pos &) const
Definition: ServiceGroups.h:94
virtual bool advance(Pos &) const
Definition: ServiceGroups.h:95
SingleService(const String &aServiceKey)
std::vector< ServiceGroupPointer > Groups
std::ostream & operator<<(std::ostream &os, const Answer &answer)
Definition: Answer.h:49
Groups & AllGroups()
ServiceGroupPointer FindGroup(const ServiceGroup::Id &id)

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors