Добавил:
korayakov
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабы / 2 / lab.05.by mice / spice / src / csp_life
.h/*******************************************************************************
* file: csp_life.h *
* version: 0.0.1 *
* author: d-evil [tmd] (mailto:d-evil.tmd@mail.ru) *
* description: not available *
*******************************************************************************/
#ifndef CSP_LIFE_INCLUDED
#define CSP_LIFE_INCLUDED
////////////////////////////////////////////////////////////////////////////////
// headers
#include <afx.h>
#include <afxwin.h>
#include <afxdlgs.h>
#include <shlwapi.h>
#include <winsock2.h>
#include <mstcpip.h>
#include "csp_parser.h"
#include "csp_file.h"
#include "csp_list.h"
#include "csp_filter.h"
#include "cdm_addr_info.h"
#include "win_errors.h"
#include "resource.h"
////////////////////////////////////////////////////////////////////////////////
// csp_life declaration
class csp_life: public CDialog {
public:
csp_life();
~csp_life();
HICON get_icon() const { return _icon; }
void set_icon(const HICON icon) { _icon = icon; }
virtual BOOL OnInitDialog();
virtual void OnOK() {}
virtual void OnCancel() {}
virtual void OnClose();
int open_file();
int close_file();
int run();
int stop();
protected:
////////////////////////////////////////////////////////////////////////////
// protected constants
static const int _WM_CAN_QUIT = WM_USER + 0xCC;
static const int _WM_DO_CLOSE = WM_USER + 0xDC;
static const int _WM_DO_OPEN = WM_USER + 0xD0;
static const int _WM_DO_CSP_FLUSH = WM_USER + 0xCF;
static const int _STATE_UNKNOWN = 0xDEAD;
static const int _STATE_BTNS_OPEN_DISABLED = -1;
static const int _STATE_BTNS_OPEN_CANOPEN = 0;
static const int _STATE_BTNS_OPEN_CANCLOSE = 1;
static const int _STATE_BTNS_RUN_DISABLED = -1;
static const int _STATE_BTNS_RUN_CANRUN = 0;
static const int _STATE_BTNS_RUN_CANSTOPR = 1; // running
static const int _STATE_BTNS_RUN_CANSTOPP = 2; // paused
static const int _STATE_BTNS_OPTS_DISABLED = -1;
static const int _STATE_BTNS_OPTS_ENABLED = 0;
static const int _BTNS_STATE_UNKNOWN = 0xDEAD;
static const int _BTNS_RUN_DISABLED = -1;
static const int _BTNS_RUN_CAN_RUN = 0;
static const int _BTNS_RUN_CAN_STOP = 1;
static const int _BTNS_LOG_DISABLED = -1;
static const int _BTNS_LOG_CAN_BROWSE = 0;
static const int _BTNS_LOG_CAN_OPEN = 1;
static const char *_DEF_CSS_FILE_NAME;
static const char *_DEF_FILTER_FILE_NAME;
static const char *_html_intro;
static const char *_html_outtro;
static const int _DTGM_MAX_LENGTH = 0xFFFF;
////////////////////////////////////////////////////////////////////////////
// protected controls
CButton *_btn_open;
CButton *_btn_browse;
CButton *_btn_run;
CButton *_btn_pause;
CButton *_btn_clr_file;
CButton *_btn_cr_new_html;
CButton *_btn_write_html;
CButton *_btn_view_html;
CButton *_btn_rw_html;
CButton *_btn_filter;
CButton *_btn_show_list;
CButton *_btn_exit;
CEdit *_edit_file;
CEdit *_edit_host;
CEdit *_edit_html_file;
CEdit *_edit_info;
CStatic *_stt_html;
CStatic *_stt_host;
CStatic *_stt_file;
CStatic *_stt_info;
////////////////////////////////////////////////////////////////////////////
// protected event handlers
DECLARE_MESSAGE_MAP();
void _on_btn_browse();
void _on_btn_open();
void _on_btn_run();
void _on_btn_pause();
void _on_btn_show_html();
void _on_btn_write_html();
void _on_btn_rw_html();
void _on_btn_filter();
void _on_btn_show_list();
void _on_btn_help();
void _on_btn_about();
void _on_btn_exit();
LRESULT _on_can_quit(WPARAM pch, LPARAM hz);
LRESULT _on_do_open(WPARAM pch, LPARAM hz);
LRESULT _on_do_close(WPARAM pch, LPARAM hz);
LRESULT _on_close_list(WPARAM pch, LPARAM hz);
LRESULT _on_close_filter(WPARAM pch, LPARAM hz);
LRESULT _on_do_csp_flush(WPARAM pch, LPARAM hz);
void _set_state_btns_open(const int state);
void _set_state_btns_run(const int state);
void _set_state_btns_opts(const int state);
void _set_state_btn_write_html(const bool is_active);
void _show_file_info(const bool running = true, const bool clear = false);
int _run_proc();
static int _run_proc_helper(csp_life *const life);
// net part
int _open_file();
int _close_file();
int _copy_css(CString &html_fn);
int _make_socket();
int _kill_socket();
int _can_read(const SOCKET sock, const int timeout_ms = 500);
int _can_read_sz(const SOCKET sock);
int _buf_ctl(const bool alloc = true);
int _read_datagram(const SOCKET sock);
int _swallow(const SOCKET sock);
private:
// states and work
HANDLE _thread_h;
DWORD _thread_id;
volatile bool _must_stop;
volatile bool _running;
volatile bool _paused;
volatile bool _opened;
volatile bool _can_quit;
volatile bool _need_csp_flush;
volatile bool _waiting_csp_flush;
volatile bool _html_file_corrupted;
volatile bool _list_closing;
// net part
SOCKET _sock;
HANDLE _file;
csp_file _csp_file;
HANDLE _html_file;
CString _css_file_name;
CString _app_path;
char *_buf;
static const int _NET_BUF_SZ = 0xFFFFF;
char *_dtgm; // for compatibility with csp_parser
int _dtgm_sz;
sockaddr _saddr_gived;
int _saddr_sz_gived;
csp_parser _parser;
bool _write_html;
unsigned int _total_dtgms;
// gui part
HICON _icon;
csp_list *volatile _csp_list;
csp_list *volatile _tmp_list;
csp_filter _csp_filter;
int _state_btns_open;
int _state_btns_run;
int _state_btns_opts;
};
#endif
Соседние файлы в папке src