Skip to content

Commit 8f5f6fb

Browse files
committed
release 0.0.5-beta source code for cpp
1 parent bb65b40 commit 8f5f6fb

File tree

11 files changed

+132
-7
lines changed

11 files changed

+132
-7
lines changed

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
# 0.0.4-beta # 0.0.4-beta 2023-02-20
1+
# 0.0.5-beta 2023-04-14
2+
3+
### G42Cloud SDK Core
4+
5+
- _Features_
6+
- None
7+
- _Bug Fix_
8+
- None
9+
- _Change_
10+
- Optimize the code structure.
11+
12+
# 0.0.4-beta 2023-02-20
213

314
### G42Cloud SDK IMS
415

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,13 @@ vcpkg install curl cpprestsdk boost openssl spdlog
8383

8484
5. click `CMakeLists.txt` and choose `Load CMake Project`
8585

86-
6. choose `Build` and start compile
86+
6. Configure compilation toolchain of clion as MSVC: Select Toolchain as Visual Studio on the `CMake` configuration page in step 3, and you cannot select other compilers such as mingw (the windows platform relies on the msvc compiler,
87+
Compiling with other compilers such as mingw will report an error). In addition, the user can also choose whether the compiled binary file is in Debug mode or Release mode, and select `Build Type` to make a drop-down selection.
88+
89+
7. Configure the architecture and platform of the target file: the windows platform supports compiling sdk link library files of different CPU architectures (x64, x86), users can configure according to actual needs, click
90+
`Build, Execution, Deployment``Toolchains`, in the Architecture option, you can drop down to select the supported CPU architecture.
91+
92+
8. choose `Build` and start compile
8793

8894
#### Step 3: Install C++ SDK
8995

