- #ifndef _RESPONSE_H
- #define _RESPONSE_H
- #include <set>
- #include <map>
- #include <boost/thread/thread.hpp>
- #include <boost/thread/recursive_mutex.hpp>
- #include <loki/singleton.h>
- #include <loki/Factory.h>
- namespace StockMarket
- {
- using namespace std;
- using namespace boost;
- using namespace Loki;
- extern recursive_mutex res_fact_mutex;
- typedef set<string> StringSet;
- typedef map <int, StringSet> IntStringSetMap; // 股票板块列表
- class StockRes
- {
- public:
- StockRes();
- StockRes(uchar* pData, ulong data_len);
- virtual ~StockRes();
- uint read(const uchar* pData, ulong data_len);
- ulong buff_left();
- bool end();
- void reset();
- virtual void operator()() = 0;
- ushort get_packet_len();
- static ushort get_packet_len(const uchar*);
- uint get_seq_id();
- static uint get_seq_id(const uchar*);
- ushort get_cmd_id();
- static ushort get_cmd_id(const uchar*);
- protected:
- void skip_byte(ulong count);
- void skip_data(ulong count);
- char get_char();
- uchar get_uchar();
- short get_short();
- ushort get_ushort();
- int get_int();
- uint get_uint();
- float get_float();
- int parse_data();
- int parse_data2();
- protected:
- const uchar* raw_data; // the raw data passed in
- ulong raw_len; // the raw data len
- const uchar* data; // payload data,
- ulong len; // payload len
- const uchar* current; // pointer to parse
- ulong left; // len left unparsed
- private:
- void umcompress_if();
- bool dataNew;
- };
- class StockHeartBeatRes: public StockRes
- {
- public:
- void operator()();
- };
- class StockListRes: public StockRes
- {
- public:
- StockListRes();
- StockListRes(uchar* pData, ulong data_len);
- void operator()();
- };
- class StockHoldChgRes: public StockRes
- {
- public:
- StockHoldChgRes();
- StockHoldChgRes(uchar* pData, ulong data_len);
- void operator()();
- private:
- };
- typedef Factory< StockRes, int > RespFct_t;
- typedef SingletonHolder<RespFct_t> ResponseFactory;
- struct StockResWrongData : public std::exception
- {
- StockResWrongData(int i = 0);
- virtual const char *what( ) const throw();
- int n_;
- };
- extern void ProcessResponsePacket(const uchar * pData , size_t len, bool test);
- extern StockRes* CreateStockListRes();
- extern StockRes* CreateStockHoldChgRes();
- extern StockRes* CreateStockHeartBeatRes();
- }
- #endif