3 #include "MsgPipeSource.h"
4 #include "MsgPipeSink.h"
5 #include "MsgPipeData.h"
7 CBDATA_CLASS_INIT(MsgPipe
);
9 // static event callback template
10 // XXX: refcounting needed to make sure destination still exists
11 #define MsgPipe_MAKE_CALLBACK(callName, destination) \
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); \
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
)
28 MsgPipe::MsgPipe(const char *aName
): name(aName
),
29 data(NULL
), source(NULL
), sink(NULL
)
35 assert(source
== NULL
);
39 void MsgPipe::sendSourceStart()
41 debug(99,5)("MsgPipe::sendSourceStart() called\n");
42 sendLater("SourceStart", &MsgPipe_sendSourceStart
, sink
);
47 void MsgPipe::sendSourceProgress()
49 debug(99,5)("MsgPipe::sendSourceProgress() called\n");
50 sendLater("SourceProgress", &MsgPipe_sendSourceProgress
, sink
);
53 void MsgPipe::sendSourceFinish()
55 debug(99,5)("MsgPipe::sendSourceFinish() called\n");
56 sendLater("sendSourceFinish", &MsgPipe_sendSourceFinish
, sink
);
60 void MsgPipe::sendSourceAbort()
62 debug(99,5)("MsgPipe::sendSourceAbort() called\n");
63 sendLater("SourceAbort", &MsgPipe_sendSourceAbort
, sink
);
68 void MsgPipe::sendSinkNeed()
70 debug(99,5)("MsgPipe::sendSinkNeed() called\n");
71 sendLater("SinkNeed", &MsgPipe_sendSinkNeed
, source
);
74 void MsgPipe::sendSinkAbort()
76 debug(99,5)("MsgPipe::sendSinkAbort() called\n");
77 sendLater("SinkAbort", &MsgPipe_sendSinkAbort
, source
);
81 void MsgPipe::sendLater(const char *callName
, EVH
* handler
, MsgPipeEnd
*destination
)
83 if (canSend(destination
, callName
, true))
84 eventAdd(callName
, handler
, this, 0.0, 0, true);
87 bool MsgPipe::canSend(MsgPipeEnd
*destination
, const char *callName
, bool future
)
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
);