VirtualBox

source: vbox/trunk/include/iprt/cpp/restbase.h@ 73789

Last change on this file since 73789 was 73789, checked in by vboxsync, 7 years ago

iprt/swagger-codegen: taking an approach to input and output similar to the OCI SDK helps solve the issue of returning different types. Here are some incomplete sketches in that direction. bugref:9167

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
Line 
1/** @file
2 * IPRT - C++ Representational State Transfer (REST) Base Classes.
3 */
4
5/*
6 * Copyright (C) 2008-2018 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___iprt_cpp_restbase_h
27#define ___iprt_cpp_restbase_h
28
29#include <iprt/types.h>
30#include <iprt/err.h>
31#include <iprt/http.h>
32#include <iprt/cpp/utils.h>
33
34
35/** @defgroup grp_rt_cpp_restbase C++ Representational State Transfer (REST) Base Classes.
36 * @ingroup grp_rt_cpp
37 * @{
38 */
39
40
41/**
42 * Base class for REST data objects.
43 */
44class RTCSRestObjectBase
45{
46public:
47 RTCSRestObjectBase() {}
48 virtual ~RTCSRestObjectBase() {}
49 /** @todo Add some kind of state? */
50};
51
52
53/**
54 * Base class for REST client requests.
55 */
56class RTCRestClientRequestBase
57{
58public:
59 RTCRestClientRequestBase() {}
60 virtual ~RTCRestClientRequestBase() {};
61
62 /**
63 * Prepares the HTTP handle for transmitting this request.
64 *
65 * @returns IPRT status code.
66 * @param a_hHttp The HTTP handle to prepare for transmitting.
67 */
68 virtual int xmitPrepare(RTHTTP a_hHttp);
69
70 /**
71 * Always called after the request has been transmitted.
72 *
73 * @param a_rcStatus Negative numbers are IPRT errors, positive are HTTP status codes.
74 * @param a_hHttp The HTTP handle the request was performed on.
75 */
76 virtual void xmitComplete(int a_rcStatus, RTHTTP a_hHttp);
77};
78
79
80/**
81 * Base class for REST client responses.
82 */
83class RTCRestClientResponseBase
84{
85public:
86 RTCRestClientResponseBase()
87 : m_rcStatus(VERR_WRONG_ORDER)
88 {}
89 RTCRestClientResponseBase(RTCRestClientResponseBase const &a_rThat)
90 : m_rcStatus(a_rThat.m_rcStatus)
91 {}
92 virtual ~RTCRestClientResponseBase();
93
94 /**
95 * Prepares the HTTP handle for receiving the response.
96 *
97 * This may install callbacks and such like.
98 *
99 * @returns IPRT status code.
100 * @param a_hHttp The HTTP handle to prepare for receiving.
101 */
102 virtual int receivePrepare(RTHTTP a_hHttp);
103
104 virtual int consumeHeader(const char *a_pvData, size_t a_cbData); ///< ??
105 virtual int consumeBody(const char *a_pvData, size_t a_cbData); ///< ??
106
107 /**
108 * Called when the HTTP request has been completely received.
109 *
110 * @returns IPRT status code?
111 * @param a_rcStatus Negative numbers are IPRT errors, positive are HTTP status codes.
112 * @param a_hHttp The HTTP handle the request was performed on.
113 */
114 virtual int receiveComplete(int a_rcStatus, RTHTTP a_hHttp);
115
116 /**
117 * Getter for m_rcStatus.
118 * @returns Negative numbers are IPRT errors, positive are HTTP status codes.
119 */
120 int getStatus() { return m_rcStatus; }
121
122private:
123 /** Negative numbers are IPRT errors, positive are HTTP status codes. */
124 int m_rcStatus;
125
126};
127
128
129/**
130 * Base class for REST client responses.
131 */
132class RTCRestClientApiBase : public RTCNonCopyable
133{
134public:
135 RTCRestClientApiBase()
136 : m_hHttp(NIL_RTHTTP)
137 {}
138 virtual ~RTCRestClientApiBase();
139
140 bool isConnected();
141
142protected:
143 /** Handle to the HTTP connection object. */
144 RTHTTP m_hHttp;
145};
146
147
148#endif
149
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette