1 /*
2  * Copyright 2009-2017 Alibaba Cloud All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #include <alibabacloud/oss/model/GetBucketQosInfoResult.h>
19 #include <external/tinyxml2/tinyxml2.h>
20 #include "utils/Utils.h"
21 
22 using namespace AlibabaCloud::OSS;
23 using namespace tinyxml2;
24 
GetBucketQosInfoResult()25 GetBucketQosInfoResult::GetBucketQosInfoResult() :
26     OssResult()
27 {
28 }
29 
GetBucketQosInfoResult(const std::string & result)30 GetBucketQosInfoResult::GetBucketQosInfoResult(const std::string& result) :
31     GetBucketQosInfoResult()
32 {
33     *this = result;
34 }
35 
GetBucketQosInfoResult(const std::shared_ptr<std::iostream> & result)36 GetBucketQosInfoResult::GetBucketQosInfoResult(const std::shared_ptr<std::iostream>& result) :
37     GetBucketQosInfoResult()
38 {
39     std::istreambuf_iterator<char> isb(*result.get()), end;
40     std::string str(isb, end);
41     *this = str;
42 }
43 
operator =(const std::string & result)44 GetBucketQosInfoResult& GetBucketQosInfoResult::operator =(const std::string& result)
45 {
46     XMLDocument doc;
47     XMLError xml_err;
48     if ((xml_err = doc.Parse(result.c_str(), result.size())) == XML_SUCCESS) {
49         XMLElement* root = doc.RootElement();
50         if (root && !std::strncmp("QoSConfiguration", root->Name(), 16)) {
51             XMLElement* node;
52             node = root->FirstChildElement("TotalUploadBandwidth");
53             if (node && node->GetText()) {
54                 qosInfo_.setTotalUploadBandwidth(std::strtoll(node->GetText(), nullptr, 10));
55             }
56             node = root->FirstChildElement("IntranetUploadBandwidth");
57             if (node && node->GetText()) {
58                 qosInfo_.setIntranetUploadBandwidth(std::strtoll(node->GetText(), nullptr, 10));
59             }
60             node = root->FirstChildElement("ExtranetUploadBandwidth");
61             if (node && node->GetText()) {
62                 qosInfo_.setExtranetUploadBandwidth(std::strtoll(node->GetText(), nullptr, 10));
63             }
64             node = root->FirstChildElement("TotalDownloadBandwidth");
65             if (node && node->GetText()) {
66                 qosInfo_.setTotalDownloadBandwidth(std::strtoll(node->GetText(), nullptr, 10));
67             }
68             node = root->FirstChildElement("IntranetDownloadBandwidth");
69             if (node && node->GetText()) {
70                 qosInfo_.setIntranetDownloadBandwidth(std::strtoll(node->GetText(), nullptr, 10));
71             }
72             node = root->FirstChildElement("ExtranetDownloadBandwidth");
73             if (node && node->GetText()) {
74                 qosInfo_.setExtranetDownloadBandwidth(std::strtoll(node->GetText(), nullptr, 10));
75             }
76             node = root->FirstChildElement("TotalQps");
77             if (node && node->GetText()) {
78                 qosInfo_.setTotalQps(std::strtoll(node->GetText(), nullptr, 10));
79             }
80             node = root->FirstChildElement("IntranetQps");
81             if (node && node->GetText()) {
82                 qosInfo_.setIntranetQps(std::strtoll(node->GetText(), nullptr, 10));
83             }
84             node = root->FirstChildElement("ExtranetQps");
85             if (node && node->GetText()) {
86                 qosInfo_.setExtranetQps(std::strtoll(node->GetText(), nullptr, 10));
87             }
88             parseDone_ = true;
89         }
90     }
91     return *this;
92 }
93