1 #include "CallbackStream.h"
5 #include "SerialConsole.h"
6 //#define DEBUG_PRINTF THEKERNEL->serial->printf
7 #define DEBUG_PRINTF(...)
9 CallbackStream::CallbackStream(cb_t cb
, void *u
)
11 DEBUG_PRINTF("Callbackstream ctor: %p\n", this);
18 CallbackStream::~CallbackStream()
20 DEBUG_PRINTF("Callbackstream dtor: %p\n", this);
23 int CallbackStream::puts(const char *s
)
27 if(s
== NULL
) return (*callback
)(NULL
, user
);
32 // call this streams result callback
33 n
= (*callback
)(s
, user
);
35 // if closed just pretend we sent it
41 // if output queue is full
42 // call idle until we can output more
43 THEKERNEL
->call_event(ON_IDLE
);
50 void CallbackStream::mark_closed()
53 if(use_count
<= 0) delete this;
55 void CallbackStream::dec()
58 if(closed
&& use_count
<= 0) delete this;
61 extern "C" void *new_callback_stream(cb_t cb
, void *u
)
63 return new CallbackStream(cb
, u
);
66 extern "C" void delete_callback_stream(void *p
)
68 // we don't delete it in case it is still on the command queue
69 ((CallbackStream
*)p
)->mark_closed();