代码:
- #ifndef __IPERF_COLLECTION_H__
- #define __IPERF_COLLECTION_H__
- #include <map>
- #include <pthread.h>
- #include "macros.h"
- using namespace std;
- typedef void ( * port_performance_calback_t ) ( void * data ) ;
- template<typename T>
- class Singleton{
- public:
- static T& get_instance(){
- static T instance;
- return instance;
- }
-
- virtual ~Singleton(){
- std::cout<<"destructor called!"<<std::endl;
- }
-
- Singleton(const Singleton&)=delete;
- Singleton& operator =(const Singleton&)=delete;
-
- protected:
- Singleton(){
- std::cout<<"constructor called!"<<std::endl;
- }
- };
- class IperfCollection:public Singleton<IperfCollection> {
- friend class Singleton<IperfCollection>;
- public:
- int Init(port_performance_calback_t cb);
-
- private:
- int createFifo();
- int stringParsing(string str,int port);
- static void *iperfDataCollection(void *data);
- IperfCollection():_callback(NULL){}
- ~IperfCollection(){}
-
- pthread_t _threadId;
- port_performance_calback_t _callback;
-
- map<int,string> _portFifo;
- map<int,int> _portFd;
- };
- #endif
|