]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/RequestId.h
Maintenance: automate header guards 2/3 (#1655)
[thirdparty/squid.git] / src / ipc / RequestId.h
1 /*
2 * Copyright (C) 1996-2023 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_SRC_IPC_REQUESTID_H
10 #define SQUID_SRC_IPC_REQUESTID_H
11
12 #include "ipc/forward.h"
13 #include "ipc/QuestionerId.h"
14
15 #include <iosfwd>
16
17 namespace Ipc
18 {
19
20 /// uniquely identifies an IPC request among same-type concurrent IPC requests
21 /// submitted by a single Squid instance
22 class RequestId
23 {
24 public:
25 /// A simple ID for correlating IPC responses with pending requests.
26 /// Value 0 has a special meaning of "unset/unknown", but otherwise opaque.
27 typedef unsigned int Index;
28
29 /// Request sender's constructor.
30 /// For performance and clarity sake, default constructor is preferred to 0 index.
31 explicit RequestId(Index);
32
33 /// request recipient's constructor
34 RequestId() = default;
35
36 /// Make the ID unset/unknown.
37 /// Optimization: leaves the questioner field alone.
38 void reset() { index_ = 0; }
39
40 /// Make the ID set/known with the given (by the questioner) index.
41 /// For performance and clarity sake, reset(void) is preferred to reset(0).
42 void reset(const Index anIndex) { *this = RequestId(anIndex); }
43
44 QuestionerId questioner() const { return qid_; }
45 Index index() const { return index_; }
46
47 // these conversion operators allow our users to treat us as an Index
48 operator Index() const { return index_; }
49 RequestId &operator =(const Index anIndex) { anIndex ? reset(anIndex) : reset(); return *this; }
50
51 private:
52 /// the sender of the request
53 QuestionerId qid_;
54
55 /// request ID; unique within pending same-qid_ questions of the same kind
56 Index index_ = 0;
57 };
58
59 std::ostream &operator <<(std::ostream &, const RequestId &);
60
61 } // namespace Ipc;
62
63 #endif /* SQUID_SRC_IPC_REQUESTID_H */
64