Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Paweł Wegner
libcloudstorage
Commits
4bb7cf08
Commit
4bb7cf08
authored
Jul 14, 2016
by
Paweł Wegner
Browse files
Request: added error callback.
parent
ecb0d2bf
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/Request/Request.cpp
View file @
4bb7cf08
...
...
@@ -57,6 +57,11 @@ void Request<T>::set_resolver(Resolver resolver) {
function_
=
std
::
async
(
std
::
launch
::
async
,
std
::
bind
(
resolver
,
this
));
}
template
<
class
T
>
void
Request
<
T
>::
set_error_callback
(
ErrorCallback
f
)
{
error_callback_
=
f
;
}
template
<
class
T
>
void
Request
<
T
>::
finish
()
{
std
::
shared_future
<
T
>
future
=
function_
;
...
...
@@ -108,7 +113,9 @@ bool Request<T>::reauthorize() {
}
template
<
class
T
>
void
Request
<
T
>::
error
(
int
,
const
std
::
string
&
)
{}
void
Request
<
T
>::
error
(
int
code
,
const
std
::
string
&
desc
)
{
if
(
error_callback_
)
error_callback_
(
code
,
desc
);
}
template
<
class
T
>
std
::
string
Request
<
T
>::
error_string
(
int
code
,
const
std
::
string
&
desc
)
const
{
...
...
src/Request/Request.h
View file @
4bb7cf08
...
...
@@ -43,10 +43,12 @@ class Request : public IRequest<ReturnValue> {
public:
using
ProgressFunction
=
std
::
function
<
void
(
uint32_t
,
uint32_t
)
>
;
using
Resolver
=
std
::
function
<
ReturnValue
(
Request
*
)
>
;
using
ErrorCallback
=
std
::
function
<
void
(
int
,
const
std
::
string
&
)
>
;
Request
(
std
::
shared_ptr
<
CloudProvider
>
);
void
set_resolver
(
Resolver
);
void
set_error_callback
(
ErrorCallback
);
void
finish
();
void
cancel
();
...
...
@@ -60,7 +62,6 @@ class Request : public IRequest<ReturnValue> {
std
::
ostream
*
error
,
ProgressFunction
download
=
nullptr
,
ProgressFunction
upload
=
nullptr
);
protected:
std
::
shared_ptr
<
CloudProvider
>
provider
()
const
{
return
provider_
;
}
virtual
void
error
(
int
code
,
const
std
::
string
&
description
);
std
::
string
error_string
(
int
code
,
const
std
::
string
&
desc
)
const
;
...
...
@@ -77,6 +78,7 @@ class Request : public IRequest<ReturnValue> {
std
::
shared_ptr
<
CloudProvider
>
provider_
;
std
::
atomic_bool
is_cancelled_
;
std
::
shared_future
<
ReturnValue
>
function_
;
ErrorCallback
error_callback_
;
};
}
// namespace cloudstorage
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment