#ifndef SICSCONN_H #define SICSCONN_H #include #include typedef enum { disconnected, connected, replying } ConnState; class SicsConnection : public QObject { Q_OBJECT public: SicsConnection(QObject *parent); ~SicsConnection(); void setHost(const char *hostport, const char *server); void setUser(const char *userpass); int command(const char *cmd); /* send a command (and connect before, if necessary) return values: 1 on success -1 on error (no connection) 0 on empty response (should not happen) */ int sendCommand(const char *cmd); // send, but do not wait int getResponse(); // get beginning of response int getLine(QString &line); /* get answer from command the return value is: - the number of characters read (excluding line break, but at least 1) - 0 when the response is at its end - negative on error */ int handleMessages(int tmo); /* handle pending messages */ int handleBuffer(int tmo); void swallow(); char *debug; ConnState state; char *startServer = NULL; enum {connect_done, connect_start, connect_wait, connect_login, connect_waitlogin, connect_error} connect_state; signals: void handle(const char *line, bool *done = NULL); void reconnected(void); void progress(int bytes); public slots: void reconnect(void); void disconnect(void); int handleBuffer(void); private: int sendThis(const char *cmd); int fd; char *hostport; char *userpass; char *server; int tmo; enum {buf_got_line, buf_got_finished, buf_sent_line, buf_got_start, buf_sent_transact} bufstate; int tries_wait_start; QString command2send; QString bufline; QString rdbuffer; int rdpos; int progressPos; long tim; }; #endif