You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.0 KiB

7 years ago
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __CURLREQUESTSMANAGER_H_INCL__
  2. #define __CURLREQUESTSMANAGER_H_INCL__
  3. #include "curlRequest.h"
  4. #include "../../components/base/basicThread.h"
  5. /**
  6. * TODO: Add class description
  7. *
  8. * @author Gagua
  9. */
  10. class curlRequestsManager {
  11. private:
  12. basicLogCollection *m_pLog;
  13. CURLM *m_pCURLM;
  14. RequestPool m_vRequestPool;
  15. RequestThreadPool m_vRequestThreadPool;
  16. #ifdef __linux__
  17. U8 m_bThreadStatus;
  18. pthread_t m_sThreadHandle;
  19. static void *m_fReaperEntryPoint(void *);
  20. static void *m_fRequestEntryPoint(void *);
  21. #else
  22. DWORD m_dwThreadID;
  23. BYTE m_bThreadStatus;
  24. HANDLE m_hThreadHandle;
  25. static DWORD WINAPI m_fReaperEntryPoint( LPVOID lpParameter);
  26. static DWORD WINAPI m_fRequestEntryPoint( LPVOID lpParameter);
  27. #endif
  28. public:
  29. // Method to fetch singleton instance.
  30. static curlRequestsManager* getInstance();
  31. // Destructor
  32. virtual ~curlRequestsManager();
  33. bool get(curlRequest *RC);
  34. bool get(CSTR URL, CSTR contentType = DEFAULT_CONTENT_TYPE);
  35. protected:
  36. // Constructor - protected so users cannot call it.
  37. curlRequestsManager();
  38. private:
  39. // private static member referencing the single instance of the object
  40. // TODO: Replace curlRequestsManager with the type of object you want to
  41. // return the single instance of
  42. static curlRequestsManager* _instance;
  43. // Copy constructor
  44. // Declared but not defined to prevent auto-generated
  45. // copy constructor. Refer to "Effective C++" by Meyers
  46. curlRequestsManager(const curlRequestsManager& src);
  47. // Assignment operator
  48. // Declared but not defined to prevent auto-generated
  49. // assignment operator. Refer to "Effective C++" by Meyers
  50. curlRequestsManager& operator=(const curlRequestsManager& src);
  51. };
  52. // Constructor implementation
  53. inline curlRequestsManager::curlRequestsManager(){
  54. m_pLog = basicLogCollection::getInstance();
  55. curl_global_init(CURL_GLOBAL_ALL);
  56. m_pCURLM = curl_multi_init();
  57. #ifdef __linux__
  58. int RetVal = pthread_create(&m_sThreadHandle, NULL, m_fReaperEntryPoint, (void *) this);
  59. if (RetVal == -1) {
  60. //LOG_ERROR("Thread Creation Faled.");
  61. return;
  62. };
  63. #else
  64. m_hThreadHandle = CreateThread(
  65. NULL,
  66. 0,
  67. (LPTHREAD_START_ROUTINE)m_fReaperEntryPoint,
  68. (LPVOID)this,
  69. 0,
  70. &m_dwThreadID);
  71. //TODO: Add thread creation check
  72. #endif
  73. };
  74. // Destructor implementation
  75. inline curlRequestsManager::~curlRequestsManager(){
  76. m_bThreadStatus = 3;
  77. m_pLog->Log("curlRequestsManager", this, "~curlRequestsManager");
  78. curl_multi_cleanup( m_pCURLM );
  79. };
  80. // TODO: Uncomment the copy constructor when you need it.
  81. //inline curlRequestsManager::curlRequestsManager(const curlRequestsManager& src)
  82. //{
  83. // // TODO: copy
  84. //}
  85. // TODO: Uncomment the assignment operator when you need it.
  86. //inline curlRequestsManager& curlRequestsManager::operator=(const curlRequestsManager& rhs)
  87. //{
  88. // if (this == &rhs) {
  89. // return *this;
  90. // }
  91. //
  92. // // TODO: assignment
  93. //
  94. // return *this;
  95. //}
  96. #endif // __CURLREQUESTSMANAGER_H_INCL__