#ifndef __CURLREQUESTSMANAGER_H_INCL__ #define __CURLREQUESTSMANAGER_H_INCL__ #include "curlRequest.h" /** * TODO: Add class description * * @author Gagua */ class curlRequestsManager { private: basicLogCollection *m_pLog; CURLM *m_pCURLM; RequestPool m_vRequestPool; RequestThreadPool m_vRequestThreadPool; #ifdef __linux__ U8 m_bThreadStatus; pthread_t m_sThreadHandle; static void *m_fReaperEntryPoint(void *); static void *m_fRequestEntryPoint(void *); #else DWORD m_dwThreadID; BYTE m_bThreadStatus; HANDLE m_hThreadHandle; static DWORD WINAPI m_fReaperEntryPoint( LPVOID lpParameter); static DWORD WINAPI m_fRequestEntryPoint( LPVOID lpParameter); #endif public: // Method to fetch singleton instance. static curlRequestsManager* getInstance(); // Destructor virtual ~curlRequestsManager(); bool get(curlRequest *RC); bool get(CSTR URL, CSTR contentType = DEFAULT_CONTENT_TYPE); protected: // Constructor - protected so users cannot call it. curlRequestsManager(); private: // private static member referencing the single instance of the object // TODO: Replace curlRequestsManager with the type of object you want to // return the single instance of static curlRequestsManager* _instance; // Copy constructor // Declared but not defined to prevent auto-generated // copy constructor. Refer to "Effective C++" by Meyers curlRequestsManager(const curlRequestsManager& src); // Assignment operator // Declared but not defined to prevent auto-generated // assignment operator. Refer to "Effective C++" by Meyers curlRequestsManager& operator=(const curlRequestsManager& src); }; // Constructor implementation inline curlRequestsManager::curlRequestsManager(){ m_pLog = basicLogCollection::getInstance(); curl_global_init(CURL_GLOBAL_ALL); m_pCURLM = curl_multi_init(); #ifdef __linux__ int RetVal = pthread_create(&m_sThreadHandle, NULL, m_fReaperEntryPoint, (void *) this); if (RetVal == -1) { //LOG_ERROR("Thread Creation Faled."); return; }; #else m_hThreadHandle = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)m_fReaperEntryPoint, (LPVOID)this, 0, &m_dwThreadID); //TODO: Add thread creation check #endif }; // Destructor implementation inline curlRequestsManager::~curlRequestsManager(){ m_bThreadStatus = 3; m_pLog->Log("curlRequestsManager", this, "~curlRequestsManager"); curl_multi_cleanup( m_pCURLM ); }; // TODO: Uncomment the copy constructor when you need it. //inline curlRequestsManager::curlRequestsManager(const curlRequestsManager& src) //{ // // TODO: copy //} // TODO: Uncomment the assignment operator when you need it. //inline curlRequestsManager& curlRequestsManager::operator=(const curlRequestsManager& rhs) //{ // if (this == &rhs) { // return *this; // } // // // TODO: assignment // // return *this; //} #endif // __CURLREQUESTSMANAGER_H_INCL__