Team Fortress 2 Source Code as on 22/4/2020
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.

70 lines
3.1 KiB

  1. //=========== Copyright Valve Corporation, All rights reserved. ===============//
  2. //
  3. // Purpose: Helper classes/functions for performing web api requests from ui code
  4. //
  5. //=============================================================================//
  6. #ifndef UIWEBAPICLIENT_H
  7. #define UIWEBAPICLIENT_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "uievent.h"
  12. namespace panorama
  13. {
  14. //-----------------------------------------------------------------------------
  15. // Purpose: Helper for performing async webapi requests
  16. //-----------------------------------------------------------------------------
  17. inline uint64 MakeAsyncJSONWebAPIRequest( EHTTPMethod eMethod, const char *pchWebAPIURL, CJSONWebAPIParams *pParams, HTTPCookieContainerHandle hCookieContianer, IUIPanel *pCallbackTargetPanel, void *pContext )
  18. {
  19. return UIEngine()->InitiateAsyncJSONWebAPIRequest( eMethod, pchWebAPIURL, pCallbackTargetPanel, pContext, pParams, hCookieContianer );
  20. }
  21. //-----------------------------------------------------------------------------
  22. // Purpose: Helper for performing async webapi requests
  23. //-----------------------------------------------------------------------------
  24. inline uint64 MakeAsyncJSONWebAPIRequest( EHTTPMethod eMethod, const char *pchWebAPIURL, CJSONWebAPIParams *pParams, HTTPCookieContainerHandle hCookieContianer, JSONWebAPIDelegate_t callback, void *pContext )
  25. {
  26. return UIEngine()->InitiateAsyncJSONWebAPIRequest( eMethod, pchWebAPIURL, callback, pContext, pParams, hCookieContianer );
  27. }
  28. //-----------------------------------------------------------------------------
  29. // Purpose: Helper for performing async webapi requests
  30. //-----------------------------------------------------------------------------
  31. inline uint32 MakeAsyncJSONWebAPIRequest( const char *pchWebAPIURL, IUIPanel *pCallbackTargetPanel, void *pContext )
  32. {
  33. return UIEngine()->InitiateAsyncJSONWebAPIRequest( k_EHTTPMethodGET, pchWebAPIURL, pCallbackTargetPanel, pContext );
  34. }
  35. //-----------------------------------------------------------------------------
  36. // Purpose: Helper for performing async webapi requests. When using this version, objects pointed to
  37. // by the provided delegate must live for the duration of the web request. Before destroying those objects,
  38. // you must get a completion callback or CancelAsyncJSONWebAPIRequest.
  39. //
  40. // Use panel & event versions above if you do not want to manage object & request lifetimes.
  41. //-----------------------------------------------------------------------------
  42. inline uint32 MakeAsyncJSONWebAPIRequest( const char *pchWebAPIURL, JSONWebAPIDelegate_t callback, void *pContext )
  43. {
  44. return UIEngine()->InitiateAsyncJSONWebAPIRequest( k_EHTTPMethodGET, pchWebAPIURL, callback, pContext );
  45. }
  46. //-----------------------------------------------------------------------------
  47. // Purpose: Cancels a job request made by MakeAsyncJSONWebAPIRequest
  48. //-----------------------------------------------------------------------------
  49. inline void CancelAsyncJSONWebAPIRequest( uint32 requestID )
  50. {
  51. UIEngine()->CancelAsyncJSONWebAPIRequest( requestID );
  52. }
  53. } // namespace panorama
  54. #endif // UIWEBAPICLIENT_H