Добавил:
korayakov
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабы / 2 / lab.01.by mice / fexchange / fx_iface
.h/*******************************************************************************
* file: fx_iface.h *
* version: 0.2.0 *
* author: d-evil [tmd] (mailto:d-evil.tmd@mail.ru) *
* description: interface (abstract) class for cfx_core *
* interfaces can use only information based on this file and *
* must not make any assumptions about any part of realization *
* *
* most of integer constants are unique *
* cfx_if class uses integer constants in range [1000, 9999] *
* the next principle used to group the integers: *
* [1000,1499] - commands for ui *
* [1500,1999] - commands for core *
* [2000,2099] - states of server *
* [2100,2199] - states of client *
* [3000,3499] - errors returned from core to ui *
* [3500,3999] - errors returned from ui to core *
* *
*******************************************************************************/
#ifndef FX_IFACE_INCLUDED
#define FX_IFACE_INCLUDED
////////////////////////////////////////////////////////////////////////////////
// program specific headers
#include "fx_const.h"
#include "fx_core.h"
namespace fx_ns {
/*******************************************************************************
* declarations *
*******************************************************************************/
////////////////////////////////////////////////////////////////////////////////
// cfx_if (declaration)
class cfx_core;
class cfx_if {
public:
////////////////////////////////////////////////////////////////////////////
// types
union sfx_data {
short sh_val;
unsigned short ush_val;
int int_val;
unsigned int uint_val;
void *pvoid;
sfx_data(): pvoid(NULL) {}
sfx_data(short sv) { sh_val = sv; }
sfx_data(unsigned short usv) { ush_val = usv; }
sfx_data(int iv) { int_val; }
sfx_data(unsigned int uiv) { uint_val = uiv; }
sfx_data(void *pv) { pvoid = pv; }
};
struct sfx_addr_info {
char *host;
char *addres;
unsigned short port;
short family;
};
struct sfx_serv_item {
sfx_addr_info addr;
int state;
sfx_data if_data; // interface can freely use (modify) this field
sfx_serv_item *prev;
sfx_serv_item *next;
};
struct sfx_clnt_item {
sfx_addr_info addr;
int state;
char *file_name;
unsigned __int64 total_sz;
unsigned __int64 done_sz;
sfx_data if_data; // interface can freely use (modify) this field
sfx_clnt_item *prev;
sfx_clnt_item *next;
};
int fuck;
////////////////////////////////////////////////////////////////////////////
// ui commands
// interfaces must return ERC_NO_CMDSUPPORT if command not supported
// ldata and rdata and returned value are sfx_data
// i - int
// ui - unsigned int
// p - void *
// s - short
// us - unsigend short
// command: CMD_NONE
// about: tests UI for connection
// ldata[p]: not used (must be NULL)
// rdata[p]: not used (must be NULL)
// return[i]: must return OK_OK, otherwise UI will be detached
static const int CMD_NONE = 1000;
// command: CMD_INVALID_CMD
// about: used for debuging
// ldata[p]: not used (must be NULL)
// rdata[p]: not used (must be NULL)
// return[i]: must return ERC_NO_CMDSUPPORT
static const int CMD_INVALID_CMD = 1001;
// command: CMD_ERROR_REPORT
// about: error message from core
// ldata[i]: fx error id (ERC_ERROR if unknown error)
// rdata[i]: windows error code (0 if not available)
// return[i]: error code (OK_OK on success)
static const int CMD_ERROR_REPORT = 1010;
// command: CMD_ASK_ACCEPTIC
// about: ask to accept incoming connection
// ldata[i]: pointer to sfx_addr_info structure
// rdata[p]: not used (must be NULL)
// result[i]: OK_OK on "ok", OK_CANCEL on "cancel" or error code
static const int CMD_ASK_ACCEPTIC = 1020;
/*
// Command: CMD_ASK_FILENAME
// ldata: pointer to cfx_askfile_struct
// rdata: pointer to int to recieve file name length
// result: OK_OK if "yes"
// OK_CANCEL if "no"
// OK_REPEAT if "yes" and buffer is too short
static const int CMD_ASKFILENAME = 5;
static const int CMD_ASKFN_OPEN = 0x0000000F;
static const int CMD_ASKFN_MSTEX = 0x000000F0; // file must exists
static const int CMD_ASKFN_CLEAR = 0x00000F00; // file will be cleaned
struct cfx_askfile_struct {
char *buf; // buffer for file name
int buf_sz; // buffer size
int flags; // flags
};
*/
// command: CMD_US_NEW
// about: update servers list (add new server)
// ldata[p]: pointer sfx_serv_item structure
// rdata[p]: not used (must be NULL)
// return[i]: error code (OK_OK on success)
static const int CMD_US_NEW = 1040;
// command: CMD_US_MODIFY
// about: update servers list (modify server data)
// ldata[p]: pointer sfx_serv_item structure
// rdata[i]: bit mask (fields to modify)
// return[i]: error code (OK_OK on success)
static const int CMD_US_MODIFY = 1050;
static const int CMD_USMF_ADDR = 1;
static const int CMD_USMF_STATE = 2;
// command: CMD_US_KILL
// about: update servers list (delete server)
// ldata[p]: pointer sfx_serv_item structure
// rdata[p]: not used (must be NULL)
// return[i]: error code (OK_OK on success)
static const int CMD_US_KILL = 1060;
// command: CMD_UC_NEW
// about: update clients list (add new client)
// ldata[p]: pointer sfx_clnt_item structure
// rdata[p]: not used (must be NULL)
// return[i]: error code (OK_OK on success)
static const int CMD_UC_NEW = 1070;
// command: CMD_UC_MODIFY
// about: update clients list (modify client data)
// ldata[p]: pointer sfx_clnt_item structure
// rdata[p]: bit mask (fields to modify)
// return[i]: error code (OK_OK on success)
static const int CMD_UC_MODIFY = 1080;
static const int CMD_UCMF_ADDR = 0x01;
static const int CMD_UCMF_STATE = 0x02;
static const int CMD_UCMF_TOTSZ = 0x04;
static const int CMD_UCMF_DONSZ = 0x08;
// command: CMD_UC_KILL
// about: update clients list (delete client)
// ldata[p]: pointer sfx_clnt_item structure
// rdata[p]: not used (must be NULL)
// return[i]: error code (OK_OK on success)
static const int CMD_UC_KILL = 1090;
////////////////////////////////////////////////////////////////////////////
// states
static const int ST_SERV_NONE = 2000;
static const int ST_SERV_LISTENING = 2010;
static const int ST_SERV_ACCEPTING = 2020;
static const int ST_SERV_STOPING = 2030;
static const int ST_SERV_STOPED = 2040;
static const int ST_CLNT_NONE = 2100;
static const int ST_CLNT_CONNECTING = 2110;
static const int ST_CLNT_CANCELED = 2120;
static const int ST_CLNT_RECVINFO = 2130;
////////////////////////////////////////////////////////////////////////////
// virtual functions
virtual int attach(class cfx_core *core) = 0;
virtual int run() = 0;
virtual int detach() = 0;
virtual sfx_data exec_cmd(const int cmd, const sfx_data ldata, const sfx_data rdata) = 0;
////////////////////////////////////////////////////////////////////////////
// functions
cfx_if(): _core(NULL) {}
sfx_data cmd_to_core(const int cmd, const sfx_data ldata, const sfx_data rdata);/* {
if (NULL != _core)
return 0; //_core->execute_cmd(cmd, ldata, rdata);
else
return ERC_CORE_BADCMD;
}*/
private:
////////////////////////////////////////////////////////////////////////////
// private variables
cfx_core *_core;
////////////////////////////////////////////////////////////////////////////
// private functions
cfx_core *_get_core() { return _core; }
void _set_core(cfx_core *const core) { _core = core; }
};
} // end of namespace "fx_ns"
#endif
Соседние файлы в папке fexchange