InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
IDHTTPWrapper.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Arvinder Singh
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // ADOBE CONFIDENTIAL
16 //
17 // Copyright 2015 Adobe Systems Incorporated. All rights reserved.
18 //
19 // NOTICE: All information contained herein is, and remains
20 // the property of Adobe Systems Incorporated and its suppliers,
21 // if any. The intellectual and technical concepts contained
22 // herein are proprietary to Adobe Systems Incorporated and its
23 // suppliers and may be covered by U.S. and Foreign Patents,
24 // patents in process, and are protected by trade secret or copyright law.
25 // Dissemination of this information or reproduction of this material
26 // is strictly forbidden unless prior written permission is obtained
27 // from Adobe Systems Incorporated.
28 //
29 //========================================================================================
30 #ifndef __IDHTTPWrapper__
31 #define __IDHTTPWrapper__
32 
33 #include "HTTPLinkSubsystemTypes.h"
34 
35 #include "LinksID.h"
36 
37 #include "boost/config.hpp"
38 #include "boost/shared_ptr.hpp"
39 #include "boost/function.hpp"
40 
41 /*
42 */
43 
44 namespace IDHTTPWrapper
45 {
46 //public:
47  //enum { kDefaultIID = IID_IDHTTPWRAPPER };
48 
49  class RequestID;
50  class Response;
51 
52  typedef WideString URL;
53  typedef std::string Payload;
54 
55  class RequestIDImpl;
56  class RequestID
57  {
58  public:
59  RequestID(RequestIDImpl *impl);
60 
61  void DeleteRequest();
62 
63  private:
64  boost::shared_ptr<RequestIDImpl> fImpl;
65  };
66 
67  class ResponseImpl;
68  class Response
69  {
70  public:
71  Response(ResponseImpl *impl);
72  /*
73  Checks from response if there is network connectivity error
74  */
75  bool16 IsNetworkConnectivityError() const;
76  /*
77  Checks from response if there is client error
78  */
79  bool16 IsClientError() const;
80  /*
81  Checks from response about request authorization
82  */
83  bool16 IsNotAuthorized() const;
84  /*
85  Checks from response if request is forbidden
86  */
87  bool16 IsForbidden() const;
88 
89  /*
90  Fetches response status code
91  */
92  int32 GetStatus() const;
93 
94  /*
95  Fetches payload from response.
96  */
97  Payload GetPayload() const;
98 
99  /*
100  Fetches HTTP headers.
101  */
102  HTTPLinkSubsystemTypes::Headers GetHeaders() const;
103 
104  private:
105  boost::shared_ptr<ResponseImpl> fImpl;
106  };
107 
108  typedef boost::function<void(RequestID, Response)> CompletionFunction;
109 
110 
111  class HTTP {
112  public:
113  /*
114  API for GET method invocation
115  @param inCompletionFunction [IN] completionFunction to be invoked at the GET request completion
116  @param inURL [IN] inURL of the request
117  @param inTimeoutInMS [IN] time out for the request with default time out set as 2 seconds
118  @return kTrue on success else kFalse
119  */
120  bool16 GET(
121  const CompletionFunction& inCompletionFunction,
122  const URL& inURL,
123  const int inTimeoutInMS = 2000, // 0 means non-blocking
124  const HTTPLinkSubsystemTypes::Headers& inHeaders = HTTPLinkSubsystemTypes::Headers());
125 
126  /*
127  API for POST method invocation
128  @param inCompletionFunction [IN] completionFunction to be invoked at the POST request completion
129  @param inURL [IN] inURL of the request
130  @param payload [IN] payload for the POST request
131  @param inTimeoutInMS [IN] time out for the request with default time out set as 2 seconds
132  @param inHeaders [IN] Headers for the POST request
133  @return kTrue on success else kFalse
134  */
135  bool16 POST(
136  const CompletionFunction& inCompletionFunction,
137  const URL& inURL,
138  const Payload &payload,
139  const int inTimeoutInMS = 2000, // 0 means non-blocking
140  const HTTPLinkSubsystemTypes::Headers& inHeaders = HTTPLinkSubsystemTypes::Headers());
141 
142  /*
143  Helper to execute a function in the main thread
144  @param inFn [IN] Function to be called Asynchronously
145  @param inDelayInMilliseconds [IN] delay after which the function is to be invoked (deafult is immediate invocation)
146  */
147  bool AsyncCallFromMainThread(const boost::function<void()>& inFn, unsigned int inDelayInMilliseconds = 0);
148  };
149 };
150 
151 #endif