]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ICAP/MsgPipe.cc
- Replaced BodyReader with BodyPipe. BodyReader was a
[thirdparty/squid.git] / src / ICAP / MsgPipe.cc
1 #include "squid.h"
2 #include "MsgPipe.h"
3 #include "MsgPipeSource.h"
4 #include "MsgPipeSink.h"
5 #include "MsgPipeData.h"
6
7 CBDATA_CLASS_INIT(MsgPipe);
8
9 // static event callback template
10 // XXX: refcounting needed to make sure destination still exists
11 #define MsgPipe_MAKE_CALLBACK(callName, destination) \
12 static \
13 void MsgPipe_send ## callName(void *p) { \
14 MsgPipe *pipe = static_cast<MsgPipe*>(p); \
15 if (pipe && pipe->canSend(pipe->destination, #callName, false)) \
16 pipe->destination->note##callName(pipe); \
17 }
18
19 // static event callbacks
20 MsgPipe_MAKE_CALLBACK(SourceStart, sink)
21 MsgPipe_MAKE_CALLBACK(SourceProgress, sink)
22 MsgPipe_MAKE_CALLBACK(SourceFinish, sink)
23 MsgPipe_MAKE_CALLBACK(SourceAbort, sink)
24 MsgPipe_MAKE_CALLBACK(SinkNeed, source)
25 MsgPipe_MAKE_CALLBACK(SinkAbort, source)
26
27
28 MsgPipe::MsgPipe(const char *aName): name(aName),
29 data(NULL), source(NULL), sink(NULL)
30 {}
31
32 MsgPipe::~MsgPipe()
33 {
34 delete data;
35 assert(source == NULL);
36 assert(sink == NULL);
37 };
38
39 void MsgPipe::sendSourceStart()
40 {
41 debug(99,5)("MsgPipe::sendSourceStart() called\n");
42 sendLater("SourceStart", &MsgPipe_sendSourceStart, sink);
43 }
44
45
46
47 void MsgPipe::sendSourceProgress()
48 {
49 debug(99,5)("MsgPipe::sendSourceProgress() called\n");
50 sendLater("SourceProgress", &MsgPipe_sendSourceProgress, sink);
51 }
52
53 void MsgPipe::sendSourceFinish()
54 {
55 debug(99,5)("MsgPipe::sendSourceFinish() called\n");
56 sendLater("sendSourceFinish", &MsgPipe_sendSourceFinish, sink);
57 source = NULL;
58 }
59
60 void MsgPipe::sendSourceAbort()
61 {
62 debug(99,5)("MsgPipe::sendSourceAbort() called\n");
63 sendLater("SourceAbort", &MsgPipe_sendSourceAbort, sink);
64 source = NULL;
65 }
66
67
68 void MsgPipe::sendSinkNeed()
69 {
70 debug(99,5)("MsgPipe::sendSinkNeed() called\n");
71 sendLater("SinkNeed", &MsgPipe_sendSinkNeed, source);
72 }
73
74 void MsgPipe::sendSinkAbort()
75 {
76 debug(99,5)("MsgPipe::sendSinkAbort() called\n");
77 sendLater("SinkAbort", &MsgPipe_sendSinkAbort, source);
78 sink = NULL;
79 }
80
81 void MsgPipe::sendLater(const char *callName, EVH * handler, MsgPipeEnd *destination)
82 {
83 if (canSend(destination, callName, true))
84 eventAdd(callName, handler, this, 0.0, 0, true);
85 }
86
87 bool MsgPipe::canSend(MsgPipeEnd *destination, const char *callName, bool future)
88 {
89 const bool res = destination != NULL;
90 const char *verb = future ?
91 (res ? "will send " : "wont send ") :
92 (res ? "sends " : "ignores ");
93 debugs(93,5, "MsgPipe " << name << "(" << this << ") " <<
94 verb << callName << " to the " <<
95 (destination ? destination->kind() : "destination") << "(" <<
96 destination << "); " <<
97 "data: " << data << "; source: " << source << "; sink " << sink);
98 return res;
99 }