@@ -165,6 +171,27 @@ $ ./vpc_test
165171
# response
166172
$
167173
```
174+
If you use cmake to manage projects under Windows, you need to introduce the relevant dependencies of the sdk core package and service package in CMakeLists.txt.
175+
You can refer to the following CMakeLists.txt file:
176+
```
177+
cmake_minimum_required(VERSION 3.16)
178+
project(demo)
179+
find_package(CURL REQUIRED)
180+
set(CMAKE_CXX_STANDARD 14)
181+
182+
set(LINK_DIR "C:/Program Files (x86)/huaweicloud_cpp_sdk_v3/bin;")
183+
set(BIN_DIR "C:/Program Files (x86)/huaweicloud_cpp_sdk_v3/lib;")
184+
set(SERVICE_DIR "C:/Program Files (x86)/huaweicloud_cpp_sdk_v3/include;")
185+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBOOST_UUID_FORCE_AUTO_LINK")
186+
187+
link_directories(${BIN_DIR})
188+
include_directories(${SERVICE_DIR})
189+
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
190+
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
191+
192+
add_executable(demo main.cpp)
193+
target_link_libraries(demo PUBLIC core vpc_v2)
194+
```
168195

169196
## Online Debugging
170197

core/include/g42cloud/core/Client.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class G42CLOUD_CORE_EXPORT Client {
9393
Region region_;
9494
HttpClient httpClient_;
9595

96-
std::atomic<int> endpointIndex = 0;
96+
std::atomic<int> endpointIndex;
9797
};
9898
}
9999
}

core/include/g42cloud/core/exception/ClientRequestException.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ class G42CLOUD_CORE_EXPORT ClientRequestException : public ServiceResponseExcept
3232
ClientRequestException(int statusCode, const std::string &errorCode, const std::string &errorMsg,
3333
const std::string &requestId);
3434

35+
ClientRequestException(int statusCode, const std::string &errorCode, const std::string &errorMsg,
36+
const std::string &requestId, const std::string &encodedAuthorizationMessage);
37+
3538
ClientRequestException(int statusCode, const SdkErrorMessage &sdkErrorMessage);
3639
};
3740
}

core/include/g42cloud/core/exception/SdkErrorMessage.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,34 @@ class G42CLOUD_CORE_EXPORT SdkErrorMessage {
3434
explicit SdkErrorMessage(int statusCode);
3535
SdkErrorMessage(const std::string &errorCode, const std::string &errorMsg, const std::string &requestId);
3636
SdkErrorMessage(const std::string &errorCode, const std::string &errorMsg);
37+
SdkErrorMessage(const std::string &errorCode, const std::string &errorMsg, const std::string &requestId,
38+
const std::string &encodedAuthorizationMessage);
3739

3840
virtual ~SdkErrorMessage();
3941

4042
int getStatusCode() const;
4143
const std::string &getErrorMsg() const;
4244
const std::string &getErrorCode() const;
4345
const std::string &getRequestId() const;
46+
const std::string &getEncodedAuthorizationMessage() const;
4447

4548
void setStatusCode(int statusCode);
4649
void setErrorMsg(const std::string &errorMsg);
4750
void setErrorCode(const std::string &errorCode);
4851
void setRequestId(const std::string &requestId);
52+
void setEncodedAuthorizationMessage(const std::string &encodedAuthorizationMessage);
4953

5054
SdkErrorMessage &withErrorMsg(const std::string &errorMsg);
5155
SdkErrorMessage &withErrorCode(const std::string &errorCode);
5256
SdkErrorMessage &withRequestId(const std::string &requestId);
57+
SdkErrorMessage &withEncodedAuthorizationMessage(const std::string &encodedAuthorizationMessage);
5358

5459
private:
5560
int statusCode_ {};
5661
std::string errorMsg_;
5762
std::string errorCode_;
5863
std::string requestId_;
64+
std::string encodedAuthorizationMessage_;
5965
};
6066
}
6167
}

core/include/g42cloud/core/exception/ServiceResponseException.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,30 @@ class G42CLOUD_CORE_EXPORT ServiceResponseException : public SdkException {
3333
ServiceResponseException(int statusCode, const SdkErrorMessage &sdkErrorMessage);
3434
ServiceResponseException(int statusCode, const std::string &errorCode, const std::string &errorMsg,
3535
const std::string &requestId);
36+
37+
ServiceResponseException(int statusCode, const std::string &errorCode, const std::string &errorMsg,
38+
const std::string &requestId, const std::string &encodedAuthorizationMessage);
39+
3640
static ServiceResponseException mapException(int statusCode, const SdkErrorMessage &sdkErrorMessage);
3741
static ServiceResponseException mapException(int statusCode, const std::string &errorCode,
3842
const std::string &errorMsg, const std::string &requestId);
3943

44+
static ServiceResponseException mapException(int statusCode, const std::string &errorCode,
45+
const std::string &errorMsg, const std::string &requestId,
46+
const std::string &encodedAuthorizationMessage);
47+
4048
int getStatusCode() const;
4149
const std::string &getErrorMsg() const;
4250
const std::string &getErrorCode() const;
4351
const std::string &getRequestId() const;
52+
const std::string &getEncodedAuthorizationMessage() const;
4453

4554
private:
4655
int statusCode_;
4756
std::string errorMsg_;
4857
std::string errorCode_;
4958
std::string requestId_;
59+
std::string encodedAuthorizationMessage_;
5060

5161
std::string toIndentedString(int msg);
5262
std::string toIndentedString(const std::string &msg);

core/src/Client.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ using namespace G42Cloud::Sdk::Core;
3030
using namespace G42Cloud::Sdk::Core::Auth;
3131
using namespace G42Cloud::Sdk::Core::Exception;
3232

33-
Client::Client() = default;
33+
Client::Client() {
34+
endpointIndex = 0;
35+
};
3436

3537
Client::~Client() = default;
3638

core/src/exception/ClientRequestException.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,10 @@ ClientRequestException::ClientRequestException(int statusCode, const SdkErrorMes
2929
ClientRequestException::ClientRequestException(int statusCode, const std::string &errorCode,
3030
const std::string &errorMsg, const std::string &requestId)
3131
: ServiceResponseException(statusCode, errorCode, errorMsg, requestId)
32+
{}
33+
34+
ClientRequestException::ClientRequestException(int statusCode, const std::string &errorCode,
35+
const std::string &errorMsg, const std::string &requestId,
36+
const std::string &encodedAuthorizationMessage)
37+
: ServiceResponseException(statusCode, errorCode, errorMsg, requestId, encodedAuthorizationMessage)
3238
{}

core/src/exception/SdkErrorMessage.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ SdkErrorMessage::SdkErrorMessage(const std::string &errorCode, const std::string
3939
requestId_ = requestId;
4040
}
4141

42+
SdkErrorMessage::SdkErrorMessage(const std::string &errorCode, const std::string &errorMsg, const std::string &requestId,
43+
const std::string &encodedAuthorizationMessage) {
44+
errorCode_ = errorCode;
45+
errorMsg_ = errorMsg;
46+
requestId_ = requestId;
47+
encodedAuthorizationMessage_ = encodedAuthorizationMessage;
48+
}
49+
4250
SdkErrorMessage::SdkErrorMessage(const std::string &errorCode, const std::string &errorMsg)
4351
{
4452
errorCode_ = errorCode;
@@ -67,6 +75,7 @@ void SdkErrorMessage::setErrorMsg(const std::string &errorMsg)
6775

6876
SdkErrorMessage &SdkErrorMessage::withErrorMsg(const std::string &errorMsg)
6977
{
78+
this->errorMsg_ = errorMsg;
7079
return *this;
7180
}
7281

@@ -82,6 +91,7 @@ void SdkErrorMessage::setErrorCode(const std::string &errorCode)
8291

8392
SdkErrorMessage &SdkErrorMessage::withErrorCode(const std::string &errorCode)
8493
{
94+
this->errorCode_ = errorCode;
8595
return *this;
8696
}
8797

@@ -97,5 +107,21 @@ void SdkErrorMessage::setRequestId(const std::string &requestId)
97107

98108
SdkErrorMessage &SdkErrorMessage::withRequestId(const std::string &requestId)
99109
{
110+
this->requestId_ = requestId;
111+
return *this;
112+
}
113+
114+
SdkErrorMessage &SdkErrorMessage::withEncodedAuthorizationMessage(const std::string &encodedAuthorizationMessage) {
115+
this->encodedAuthorizationMessage_ = encodedAuthorizationMessage;
100116
return *this;
101-
}
117+
}
118+
119+
const std::string& SdkErrorMessage::getEncodedAuthorizationMessage() const {
120+
return this->encodedAuthorizationMessage_;
121+
}
122+
123+
void SdkErrorMessage::setEncodedAuthorizationMessage(const std::string &encodedAuthorizationMessage) {
124+
SdkErrorMessage::encodedAuthorizationMessage_ = encodedAuthorizationMessage;
125+
}
126+
127+

core/src/exception/ServiceResponseException.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ ServiceResponseException::ServiceResponseException(int statusCode, const SdkErro
3434
errorMsg_ = sdkErrorMessage.getErrorMsg();
3535
errorCode_ = sdkErrorMessage.getErrorCode();
3636
requestId_ = sdkErrorMessage.getRequestId();
37+
encodedAuthorizationMessage_ = sdkErrorMessage.getEncodedAuthorizationMessage();
3738
}
3839

3940
ServiceResponseException::ServiceResponseException(int statusCode, const std::string &errorCode,
@@ -46,11 +47,21 @@ ServiceResponseException::ServiceResponseException(int statusCode, const std::st
4647
requestId_ = requestId;
4748
}
4849

50+
ServiceResponseException::ServiceResponseException(int statusCode, const std::string &errorCode, const std::string &errorMsg,
51+
const std::string &requestId, const std::string &encodedAuthorizationMessage)
52+
: SdkException(errorMsg.c_str()) {
53+
statusCode_ = statusCode;
54+
errorMsg_ = errorMsg;
55+
errorCode_ = errorCode;
56+
requestId_ = requestId;
57+
encodedAuthorizationMessage_ = encodedAuthorizationMessage;
58+
}
59+
4960
ServiceResponseException ServiceResponseException::mapException(int statusCode,
5061
const SdkErrorMessage &sdkErrorMessage)
5162
{
5263
return mapException(statusCode, sdkErrorMessage.getErrorCode(), sdkErrorMessage.getErrorMsg(),
53-
sdkErrorMessage.getRequestId());
64+
sdkErrorMessage.getRequestId(), sdkErrorMessage.getEncodedAuthorizationMessage());
5465
}
5566

5667
ServiceResponseException ServiceResponseException::mapException(int statusCode, const std::string &errorCode,
@@ -65,6 +76,19 @@ ServiceResponseException ServiceResponseException::mapException(int statusCode,
6576
return ServiceResponseException(statusCode, errorCode, errorMsg, requestId);
6677
}
6778

79+
ServiceResponseException ServiceResponseException::mapException(int statusCode, const std::string &errorCode,
80+
const std::string &errorMsg, const std::string &requestId,
81+
const std::string &encodedAuthorizationMessage)
82+
{
83+
if (statusCode >= 400 && statusCode < 499) { // 400,499 statusCode
84+
return ClientRequestException(statusCode, errorCode, errorMsg, requestId, encodedAuthorizationMessage);
85+
}
86+
if (statusCode >= 500 && statusCode < 600) { // 500,600 statusCode
87+
return ServerResponseException(statusCode, errorCode, errorMsg, requestId);
88+
}
89+
return ServiceResponseException(statusCode, errorCode, errorMsg, requestId, encodedAuthorizationMessage);
90+
}
91+
6892
int ServiceResponseException::getStatusCode() const
6993
{
7094
return statusCode_;
@@ -85,6 +109,10 @@ const std::string &ServiceResponseException::getRequestId() const
85109
return requestId_;
86110
}
87111

112+
const std::string &ServiceResponseException::getEncodedAuthorizationMessage() const {
113+
return encodedAuthorizationMessage_;
114+
}
115+
88116
std::string ServiceResponseException::toIndentedString(int msg)
89117
{
90118
std::stringstream temp;

0 commit comments

Comments
 (0)