www.pudn.com > net_oss.rar > collection.h
#ifndef __COLLECTION_H__ #define __COLLECTION_H__ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /////////////////////////////////// #include #include ////////////////////////////////// using std::string; using std::cout; using std::endl; using std::ifstream; using std::ofstream; using std::list; using std::multimap; using std::pair; #ifndef __DEBUG #define __DEBUG #endif #ifndef __TIMER #define __TIMER #endif #define BACKUP_TAG "BACKUP" #define POSITION_TAG "POSITION" #define SYSTEM_TAG "SYSTEM" #define COMMENT_TAG "#" #define DELIMITER_TAG "=" #define BACKUP "utmpx.bakx" #define SYSTEM "/var/adm/wtmpx" #define POSITION "utmpx.posx" #define DEFAULT_CONF "../etc/config.ini" #define NOT_ASSIGNED "**NOT**" #define END 999 #define MAX_BUF 255 struct info{ char user_name[50]; time_t start_time; time_t duration; char IP[16]; info() { strcpy(IP,"127.0.0.1"); } }; #ifdef __TIMER class timer { time_t _start; time_t _end; string pro_name; public: timer() {} void start(const string pro_name) { this->pro_name = pro_name; _start = time(0); } void end() { _end = time(0); } void show() const { cout << " Timer Calc: " << (_end - _start)/60; cout << " min " << (_end - _start)%60 << " sec [" << pro_name << " ]\n"; } }; #endif class collection { /////////////////////////////////////////// key_t key; pid_t pid; int msgid; struct msg{ long mtype; char inf[sizeof(info)]; }; /////////////////////////////////////////// string backup_file; string position_file; string system_file; multimap login,logoff; list data; struct utmpx last; #ifdef __TIMER timer _timer; #endif void show(struct utmpx*&); void store(const utmpx*, const time_t&); void dump_unfinished(); void dump_lastposition(); void receive(); void setdefault(); string localIP(); public: collection(); ~collection(); void retrieve(); int processing(); void start_cllection(); void loadconfiguration(const char* file = NULL); }; #endif