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
2.9 KiB

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