Revisión | abc10232bc18ef1bb46c957ceec0a9e1805f4182 (tree) |
---|---|
Tiempo | 2012-03-30 07:59:01 |
Autor | qwerty2501 <qwerty2501@user...> |
Commiter | qwerty2501 |
xmlhttpapi実装
@@ -1,4 +1,5 @@ | ||
1 | 1 | #include "stdafx.h" |
2 | +#include "nexception.h" | |
2 | 3 | #include "define.h" |
3 | 4 | #include "http.h" |
4 | 5 |
@@ -11,8 +12,10 @@ CWinHttpClient::CWinHttpClient(){ | ||
11 | 12 | |
12 | 13 | CHResult CWinHttpClient::Open(const NString &method,const NString &url,const _variant_t &async){ |
13 | 14 | |
14 | - return m_ptr->Open(method.c_str(),url.c_str(),async); | |
15 | - | |
15 | + CHResult result = m_ptr->Open(method.c_str(),url.c_str(),async); | |
16 | + CHECK_HRESULT(result); | |
17 | + | |
18 | + return result; | |
16 | 19 | } |
17 | 20 | |
18 | 21 |
@@ -27,13 +30,17 @@ CHResult CWinHttpClient::get_Response(IStream **ppStream){ | ||
27 | 30 | |
28 | 31 | |
29 | 32 | } |
33 | + CHECK_HRESULT(result); | |
30 | 34 | |
31 | 35 | return result; |
32 | 36 | } |
33 | 37 | |
34 | 38 | CHResult CWinHttpClient::SetRequestHeader(const NString &headerName,const NString &headerBody){ |
35 | 39 | |
36 | - return m_ptr->SetRequestHeader(headerName.c_str(),headerBody.c_str()); | |
40 | + CHResult result = m_ptr->SetRequestHeader(headerName.c_str(),headerBody.c_str()); | |
41 | + CHECK_HRESULT(result); | |
42 | + | |
43 | + return result; | |
37 | 44 | } |
38 | 45 | |
39 | 46 | CHResult CWinHttpClient::SetRequestHeader(const cookie::CCookie &val){ |
@@ -44,12 +51,16 @@ CHResult CWinHttpClient::SetRequestHeader(const cookie::CCookie &val){ | ||
44 | 51 | ss << _T("="); |
45 | 52 | ss << val.GetCookieValue(); |
46 | 53 | |
47 | - return m_ptr->SetRequestHeader(_T("Cookie"),ss.str().c_str()); | |
54 | + CHResult result = m_ptr->SetRequestHeader(_T("Cookie"),ss.str().c_str()); | |
48 | 55 | |
56 | + CHECK_HRESULT(result); | |
57 | + return result; | |
49 | 58 | } |
50 | 59 | |
51 | 60 | CHResult CWinHttpClient::Send(const _variant_t &value){ |
52 | 61 | |
53 | - return m_ptr->Send(value); | |
62 | + CHResult result = m_ptr->Send(value); | |
63 | + CHECK_HRESULT(result); | |
64 | + return result; | |
54 | 65 | } |
55 | 66 | #include "namespace_end.h" |
\ No newline at end of file |
@@ -53,17 +53,14 @@ public: | ||
53 | 53 | |
54 | 54 | CXmlReader xmlReader; |
55 | 55 | |
56 | - result = xmlReader.Create(); | |
56 | + xmlReader.Create(); | |
57 | 57 | |
58 | - if(result.IsSucceded()){ | |
58 | + xmlReader.SetInput(pStream); | |
59 | 59 | |
60 | - result = xmlReader.SetInput(pStream); | |
61 | 60 | |
62 | - if(result.IsSucceded()){ | |
63 | - | |
64 | - result = func(xmlReader); | |
65 | - } | |
66 | - } | |
61 | + result = func(xmlReader); | |
62 | + | |
63 | + CHECK_HRESULT(result); | |
67 | 64 | |
68 | 65 | } |
69 | 66 |
@@ -57,4 +57,8 @@ class Exception:public std::runtime_error{ | ||
57 | 57 | |
58 | 58 | #define THROW_EXCEPTION(E,M) throw E(M,__LINE__,_T(__FILE__),_T(__FUNCTION__)) |
59 | 59 | |
60 | +#define THROW_HRESULTEXCEPTION() THROW_EXCEPTION(Exception,_T("HResult例外値が発生しました")) | |
61 | + | |
62 | +#define CHECK_HRESULT(r) if(r.IsFailed())THROW_HRESULTEXCEPTION() | |
63 | + | |
60 | 64 | #include "namespace_end.h" |
\ No newline at end of file |
@@ -47,6 +47,7 @@ static_assert(sizeof(CHResult) <= 4,"CHResult size error"); | ||
47 | 47 | |
48 | 48 | |
49 | 49 | |
50 | + | |
50 | 51 | /// |
51 | 52 | ///レジストリキークラス |
52 | 53 | /// |
@@ -1,4 +1,5 @@ | ||
1 | 1 | #include "stdafx.h" |
2 | +#include "nexception.h" | |
2 | 3 | #include "xmlReader.h" |
3 | 4 | |
4 | 5 | #include "namespace_start.h" |
@@ -13,28 +14,38 @@ CHResult CXmlReader::Create(REFIID riid,IMalloc *pMalloc){ | ||
13 | 14 | |
14 | 15 | CHResult CXmlReader::SetInput(IStream *pStream){ |
15 | 16 | |
16 | - return m_xmlReader->SetInput(pStream); | |
17 | + CHResult result = m_xmlReader->SetInput(pStream); | |
18 | + CHECK_HRESULT(result); | |
19 | + return result; | |
17 | 20 | } |
18 | 21 | |
19 | 22 | |
20 | 23 | CHResult CXmlReader::Read(XmlNodeType *pXmlNodeType){ |
21 | 24 | |
22 | 25 | |
23 | - return m_xmlReader->Read(pXmlNodeType); | |
26 | + CHResult result = m_xmlReader->Read(pXmlNodeType); | |
27 | + CHECK_HRESULT(result); | |
28 | + return result; | |
24 | 29 | } |
25 | 30 | |
26 | 31 | CHResult CXmlReader::GetLocalName(const NChar **ppLocalName,UInt *pLocalNameLen){ |
27 | 32 | |
28 | - return m_xmlReader->GetLocalName(ppLocalName,pLocalNameLen); | |
33 | + CHResult result = m_xmlReader->GetLocalName(ppLocalName,pLocalNameLen); | |
34 | + CHECK_HRESULT(result); | |
35 | + return result; | |
29 | 36 | } |
30 | 37 | |
31 | -CHResult CXmlReader::GetValue(const NChar **ppValue,UInt *pValueLen = nullptr){ | |
38 | +CHResult CXmlReader::GetValue(const NChar **ppValue,UInt *pValueLen){ | |
32 | 39 | |
33 | - return m_xmlReader->GetValue(ppValue,pValueLen); | |
40 | + CHResult result = m_xmlReader->GetValue(ppValue,pValueLen); | |
41 | + CHECK_HRESULT(result); | |
42 | + return result; | |
34 | 43 | } |
35 | 44 | CHResult CXmlReader::MoveToFirstAttribute(){ |
36 | 45 | |
37 | - return m_xmlReader->MoveToFirstAttribute(); | |
46 | + CHResult result = m_xmlReader->MoveToFirstAttribute(); | |
47 | + CHECK_HRESULT(result); | |
48 | + return result; | |
38 | 49 | } |
39 | 50 | |
40 | 51 | #include "namespace_end.h" |
\ No newline at end of file |
@@ -109,6 +109,7 @@ | ||
109 | 109 | <ClInclude Include="stdafx.h" /> |
110 | 110 | <ClInclude Include="targetver.h" /> |
111 | 111 | <ClInclude Include="unit_test.h" /> |
112 | + <ClInclude Include="xmlHttpApi.h" /> | |
112 | 113 | </ItemGroup> |
113 | 114 | <ItemGroup> |
114 | 115 | <ClCompile Include="auth.cpp" /> |
@@ -39,6 +39,9 @@ | ||
39 | 39 | <ClInclude Include="auth.h"> |
40 | 40 | <Filter>ヘッダー ファイル</Filter> |
41 | 41 | </ClInclude> |
42 | + <ClInclude Include="xmlHttpApi.h"> | |
43 | + <Filter>ヘッダー ファイル</Filter> | |
44 | + </ClInclude> | |
42 | 45 | </ItemGroup> |
43 | 46 | <ItemGroup> |
44 | 47 | <ClCompile Include="stdafx.cpp"> |
@@ -0,0 +1,30 @@ | ||
1 | +#pragma once | |
2 | + | |
3 | + | |
4 | +#include <nlite_common\http.h> | |
5 | + | |
6 | + | |
7 | + | |
8 | +#include "namespace_start.h" | |
9 | + | |
10 | +class CXmlHttpAPI{ | |
11 | + | |
12 | +private: | |
13 | + CWinHttpClient httpClient; | |
14 | + | |
15 | +public: | |
16 | + | |
17 | + template<typename F> | |
18 | + | |
19 | + Bool Get(const NString &method,const NString &url,F func){ | |
20 | + | |
21 | + httpClient.Open(method,url); | |
22 | + CHResult result =httpClient.get_ResponseXml(func); | |
23 | + return result.IsSucceded(); | |
24 | + } | |
25 | + | |
26 | +}; | |
27 | + | |
28 | + | |
29 | + | |
30 | +#include "namespace_end.h" | |
\ No newline at end of file |