1 #include "CallbackStream.h"
4 #define DEBUG_PRINTF std::printf
6 CallbackStream::CallbackStream(cb_t cb
, void *u
)
8 DEBUG_PRINTF("Callbackstream ctor: %p\n", this);
15 CallbackStream::~CallbackStream()
17 DEBUG_PRINTF("Callbackstream dtor: %p\n", this);
20 int CallbackStream::puts(const char *s
)
24 if(s
== NULL
) return (*callback
)(NULL
, user
);
29 // call this streams result callback
30 n
= (*callback
)(s
, user
);
32 // if closed just pretend we sent it
38 // if output queue is full
39 // call idle until we can output more
40 THEKERNEL
->call_event(ON_IDLE
);
47 void CallbackStream::mark_closed()
50 if(use_count
<= 0) delete this;
52 void CallbackStream::dec()
55 if(closed
&& use_count
<= 0) delete this;
58 extern "C" void *new_callback_stream(cb_t cb
, void *u
)
60 return new CallbackStream(cb
, u
);
63 extern "C" void delete_callback_stream(void *p
)
65 // we don't delete it in case it is still on the command queue
66 ((CallbackStream
*)p
)->mark_closed();