X-Git-Url: http://sraa.de/git/?a=blobdiff_plain;f=dol%2Fsrc%2Fdol%2Fvisitor%2Fhdsd%2Fscd%2Fscd_command_writer.h;fp=dol%2Fsrc%2Fdol%2Fvisitor%2Fhdsd%2Fscd%2Fscd_command_writer.h;h=a8bb427a367eee5e424d3a11261580b0b56cbd06;hb=8c411cf24ed0eb889191aaeafd8fa1e69081df42;hp=0000000000000000000000000000000000000000;hpb=dea7a4fb1ed110d3ce6e6d9255103d724bd66c0e;p=jump.git diff --git a/dol/src/dol/visitor/hdsd/scd/scd_command_writer.h b/dol/src/dol/visitor/hdsd/scd/scd_command_writer.h new file mode 100644 index 0000000..a8bb427 --- /dev/null +++ b/dol/src/dol/visitor/hdsd/scd/scd_command_writer.h @@ -0,0 +1,61 @@ +#ifndef SCD_COMMAND_WRITER_H +#define SCD_COMMAND_WRITER_H + +#include + +#include "scd_command.h" +#include "scd_socket.h" + + +/** + * Queues multiple commands and writes then to a socket continuously. + */ +class scd_command_writer +{ +public: + scd_command_writer(); + + virtual ~scd_command_writer(); + + /** + * Sets the socket to write to. Do not try to write before + * setting the socket. + */ + void set_socket(scd_socket& sock); + + /** + * Indicates if the writer is currently sending a command. + * \return true if the writer is busy sending commands + */ + bool is_writing() const; + + /** + * Queues a command to be sent. Commands will be sent out in FIFO + * manner. Sending is not initiated by this call. + * \param message to send + * \return false if the message is longet than SCD_CM_MAXLEN. In this + * case the message is destroyed. + */ + bool queue_command(scd_command* cmd); + + /** + * Write commands or part of commands to the socket. As many queued + * commands as possible are sent but none has to be finished. + * \exception scd_exception if unexpected errors occured + */ + void write(); + +private: + scd_socket* _socket; + bool _is_writing; + + std::list_commands; + char _buf[SCD_CM_HEADER + SCD_CM_MAXLEN]; + size_t _remaining; + size_t _off; + + inline bool _send_cmd(); + +}; + +#endif