1 #include "CallbackStream.h"
5 #include "SerialConsole.h"
6 #define DEBUG_PRINTF THEKERNEL->serial->printf
8 CallbackStream::CallbackStream(cb_t cb
, void *u
)
10 DEBUG_PRINTF("Callbackstream ctor: %p\n", this);
17 CallbackStream::~CallbackStream()
19 DEBUG_PRINTF("Callbackstream dtor: %p\n", this);
22 int CallbackStream::puts(const char *s
)
26 if(s
== NULL
) return (*callback
)(NULL
, user
);
31 // call this streams result callback
32 n
= (*callback
)(s
, user
);
34 // if closed just pretend we sent it
40 // if output queue is full
41 // call idle until we can output more
42 THEKERNEL
->call_event(ON_IDLE
);
49 void CallbackStream::mark_closed()
52 if(use_count
<= 0) delete this;
54 void CallbackStream::dec()
57 if(closed
&& use_count
<= 0) delete this;
60 extern "C" void *new_callback_stream(cb_t cb
, void *u
)
62 return new CallbackStream(cb
, u
);
65 extern "C" void delete_callback_stream(void *p
)
67 // we don't delete it in case it is still on the command queue
68 ((CallbackStream
*)p
)->mark_closed();