X-Git-Url: http://sraa.de/git/?a=blobdiff_plain;f=dol%2Fsrc%2Fdol%2Fvisitor%2Fhdsd%2Fscd%2Fscd_command_reader.h;fp=dol%2Fsrc%2Fdol%2Fvisitor%2Fhdsd%2Fscd%2Fscd_command_reader.h;h=db06830a05dd7088633abe05f1d7656a4df6088c;hb=8c411cf24ed0eb889191aaeafd8fa1e69081df42;hp=0000000000000000000000000000000000000000;hpb=dea7a4fb1ed110d3ce6e6d9255103d724bd66c0e;p=jump.git diff --git a/dol/src/dol/visitor/hdsd/scd/scd_command_reader.h b/dol/src/dol/visitor/hdsd/scd/scd_command_reader.h new file mode 100644 index 0000000..db06830 --- /dev/null +++ b/dol/src/dol/visitor/hdsd/scd/scd_command_reader.h @@ -0,0 +1,64 @@ +#ifndef SCD_COMMAND_READER_H +#define SCD_COMMAND_READER_H + +#include "scd_command.h" +#include "scd_socket.h" + +/** + * Reads commands from a socket. The receiption does not have to complete + * withing one call. As long as it is ongoing the socket shall not be read + * by the application. + */ +class scd_command_reader +{ +public: + scd_command_reader(); + + virtual ~scd_command_reader(); + + /** + * Sets the socket to read from. Do not try to read before setting the + * socket. + */ + void set_socket(scd_socket &sock); + + /** + * Initiates reading a command if it is not reading yet or continues + * to read a previously unfinished command. + */ + void read(); + + /** + * Indicates if a command is being read. This is the case between calling + * read() and the completion of the command (or failure if an illegal + * command was received). + * \return true if a command is currently being received + */ + bool is_reading(); + + /** + * Indicates if a command has been received successfully and is ready + * to be picked up. + * \return true if a command can be collected + */ + bool has_command(); + + /** + * Returns a successfully received command. The application has to free + * it by itself. The reader does not keep a reference. + * \return the command or NULL if has_command() is false + */ + scd_command* get_command(); + +private: + scd_socket* _socket; + scd_command* _command; + bool _is_reading; + bool _header_read; + bool _success; + size_t _remaining; + size_t _off; + char _header_buf[SCD_CM_HEADER]; +}; + +#endif